Shaders and Shader Sharing

The section on models and shaders used by an IFXModelResource, covered most issues about shaders. Keep in mind that surface property data from the authoring tool is placed in several locations in a Shockwave 3D§ scenegraph database:

Be sure that only one copy of each unique asset is created in the palettes. When a shader is to be applied to a model, the index to the appropriate entry in the Shader Resource Palette is placed into a style in the IFXModelResource's Style Palette.

Texture Layers

Shockwave 3D, like many real-time 3-D rendering systems, uses hardware texture layers, rather than the more expensive algorithms favored by non-real-time authoring systems, to simulate complex lighting effects. The texture layers currently implemented are:

Texture Layer

Hardware Texture Blending Function

IFXShaderLitTexture:BASE
(Diffuse Color)

MULTIPLY (or REPLACE when a shader uses diffuse lighting or specular lighting)

IFXShaderLitTexture::REFLECTION

Blend

IFXShaderLitTexture::GLOSS

Multiply

IFXShaderLitTexture::DIFFUSE
(Diffuse Lighting)

Multiply

IFXShaderLitTexture::SPECULAR
(Specular Lighting)

Add

Texture layers are added to a IFXShaderLitTexture by specifying a texture resource palette ID to use for the given layer, calling the IFXShaderLitTexture::SetTextureID() method. They operate in the order specified by the table above. Do not change the blending functions, texture modes, or blending sources defaults from within the exporter; rather, leave these to be manipulated in Director*.

The Blending Functions work as follows:

Texture Layer

Result

REPLACE

The nth texture replaces all prior texture layers and lighting calculations

MULTIPLY

Pixels in the nth texture are multiplied by the previous texture layer's pixels

ADD

Pixels in the nth texture are added to the previous texture layer's pixels, and then clamped to the range of 0.0 to 1.0.

BLEND

The nth texture combines with the previous layers according to the layer's blendSource setting

The blendSource settings operate as follows:

Texture Layer

Result

ALPHA

The color at each pixel is a weighted blend between the nth texture's pixel color and the pixel color that is the result of combining the previous texture layers, where the weight is the nth texture's alpha value.

For example, if a pixel in the nth texture layer has an alpha value of 0.9, the resulting pixel will contain 90% of the pixel's color and 10% of the pixel color that resulted from combining the previous texture layers.

CONSTANT

The nth texture is combined with the product of the previous texture layers using a single blending ratio, which is the value of blendConstant for the nth layer.

For example, if the nth layer's blendConstant value is 0.9, the resulting texture will contain 90% of the nth texture and 10% of the texture that resulted from combining the previous texture layers.

Refer to OpenGL or DirectX user manuals and the "Shaders" section of 3D Xtra Lingo API for more details on texture layering and blending.

§See asterisked (*) statement at Legal Information © 2001 Intel Corporation.