karx11erx
11-21-2007, 05:59 AM
I have copied the depth buffer to a depth texture using the following code:
glGenTextures (1, &hDepthBuffer);
glBindTexture (GL_TEXTURE_2D, hDepthBuffer);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D (GL_TEXTURE_2D, 0, 1, <width>, <height>, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glCopyTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, <width>, <height>, 0);
How do I access depth values from that texture in a GLSL shader?
My shader looks like this:
uniform sampler2DShadow depthTex;
void main (void)
{
float depth = shadow2D (depthTex, gl_FragCoord.xy).x;
}
Is that correct?
Is there anything I have to regard (I have read something about a texture compare mode)?
glGenTextures (1, &hDepthBuffer);
glBindTexture (GL_TEXTURE_2D, hDepthBuffer);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D (GL_TEXTURE_2D, 0, 1, <width>, <height>, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glCopyTexImage2D (GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, <width>, <height>, 0);
How do I access depth values from that texture in a GLSL shader?
My shader looks like this:
uniform sampler2DShadow depthTex;
void main (void)
{
float depth = shadow2D (depthTex, gl_FragCoord.xy).x;
}
Is that correct?
Is there anything I have to regard (I have read something about a texture compare mode)?