Fresnel effect does not work with orthographic cameras.

I’ve been trying to implement this shader on Unity 2019.2.16f1.

But I couldn’t make it work. I tried several possibilities, but it only worked after I changed the camera’s projection from orthographic to perspective.

Please post the relevant information, I don’t want to waste 16 minutes watching a video.

But taking a shot in the dark judging from that thumbnail, it’s not the fresnel effect that’s problematic, I’m guessing he uses some sort of depth value, which won’t work since with orthographic supposedly everything is an infinity away.

Edit: Nevermind, read bgolus’ answer below.

No. The depth is fine with an orthographic camera. It’s actually simpler than a perspective camera because it’s just linear 0.0 to 1.0 from the near to the far plane.

The problem with fresnel is it’s doing a dot product between the the surface normal and the “view direction”. The view direction being a normalized vector from the surface position to the camera position. For perspective cameras this is correct. For orthographic cameras this is wrong.
5358780--541689--upload_2020-1-10_16-36-29.jpg

For orthographic cameras you want a dot product between the normal and the forward view vector. The easiest way to do that is by converting the normal into view space and using a constant Vector3(0,0,1) for the view dir.
5358780--541692--upload_2020-1-10_16-36-57.jpg

Alternatively, extract the forward view vector from the inverse view matrix.
5358780--541695--upload_2020-1-10_16-39-8.png

13 Likes

I should also probably clarify my “depth is fine” comment. The way depth comparisons are done in Shader Graph (like as shown in the Brackey’s video linked above) won’t work with an orthographic camera either. Unity’s Scene Depth node also assumes a perspective camera when decoding the depth buffer, which means it’ll output the wrong value when using an orthographic camera. Similarly the use of the Position node’s Raw “A” won’t work because the “A” is always 1.0 in a perspective camera.

So instead you need to do something like this.

13 Likes

Ok… you are right!.. Thank you for the so complete explanation!

1 Like