From 365d7d46fdb1f5ebd86c2e4be17d8fc1bda777af Mon Sep 17 00:00:00 2001
From: Alexander Rose <alexander.rose@weirdbyte.de>
Date: Sun, 22 Jan 2023 11:47:17 -0800
Subject: [PATCH] fix SSAO artefacts with high bias values

---
 CHANGELOG.md                   | 1 +
 src/mol-gl/shader/ssao.frag.ts | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d1a7d2302..cb1eed9a9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ Note that since we don't clearly distinguish between a public and private interf
     - [Breaking] Rename `DnatcoConfalPyramids` to `DnatcoNtCs`
 - Improve boundary calculation performance
 - Add option to create & include images in state snapshots
+- Fix SSAO artefacts with high bias values
 
 ## [v3.29.0] - 2023-01-15
 
diff --git a/src/mol-gl/shader/ssao.frag.ts b/src/mol-gl/shader/ssao.frag.ts
index 41850c5ea..b4d61f5db 100644
--- a/src/mol-gl/shader/ssao.frag.ts
+++ b/src/mol-gl/shader/ssao.frag.ts
@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2019-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-2023 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  * @author Áron Samuel Kovács <aron.kovacs@mail.muni.cz>
@@ -115,7 +115,7 @@ void main(void) {
     }
     occlusion = 1.0 - (uBias * occlusion / float(dNSamples));
 
-    vec2 packedOcclusion = packUnitIntervalToRG(occlusion);
+    vec2 packedOcclusion = packUnitIntervalToRG(clamp(occlusion, 0.01, 1.0));
 
     gl_FragColor = vec4(packedOcclusion, selfPackedDepth);
 }
-- 
GitLab