Skip to content

Fix some NaNs issues on consoles #699

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 1 commit into from
Jun 4, 2020
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 @@ -139,6 +139,13 @@ Texture FilterAreaLightTexture(CommandBuffer cmd, Texture source)
name = cacheName + "TempAreaLightRT0"
};

// Clear the textures to avoid filtering with NaNs on consoles.
for (int mipIdx = 0; mipIdx < mipMapCount; ++mipIdx)
{
cmd.SetRenderTarget(m_TempRenderTexture0, mipIdx);
cmd.ClearRenderTarget(false, true, Color.clear);
}

// We start by a horizontal gaussian into mip 1 that reduces the width by a factor 2 but keeps the same height
m_TempRenderTexture1 = new RenderTexture(sourceWidth >> 1, sourceHeight, 1, cookieFormat)
{
Expand All @@ -147,6 +154,14 @@ Texture FilterAreaLightTexture(CommandBuffer cmd, Texture source)
autoGenerateMips = false,
name = cacheName + "TempAreaLightRT1"
};

// Clear the textures to avoid filtering with NaNs on consoles.
for (int mipIdx = 0; mipIdx < mipMapCount - 1; ++mipIdx)
{
cmd.SetRenderTarget(m_TempRenderTexture1, mipIdx);
cmd.ClearRenderTarget(false, true, Color.clear);
}

}

using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.AreaLightCookieConvolution)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public PlanarReflectionProbeCache(RenderPipelineResources defaultResources, IBLF
Debug.Assert(probeFormat == GraphicsFormat.RGB_BC6H_SFloat || probeFormat == GraphicsFormat.R16G16B16A16_SFloat, "Reflection Probe Cache format for HDRP can only be BC6H or FP16.");

m_ProbeSize = atlasResolution;
m_TextureAtlas = new PowerOfTwoTextureAtlas(atlasResolution, 0, probeFormat, useMipMap: isMipmaped, name: "PlanarReflectionProbe Atlas");
m_TextureAtlas = new PowerOfTwoTextureAtlas(atlasResolution, 1, probeFormat, useMipMap: isMipmaped, name: "PlanarReflectionProbe Atlas");
m_IBLFilterGGX = iblFilter;

m_PerformBC6HCompression = probeFormat == GraphicsFormat.RGB_BC6H_SFloat;
Expand Down Expand Up @@ -69,6 +69,15 @@ void Initialize()
m_ConvolutionTargetTexture.name = CoreUtils.GetRenderTargetAutoName(m_ProbeSize, m_ProbeSize, 0, RenderTextureFormat.ARGBHalf, "PlanarReflectionConvolution", mips: true);
m_ConvolutionTargetTexture.enableRandomWrite = true;
m_ConvolutionTargetTexture.Create();

// Clear to avoid garbage in the convolution texture.
int mipCount = Mathf.FloorToInt(Mathf.Log(m_ProbeSize, 2)) + 1;
for (int mipIdx = 0; mipIdx < mipCount; ++mipIdx)
{
Graphics.SetRenderTarget(m_ConvolutionTargetTexture, mipIdx, CubemapFace.Unknown);
GL.Clear(false, true, Color.clear);
}

}

m_FrameProbeIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,12 @@ void AddVisibleProbeVisibleIndexIfUpdateIsRequired(HDProbe probe, int visibleInI
return;

// Notify that we render the probe at this frame
probe.SetIsRendered(m_FrameCount);
// NOTE: If the probe was rendered on the very first frame, we could have some data that was used and it wasn't in a fully initialized state, which is fine on PC, but on console
// might lead to NaNs due to lack of complete initialization. To circumvent this, we force the probe to render again only if it was rendered on the first frame. Note that the problem
// doesn't apply if probe is enable any frame other than the very first. Also note that we are likely to be re-rendering the probe anyway due to the issue on sky ambient probe
// (see m_SkyManager.HasSetValidAmbientProbe in this function).
if (m_FrameCount > 1)
probe.SetIsRendered(m_FrameCount);

float visibility = ComputeVisibility(visibleInIndex, probe);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public int RenderColorGaussianPyramid(CommandBuffer cmd, Vector2Int size, Textur
useDynamicScale: true,
name: "Temporary Downsampled Pyramid"
);

cmd.SetRenderTarget(m_TempDownsamplePyramid[rtIndex]);
cmd.ClearRenderTarget(false, true, Color.black);
}

float sourceScaleX = (float)size.x / source.width;
Expand Down