From 6520e37fbf87da596fe18d98efc71d33f95350ba Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Wed, 23 Sep 2020 10:42:45 +0200 Subject: [PATCH 01/16] Brought changes from volume branch. --- .../Runtime/Lighting/LightEvaluation.hlsl | 5 + .../Lighting/LightLoop/CookieSampling.hlsl | 5 + .../Lighting/LightLoop/LightLoopDef.hlsl | 5 + .../Material/LayeredLit/LayeredLit.shader | 7 +- .../Runtime/Material/Lit/Lit.shader | 5 +- .../Runtime/Material/Unlit/Unlit.shader | 4 +- .../PathTracing/Shaders/PathTracingBSDF.hlsl | 1 + .../PathTracing/Shaders/PathTracingLight.hlsl | 183 +++++++++++++++++- .../Shaders/PathTracingMain.raytrace | 35 +++- .../Shaders/PathTracingSampling.hlsl | 14 ++ .../Shaders/PathTracingVolume.hlsl | 181 +++++++++++++++++ .../Shaders/PathTracingVolume.hlsl.meta | 10 + .../AtmosphericScatteringRayTracing.hlsl | 22 ++- .../Shaders/RaytracingSampling.hlsl | 17 +- .../ShaderPass/ShaderPassPathTracing.hlsl | 93 ++++++--- 15 files changed, 525 insertions(+), 62 deletions(-) create mode 100644 com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl create mode 100644 com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl.meta diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl index 493a656b1a3..d261c7b1e44 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl @@ -1,3 +1,6 @@ +#ifndef UNITY_LIGHT_EVALUATION_INCLUDED +#define UNITY_LIGHT_EVALUATION_INCLUDED + // This files include various function uses to evaluate lights // use #define LIGHT_EVALUATION_NO_HEIGHT_FOG to disable Height fog attenuation evaluation // use #define LIGHT_EVALUATION_NO_COOKIE to disable cookie evaluation @@ -582,3 +585,5 @@ void ApplyScreenSpaceReflectionWeight(inout float4 ssrLighting) ssrLighting.rgb *= ssrLighting.a; } #endif + +#endif // UNITY_LIGHT_EVALUATION_INCLUDED diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/CookieSampling.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/CookieSampling.hlsl index 0a0d951d650..3a511f7ba16 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/CookieSampling.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/CookieSampling.hlsl @@ -1,3 +1,6 @@ +#ifndef UNITY_COOKIE_SAMPLING_INCLUDED +#define UNITY_COOKIE_SAMPLING_INCLUDED + //----------------------------------------------------------------------------- // Cookie sampling functions // ---------------------------------------------------------------------------- @@ -47,3 +50,5 @@ float3 SamplePointCookie(float3 lightToSample, float4 scaleOffset, float lod = 0 return SampleCookie2D(uv, scaleOffset, lod); } + +#endif // UNITY_COOKIE_SAMPLING_INCLUDED diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl index 2cb84b578e9..8b0a8658616 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl @@ -1,3 +1,6 @@ +#ifndef UNITY_LIGHT_LOOP_DEF_INCLUDED +#define UNITY_LIGHT_LOOP_DEF_INCLUDED + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/CookieSampling.hlsl" @@ -354,3 +357,5 @@ float3 GetScreenSpaceColorShadow(PositionInputs posInput, int shadowIndex) float4 res = LOAD_TEXTURE2D_ARRAY(_ScreenSpaceShadowsTexture, posInput.positionSS, INDEX_TEXTURE2D_ARRAY_X(shadowIndex & SCREEN_SPACE_SHADOW_INDEX_MASK)); return (SCREEN_SPACE_COLOR_SHADOW_FLAG & shadowIndex) ? res.xyz : res.xxx; } + +#endif // UNITY_LIGHT_LOOP_DEF_INCLUDED diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader index 3a322d992ff..16b5ce000ca 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader @@ -1089,19 +1089,16 @@ Shader "HDRP/LayeredLit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" #define HAS_LIGHTLOOP #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitRaytracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightLoop.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitData.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitPathTracing.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl" ENDHLSL diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader index d83743bdb8d..489321a767a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader @@ -1128,19 +1128,16 @@ Shader "HDRP/Lit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" #define HAS_LIGHTLOOP #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitRaytracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingLightLoop.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitPathTracing.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl" ENDHLSL diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader index d330af0812b..b33a114f7a7 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader @@ -577,6 +577,9 @@ Shader "HDRP/Unlit" #pragma raytracing surface_shader #define SHADERPASS SHADERPASS_PATH_TRACING + + #define HAS_LIGHTLOOP // Used when computing volumetric scattering + #define EMISSIVE_ONLY #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingMacros.hlsl" @@ -584,7 +587,6 @@ Shader "HDRP/Unlit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/ShaderPass/UnlitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingBSDF.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingBSDF.hlsl index a56b52c75bb..a19184de880 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingBSDF.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingBSDF.hlsl @@ -1,6 +1,7 @@ #ifndef UNITY_PATH_TRACING_BSDF_INCLUDED #define UNITY_PATH_TRACING_BSDF_INCLUDED +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingSampling.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/SubSurface.hlsl" #define DELTA_PDF 1000000.0 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 fb03efd30c0..9f098d34e11 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 @@ -1,6 +1,18 @@ #ifndef UNITY_PATH_TRACING_LIGHT_INCLUDED #define UNITY_PATH_TRACING_LIGHT_INCLUDED +// This is just because it need to be defined, shadow maps are not used. +#define SHADOW_LOW + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/CookieSampling.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl" + +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracingLightLoop.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Shadows/SphericalQuad.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RayTracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl" + // How many lights (at most) do we support at one given shading point // FIXME: hardcoded limits are evil, this LightList should instead be put together in C# #define MAX_LOCAL_LIGHT_COUNT 16 @@ -77,12 +89,18 @@ bool IsDistantLightActive(DirectionalLightData lightData, float3 normal) return dot(normal, lightData.forward) < sin(lightData.angularDiameter * 0.5); } -LightList CreateLightList(float3 position, float3 normal, uint lightLayers) +LightList CreateLightList(float3 position, float3 normal, uint lightLayers, bool withLocal = true, bool withDistant = true) { LightList list; + uint i; // First take care of local lights (point, area) - uint i, localPointCount, localCount; + list.localCount = 0; + list.localPointCount = 0; + +if (withLocal) +{ + uint localPointCount, localCount; #ifdef USE_LIGHT_CLUSTER if (PointInsideCluster(position)) @@ -102,7 +120,7 @@ LightList CreateLightList(float3 position, float3 normal, uint lightLayers) #endif // First point lights (including spot lights) - for (list.localPointCount = 0, i = 0; i < localPointCount && list.localPointCount < MAX_LOCAL_LIGHT_COUNT; i++) + for (i = 0; i < localPointCount && list.localPointCount < MAX_LOCAL_LIGHT_COUNT; i++) { #ifdef USE_LIGHT_CLUSTER const LightData lightData = FetchClusterLightIndex(list.cellIndex, i); @@ -134,10 +152,13 @@ LightList CreateLightList(float3 position, float3 normal, uint lightLayers) ) list.localIndex[list.localCount++] = i; } +} // Then filter the active distant lights (directional) list.distantCount = 0; +if (withDistant) +{ for (i = 0; i < _DirectionalLightCount && list.distantCount < MAX_DISTANT_LIGHT_COUNT; i++) { if (IsMatchingLightLayer(_DirectionalLightDatas[i].lightLayers, lightLayers) @@ -147,6 +168,7 @@ LightList CreateLightList(float3 position, float3 normal, uint lightLayers) ) list.distantIndex[list.distantCount++] = i; } +} // Compute the weights, used for the lights PDF (we split 50/50 between local and distant, if both are present) list.localWeight = list.localCount ? (list.distantCount ? 0.5 : 1.0) : 0.0; @@ -297,7 +319,7 @@ bool SampleLights(LightList lightList, dist = sqrt(sqDist); outgoingDir /= dist; - if (dot(normal, outgoingDir) < 0.001) + if (any(normal) && dot(normal, outgoingDir) < 0.001) return false; float cosTheta = -dot(outgoingDir, lightData.forward); @@ -331,7 +353,7 @@ bool SampleLights(LightList lightList, pdf = DELTA_PDF; } - if (dot(normal, outgoingDir) < 0.001) + if (any(normal) && dot(normal, outgoingDir) < 0.001) return false; value = GetPunctualEmission(lightData, outgoingDir, dist) * pdf; @@ -364,7 +386,7 @@ bool SampleLights(LightList lightList, outgoingDir = -lightData.forward; } - if (dot(normal, outgoingDir) < 0.001) + if (any(normal) && dot(normal, outgoingDir) < 0.001) return false; dist = FLT_INF; @@ -448,4 +470,153 @@ void EvaluateLights(LightList lightList, } } +// Functions used by volumetric sampling + +bool SolvePoly2(float a, float b, float c, out float x1, out float x2) +{ + float det = Sq(b) - 4.0 * a * c; + + if (det < 0.0) + return false; + + float sqrtDet = sqrt(det); + x1 = (-b - sign(a) * sqrtDet) / (2.0 * a); + x2 = (-b + sign(a) * sqrtDet) / (2.0 * a); + + return true; +} + +bool GetSphereInterval(float3 lightToPos, float radius, float3 rayDirection, out float tMin, out float tMax) +{ + // We consider Direction to be normalized => a = 1 + float b = 2.0 * dot(rayDirection, lightToPos); + float c = Length2(lightToPos) - Sq(radius); + + float t1, t2; + if (!SolvePoly2(1.0, b, c, t1, t2)) + return false; + + tMin = max(t1, 0.0); + tMax = max(t2, 0.0); + + return tMin < tMax; +} + +bool GetRectAreaLightInterval(LightData lightData, float3 rayOrigin, float3 rayDirection, out float tMin, out float tMax) +{ + float3 lightVec = rayOrigin - GetAbsolutePositionWS(lightData.positionRWS); + + if (!GetSphereInterval(lightVec, lightData.range, rayDirection, tMin, tMax)) + return false; + + float LdotD = dot(lightData.forward, rayDirection); + float t = -dot(lightData.forward, lightVec) / LdotD; + if (LdotD > 0.0) + tMin = max(tMin, t); + else + tMax = min(tMax, t); + + return tMin < tMax; +} + +bool GetPointLightInterval(LightData lightData, float3 rayOrigin, float3 rayDirection, out float tMin, out float tMax) +{ + float3 lightVec = rayOrigin - GetAbsolutePositionWS(lightData.positionRWS); + + if (!GetSphereInterval(lightVec, lightData.range, rayDirection, tMin, tMax)) + return false; + + // This is just a point light (no spot cone angle) + if (lightData.lightType == GPULIGHTTYPE_POINT) + return true; + + // Intersect our ray with the spot light's cone + float LdotD = dot(lightData.forward, rayDirection); + float cosTheta2 = Sq(lightData.angleOffset / lightData.angleScale); + + // Offset light origin to account for light radius + lightVec += sqrt(lightData.size.x / (1.0 - cosTheta2)) * lightData.forward; + float LdotV = dot(lightData.forward, lightVec); + + float a = Sq(LdotD) - cosTheta2; + float b = 2.0 * (LdotD * LdotV - dot(rayDirection, lightVec) * cosTheta2); + float c = Sq(LdotV) - Length2(lightVec) * cosTheta2; + + float t1, t2; + if (!SolvePoly2(a, b, c, t1, t2)) + return false; + + // Check validity of the intersections (we want them with the front cone only) + bool t1Valid = dot(lightVec + t1 * rayDirection, lightData.forward) > 0.0; + bool t2Valid = dot(lightVec + t2 * rayDirection, lightData.forward) > 0.0; + + if (t1Valid) + { + if (t2Valid) + { + tMin = max(t1, tMin); + tMax = min(t2, tMax); + } + else + { + tMax = min(t1, tMax); + } + } + else + { + if (t2Valid) + { + tMin = max(t2, tMin); + } + else + { + tMin = 0.0; + tMax = 0.0; + } + } + + return tMin < tMax; +} + +float GetLocalLightsInterval(float3 rayOrigin, float3 rayDirection, out float tMin, out float tMax) +{ + tMin = FLT_MAX; + tMax = 0.0; + + float tLightMin, tLightMax; + + // First process point lights + uint i = 0, n = _PunctualLightCountRT, localCount = 0; + for (; i < n; i++) + { + if (GetPointLightInterval(_LightDatasRT[i], rayOrigin, rayDirection, tLightMin, tLightMax)) + { + tMin = min(tMin, tLightMin); + tMax = max(tMax, tLightMax); + localCount++; + } + } + + // Then area lights + n += _AreaLightCountRT; + for (; i < n; i++) + { + if (GetRectAreaLightInterval(_LightDatasRT[i], rayOrigin, rayDirection, tLightMin, tLightMax)) + { + tMin = min(tMin, tLightMin); + tMax = max(tMax, tLightMax); + localCount++; + } + } + + uint lightCount = localCount + _DirectionalLightCount; + + return lightCount ? float(localCount) / lightCount : -1.0; +} + +LightList CreateLightList(float3 position, bool sampleLocalLights) +{ + return CreateLightList(position, 0.0, ~0, sampleLocalLights, !sampleLocalLights); +} + #endif // UNITY_PATH_TRACING_LIGHT_INCLUDED diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingMain.raytrace b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingMain.raytrace index e38166d52a7..d120b0507b0 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingMain.raytrace +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingMain.raytrace @@ -12,11 +12,15 @@ // Ray tracing includes #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RayTracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl" + +// We need this for the potential volumetric integration on camera misses +#define HAS_LIGHTLOOP // Path tracing includes #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingSampling.hlsl" -#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RayTracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl" // Input(s) float4x4 _PixelCoordToViewDirWS; @@ -24,7 +28,7 @@ int _RaytracingCameraSkyEnabled; float3 _RaytracingCameraClearColor; // DoF related parameters -float4 _PathTracedDoFConstants; // x: aperture radius, y: focus distance, zw: unused +float4 _PathTracedDoFConstants; // x: aperture radius, y: focus distance, zw: unused // Output(s) RWTexture2D _RadianceTexture; @@ -37,6 +41,33 @@ void MissCamera(inout PathIntersection pathIntersection : SV_RayPayload) SampleSkyTexture(WorldRayDirection(), 0.0, 0).xyz : _RaytracingCameraClearColor * GetInverseCurrentExposureMultiplier(); ApplyFogAttenuation(WorldRayOrigin(), WorldRayDirection(), pathIntersection.value); + + if (_EnableVolumetricFog && _RaytracingMinRecursion <= 1) + { + float3 envValue = pathIntersection.value; + + // Generate a 4D unit-square sample for this depth, from our QMC sequence + float4 inputSample = GetSample4D(pathIntersection.pixelCoord, _RaytracingSampleIndex, 0); + + // Compute volumetric scattering + pathIntersection.value = 0.0; + pathIntersection.t = FLT_MAX; + float pdf = 1.0; + bool sampleLocalLights; + if (SampleVolumeScatteringPosition(inputSample.w, pathIntersection.t, pdf, sampleLocalLights)) + { + ComputeVolumeScattering(pathIntersection, inputSample.xyz, sampleLocalLights); + + // Apply the pdf + pathIntersection.value /= pdf; + + // Apply volumetric attenuation + ApplyFogAttenuation(WorldRayOrigin(), WorldRayDirection(), pathIntersection.t, pathIntersection.value); + } + + // Reinject the environment value + pathIntersection.value += envValue; + } } [shader("miss")] diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingSampling.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingSampling.hlsl index f0b1c0f4e1c..b7bf648cb5a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingSampling.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingSampling.hlsl @@ -11,6 +11,20 @@ float GetSample(uint2 coord, uint index, uint dim) return GetBNDSequenceSample(coord, index, dim); } +float4 GetSample4D(uint2 coord, uint index, uint dim) +{ + // If we go past the number of stored samples per dim, just shift all to the next pair of dimensions + dim += (index / 256) * 2; + + float4 sample; + sample.x = GetBNDSequenceSample(coord, index, dim); + sample.y = GetBNDSequenceSample(coord, index, dim + 1); + sample.z = GetBNDSequenceSample(coord, index, dim + 2); + sample.w = GetBNDSequenceSample(coord, index, dim + 3); + + return sample; +} + bool RussianRouletteTest(float threshold, float value, float rand, out float factor, bool skip = false) { if (skip || value >= threshold) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl new file mode 100644 index 00000000000..0048f86ea36 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl @@ -0,0 +1,181 @@ +#ifndef UNITY_PATH_TRACING_VOLUME_INCLUDED +#define UNITY_PATH_TRACING_VOLUME_INCLUDED + +#ifdef HAS_LIGHTLOOP +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingLight.hlsl" +#endif + +float ComputeHeightFogMultiplier(float height) +{ + return ComputeHeightFogMultiplier(height, _HeightFogBaseHeight, _HeightFogExponents); +} + +bool SampleVolumeScatteringPosition(inout float sample, inout float t, inout float pdf, out bool sampleLocalLights) +{ + sampleLocalLights = false; + + if (!_FogEnabled || !_EnableVolumetricFog) + return false; + + // This will determin the interval in which volumetric scattering can occur + float tMin, tMax; + float pdfVol = 1.0; + float tFog = min(t, _MaxFogDistance); + +#ifdef HAS_LIGHTLOOP + float localWeight = GetLocalLightsInterval(WorldRayOrigin(), WorldRayDirection(), tMin, tMax); + + if (localWeight < 0.0) + return false; + + sampleLocalLights = sample < localWeight; + if (sampleLocalLights) + { + tMax = min(tMax, tFog); + if (tMin >= tMax) + return false; + + sample /= localWeight; + pdfVol *= localWeight; + } + else + { + tMin = 0.0; + tMax = tFog; + + sample -= localWeight; + sample /= 1.0 - localWeight; + pdfVol *= 1.0 - localWeight; + } +#else + tMin = 0.0; + tMax = tFog; +#endif + + // FIXME: not quite sure what the sigmaS, sigmaT values are supposed to be... + const float sigmaS = (t == FLT_MAX) ? 1.0 : Luminance(_HeightFogBaseScattering.xyz); + const float sigmaT = _HeightFogBaseExtinction; + const float transmittanceMax = exp(-tMax * sigmaT); + + const float pdfNoVolA = 1.0 - sigmaS; + const float pdfNoVolB = sigmaS * transmittanceMax; + const float pdfNoVol = pdfNoVolA + pdfNoVolB; + pdfVol *= 1.0 - pdfNoVol; + + if (sample >= sigmaS) + { + // Re-scale the sample + sample -= sigmaS; + sample /= 1.0 - sigmaS; + + // Set the pdf + pdf *= pdfNoVol; + + return false; + } + + // Re-scale the sample + sample /= sigmaS; + + // Evaluate the length to a potential volume scattering event + if (-log(1.0 - sample) / sigmaT >= tMax) + { + // Re-scale the sample + sample -= 1.0 - transmittanceMax; + sample /= transmittanceMax; + + // Set the pdf + pdf *= pdfNoVol; + + return false; + } + + if (sampleLocalLights) + { + // Re-scale the sample + sample /= 1.0 - transmittanceMax; + + // Linear sampling + float deltaT = tMax - tMin; + t = tMin + sample * deltaT; + + // Set the pdf + pdf *= pdfVol / deltaT; + } + else + { + // Re-scale the sample (and offset it so that we sample between tMin and tMax) + const float transmittanceMin = exp(-tMin * sigmaT); + float transmittanceRatio = (transmittanceMin - transmittanceMax) / (1.0 - transmittanceMax); + + // Log sampling + sample = 1.0 - transmittanceMin + sample * transmittanceRatio; + + float transmittance = 1.0 - sample; + t = -log(transmittance) / sigmaT; + + // Set the pdf + pdf *= pdfVol * sigmaT * transmittance / transmittanceRatio; + } + + return true; +} + +// Function responsible for volume scattering +void ComputeVolumeScattering(inout PathIntersection pathIntersection : SV_RayPayload, float3 inputSample, bool sampleLocalLights) +{ + // Reset the ray intersection color, which will store our final result + pathIntersection.value = 0.0; + +#ifdef HAS_LIGHTLOOP + + // Grab depth information + uint currentDepth = _RaytracingMaxRecursion - pathIntersection.remainingDepth; + + // Check if we want to compute direct and emissive lighting for current depth + bool computeDirect = currentDepth >= _RaytracingMinRecursion - 1; + + // Compute the scattering position + float3 scatteringPosition = WorldRayOrigin() + pathIntersection.t * WorldRayDirection(); + + // Create the list of active lights + LightList lightList = CreateLightList(scatteringPosition, sampleLocalLights); + + // Bunch of variables common to material and light sampling + float pdf; + float3 value; + + RayDesc ray; + ray.Origin = scatteringPosition; + ray.TMin = 0.0; + + PathIntersection nextPathIntersection; + + // Light sampling + if (computeDirect) + { + if (SampleLights(lightList, inputSample.xyz, scatteringPosition, 0.0, ray.Direction, value, pdf, ray.TMax)) + { + // FIXME: Apply phase function and divide by pdf (only isotropic for now, and not sure about sigmaS value) + value *= _HeightFogBaseScattering.xyz * ComputeHeightFogMultiplier(scatteringPosition.y) * INV_FOUR_PI / pdf; + + if (Luminance(value) > 0.001) + { + // Shoot a transmission ray (to mark it as such, purposedly set remaining depth to an invalid value) + nextPathIntersection.remainingDepth = _RaytracingMaxRecursion + 1; + ray.TMax -= _RaytracingRayBias; + nextPathIntersection.value = 1.0; + + // FIXME: For the time being, we choose not to apply any back/front-face culling for shadows, will possibly change in the future + TraceRay(_RaytracingAccelerationStructure, RAY_FLAG_ACCEPT_FIRST_HIT_AND_END_SEARCH | RAY_FLAG_FORCE_NON_OPAQUE | RAY_FLAG_SKIP_CLOSEST_HIT_SHADER, + RAYTRACINGRENDERERFLAG_CAST_SHADOW, 0, 1, 1, ray, nextPathIntersection); + + pathIntersection.value += value * nextPathIntersection.value; + } + } + } + +#endif // HAS_LIGHTLOOP +} + +#endif // UNITY_PATH_TRACING_VOLUME_INCLUDED diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl.meta new file mode 100644 index 00000000000..8a69440686d --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: e7afdfa6d79198541bc5a99fd0d71575 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl index d9aa3b3d322..16e5b49854c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl @@ -1,5 +1,5 @@ -#ifndef UNITY_RAY_TRACING_VOLUME_INCLUDED -#define UNITY_RAY_TRACING_VOLUME_INCLUDED +#ifndef UNITY_ATMOSPHERIC_SCATTERING_RAY_TRACING_INCLUDED +#define UNITY_ATMOSPHERIC_SCATTERING_RAY_TRACING_INCLUDED #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/AtmosphericScattering.hlsl" @@ -7,10 +7,15 @@ void ApplyFogAttenuation(float3 origin, float3 direction, float t, inout float3 { if (_FogEnabled) { - float dist = min(t, _MaxFogDistance); + float dist = t; // FIXME: This gives a better match with the raster version... + //float dist = min(t, _MaxFogDistance); float absFogBaseHeight = GetAbsolutePositionWS(float3(0.0, _HeightFogBaseHeight, 0.0)).y; float fogTransmittance = TransmittanceHeightFog(_HeightFogBaseExtinction, absFogBaseHeight, _HeightFogExponents, direction.y, origin.y, dist); - float3 fogColor = useFogColor ? GetFogColor(-direction, dist) : 0.0; + + // This is designed to match the raster volumes... even though I'm not sure why it's working that way + float3 fogColor = useFogColor && !_EnableVolumetricFog ? + GetFogColor(-direction, dist) * _HeightFogBaseScattering.xyz / _HeightFogBaseExtinction : + 0.0; value = lerp(fogColor, value, fogTransmittance); } } @@ -22,8 +27,13 @@ void ApplyFogAttenuation(float3 origin, float3 direction, inout float3 value) float dist = min(_MipFogFar, _MaxFogDistance); float absFogBaseHeight = GetAbsolutePositionWS(float3(0.0, _HeightFogBaseHeight, 0.0)).y; float fogTransmittance = TransmittanceHeightFog(_HeightFogBaseExtinction, absFogBaseHeight, _HeightFogExponents, direction.y, origin.y, dist); - value = lerp(GetFogColor(-direction, dist), value, fogTransmittance); + + // This is designed to match the raster volumes... even though I'm not sure why it's working that way + float3 fogColor = !_EnableVolumetricFog ? + GetFogColor(-direction, dist) * _HeightFogBaseScattering.xyz / _HeightFogBaseExtinction : + 0.0; + value = lerp(fogColor, value, fogTransmittance); } } -#endif // UNITY_RAY_TRACING_VOLUME_INCLUDED +#endif // UNITY_ATMOSPHERIC_SCATTERING_RAY_TRACING_INCLUDED diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingSampling.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingSampling.hlsl index 054ab42dd40..02ab9bfc027 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingSampling.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingSampling.hlsl @@ -21,13 +21,13 @@ float2 ScramblingValueFloat2(uint2 pixelCoord) uint ScramblingValueUInt(uint2 pixelCoord) { pixelCoord = pixelCoord & 255; - return clamp((uint)(_ScramblingTexture[uint2(pixelCoord.x, pixelCoord.y)].x * 256.0f), 0, 255); + return clamp((uint)(_ScramblingTexture[uint2(pixelCoord.x, pixelCoord.y)].x * 256.0), 0, 255); } uint2 ScramblingValueUInt2(uint2 pixelCoord) { pixelCoord = pixelCoord & 255; - return clamp((uint2)(_ScramblingTexture[uint2(pixelCoord.x, pixelCoord.y)] * 256.0f), uint2(0,0), uint2(255, 255)); + return clamp((uint2)(_ScramblingTexture[uint2(pixelCoord.x, pixelCoord.y)] * 256.0), uint2(0,0), uint2(255, 255)); } // Wrapper to sample the scrambled low Low-Discrepancy sequence (returns a float) @@ -49,7 +49,7 @@ uint GetLDSequenceSampleUInt(uint sampleIndex, uint sampleDimension) // sampleDimension = sampleDimension & 255; // Fetch the sequence value and return it - return clamp((uint)(_OwenScrambledTexture[uint2(sampleDimension, sampleIndex)] * 256.0f), 0, 255); + return clamp((uint)(_OwenScrambledTexture[uint2(sampleDimension, sampleIndex)] * 256.0), 0, 255); } // This is an implementation of the method from the paper @@ -63,17 +63,18 @@ float GetBNDSequenceSample(uint2 pixelCoord, uint sampleIndex, uint sampleDimens // xor index based on optimized ranking uint rankingIndex = (pixelCoord.x + pixelCoord.y * 128) * 8 + (sampleDimension & 7); - uint rankedSampleIndex = sampleIndex ^ clamp((uint)(_RankingTileXSPP[uint2(rankingIndex & 127, rankingIndex / 128)] * 256.0f), 0, 255); + uint rankedSampleIndex = sampleIndex ^ clamp((uint)(_RankingTileXSPP[uint2(rankingIndex & 127, rankingIndex / 128)] * 256.0), 0, 255); // fetch value in sequence - uint value = clamp((uint)(_OwenScrambledTexture[uint2(sampleDimension, rankedSampleIndex.x)] * 256.0f), 0, 255); + uint value = clamp((uint)(_OwenScrambledTexture[uint2(sampleDimension, rankedSampleIndex.x)] * 256.0), 0, 255); // If the dimension is optimized, xor sequence value based on optimized scrambling uint scramblingIndex = (pixelCoord.x + pixelCoord.y * 128) * 8 + (sampleDimension & 7); - value = value ^ clamp((uint)(_ScramblingTileXSPP[uint2(scramblingIndex & 127, scramblingIndex / 128)] * 256.0f), 0, 255); + float scramblingValue = min(_ScramblingTileXSPP[uint2(scramblingIndex & 127, scramblingIndex / 128)], 0.999); + value = value ^ uint(scramblingValue * 256.0); - // convert to float and return - return (0.5f + value) / 256.0f; + // Convert to float (to avoid the same 1/256th quantization everywhere, we jitter by the pixel scramblingValue) + return (scramblingValue + value) / 256.0; } #endif // UNITY_RAYTRACING_SAMPLING_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 e72fca5c172..ddb3c207fa3 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 @@ -1,15 +1,13 @@ // Ray tracing includes #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingFragInputs.hlsl" -#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Shadows/SphericalQuad.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RayTracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl" // Path tracing includes #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingIntersection.hlsl" -#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RayTracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl" - +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl" #ifdef HAS_LIGHTLOOP #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingLight.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingSampling.hlsl" -#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitPathTracing.hlsl" #endif float PowerHeuristic(float f, float b) @@ -22,20 +20,9 @@ float3 GetPositionBias(float3 geomNormal, float bias, bool below) return geomNormal * (below ? -bias : bias); } -// Generic function that handles the reflection code -[shader("closesthit")] -void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, AttributeData attributeData : SV_IntersectionAttributes) +// Function responsible for surface scattering +void ComputeSurfaceScattering(inout PathIntersection pathIntersection : SV_RayPayload, AttributeData attributeData : SV_IntersectionAttributes, float4 inputSample) { - // Always set the new t value - pathIntersection.t = RayTCurrent(); - - // If the max depth has been reached, bail out - if (!pathIntersection.remainingDepth) - { - pathIntersection.value = 0.0; - return; - } - // The first thing that we should do is grab the intersection vertex IntersectionVertex currentVertex; GetCurrentIntersectionVertex(attributeData, currentVertex); @@ -57,7 +44,7 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu // Make sure to add the additional travel distance pathIntersection.cone.width += pathIntersection.t * abs(pathIntersection.cone.spreadAngle); -#ifndef HAS_LIGHTLOOP +#ifdef EMISSIVE_ONLY // This is quick and dirty way to avoid double contribution from light meshes if (currentDepth) pathIntersection.cone.spreadAngle = -1.0; @@ -86,17 +73,11 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu // Compute the bsdf data BSDFData bsdfData = ConvertSurfaceDataToBSDFData(posInput.positionSS, surfaceData); -#ifdef HAS_LIGHTLOOP +#ifndef EMISSIVE_ONLY // Let's compute the world space position (the non-camera relative one if camera relative rendering is enabled) float3 shadingPosition = GetAbsolutePositionWS(fragInput.positionRWS); - // Generate the new sample (following values of the sequence) - float3 inputSample = 0.0; - inputSample.x = GetSample(pathIntersection.pixelCoord, _RaytracingSampleIndex, 4 * currentDepth); - inputSample.y = GetSample(pathIntersection.pixelCoord, _RaytracingSampleIndex, 4 * currentDepth + 1); - inputSample.z = GetSample(pathIntersection.pixelCoord, _RaytracingSampleIndex, 4 * currentDepth + 2); - // Get current path throughput float3 pathThroughput = pathIntersection.value; @@ -124,7 +105,7 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu // Light sampling if (computeDirect) { - if (SampleLights(lightList, inputSample, rayDescriptor.Origin, mtlData.bsdfData.normalWS, rayDescriptor.Direction, value, pdf, rayDescriptor.TMax)) + if (SampleLights(lightList, inputSample.xyz, rayDescriptor.Origin, mtlData.bsdfData.normalWS, rayDescriptor.Direction, value, pdf, rayDescriptor.TMax)) { EvaluateMaterial(mtlData, rayDescriptor.Direction, mtlResult); @@ -147,7 +128,7 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu } // Material sampling - if (SampleMaterial(mtlData, inputSample, rayDescriptor.Direction, mtlResult)) + if (SampleMaterial(mtlData, inputSample.xyz, rayDescriptor.Direction, mtlResult)) { // Compute overall material value and pdf pdf = mtlResult.diffPdf + mtlResult.specPdf; @@ -158,9 +139,8 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu // Apply Russian roulette to our path const float rrThreshold = 0.2 + 0.1 * _RaytracingMaxRecursion; float rrFactor, rrValue = Luminance(pathThroughput); - float rrSample = GetSample(pathIntersection.pixelCoord, _RaytracingSampleIndex, 4 * currentDepth + 3); - if (RussianRouletteTest(rrThreshold, rrValue, rrSample, rrFactor, !currentDepth)) + if (RussianRouletteTest(rrThreshold, rrValue, inputSample.w, rrFactor, !currentDepth)) { bool isSampleBelow = IsBelow(mtlData, rayDescriptor.Direction); @@ -206,7 +186,7 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu } } -#else // HAS_LIGHTLOOP +#else // EMISSIVE_ONLY pathIntersection.value = (!currentDepth || computeDirect) ? bsdfData.color * GetInverseCurrentExposureMultiplier() + builtinData.emissiveColor : 0.0; @@ -229,8 +209,61 @@ void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, Attribu } #endif +#endif // EMISSIVE_ONLY +} + +// Generic function that handles one scattering event (a vertex along the full path), can be either: +// - Surface scattering +// - Volume scattering +[shader("closesthit")] +void ClosestHit(inout PathIntersection pathIntersection : SV_RayPayload, AttributeData attributeData : SV_IntersectionAttributes) +{ + // Always set the new t value + pathIntersection.t = RayTCurrent(); + + // If the max depth has been reached, bail out + if (!pathIntersection.remainingDepth) + { + pathIntersection.value = 0.0; + return; + } + + // Grab depth information + int currentDepth = _RaytracingMaxRecursion - pathIntersection.remainingDepth; + + float4 inputSample = 0.0; + +#ifdef HAS_LIGHTLOOP + + float pdf = 1.0; + bool sampleLocalLights, sampleVolume = false; + + if (currentDepth >= 0) + { + // Generate a 4D unit-square sample for this depth, from our QMC sequence + inputSample = GetSample4D(pathIntersection.pixelCoord, _RaytracingSampleIndex, 4 * currentDepth); + + // For the time being, we test for volumetric scattering only on camera rays + if (!currentDepth) + sampleVolume = SampleVolumeScatteringPosition(inputSample.w, pathIntersection.t, pdf, sampleLocalLights); + } + + if (sampleVolume) + ComputeVolumeScattering(pathIntersection, inputSample.xyz, sampleLocalLights); + else + ComputeSurfaceScattering(pathIntersection, attributeData, inputSample); + + // Apply the volume/surface pdf + pathIntersection.value /= pdf; + +#else // HAS_LIGHTLOOP + + ComputeSurfaceScattering(pathIntersection, attributeData, inputSample); + #endif // HAS_LIGHTLOOP + // Apply volumetric attenuation + bool computeDirect = currentDepth >= _RaytracingMinRecursion - 1; ApplyFogAttenuation(WorldRayOrigin(), WorldRayDirection(), pathIntersection.t, pathIntersection.value, computeDirect); if (currentDepth) From 2a3f1ab26f9f3f3037fdfc2558ce03bf33df0fd2 Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Wed, 23 Sep 2020 15:33:22 +0200 Subject: [PATCH 02/16] Minor fixes on cone region of spot lights. --- .../PathTracing/Shaders/PathTracingLight.hlsl | 6 +++--- .../PathTracing/Shaders/PathTracingVolume.hlsl | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) 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 9f098d34e11..5371921e3fa 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 @@ -77,8 +77,8 @@ bool IsPointLightActive(LightData lightData, float3 position, float3 normal) // Offset the light position towards the back, to account for the radius, // then check whether we are still within the dilated cone angle - float sqSinAngle = 1.0 - Sq(lightData.angleOffset / lightData.angleScale); - float3 lightOffset = sqrt(lightData.size.x / sqSinAngle) * lightData.forward; + float cosTheta2 = Sq(lightData.angleOffset / lightData.angleScale); + float3 lightOffset = sqrt(lightData.size.x * cosTheta2 / (1.0 - cosTheta2)) * lightData.forward; float lightCos = dot(normalize(lightVec + lightOffset), lightData.forward); return lightCos * lightData.angleScale + lightData.angleOffset > 0.0; @@ -535,7 +535,7 @@ bool GetPointLightInterval(LightData lightData, float3 rayOrigin, float3 rayDire float cosTheta2 = Sq(lightData.angleOffset / lightData.angleScale); // Offset light origin to account for light radius - lightVec += sqrt(lightData.size.x / (1.0 - cosTheta2)) * lightData.forward; + lightVec += sqrt(lightData.size.x * cosTheta2 / (1.0 - cosTheta2)) * lightData.forward; float LdotV = dot(lightData.forward, lightVec); float a = Sq(LdotD) - cosTheta2; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl index 0048f86ea36..f4d9dd25543 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl @@ -53,7 +53,7 @@ bool SampleVolumeScatteringPosition(inout float sample, inout float t, inout flo #endif // FIXME: not quite sure what the sigmaS, sigmaT values are supposed to be... - const float sigmaS = (t == FLT_MAX) ? 1.0 : Luminance(_HeightFogBaseScattering.xyz); + const float sigmaS = (t == FLT_MAX) ? 1.0 : sqrt(Luminance(_HeightFogBaseScattering.xyz)); const float sigmaT = _HeightFogBaseExtinction; const float transmittanceMax = exp(-tMax * sigmaT); From 7732187ed5bacb77e92e72b967be978da54e950a Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Wed, 23 Sep 2020 16:14:20 +0200 Subject: [PATCH 03/16] Re-added mistakenly removed headers from the PT pass of Unlit & Lit. --- .../Runtime/Material/LayeredLit/LayeredLit.shader | 3 ++- .../Runtime/Material/Lit/Lit.shader | 3 ++- .../Runtime/Material/Unlit/Unlit.shader | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader index 3b7cfb0e785..6c58fd2191e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLit.shader @@ -1120,12 +1120,13 @@ Shader "HDRP/LayeredLit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" #define HAS_LIGHTLOOP - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/LayeredLit/LayeredLitData.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitPathTracing.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader index 3f2034812da..7fc3c8a0791 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader @@ -1159,12 +1159,13 @@ Shader "HDRP/Lit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/Lighting.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/ShaderPass/LitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoopDef.hlsl" #define HAS_LIGHTLOOP - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitData.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitPathTracing.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader index d46c2ddb409..f03c42ad1bd 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader @@ -616,10 +616,10 @@ Shader "HDRP/Unlit" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/ShaderVariablesRaytracing.hlsl" + #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/ShaderPass/UnlitSharePass.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingIntersection.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.hlsl" - #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitData.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl" From 8e6ef8207fe3973a2b6d52223602be43dba48c46 Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Wed, 23 Sep 2020 17:57:34 +0200 Subject: [PATCH 04/16] Added clamping on cam ray misses with vol scattering. --- .../PathTracing/Shaders/PathTracingMain.raytrace | 5 +++++ .../PathTracing/Shaders/PathTracingVolume.hlsl | 8 +------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingMain.raytrace b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingMain.raytrace index d120b0507b0..5376eea60b5 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingMain.raytrace +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingMain.raytrace @@ -67,6 +67,11 @@ void MissCamera(inout PathIntersection pathIntersection : SV_RayPayload) // Reinject the environment value pathIntersection.value += envValue; + + // Bias the result (making it too dark), but reduces fireflies a lot + float intensity = Luminance(pathIntersection.value) * GetCurrentExposureMultiplier(); + if (intensity > _RaytracingIntensityClamp) + pathIntersection.value *= _RaytracingIntensityClamp / intensity; } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl index f4d9dd25543..c26f5599a11 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl @@ -104,18 +104,12 @@ bool SampleVolumeScatteringPosition(inout float sample, inout float t, inout flo } else { - // Re-scale the sample (and offset it so that we sample between tMin and tMax) - const float transmittanceMin = exp(-tMin * sigmaT); - float transmittanceRatio = (transmittanceMin - transmittanceMax) / (1.0 - transmittanceMax); - // Log sampling - sample = 1.0 - transmittanceMin + sample * transmittanceRatio; - float transmittance = 1.0 - sample; t = -log(transmittance) / sigmaT; // Set the pdf - pdf *= pdfVol * sigmaT * transmittance / transmittanceRatio; + pdf *= pdfVol * sigmaT * transmittance; } return true; From e55ab5b1bae8dd4b5a63527e1e5f3adaa22bf11f Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Wed, 23 Sep 2020 19:33:20 +0200 Subject: [PATCH 05/16] Minor tweaks. --- .../PathTracing/Shaders/PathTracingLight.hlsl | 4 ++-- .../PathTracing/Shaders/PathTracingMain.raytrace | 5 ----- .../PathTracing/Shaders/PathTracingVolume.hlsl | 4 ++++ .../RenderPipelineResources/Foliage Diffusion Profile.asset | 6 ++---- 4 files changed, 8 insertions(+), 11 deletions(-) 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 5371921e3fa..aed4e281691 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 @@ -78,7 +78,7 @@ bool IsPointLightActive(LightData lightData, float3 position, float3 normal) // Offset the light position towards the back, to account for the radius, // then check whether we are still within the dilated cone angle float cosTheta2 = Sq(lightData.angleOffset / lightData.angleScale); - float3 lightOffset = sqrt(lightData.size.x * cosTheta2 / (1.0 - cosTheta2)) * lightData.forward; + float3 lightOffset = sqrt(lightData.size.x / (1.0 - cosTheta2)) * lightData.forward; float lightCos = dot(normalize(lightVec + lightOffset), lightData.forward); return lightCos * lightData.angleScale + lightData.angleOffset > 0.0; @@ -535,7 +535,7 @@ bool GetPointLightInterval(LightData lightData, float3 rayOrigin, float3 rayDire float cosTheta2 = Sq(lightData.angleOffset / lightData.angleScale); // Offset light origin to account for light radius - lightVec += sqrt(lightData.size.x * cosTheta2 / (1.0 - cosTheta2)) * lightData.forward; + lightVec += sqrt(lightData.size.x / (1.0 - cosTheta2)) * lightData.forward; float LdotV = dot(lightData.forward, lightVec); float a = Sq(LdotD) - cosTheta2; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingMain.raytrace b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingMain.raytrace index 5376eea60b5..d120b0507b0 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingMain.raytrace +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingMain.raytrace @@ -67,11 +67,6 @@ void MissCamera(inout PathIntersection pathIntersection : SV_RayPayload) // Reinject the environment value pathIntersection.value += envValue; - - // Bias the result (making it too dark), but reduces fireflies a lot - float intensity = Luminance(pathIntersection.value) * GetCurrentExposureMultiplier(); - if (intensity > _RaytracingIntensityClamp) - pathIntersection.value *= _RaytracingIntensityClamp / intensity; } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl index c26f5599a11..9a6cf4279a2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/PathTracing/Shaders/PathTracingVolume.hlsl @@ -104,6 +104,10 @@ bool SampleVolumeScatteringPosition(inout float sample, inout float t, inout flo } else { + // Let's (avoid very low transmittance, for robustness sake (minor bias) + if (transmittanceMax < 0.01) + sample = sample * 0.99 / (1.0 - transmittanceMax); + // Log sampling float transmittance = 1.0 - sample; t = -log(transmittance) / sigmaT; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset index 1e0cf48c755..8d905cd333a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset @@ -12,15 +12,13 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: b2686e09ec7aef44bad2843e4416f057, type: 3} m_Name: Foliage Diffusion Profile m_EditorClassIdentifier: + m_Version: 1 profile: - name: Foliage scatteringDistance: {r: 0.7568628, g: 0.7019608, b: 0.24313727, a: 1} transmissionTint: {r: 1, g: 1, b: 1, a: 1} texturingMode: 0 transmissionMode: 1 thicknessRemap: {x: 0, y: 0.2873168} - worldScale: 1 + worldScale: 0.01 ior: 1.4 hash: 1081692787 - m_Version: 1 - profiles: [] From 0b7c2e21525ad702326f1819a970680b01b1c92f Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Fri, 25 Sep 2020 18:22:36 +0200 Subject: [PATCH 06/16] Added support for box and pyramid point lights. --- .../PathTracing/Shaders/PathTracingLight.hlsl | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) 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 fb03efd30c0..a4ea5493241 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 @@ -63,13 +63,33 @@ bool IsPointLightActive(LightData lightData, float3 position, float3 normal) if (lightTangentDist * abs(lightTangentDist) > lightData.size.x) return false; - // Offset the light position towards the back, to account for the radius, - // then check whether we are still within the dilated cone angle - float sqSinAngle = 1.0 - Sq(lightData.angleOffset / lightData.angleScale); - float3 lightOffset = sqrt(lightData.size.x / sqSinAngle) * lightData.forward; - float lightCos = dot(normalize(lightVec + lightOffset), lightData.forward); + // If this is an omni-directional point light, we're done + if (lightData.lightType == GPULIGHTTYPE_POINT) + return true; + + // Check that we are on the right side of the light plane + float z = dot(lightVec, lightData.forward); + if (z < 0.0) + return false; + + if (lightData.lightType == GPULIGHTTYPE_SPOT) + { + // Offset the light position towards the back, to account for the radius, + // then check whether we are still within the dilated cone angle + float sinTheta2 = 1.0 - Sq(lightData.angleOffset / lightData.angleScale); + float3 lightRadiusOffset = sqrt(lightData.size.x / sinTheta2) * lightData.forward; + float lightCos = dot(normalize(lightVec + lightRadiusOffset), lightData.forward); + + return lightCos * lightData.angleScale + lightData.angleOffset > 0.0; + } + + // Our light type is either BOX or PYRAMID + float x = abs(dot(lightVec, lightData.right)); + float y = abs(dot(lightVec, lightData.up)); - return lightCos * lightData.angleScale + lightData.angleOffset > 0.0; + return (lightData.lightType == GPULIGHTTYPE_PROJECTOR_BOX) ? + x < 1 && y < 1 : // BOX + x < z && y < z; // PYRAMID } bool IsDistantLightActive(DirectionalLightData lightData, float3 normal) From 68ad43ec8899ac81682819f343c0688087ea1832 Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Fri, 2 Oct 2020 11:38:54 +0200 Subject: [PATCH 07/16] Updated changelog. --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index eed9eae1dd7..b30572a740f 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added Simple mode to Earth Preset for PBR Sky - Added the export of normals during the prepass for shadow matte for proper SSAO calculation. - Added the usage of SSAO for shadow matte unlit shader graph. +- Added support for 'Pyramid' and 'Box' spot light shapes in path tracing. ### Fixed - Fixed several issues with physically-based DoF (TAA ghosting of the CoC buffer, smooth layer transitions, etc) From cdcdd65e58ca2446e645a5fa6d491bd958810bfd Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Fri, 2 Oct 2020 16:32:36 +0200 Subject: [PATCH 08/16] Added vol light intensity multiplier support. --- .../PathTracing/Shaders/PathTracingLight.hlsl | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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 cba27f38ccf..f9b19a2ab07 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 @@ -320,6 +320,9 @@ bool SampleLights(LightList lightList, if (!GetLightCount(lightList)) return false; + // Are we lighting a volume or a surface? + bool isVolume = !any(normal); + if (PickLocalLights(lightList, inputSample.z)) { // Pick a local light from the list @@ -339,7 +342,7 @@ bool SampleLights(LightList lightList, dist = sqrt(sqDist); outgoingDir /= dist; - if (any(normal) && dot(normal, outgoingDir) < 0.001) + if (!isVolume && dot(normal, outgoingDir) < 0.001) return false; float cosTheta = -dot(outgoingDir, lightData.forward); @@ -373,13 +376,16 @@ bool SampleLights(LightList lightList, pdf = DELTA_PDF; } - if (any(normal) && dot(normal, outgoingDir) < 0.001) + if (!isVolume && dot(normal, outgoingDir) < 0.001) return false; value = GetPunctualEmission(lightData, outgoingDir, dist) * pdf; pdf = GetLocalLightWeight(lightList) * pdf; } + if (isVolume) + value *= lightData.volumetricLightDimmer; + #ifndef LIGHT_EVALUATION_NO_HEIGHT_FOG ApplyFogAttenuation(position, outgoingDir, dist, value); #endif @@ -406,11 +412,14 @@ bool SampleLights(LightList lightList, outgoingDir = -lightData.forward; } - if (any(normal) && dot(normal, outgoingDir) < 0.001) + if (!isVolume && (dot(normal, outgoingDir) < 0.001)) return false; dist = FLT_INF; + if (isVolume) + value *= lightData.volumetricLightDimmer; + #ifndef LIGHT_EVALUATION_NO_HEIGHT_FOG ApplyFogAttenuation(position, outgoingDir, value); #endif @@ -524,6 +533,9 @@ bool GetSphereInterval(float3 lightToPos, float radius, float3 rayDirection, out bool GetRectAreaLightInterval(LightData lightData, float3 rayOrigin, float3 rayDirection, out float tMin, out float tMax) { + if (lightData.volumetricLightDimmer < 0.001) + return false; + float3 lightVec = rayOrigin - GetAbsolutePositionWS(lightData.positionRWS); if (!GetSphereInterval(lightVec, lightData.range, rayDirection, tMin, tMax)) @@ -541,6 +553,9 @@ bool GetRectAreaLightInterval(LightData lightData, float3 rayOrigin, float3 rayD bool GetPointLightInterval(LightData lightData, float3 rayOrigin, float3 rayDirection, out float tMin, out float tMax) { + if (lightData.volumetricLightDimmer < 0.001) + return false; + float3 lightVec = rayOrigin - GetAbsolutePositionWS(lightData.positionRWS); if (!GetSphereInterval(lightVec, lightData.range, rayDirection, tMin, tMax)) From 1d5560d4bd2c42f490e2f5b0fae37f5c2abde9f6 Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Wed, 7 Oct 2020 03:13:21 +0200 Subject: [PATCH 09/16] Added support for box and pyramid spot lights. --- .../PathTracing/Shaders/PathTracingLight.hlsl | 196 +++++++++++------- .../AtmosphericScatteringRayTracing.hlsl | 1 - .../ShaderPass/ShaderPassPathTracing.hlsl | 7 +- 3 files changed, 131 insertions(+), 73 deletions(-) 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 2e19fc2d2d5..e379319de58 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 @@ -39,21 +39,21 @@ struct LightList bool IsRectAreaLightActive(LightData lightData, float3 position, float3 normal) { - float3 lightVec = position - lightData.positionRWS; + float3 lightToPosition = position - lightData.positionRWS; #ifndef USE_LIGHT_CLUSTER // Check light range first - if (Length2(lightVec) > Sq(lightData.range)) + if (Length2(lightToPosition) > Sq(lightData.range)) return false; #endif // Check that the shading position is in front of the light - float lightCos = dot(lightVec, lightData.forward); + float lightCos = dot(lightToPosition, lightData.forward); if (lightCos < 0.0) return false; // Check that at least part of the light is above the tangent plane - float lightTangentDist = dot(normal, lightVec); + float lightTangentDist = dot(normal, lightToPosition); if (4.0 * lightTangentDist * abs(lightTangentDist) > Sq(lightData.size.x) + Sq(lightData.size.y)) return false; @@ -62,16 +62,16 @@ bool IsRectAreaLightActive(LightData lightData, float3 position, float3 normal) bool IsPointLightActive(LightData lightData, float3 position, float3 normal) { - float3 lightVec = position - lightData.positionRWS; + float3 lightToPosition = position - lightData.positionRWS; #ifndef USE_LIGHT_CLUSTER // Check light range first - if (Length2(lightVec) > Sq(lightData.range)) + if (Length2(lightToPosition) > Sq(lightData.range)) return false; #endif // Check that at least part of the light is above the tangent plane - float lightTangentDist = dot(normal, lightVec); + float lightTangentDist = dot(normal, lightToPosition); if (lightTangentDist * abs(lightTangentDist) > lightData.size.x) return false; @@ -80,7 +80,7 @@ bool IsPointLightActive(LightData lightData, float3 position, float3 normal) return true; // Check that we are on the right side of the light plane - float z = dot(lightVec, lightData.forward); + float z = dot(lightToPosition, lightData.forward); if (z < 0.0) return false; @@ -90,18 +90,18 @@ bool IsPointLightActive(LightData lightData, float3 position, float3 normal) // then check whether we are still within the dilated cone angle float sinTheta2 = 1.0 - Sq(lightData.angleOffset / lightData.angleScale); float3 lightRadiusOffset = sqrt(lightData.size.x / sinTheta2) * lightData.forward; - float lightCos = dot(normalize(lightVec + lightRadiusOffset), lightData.forward); + float lightCos = dot(normalize(lightToPosition + lightRadiusOffset), lightData.forward); return lightCos * lightData.angleScale + lightData.angleOffset > 0.0; } // Our light type is either BOX or PYRAMID - float x = abs(dot(lightVec, lightData.right)); - float y = abs(dot(lightVec, lightData.up)); + float x = abs(dot(lightToPosition, lightData.right)); + float y = abs(dot(lightToPosition, lightData.up)); return (lightData.lightType == GPULIGHTTYPE_PROJECTOR_BOX) ? - x < 1 && y < 1 : // BOX - x < z && y < z; // PYRAMID + x < 1.0 && y < 1.0 : // BOX + x < z && y < z; // PYRAMID } bool IsDistantLightActive(DirectionalLightData lightData, float3 normal) @@ -148,11 +148,7 @@ if (withLocal) const LightData lightData = _LightDatasRT[i]; #endif - if (IsMatchingLightLayer(lightData.lightLayers, lightLayers) -#ifndef _SURFACE_TYPE_TRANSPARENT - && IsPointLightActive(lightData, position, normal) -#endif - ) + if (IsMatchingLightLayer(lightData.lightLayers, lightLayers) && IsPointLightActive(lightData, position, normal)) list.localIndex[list.localPointCount++] = i; } @@ -165,11 +161,7 @@ if (withLocal) const LightData lightData = _LightDatasRT[i]; #endif - if (IsMatchingLightLayer(lightData.lightLayers, lightLayers) -#ifndef _SURFACE_TYPE_TRANSPARENT - && IsRectAreaLightActive(lightData, position, normal) -#endif - ) + if (IsMatchingLightLayer(lightData.lightLayers, lightLayers) && IsRectAreaLightActive(lightData, position, normal)) list.localIndex[list.localCount++] = i; } } @@ -181,11 +173,7 @@ if (withDistant) { for (i = 0; i < _DirectionalLightCount && list.distantCount < MAX_DISTANT_LIGHT_COUNT; i++) { - if (IsMatchingLightLayer(_DirectionalLightDatas[i].lightLayers, lightLayers) -#ifndef _SURFACE_TYPE_TRANSPARENT - && IsDistantLightActive(_DirectionalLightDatas[i], normal) -#endif - ) + if (IsMatchingLightLayer(_DirectionalLightDatas[i].lightLayers, lightLayers) && IsDistantLightActive(_DirectionalLightDatas[i], normal)) list.distantIndex[list.distantCount++] = i; } } @@ -417,8 +405,8 @@ bool SampleLights(LightList lightList, dist = FLT_INF; - if (isVolume) - value *= lightData.volumetricLightDimmer; + if (isVolume) + value *= lightData.volumetricLightDimmer; #ifndef LIGHT_EVALUATION_NO_HEIGHT_FOG ApplyFogAttenuation(position, outgoingDir, value); @@ -515,11 +503,11 @@ bool SolvePoly2(float a, float b, float c, out float x1, out float x2) return true; } -bool GetSphereInterval(float3 lightToPos, float radius, float3 rayDirection, out float tMin, out float tMax) +bool GetSphereInterval(float3 lightToRayOrigin, float radius, float3 rayDirection, out float tMin, out float tMax) { // We consider Direction to be normalized => a = 1 - float b = 2.0 * dot(rayDirection, lightToPos); - float c = Length2(lightToPos) - Sq(radius); + float b = 2.0 * dot(rayDirection, lightToRayOrigin); + float c = Length2(lightToRayOrigin) - Sq(radius); float t1, t2; if (!SolvePoly2(1.0, b, c, t1, t2)) @@ -536,13 +524,13 @@ bool GetRectAreaLightInterval(LightData lightData, float3 rayOrigin, float3 rayD if (lightData.volumetricLightDimmer < 0.001) return false; - float3 lightVec = rayOrigin - GetAbsolutePositionWS(lightData.positionRWS); + float3 lightToRayOrigin = rayOrigin - lightData.positionRWS; - if (!GetSphereInterval(lightVec, lightData.range, rayDirection, tMin, tMax)) + if (!GetSphereInterval(lightToRayOrigin, lightData.range, rayDirection, tMin, tMax)) return false; float LdotD = dot(lightData.forward, rayDirection); - float t = -dot(lightData.forward, lightVec) / LdotD; + float t = -dot(lightData.forward, lightToRayOrigin) / LdotD; if (LdotD > 0.0) tMin = max(tMin, t); else @@ -551,63 +539,129 @@ bool GetRectAreaLightInterval(LightData lightData, float3 rayOrigin, float3 rayD return tMin < tMax; } +void Sort(inout float x, inout float y) +{ + if (x > y) + { + float tmp = x; + x = y; + y = tmp; + } +} + +void GetFrontInterval(float oz, float dz, float t1, float t2, inout float tMin, inout float tMax) +{ + bool t1Valid = oz + t1 * dz > 0.0; + bool t2Valid = oz + t2 * dz > 0.0; + + if (t1Valid) + { + if (t2Valid) + { + tMin = max(t1, tMin); + tMax = min(t2, tMax); + } + else + { + tMax = min(t1, tMax); + } + } + else + { + tMin = t2Valid ? max(t2, tMin) : tMax; + } +} + bool GetPointLightInterval(LightData lightData, float3 rayOrigin, float3 rayDirection, out float tMin, out float tMax) { if (lightData.volumetricLightDimmer < 0.001) return false; - float3 lightVec = rayOrigin - GetAbsolutePositionWS(lightData.positionRWS); + float3 lightToRayOrigin = rayOrigin - lightData.positionRWS; - if (!GetSphereInterval(lightVec, lightData.range, rayDirection, tMin, tMax)) + if (!GetSphereInterval(lightToRayOrigin, lightData.range, rayDirection, tMin, tMax)) return false; // This is just a point light (no spot cone angle) if (lightData.lightType == GPULIGHTTYPE_POINT) return true; - // Intersect our ray with the spot light's cone - float LdotD = dot(lightData.forward, rayDirection); - float cosTheta2 = Sq(lightData.angleOffset / lightData.angleScale); + // We are dealing with either a cone, a pyramid or a box + float3 localOrigin = float3(dot(lightToRayOrigin, lightData.right), + dot(lightToRayOrigin, lightData.up), + dot(lightToRayOrigin, lightData.forward)); + float3 localDirection = float3(dot(rayDirection, lightData.right), + dot(rayDirection, lightData.up), + dot(rayDirection, lightData.forward)); - // Offset light origin to account for light radius - lightVec += sqrt(lightData.size.x / (1.0 - cosTheta2)) * lightData.forward; - float LdotV = dot(lightData.forward, lightVec); + if (lightData.lightType == GPULIGHTTYPE_PROJECTOR_BOX) + { + // Compute intersections with planes x=-1 and x=1 + float tx1 = (-1.0 - localOrigin.x) / localDirection.x; + float tx2 = (1.0 - localOrigin.x) / localDirection.x; + Sort(tx1, tx2); - float a = Sq(LdotD) - cosTheta2; - float b = 2.0 * (LdotD * LdotV - dot(rayDirection, lightVec) * cosTheta2); - float c = Sq(LdotV) - Length2(lightVec) * cosTheta2; + // Compute intersections with planes y=-1 and y=1 + float ty1 = (-1.0 - localOrigin.y) / localDirection.y; + float ty2 = (1.0 - localOrigin.y) / localDirection.y; + Sort(ty1, ty2); - float t1, t2; - if (!SolvePoly2(a, b, c, t1, t2)) - return false; + // Compute intersection with plane z=0 + float tz = -localOrigin.z / localDirection.z; - // Check validity of the intersections (we want them with the front cone only) - bool t1Valid = dot(lightVec + t1 * rayDirection, lightData.forward) > 0.0; - bool t2Valid = dot(lightVec + t2 * rayDirection, lightData.forward) > 0.0; + float t1 = max(tx1, ty1); + float t2 = min(tx2, ty2); - if (t1Valid) + // Check validity of the intersections (we want them only in front of the light) + bool t1Valid = localOrigin.z + t1 * localDirection.z > 0.0; + bool t2Valid = localOrigin.z + t2 * localDirection.z > 0.0; + + tMin = t1Valid ? max(t1, tMin) : tz; + tMax = t2Valid ? min(t2, tMax) : tz; + } + else if (lightData.lightType == GPULIGHTTYPE_PROJECTOR_PYRAMID) { - if (t2Valid) - { - tMin = max(t1, tMin); - tMax = min(t2, tMax); - } - else + // Compute intersections with planes x=-z and x=z + float tx1 = -(localOrigin.x - localOrigin.z) / (localDirection.x - localDirection.z); + float tx2 = -(localOrigin.x + localOrigin.z) / (localDirection.x + localDirection.z); + Sort(tx1, tx2); + + // Check validity of the intersections (we want them only in front of the light) + GetFrontInterval(localOrigin.z, localDirection.z, tx1, tx2, tMin, tMax); + + if (tMin < tMax) { - tMax = min(t1, tMax); + // Compute intersections with planes y=-1 and y=1 + float ty1 = -(localOrigin.y - localOrigin.z) / (localDirection.y - localDirection.z); + float ty2 = -(localOrigin.y + localOrigin.z) / (localDirection.y + localDirection.z); + Sort(ty1, ty2); + + // Check validity of the intersections (we want them only in front of the light) + GetFrontInterval(localOrigin.z, localDirection.z, ty1, ty2, tMin, tMax); } } - else + else // lightData.lightType == GPULIGHTTYPE_SPOT { - if (t2Valid) - { - tMin = max(t2, tMin); - } - else - { - tMin = 0.0; - tMax = 0.0; - } + float cosTheta2 = Sq(lightData.angleOffset / lightData.angleScale); + + // Offset light origin to account for light radius + localOrigin.z += sqrt(lightData.size.x / (1.0 - cosTheta2)); + + // Account for non-normalized local basis + float3 normalizedLocalOrigin = float3(localOrigin.x / Length2(lightData.right), + localOrigin.y / Length2(lightData.up), + localOrigin.z); + + float a = Sq(localDirection.z) - cosTheta2; + float b = 2.0 * (localOrigin.z * localDirection.z - dot(normalizedLocalOrigin, localDirection) * cosTheta2); + float c = Sq(localOrigin.z) - dot(normalizedLocalOrigin, localOrigin) * cosTheta2; + + float t1, t2; + if (!SolvePoly2(a, b, c, t1, t2)) + return false; + + // Check validity of the intersections (we want them only in front of the light) + GetFrontInterval(localOrigin.z, localDirection.z, t1, t2, tMin, tMax); } return tMin < tMax; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl index 667fa98f04f..8a2acb84d2a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl @@ -9,7 +9,6 @@ void ApplyFogAttenuation(float3 origin, float3 direction, float t, inout float3 { float dist = t; // FIXME: This gives a better match with the raster version... //float dist = min(t, _MaxFogDistance); - //float absFogBaseHeight = GetAbsolutePositionWS(float3(0.0, _HeightFogBaseHeight, 0.0)).y; float absFogBaseHeight = _HeightFogBaseHeight; float fogTransmittance = TransmittanceHeightFog(_HeightFogBaseExtinction, absFogBaseHeight, _HeightFogExponents, direction.y, origin.y, dist); 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 6bc05405516..5f7b811078b 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 @@ -89,7 +89,12 @@ void ComputeSurfaceScattering(inout PathIntersection pathIntersection : SV_RayPa if (CreateMaterialData(pathIntersection, builtinData, bsdfData, shadingPosition, inputSample.z, mtlData)) { // Create the list of active lights - LightList lightList = CreateLightList(shadingPosition, mtlData.bsdfData.geomNormalWS, builtinData.renderingLayers); + #ifdef _SURFACE_TYPE_TRANSPARENT + float3 lightNormal = 0.0; + #else + float3 lightNormal = mtlData.bsdfData.geomNormalWS; + #endif + LightList lightList = CreateLightList(shadingPosition, lightNormal, builtinData.renderingLayers); // Bunch of variables common to material and light sampling float pdf; From be0380966941f4a47f3ab8b5742bad0aff7257e4 Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Wed, 7 Oct 2020 10:35:36 +0200 Subject: [PATCH 10/16] Updated Changelog. --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 37ae46288bc..b592e2b0d7a 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added support for camera relative ray tracing (and keeping non-camera relative ray tracing working) - Added a rough refraction option on planar reflections. - Added scalability settings for the planar reflection resolution. +- Added fog volumetric scattering support for path tracing. ### Fixed - Fixed several issues with physically-based DoF (TAA ghosting of the CoC buffer, smooth layer transitions, etc) From 00f7a5808805e2710b6e67d7f256f7a40d4c702c Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Wed, 14 Oct 2020 01:11:25 +0200 Subject: [PATCH 11/16] Reverted unwanted changes to diffusion profile asset. --- .../RenderPipelineResources/Foliage Diffusion Profile.asset | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset index 8d905cd333a..94194cc3da9 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset @@ -12,13 +12,15 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: b2686e09ec7aef44bad2843e4416f057, type: 3} m_Name: Foliage Diffusion Profile m_EditorClassIdentifier: - m_Version: 1 profile: + name: Foliage scatteringDistance: {r: 0.7568628, g: 0.7019608, b: 0.24313727, a: 1} transmissionTint: {r: 1, g: 1, b: 1, a: 1} texturingMode: 0 transmissionMode: 1 thicknessRemap: {x: 0, y: 0.2873168} - worldScale: 0.01 + worldScale: 1 ior: 1.4 hash: 1081692787 + m_Version: 1 + profiles: [] \ No newline at end of file From 909f261dbc0c6f8298671efa7b5eedbcfa0ea599 Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Wed, 14 Oct 2020 01:12:45 +0200 Subject: [PATCH 12/16] ... --- .../RenderPipelineResources/Foliage Diffusion Profile.asset | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset index 94194cc3da9..20bb0559819 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset @@ -23,4 +23,5 @@ MonoBehaviour: ior: 1.4 hash: 1081692787 m_Version: 1 - profiles: [] \ No newline at end of file + profiles: [] + \ No newline at end of file From 6718735938f54f13d5d47f9b77b022c10d811327 Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Wed, 14 Oct 2020 01:14:24 +0200 Subject: [PATCH 13/16] FFS --- .../RenderPipelineResources/Foliage Diffusion Profile.asset | 1 - 1 file changed, 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset index 20bb0559819..1e0cf48c755 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Foliage Diffusion Profile.asset @@ -24,4 +24,3 @@ MonoBehaviour: hash: 1081692787 m_Version: 1 profiles: [] - \ No newline at end of file From e65de57da134885cb939e0a5ad6a98631dc67c3c Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Wed, 14 Oct 2020 15:45:20 +0200 Subject: [PATCH 14/16] Added better path tracing support in shader graph. --- .../Editor/Material/Lit/ShaderGraph/HDLitSubTarget.cs | 1 + .../Editor/Material/ShaderGraph/HDShaderPasses.cs | 4 ++-- .../Editor/Material/ShaderGraph/HDSubTarget.cs | 3 +++ .../Editor/Material/ShaderGraph/HDTarget.cs | 2 ++ .../Runtime/Material/Lit/Lit.shader | 2 +- .../Runtime/Material/Unlit/Unlit.shader | 4 ++-- .../RenderPipeline/Accumulation/SubFrameManager.cs | 2 +- .../RenderPipeline/HDRenderPipeline.RenderGraph.cs | 2 +- .../Shaders/Common/AtmosphericScatteringRayTracing.hlsl | 3 +-- .../RenderPipeline/ShaderPass/ShaderPassPathTracing.hlsl | 8 ++++---- 10 files changed, 18 insertions(+), 13 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.cs index cc309066451..c23dfe93630 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/Lit/ShaderGraph/HDLitSubTarget.cs @@ -46,6 +46,7 @@ public HDLitData litData protected override string postDecalsInclude => "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitDecalData.hlsl"; protected override ShaderID shaderID => HDShaderUtils.ShaderID.SG_Lit; protected override string raytracingInclude => CoreIncludes.kLitRaytracing; + protected override string pathtracingInclude => CoreIncludes.kLitPathtracing; protected override FieldDescriptor subShaderField => new FieldDescriptor(kSubShader, "Lit Subshader", ""); protected override string subShaderInclude => CoreIncludes.kLit; diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs index 9806b902065..7df16453b37 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDShaderPasses.cs @@ -1115,8 +1115,8 @@ IncludeCollection GenerateIncludes() // Each material has a specific hlsl file that should be included pre-graph and holds the lighting model includes.Add(CoreIncludes.kPassPlaceholder, IncludeLocation.Pregraph); - // We need to then include the ray tracing missing bits for the lighting models (based on which lighting model) - includes.Add(CoreIncludes.kRaytracingPlaceholder, IncludeLocation.Pregraph); + // We need to then include path tracing support for the material + includes.Add(CoreIncludes.kPathtracingPlaceholder, IncludeLocation.Pregraph); includes.Add(CoreIncludes.CoreUtility); includes.Add(CoreIncludes.kRaytracingCommon, IncludeLocation.Pregraph); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs index a3955bc346c..523ec270bb8 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs @@ -50,6 +50,7 @@ public SystemData systemData protected virtual string postDecalsInclude => null; protected virtual string raytracingInclude => null; + protected virtual string pathtracingInclude => null; protected virtual bool supportPathtracing => false; protected virtual bool supportRaytracing => false; @@ -148,6 +149,8 @@ protected SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor subShader include.descriptor.value = postDecalsInclude; if (include.descriptor.value == CoreIncludes.kRaytracingPlaceholder) include.descriptor.value = raytracingInclude; + if (include.descriptor.value == CoreIncludes.kPathtracingPlaceholder) + include.descriptor.value = pathtracingInclude; if (!String.IsNullOrEmpty(include.descriptor.value)) finalIncludes.Add(include.descriptor.value, include.descriptor.location, include.fieldConditions); diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs index 4abc3a71e97..100773e4678 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDTarget.cs @@ -872,6 +872,7 @@ static class CoreIncludes public const string kRaytracingIntersectionGBuffer = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingIntersectonGBuffer.hlsl"; public const string kRaytracingIntersectionSubSurface = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/SubSurface/RayTracingIntersectionSubSurface.hlsl"; public const string kLitRaytracing = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitRaytracing.hlsl"; + public const string kLitPathtracing = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/LitPathTracing.hlsl"; public const string kUnlitRaytracing = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/UnlitRaytracing.hlsl"; public const string kFabricRaytracing = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Fabric/FabricRaytracing.hlsl"; public const string kStackLitRaytracing = "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/StackLit/StackLitRaytracing.hlsl"; @@ -911,6 +912,7 @@ static class CoreIncludes public const string kPassPlaceholder = "Pass Include Placeholder, replace me !"; public const string kPostDecalsPlaceholder = "After Decal Include Placeholder, replace me !"; public const string kRaytracingPlaceholder = "Raytracing Include Placeholder, replace me !"; + public const string kPathtracingPlaceholder = "Pathtracing Include Placeholder, replace me !"; // Public Postgraph Pass public const string kPassLightTransport = "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassLightTransport.hlsl"; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader index 5f4227f7ca5..295c7ad07bd 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.shader @@ -1152,7 +1152,7 @@ Shader "HDRP/Lit" #define SHADERPASS SHADERPASS_PATH_TRACING - // This is just because it need to be defined, shadow maps are not used. + // This is just because it needs to be defined, shadow maps are not used. #define SHADOW_LOW #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingMacros.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader index 574753f66ae..f0f445e1324 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Material/Unlit/Unlit.shader @@ -605,9 +605,9 @@ Shader "HDRP/Unlit" #pragma raytracing surface_shader #define SHADERPASS SHADERPASS_PATH_TRACING - + + #define SHADER_UNLIT #define HAS_LIGHTLOOP // Used when computing volumetric scattering - #define EMISSIVE_ONLY #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RaytracingMacros.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs index 640f179af0b..5bfd3ce6183 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs @@ -311,7 +311,7 @@ RenderAccumulationParameters PrepareRenderAccumulationParameters(HDCamera hdCame void RenderAccumulation(HDCamera hdCamera, RTHandle inputTexture, RTHandle outputTexture, bool needExposure, CommandBuffer cmd) { - // Grab the history buffer (hijack the reflections one) + // Grab the history buffer RTHandle history = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.PathTracing) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.PathTracing, PathTracingHistoryBufferAllocatorFunction, 1); 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 5d82c8928aa..acf95336207 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 @@ -1379,7 +1379,7 @@ void RenderAccumulation(RenderGraph renderGraph, HDCamera hdCamera, TextureHandl { using (var builder = renderGraph.AddRenderPass("Render Accumulation", out var passData)) { - // Grab the history buffer (hijack the reflections one) + // Grab the history buffer TextureHandle history = renderGraph.ImportTexture(hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.PathTracing) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.PathTracing, PathTracingHistoryBufferAllocatorFunction, 1)); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl index 8a2acb84d2a..52beb2ad5a8 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/AtmosphericScatteringRayTracing.hlsl @@ -7,8 +7,7 @@ void ApplyFogAttenuation(float3 origin, float3 direction, float t, inout float3 { if (_FogEnabled) { - float dist = t; // FIXME: This gives a better match with the raster version... - //float dist = min(t, _MaxFogDistance); + float dist = min(t, _MaxFogDistance); float absFogBaseHeight = _HeightFogBaseHeight; float fogTransmittance = TransmittanceHeightFog(_HeightFogBaseExtinction, absFogBaseHeight, _HeightFogExponents, direction.y, origin.y, dist); 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 5f7b811078b..9a468a33ff4 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 @@ -44,7 +44,7 @@ void ComputeSurfaceScattering(inout PathIntersection pathIntersection : SV_RayPa // Make sure to add the additional travel distance pathIntersection.cone.width += pathIntersection.t * abs(pathIntersection.cone.spreadAngle); -#ifdef EMISSIVE_ONLY +#ifdef SHADER_UNLIT // This is quick and dirty way to avoid double contribution from light meshes if (currentDepth) pathIntersection.cone.spreadAngle = -1.0; @@ -73,7 +73,7 @@ void ComputeSurfaceScattering(inout PathIntersection pathIntersection : SV_RayPa // Compute the bsdf data BSDFData bsdfData = ConvertSurfaceDataToBSDFData(posInput.positionSS, surfaceData); -#ifndef EMISSIVE_ONLY +#ifndef SHADER_UNLIT // Let's compute the world space position (the non-camera relative one if camera relative rendering is enabled) float3 shadingPosition = fragInput.positionRWS; @@ -191,7 +191,7 @@ void ComputeSurfaceScattering(inout PathIntersection pathIntersection : SV_RayPa } } -#else // EMISSIVE_ONLY +#else // SHADER_UNLIT pathIntersection.value = (!currentDepth || computeDirect) ? bsdfData.color * GetInverseCurrentExposureMultiplier() + builtinData.emissiveColor : 0.0; @@ -214,7 +214,7 @@ void ComputeSurfaceScattering(inout PathIntersection pathIntersection : SV_RayPa } #endif -#endif // EMISSIVE_ONLY +#endif // SHADER_UNLIT } // Generic function that handles one scattering event (a vertex along the full path), can be either: From 2db05b4ef873966805e3fd9c3a063af697fe4a44 Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Wed, 14 Oct 2020 16:40:21 +0200 Subject: [PATCH 15/16] Fix PT directional light activation for null radius. --- .../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 e379319de58..419793ad3cd 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 @@ -106,7 +106,7 @@ bool IsPointLightActive(LightData lightData, float3 position, float3 normal) bool IsDistantLightActive(DirectionalLightData lightData, float3 normal) { - return dot(normal, lightData.forward) < sin(lightData.angularDiameter * 0.5); + return dot(normal, lightData.forward) <= sin(lightData.angularDiameter * 0.5); } LightList CreateLightList(float3 position, float3 normal, uint lightLayers, bool withLocal = true, bool withDistant = true) From 9c52ff423da372d80a896ff17b75b9581eb6b9fb Mon Sep 17 00:00:00 2001 From: Emmanuel Turquin Date: Wed, 14 Oct 2020 16:45:25 +0200 Subject: [PATCH 16/16] Updated png reference images, to account for sampling seq changes. --- .../None/1000_RaytracingQualityKeyword_PathTracer_Default.png | 4 ++-- .../Direct3D12/None/201_LargeAmbientOcclusion.png | 4 ++-- .../Direct3D12/None/202_LargeAmbientOcclusionDenoised.png | 4 ++-- .../Direct3D12/None/203_LocalAmbientOcclusionNoisy.png | 4 ++-- .../Direct3D12/None/204_LocalAmbientOcclusionDenoised.png | 4 ++-- .../Direct3D12/None/3001_AreaShadowsDeferred.png | 4 ++-- .../WindowsEditor/Direct3D12/None/3001_AreaShadowsForward.png | 4 ++-- .../Direct3D12/None/301_GlobalIlluminationPerfFull.png | 4 ++-- .../None/301_GlobalIlluminationPerfFullLightLayers.png | 4 ++-- .../Direct3D12/None/302_GlobalIlluminationPerfHalf.png | 4 ++-- .../Direct3D12/None/303_GlobalIlluminationQuality.png | 4 ++-- .../Direct3D12/None/304_GlobalIlluminationDenoised1.png | 4 ++-- .../Direct3D12/None/305_GlobalIlluminationDenoisedHalf1.png | 4 ++-- .../Direct3D12/None/306_GlobalIlluminationDenoised2.png | 4 ++-- .../Direct3D12/None/307_GlobalIlluminationFog.png | 4 ++-- .../Linear/WindowsEditor/Direct3D12/None/5001_PathTracing.png | 4 ++-- .../WindowsEditor/Direct3D12/None/5002_PathTracing_GI.png | 4 ++-- .../Direct3D12/None/5003_PathTracing_transparency.png | 4 ++-- .../Direct3D12/None/5004_PathTracing_arealight.png | 4 ++-- .../WindowsEditor/Direct3D12/None/5005_PathTracing_Fog.png | 4 ++-- .../WindowsEditor/Direct3D12/None/5006_PathTracing_DoF.png | 4 ++-- .../Direct3D12/None/5007_PathTracing_Materials_SG_Lit.png | 4 ++-- .../Direct3D12/None/5007_PathTracing_Materials_SG_Unlit.png | 4 ++-- .../Direct3D12/None/5008_PathTracing_NormalMapping.png | 4 ++-- .../Direct3D12/None/801_SubSurfaceScatteringDeferred.png | 4 ++-- .../Direct3D12/None/802_SubSurfaceScatteringForward.png | 4 ++-- 26 files changed, 52 insertions(+), 52 deletions(-) diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1000_RaytracingQualityKeyword_PathTracer_Default.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1000_RaytracingQualityKeyword_PathTracer_Default.png index 3db1baabbd5..510a66bdae4 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1000_RaytracingQualityKeyword_PathTracer_Default.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/1000_RaytracingQualityKeyword_PathTracer_Default.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f5bd13fedf367db42d061aabe39a07b8d5e557a87fef0be971e1460c784692d7 -size 594092 +oid sha256:08b57a5a118c31de7a0b88921a96aab1fe7f029eeed3e4bcd5e04d13067cb1a5 +size 594548 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/201_LargeAmbientOcclusion.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/201_LargeAmbientOcclusion.png index 1bdfaaec477..ea63eaa50a4 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/201_LargeAmbientOcclusion.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/201_LargeAmbientOcclusion.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fb8fee11b0ada86c65e99dba270c1aa81bd35df939c9625a76a53e762ef366f0 -size 144623 +oid sha256:005b80510b9a3462ab0bfe7e03db36bb1f17b70dffd75f8a92efc18bde862cf1 +size 144719 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/202_LargeAmbientOcclusionDenoised.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/202_LargeAmbientOcclusionDenoised.png index d72bc39c3f3..45226939484 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/202_LargeAmbientOcclusionDenoised.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/202_LargeAmbientOcclusionDenoised.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d194f86e32e2ff59bc5133f0769983712b60686d67b92acc4ce87edcd6d2fe0e -size 400073 +oid sha256:b4380020c4b82672470fdc0d1eeaaf4cfde0756d91409bbf21f947194ea2c487 +size 400036 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/203_LocalAmbientOcclusionNoisy.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/203_LocalAmbientOcclusionNoisy.png index 289ebdb3412..cf05f36faa9 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/203_LocalAmbientOcclusionNoisy.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/203_LocalAmbientOcclusionNoisy.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7dd05d2ea697861ac8dc2fd49c35a5e9cc294d83474bdfa2ce78bdea54851827 -size 206914 +oid sha256:67a7152f306af4a22ce50281d593efa8b6cbd726266f3ade39c1afd1f0124b02 +size 208153 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/204_LocalAmbientOcclusionDenoised.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/204_LocalAmbientOcclusionDenoised.png index ca95392224e..a71162e101a 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/204_LocalAmbientOcclusionDenoised.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/204_LocalAmbientOcclusionDenoised.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:fb3ee4209d2280e044ce4491ea54a8c3f5cd3532d94806e38617e077a160c597 -size 424915 +oid sha256:befef94c5b5411a3aa4f7da787f2aa3f7382aea45f2084b1b52a68be245aaec1 +size 424552 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/3001_AreaShadowsDeferred.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/3001_AreaShadowsDeferred.png index 131933e7cc9..bb2845cea23 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/3001_AreaShadowsDeferred.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/3001_AreaShadowsDeferred.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4da9432871cff1ff6d92d06d67f49a19bda814e2e022d03745823426968bf4d5 -size 337460 +oid sha256:9ac30ae9e08fce97ca1f4c37617a41eaa2c7bef065cf6ddb0cc0fd34052672fa +size 307716 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/3001_AreaShadowsForward.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/3001_AreaShadowsForward.png index 1fd1b5b13ed..68cbd4efaec 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/3001_AreaShadowsForward.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/3001_AreaShadowsForward.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:77776f4f55f0e7197d09c55da2216083b287f450934148af0aba71c1a5e50f67 -size 320508 +oid sha256:713377f7ff07d60ac32f829d400e3868b5e32bc4d3c2ac79b99f173db11b706f +size 289480 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFull.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFull.png index f927ab6ba75..ab6d72c0dae 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFull.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFull.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5846572053f940582ebc5adda12e7d7410795e71373201c95b1378341392dac8 -size 598630 +oid sha256:c655691ed383fb158ab471098f0aad6cc7385a3ba7d3692f3914edace75dca50 +size 598547 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFullLightLayers.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFullLightLayers.png index 1a252036f66..ab6d72c0dae 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFullLightLayers.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/301_GlobalIlluminationPerfFullLightLayers.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6507e48fadc4fdb35f84b137b4674a9b96f151066c4ddcd42f6c16759b38808d -size 667745 +oid sha256:c655691ed383fb158ab471098f0aad6cc7385a3ba7d3692f3914edace75dca50 +size 598547 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/302_GlobalIlluminationPerfHalf.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/302_GlobalIlluminationPerfHalf.png index c41c7c2e831..0dbb0395035 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/302_GlobalIlluminationPerfHalf.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/302_GlobalIlluminationPerfHalf.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5b936997e46e2e41449a619fbffc5a9aee214b92945e9bf9fc078d90ab6a0c9f -size 624479 +oid sha256:9cb1fb2427e4854c0c30351482e3c99ff0edada20b3a2a6c01ada2607e1ac46b +size 624661 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/303_GlobalIlluminationQuality.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/303_GlobalIlluminationQuality.png index 31f29eea6a7..78b2ac8e756 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/303_GlobalIlluminationQuality.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/303_GlobalIlluminationQuality.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9ddbd4ab23be231ede3c8cf2566700d55b0a719204cb2491f7414e8691bdf5d5 -size 677232 +oid sha256:09b6e43ad80f7beff782b6e67981de705b0c14ef35cb5fe7258a17e17d89e29d +size 677024 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/304_GlobalIlluminationDenoised1.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/304_GlobalIlluminationDenoised1.png index f849c1f1d7f..84e8ed383cb 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/304_GlobalIlluminationDenoised1.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/304_GlobalIlluminationDenoised1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d262e35ccb13b1105b1ae00ab6d5fd2a2ca1fa1ef86fe4a79dbed548ed5d112f -size 565063 +oid sha256:922f6befa2d70e8afb61ac7f10dc035055f13853ea47eca47da8df64283d0432 +size 564560 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/305_GlobalIlluminationDenoisedHalf1.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/305_GlobalIlluminationDenoisedHalf1.png index 8c10957aeb1..979c4de3300 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/305_GlobalIlluminationDenoisedHalf1.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/305_GlobalIlluminationDenoisedHalf1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8e0d78e4c4befff7685ef00bea4630cd3486881216079b8a4779bd5dbe842808 -size 289541 +oid sha256:5983b6337c4900f9b94676562b372d4aa3d14b1363d07f87d10b877b802ccad8 +size 289175 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/306_GlobalIlluminationDenoised2.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/306_GlobalIlluminationDenoised2.png index f5564677c4d..44b0e2cfee6 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/306_GlobalIlluminationDenoised2.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/306_GlobalIlluminationDenoised2.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:204f3f31529fcf62cdeeb6ad951864bce13a58014f504712e02917d46b71e332 -size 460144 +oid sha256:6f94089dc0b62d35bf073dcc8f7f71dbc4a2a8e3d1b512fadfe7e255c4072f2e +size 459411 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/307_GlobalIlluminationFog.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/307_GlobalIlluminationFog.png index 0eb4b6b2e07..5eff2c6b3a8 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/307_GlobalIlluminationFog.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/307_GlobalIlluminationFog.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:05cdaa37a837309e0fb7746e928c8ea619340a3e36e085533eadc3126df3186e -size 431316 +oid sha256:06166c87865fbc833efbc4498f658a44d331b9de2a5d4249613824c9eb9954ba +size 430880 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5001_PathTracing.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5001_PathTracing.png index 42836bef2d4..0bfaf7bc659 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5001_PathTracing.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5001_PathTracing.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c41d3240cc1a61873e44b11f3727b02b0796b9a15a21ad28e1b072c3cf53ba30 -size 594955 +oid sha256:0b3ee66248fbe0d0efd11cc27f449512991d36bbdcd4cf67f81bbccca3be19e9 +size 595123 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5002_PathTracing_GI.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5002_PathTracing_GI.png index adf0c6cee30..ee899eccdb8 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5002_PathTracing_GI.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5002_PathTracing_GI.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:63c58974f312e0e16055ba4dc98a89c98b5a5f63806947f884b59d5e1d9c5047 -size 145858 +oid sha256:fee73f0f3bf5fc030aa4cc5eead6f4a851ff5aa10d77a46a5141f7508836d361 +size 146056 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5003_PathTracing_transparency.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5003_PathTracing_transparency.png index d373862e147..dd69b1a423e 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5003_PathTracing_transparency.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5003_PathTracing_transparency.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:94b15e3f04fea302b44fc24973c3271fb93cc193ebf512e5c66783eccf5af478 -size 816378 +oid sha256:dc38ea9ae91b8ee15318c1e62948c30de267fa3f18ee31988c31db3c543ea21b +size 816829 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5004_PathTracing_arealight.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5004_PathTracing_arealight.png index f1ba4805c13..852f39a720f 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5004_PathTracing_arealight.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5004_PathTracing_arealight.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:4a812bb84d35db5575a730bf753959063c30fb21921a003cb988e2aa4cd711e2 -size 171136 +oid sha256:dc1a2173a5e35298161b2811511f154e81dfbab75fcc30d40a044b0f4f099477 +size 171551 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5005_PathTracing_Fog.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5005_PathTracing_Fog.png index 3acc0724825..7280ba1fb75 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5005_PathTracing_Fog.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5005_PathTracing_Fog.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:81d3b4dad30801833f6b3cff97726c9084e95b5bcfa2ece8e1fe347525901609 -size 333921 +oid sha256:c395ab1c4b6490a09e59522d463fd2a64f4ada3a5de95d9a1b1f15f6085fb2fe +size 333531 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5006_PathTracing_DoF.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5006_PathTracing_DoF.png index 9ce3911c7b6..9f615549e99 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5006_PathTracing_DoF.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5006_PathTracing_DoF.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:293a4b4420f4ff33b083bae34a3b9bff853b3b29e5d06a9308aa365781280882 -size 582743 +oid sha256:f0d0ee8840624839d44e46b03d4fb624dee9a7f889b78a064f21f788bb734d01 +size 582422 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5007_PathTracing_Materials_SG_Lit.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5007_PathTracing_Materials_SG_Lit.png index 3c2b86b7071..39f79b0fa2f 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5007_PathTracing_Materials_SG_Lit.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5007_PathTracing_Materials_SG_Lit.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:808bf35a152913a2050829abb22df34d4796b0ee997ec0f4f5fd5633a5eb7675 -size 512130 +oid sha256:725c3b80a3d7276968bffc9deebe56c019716790f524c0473b66d68a339e6915 +size 425111 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5007_PathTracing_Materials_SG_Unlit.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5007_PathTracing_Materials_SG_Unlit.png index ed7cff3fef2..5a5c85e20aa 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5007_PathTracing_Materials_SG_Unlit.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5007_PathTracing_Materials_SG_Unlit.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:75313116e965773d446e8027dc8e7ff244114bfef9cdc226fd7da260394de554 -size 55192 +oid sha256:7a3e844edd86e44eac4f82b651d4aed5bcd51a8a5037ff43c2da12d61e4b386c +size 54995 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5008_PathTracing_NormalMapping.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5008_PathTracing_NormalMapping.png index f316c3dcf34..79b3d5676c3 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5008_PathTracing_NormalMapping.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5008_PathTracing_NormalMapping.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:689f1b1db73d6d3a717d4d615403f7977e64bdf1f505e26bbb7afda54ae11d81 -size 788532 +oid sha256:988900879c0dc8e9bb026ede6039131020e69f9e13e3eb5def73d058d596717e +size 690107 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/801_SubSurfaceScatteringDeferred.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/801_SubSurfaceScatteringDeferred.png index 427767bab4d..37ba482a590 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/801_SubSurfaceScatteringDeferred.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/801_SubSurfaceScatteringDeferred.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:63310a095e4923e58f4a1171f4ed154acbdce084bc16dd9367935d4270fc74df -size 176871 +oid sha256:217eba3acb0edfb22bdb2d8c6577df54b6b27393a40b6e462092463d69bd1d10 +size 176647 diff --git a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/802_SubSurfaceScatteringForward.png b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/802_SubSurfaceScatteringForward.png index 5014a27c9a4..3f9a67bc066 100644 --- a/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/802_SubSurfaceScatteringForward.png +++ b/TestProjects/HDRP_DXR_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/802_SubSurfaceScatteringForward.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:797184bbcb6e8a3d006fff007ef081c940e078df17063ab9729d18b9df009b72 -size 176965 +oid sha256:9f9a6c32e075ae9dacc5963f642d638841e4b97763106bb2bb2b001b34de2087 +size 176239