Stencil buffer manipulation

Author: Gmod4phunCreated Dec 21, 2024Updated Sep 24, 2026

What can't you do?

Currently, you can't manipulate the stencil buffer from the C# side, only from a shader. This is pretty limiting as it requires custom shaders to be created for specific effects for the stencil masks and occluders (for example 'impossible space' aka 'bigger on the inside').

How would you like it to work?

Most likely as part of the existing Graphics library, with various operations regarding the stencil buffer. GMod has this as part of its render library, allowing you to manipulate the stencil buffer and render various stuff as needed.

Image

This would allow us to to do this inside of a rendering context:

1. Setup stencil state for mask
2. Draw mask
3. Setup stencil state for occluder
4. Draw the other thing

What have you tried?

Using two custom shaders, one for the stencil mask and the other for the object to be rendered. Works for simple things, but not compatible with existing assets.

Additional context

No response