Chapter 13: Direct, indirect, and environment noise
Figure 28. All sample counts are set to 8 (left). All sample counts are set to 2048 (right).
13.1 Why does this happen?
Progressive Lightmapper is a Monte Carlo path tracer. To achieve clean results, lightmapper needs to spawn many rays from each lightmap texel. Insufficient ray counts will lead to noisy lightmaps.
13.2 How to fix it?
Note: to make the process of debugging easier, in the Lighting window, set the Filtering property to None.
Increasing the number of samples will reduce lightmap noise. It will increase bake times in a linear fashion.
There are three types of sample counts: direct, indirect, and environment.
13.2.1 Increase direct samples
Figure 29. Scene lit only by direct light. Direct samples are set to 8 (left). Direct samples are set to 2048 (right).
Direct samples control the number of rays, which the lightmapper shoots towards light sources.
Increase Direct Samples if:
- Objects lit by area lights produce noisy soft shadows.
- Baked lights with a modified Baked Shadow Angle value produce noisy results.
13.2.2 Increase indirect samples
Figure 30. Scene lit only by the indirect bounce light. Indirect samples are set to 8 (left). Indirect samples are set to 2048 (right).
Indirect samples control the number of paths, which the lightmapper shoots towards the GI contributors in the scene. Once they intersect geometry, texels spawn rays towards:
- Environment, which makes it an indirect environment sample.
- A light source, which makes it an indirect lighting sample.
Paths can bounce off surfaces. There are a few ways Unity can end a path:
- Once it reaches the Max Bounces value.
- If it does not intersect any geometry.
- By the Russian roulette algorithm.
Increase Indirect Samples if:
- Indirectly lit areas are noisy.
- Objects using emissive materials produce a lot of noise.
13.2.3 Increase environment samples
Figure 31. Scene lit only by environment lighting. Environment samples are set to 8 (left). Environment samples are set to 2048 (right).
Environment samples control the number of rays, which the lightmapper shoots towards the sky/environment.
Increase Environment Samples if:
- Baked environment/HDRI produces noisy results.
- Note that you would need to disable all lights in the scene to verify this.
13.2.4 Use denoising and filtering
Achieving pristine lightmaps without using filtering would need tens of thousands of samples. Unity can apply a post-processing step to remove noise by using filtering or machine learning denoisers. To enable filtering, navigate to the Lighting window (Window > Rendering > Lighting) and select the Filtering property. There are three options:
- None. Disables filtering and denoising.
- Auto. Attempts to select the best filtering and denoising option based on current system configuration.
- Advanced. Allows users to fine-tune filtering and denoising properties.
Here are the available filters:
- Gaussian. Applies a bilateral filter (blur) to the lightmap. This may smooth-out noise, at the expense of visual fidelity. Increase radius parameters to increase filtering strength. High values can lead to leaking artifacts.
- A-Trous. Edge-aware filter which attempts to remove noise, while maintaining edge definition. Works well with high sample counts and in conjunction with denoising. Does not work well with noisy HDR lightmaps.
Here are the available machine learning denoisers:
- Open Image Denoise (OIDN). Machine learning denoiser from Intel. Vendor agnostic. Works on Windows, macOS, and Linux platforms.
- Optix. Machine learning denoiser from Nvidia. Works only with Nvidia GPUs. Supports Windows only.
- RadeonPro. Machine learning denoiser from AMD. Vendor agnostic. Works on Windows and Linux.
For best results, experiment with different denoiser and filtering combinations.