diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 4cfad028fc0..590aa178401 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -60,6 +60,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Moved AMD FidelityFX shaders to core - Improved sampling of overlapping point/area lights in path-traced volumetric scattering (case 1358777). - Path-traced volumetric scattering now takes fog color into account, adding scattered contribution on top of the non-scattered result (cases 1346105, 1358783). +- Fixed minor readability issues in the ray tracing code. ## [12.0.0] - 2021-01-11 diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/RayBinning.compute b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/RayBinning.compute index 8e8da7df450..7c598bc9a3b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/RayBinning.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Common/RayBinning.compute @@ -6,7 +6,9 @@ #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl" #define RAY_BINNING_TILE_SIZE 16 #define BINNING_TILE_SIZE 16 @@ -30,7 +32,7 @@ void RAY_BINNING(uint2 groupThreadId : SV_GroupThreadID, uint3 dispatchThreadId uint2 currentCoord = groupId * RAY_BINNING_TILE_SIZE + groupThreadId.xy; #if HALF_RESOLUTION - currentCoord *= 2; + currentCoord = ComputeSourceCoordinates(currentCoord, _RaytracingFrameIndex); #endif // Initialize the invalid counter to 0 diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute index d0cc852c981..e92340f37be 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingDeferred.compute @@ -30,6 +30,7 @@ #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/Common/AtmosphericScatteringRayTracing.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/RayTracingFallbackHierarchy.cs.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl" #define RAYTRACING_DEFERRED_TILE_SIZE 8 @@ -48,7 +49,7 @@ void RAYTRACING_DEFERRED(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 gro uint2 currentCoord = groupId * RAYTRACING_DEFERRED_TILE_SIZE + groupThreadId; #ifdef HALF_RESOLUTION - currentCoord *=2; + currentCoord = ComputeSourceCoordinates(currentCoord, _RaytracingFrameIndex); #endif // Initialize the output buffer @@ -71,7 +72,7 @@ void RAYTRACING_DEFERRED(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 gro float3 finalColor = 0.0f; // if the distance is exactly zero, this means we are facing an environement ray that we need to evaluate - if (rayDistance == 0.0f) + if (RayTracingGBufferIsSky(rayDistance)) { // Weight value used to do the blending float weight = 0.0; @@ -96,7 +97,7 @@ void RAYTRACING_DEFERRED(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 gro finalColor = HsvToRgb(finalColor); } } - else if (rayDistance < 0.0f) + else if (RayTracingGBufferIsUnlit(rayDistance)) { finalColor = LOAD_TEXTURE2D_X(_GBufferTexture3, currentCoord).rgb; @@ -119,7 +120,7 @@ void RAYTRACING_DEFERRED(uint3 dispatchThreadId : SV_DispatchThreadID, uint2 gro } // If the distance is negative, this means it is a sky pixel or an unlit material - if (rayDistance <= 0.0f) + if (!RayTracingGBufferIsLit(rayDistance)) { _RaytracingLitBufferRW[COORD_TEXTURE2D_X(currentCoord)] = float4(finalColor * (_RaytracingPreExposition ? 1.0 : GetInverseCurrentExposureMultiplier()), 0.0); return; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingGBuffer.raytrace b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingGBuffer.raytrace index b9a0925a9c6..bdfb1afae87 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingGBuffer.raytrace +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/Deferred/RaytracingGBuffer.raytrace @@ -58,7 +58,7 @@ uint _RayBinTileViewOffset; [shader("miss")] void MissShaderGBuffer(inout RayIntersectionGBuffer rayIntersection : SV_RayPayload) { - rayIntersection.t = 0; + rayIntersection.t = RAY_TRACING_DISTANCE_FLAG_SKY; } struct PixelCoordinates diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl index 6ae0d642877..e459aad5e90 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Raytracing/Shaders/RayTracingCommon.hlsl @@ -57,4 +57,23 @@ uint2 ComputeSourceCoordinates(uint2 halfResCoord, int frameIndex) { return halfResCoord * 2; } + +// These need to be negative for RayDistanceIndicatesHitSkyOrUnlit +#define RAY_TRACING_DISTANCE_FLAG_UNLIT -1.0 +#define RAY_TRACING_DISTANCE_FLAG_SKY 0.0 + +bool RayTracingGBufferIsUnlit(float rayDistance) +{ + return rayDistance < 0.0; +} + +bool RayTracingGBufferIsSky(float rayDistance) +{ + return rayDistance == RAY_TRACING_DISTANCE_FLAG_SKY; +} + +bool RayTracingGBufferIsLit(float rayDistance) +{ + return rayDistance > 0.0; +} #endif // RAY_TRACING_COMMON_HLSL diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingGBuffer.hlsl b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingGBuffer.hlsl index 1ebadafd26e..0774128103a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingGBuffer.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/ShaderPass/ShaderPassRaytracingGBuffer.hlsl @@ -48,7 +48,7 @@ void ClosestHitGBuffer(inout RayIntersectionGBuffer rayIntersectionGbuffer : SV_ // Then export it to the gbuffer EncodeIntoStandardGBuffer(standardLitData, rayIntersectionGbuffer.gbuffer0, rayIntersectionGbuffer.gbuffer1, rayIntersectionGbuffer.gbuffer2, rayIntersectionGbuffer.gbuffer3); - rayIntersectionGbuffer.t = standardLitData.isUnlit != 0 ? -1 : RayTCurrent(); + rayIntersectionGbuffer.t = standardLitData.isUnlit != 0 ? RAY_TRACING_DISTANCE_FLAG_UNLIT : RayTCurrent(); } // Generic function that handles the reflection code