I am relatively new to GLSL and i want to do some GPGPU computing using shaders, but i’m having some problems/questions regarding depth values/lookup… i hope you can help me with it…
I am using FBO and have attachted 32bit floating point color and depth buffers:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, Width, Height, 0, GL_RGBA, GL_FLOAT, NULL);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+i, GL_TEXTURE_2D, ColorAttachmentTextures[i], 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, Width, Height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, DepthBuffer,0);
both using GL_CLAMP wrapping and GL_NEAREST filtering (min and mag).
I want to do a two pass rendering where in the first pass the depth buffer is filled with the depth values as usual and in the second pass i’d like to access these values via a sampler2Dshadow. For all tests the vertex shader only does gl_Position = ftransform();
For looking up the depth value at the current fragment position i do:
gl_FragColor = shadow2D(depthBuffer, vec3(gl_FragCoord.x/xSize,gl_FragCoord.y/ySize , 1.0));
where xSize/ySize are the number of pixels in my buffer in x-/y-direction.
QUESTION 1: What does the 3rd coordinate mean? It does not seem to have an influence on the value(s) returned by shadow2D and i don’t understand the specs.
QUESTION 2: Is the x,y position calculation gl_FragCoord.x/xSize,gl_FragCoord.y/ySize correct?
QUESTION 3: When reading back the framebuffer and depthbuffer using glReadpixels i get different results: the values in the depthbuffer are all slightly larger compared to the values in the color-framebuffer (which should have been filled with the depth-buffer values in the fragment shader). The difference always is 5.96046447753906e-008. Is this due to distinct 32-bit-floating point implementations for GL_RGBA_32F and GL_DEPTH_COMPONENT32 ? Shouldn’t both be IEEE 754?
QUESTION 4: … and a lookup-and-store-in-colorbuffer should not alter the value in any way?!
I’d greatly appreciate any help …