Search Unity

Confusion about new Lightmap parameters

Discussion in 'General Graphics' started by Kolyasisan, May 23, 2019.

  1. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    Starting from 2019.1 some new lightmap parameters showed up in the Lighting window, mainly Environment Samples and Multiple Importance Sampling. So far I can't understand them at all (the wording is a bit confusing) and I've noticed that now lightmapping takes exponentially more time to complete while giving far, far worse results than in 2018.3. As such I would've liked to ask for clarification what exactly Environment Samples are, how they differ from Indirect Samples and get clarification how Environment Samples and Multiple Importance Sampling were used in 2018.3 (in case if they were always present, but internally).
     
  2. uy3d

    uy3d

    Unity Technologies

    Joined:
    Aug 16, 2016
    Posts:
    187
    The environment used to be sampled as part of the indirect samples. Everytime an indirect ray was shot from a lightmap texel, or bounced off a surface, and didn't hit anything, the environment was evaluated. The problem with this approach is that high frequency environment maps would lead to a lot of noise due to undersampling.
    With the latest changes the first difference is that environment sampling has been split into direct and indirect environment sampling. Direct environment sampling is controlled via the new sampling parameter in the UI and determines how many occlusion rays are shot into the environment from a lightmap texel. If you have noise coming from the parts of the environment that are directly visible by a lightmap texel, increasing this sample value will give better results.
    For indirect rays, everytime the ray bounces off a surface, an additional environment occlusion ray is also shot. This also means that if you are getting noise from the environment via bounce lighting, you have to increase the indirect sample count to get better results. Increasing "Environment Samples" in the UI will not make a difference in this case. So whereas before, for one indirect sample, you could get at most one sample of environment contribution, with the latest changes you get an environment ray at each bounce plus the environment rays spawned directly at the lightmap texel.

    The second difference is how the directions for the environment rays are determined. Before, the ray direction was more or less a random direction from the hemisphere. This works alright when the environment map has low frequencies in it, but breaks down with high frequencies (think HDR map with a small bright spot for the sun at the horizon). When enabling MIS, we analyze the environment map and find spots of high influence in it. When generating the ray directions, we alternate between either picking a random direction like before, or picking a direction from the pre-calculated points.
    MIS works best for high frequency environments, but will produce noisier results, the smoother the environment gets. The worst case is an environment of uniform color.
     
  3. Kolyasisan

    Kolyasisan

    Joined:
    Feb 2, 2015
    Posts:
    397
    Thank you very much for clarification.
     
  4. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,741
    Does that mean that if my environment is just a single color, I can keep the Environment Samples value way too low (like.... 8?) and still get good results? Or will that give me noise in "the first bounce" from the environment?