Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Progressive Lightmapper not baking correct emission from vertex colors

Discussion in 'Global Illumination' started by Saxy_Guy, Oct 10, 2018.

  1. Saxy_Guy

    Saxy_Guy

    Joined:
    Nov 27, 2013
    Posts:
    34
    I've got a modified version of the lightweight PBR shader, the only difference from the normal shader being that it passes the vertex colors to the emission output (both for lit and meta passes), to save draw calls for multiple objects. It works fine in-scene and bakes fine with Enlighten, but for some reason when I try to bake using the Progressive Lightmapper, it seems to arbitrarily pick one of the mesh's colors and use it for other meshes, even if they aren't the same color.

    Enlighten:


    Progressive:


    Anyone have an idea as to what might be causing this?
     
  2. JenniferNordwall

    JenniferNordwall

    Unity Technologies

    Joined:
    Sep 19, 2016
    Posts:
    160
    Hi

    Are you using GPU instancing? And if you were to disable it, would it solve the issue? If so, please report a bug to us :)

    Cheers,

    Jennifer Nordwall
    Lighting team, Unity
     
  3. Saxy_Guy

    Saxy_Guy

    Joined:
    Nov 27, 2013
    Posts:
    34
    I'm not using GPU instancing for the emitting meshes nor the floor as ideally everything is statically batched, however I think I may have found the issue.

    I'm generating the different colored meshes at by copying the vertices/uvs from a template mesh of each type, and changing the vertex colors as required:

    Code (CSharp):
    1. private Mesh GetColoredMesh(Mesh baseMesh, Color color)
    2. {
    3.     Mesh newMesh = new Mesh
    4.     {
    5.         vertices = baseMesh.vertices,
    6.         triangles = baseMesh.triangles,
    7.         normals = baseMesh.normals,
    8.         tangents = baseMesh.tangents,
    9.         bounds = baseMesh.bounds,
    10.         uv = baseMesh.uv,
    11.         uv2 = baseMesh.uv2
    12.     };
    13.        
    14.     List<Color> colors = new List<Color>(baseMesh.vertices.Length);
    15.  
    16.     for (int i = 0; i < baseMesh.vertices.Length; i++)
    17.     {
    18.         colors.Add(color);
    19.     }
    20.  
    21.     newMesh.SetColors(colors);
    22.  
    23.     return newMesh;
    24. }
    However, if I modify the position of a single vertex for each color needed, the issue completely goes away.

    My best guess is that maybe the Progressive Lightmapper is doing some caching, but only checking the positions and uv0s of each mesh, thus missing that each mesh has different vertex colors?

    In any case, moving the position by a tiny random value does the trick and is so far unnoticeable :)
     
  4. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    Please have a look at the baked emission scene view mode and post a screenshot here. I think all three objects are all using the same color so emitted light comes out wrong.

    https://docs.unity3d.com/Manual/GIVis.html

    I did fix an issue in 2019.1.0a1 about material property blocks and GI but this could be something else.