shadow2DRect problem

uniform sampler2DRectShadow shadow;

uniform int offset;
void main(){
vec3 r0 = gl_FragCoord.xyz;
r0.x = r0.x - float(offset);
float tmp = shadow2DRect(shadow, r0).x;
if (tmp < 0.5)
discard;
gl_FragColor = gl_Color;
}

r0keeps the fragment position ,then r0 is used as the texcoord parameter of shadow2DRect. However r0’s x and y component value can be negative,can texcoord be negative value?

Out of interest, what is this shader supposed to do? It’s not performing a ‘standard’ shadowmap comparison.

However r0’s x and y component value can be negative
Given

 vec3 r0 = gl_FragCoord.xyz

I don’t see where r0.y is -ve.

r0.x = r0.x - float(offset);

r0.x could be -ve if gl_FragCoord.x is 0 and offset > 0.
So, it’s odd, and not legal either according to ARB_TEXTURE_RECTANGLE spec.
http://www.opengl.org/registry/specs/ARB/texture_rectangle.txt

“the NPOTS texture image lies in a [0…w]x[0…h] range.”

and issues sections 13,14:

"13) How does the handling of the R texture component differ from
the handling of S and T?

 The R texture coordinate for rectangular textures is handled
 as it would be for standard two dimensional textures.  Thus the coordinates range from [0..1] and the wrapping mode is unchanged from the default."

" 14) Does this extension work with OpenGL 1.4’s shadow mapping?
Yes. The one non-obvious allowance to support OpenGL 1.4’s shadow mapping is that the R texture coordinate wrap mode remains UNCHANGED for rectangular textures. Clamping of the R texture coordinate for rectangular textures uses the standard [0,1] interval rather than the [0,w_s] or [0,h_s] intervals as in the case of S and T. This is because R represents a depth value in the [0,1] range whether using a 2D or rectangular texture."

The other part that’s odd about this code is that the 3rd texture coordinate is crucial for shadowmap comparison, but here the 3rd coord is given by glFragCoord.z. I can not belive for a second that that’s valid for a proper shadow map.

The code is one sample called Depth Peeling in the NVIDIA OpenGL SDK. The function of this shader is to discard the fragment which fail the GL_COMPARE_R_TO_TEXTURE .it use the fragment.xy to be the texcoord , so i think fragment.x or.y can be negative value ,so can it sample the shadowmap texture correctly?

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