Recalling the basics of z-buffering and blending modes
Another essential component of a shader is how it interacts with the rest of the environment, or in other words, what kind of behavior you expect from an object using your shader. Should it always be rendered in front of the rest? Should it be visible both from the front and the back? Should it be partially transparent and mix with the background color?
This scene interaction can be separated into two parts:
- On the one hand, it is crucial to decide whether your camera should render your shader in the front or in the back – to optimize the rendering process, a clever thing to do is to check whether some opaque objects are masking others, and thus we can decide whether we can ignore the ones further away or discard all the faces that are not visible from our point of view. To do this, we can rely on the technique of z-buffering.
- On the other hand, there are still cases where you will have one or more objects...