Platform Tutorial Editing Material Files
From Multiverse
Contents |
Overview
The Multiverse Model Conversion Tool creates a template of a simple software-shaded material file. You must edit this file for it to be useful. NOTE: A future release of the tools will make this easier.
You can use either a standard software-driven material script, or an advanced, hardware shader material script. With either of these, you can additionally specify animated materials.
Each material will print out a separate material section in the file. You must edit the names of the textures to be used for each of these sections in using the shader model.
For a model with multiple materials, Conversion Tool outputs:
material human_female_run_axe.ruth_hair_mat
{
technique
{
pass
{
shading phong
ambient 0.58824 0.58824 0.58824 0.00000
diffuse 1.00000 1.00000 1.00000 1.00000
specular 0.90000 0.90000 0.90000 0.00000 1.00000
emissive 0.00000 0.00000 0.00000 0.00000
texture_unit
{
texture
tex_coord_set 0
}
}
}
}
material human_female_run_axe.ruth_head_mat
{
technique
{
pass
{
shading phong
ambient 0.58824 0.58824 0.58824 0.00000
diffuse 1.00000 1.00000 1.00000 1.00000
specular 0.90000 0.90000 0.90000 0.00000 1.00000
emissive 0.00000 0.00000 0.00000 0.00000
texture_unit
{
texture
tex_coord_set 0
}
}
}
}
material human_female_run_axe.ruth_body_clothed_mat
{
technique
{
pass
{
shading phong
ambient 0.58824 0.58824 0.58824 0.00000
diffuse 1.00000 1.00000 1.00000 1.00000
specular 0.90000 0.90000 0.90000 0.00000 1.00000
emissive 0.00000 0.00000 0.00000 0.00000
texture_unit
{
texture
tex_coord_set 0
}
}
}
}
To use the software shader with a diffuse map, set the specularity values and set the texture file names for the materials, for example:
material human_female_run_axe.ruth_hair_mat
{
technique
{
pass
{
shading phong
ambient 0.58824 0.58824 0.58824 0.00000
diffuse 1.00000 1.00000 1.00000 1.00000
specular 0.10000 0.10000 0.10000 0.00000 1.00000
emissive 0.00000 0.00000 0.00000 0.00000
texture_unit
{
texture ruth_hair.dds
tex_coord_set 0
}
}
}
}
material human_female_run_axe.ruth_head_mat
{
technique
{
pass
{
shading phong
ambient 0.58824 0.58824 0.58824 0.00000
diffuse 1.00000 1.00000 1.00000 1.00000
specular 0.10000 0.10000 0.10000 0.00000 1.00000
emissive 0.00000 0.00000 0.00000 0.00000
texture_unit
{
texture ruth_head.dds
tex_coord_set 0
}
}
}
}
material human_female_run_axe.ruth_body_clothed_mat
{
technique
{
pass
{
shading phong
ambient 0.58824 0.58824 0.58824 0.00000
diffuse 1.00000 1.00000 1.00000 1.00000
specular 0.10000 0.10000 0.10000 0.00000 1.00000
emissive 0.00000 0.00000 0.00000 0.00000
texture_unit
{
texture ruth_body.dds
tex_coord_set 0
}
}
}
}
To use a hardware shader that incorporates diffuse, normal, and specular maps, change the shader model and put in the correct texture file names. For example, for the hair:
material human_female_run_axe.ruth_hair_mat
{
technique
{
pass
{
// Vertex program reference
vertex_program_ref Examples/CompoundVS_Skinned
{
param_named_auto FogSettings fog_params
param_named_auto WorldMatrix3x4Array[0] world_matrix_array_3x4
param_named_auto ViewProj viewproj_matrix
param_named_auto WorldMatrix world_matrix
param_named_auto LightPosition[0] light_position_object_space 0
param_named_auto LightPosition[1] light_position_object_space 1
param_named_auto LightAttenuation[0] light_attenuation 0
param_named_auto LightAttenuation[1] light_attenuation 1
param_named_auto EyePosition camera_position_object_space
}
fragment_program_ref Examples/CompoundPS_20_NS
{
param_named LMe float4 0 0 0 1
param_named_auto LMa ambient_light_colour
param_named_auto LMd[0] light_diffuse_colour 0
param_named_auto LMd[1] light_diffuse_colour 1
param_named_auto LMs[0] light_specular_colour 0
param_named_auto LMs[1] light_specular_colour 1
param_named shininess float 10
}
// Normal map
texture_unit
{
tex_coord_set 0
texture ruth_hair_normals.dds
}
// Specular map
texture_unit
{
tex_coord_set 1
texture ruth_hair_specular.dds
}
// Diffuse map
texture_unit
{
alpha_rejection greater 128
tex_coord_set 2
texture ruth_hair.dds
}
}
}
}
material human_female_run_axe.ruth_head_mat
{
technique
{
pass
{
shading phong
ambient 0.58824 0.58824 0.58824 0.00000
diffuse 1.00000 1.00000 1.00000 1.00000
specular 0.10000 0.10000 0.10000 0.00000 1.00000
emissive 0.00000 0.00000 0.00000 0.00000
texture_unit
{
texture ruth_head.dds
tex_coord_set 0
}
}
}
}
material human_female_run_axe.ruth_body_clothed_mat
{
technique
{
pass
{
shading phong
ambient 0.58824 0.58824 0.58824 0.00000
diffuse 1.00000 1.00000 1.00000 1.00000
specular 0.10000 0.10000 0.10000 0.00000 1.00000
emissive 0.00000 0.00000 0.00000 0.00000
texture_unit
{
texture ruth_body.dds
tex_coord_set 0
}
}
}
}
In this case since it is an animated model that has a skeleton the material script uses the CompoundVS_Skinned shader model because the model needs to transform the surface coordinates with the animation. This shader passes in an extra matrix for the animation translation solution.
For a static mesh like a building, you would use the regular CompoundVS shader that
looks like this:
vertex_program_ref Examples/CompoundVS
{
param_named_auto FogSettings fog_params
param_named_auto WorldViewProj worldviewproj_matrix
param_named_auto WorldMatrix world_matrix
param_named_auto LightPosition[0] light_position_object_space 0
param_named_auto LightPosition[1] light_position_object_space 1
param_named_auto LightAttenuation[0] light_attenuation 0
param_named_auto LightAttenuation[1] light_attenuation 1
param_named_auto EyePosition camera_position_object_space
}
After you have edited the material file, put it in the material directory in your asset repository so the tools can find it. Likewise, put the meshes it references meshes directory, and so on.
To place this asset into your world in the world editor you must create a material .asset and a mesh .asset with the asset importer and place them in the asset definitions folder.
Standard material script
The standard material script uses a software shader and has only a diffuse component (color texture file) modified by a set of matrix-driven components.
To use the file, you must:
- Add the name of the texture file (DDS file).
- Change the specular value for the collision volumes.
The following code is an example of a material file created by Conversion Tool:
material tutorial_shack.shack_mat
{
technique
{
pass
{
shading phong
ambient 0.58824 0.58824 0.58824 1.00000
diffuse 1.00000 1.00000 1.00000 1.00000
specular 0.00000 0.00000 0.00000 1.00000 1.00000
emissive 0.00000 0.00000 0.00000 1.00000
texture_unit
{
texture
tex_coord_set 0
}
}
}
}
Conversion Tool currently omits the name of the texture file. So, add the name of the texture file (shown in bold), as illustrated below:
texture_unit
{
texture tutorial_shack_texture.dds
The next section is for the associated collision volume. The collision volume material is named to match the base material, to make the file easier to read.
...
material tutorial_shack.collision_volume_lambert
{
technique
{
pass
{
shading phong
ambient 0.58824 0.58824 0.58824 1.00000
diffuse 0.58824 0.58824 0.58824 1.00000
specular 0.90000 0.90000 0.90000 1.00000 1.00000
emissive 0.00000 0.00000 0.00000 1.00000
}
}
}
You only need to change one line in the above section. Unless you set the specular value in 3ds Max, it will be too intense (too high) for proper visuals. In the material file above, the collision volume section has specular values of 0.9:
material tutorial_shack.collision_volume_lambert
{
.
.
.
specular 0.90000 0.90000 0.90000 1.00000 1.00000
...
Change the first three numbers to 0.00000:
specular 0.00000 0.00000 0.00000 1.00000 1.00000
After you make these two changes, save the file.
This material file will provide a simple software shader.
A note about alpha channels
The tutorial_shack material does not have an alpha channel, so you don't need to do anything for this tutorial.
However, for texture files with an alpha map, you must set the alpha channel/map for transparency with the following command:
alpha_rejection greater 128
This code goes just before the texture definition line. For example:
material alpha_shack.shack_mat
{
.
.
.
texture_unit
{
alpha_rejection greater 128
texture human_shack_tall_texture.dds
tex_coord_set 0
}
Hardware shader material script
In addition to a software shader, you can specify a hardware-driven shader that can use normal maps, specular maps, alpha channels, and the diffuse component. In the current set of shaders there are two shaders: one for an animated mesh with a skeleton and one for a static mesh. You create this material file by copying a basic template or other material and adding texture information.
For example, the following illustrates a hardware-driven material script:
material FC_yourthingy.FC_yourmaterialname_upper_mat
{
technique
{
pass
{
// Vertex program reference
vertex_program_ref Examples/CompoundVS
{
param_named_auto FogSettings fog_params
param_named_auto WorldViewProj worldviewproj_matrix
param_named_auto WorldMatrix world_matrix
param_named_auto LightPosition[0] light_position_object_space 0
param_named_auto LightPosition[1] light_position_object_space 1
param_named_auto LightAttenuation[0] light_attenuation 0
param_named_auto LightAttenuation[1] light_attenuation 1
param_named_auto EyePosition camera_position_object_space
}
fragment_program_ref Examples/CompoundPS_20_NS
{
param_named LMe float4 0 0 0 1
param_named_auto LMa ambient_light_colour
param_named_auto LMd[0] light_diffuse_colour 0
param_named_auto LMd[1] light_diffuse_colour 1
param_named_auto LMs[0] light_specular_colour 0
param_named_auto LMs[1] light_specular_colour 1
param_named shininess float 20
}
// Normal map
texture_unit
{
texture YourFileHere_normals.dds
}
// Specular map
texture_unit
{
texture YourFileHere_specular.tga
}
// Diffuse map
texture_unit
{
texture YourFileHere_diffuse.tga
}
}
}
}
You must modify the texture lines. Specify the names of the files to use for the various functions in these lines, for example:
texture YourFileHere.dds
The order that the three maps appear is vital for the material script to function properly.
Animated materials
With either the software or hardware material scripts, you can also include a series of images in a texture unit that cycle, providing an animated material.
For example:
// Diffuse map
texture_unit
{
tex_coord_set 0
anim_texture TextureName_01.dds TextureName_02.dds TextureName_03.dds
TextureName_04.dds TextureName_05.dds 2.5
// Shown on two lines for readability - put on one line in actual file
}
The list of files indicates the frames to be played. The 2.5 at the end is the amount of time in seconds that a cycle through the list will take. If this value is a zero, then a persistant state of non-cycling takes place where you can then set the viewed texture by setting it in script dynamically, as described later.
This animation process will also work for normals as well as specular maps in the hardware-driven shader material. It also works with both the software-driven and hardware-driven shader materials.
There is an alternative method if all your files use the same base name with a numbered extension:
// Diffuse map
texture_unit
{
tex_coord_set 0
anim_texture TextureName.dds 5 2.5
}
This code sets up a series of five textures that cycle over a duration of 2.5 seconds and have the naming scheme of TextureName_01, TextureName_02, and so on.
