Original Post
The following pixel program is part of a vertex/pixel shader pair for implementing a spherical environment map to be combined with a base texture. The vertex shader passes through the base map coordinate and computes the spherical map coordinate.
void pmain (
in float2 iBaseMapCoord : TEXCOORD0,
in float2 iSphereMapCoord : TEXCOORD1,
out float4 oColor : COLOR,
uniform float uMode,
uniform sampler2D uBaseMap,
uniform sampler2D uSphereMap)
{
float4 baseMapColor = tex2D(uBaseMap, iBaseMapCoord);
float4 sphereMapColor = tex2D(uSphereMap, iSphereMapCoord);
if (uMode == 0) // replace
{
oColor = sphereMapColor;
}
else if (uMode == 1) // modulate
{
oColor = baseMapColor * sphereMapColor;
}
else if (uMode == 2) // add
{
oColor = saturate(baseMapColor + sphereMapColor);
}
else // unsupported mode
{
oColor = 0;
}
}
My program changes the mode dynamically. This compiles with Cg 1.1. The OpenGL version uses the arbfp1 profile. The DirectX9 version uses the ps_2_0 profile. When I run this with OpenGL and change the mode, the rendered object changes its appearance correctly. When I run this with DirectX9, the rendered object is drawn with replace mode no matter what I set the mode to. Is there some restriction on conditional statements in DirectX that I am missing?