Stratos: Punto de Encuentro de Desarrolladores

¡Bienvenido a Stratos!

Acceder

Foros





Material And .hadddd Scripts

Iniciado por auron, 07 de Febrero de 2006, 03:39:26 AM

« anterior - próximo »

auron

 Hey guys,

Do you think it would be better seperate the material portion of the .haddd files into a seperate material file? Maybe a .material file? That way it would be easier for someone to load the same mesh but with different textures using external files. Of course it would mean there would have to be an extra line of code to specify the material file... But shouldn't be that much trouble if you just put it as Mesh.LoadMaterial(string) right? :D

Another thing is, at the moment, we're creating a material array whenever we want to assign a material to a mesh right? Would it be a better idea to make it a list instead and have users create a single material and add it to the mesh.

Maybe something like this:
HMaterial material = new HMaterial;
HMaterialLayer layer = new HMaterialLayer();
material.AddLayer( layer );
sphere.AddMaterial(material);


That way we can keep adding materials to it without having to worry about reconstructing the array.
Is this feasible or does it cause performance issues?

BeRSeRKeR

 
Cita de: "auron"Do you think it would be better seperate the material portion of the .haddd files into a seperate material file? Maybe a .material file? That way it would be easier for someone to load the same mesh but with different textures using external files. Of course it would mean there would have to be an extra line of code to specify the material file... But shouldn't be that much trouble if you just put it as Mesh.LoadMaterial(string) right? :D
There's two ways to specify a material. One is through MAX materials and the other one is through material scripts. I think material scripts are just what you are looking for. Material scripts are similar to those on Doom3 or Quake3. In the tutorial #10 you can see how to load these material scripts. You can take a look at the "base/materials/tutorials" folder for some examples. Anyway, I'll show you an example here:

material "imp" {

renderStates {

 cull  CCW
}

layer "layer0" {

 map diffuse {

  fileName "imp_d"
 
  amount  1.0
 
  color  ( 1.0 1.0 1.0 1.0 )

  samplerStates {

   addressU  Clamp
   addressV  Clamp
   minFilter  Linear
   magFilter  Linear
   mipFilter  Linear
  }
 }

 map normal {

  fileName "imp_n"
 
  amount  1.0
 
  bumpiness 1.0

  samplerStates {

   addressU  Clamp
   addressV  Clamp
   minFilter  Linear
   magFilter  Linear
   mipFilter  Linear
  }
 }

 map specular {

  fileName "imp_s"

  amount  1.0

  color  ( 0.3 0.3 0.3 1.0 )
  power  64.0

  samplerStates {

   addressU  Clamp
   addressV  Clamp
   minFilter  Linear
   magFilter  Linear
   mipFilter  Linear
  }
 }
}
}


In this example we have a material with one layer and three maps, a color map, a normal map and a specular map. Also, sampler states for each map are specified. As you can see, you can specify render states too and a lot more things. For example you can apply geometry shaders to modify texture coordinates (rotate, scale, scroll, turbulence, etc), diffuse color or vertex positions. Another things you can apply are lighting fragments (see tutorial #10 for an example). For a more in depth explanation about material scripts, you can take a look at the "materials.txt" document placed at the "Docs" folder (I just realized that it isn't translated to english yet, sorry). Surprisingly we've forgot to write a tutorial about geometry shaders (maybe on the next update :)) but you can see an example in the tutorial #17. The things on the sides of the table have a glow and this glow varies its intensity over time. Well, this is achieved through a geometry shader that changes the diffuse color through a sine function. Here is the material script (you can find it in the "base/materials/tutorials" folder):

material "column_glow" {

layer "layer0" {


 map diffuse {

  amount      1.0
 
  color  ( 1.0 0.39215 0.07843 1.0 )
 }

 map emissive {
 
  intensity 0.2  
 }

 geometryShader "rgbGen" {

  param "rgbGen_WaveType"   Wave.Sin
  param "rgbGen_WaveBase"   0.5
  param "rgbGen_WaveAmplitude" 0.3
  param "rgbGen_WavePhase"  0.1
  param "rgbGen_WaveFrequency" 0.5
 }
}
}


So once you have your material script, you can do something like this in your code:

myMeshObject.Material[0] = Haddd.Scene.Materials.Create("myMaterialScript");

Oh, one more thing about this. You can specify these materials scripts through a material connection I wrote for MAX but I have to do a video tutorial explaining all these things!.

So to conclude with this, I'll say that material scripts (in conjunction with shaders) are really powerful but we should do some more samples to show its power. :)

Cita de: "auron"Another thing is, at the moment, we're creating a material array whenever we want to assign a material to a mesh right? Would it be a better idea to make it a list instead and have users create a single material and add it to the mesh.

Well, the HMeshObject material array is not a list of materials the model could take any time. Each material in this array is a sub-material for a certain part of the mesh, I mean, you could have a one piece model with two materials applied, one for the body and another one for the head. So in this case, the material array will contain these two materials. That is, the material array isn't meant to be modified (although you could reassign a different material to some of the existing material in the array) by the user, it's created at load time and that's all. I know, in some tutorials this array is created by hand but just because the model creation is hardcoded.

Hope it helps.
¡Si te buscan en nombre de la ley, huye en nombre de la libertad!!

auron

 Wow that's some pretty damn powerful stuff...
Haha.. The material scripts rule! :D

Thanks berserker! (ole)

auron

 Hi berserker,
What's the variable to set in my material script that adjusts the U and V tiling?

material "terrain" {

layer "layer0" {
 map diffuse {
  mapChannel 0
  amount 1
  u_tile 10
  v_tile 10
  color  ( 0.690196 0.690196 0.690196 1.0 )
  fileName "grass"
 }

 map specular {
  color ( 0.1 0.1 0.1 0.1 )
  power 50.0
 }
}
}


I can't seem to get this to work right.

BeRSeRKeR

 
Cita de: "auron"Hi berserker,
What's the variable to set in my material script that adjusts the U and V tiling?

Should be like this:

Citarmaterial "terrain" {

   layer "layer0" {
  map diffuse {
     mapChannel 0
     amount 1
     tile ( 10 10 )
     color  ( 0.690196 0.690196 0.690196 1.0 )
     fileName "grass"
  }

  map specular {
     color   ( 0.1 0.1 0.1 0.1 )
     power 50.0
  }
   }
}
¡Si te buscan en nombre de la ley, huye en nombre de la libertad!!

auron


auron

 By the way Berserker,
Can you release some documentation on the scripting commands?
List what kinda options are available...

BeRSeRKeR

Cita de: "auron"By the way Berserker,
Can you release some documentation on the scripting commands?
List what kinda options are available...
The material scripts documentation is in the "source\Engine\Docs" folder (materials.txt) but is not translated to english yet. Hopefully it will be done tonight. :)
¡Si te buscan en nombre de la ley, huye en nombre de la libertad!!

BeRSeRKeR

 Done.

You can download the english/spanish reference for material scripts here. It's not that extensive but could help you.

Greets.
¡Si te buscan en nombre de la ley, huye en nombre de la libertad!!

auron







Stratos es un servicio gratuito, cuyos costes se cubren en parte con la publicidad.
Por favor, desactiva el bloqueador de anuncios en esta web para ayudar a que siga adelante.
Muchísimas gracias.