Search Unity

Can I force LIGHTMAP_ON shader keyword?

Discussion in 'General Graphics' started by RicoAlbe, Nov 26, 2021.

  1. RicoAlbe

    RicoAlbe

    Joined:
    Apr 28, 2015
    Posts:
    6
    I'm working on a mobile game with a big scene with baked lightmaps. We found some phones don't load the scene fast enough and as part of our solution is we've taken some renderers out of the scene itself and then instance them during runtime as needed.

    Of course then the prefabs don't save their lightmap info. That's ok, I can store the Lightmap ScaleOffset and Index for the renderers and set it from script. The problem is my shader is looking for the LIGHTMAP_ON keyword to choose variants, and while it gets set when I try it in my computer and even compiled in an apk, it doesn't work when I compile an aab with the renderers prefabs in asset bundles, they just en up using the shader without LIGHTMAP_ON.

    I've worked around it by creating a new material in runtime with the keyword defined and applying it to the lightmapped renderers. But the question remains when is LIGHTMAP_ON keyword defined? it's supposed to be set automatically for all renderers with a lightmapIndex different to -1, as I understand it, but what can I force it if it's not happening? How does Unity set a shader keyword per-renderer? is it allowed for us users or is it some special magic?
     
    Last edited: Nov 26, 2021
  2. sewy

    sewy

    Joined:
    Oct 11, 2015
    Posts:
    150
    Have you found a solution/work around for this? I would need it for combined meshes as I handle my LM UVs myself (I know that CombineMeshes have LM parameters, but it clears up my Vector and Color data used for texture array indicing set on the meshes). I dont want to force the shader to always use LIGHTMAP_ON.
     
  3. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    727
    For us what works is to just turn off light probe usage, set the lightmap index to -1, and use EnableKeyword on the material