Skip to content

Dynamic Ambient improvement and doc update #5951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ In the High Definition Render Pipeline (HDRP), there are two parts to environmen
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.

## Visual Environment
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.
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.

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

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

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).
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).

***\*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).

### Limitation of Dynamic Ambient mode

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.

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.

## Ambient Reflection Probe

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ struct CachedSkyContext

public void Reset()
{
// We keep around the renderer and the rendering context to avoid useless allocation if they get reused.
// We keep around the rendering context to avoid useless allocation if they get reused.
hash = 0;
refCount = 0;
if (renderingContext != null)
renderingContext.Reset();
}

public void Cleanup()
Expand Down Expand Up @@ -882,14 +884,15 @@ public void UpdateEnvironment(HDCamera hdCamera,
// Debug.Log("Update Sky Lighting");
RenderSkyToCubemap(skyContext);

if (updateAmbientProbe)
if (updateAmbientProbe && !renderingContext.computeAmbientProbeRequested)
{
using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.UpdateSkyAmbientProbe)))
{
cmd.SetComputeBufferParam(m_ComputeAmbientProbeCS, m_ComputeAmbientProbeKernel, m_AmbientProbeOutputBufferParam, renderingContext.ambientProbeResult);
cmd.SetComputeTextureParam(m_ComputeAmbientProbeCS, m_ComputeAmbientProbeKernel, m_AmbientProbeInputCubemap, renderingContext.skyboxCubemapRT);
cmd.DispatchCompute(m_ComputeAmbientProbeCS, m_ComputeAmbientProbeKernel, 1, 1, 1);
cmd.RequestAsyncReadback(renderingContext.ambientProbeResult, renderingContext.OnComputeAmbientProbeDone);
renderingContext.computeAmbientProbeRequested = true;

// When the profiler is enabled, we don't want to submit the render context because
// it will break all the profiling sample Begin() calls issued previously, which leads
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ internal class SkyRenderingContext
public bool supportsConvolution { get; private set; } = false;

internal bool ambientProbeIsReady = false;
public bool computeAmbientProbeRequested = false;

public SkyRenderingContext(int resolution, int bsdfCount, bool supportsConvolution, SphericalHarmonicsL2 ambientProbe, string name)
{
Expand All @@ -40,6 +41,12 @@ public SkyRenderingContext(int resolution, int bsdfCount, bool supportsConvoluti
}
}

public void Reset()
{
ambientProbeIsReady = false;
computeAmbientProbeRequested = false;
}

public void Cleanup()
{
RTHandles.Release(skyboxCubemapRT);
Expand Down