diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 7d05d21e993..9f39133ec4b 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed decal position when created from context menu. (case 1368987) - Fixed the clouds not taking properly into account the fog when in distant mode and with a close far plane (case 1367993). - Fixed overwriting of preview camera background color. [case 1357004](https://issuetracker.unity3d.com/product/unity/issues/guid/1361557/) +- Fixed selection of light types (point, area, directional) for path-traced Unlit shadow mattes. ## [13.0.0] - 2021-09-01 diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingLight.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingLight.hlsl index f4a5cc2f65e..822e374bf42 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingLight.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingLight.hlsl @@ -110,7 +110,9 @@ bool IsDistantLightActive(DirectionalLightData lightData, float3 normal) return dot(normal, lightData.forward) <= sin(lightData.angularDiameter * 0.5); } -LightList CreateLightList(float3 position, float3 normal, uint lightLayers = DEFAULT_LIGHT_LAYERS, bool withLocal = true, bool withDistant = true, float3 lightPosition = FLT_MAX) +LightList CreateLightList(float3 position, float3 normal, uint lightLayers = DEFAULT_LIGHT_LAYERS, + bool withPoint = true, bool withArea = true, bool withDistant = true, + float3 lightPosition = FLT_MAX) { LightList list; uint i; @@ -119,7 +121,7 @@ LightList CreateLightList(float3 position, float3 normal, uint lightLayers = DEF list.localCount = 0; list.localPointCount = 0; - if (withLocal) + if (withPoint || withArea) { uint localPointCount, localCount; @@ -144,35 +146,43 @@ LightList CreateLightList(float3 position, float3 normal, uint lightLayers = DEF bool forceLightPosition = (lightPosition.x != FLT_MAX); // First point lights (including spot lights) - for (i = 0; i < localPointCount && list.localPointCount < MAX_LOCAL_LIGHT_COUNT; i++) + if (withPoint) { -#ifdef USE_LIGHT_CLUSTER - const LightData lightData = FetchClusterLightIndex(list.cellIndex, i); -#else - const LightData lightData = _LightDatasRT[i]; -#endif + for (i = 0; i < localPointCount && list.localPointCount < MAX_LOCAL_LIGHT_COUNT; i++) + { + #ifdef USE_LIGHT_CLUSTER + const LightData lightData = FetchClusterLightIndex(list.cellIndex, i); + #else + const LightData lightData = _LightDatasRT[i]; + #endif + + if (forceLightPosition && any(lightPosition - lightData.positionRWS)) + continue; - if (forceLightPosition && any(lightPosition - lightData.positionRWS)) - continue; + if (IsMatchingLightLayer(lightData.lightLayers, lightLayers) && IsPointLightActive(lightData, position, normal)) + list.localIndex[list.localPointCount++] = i; + } - if (IsMatchingLightLayer(lightData.lightLayers, lightLayers) && IsPointLightActive(lightData, position, normal)) - list.localIndex[list.localPointCount++] = i; + list.localCount = list.localPointCount; } // Then rect area lights - for (list.localCount = list.localPointCount; i < localCount && list.localCount < MAX_LOCAL_LIGHT_COUNT; i++) + if (withArea) { -#ifdef USE_LIGHT_CLUSTER - const LightData lightData = FetchClusterLightIndex(list.cellIndex, i); -#else - const LightData lightData = _LightDatasRT[i]; -#endif + for (i = localPointCount; i < localCount && list.localCount < MAX_LOCAL_LIGHT_COUNT; i++) + { + #ifdef USE_LIGHT_CLUSTER + const LightData lightData = FetchClusterLightIndex(list.cellIndex, i); + #else + const LightData lightData = _LightDatasRT[i]; + #endif - if (forceLightPosition && any(lightPosition - lightData.positionRWS)) - continue; + if (forceLightPosition && any(lightPosition - lightData.positionRWS)) + continue; - if (IsMatchingLightLayer(lightData.lightLayers, lightLayers) && IsRectAreaLightActive(lightData, position, normal)) - list.localIndex[list.localCount++] = i; + if (IsMatchingLightLayer(lightData.lightLayers, lightLayers) && IsRectAreaLightActive(lightData, position, normal)) + list.localIndex[list.localCount++] = i; + } } } @@ -837,7 +847,7 @@ float PickLocalLightInterval(float3 rayOrigin, float3 rayDirection, inout float LightList CreateLightList(float3 position, bool sampleLocalLights, float3 lightPosition = FLT_MAX) { - return CreateLightList(position, 0.0, DEFAULT_LIGHT_LAYERS, sampleLocalLights, !sampleLocalLights, lightPosition); + return CreateLightList(position, 0.0, DEFAULT_LIGHT_LAYERS, sampleLocalLights, sampleLocalLights, !sampleLocalLights, lightPosition); } #endif // UNITY_PATH_TRACING_LIGHT_INCLUDED diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl index 552a7276c75..f2c881c9b52 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl @@ -23,7 +23,12 @@ float3 GetPositionBias(float3 geomNormal, float bias, bool below) // Compute scalar visibility for shadow mattes, between 0 and 1 float ComputeVisibility(float3 position, float3 normal, float3 inputSample) { - LightList lightList = CreateLightList(position, normal); + // Select active types of lights + bool withPoint = asuint(_ShadowMatteFilter) & LIGHTFEATUREFLAGS_PUNCTUAL; + bool withArea = asuint(_ShadowMatteFilter) & LIGHTFEATUREFLAGS_AREA; + bool withDistant = asuint(_ShadowMatteFilter) & LIGHTFEATUREFLAGS_DIRECTIONAL; + + LightList lightList = CreateLightList(position, normal, DEFAULT_LIGHT_LAYERS, withPoint, withArea, withDistant); RayDesc rayDescriptor; rayDescriptor.Origin = position + normal * _RaytracingRayBias;