I tried to do phong bump mapping with a lookup texture in cg, but when the program start it gave me this error:
dependent texture operations don’t meet the restrictions of texture shaders.
Why this happens? It is possible to pass the reflection vector to lookup texture?
Here’s the code:
IN.TexCoord2 is the tangent space Light Vector
IN.TexCoord3 is the tangent space eye vector
float4 expand ( float4 v )
{
return ( v - 0.5 ) * 2;
}
float3 normalize ( float3 v )
{
float DistSq = 1 - ( dot( 2 * ( v - 0.5 ), 2 * ( v - 0.5 ) ) );
return ( 2 * ( v - 0.5 ) ) + ( ( v - 0.5 ) * DistSq );
}
float4 reflect ( float4 I, float4 N )
{
return I - 2.0 * N * dot( N, I );
}
struct fpin
{
float4 Color0 : COLOR0;
float4 Color1 : COLOR1;
float2 TexCoord0 : TEXCOORD0;
float2 TexCoord1 : TEXCOORD1;
float4 TexCoord2 : TEXCOORD2;
float4 TexCoord3 : TEXCOORD3;
};
struct fpout
{
float4 Color : COLOR;
};
fpout main ( fpin IN,
uniform sampler2D NormalMap,
uniform sampler2D DecalMap,
uniform sampler2D LookupMap )
{
fpout OUT;
float4 NormalTex = tex2D( NormalMap, IN.TexCoord0 );
float4 DecalTex = tex2D( DecalMap, IN.TexCoord1 );
float4 LdotN = saturate( dot( expand( IN.TexCoord2 ), expand( NormalTex ) ) );
float4 ReflectionVector = reflect( IN.TexCoord3, NormalTex );
float4 RdotV = saturate( dot( normalize( ReflectionVector ), expand( IN.TexCoord3 ) ) );
float4 LookupTex = tex2D( LookupMap, float2( dot( IN.TexCoord2.xyz, expand( NormalTex ) ),
dot( IN.TexCoord3.xyz, ReflectionVector.xyz ) ) );
float4 DiffuseColor = float4( 1.0, 1.0, 1.0, 1.0 );
float4 SpecularColor = float4( 1.0, 1.0, 1.0, 1.0 );
OUT.Color.rgb = ( LookupTex.rgb * DecalTex * DiffuseColor.xyz ) + ( LookupTex.a * SpecularColor );
OUT.Color.a = 0.0;
return OUT;
}