From 480c20522132b4fee95ae274274d0101c005eeeb Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Thu, 30 Sep 2021 11:46:04 +0200 Subject: [PATCH 1/3] Added selection of light types for shadow mattes. --- .../CHANGELOG.md | 1 + .../PathTracing/Shaders/PathTracingLight.hlsl | 56 +++++++++++-------- .../ShaderPass/ShaderPassPathTracing.hlsl | 7 ++- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index f3357e9cbd1..ddd650fd4d3 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -149,6 +149,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added a built-in custom pass to draw object IDs. - Added an example in the documentation that shows how to use the accumulation API for high quality antialiasing (supersampling). - Added a SG node to get the main directional light direction. +- Added selection of light types (point, area, directional) for path-traced Unlit shadow mattes. ### Fixed - Fixed Intensity Multiplier not affecting realtime global illumination. 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 faa8e3e75bf..fa853ac9b3a 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 @@ -109,7 +109,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; @@ -118,7 +120,7 @@ LightList CreateLightList(float3 position, float3 normal, uint lightLayers = DEF list.localCount = 0; list.localPointCount = 0; - if (withLocal) + if (withPoint || withArea) { uint localPointCount, localCount; @@ -143,35 +145,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; + } } } @@ -814,7 +824,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 1f34b464bb1..f2668d966c3 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 @@ -25,7 +25,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; From 735a6a31f13f4f773b81470edb1f7c07e5bbf796 Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Fri, 1 Oct 2021 16:25:13 +0200 Subject: [PATCH 2/3] Update CHANGELOG.md --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index ddd650fd4d3..1f385da3d5e 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -56,6 +56,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed the volume not being assigned on some scene templates. - Fixed corruption in player with lightmap uv when Optimize Mesh Data is enabled [1357902] - Fixed a warning to Rendering Debugger Runtime UI when debug shaders are stripped. +- Fixed selection of light types (point, area, directional) for path-traced Unlit shadow mattes. ### Changed - Visual Environment ambient mode is now Dynamic by default. @@ -149,7 +150,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added a built-in custom pass to draw object IDs. - Added an example in the documentation that shows how to use the accumulation API for high quality antialiasing (supersampling). - Added a SG node to get the main directional light direction. -- Added selection of light types (point, area, directional) for path-traced Unlit shadow mattes. ### Fixed - Fixed Intensity Multiplier not affecting realtime global illumination. From c4f23d61de5f74d35cb4d767e2d405d1ed19626c Mon Sep 17 00:00:00 2001 From: Sebastien Lagarde Date: Thu, 7 Oct 2021 19:50:27 +0200 Subject: [PATCH 3/3] Formatting --- .../RenderPipeline/PathTracing/Shaders/PathTracingLight.hlsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fa853ac9b3a..68bbdef3893 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 @@ -161,7 +161,7 @@ LightList CreateLightList(float3 position, float3 normal, uint lightLayers = DEF if (IsMatchingLightLayer(lightData.lightLayers, lightLayers) && IsPointLightActive(lightData, position, normal)) list.localIndex[list.localPointCount++] = i; } - + list.localCount = list.localPointCount; }