Here are my GLSL shaders:
Vertex shader
uniform mat4 worldViewProjMat;
attribute vec3 vertPos;
void main(void) {
gl_Position = worldViewProjMat * vec4(vertPos,1);
}
Pixel shader
void main(void) {
discard;
}
I am quite sure this is not how I should render to the depth buffer. Can anyone enlighten me as to what should the fragment do in the later case as I do not want any color output.
I tweaked my pixel shader a bit to do:
void main(void) {
gl_FragDepth = 0.5;
}
This rendered the scene as expected with the common depth value in the depth buffer (in other words, it showed up some gray pixels, the outline of the geometry I was rendering from light view point).
What I do not understand is if automatic depth test and depth write should write those depth values to the texture anyway why am I getting a value of 1.0f in all cases except when I am explicitly outputting the depth value from frag program.
I certainly do not plan to output depth value from fragment program nor compare the values and loose all optimization for Early Z or Hierachical Z outs.
I even adjusted the near and the far planes (400 units apart), but still outputs white.
EDIT:
One of my mistakes was using 'discard' which disables depth write/test. So my pixel shader now looks like:
void main(void) {
// do nothing???
}
Thanks for reading,
obhi