1

Target: OpenGL ES >= 3.0

My app:

1) creates several complicated Meshes 
2) for each Mesh, renders it:   
  a) runs vertex shader which distorts the Mesh' vertices in nontrivial ways    
  b) nothing special in fragment shader

3) Again for each Mesh:    
  a) postprocess the area taken by it

Now, in order for postprocessing to be efficient, I call glScissor and make only the smallest rectangle containing the Mesh pass the Scissor test. In order to do that, I need to know the bounding rectangle, and to compute that, I need to know the Mesh

   a) leftmost
   b) rightmost
   c) topmost
   d) bottom-most

vertices in window coordinates. It wouldn't be such a big problem if not for the Vertex Shader which distorts the Mesh' vertices (step 2a above).

I deal with that by setting up Transform Feedback so that after step 2, I have the transformed vertices in CPU. I then compute the leftmost- (and the 3 others) one by simply one loop though all of them.

There are hundreds of thousands of vertices though and I was thinking if this job couldn't be done by the Vertex Shader itself.

Question: can a Vertex Shader - one which modifies the vertices positions - figure out the leftmost one and only pass me back it (and the 3 other 'extreme' vertices) ?

Leszek
  • 1,181
  • 1
  • 10
  • 21
  • 1
    Suggestion: use the stencil buffer instead. Configure the stencil state to write '1' in the stencil when you render your distorted mesh and when you render the post effect, configure the stencil state to only process the fragments for which stencil value is '1'. Like that your complex postprocess fragment shader will only apply to the pixels of your mesh (so better that a scissor) – VB_overflow May 11 '17 at 09:03
  • Yes, I thought about that, there's one issue though (unmentioned by the original question): the area marked for postprocessing must actually be a bit larger than the Mesh (must include a halo around it). I actually compute the 4 'extreme' vertices and add a configurable margin. – Leszek May 11 '17 at 09:20
  • But then again, you're right: I could forget about my initial Transform Feedback stage, and rather than that, have a initial 'preparation' stage which switches off color/depth writing, sets up stencil to write 1 like you say, and render the Mesh enlarged by N% ! – Leszek May 11 '17 at 10:08
  • Yes, looks like a good idea, and one benefit from this is that you can do the post process in only a single pass (instead of multiple passes with scissors, one pass per object) – VB_overflow May 11 '17 at 10:40

0 Answers0