sampler2DShadow

i’m trying to send depth info to my shader:

uniform sampler2DShadow depth;

but then i try something like, jsut for a test:

float focalDepth = 0.5;
vec4 depth = texture2D(depthTex, gl_TexCoord[1].st);

if (depth.z < focalDepth)
discard;

but get a compile errors saying:

texture2D no matching overloaded operator function found.

and

‘=’ cannot convert from ‘const float’ to ‘4-component vector of float’

any idea is firstly, im accessing the depth texture wrong, and secondly, what does the second error mean?

Hello,
I can see some errors in your code:

#1 You are calling ‘depth’ to the sampler2DShadow and to the return value.
#2 You are using in texture2D function a sampler called ‘depthTex’, and you have declared ‘depth’.
#3 You are using texture2D function, and for shadow samplers, the fuction is shadow[1|2|3]D[Proj|Lod], and this functions needs a vec3 or vec4 for texture coordinates.
try something like vec4 depthval = shadow2D(depth, gl_TexCoord[0].str);

Hope this helps

okay there was a bobo in my post, first line was:

uniform sampler2DShadow depthTex;
not
uniform sampler2DShadow depth;

but yeah shadow2D was the problem, with it taking a vec3, if im using 2d texture coords, i assume it will still work?

now i have:

void main()
{
vec4 depth = shadow2D(depthTex, gl_TexCoord[0].str);
gl_FragColor = depth;
}

which doesnt come out right, so i assume im trying to display it incorectly, i get a white screen and seems when i get really close to something i get blackness where there is polys… but really close!

if i change it to be a texture2D and not shadow sampler, it comes up as expected?

so should i treat my depth texture as a regular texture or as a shadow texture?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.