CG ddy function returning negated vector in game view. Macro to check?

I have a pretty simple pixel shader that calculates the face normal by relying on the ddx and ddy CG functions. Pretty straight forward.

float3 normal = -normalize(cross(ddx(i.position), ddy(i.position)));

This worked out very well in the scene view but I get the negated normal in game view.

The normal is inverted! I realized that this was due to the ddy function. If I just output the result of the ddy function (multiplied by 200) I get the following result.

So I’m pretty sure that’s what’s causing the problem (the ddx result is consistent for both the game and screen view). My question is if there’s a macro or something I can check for? It looks like maybe the screen y is flipped? I tried using UNITY_UV_STARTS_AT_TOP but it didn’t solve this issue.

Thanks!

  • _ProjectionParams.x
1 Like

I started looking into checking the projection matrix to use that to see if it flips it or not but this is nicer :slight_smile: Thanks!