Search Unity

Sprite Renderer no longer providing meaningful tangentToWorldAndPackedData on Flips.

Discussion in 'Shaders' started by HiddenTess, Nov 9, 2017.

  1. HiddenTess

    HiddenTess

    Joined:
    Jan 7, 2016
    Posts:
    21
    A while a go, I made a modified version of the Unity Standard Shader that could be used on sprites, so that it not only made their backfaces visible, but also corrected the math so that the normal-map did not appear to be inside-out when the sprite was flipped. This was simply a matter of multiplying the tangentToWorldAndPackedData.xyz by the facing (from VFACE or SV_IsFrontFace, depending on SHADER_TARGET).

    After a recent Unity update, we started noticing reversed normal-maps again. Frustrating! So, I did some tinkering, and determined that the tangentToWorldAndPackedData vector on the sprites is now ignoring the Flip flags, completely. This works out OK for y-flips, since they don't change the tangent, anyway, but all x-flips provide bad results.

    Here's an illustration of the problem, in case it helps anyone visualize it.
    broken-shader.png

    The colors in that image were mathematically generated from within a shader, so none of this is guesswork. As you can see, the tangent is behaving as expected for sprites that are flipped using negative scale, but it's completely ignoring the flip flags.

    Right now, I'm looking at probably having to edit a whole lot of stuff to switch from using Flip to using negative scale, and that's got me kind of unhappy. I'm curious if anyone has any insight into what happened, here, and if I should expect a "fix."