2
0
Эх сурвалжийг харах

Improve edge stopping of SVGF

Panagiotis Christopoulos Charitos 4 жил өмнө
parent
commit
aa2a8a1511

+ 11 - 13
AnKi/Renderer/RtShadows.cpp

@@ -554,13 +554,12 @@ void RtShadows::runSvgfVariance(RenderPassWorkContext& rgraphCtx)
 	rgraphCtx.bindColorTexture(0, 3, m_runCtx.m_currentMomentsRt);
 	rgraphCtx.bindColorTexture(0, 3, m_runCtx.m_currentMomentsRt);
 	rgraphCtx.bindColorTexture(0, 4, m_runCtx.m_currentHistoryLengthRt);
 	rgraphCtx.bindColorTexture(0, 4, m_runCtx.m_currentHistoryLengthRt);
 	rgraphCtx.bindColorTexture(0, 5, m_r->getDepthDownscale().getHiZRt());
 	rgraphCtx.bindColorTexture(0, 5, m_r->getDepthDownscale().getHiZRt());
-	rgraphCtx.bindColorTexture(0, 6, m_r->getGBuffer().getColorRt(2));
 
 
-	rgraphCtx.bindImage(0, 7, m_runCtx.m_intermediateShadowsRts[1]);
-	rgraphCtx.bindImage(0, 8, m_runCtx.m_varianceRts[1]);
+	rgraphCtx.bindImage(0, 6, m_runCtx.m_intermediateShadowsRts[1]);
+	rgraphCtx.bindImage(0, 7, m_runCtx.m_varianceRts[1]);
 
 
-	// const Mat4& invViewProjMat = m_runCtx.m_ctx->m_matrices.m_invertedViewProjectionJitter;
-	// cmdb->setPushConstants(&invViewProjMat, sizeof(invViewProjMat));
+	const Mat4& invProjMat = m_runCtx.m_ctx->m_matrices.m_projectionJitter.getInverse();
+	cmdb->setPushConstants(&invProjMat, sizeof(invProjMat));
 
 
 	dispatchPPCompute(cmdb, 8, 8, m_r->getWidth() / 2, m_r->getHeight() / 2);
 	dispatchPPCompute(cmdb, 8, 8, m_r->getWidth() / 2, m_r->getHeight() / 2);
 }
 }
@@ -585,22 +584,21 @@ void RtShadows::runSvgfAtrous(RenderPassWorkContext& rgraphCtx)
 	cmdb->bindSampler(0, 1, m_r->getSamplers().m_trilinearClamp);
 	cmdb->bindSampler(0, 1, m_r->getSamplers().m_trilinearClamp);
 
 
 	rgraphCtx.bindColorTexture(0, 2, m_r->getDepthDownscale().getHiZRt());
 	rgraphCtx.bindColorTexture(0, 2, m_r->getDepthDownscale().getHiZRt());
-	rgraphCtx.bindColorTexture(0, 3, m_r->getGBuffer().getColorRt(2));
-	rgraphCtx.bindColorTexture(0, 4, m_runCtx.m_intermediateShadowsRts[readRtIdx]);
-	rgraphCtx.bindColorTexture(0, 5, m_runCtx.m_varianceRts[readRtIdx]);
+	rgraphCtx.bindColorTexture(0, 3, m_runCtx.m_intermediateShadowsRts[readRtIdx]);
+	rgraphCtx.bindColorTexture(0, 4, m_runCtx.m_varianceRts[readRtIdx]);
 
 
 	if(!lastPass)
 	if(!lastPass)
 	{
 	{
-		rgraphCtx.bindImage(0, 7, m_runCtx.m_varianceRts[!readRtIdx]);
-		rgraphCtx.bindImage(0, 6, m_runCtx.m_intermediateShadowsRts[!readRtIdx]);
+		rgraphCtx.bindImage(0, 5, m_runCtx.m_intermediateShadowsRts[!readRtIdx]);
+		rgraphCtx.bindImage(0, 6, m_runCtx.m_varianceRts[!readRtIdx]);
 	}
 	}
 	else
 	else
 	{
 	{
-		rgraphCtx.bindImage(0, 6, m_runCtx.m_historyRt);
+		rgraphCtx.bindImage(0, 5, m_runCtx.m_historyRt);
 	}
 	}
 
 
-	// const Mat4& invViewProjMat = m_runCtx.m_ctx->m_matrices.m_invertedViewProjectionJitter;
-	// cmdb->setPushConstants(&invViewProjMat, sizeof(invViewProjMat));
+	const Mat4& invProjMat = m_runCtx.m_ctx->m_matrices.m_projectionJitter.getInverse();
+	cmdb->setPushConstants(&invProjMat, sizeof(invProjMat));
 
 
 	dispatchPPCompute(cmdb, 8, 8, m_r->getWidth() / 2, m_r->getHeight() / 2);
 	dispatchPPCompute(cmdb, 8, 8, m_r->getWidth() / 2, m_r->getHeight() / 2);
 
 

+ 12 - 17
AnKi/Shaders/RtShadowsSvgfAtrous.ankiprog

@@ -19,28 +19,27 @@ layout(local_size_x = WORKGROUP_SIZE.x, local_size_y = WORKGROUP_SIZE.y, local_s
 layout(set = 0, binding = 0) uniform sampler u_nearestAnyClampSampler;
 layout(set = 0, binding = 0) uniform sampler u_nearestAnyClampSampler;
 layout(set = 0, binding = 1) uniform sampler u_linearAnyClampSampler;
 layout(set = 0, binding = 1) uniform sampler u_linearAnyClampSampler;
 layout(set = 0, binding = 2) uniform texture2D u_depthTex;
 layout(set = 0, binding = 2) uniform texture2D u_depthTex;
-layout(set = 0, binding = 3) uniform texture2D u_gbuffer2Tex;
-layout(set = 0, binding = 4) uniform utexture2D u_shadowsTex;
-layout(set = 0, binding = 5) uniform texture2D u_varianceTex;
+layout(set = 0, binding = 3) uniform utexture2D u_shadowsTex;
+layout(set = 0, binding = 4) uniform texture2D u_varianceTex;
 
 
-layout(set = 0, binding = 6) uniform uimage2D u_shadowsImage;
+layout(set = 0, binding = 5) uniform uimage2D u_shadowsImage;
 #if !LAST_PASS
 #if !LAST_PASS
-layout(set = 0, binding = 7) uniform image2D u_varianceImage;
+layout(set = 0, binding = 6) uniform image2D u_varianceImage;
 #endif
 #endif
 
 
 layout(std430, push_constant, row_major) uniform b_pc
 layout(std430, push_constant, row_major) uniform b_pc
 {
 {
-	Mat4 u_invViewProjMat;
+	Mat4 u_invProjMat;
 };
 };
 
 
 const I32 CONVOLUTION_RADIUS = 2;
 const I32 CONVOLUTION_RADIUS = 2;
 const F32 KERNEL_WEIGHTS[CONVOLUTION_RADIUS + 1] = F32[3](1.0, 2.0 / 3.0, 1.0 / 6.0);
 const F32 KERNEL_WEIGHTS[CONVOLUTION_RADIUS + 1] = F32[3](1.0, 2.0 / 3.0, 1.0 / 6.0);
 
 
-Vec3 unproject(Vec2 uv, F32 depth)
+Vec3 toViewspace(Vec2 uv, F32 depth)
 {
 {
-	const Vec4 worldPos4 = u_invViewProjMat * Vec4(UV_TO_NDC(uv), depth, 1.0);
-	const Vec3 worldPos = worldPos4.xyz / worldPos4.w;
-	return worldPos;
+	const Vec4 pos4 = u_invProjMat * Vec4(UV_TO_NDC(uv), depth, 1.0);
+	const Vec3 pos = pos4.xyz / pos4.w;
+	return pos;
 }
 }
 
 
 F32 computeShadowsLuma(F32 shadowLayers[MAX_RT_SHADOW_LAYERS])
 F32 computeShadowsLuma(F32 shadowLayers[MAX_RT_SHADOW_LAYERS])
@@ -95,8 +94,7 @@ void main()
 
 
 	// Set the reference sample
 	// Set the reference sample
 	const F32 depthCenter = depth;
 	const F32 depthCenter = depth;
-	const Vec3 positionCenter = unproject(uv, depthCenter);
-	const Vec3 normalCenter = readNormalFromGBuffer(u_gbuffer2Tex, u_linearAnyClampSampler, uv);
+	const Vec3 positionCenter = toViewspace(uv, depthCenter);
 
 
 	// Read center luma
 	// Read center luma
 	F32 shadowLayers[MAX_RT_SHADOW_LAYERS];
 	F32 shadowLayers[MAX_RT_SHADOW_LAYERS];
@@ -133,13 +131,10 @@ void main()
 
 
 			// Set the current sample
 			// Set the current sample
 			const F32 depthTap = textureLod(u_depthTex, u_linearAnyClampSampler, sampleUv, 0.0).r;
 			const F32 depthTap = textureLod(u_depthTex, u_linearAnyClampSampler, sampleUv, 0.0).r;
-			const Vec3 positionTap = unproject(sampleUv, depthTap);
-			const Vec3 normalTap =
-				unpackNormalFromGBuffer(textureLod(u_gbuffer2Tex, u_linearAnyClampSampler, sampleUv, 0.0));
+			const Vec3 positionTap = toViewspace(sampleUv, depthTap);
 
 
 			// Do bilateral
 			// Do bilateral
-			// F32 w = calculateBilateralWeightPlane(positionCenter, normalCenter, positionTap, normalTap, 1.0);
-			F32 w = calculateBilateralWeightDepth(depthCenter, depthTap, 1.0);
+			F32 w = calculateBilateralWeightViewspacePosition(positionCenter, positionTap, 0.5);
 
 
 			// Include more weights
 			// Include more weights
 			w *= wl;
 			w *= wl;

+ 10 - 16
AnKi/Shaders/RtShadowsSvgfVariance.ankiprog

@@ -20,23 +20,22 @@ layout(set = 0, binding = 2) uniform utexture2D u_shadowsTex;
 layout(set = 0, binding = 3) uniform texture2D u_momentsTex;
 layout(set = 0, binding = 3) uniform texture2D u_momentsTex;
 layout(set = 0, binding = 4) uniform texture2D u_historyLengthTex;
 layout(set = 0, binding = 4) uniform texture2D u_historyLengthTex;
 layout(set = 0, binding = 5) uniform texture2D u_depthTex;
 layout(set = 0, binding = 5) uniform texture2D u_depthTex;
-layout(set = 0, binding = 6) uniform texture2D u_gbuffer2Tex;
 
 
-layout(set = 0, binding = 7) uniform uimage2D u_shadowsImage;
-layout(set = 0, binding = 8) uniform image2D u_varianceImage;
+layout(set = 0, binding = 6) uniform uimage2D u_shadowsImage;
+layout(set = 0, binding = 7) uniform image2D u_varianceImage;
 
 
 layout(std430, push_constant, row_major) uniform b_pc
 layout(std430, push_constant, row_major) uniform b_pc
 {
 {
-	Mat4 u_invViewProjMat;
+	Mat4 u_invProjMat;
 };
 };
 
 
 const I32 CONVOLUTION_RADIUS = 1;
 const I32 CONVOLUTION_RADIUS = 1;
 
 
-Vec3 unproject(Vec2 uv, F32 depth)
+Vec3 toViewspace(Vec2 uv, F32 depth)
 {
 {
-	const Vec4 worldPos4 = u_invViewProjMat * Vec4(UV_TO_NDC(uv), depth, 1.0);
-	const Vec3 worldPos = worldPos4.xyz / worldPos4.w;
-	return worldPos;
+	const Vec4 pos4 = u_invProjMat * Vec4(UV_TO_NDC(uv), depth, 1.0);
+	const Vec3 pos = pos4.xyz / pos4.w;
+	return pos;
 }
 }
 
 
 void main()
 void main()
@@ -70,8 +69,7 @@ void main()
 
 
 		// Set the reference sample
 		// Set the reference sample
 		const F32 depthCenter = depth;
 		const F32 depthCenter = depth;
-		const Vec3 positionCenter = unproject(uv, depthCenter);
-		const Vec3 normalCenter = readNormalFromGBuffer(u_gbuffer2Tex, u_linearAnyClampSampler, uv);
+		const Vec3 positionCenter = toViewspace(uv, depthCenter);
 
 
 		// Init the sums
 		// Init the sums
 		Vec2 sumMoments = Vec2(0.0);
 		Vec2 sumMoments = Vec2(0.0);
@@ -88,14 +86,10 @@ void main()
 
 
 				// Set the current sample
 				// Set the current sample
 				const F32 depthTap = textureLod(u_depthTex, u_linearAnyClampSampler, sampleUv, 0.0).r;
 				const F32 depthTap = textureLod(u_depthTex, u_linearAnyClampSampler, sampleUv, 0.0).r;
-				const Vec3 positionTap = unproject(sampleUv, depthTap);
-				const Vec3 normalTap =
-					unpackNormalFromGBuffer(textureLod(u_gbuffer2Tex, u_linearAnyClampSampler, sampleUv, 0.0));
+				const Vec3 positionTap = toViewspace(sampleUv, depthTap);
 
 
 				// Do bilateral
 				// Do bilateral
-				// const F32 w = calculateBilateralWeightPlane(positionCenter, normalCenter, positionTap,
-				// normalTap, 1.0);
-				const F32 w = calculateBilateralWeightDepth(depthCenter, depthTap, 1.0);
+				const F32 w = calculateBilateralWeightViewspacePosition(positionCenter, positionTap, 0.5);
 
 
 				// Sum
 				// Sum
 				const Vec2 moments = textureLod(u_momentsTex, u_linearAnyClampSampler, sampleUv, 0.0).xy;
 				const Vec2 moments = textureLod(u_momentsTex, u_linearAnyClampSampler, sampleUv, 0.0).xy;