Author Topic: Application d’une alphamap sur un modèle 3ds avec un submesh  (Read 3715 times)

0 Members and 1 Guest are viewing this topic.

John Difool

  • Thug
  • *
  • Posts: 48
    • KoKon3D
Application d’une alphamap sur un modèle 3ds avec un submesh
« on: September 14, 2006, 03:21:15 PM »
Salut JeGX!!!!

Afin de pouvoir positionner mes alphamap précisément dans ma demo, j’aimerais d’abord créer mes modèles dans 3dsmax et ensuite leurs appliquer les textures alphamap.

Cependant quand je met mon modèle dans hyperion et que je lui applique la texture alphamap à l'aide d'un sub mesh, il n’apparaît pas.

Ps : j’ais verifié sans la texture, il apparaît correctement.

Là je bloque :oops: , as tu une solution ?

Merci d'avance :D !!!

Ci-joint, mon code :


Code: [Select]
<?xml version="1.0" encoding="Windows-1252" standalone="yes"?>



<hyperion version="1.0">



<scene name="test trans"
       display_fps="TRUE"
       show_ref_grid="FALSE"
       vsync="TRUE" display_hyperion_logo="FALSE">
<background_image image="" />
<infos_color r="0.0" g="0.0" b="0.0" />
<window_size width="1024" height="768" />
<background_color r="02.0" g="0.4" b="0.2" />
<global_ambient_light r="01.4" g="01.4" b="01.4" />
</scene>

<camera name="Main_Camera" navigation_mode="FLY" fov="70.0" >
<position x="0.0" y="50.0" z="150.0" />
<add_child name="myLight" />
</camera>

<light name="myLight" render="FALSE"  type="OMNI"  radius="1000.0" linear_att= "0.001"
constant_att ="0.00005" quadratic_att="0.000015" >
<ambient r="00.4" g="0.4" b="0.4" a="1.0" />
<diffuse r="0.2" g="0.2" b="0.2" a="1.0" />
<specular r="0.2" g="0.2" b="0.2" a="1.0" />
<position x="0.0" y="-15.0" z="-90.0" />
<orientation pitch="0.0" yaw="180.0" />

</light>



<texture name="buissons" filename="buisson.jpg" filtering_mode="LINEAR" />

<texture name="buisson bump" filename="buisson bump.jpg" filtering_mode="LINEAR" />



<material name="buisson_mat" shader_program_name="AlphaMapShader" >
<ambient_reflection_factor r="0.15" g="0.15" b="0.15" a="1.0" />
<diffuse_reflection_factor r="0.7" g="0.7" b="0.7" a="1.0" />
<specular_reflection_factor r="0.0" g="0.0" b="0.0" a="1.0" />
</material>


<!--
                                                           [ L'alphamap fonctionne ]
-->


<mesh name="mesh_plane" shape_type="PLANE" lighting="FALSE" texturing="TRUE" polygon_mode="SOLID" use_vbo="TRUE"
      remove_seam="TRUE" auto_spin="FALSE"  >
<plane
x_size="200.0"
z_size="200.0"
num_segs_x="2"
num_segs_z="2" />

<attach_material name="buisson_mat" />

<texture material_name="buisson_mat" texture_name="buissons" texture_unit="0" />
<texture material_name="buisson_mat" texture_name="buisson bump" texture_unit="1" />

<position x="160.0" y="70.0" z="70.0" />
<orientation pitch="90.0" />
<spin_values x="90.0" y="90.0" z="90.0" />

</mesh>


<!--  
                                                             [ Le model n'apparait pas ]
-->

<model name="buisson" filename="buisson.3ds"
load_texture="FALSE" render="FALSE" texturing="TRUE" lighting="TRUE" polygon_mode="SOLID" >

<position x="190.0" y="100.0" z="180.0" />

</model>

<mesh name="buiss" parent_name="buisson" shape_type="MODEL_SUB_MESH" render="TRUE"
      lighting="TRUE" texturing="TRUE" >

<attach_material name="buisson_mat" />

<texture material_name="buisson_mat" texture_name="buissons" texture_unit="0" />
<texture material_name="buisson_mat" texture_name="buisson bump" texture_unit="1" />

</mesh>

<!--
                                                           [ Alphamap shader ]
-->

<shader_program name="AlphaMapShader"  >
<constant_1i name="colorMap" value="0" />
<constant_1i name="alphaMap" value="1" />

<raw_data><![CDATA[
[Vertex_Shader]
     
varying vec3 normal, lightDir, eyeVec;
varying float att;

void main()
{  
   normal = gl_NormalMatrix * gl_Normal;

   vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex);
   lightDir = vec3(gl_LightSource[0].position.xyz - vVertex);
   eyeVec = -vVertex;
   
   float d = length(lightDir);
   
   att = 1.0 / ( gl_LightSource[0].constantAttenuation +
   (gl_LightSource[0].linearAttenuation*d) +
   (gl_LightSource[0].quadraticAttenuation*d*d) );
   

   gl_Position = ftransform();  
   
   gl_TexCoord[0] = gl_MultiTexCoord0;  
}


[Pixel_Shader]
     
varying vec3 normal, lightDir, eyeVec;
varying float att;

uniform sampler2D colorMap;
uniform sampler2D alphaMap;

void main (void)
{
   vec4 alpha_color = texture2D(alphaMap, gl_TexCoord[0].xy);
   
   if(alpha_color.r<0.1)
   {
      discard;
   }  
   
   vec4 color_map  = texture2D(colorMap, gl_TexCoord[0].xy);

   vec4 final_color =
   ( gl_FrontLightModelProduct.sceneColor * gl_FrontMaterial.ambient +
     gl_LightSource[0].ambient * gl_FrontMaterial.ambient ) *
     color_map;
                     
   vec3 N = normalize(normal);
   vec3 L = normalize(lightDir);
   
   float lambertTerm = dot(N,L);
   
   if(lambertTerm > 0.0)
   {
      final_color += gl_LightSource[0].diffuse *
      gl_FrontMaterial.diffuse *
      lambertTerm * color_map;  
     
      vec3 E = normalize(eyeVec);
      vec3 R = reflect(-L, N);
     
      float specular = pow( max(dot(R, E), 0.0),
      gl_FrontMaterial.shininess );
     
      final_color += gl_LightSource[0].specular *
      gl_FrontMaterial.specular * specular;  
   }

   gl_FragColor = final_color * att;        
}
  ]]></raw_data>

</shader_program>


<!--
<shader_program name="AlphaMapShader"  >
<constant_1i name="colorMap" value="0" />
<constant_1i name="alphaMap" value="1" />

<raw_data><![CDATA[
[Vertex_Shader]


void main()
{
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
}

[Pixel_Shader]

uniform sampler2D colorMap;
uniform sampler2D alphaMap;

void main (void)
{
vec4 alpha_color = texture2D(alphaMap, gl_TexCoord[0].xy);

if(alpha_color.r<0.1)
{
discard;
}

gl_FragColor  = texture2D(colorMap, gl_TexCoord[0].xy);
}
  ]]></raw_data>

</shader_program>
-->

<script name="init_scene" run_mode="EXECUTE_ONCE" >
<raw_data><![CDATA[


]]></raw_data>
</script>


<script name="update_scene" run_mode="EXECUTE_EACH_FRAME" >
<raw_data><![CDATA[


]]></raw_data>
</script>

</hyperion>

JeGX

  • Global Moderator
  • Capo Crimine
  • *****
  • Posts: 2357
    • oZone3D.Net
Application d’une alphamap sur un modèle 3ds avec un submesh
« Reply #1 on: September 14, 2006, 05:14:00 PM »
J'ai pas regardé à fond ton code mais sans le gpu-shader, est-ce que le mesh  est rendu ?

John Difool

  • Thug
  • *
  • Posts: 48
    • KoKon3D
Application d’une alphamap sur un modèle 3ds avec un submesh
« Reply #2 on: September 14, 2006, 09:05:02 PM »
Sans le GPU shader, il y a toujours le même souci, si je retire la partie sub mesh, mon modèle s'affiche bien.

ps: ne prend pas en compte le "render : false" de mon modèle, je l'ai remis en true.

encore merci!!!

JeGX

  • Global Moderator
  • Capo Crimine
  • *****
  • Posts: 2357
    • oZone3D.Net
Application d’une alphamap sur un modèle 3ds avec un submesh
« Reply #3 on: September 15, 2006, 10:19:25 AM »
Voila je t'ai fait une petite demo de test:

TestSubMesh.zip

Elle charge un model composé de deux sous meshes (un plan et une teapot).
Le rendu du plan est desactivé et celui de la teapot est actif.
Dans le materiau de la teapot, j'ai ajouté une texture.
J'espère que ca pourra t'aider un peu.
Utilise toujours la dernière version d'Hyperion... (en ce moment la 1.8.1).

John Difool

  • Thug
  • *
  • Posts: 48
    • KoKon3D
Application d’une alphamap sur un modèle 3ds avec un submesh
« Reply #4 on: September 15, 2006, 06:30:17 PM »
Merci!!!

je n'avais pas assez isolé le cas, en fait je confondais le nom du mesh et celui du matériau.

D'ailleurs, si je veux appliquer la texture alphamap pour chaque sub_mesh de mon modèle, je suis obligé de faire un code du type:

Code: [Select]
<mesh name="buiss" parent_name="buisson" shape_type="MODEL_SUB_MESH" render="TRUE"
      lighting="TRUE" texturing="TRUE" >

<attach_material name="trans" />

<texture material_name="trans" texture_name="buissons" texture_unit="0" />
<texture material_name="trans" texture_name="buisson bump" texture_unit="1" />

</mesh>


pour chaque mesh, ou y a t'il une manière de citer le nom de chaque mesh et de préciser apres le materiau et la texture à leurs appliquer?

par exemple :

Code: [Select]
<mesh name="buiss", "buiss01", "buiss02","buiss03",... parent_name="buisson" shape_type="MODEL_SUB_MESH" render="TRUE"
      lighting="TRUE" texturing="TRUE" >

<attach_material name="trans" />

<texture material_name="trans" texture_name="buissons" texture_unit="0" />
<texture material_name="trans" texture_name="buisson bump" texture_unit="1" />

</mesh>


Car pour l'instant je suis obligé de faire:

Code: [Select]
<model name="buisson" filename="buisson.3ds"
load_texture="FALSE" render="TRUE" texturing="TRUE" lighting="TRUE" polygon_mode="SOLID" >

<position x="190.0" y="100.0" z="180.0" />

</model>

<mesh name="buiss" parent_name="buisson" shape_type="MODEL_SUB_MESH" render="TRUE"
      lighting="TRUE" texturing="TRUE" >

<attach_material name="trans" />

<texture material_name="trans" texture_name="buissons" texture_unit="0" />
<texture material_name="trans" texture_name="buisson bump" texture_unit="1" />

</mesh>

<mesh name="buiss01" parent_name="buisson" shape_type="MODEL_SUB_MESH" render="TRUE"
      lighting="TRUE" texturing="TRUE" >

<attach_material name="trans" />

<texture material_name="trans" texture_name="buissons" texture_unit="0" />
<texture material_name="trans" texture_name="buisson bump" texture_unit="1" />

</mesh>

<mesh name="buiss02" parent_name="buisson" shape_type="MODEL_SUB_MESH" render="TRUE"
      lighting="TRUE" texturing="TRUE" >

<attach_material name="trans" />

<texture material_name="trans" texture_name="buissons" texture_unit="0" />
<texture material_name="trans" texture_name="buisson bump" texture_unit="1" />

</mesh>


et ainsi de suite...

Merci encors pour ton aide, grace à toi ma demo avance à pas de géant :D !!!

JeGX

  • Global Moderator
  • Capo Crimine
  • *****
  • Posts: 2357
    • oZone3D.Net
Application d’une alphamap sur un modèle 3ds avec un submesh
« Reply #5 on: September 15, 2006, 07:14:55 PM »
Si un materiau est utilisé par plusieurs meshes, tu peux ajouter les textures directement dans le materiau:
Code: [Select]

<material name="teapot_m" >
<add_texture texture_name="myTex01" texture_unit="0" />
<add_texture texture_name="myTex02" texture_unit="1" />
</material>


Sinon pour faire des operations encore plus puissantes, tu peux utiliser un peu de scripting LUA mais là on passe à un autre niveau.

John Difool

  • Thug
  • *
  • Posts: 48
    • KoKon3D
Application d’une alphamap sur un modèle 3ds avec un submesh
« Reply #6 on: September 15, 2006, 10:02:02 PM »
Merci, sa fonctionne !

Cependant, je ne peux pas utiliser cette technique pour :
« u_tile="" v_tile="" ,bump_mapping_attach_light name="",texture_type="COLOR_MAP",…>.

Ce n'est pas compatibles avec le noeud  "material"

Et donc, c’est là qu’interviendrait le script lua ?

JeGX

  • Global Moderator
  • Capo Crimine
  • *****
  • Posts: 2357
    • oZone3D.Net
Application d’une alphamap sur un modèle 3ds avec un submesh
« Reply #7 on: September 16, 2006, 07:59:31 AM »
Et non, les paramètres genre u_tile, v_tile et autres sont spécifiques à un mesh en particulier alors qu'un même matériau peut être utilisé par plusieurs meshes (idem pour les textures ou les gpu-shaders: une même texture ou un même gpu-shader peut etre utilisée par plusieurs materiaux). Tu dois donc définir les params (u_tile/v_tile) pour chaque mesh que ce soit par XML ou LUA.

Juste comme ça au passage, n'utilise plus l'attribut bump_mapping_attach_light name. C'est un reste d'une vielle époque ou les vertex et pixel shaders n'existaient pas encore et où le bump mapping était fait en utilisant les fonctions cablées du pipeline 3D...

John Difool

  • Thug
  • *
  • Posts: 48
    • KoKon3D
Application d’une alphamap sur un modèle 3ds avec un submesh
« Reply #8 on: September 16, 2006, 12:26:29 PM »
dak! Donc je jouerais un peu plus du copier coller  :wink: !
En ce qui concerne, le bump_mapping_attach_light name, je trouvais qu’il utilisait moins de process system que les vertex shader, cependant c’est vrai que le résultat est meilleur avec les vertex shader. Je verrais par la suite…
Sinon, j’ai encore une autre question, mais je vais ouvrir un autre topic.