diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index e3c66b493d2..439c16f00a1 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -108,6 +108,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed APV loading data outside of the relevant area containing probes. - Fixed the roughness value used for screen space reflections and ray traced reflections to match environment lighting (case 1390916). - Fixed editor issue with the LiftGammaGain and ShadowsMidtonesHighlights volume components. +- 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/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; 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 2d1b8bb5d2a..c5fa74b6e03 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);