Posts

Showing posts with the label stencil buffer

Stencil Buffers pt2 - object that only appears behind certain "glass"

More or less the same as what happened in the last post about stencil buffers - the few lines with Enums are useful - they "enumerate" - put all the functions into a drop down list in the Inspector for us. So we store these in variables - _SComp and _SOp. Notice the values are just numbers, as they are just entries in a list/array. A trick in the tutorial i watched was having an object only appear behind a certain "pane of glass" - or quad. The quad holds the stencil window shader and faces the object (so it faces away from the camera), and the SComp is set to always, the SOp is set to Replace. The trick is that both the object and glass have the same ref numbers, so if you had another pane of glass with a different ref number, the object does not appear behind it. The object's shader beneath, has a bump and albedo in it. Set the SComp to Equal (different to the last example we did) and the SOp to Keep.   Shader "Dave/stencilwindow" {     Properties{  ...

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...