// https://seblagarde.wordpress.com/2013/04/29/memo-on-fresnel-equations/ public static RgbColor Evaluate(float cosThetaI, RgbColor etai, RgbColor etat, RgbColor k) { cosThetaI = Math.Clamp(cosThetaI, -1, 1); RgbColor eta = etat / etai; RgbColor etak = k / etai; float cosThetaI2 = cosThetaI * cosThetaI; float sinThetaI2 = 1 - cosThetaI2; RgbColor eta2 = eta * eta; RgbColor etak2 = etak * etak; RgbColor t0 = eta2 - etak2 - sinThetaI2; RgbColor a2plusb2 = RgbColor.Sqrt(t0 * t0 + 4 * eta2 * etak2); RgbColor t1 = a2plusb2 + cosThetaI2; RgbColor a = RgbColor.Sqrt(0.5f * (a2plusb2 + t0)); RgbColor t2 = 2 * cosThetaI * a; RgbColor Rs = (t1 - t2) / (t1 + t2); RgbColor t3 = cosThetaI2 * a2plusb2 + sinThetaI2 * sinThetaI2; RgbColor t4 = t2 * sinThetaI2; RgbColor Rp = Rs * (t3 - t4) / (t3 + t4); return(0.5f * (Rp + Rs)); }