Mathematical formula of Vector Refraction?

And for the sake of precision, I’d like to note that, while the formulas you’ve used on both posts are correct (the first one assumes the normal and the incident vectors have the same “overall direction”: the normal “points downwards” from the surface, thus (n · i) >= 0; the second one assumes the opposite, the normal “pointing upwards” from the medium interface), the usual convention in physics is the one you’ve used in the second image: if the normal vector is (2,2,0), the incident vector must be coming “from above”, (-2,-2,-2).

Since — as far as I can see, given the second convention — the formula is meaningless if the normal and incident vector have the same “overall direction” (as the incident ray would be coming from inside the surface it wants to enter), it might be a good idea to think of the normal vector as an “undirected vector”, and adjust its sign during the calculations to always make sure that (n · i) <= 0. This would prevent users from making meaningless calculations, and from having to guess which convention is used with regards to the direction of the normal. On the other hand, this behaviour might be slightly unexpected, and some users may find the “impossible angles” useful (?) for some arcane stuff.

What do you think? I’ll ask the blender devs as well.

1 Like