cg 1.2 to cg 1.4


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 ??


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;
    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(;
    float3 EyeVector=normalize(Point);
    float3 Reflected=normalize(reflect(EyeVector,Normal));

    float4 ReflectionColor = tex2D( Texture0, newtexcoords );
    float3 HalfAngle=normalize(LightVector-EyeVector);

    float specular = saturate(dot(,;

    float2 FresnelCoord=float2(dot(EyeVector,Reflected),1.0);
    float Fresnel=tex2D(Texture1, FresnelCoord).x;


Hi, Bruno!

I advice you to bind your texture samplers to associated texture units exactly.

I mean, try specifying

in uniform sampler2D Texture0 : TEXUNIT0,//reflection
in uniform sampler2D Texture1 : TEXUNIT1,//fresnel map
in uniform sampler2D Texture2 : TEXUNIT2,//normal map
in uniform sampler2D Texture3 : TEXUNIT3,//refraction

Also bind your texture to correspondant unit exactly (not via Cg, but with glActiveTextureARB()+glBindTexture()).
Hope, this should help.

I use multiple textures with cg 1.5. I was using cg 1.4 and had it working.

I recall that I had to tell cg about the texture:

CGparameter param = cgGetNamedParameter(prog,name.c_str()); cgGLSetTextureParameter(param,_id);

Where handle is just the texture name in opengl that points to the texture. ( from glGenTextures )

Then I’d just bind the texture unit like:

//enable unit 1
//glEnable(GL_TEXTURE_2D);//only using texture unit
glBindTexture (GL_TEXTURE_2D, _id );

Hope that helps…

Hi Bruno,

Please let me know if you have problems with Cg 1.5. It’s the latest release.

Thanks -

Thanks guys, i got it working.
cass, can’t test Cg 1.5 right now, i’m on a VC6++ IDE, i’l try it later.