Search Unity

Dynamic lightmapping solution

Discussion in 'General Graphics' started by Spacer429, Aug 15, 2021.

  1. Spacer429

    Spacer429

    Joined:
    Aug 9, 2018
    Posts:
    1
    Hi all,

    I'm trying to create a lighting system via URP similar to the old Thief games. I believe scenes in that game have only baked lighting, but some torches can be extinguished at runtime which then changes the lightmap.

    Currently I've got a test scene that has only 2 lights (both baked). I know how to create a lightmap per light, but I'd like to be able to manipulate those lightmaps individually (i.e., colour and intensity) at runtime. This would ideally let me do flickering effects and colour changes without a big performance hit.

    As I did research for this I found the following examples of what I'm looking for (both use Unity - the first one has a bit of an explanation but I'm not sure how to implement it). They apparently only used baked lights to achieve this:

    https://twitter.com/fusedotcore/status/1320074432568823812
    https://twitter.com/TheZombieKiller/status/1332867399868039168

    I also found a research paper that says Thief probably did it by baking lightmaps for each possible combination of torches being on/off and just assigned the correct one at runtime. I assume that's not how the above examples work because the amount of lightmaps you'd need to store would be massive.

    Appreciate that this can be done easily with real time and mixed lighting, but at this point I'm just very curious about how the above examples work. Any ideas folks?

    Cheers,
     
  2. ProfessorOliver

    ProfessorOliver

    Joined:
    Jul 2, 2021
    Posts:
    4
    They are baking a single luminosity value into each channel of the lightmap then multiplying it by a colour in the shader. The first example bakes a full colour lightmap into RGB and then uses the Alpha and a second texture for 5 additional single-channel lightmaps. The second example only has 3 lights so I assume it is using a single 3-channel lightmap.

    You can flicker and fade them as much as you want each frame and it only costs uploading a single colour vector per lightmap channel (and then the constant cost of multiplying each one out but that's pretty cheap in a shader). If each baked lightmap channel is limited to a single light source, you could even calculate a direction for normal mapping.

    You could do a similar trick with reflection probes to get a specular contribution from the baked lights.

    The obvious downside is that you lose the hue contribution of bounced light, but for a lot of scenes this is not very noticeable. And if it were important, you could bake it out per-vertex and still save a lot of memory in the lightmap.