This is Jim Craighead’s code. Ripped straight from Studio…
This basically computes a fresnel reflection coeficient.
It could probably use some optimization, but the trig identities are left as an exercise for the masochistic.
Also note that this is reasonably accurate for refractive indices greater than 1, but a complete hack for smaller values.
There are still problems with values below 0.6 such as Gold and Silver.