Skip to content

Commit cfbda5e

Browse files
Dynamic Ambient improvement and doc update (#5951)
* Avoided unnecessary ambient probe updates Updated doc with dynamic ambient probe limitations * Update Environment-Lighting.md Co-authored-by: sebastienlagarde <[email protected]>
1 parent d323a87 commit cfbda5e

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

com.unity.render-pipelines.high-definition/Documentation~/Environment-Lighting.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ In the High Definition Render Pipeline (HDRP), there are two parts to environmen
99
Essentially, you use the visual environment to control how the sky looks in your Scene and use the lighting environment to control how the sky contributes to indirect ambient lighting.
1010

1111
## Visual Environment
12-
The Visual Environment is a Volume override that tells HDRP what type of [sky](HDRP-Features.md#sky) and [fog](HDRP-Features.md#fog) you want to see through Cameras that the Volume affects. For information on how to customize Visual Environments, see the [Visual Environment](Override-Visual-Environment.md) documentation.
12+
The Visual Environment is a Volume override that tells HDRP what type of [sky](HDRP-Features.md#sky) you want to see through Cameras that the Volume affects. For information on how to customize Visual Environments, see the [Visual Environment](Override-Visual-Environment.md) documentation.
1313

1414
Your Unity Project’s [HDRP Asset](HDRP-Asset.md) has the following properties that also affect all Visual Environments:
1515

@@ -66,7 +66,15 @@ HDRP uses the ambient Light Probe as the final fallback for indirect diffuse lig
6666
- Mesh Renderers that have their **Light Probe Mode** set to **Off**
6767
- Volumetric fog if the Global Light Probe dimmer is set to a value above 0
6868

69-
The ambient Light Probe can be static (generated only once) or dynamic (updated at runtime).**Note**: If there is a **Light Probe group** in your Scene and you have computed indirect ambient lighting, then the Ambient Light Probe only affects Mesh Renderers that have their **Light Probe Mode** set to **Off**, and that have **Volumetric fog** (if it’s enabled in the Scene).
69+
The ambient Light Probe can be static (generated only once from the static lighting sky set in the HDRP **Environment (HDRP)**panel) or dynamic (updated at runtime from the sky currently in use).
70+
71+
***\*Note\****: If there is a ***\*Light Probe group\**** in your Scene and you have computed indirect ambient lighting, then the Ambient Light Probe only affects Mesh Renderers that have their ***\*Light Probe Mode\**** set to ***\*Off\****, and that have ***\*Volumetric fog\**** (if it’s enabled in the Scene).
72+
73+
### Limitation of Dynamic Ambient mode
74+
75+
The Ambient Light Probe always affects your scene one frame late after HDRP calculates it. This is because HDRP calculates Ambient Light Probes on the GPU and then uses asynchronous readback on the CPU.
76+
77+
As a result, the ambient lighting might not match the actual lighting and cause visual artifacts. This can happen when you use the dynamic ambient mode and use reflection probes that update on demand.
7078

7179
## Ambient Reflection Probe
7280

com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ struct CachedSkyContext
101101

102102
public void Reset()
103103
{
104-
// We keep around the renderer and the rendering context to avoid useless allocation if they get reused.
104+
// We keep around the rendering context to avoid useless allocation if they get reused.
105105
hash = 0;
106106
refCount = 0;
107+
if (renderingContext != null)
108+
renderingContext.Reset();
107109
}
108110

109111
public void Cleanup()
@@ -882,14 +884,15 @@ public void UpdateEnvironment(HDCamera hdCamera,
882884
// Debug.Log("Update Sky Lighting");
883885
RenderSkyToCubemap(skyContext);
884886

885-
if (updateAmbientProbe)
887+
if (updateAmbientProbe && !renderingContext.computeAmbientProbeRequested)
886888
{
887889
using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.UpdateSkyAmbientProbe)))
888890
{
889891
cmd.SetComputeBufferParam(m_ComputeAmbientProbeCS, m_ComputeAmbientProbeKernel, m_AmbientProbeOutputBufferParam, renderingContext.ambientProbeResult);
890892
cmd.SetComputeTextureParam(m_ComputeAmbientProbeCS, m_ComputeAmbientProbeKernel, m_AmbientProbeInputCubemap, renderingContext.skyboxCubemapRT);
891893
cmd.DispatchCompute(m_ComputeAmbientProbeCS, m_ComputeAmbientProbeKernel, 1, 1, 1);
892894
cmd.RequestAsyncReadback(renderingContext.ambientProbeResult, renderingContext.OnComputeAmbientProbeDone);
895+
renderingContext.computeAmbientProbeRequested = true;
893896

894897
// When the profiler is enabled, we don't want to submit the render context because
895898
// it will break all the profiling sample Begin() calls issued previously, which leads

com.unity.render-pipelines.high-definition/Runtime/Sky/SkyRenderingContext.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal class SkyRenderingContext
1515
public bool supportsConvolution { get; private set; } = false;
1616

1717
internal bool ambientProbeIsReady = false;
18+
public bool computeAmbientProbeRequested = false;
1819

1920
public SkyRenderingContext(int resolution, int bsdfCount, bool supportsConvolution, SphericalHarmonicsL2 ambientProbe, string name)
2021
{
@@ -40,6 +41,12 @@ public SkyRenderingContext(int resolution, int bsdfCount, bool supportsConvoluti
4041
}
4142
}
4243

44+
public void Reset()
45+
{
46+
ambientProbeIsReady = false;
47+
computeAmbientProbeRequested = false;
48+
}
49+
4350
public void Cleanup()
4451
{
4552
RTHandles.Release(skyboxCubemapRT);

0 commit comments

Comments
 (0)