Search Unity

Subtractive lighting DLDR encoding still gives incorrect results in editor and on device.

Discussion in 'Global Illumination' started by Arycama, May 31, 2019.

  1. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    184
    I have seen this issue pop up a few times, and it was usually due to people having very bright light intensities. However I have my directional light set to an intensity of 0.5, and my ambient light is a grey color set to 0.75.

    Lightmapping with DLDR encoding is supposed to be able to encode a range of 0-2. The sum of my lights would be 1.25, so the lighting should never exceed the value of 2. Even if it did, I assume the result would just be clipped at white, rather than the entire lightmap losing intensity.

    However, the end result is a lightmap which is substantially lacking in both brightness and contrast, compared to a non-baked version. I can't think of any technical reason why it should not be possible to encode the original lighting in a DLDR lightmap. Manually modifying the shader code does not seem to be able to give me correct results either. This project is in gamma space, however any mobile project using subtractive lightmapping is probably doing it to save as much performance as possible, so suggesting that I should be using linear is not an acceptable solution.

    The way that Unity encodes the lightmap when your platform is set to mobile, with gamma space must be incorrect. I have tested in editor and on device, and both give the same incorrect results.

    For reference, here are two screenshots, one with realtime lighting + shadows using the legacy diffuse terrain shader, and one with subtrative lightmapping:

    (Note that the trees are not lightmapped. This highlights another issue: Realtime and baked objects sharing the same mixed directional light will have noticeably different intensities, requiring the use of a second light to match them)

    Realtime lighting + shadows:
    upload_2019-5-31_12-13-46.png

    Subtractive lightmapping:
    upload_2019-5-31_12-13-22.png
     
  2. kristijonas_unity

    kristijonas_unity

    Unity Technologies

    Joined:
    Feb 8, 2018
    Posts:
    1,080
    Realtime and baked lighting is hardly comparable - especially when using fully baked lights. In your second screenshot, you are lacking any specular response, since subtractive light mode does bakes direct lighting into the lightmap.

    If you want to achieve a look that is similar to your first screenshot, you'd have to resort to baked indirect or shadowmask modes + mixed directional lights.
     
  3. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    184
    The first screenshot is using a custom shader which is only a per-vertex diffuse, with no specular, or normal mapping. (The ambient light is also a flat color)

    It seems like Unity is getting the encoding wrong, or doing some magic in the background which makes a baked diffuse result not match the realtime diffuse result.
     
  4. uy3d

    uy3d

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    187
    What result do you get with your custom shader if you divide the result by PI (3.1416.....)?
     
  5. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    184
    Dividing the result by PI makes everything dark, as expected. (Undivided result below for reference) I also tried multiplying by PI which makes everything very bright (Eg saturated to 1). I have also checked with mobile diffuse shader which gives a visually identical (incorrect) result to my custom shader in subtractive mode.

    Divided
    upload_2019-6-4_9-25-6.png upload_2019-6-4_9-25-57.png