Skip to content

Fix issue with ambient probe not being correct with OnEnable/OnDemand probes #291

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
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
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed a performance issue with stochastic ray traced area shadows.
- Fixed cookie texture not updated when changing an import settings (srgb for example).
- Fixed flickering of the game/scene view when lookdev is running.
- Fixed issue with reflection probes in realtime time mode with OnEnable baking having wrong lighting with sky set to dynamic (case 1238047).

### Changed
- Improve MIP selection for decals on Transparents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,13 @@ public virtual void PrepareCulling() { }
/// </summary>
public void RequestRenderNextUpdate() => m_WasRenderedSinceLastOnDemandRequest = false;

// Forces the re-rendering for both OnDemand and OnEnable
internal void ForceRenderingNextUpdate()
{
m_WasRenderedSinceLastOnDemandRequest = false;
wasRenderedAfterOnEnable = false;
}

void UpdateProbeName()
{
// TODO: ask if this is ok:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,14 @@ ref _cullingResults
continue;
}

// HACK! We render the probe until we know the ambient probe for the associated sky context is ready.
// For one-off rendering the dynamic ambient probe will be set to black until they are not processed, leading to faulty rendering.
// So we enqueue another rendering and then we will not set the probe texture until we have rendered with valid ambient probe.
if (!m_SkyManager.HasSetValidAmbientProbe(hdCamera))
{
visibleProbe.ForceRenderingNextUpdate();
}

hdCamera.parentCamera = parentCamera; // Used to inherit the properties of the view

HDAdditionalCameraData hdCam;
Expand Down Expand Up @@ -1730,26 +1738,30 @@ ref _cullingResults
// TODO: store DecalCullResult
};

// As we render realtime texture on GPU side, we must tag the texture so our texture array cache detect that something have change
visibleProbe.realtimeTexture.IncrementUpdateCount();

if (cameraSettings.Count > 1)
if (m_SkyManager.HasSetValidAmbientProbe(hdCamera))
{
var face = (CubemapFace)j;
request.target = new RenderRequest.Target
// As we render realtime texture on GPU side, we must tag the texture so our texture array cache detect that something have change
visibleProbe.realtimeTexture.IncrementUpdateCount();

if (cameraSettings.Count > 1)
{
copyToTarget = visibleProbe.realtimeTexture,
face = face
};
}
else
{
request.target = new RenderRequest.Target
var face = (CubemapFace)j;
request.target = new RenderRequest.Target
{
copyToTarget = visibleProbe.realtimeTexture,
face = face
};
}
else
{
id = visibleProbe.realtimeTexture,
face = CubemapFace.Unknown
};
request.target = new RenderRequest.Target
{
id = visibleProbe.realtimeTexture,
face = CubemapFace.Unknown
};
}
}

renderRequests.Add(request);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,24 @@ internal SphericalHarmonicsL2 GetAmbientProbe(HDCamera hdCamera)
return GetAmbientProbe(hdCamera.lightingSky);
}

internal bool HasSetValidAmbientProbe(HDCamera hdCamera)
{
SkyAmbientMode ambientMode = hdCamera.volumeStack.GetComponent<VisualEnvironment>().skyAmbientMode.value;
if (ambientMode == SkyAmbientMode.Static)
return true;

if (hdCamera.skyAmbientMode == SkyAmbientMode.Dynamic && hdCamera.lightingSky != null &&
hdCamera.lightingSky.IsValid() && IsCachedContextValid(hdCamera.lightingSky))
{
ref CachedSkyContext cachedContext = ref m_CachedSkyContexts[hdCamera.lightingSky.cachedSkyRenderingContextId];
var renderingContext = cachedContext.renderingContext;
return renderingContext.ambientProbeIsReady;
}

return false;

}

internal void SetupAmbientProbe(HDCamera hdCamera)
{
// Working around GI current system
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ internal class SkyRenderingContext
public CubemapArray skyboxBSDFCubemapArray { get; private set; }
public bool supportsConvolution { get; private set; } = false;

internal bool ambientProbeIsReady = false;

public SkyRenderingContext(int resolution, int bsdfCount, bool supportsConvolution, SphericalHarmonicsL2 ambientProbe, string name)
{
m_AmbientProbe = ambientProbe;
Expand Down Expand Up @@ -71,6 +73,8 @@ public void OnComputeAmbientProbeDone(AsyncGPUReadbackRequest request)
m_AmbientProbe[channel, coeff] = result[channel * 9 + coeff];
}
}

ambientProbeIsReady = true;
}
}
}
Expand Down