Skip to content

Commit 65f5f75

Browse files
Masayoshi MiyamotoEvergreen
authored andcommitted
Fix for the preview rendering issue (no default sky ambient)
In the initial rendering of the preview in the inspector window, the ambient color of the default sky may not be ready (black ambient color), due to the lag of GPU readback of the SH coefficients. The ambient color is not updated until the preview is updated by some triggers like hovering the cursor over the inspector. This PR fixes the issue by using the hard-coded value of the default sky's SH.
1 parent b7e3c5b commit 65f5f75

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ internal void UpdateCurrentSky(SkyManager skyManager)
17731773
visualSky.cloudSettings = null;
17741774
visualSky.volumetricClouds = null;
17751775
lightingSky = visualSky;
1776-
skyAmbientMode = SkyAmbientMode.Dynamic;
1776+
skyAmbientMode = SkyAmbientMode.Static;
17771777
}
17781778
else
17791779
#endif

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ class SkyManager
188188
#if UNITY_EDITOR
189189
// For Preview windows we want to have a 'fixed' sky, so we can display chrome metal and have always the same look
190190
HDRISky m_DefaultPreviewSky;
191+
192+
// Hard-coded SH for DefaultHDRISky.exr
193+
// This is a temporary solution for the preview rendering issue when SH is not ready.
194+
// A proper fix is needed when we want to expose the control of sky for preview.
195+
SphericalHarmonicsL2 m_DefaultPreviewSkyAmbientProbe = new SphericalHarmonicsL2();
191196
#endif
192197

193198
// Shared resources for sky rendering.
@@ -456,6 +461,36 @@ public void Build(HDRenderPipelineAsset hdAsset, HDRenderPipeline renderPipeline
456461

457462
#if UNITY_EDITOR
458463
UnityEditor.Lightmapping.bakeStarted += OnBakeStarted;
464+
465+
{
466+
m_DefaultPreviewSkyAmbientProbe[0, 0] = 0.1279895f;
467+
m_DefaultPreviewSkyAmbientProbe[0, 1] = -0.01244975f;
468+
m_DefaultPreviewSkyAmbientProbe[0, 2] = 0.002333597f;
469+
m_DefaultPreviewSkyAmbientProbe[0, 3] = -0.01013585f;
470+
m_DefaultPreviewSkyAmbientProbe[0, 4] = -0.006032045f;
471+
m_DefaultPreviewSkyAmbientProbe[0, 5] = 0.0005331814f;
472+
m_DefaultPreviewSkyAmbientProbe[0, 6] = 0.002311948f;
473+
m_DefaultPreviewSkyAmbientProbe[0, 7] = -0.001873836f;
474+
m_DefaultPreviewSkyAmbientProbe[0, 8] = 0.0231871f;
475+
m_DefaultPreviewSkyAmbientProbe[1, 0] = 0.1585829f;
476+
m_DefaultPreviewSkyAmbientProbe[1, 1] = 0.01596837f;
477+
m_DefaultPreviewSkyAmbientProbe[1, 2] = 0.003311858f;
478+
m_DefaultPreviewSkyAmbientProbe[1, 3] = -0.01475812f;
479+
m_DefaultPreviewSkyAmbientProbe[1, 4] = -0.009350514f;
480+
m_DefaultPreviewSkyAmbientProbe[1, 5] = 0.000841937f;
481+
m_DefaultPreviewSkyAmbientProbe[1, 6] = 0.003378667f;
482+
m_DefaultPreviewSkyAmbientProbe[1, 7] = -0.002562553f;
483+
m_DefaultPreviewSkyAmbientProbe[1, 8] = 0.03318842f;
484+
m_DefaultPreviewSkyAmbientProbe[2, 0] = 0.209883f;
485+
m_DefaultPreviewSkyAmbientProbe[2, 1] = 0.06525062f;
486+
m_DefaultPreviewSkyAmbientProbe[2, 2] = 0.004639104f;
487+
m_DefaultPreviewSkyAmbientProbe[2, 3] = -0.02339679f;
488+
m_DefaultPreviewSkyAmbientProbe[2, 4] = -0.01619671f;
489+
m_DefaultPreviewSkyAmbientProbe[2, 5] = 0.001453806f;
490+
m_DefaultPreviewSkyAmbientProbe[2, 6] = 0.003758613f;
491+
m_DefaultPreviewSkyAmbientProbe[2, 7] = -0.003646188f;
492+
m_DefaultPreviewSkyAmbientProbe[2, 8] = 0.04316145f;
493+
}
459494
#endif
460495
}
461496

@@ -608,6 +643,13 @@ internal SphericalHarmonicsL2 GetAmbientProbe(HDCamera hdCamera)
608643
return m_BlackAmbientProbe;
609644
}
610645

646+
#if UNITY_EDITOR
647+
if (HDUtils.IsRegularPreviewCamera(hdCamera.camera))
648+
{
649+
return m_DefaultPreviewSkyAmbientProbe;
650+
}
651+
#endif
652+
611653
return GetAmbientProbe(GetLightingSky(hdCamera));
612654
}
613655

0 commit comments

Comments
 (0)