Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice

Strange result from specific configuration: Perspective Camera + Normal Map + Rotated Sprite

Discussion in '2D Experimental Preview' started by Jamez0r, Feb 5, 2021.

  1. Jamez0r

    Jamez0r

    Joined:
    Jul 29, 2019
    Posts:
    189
    Figured I'd post about this in case anyone else runs into the same issue. Took me a couple hours to figure out what was going on here :eek: I'm not sure if its a bug or not.

    The issue:
    The normalmap for this Player character would become 'offset' seemingly randomly:




    The setup:
    1) Project is using a Perspective camera (so we can parallax easily).
    2) A Light2D as Point Light with Use Normal Map selected (its positioned near the Player's feet in the screenshot)
    2) A big grass-sprite that is underneath the Player. It is rotated on the X-axis.
    3) The Player character who has a normal-map on top of the grass. Nothing rotated or anything abnormal with this.



    I had accidentally rotated the grass-sprite beneath the character. If you are using a Perspective camera, with the 2D Lights, with Normal Maps, then rotating a sprite on the X or Y axis causes the normal-map to become offset/skewed. Here is the Frame Debugger at the step where the rotated-grass sprite was drawn:



    Another thing worth noting is that a similar behavior (normal-maps becoming 'offset') happens if your Perspective Camera itself rotates on the X or Y axis. I don't imagine anyone should be rotating the camera like that for a 2D game, but just wanted to mention it - if you accidentally let the camera get rotated even a little bit, everything with the Lights will get out of whack (at least if you're using normal-maps).

    Hoping that the "Use Normal Map" part of the 2D Lights system gets a little TLC - there are a couple weird behaviours with it, such as the "Distance" value affecting falloff, etc.
     
unityunity