How it works...

Both shaders are quite similar to the shaders in the previous recipe.

The vertex shader computes the position, normal, and view direction in world coordinates (worldPos, worldNorm, and worldView). They are then used to compute the reflected direction using the reflect function, and the result is stored in the output variable ReflectDir. The transmitted direction is computed using the built-in function refract (which requires the ratio of the indices of refraction Material.Eta). This function makes use of Snell's law to compute the direction of the transmitted vector, which is then stored in the output variable RefractDir.

In the fragment shader, we use the two vectors ReflectDir and RefractDir to access the cube map texture. The color retrieved by the reflected ray is stored in reflectColor and the color retrieved by the transmitted ray is stored in refractColor. We then mix those two colors together based on the value of Material.ReflectionFactor. The result is a mixture between the color of the reflected ray and the color of the transmitted ray.

The following image shows the teapot rendered with 10 percent reflection and 90 percent refraction (Cubemap © Paul Debevec):

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.15.94