disable depth testing just for writing to stencil buffer?
what i want to do is add a highlighting outline around certain 3d meshes. in my opinion it makes sense for this outline to be fully visible even if the mesh itself is partially occluded.
the way i managed to achieve what i want right now:
- the mesh has a material/shader that handles its rendering, depth test is enabled, nothing is written to the stencil buffer, basically your standard shader
- in next_pass of the first material i have a shader that redraws the same mesh with alpha of 0 (so that it doesn't visually interfere with occlusion). here depth test is disabled and the shader also writes to the stencil buffer. this pass allows me to ignore depth testing JUST for the purposes of writing to the buffer.
- in next_pass of the second material i have a shader that scales the original mesh up a bit, colors it to my outline color and only draws where stencil buffer is not written to. depth test is also disabled here.
skipping step 2 gives me an xray effect which is not what i want. and not disabling depth test on the outline rendering part makes parts of the outline occluded depending on camera angle/scene composition.
i'm happy with the result i have visually, but in my understanding what i'm doing is rendering the same mesh three times to get there, which seems like a lot of extra work. is there a better way of doing this?
Posted Jun 4, 2026, 12:50 AM UTC
12