I realize this is six years later, so please forgive me. I just had a question regarding the phase change calculation. The code is such:
// compute the phase change term (constant)
const float d10 = (n1 > n0) ? 0 : PI;
const float d12 = (n1 > n2) ? 0 : PI;
const float delta = d10 + d12;
shouldn't the d10 calculation be:
const float d10 = (n0 > n1) ? 0 : PI;
If I understand correctly, there is a 180 degree shift if the second medium is denser than the first, which the d12 calculation conforms to, but not the d10 calculation.