Search code examples
openglglslshaderlwjgl

LWJGL 3 - Clipping mask


For drawing, I am using VAOs with glDrawElements and GLSL 3.30.

Imagine you have two objects (image below), the cyan one is the mask, and the red circle is the object to be clipped. All other objects aren't affected by the mask.

Only the part inside the cyan is showing on the screen.

What would be the most effective way to make this in real-time (no alpha maps), so it could be animated?


Solution

  • You could use the stencil test. Essentially you render the mask first writing a specific stencil values, then you render the red circle only where you do not have those values.

    Some good resources: