I am trying to do the following
Pass 1. Render meshes to frame buffer object and set gl_FragDepth to 0 based on a certain condition. I only set COLOR_ATTACHMENT0, so depth is written to the common z buffer.
This is done so all the shader used in the next pass will not execute on pixels that I don’t want them to.
Pass 2. Render meshes to FBO. This is an expensive shader, so i’d like to limit the number of pixels. This pass also only has COLOR_ATTACHMENT0 so I assume I am still using the common depth buffer (which I haven’t cleared between the passes).
Render some other objects with tex generated in pass 2.
The problem: How do I use the depth buffer values generated in Pass 1 to ‘cull’ pixels in pass2? If I add a GL_DEPTH attachment, how can I use this texture as preset depth values in the next pass? My current setup does not seem to be doing the job. Is there a better way to cull pixels? I know texkill etc don’t really stop the pixel shader from executing.