Total Internal Reflection

TIR is a physical phenomonon when light tries to pass from a dense medium to a less-dense medium at too shallow an angle. The result is that the light glances off the interface between the media, and is specularly reflected instead of transmitted. At this point we just compute specular reflection.

When the expression under the radical in the T calculation is negative then we have reached the critical angle.