diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md
index 4f23d3d13e6..a202259f8d8 100644
--- a/com.unity.render-pipelines.high-definition/CHANGELOG.md
+++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md
@@ -311,6 +311,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fixed ghosting issues if the exposure changed too much (RTGI).
- Fixed failures on platforms that do not support ray tracing due to an engine behavior change.
- Fixed infinite propagation of nans for RTGI and SSGI (case 1349738).
+- Fixed access to main directional light from script.
### Changed
- Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs
index b4421fb274a..f04310b4b4c 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs
@@ -636,7 +636,12 @@ enum ClusterDepthSource : int
int m_CurrentShadowSortedSunLightIndex = -1;
HDAdditionalLightData m_CurrentSunLightAdditionalLightData;
DirectionalLightData m_CurrentSunLightDirectionalLightData;
- internal Light GetCurrentSunLight() { return m_CurrentSunLight; }
+
+ ///
+ /// Main directional Light for the HD Render Pipeline.
+ ///
+ /// The main directional Light.
+ public Light GetMainLight() { return m_CurrentSunLight; }
// Screen space shadow data
struct ScreenSpaceShadowData
@@ -1178,7 +1183,7 @@ internal void GetDirectionalLightData(CommandBuffer cmd, HDCamera hdCamera, Visi
size = new Vector2(additionalLightData.shapeWidth, additionalLightData.shapeHeight),
position = light.GetPosition()
};
- if (lightComponent == GetCurrentSunLight())
+ if (lightComponent == GetMainLight())
{
// If this is the current sun light and volumetric cloud shadows are enabled we need to render the shadows
if (HasVolumetricCloudsShadows_IgnoreSun(hdCamera))
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/HDRenderPipeline.VolumetricClouds.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/HDRenderPipeline.VolumetricClouds.cs
index 373865af6c2..be96c0084d8 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/HDRenderPipeline.VolumetricClouds.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/HDRenderPipeline.VolumetricClouds.cs
@@ -397,7 +397,7 @@ void UpdateShaderVariableslClouds(ref ShaderVariablesClouds cb, HDCamera hdCamer
// PB Sun/Sky settings
var visualEnvironment = hdCamera.volumeStack.GetComponent();
cb._PhysicallyBasedSun = visualEnvironment.skyType.value == (int)SkyType.PhysicallyBased ? 1 : 0;
- Light currentSun = GetCurrentSunLight();
+ Light currentSun = GetMainLight();
if (currentSun != null)
{
// Grab the target sun additional data
@@ -617,7 +617,7 @@ VolumetricCloudsParameters PrepareVolumetricCloudsParameters(HDCamera hdCamera,
parameters.worley32RGB = m_Asset.renderPipelineResources.textures.worleyNoise32RGB;
BlueNoise blueNoise = GetBlueNoiseManager();
parameters.ditheredTextureSet = blueNoise.DitheredTextureSet8SPP();
- parameters.sunLight = GetCurrentSunLight();
+ parameters.sunLight = GetMainLight();
parameters.enableExposureControl = hdCamera.exposureControlFS;
// Update the constant buffer
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/HDRenderPipeline.VolumetricCloudsShadows.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/HDRenderPipeline.VolumetricCloudsShadows.cs
index c9e1ebf6984..ad50a397b1f 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/HDRenderPipeline.VolumetricCloudsShadows.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/HDRenderPipeline.VolumetricCloudsShadows.cs
@@ -30,7 +30,7 @@ void ReleaseVolumetricCloudsShadows()
bool HasVolumetricCloudsShadows(HDCamera hdCamera, in VolumetricClouds settings)
{
return (HasVolumetricClouds(hdCamera, in settings)
- && GetCurrentSunLight() != null
+ && GetMainLight() != null
&& settings.shadows.value);
}
@@ -133,7 +133,7 @@ CookieParameters RenderVolumetricCloudsShadows(CommandBuffer cmd, HDCamera hdCam
TraceVolumetricCloudShadow(cmd, parameters, currentHandle);
// Grab the current sun light
- Light sunLight = GetCurrentSunLight();
+ Light sunLight = GetMainLight();
// Compute the shadow size
float groundShadowSize = settings.shadowDistance.value * 2.0f;
diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs
index e8ae9728bc2..9b0a1d2c38e 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs
@@ -1383,7 +1383,7 @@ void PreRenderSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colo
using (var builder = renderGraph.AddRenderPass("Pre Render Sky", out var passData))
{
- passData.sunLight = GetCurrentSunLight();
+ passData.sunLight = GetMainLight();
passData.hdCamera = hdCamera;
passData.colorBuffer = builder.WriteTexture(colorBuffer);
passData.depthStencilBuffer = builder.WriteTexture(depthStencilBuffer);
@@ -1421,7 +1421,7 @@ void RenderSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colorBu
using (var builder = renderGraph.AddRenderPass("Render Sky And Fog", out var passData))
{
passData.visualEnvironment = hdCamera.volumeStack.GetComponent();
- passData.sunLight = GetCurrentSunLight();
+ passData.sunLight = GetMainLight();
passData.hdCamera = hdCamera;
passData.volumetricLighting = builder.ReadTexture(volumetricLighting);
passData.colorBuffer = builder.WriteTexture(colorBuffer);
diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs
index 2c429ee31a5..0477991bff2 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs
@@ -2520,7 +2520,7 @@ void RenderWireFrame(CullingResults cull, HDCamera hdCamera, RenderTargetIdentif
void UpdateSkyEnvironment(HDCamera hdCamera, ScriptableRenderContext renderContext, CommandBuffer cmd)
{
- m_SkyManager.UpdateEnvironment(hdCamera, renderContext, GetCurrentSunLight(), cmd);
+ m_SkyManager.UpdateEnvironment(hdCamera, renderContext, GetMainLight(), cmd);
}
///
diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs
index 43a34c19251..bc01b51192f 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/PathTracing.cs
@@ -334,7 +334,7 @@ void RenderSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle skyBuff
using (var builder = renderGraph.AddRenderPass("Render Sky for Path Tracing", out var passData))
{
passData.visualEnvironment = hdCamera.volumeStack.GetComponent();
- passData.sunLight = GetCurrentSunLight();
+ passData.sunLight = GetMainLight();
passData.hdCamera = hdCamera;
passData.colorBuffer = builder.WriteTexture(skyBuffer);
passData.depthTexture = builder.WriteTexture(CreateDepthBuffer(renderGraph, true, MSAASamples.None));
diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudSystem/CloudLayer/CloudLayerRenderer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudSystem/CloudLayer/CloudLayerRenderer.cs
index 35362e2d4ec..448e8e5d2c4 100644
--- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudSystem/CloudLayer/CloudLayerRenderer.cs
+++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudSystem/CloudLayer/CloudLayerRenderer.cs
@@ -73,7 +73,7 @@ public override bool GetSunLightCookieParameters(CloudSettings settings, ref Coo
if (cloudLayer.CastShadows)
{
if (m_PrecomputedData == null || m_PrecomputedData.cloudShadowsRT == null)
- UpdateCache(cloudLayer, HDRenderPipeline.currentPipeline.GetCurrentSunLight());
+ UpdateCache(cloudLayer, HDRenderPipeline.currentPipeline.GetMainLight());
cookieParams.texture = m_PrecomputedData.cloudShadowsRT;
cookieParams.size = new Vector2(cloudLayer.shadowSize.value, cloudLayer.shadowSize.value);