瀏覽代碼

Fix a bug in motion blur

Panagiotis Christopoulos Charitos 1 年之前
父節點
當前提交
6fb43522b0
共有 2 個文件被更改,包括 18 次插入4 次删除
  1. 4 0
      AnKi/Renderer/MotionBlur.cpp
  2. 14 4
      AnKi/Shaders/MotionBlur.ankiprog

+ 4 - 0
AnKi/Renderer/MotionBlur.cpp

@@ -66,9 +66,13 @@ void MotionBlur::populateRenderGraph(RenderingContext& ctx)
 
 			cmdb.bindShaderProgram(m_maxVelocityGrProg.get());
 
+			cmdb.bindSampler(0, 0, getRenderer().getSamplers().m_trilinearClamp.get());
 			rgraphCtx.bindSrv(0, 0, getRenderer().getMotionVectors().getMotionVectorsRt());
 			rgraphCtx.bindUav(0, 0, maxVelRt);
 
+			const Vec4 consts(Vec2(getRenderer().getPostProcessResolution()), 0.0f, 0.0f);
+			cmdb.setFastConstants(&consts, sizeof(consts));
+
 			const UVec2 tiledTexSize = (getRenderer().getPostProcessResolution() + g_motionBlurTileSizeCVar - 1) / g_motionBlurTileSizeCVar;
 			cmdb.dispatchCompute(tiledTexSize.x(), tiledTexSize.y(), 1);
 		});

+ 14 - 4
AnKi/Shaders/MotionBlur.ankiprog

@@ -27,21 +27,31 @@ Vec2 computeMaxVelocity(Vec2 a, Vec2 b)
 #if ANKI_TECHNIQUE_MaxTileVelocity
 #	define NUMTHREADS 64
 
+SamplerState g_linearClampSampler : register(s0);
 Texture2D<Vec4> g_motionVectorsTex : register(t0);
 RWTexture2D<Vec4> g_maxVelocityTex : register(u0);
 
 groupshared Vec2 g_maxVelocities[NUMTHREADS];
 
+struct Consts
+{
+	Vec2 m_resolution;
+	Vec2 m_padding;
+};
+
+ANKI_FAST_CONSTANTS(Consts, g_consts)
+
 [numthreads(8, 8, 1)] void main(UVec2 svDispatchThreadId : SV_DispatchThreadID, U32 svGroupIndex : SV_GroupIndex, UVec2 svGroupId : SV_GroupID)
 {
 	// Gather the thread result
-	const U32 pixelsPerThread = TILE_SIZE / 8;
+	const F32 pixelsPerThread = TILE_SIZE / 8;
 	Vec2 maxV = 0.0;
-	for(U32 x = 0; x < pixelsPerThread; ++x)
+	for(F32 x = 0.0; x < pixelsPerThread; x += 1.0)
 	{
-		for(U32 y = 0; y < pixelsPerThread; ++y)
+		for(F32 y = 0; y < pixelsPerThread; y += 1.0)
 		{
-			const Vec2 v = g_motionVectorsTex[svDispatchThreadId * pixelsPerThread + UVec2(x, y)];
+			const Vec2 uv = (svDispatchThreadId * pixelsPerThread + Vec2(x, y) + 0.5) / g_consts.m_resolution;
+			const Vec2 v = g_motionVectorsTex.SampleLevel(g_linearClampSampler, uv, 0.0);
 			maxV = computeMaxVelocity(maxV, v);
 		}
 	}