Search code examples
unity-game-enginemappingshadervertexlight

Unity - Vertex light ignored by static objects (lightmapped)


Vertex lights work fine on dynamic objects, but the second I make them static and bake lightmaps they're ignored.

I've tried changing to different "lightmodes" within the shader, but none has worked. Lightmode "ForwardBase" seems to really mess up, even though I would assume its the one to use given its description on https://docs.unity3d.com/Manual/SL-PassTags.html

Any suggestions would be very appreciated :)


Solution

  • My understanding of the question at hand

    As I understand, when you bake a lightmap, the only light source that will change the light of the baked objects is a pixel light. But you would like to make it work with a vertex light.

    I'm still not entirely sure whether you mean that the light simply won't bake into the baked map in the first place, or whether it cannot affect the light level of the object after it has been baked.

    In any case, I did some searching.

    Possible solution/explanation 1

    When I searched I came across this tool and description.

    https://assetstore.unity.com/packages/vfx/shaders/vertex-lit-shader-baked-shadows-realtime-light-75977

    By default, using Unity’s built-in shader Mobile/VertexLit lighting works only as either baked or realtime but you cannot display a realtime light on a baked surface. This shader allows a baked surface to also receive realtime lighting.

    Note that the tool is free.


    Possible solution/explanation 2

    I also came across this tutorial: https://catlikecoding.com/unity/tutorials/rendering/part-16/

    Where the author writes

    When lightmaps are used, Unity will never include vertex lights. Their keywords are mutually exclusive. So we don't need a variant with both VERTEXLIGHT_ON and LIGHTMAP_ON at the same time.

    Lastly please note that these solutions seem to be developed at earlier versions of Unity. Newer solutions more appropriate may exist.

    Hope this helps you.