Modifying the depth values between draw calls

64 views Asked by At

I will start with the general idea of what I intend to do, my question is how to implement the actual operations on the depth buffer:

General situation There is a plane P, which separates two half-spaces A and B. The camera is in A. I have some geometry all of which needs to be rendered with depth testing. Some is contained solely in A, some solely in B and some may lie across the boundary plane P.

The goal Now I wish to render using different vertex shaders in regions A and B, though these vertex shaders behave the same on the boundary plane P. The details of this are unimportant. The following details of how I wish to draw this are the important bit.

  1. Draw into the depth buffer the depths corresponding to the plane P.
  2. With depth testing enabled and using the first vertex shader draw all triangles which intersect region A.
  3. For any depth values that haven't changed in step 2, set them to infinity, leave the rest of the buffer unchanged.
  4. Again with depth testing enabled, but this time with the second vertex shader, draw all triangles which intersect region B.

Commentary on this workflow This would give the effect I want and should be efficient because when we're drawing the geometry we're not discarding fragments or setting depths in the fragment shader. Triangles which are contained in both regions are drawn twice, once in each call, but that's unavoidable. The only time we're "breaking the rules" is in step 3, but that doesn't involve much computation at all.

Question How do I edit the depth buffer in step 3? I would like to use OpenGL ES 2.0 (WebGL).

Or Can I use a stencil buffer to achieve the same effect? If so, how?

0

There are 0 answers