effect

Ein Material-Effekt ist ein Text String (in "..." in der Material Definition) oder ein Dateiname mit der Endung .fx (für Effekt-Skripte) oder .fxo (für kompilierte Effekte).. Ein Effekt besteht aus einem oder mehreren techniques. Jede technique enthält eine oder mehere Passes. Jeder Pass enthält Einstellungen für ein oder mehrere Textur-Stage-Register der 3D Hardware. Optional können Pixel- und Vertex-Shader zu Neudefinition des Verhaltens der Stages eingesetzt werden. Das Modell wird einmal für jedes Pass mit den gegeben Einstellungen gerendert.

Funktioniert eine technique nicht, da die angegeben Texture Stages Zustände von der 3D Hardware nicht unterstützt werden, wird automatisch zur nächste technique des Effekts gesprungen. Deswegen sollte jeder Effekt eine einfache Fallback technique enthalten, um auch alte Hardware zu unterstützen.

Der Effekt String ist mit dem DirectX .fx Format kompatibel. Die Schlüsselwörter für die Textur Stage Einstellungen sind grundsätzlich die gleichen wie in der Microsoft DirectX 9.0c Refenze für Textur und Render States. Deswegen kann ein Effekt anhand der Microsoft Dokumentation entwickelt werden.

Eine Referenzliste kann in der DirectX9 Dokumentation unter DirectX Graphics -> Reference -> Effect Files Reference gefunden werden.

Bemerkungen:

Edition

 C   P 

Beispiel 1:

MATERIAL* mat_test =
{
   effect = "shadertest.fx"; 
}

Beispiel 2:

// the following 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 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
}


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
   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);
}

Siehe auch:

Material, Effekt, material.event, material.flags, material.matrix, effect_load ► Aktuelle Version Online