Search Unity

Negative Scale in Prefab Flips the Lighting Normals in Play Mode?

Discussion in 'High Definition Render Pipeline' started by Goatogrammetry, Jul 6, 2021.

  1. Goatogrammetry

    Goatogrammetry

    Joined:
    Apr 27, 2017
    Posts:
    197
    Here you see two copies of the same mesh, the left one is -1 in the X scale.

    The correct frame in the animation is from the editor (looks the same in the scene or game window)
    The bad frame is in "Play" mode.

    Obviously the normal map or the mesh normals or something related to that is getting reversed but only in "Play" mode.

    This is a 2 week old fresh install of HDRP 2020.3LTS. I think its a massive, critical issue that probably should not have made it this far into 2021 in an LTS version (Even if its fixed in newer versions, LTS is LTS). I have no idea if this is a shader issue or if this is happening deeper in the engine, but the shader is just the ordinary HDRP Lit default, no tricks.

    negative.gif

    Pretty ugly but I bet its an easy fix. God help me but I'm a few hours from releasing an update to my asset pack and this is what people are going to see. I can sense the bad reviews rolling in already even if its not my fault. The mesh and textures and shader check-out. Nothing fishy going on with the import.

    Does anyone know whats up? Unity guys? What do?
     
    Ghost_Pig likes this.
  2. Ghost_Pig

    Ghost_Pig

    Joined:
    Nov 30, 2017
    Posts:
    6
    I am so glad I am not the only one with that problem! I've been searching for hours for errors in my normal map, mesh normals, export settings, UV coordinates ... Turns out it is just unity.
    In the meantime I ran a couple of tests:

    Same problem in Unity 2021.1.22f1, HDRP version 11.0.0, 2019.4 LTS URP and Unity 2018.4.28f1 standard renderer.

    Scene view - fine
    game view (before I hit play) - fine
    Game view (as soon as I hit play) - broken

    a model with a negative scale value - fine
    a model as a child of an object with a negative scale value - fine
    a prefab with a negative scale value - broken
    a prefab with a positive scale value, but the model within the prefab has a negative scale value - fine
    a prefab with a positive scale value as a child of an object with a negative scale value - broken


    That means there is no way to mirror a prefab, or am I missing something? How did nobody ever notice this?
    Are we supposed to create a new prefab for each mirrored version of a model? That would be incredibly annoying.
     
    Last edited: Sep 30, 2021
    Goatogrammetry likes this.
  3. Ghost_Pig

    Ghost_Pig

    Joined:
    Nov 30, 2017
    Posts:
    6
  4. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    703
    Hello, thanks for reporting.
    I might look at it closer, but first a question : Is static batching enabled ?
     
  5. Goatogrammetry

    Goatogrammetry

    Joined:
    Apr 27, 2017
    Posts:
    197
    Yeah its in static meshes for sure.
     
  6. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    703
    So, I'll double check on my side, but this might be expected then :/
    Static batching will try to merge static meshes together (literally bake multiple meshes together in a single one), and in the case of meshes with a negative scale, this can result in a normal flip.
     
  7. Goatogrammetry

    Goatogrammetry

    Joined:
    Apr 27, 2017
    Posts:
    197
    Then dont include them in the same batch. But flipping objects is more important than one batch or state-change more or less. Dont shrug this off. Its very very serious for level designers and artists and it MUST be possible to flip stuff. If the batching is doing this, and it sounds like it is the case, then a quick edit to the sorting and sifting of batches and its fixed! Till then, I assure you there are people rage-quitting every single day after they discover the map that looked so good in the editor looks like poop in play mode.
     
    Last edited: Nov 27, 2021
    Deleted User likes this.
  8. Ghost_Pig

    Ghost_Pig

    Joined:
    Nov 30, 2017
    Posts:
    6
    You are right, static batching is the cause of this. While I don't fully understand how that is the explanation (shouldn't vertex normals get messed up as well then, not just the normal map?) I am very grateful for the information! At least I can prevent it from happening now :)