Implementing a Glass Shader
Glass is a very complicated material; it should not be a surprise that other recipes have already created shaders to simulate it, such as in the Adding transparency to PBR recipe of Chapter 6, Physically Based Rendering. We already know how to make our glasses semi-transparent to show the objects behind them perfectly, and this works for several applications. However, most glasses are not perfect. For instance, if you look through a stained glass window, you may notice distortions or deformations. This recipe will teach you how to achieve that effect. The idea behind this effect is to use a Vertex and Fragment Shader with a GrabPass
, and then sample the grab texture by changing its UV data to create a distortion. You can see this effect in the following screenshot. Here, we used the glass-stained textures from Unity's Standard Assets:
Getting ready
The setup...