If a certain technique does not work because the 3D hardware does not support the given texture stage states, the next technique from the effect is automatically selected. Therefore, an effect should always contain a simple fallback technique for supporting old hardware.
The effect string is compatible to the DirectX .fx format. The keywords used in the texture stage settings are basically the same used in the Microsoft DirectX 9c reference for texture and render states. Therefore, an effect can be written based on the microsoft documentation.
A reference list can be found in the DirectX9 documentation under DirectX Graphics -> Reference -> Effect Files Reference.
material mat_test
{
effect = "shadertest.fx";
}
// the following code creates a material that adds DOT3 bumpmapping to a model
BMAP* reptile = "scales.tga";
material mat_bump
{
skin2 = reptile; // set a reptile skin
scale1 = 0.2; // factor for the skin scale at stage 0
// define a material effect string
effect = "
// declare the used textures and variables
texture entSkin1; // the entity skin
texture mtlSkin2; // the bump map
dword mtlSkill1; // the light vector
// default technique
technique bump_dot3
{
pass P0
{
// set texture stage states
Texture[0] = <mtlSkin2>;
Texture[1] = <entSkin1>;
TextureFactor = <mtlSkill1>;
ColorArg1[0] = Texture; // stage 0 = bumpmap
ColorOp[0] = DotProduct3;
ColorArg2[0] = TFactor;
ColorArg1[1] = Texture; // stage 1 - skin texture
ColorOp[1] = AddSigned;
ColorArg2[1] = Current;
ColorArg1[2] = Diffuse; // stage 2 - lighting
ColorOp[2] = Modulate2x;
ColorArg2[2] = Current;
}
}
// fallback technique for devices that do not support bumpmapping
technique fallback
{
pass P0
{
// set texture stage states
Texture[0] = <entSkin1>;
ColorArg1[0] = Texture; // stage 0 = skin texture
ColorOp[0] = Modulate2x;
ColorArg2[0] = Diffuse; // modulate by lighting
}
}
"; // end of the effect string
}
starter mat_bump_init
{
// initialize the material properties
vec_set(mat_bump.ambient_blue, mat_model.ambient_blue);
vec_set(mat_bump.diffuse_blue, mat_model.diffuse_blue);
vec_set(mat_bump.specular_blue, mat_model.specular_blue);
mat_bump.power = mat_model.power;
// create the normals map for DOT3 bumpmapping
bmap_to_normals(mat_bump.skin2,2);
// set a lighting vector for DOT3 bumpmapping
mat_bump.skill1 = pixel_for_vec(vector(200,200,200),100,8888);
}
Material, Effect, material.event, material.flags, material.matrix, effect_load