From 5724880da612400378434dda99dfd2a9c35bd09b Mon Sep 17 00:00:00 2001 From: Pentalimbed Date: Thu, 12 Dec 2024 16:58:14 +0000 Subject: [PATCH] fix: clean up ssgi blur and upsample, change presets --- .../Shaders/ScreenSpaceGI/blur.cs.hlsl | 22 +++++++++++-------- .../Shaders/ScreenSpaceGI/common.hlsli | 7 ++++-- .../Shaders/ScreenSpaceGI/gi.cs.hlsl | 7 +++--- .../Shaders/ScreenSpaceGI/upsample.cs.hlsl | 8 +++---- src/Features/ScreenSpaceGI.cpp | 20 ++++++++++------- src/Features/ScreenSpaceGI.h | 8 +++---- 6 files changed, 41 insertions(+), 31 deletions(-) diff --git a/features/Screen Space GI/Shaders/ScreenSpaceGI/blur.cs.hlsl b/features/Screen Space GI/Shaders/ScreenSpaceGI/blur.cs.hlsl index 47eb61f36..a29ea8b22 100644 --- a/features/Screen Space GI/Shaders/ScreenSpaceGI/blur.cs.hlsl +++ b/features/Screen Space GI/Shaders/ScreenSpaceGI/blur.cs.hlsl @@ -5,6 +5,7 @@ #include "Common/FrameBuffer.hlsli" #include "Common/GBuffer.hlsli" #include "Common/Math.hlsli" +#include "Common/Random.hlsli" #include "Common/VR.hlsli" #include "ScreenSpaceGI/common.hlsli" @@ -76,6 +77,12 @@ float2x3 getKernelBasis(float3 D, float3 N, float roughness = 1.0, float anisoFa } // TODO: spinning blur +float2x2 getRotationMatrix(float noise) +{ + float2 sin_cos; + sincos(noise * Math::PI * 2, sin_cos.y, sin_cos.x); + return float2x2(sin_cos.x, sin_cos.y, -sin_cos.y, sin_cos.x); +} [numthreads(8, 8, 1)] void main(const uint2 dtid : SV_DispatchThreadID) { @@ -99,7 +106,7 @@ float2x3 getKernelBasis(float3 D, float3 N, float roughness = 1.0, float anisoFa const float2 pixelDirRBViewspaceSizeAtCenterZ = depth.xx * (eyeIndex == 0 ? NDCToViewMul.xy : NDCToViewMul.zw) * RCP_OUT_FRAME_DIM; const float worldRadius = radius * pixelDirRBViewspaceSizeAtCenterZ.x; float2x3 TvBv = getKernelBasis(normal, normal); // D = N - float halfAngle = Math::HALF_PI * .5f; + float halfAngle = Math::HALF_PI; TvBv[0] *= worldRadius; TvBv[1] *= worldRadius; @@ -139,10 +146,10 @@ float2x3 getKernelBasis(float3 D, float3 N, float roughness = 1.0, float anisoFa float2 uvSample = Stereo::ConvertToStereoUV(screenPosSample.xy, eyeIndex); uvSample = (floor(uvSample * OUT_FRAME_DIM) + 0.5) * RCP_OUT_FRAME_DIM; // Snap to the pixel centre - float depthSample = srcDepth.SampleLevel(samplerLinearClamp, uvSample * frameScale, 0); + float depthSample = srcDepth.SampleLevel(samplerPointClamp, uvSample * frameScale, RES_MIP); float3 posSample = ScreenToViewPosition(screenPosSample.xy, depthSample, eyeIndex); - float4 normalRoughnessSample = srcNormalRoughness.SampleLevel(samplerLinearClamp, uvSample * frameScale, 0); + float4 normalRoughnessSample = srcNormalRoughness.SampleLevel(samplerPointClamp, uvSample * frameScale, 0); float3 normalSample = GBuffer::DecodeNormal(normalRoughnessSample.xy); // geometry weight @@ -151,13 +158,10 @@ float2x3 getKernelBasis(float3 D, float3 N, float roughness = 1.0, float anisoFa w *= 1 - saturate(FastMath::acosFast4(saturate(dot(normalSample, normal))) / halfAngle); if (w > 1e-8) { - float4 ySample = srcIlY.SampleLevel(samplerLinearClamp, uvSample * OUT_FRAME_SCALE, 0); - float2 coCgSample = srcIlCoCg.SampleLevel(samplerLinearClamp, uvSample * OUT_FRAME_SCALE, 0); - - ySum += ySample * w; - coCgSum += coCgSample * w; + ySum += srcIlY.SampleLevel(samplerPointClamp, uvSample * OUT_FRAME_SCALE, 0) * w; + coCgSum += srcIlCoCg.SampleLevel(samplerPointClamp, uvSample * OUT_FRAME_SCALE, 0) * w; #if defined(TEMPORAL_DENOISER) - fSum += srcAccumFrames.SampleLevel(samplerLinearClamp, uvSample * OUT_FRAME_SCALE, 0) * w; + fSum += srcAccumFrames.SampleLevel(samplerPointClamp, uvSample * OUT_FRAME_SCALE, 0) * w; #endif wSum += w; } diff --git a/features/Screen Space GI/Shaders/ScreenSpaceGI/common.hlsli b/features/Screen Space GI/Shaders/ScreenSpaceGI/common.hlsli index 9e7d5d722..872825e4c 100644 --- a/features/Screen Space GI/Shaders/ScreenSpaceGI/common.hlsli +++ b/features/Screen Space GI/Shaders/ScreenSpaceGI/common.hlsli @@ -79,18 +79,21 @@ SamplerState samplerLinearClamp : register(s1); // texCoord - texture coordinate #ifdef HALF_RES -# define READ_DEPTH(tex, px) tex.Load(int3(px, 1)) +# define RES_MIP 1 +# define READ_DEPTH(tex, px) tex.Load(int3(px, RES_MIP)) # define FULLRES_LOAD(tex, px, texCoord, samp) tex.SampleLevel(samp, texCoord, 0) # define OUT_FRAME_DIM (FrameDim * 0.5) # define RCP_OUT_FRAME_DIM (RcpFrameDim * 2) # define OUT_FRAME_SCALE (frameScale * 0.5) #elif defined(QUARTER_RES) -# define READ_DEPTH(tex, px) tex.Load(int3(px, 2)) +# define RES_MIP 2 +# define READ_DEPTH(tex, px) tex.Load(int3(px, RES_MIP)) # define FULLRES_LOAD(tex, px, texCoord, samp) tex.SampleLevel(samp, texCoord, 0) # define OUT_FRAME_DIM (FrameDim * 0.25) # define RCP_OUT_FRAME_DIM (RcpFrameDim * 4) # define OUT_FRAME_SCALE (frameScale * 0.25) #else +# define RES_MIP 0 # define READ_DEPTH(tex, px) tex[px] # define FULLRES_LOAD(tex, px, texCoord, samp) tex[px] # define OUT_FRAME_DIM FrameDim diff --git a/features/Screen Space GI/Shaders/ScreenSpaceGI/gi.cs.hlsl b/features/Screen Space GI/Shaders/ScreenSpaceGI/gi.cs.hlsl index 8682e4194..3fdb2695f 100644 --- a/features/Screen Space GI/Shaders/ScreenSpaceGI/gi.cs.hlsl +++ b/features/Screen Space GI/Shaders/ScreenSpaceGI/gi.cs.hlsl @@ -217,13 +217,12 @@ void CalculateGI( if (frontBackMult > 0.f) { float3 sampleHorizonVecWS = normalize(mul(FrameBuffer::CameraViewInverse[eyeIndex], half4(sampleHorizonVec, 0)).xyz); - float3 sampleRadiance = srcRadiance.SampleLevel(samplerPointClamp, sampleUV * OUT_FRAME_SCALE, mipLevel).rgb * frontBackMult * giBoost; + float3 sampleRadiance = srcRadiance.SampleLevel(samplerPointClamp, sampleUV * OUT_FRAME_SCALE, mipLevel).rgb * frontBackMult * giBoost * countbits(validBits) * 0.03125; sampleRadiance = max(sampleRadiance, 0); float3 sampleRadianceYCoCg = Color::RGBToYCoCg(sampleRadiance); - float bitmaskWeight = countbits(validBits) * 0.03125; - radianceY += sampleRadianceYCoCg.r * SphericalHarmonics::Evaluate(sampleHorizonVecWS) * bitmaskWeight; - radianceCoCg += sampleRadianceYCoCg.gb * bitmaskWeight; + radianceY += sampleRadianceYCoCg.r * SphericalHarmonics::Evaluate(sampleHorizonVecWS); + radianceCoCg += sampleRadianceYCoCg.gb; } } #endif // GI diff --git a/features/Screen Space GI/Shaders/ScreenSpaceGI/upsample.cs.hlsl b/features/Screen Space GI/Shaders/ScreenSpaceGI/upsample.cs.hlsl index 0e79ea11c..ed29b6556 100644 --- a/features/Screen Space GI/Shaders/ScreenSpaceGI/upsample.cs.hlsl +++ b/features/Screen Space GI/Shaders/ScreenSpaceGI/upsample.cs.hlsl @@ -29,10 +29,10 @@ RWTexture2D outIlCoCg : register(u2); int2 px11 = px00 + int2(1, 1); float4 d = float4( - srcDepth.Load(int3(px00, 1)), - srcDepth.Load(int3(px01, 1)), - srcDepth.Load(int3(px10, 1)), - srcDepth.Load(int3(px11, 1))); + srcDepth.Load(int3(px00, RES_MIP)), + srcDepth.Load(int3(px01, RES_MIP)), + srcDepth.Load(int3(px10, RES_MIP)), + srcDepth.Load(int3(px11, RES_MIP))); // note: edge-detection float mind = min4(d); diff --git a/src/Features/ScreenSpaceGI.cpp b/src/Features/ScreenSpaceGI.cpp index 6e061567f..94e8e3b2e 100644 --- a/src/Features/ScreenSpaceGI.cpp +++ b/src/Features/ScreenSpaceGI.cpp @@ -79,43 +79,47 @@ void ScreenSpaceGI::DrawSettings() ImGui::TableNextColumn(); if (ImGui::Button("Low", { -1, 0 })) { - settings.NumSlices = 2; - settings.NumSteps = 4; + settings.NumSlices = 10; + settings.NumSteps = 12; + settings.ResolutionMode = 2; settings.EnableGI = true; recompileFlag = true; } if (auto _tt = Util::HoverTooltipWrapper()) - ImGui::Text("2 Slices, 4 Steps"); + ImGui::Text("Quarter res and blurry."); ImGui::TableNextColumn(); if (ImGui::Button("Medium", { -1, 0 })) { - settings.NumSlices = 3; - settings.NumSteps = 6; + settings.NumSlices = 5; + settings.NumSteps = 8; + settings.ResolutionMode = 1; settings.EnableGI = true; recompileFlag = true; } if (auto _tt = Util::HoverTooltipWrapper()) - ImGui::Text("3 Slices, 6 Steps"); + ImGui::Text("Half res and somewhat stable."); ImGui::TableNextColumn(); if (ImGui::Button("High", { -1, 0 })) { settings.NumSlices = 4; settings.NumSteps = 8; + settings.ResolutionMode = 0; settings.EnableGI = true; recompileFlag = true; } if (auto _tt = Util::HoverTooltipWrapper()) - ImGui::Text("4 Slices, 8 Steps"); + ImGui::Text("Full res and clean."); ImGui::TableNextColumn(); if (ImGui::Button("Ultra", { -1, 0 })) { settings.NumSlices = 6; settings.NumSteps = 10; + settings.ResolutionMode = 0; settings.EnableGI = true; recompileFlag = true; } if (auto _tt = Util::HoverTooltipWrapper()) - ImGui::Text("6 Slices, 10 Steps"); + ImGui::Text("Reference mode."); ImGui::EndTable(); } diff --git a/src/Features/ScreenSpaceGI.h b/src/Features/ScreenSpaceGI.h index fc77411a8..a17cc9b2e 100644 --- a/src/Features/ScreenSpaceGI.h +++ b/src/Features/ScreenSpaceGI.h @@ -48,8 +48,8 @@ struct ScreenSpaceGI : Feature bool Enabled = true; bool EnableGI = true; // performance/quality - uint NumSlices = 2; - uint NumSteps = 4; + uint NumSlices = 5; + uint NumSteps = 8; int ResolutionMode = 1; // 0-full, 1-half, 2-quarter // visual float MinScreenRadius = 0.01f; @@ -70,8 +70,8 @@ struct ScreenSpaceGI : Feature bool EnableBlur = true; float DepthDisocclusion = .1f; float NormalDisocclusion = .1f; - uint MaxAccumFrames = 32; - float BlurRadius = 15.f; + uint MaxAccumFrames = 16; + float BlurRadius = 5.f; float DistanceNormalisation = 2.f; } settings;