From 66b597818221166e46e4af091ece024609bbdbbe Mon Sep 17 00:00:00 2001
From: Alexander Gauggel <agauggel@uni-koblenz.de>
Date: Mon, 16 Aug 2021 16:13:39 +0200
Subject: [PATCH] [#106] Fix motion blur image border artifacts

---
 .../indirect_dispatch/resources/shaders/motionBlur.comp     | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/projects/indirect_dispatch/resources/shaders/motionBlur.comp b/projects/indirect_dispatch/resources/shaders/motionBlur.comp
index a90e142d..42f6c431 100644
--- a/projects/indirect_dispatch/resources/shaders/motionBlur.comp
+++ b/projects/indirect_dispatch/resources/shaders/motionBlur.comp
@@ -43,8 +43,10 @@ void main(){
     vec3        color       = vec3(0);
     const int   sampleCount = 16;
     
-    vec2 uvStart    = uv - motion;
-    vec2 uvEnd      = uv + motion;
+    // clamping start and end points avoids artifacts at image borders
+    // the sampler clamps the sample uvs anyways, but without clamping here, many samples can be stuck at the border
+    vec2 uvStart    = clamp(uv - motion, 0, 1);
+    vec2 uvEnd      = clamp(uv + motion, 0, 1);
     
     for(int i = 0; i < sampleCount; i++){
         vec2 sampleUV   = mix(uvStart, uvEnd, i / float(sampleCount - 1));    
-- 
GitLab