Search Unity

Lightmaps in Vertex-Lit shader

Discussion in 'Shaders' started by uwdlg, Aug 7, 2020.

  1. uwdlg

    uwdlg

    Joined:
    Jan 16, 2017
    Posts:
    150
    Hi,

    is it possible to sample lightmaps in a custom vertex-lit shader with
    "LightMode" = "Vertex"
    ?
    What I tried so far is adding a TEXCOORD1 float2 to both the appdata and v2f structs, calculating
    o.lmuv = v.lmuv.xy * unity_LightmapST.xy + unity_LightmapST.zw;
    in the vertex shader and sampling the lightmap with
    DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.lmuv));
    in the fragment shader. This however makes objects render as if they were fully transparent, even if I just return the DecodeLightmap result in the fragment shader. Is there some way to get Lightmaps to work with Vertex Lighting (without it my custom lighting breaks)?
     
  2. uwdlg

    uwdlg

    Joined:
    Jan 16, 2017
    Posts:
    150
    Found the answer myself: it's
    "LightMode" = "VertexLM"
    .
    Is there a nicer way to have a shader handle the cases with and without a lightmap other than having Vertex and VertexLM LightMode passes with the same contents except for the lightmap part?