Material effect script, either directly given in "" in the material definition, or a reference to an external effect file name with extension .fx (for compiled effects and effect scripts) or .fxo (for compiled effects only) . The script can contain either a shader or a fixed function pipeline effect, or both.

Writing effect scripts is covered in the Gamestudio Shader Workshops. In short, an effect consists of one or more techniques, and each technique consists of one or more passes. Each pass consists of a setting of one or more texture stage registers of the 3D hardware, and optionally a pixel or vertex shader that redefines the behavior of the stage. The model is rendered once for each pass, using the given settings. 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 script is compatible to the DirectX .fx format. The keywords used in the texture stage settings are 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.


STRING or char*



 C   P 

Example 1:

MATERIAL* mat_test =
   effect = "shadertest.fx"; // external effect file

Example 2:

// the following fixed function pipeline code creates a material that adds DOT3 bumpmapping to a model
BMAP* reptile_map = "scales.tga";

MATERIAL* mat_bump =
   skin2 = reptile_map; // set a reptile skin
   scale1 = 0.2; // factor for the skin scale at stage 0

// define a material effect script
   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

function mat_bump_startup()
// 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
// set a lighting vector for DOT3 bumpmapping
   mat_bump.skill1 = pixel_for_vec(vector(200,200,200),100,8888);

See also:

Material, Effect, material.event, material.flags, material.matrix, effect_load ► latest version online