Torque Shader Engine DocumentationCVS Revision Label 0.1.x |
Materials offer a lot of options for surface properties, but if even more control is desired, CustomMaterials can be used. CustomMaterials allow the user to specify their own shaders via the ShaderData datablock.
CustomMaterials are derived from Materials, so they can hold a lot of the same properties, but it is up to the user to code how these properties are used.
Specifies either a texture filename, or a texture coming from the scenegraph. The "x" is a number from 0 to the max number of texture units supported on the hardware the CustomMaterial shader is targeting (see the version property description, below).
There are several textures that can be grabbed from the scenegraph and used in shaders. Here is a list:
Interior lightmap
Interior light-normal map (not a bumpmap, but used for bumpmapping)
The fog texture generated by the scenegraph
The cubemap specified with the cubemap parameter of the CustomMaterial
Cubemap passed in from scenegraph
A copy of the screenbuffer - useful for refraction effects
The shader parameter indicates the pixel and/or vertex shader to be used with the CustomMaterial. This parameter expects a ShaderData datablock. See Shaders.
Each CustomMaterial datablock targets a specific level of pixel shader hardware. The version parameter indicates this level. Ie. nVIDIA's Geforce 2 would be 0.0, Geforce 3 and 4ti's would be 1.1, the Geforce FX cards would be 2.0, and the Geforce 6xxx cards would be 3.0.
High level CustomMaterials (ones targeting 3.0 or 2.0 pixel shader hardware) can specify fallbacks for lower levels of hardware. This allows complete control over how a material looks on each possible platform. The fallback parameter is simply another CustomMaterial that is targeting a lower level hardware.
When mapping a CustomMaterial to a texture, the highest level CustomMaterial in the fallback chain should be specified. That way the TSE can follow the fallback chain down until it reaches a material that can be rendered.
Example 3.2.
datablock CustomMaterial( ShinyMetal2_0 )
{
texture[0] = "test/metalBump"; // bumpmap texture in texture unit 0
texture[3] = "$cubemap"; // cubemap texture in texture unit 3
cubemap = Lobby;
shader = BumpCubemap;
version = 2.0;
fallback = ShinyMetal1; // specify fallback for 1.1 hardware
pass[0] = ShinyMetal2_1; // specify second pass
specular = "1.0 1.0 1.0 0.0"; // can use the specular parameter from Material
specularPower = 8.0;
};