   CG shadow mapping projecting depth map
  Hi,Im using CG to implement shadow mapping, I have done this before in an Nvidia card without any problems but and now adapting for an ATI.  The result from the projection is that the depth map is projected as if it were a normal texture.  The hardware isnt picking up that it is a depth map and doing the correct comparison.What glTexParameteri do I need to setup for the texture so CG will decide its a depth map.Thanks.   
  Ok,I found the texParameters I needed,glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_SGIX, GL_TRUE );glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_OPERATOR_SGIX, GL_TEXTURE_LEQUAL_R_SGIX );But this doesnt work on my ATI card, only on an Nvidia card.  I checked out what extenstions were available on my card and found the SGIX extentions were not there.  I do however have GL_ARB_DEPTH_TEXTURE and GL_ARB_SHADOW which say they do the same thing as the SGIX extentions.I tried the code:glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);which as far as I can tell from this linkhttp://oss.sgi.com/projects/ogl-sample/registry/ARB/shadow.txtshould do the same thing.  However all I get the the depth map projected as if it were an RGB texture and no shadowing.  Does anyone know what extentions I should be using?  As far as I can tell the ARB_SHADOW extention should do the trick.Thanks   ;  what does your shader code look like?   ;  HiMy Vertex shaders is really simplevoid main(float4 position : POSITION,float3 normal: NORMAL,float4 color: COLOR,out float4 oPosition : POSITION,out float4 oColor : COLOR,out float3 objectPos : TEXCOORD1,out float3 oNormal   : TEXCOORD2,out float4 shadowCoordProj: TEXCOORD3,uniform float4x4 modelViewProj,uniform float4x4 shadowMatrix ){  oPosition = mul(modelViewProj, position);  objectPos = position.xyz;  oNormal = normal;  oColor = color;   shadowCoordProj = mul(shadowMatrix, position);}And my fragment shader is thisvoid main(float4 color : COLOR,float4 position  : TEXCOORD1,    float3 normal    : TEXCOORD2,float4 shadowCoordProj: TEXCOORD3,out float4 oColor: COLOR,uniform float3 globalAmbient,uniform float3 lightColor,uniform float3 lightPosition,uniform float3 eyePosition,uniform float3 Ke,uniform float3 Ka,uniform float3 Kd,uniform float3 Ks,uniform float  shininess,//uniform sampler2D shadowMap)uniform sampler2D shadowMap : TEXUNIT0){  float4 shadowed = tex2Dproj(shadowMap, shadowCoordProj);    float3 P = position.xyz;  float3 N = normal;    // Compute emissive term  float3 emissive = Ke;  // Compute ambient term  float3 ambient = Ka * globalAmbient;  // Compute the diffuse term  float3 L = normalize(lightPosition - P);  float diffuseLight = max(dot(L, N), 0);  float3 diffuse = Kd * lightColor * diffuseLight;  // Compute the specular term  float3 V = normalize(eyePosition - P);  float3 H = normalize(L + V);  float specularLight = pow(max(dot(H, N), 0), shininess);  if (diffuseLight &lt;= 0) specularLight = 0;  float3 specular = Ks * lightColor * specularLight;  float3 temp = shadowed.xyz * (diffuse + specular);  oColor.xyz = temp + ambient + emissive;  oColor.w = 1;}These work fine on any Nvidia hardware, but the depth function extentions jsut wont work on the ATI.  The same extention did work when I made a fixed function shadow mapping program, but it doesnt seem to interact with CG.Thanks.   ;float4 shadowed = tex2Dproj(shadowMap, shadowCoordProj);That line fills me with a sense of 'huh?'In GLSL there is a proper shadow projection function call which does the lookup and the 'r' compare for you, giving you back a float4 (or vec4 in GLSL speak) with the shadowing worked out.Isn't that anything like that in Cg?If so, have you tried using it? (the GLSL version works on ATI hardware you see, I've used it myself, which is why I'm wondering if maybe the NV driver is doing something funky behind the scenes because it knows its a shadow map but the ATI driver is just doing what you ask, namely a normal projective lookup).   ;  Even though I don't use fragment shaders - I thought that this was something interesting - I did a google and came up with this page. If you take a look they have different shaders for shadowmapping on ATI and others:In default shader:return texRECTproj(shadowmap, IN.texcoord) * IN.color;In ATI shader:float4 color = tex2Dproj(shadowmap, IN.texcoord);float test = IN.texcoord.z / IN.texcoord.w;float val;val = (test < color.x) ? 1.0 : 0.0;return IN.color * val;I don't know much about shader shadowmapping but it looks like on ATI automatic texture depth comparison "GL_COMPARE_R_TO_TEXTURE" doesn't work - so they are doing it manually in the shader. Makes sense! [smile]   ;  Well, if thats the case its going to be a Cg specific issue as GLSL can do a shadow lookup just fine on ATI hardware.From my own code archives;void main(){vec4 lightValue = texture2DProj(lightTex, projCoord);vec4 shadowValue = shadow2DProj(shadowMap, projCoord);gl_FragColor = boost * gl_Color * lightValue * shadowValue + ambient;}and it produces good results (damn slow ones however as readback of depthbuffer on my card = 1fps max, huzzah!)... infact, I should really update my code base to use FBOs instead...   ;Quote:Original post by phantomdamn slow ones however as readback of depthbuffer on my card = 1fps max, huzzah!)... infact, I should really update my code base to use FBOs instead...LOL FBO's is the only way to go! :);  well, this code pre-dates FBOs being available, thats how old it is!   ;  I will try the ATI specific shader and see if that does the trick.  I know the GL_COMPARE_R_TO_TEXTURE works in the fixed function version I made.  It does seem that Cg isnt automatically sensing what type of projection to do, which it says it does in the book.Thanks   