From 82c892f663200f5ff6e2d2eb0c85c74792a83194 Mon Sep 17 00:00:00 2001 From: Kleber Garcia Date: Mon, 31 Jan 2022 20:15:39 -0500 Subject: [PATCH 1/2] Saving index of first light as sun light, and checking for shadow flag --- .../Runtime/Lighting/LightLoop/LightLoop.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 c0aaf020955..806715fdeae 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 @@ -603,6 +603,7 @@ enum ClusterDepthSource : int // Directional light Light m_CurrentSunLight; + int m_CurrentSunLightDataIndex = -1; int m_CurrentShadowSortedSunLightIndex = -1; HDAdditionalLightData m_CurrentSunLightAdditionalLightData; HDProcessedVisibleLightsBuilder.ShadowMapFlags m_CurrentSunShadowMapFlags = HDProcessedVisibleLightsBuilder.ShadowMapFlags.None; @@ -1577,8 +1578,11 @@ void PreprocessVisibleLights(CommandBuffer cmd, HDCamera hdCamera, in CullingRes { // Sunlight is the directional casting shadows // Fallback to the first non shadow casting directional light. - if ((processedLightEntity.shadowMapFlags & HDProcessedVisibleLightsBuilder.ShadowMapFlags.WillRenderShadowMap) != 0 || m_CurrentSunLight == null) + if (additionalLightData.ShadowsEnabled() || m_CurrentSunLight == null) + { + m_CurrentSunLightDataIndex = i; m_CurrentSunLight = additionalLightData.legacyLight; + } } ReserveCookieAtlasTexture(additionalLightData, additionalLightData.legacyLight, processedLightEntity.lightType); @@ -1839,6 +1843,7 @@ bool PrepareLightsForGPU( // We need to properly reset this here otherwise if we go from 1 light to no visible light we would keep the old reference active. m_CurrentSunLight = null; + m_CurrentSunLightDataIndex = -1; m_CurrentSunLightAdditionalLightData = null; m_CurrentShadowSortedSunLightIndex = -1; m_DebugSelectedLightShadowIndex = -1; From 159a6aad880e8ded58b1690e3283077bc1988d79 Mon Sep 17 00:00:00 2001 From: anisunity Date: Tue, 1 Feb 2022 10:58:28 +0100 Subject: [PATCH 2/2] Fixed using the wrong directional light data for clouds and the definition of current Sun when the shadow pass is culled (case 1399000). --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + .../Runtime/Lighting/LightUtils.cs | 8 ++++++++ .../HDRenderPipeline.VolumetricClouds.cs | 3 ++- .../RenderPipeline/Raytracing/HDRaytracingLightCluster.cs | 5 +---- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index b5ab8d146ba..ecd373b31aa 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -94,6 +94,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed issue that placed an OnDemand shadow in the atlas before it was ever rendered. - Fixed issue at edge of screen on some platforms when SSAO is on. - Fixed reflection probe rendering order when visible in multiple cameras. +- Fixed using the wrong directional light data for clouds and the definition of current Sun when the shadow pass is culled (case 1399000). ## [14.0.0] - 2021-11-17 diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightUtils.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightUtils.cs index 74d13b848ce..934b323a35c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightUtils.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightUtils.cs @@ -524,5 +524,13 @@ internal static void ConvertLightIntensity(LightUnit oldLightUnit, LightUnit new hdLight.intensity = intensity; } + + internal static Color EvaluateLightColor(Light light, HDAdditionalLightData hdLight) + { + Color finalColor = light.color.linear * light.intensity; + if (hdLight.useColorTemperature) + finalColor *= Mathf.CorrelatedColorTemperatureToRGB(light.colorTemperature); + return finalColor; + } } } 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 0ee37d77ad3..fb09a7741fa 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 @@ -389,7 +389,8 @@ void UpdateShaderVariableslClouds(ref ShaderVariablesClouds cb, HDCamera hdCamer if (!shadowPass) { - cb._SunLightColor = m_GpuLightsBuilder.directionalLights[0].color * settings.sunLightDimmer.value; + // m_CurrentSunLightDataIndex is supposed to be guaranteed to be non -1 if the current sun is not null + cb._SunLightColor = m_GpuLightsBuilder.directionalLights[m_CurrentSunLightDataIndex].color * settings.sunLightDimmer.value; } } else diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingLightCluster.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingLightCluster.cs index 4b699c55d34..62c25259c38 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingLightCluster.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/HDRaytracingLightCluster.cs @@ -537,10 +537,7 @@ void BuildLightData(CommandBuffer cmd, HDCamera hdCamera, HDRayTracingLights ray processedLightEntity.isBakedShadowMask = HDRenderPipeline.IsBakedShadowMaskLight(lightComponent); // Build a visible light - Color finalColor = lightComponent.color.linear * lightComponent.intensity; - if (additionalLightData.useColorTemperature) - finalColor *= Mathf.CorrelatedColorTemperatureToRGB(lightComponent.colorTemperature); - visibleLight.finalColor = finalColor; + visibleLight.finalColor = LightUtils.EvaluateLightColor(lightComponent, additionalLightData); visibleLight.range = lightComponent.range; // This should be done explicitly, localToWorld matrix doesn't work here localToWorldMatrix.SetColumn(3, lightComponent.gameObject.transform.position);