Posts

Showing posts with the label stencil

Stencil Buffers Pt 1 - cut a hole in an object

This is quite cool stuff. You can essentially cut out areas of other objects, by using the stencil buffer There are two shaders below- one for the "hole" or the "window", the "cutter outer", whatever you wish to call it. And one for the wall or thing you're "cutting" into. The main CGPROGRAM block remains simple, the changes happen at the start of the SubShader. Firstly we ensure we draw the hole before the geometry, by giving it the Geometry-1 queue tag. The smaller the value, the sooner an object is drawn. We disable writing to the zbuffer for the whole subshader, as well as with colors (colormask 0). The stencil has it's own sub block - in it, we define Ref with the value of 1. Comp is the comparision which compares the object's pixels with Ref. We "always" want to write to the stencil buffer using our cutter object's pixels, so it "always" passes this comparison & does what the Pass operation wants - i...