SurfaceOutput.viewDir not the same in deferred

I have a surface shader that I’m trying to get Fresnel working on and I’m getting strange results in Deferred rendering rather than Forward (forward looks correct). Seems to be related to the value of viewDir.

Here’s the code I’m using for the Fresnel effect;

half fresnel = pow(1.0f - saturate(dot(IN.viewDir, N)), _Fresnel);

I see the same result in Skyshop’s materials as well.

Anyone know how to get around this?

I noticed the same issue. It seems viewDir is not set correctly during deferred rendering.

My current simple workaround is to replace “IN.viewDir” with “(_WorldSpaceCameraPos - IN.worldPos)”.

Of course you do have to make sure that worldPos is specified in your input structure.