Hi all,
We were facing a very strange issue where, when camera move far enough away from objects, they become whiteout. I saw a few threads on this but no one were able to identify exactly where it went wrong.
We eventually narrow this issue down to the way ViewDirection is being normalized, we used SafeNormalize instead of normalize. And it causes ViewDirection to become zero (0.0, 0.0, 0.0) in some cases.
We tried this with Xcode shader debugger, and can see iOS Metal outputting very different results for normalize and SafeNormalize, given the same ViewDirection input.
And remember that ViewDirection we pass from vertex to fragment is not a direction per se, it’s the actual distance between camera and vertex position. So I suspect it has something to do with float/half precision (SafeNormalize compile to half precision for mobile platforms).
(But unfortunately we were not able to reproduce the same issue on desktop GPU using half precision; so we don’t know if this is hardware independent.)
In short, try normalize() first where you can, SafeNormalize() isn’t safe when you can have potentially large input (any value in the hundreds can trigger it due to dot product, see unity shader precision doc).
Thx for reading