Bruno

10-24-2006, 09:48 AM

Hi.,

I recently updated fom cg 1.2 to cg 1.4, and altough all shaders work, they don't as expected.

It seems that all texture stages in cg 1.4 are being ignored, for example a bumpmapping shader that needs a difuse texture and a normal texture, only shows the normal( normal is binded to unit0), a water shader that has 4 textures units, only unit 0 is used, the rest is ignored..

I don't know what change have they made that would cause this, but i guess it must be something on how the input variables are declared ??

This one for example, is a water shader that was working in cg1.2

Do you guys spot something that could be done wrong here that wasn't spotted in 1.2, and now it's spotted in 1.4 ??

thanks,

Bruno

void main(

float4 TexCoord0 : TEXCOORD0,

float4 TexCoord2 : TEXCOORD2,

out float4 oColor : COLOR0,

uniform sampler2D Texture0,//reflection

uniform sampler2D Texture1,//fresnel map

uniform sampler2D Texture2,//normal map

uniform sampler2D Texture3,//refraction

uniform float Interpolate,

uniform float OffsetTex,

uniform float UnderWater,

uniform float2 HeightOffset,

uniform float3 EyePosition,

uniform float3 LightVector,

uniform float3 LightColor,

uniform float SpecularPower

)

{

float4 NormalF = tex2D(Texture2, TexCoord2.xz/20.0 + OffsetTex ) - 0.5;

NormalF.x=lerp(NormalF.x,NormalF.z,Interpolate);

NormalF.z=lerp(NormalF.y,NormalF.w,Interpolate);

NormalF.y=4.0;

NormalF.w=1.0;

float3 Point=TexCoord2.xyz-EyePosition;

float dist=clamp((dot(Point,Point)-150.0)/30.0,0.0,8.0);

float2 ReflectionOffset = float2(NormalF.x/(3.0+dist),NormalF.z/3.0)/12.0;

float2 newtexcoords;

newtexcoords.x = TexCoord0.x/TexCoord0.w;// + ReflectionOffset.x;

newtexcoords.y = TexCoord0.y/TexCoord0.w;// + ReflectionOffset.y;

float4 RefractionColorTemp = tex2D( Texture3, newtexcoords );

newtexcoords.x = TexCoord0.x/TexCoord0.w + ReflectionOffset.x*RefractionColorTemp.w;

newtexcoords.y = TexCoord0.y/TexCoord0.w + ReflectionOffset.y*RefractionColorTemp.w;

float4 RefractionColor = tex2D( Texture3, newtexcoords );

float3 Normal=normalize(NormalF.xyz);

float3 EyeVector=normalize(Point);

float3 Reflected=normalize(reflect(EyeVector,Normal));

float4 ReflectionColor = tex2D( Texture0, newtexcoords );

float3 HalfAngle=normalize(LightVector-EyeVector);

float specular = saturate(dot(Normal.xyz, HalfAngle.xyz));

specular=pow(specular,SpecularPower);

float2 FresnelCoord=float2(dot(EyeVector,Reflected),1.0);

float Fresnel=tex2D(Texture1, FresnelCoord).x;

oColor=lerp(RefractionColor,ReflectionColor,Fresne l*RefractionColor.w)+specular*LightColor.xyzz;

oColor.w=1.0f;

}

I recently updated fom cg 1.2 to cg 1.4, and altough all shaders work, they don't as expected.

It seems that all texture stages in cg 1.4 are being ignored, for example a bumpmapping shader that needs a difuse texture and a normal texture, only shows the normal( normal is binded to unit0), a water shader that has 4 textures units, only unit 0 is used, the rest is ignored..

I don't know what change have they made that would cause this, but i guess it must be something on how the input variables are declared ??

This one for example, is a water shader that was working in cg1.2

Do you guys spot something that could be done wrong here that wasn't spotted in 1.2, and now it's spotted in 1.4 ??

thanks,

Bruno

void main(

float4 TexCoord0 : TEXCOORD0,

float4 TexCoord2 : TEXCOORD2,

out float4 oColor : COLOR0,

uniform sampler2D Texture0,//reflection

uniform sampler2D Texture1,//fresnel map

uniform sampler2D Texture2,//normal map

uniform sampler2D Texture3,//refraction

uniform float Interpolate,

uniform float OffsetTex,

uniform float UnderWater,

uniform float2 HeightOffset,

uniform float3 EyePosition,

uniform float3 LightVector,

uniform float3 LightColor,

uniform float SpecularPower

)

{

float4 NormalF = tex2D(Texture2, TexCoord2.xz/20.0 + OffsetTex ) - 0.5;

NormalF.x=lerp(NormalF.x,NormalF.z,Interpolate);

NormalF.z=lerp(NormalF.y,NormalF.w,Interpolate);

NormalF.y=4.0;

NormalF.w=1.0;

float3 Point=TexCoord2.xyz-EyePosition;

float dist=clamp((dot(Point,Point)-150.0)/30.0,0.0,8.0);

float2 ReflectionOffset = float2(NormalF.x/(3.0+dist),NormalF.z/3.0)/12.0;

float2 newtexcoords;

newtexcoords.x = TexCoord0.x/TexCoord0.w;// + ReflectionOffset.x;

newtexcoords.y = TexCoord0.y/TexCoord0.w;// + ReflectionOffset.y;

float4 RefractionColorTemp = tex2D( Texture3, newtexcoords );

newtexcoords.x = TexCoord0.x/TexCoord0.w + ReflectionOffset.x*RefractionColorTemp.w;

newtexcoords.y = TexCoord0.y/TexCoord0.w + ReflectionOffset.y*RefractionColorTemp.w;

float4 RefractionColor = tex2D( Texture3, newtexcoords );

float3 Normal=normalize(NormalF.xyz);

float3 EyeVector=normalize(Point);

float3 Reflected=normalize(reflect(EyeVector,Normal));

float4 ReflectionColor = tex2D( Texture0, newtexcoords );

float3 HalfAngle=normalize(LightVector-EyeVector);

float specular = saturate(dot(Normal.xyz, HalfAngle.xyz));

specular=pow(specular,SpecularPower);

float2 FresnelCoord=float2(dot(EyeVector,Reflected),1.0);

float Fresnel=tex2D(Texture1, FresnelCoord).x;

oColor=lerp(RefractionColor,ReflectionColor,Fresne l*RefractionColor.w)+specular*LightColor.xyzz;

oColor.w=1.0f;

}