Skip to main content
edited tags
Link
Nicol Bolas
  • 26.1k
  • 3
  • 78
  • 104
Source Link
Martin Perry
  • 1.1k
  • 1
  • 14
  • 29

GLSL - Stencil buffer - instanced geometry

I have geometry that have attached some "ID" data. I have generated stencil buffer, that holds these IDs. Now, in second pass, I render different geometry, but this time I need to mask it with already existing stencil. Each part of geometry can have different "ID". Is there a way, how to control stencil buffer test value from shader?

I give an example:

  1. render geometry with ID = 1, writes 1 to stencil
  2. render geometry with ID = 2 if ID in stencil != 1, writes 2 to stencil
  3. do some other rendering with stencil turn off
  4. render bunch of particles at one go, but some of them have ID 1, some of them ID 2 -> I want to mask them, so 1 is rendered only if 1 is in stencil and 2 only if 2 is in stencil

I need this for OpenGL ES 2.0