From 55e940e88c577803b73e6900b374900aea813dd2 Mon Sep 17 00:00:00 2001
From: Alexander Rose <alexander.rose@weirdbyte.de>
Date: Wed, 12 Apr 2023 23:25:57 -0700
Subject: [PATCH] fix rendering with very small viewport and SSAO

---
 CHANGELOG.md                              |  1 +
 src/mol-canvas3d/passes/postprocessing.ts | 16 ++++++++--------
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index e97d58488..c80c7cdc6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@ Note that since we don't clearly distinguish between a public and private interf
 - Fix rendering issues caused by VAO reuse
 - Add "Zoom All", "Orient Axes", "Reset Axes" buttons to the "Reset Camera" button
 - Improve trackball move-state handling when key bindings use modifiers
+- Fix rendering with very small viewport and SSAO enabled
 
 ## [v3.33.0] - 2023-04-02
 
diff --git a/src/mol-canvas3d/passes/postprocessing.ts b/src/mol-canvas3d/passes/postprocessing.ts
index 4ec19e94f..78cff8274 100644
--- a/src/mol-canvas3d/passes/postprocessing.ts
+++ b/src/mol-canvas3d/passes/postprocessing.ts
@@ -506,11 +506,11 @@ export class PostprocessingPass {
         const sw = Math.floor(width * this.ssaoScale);
         const sh = Math.floor(height * this.ssaoScale);
 
-        const hw = Math.floor(sw * 0.5);
-        const hh = Math.floor(sh * 0.5);
+        const hw = Math.max(1, Math.floor(sw * 0.5));
+        const hh = Math.max(1, Math.floor(sh * 0.5));
 
-        const qw = Math.floor(sw * 0.25);
-        const qh = Math.floor(sh * 0.25);
+        const qw = Math.max(1, Math.floor(sw * 0.25));
+        const qh = Math.max(1, Math.floor(sh * 0.25));
 
         this.downsampledDepthTarget = drawPass.packedDepth
             ? webgl.createRenderTarget(sw, sh, false, 'uint8', 'linear', 'rgba')
@@ -562,12 +562,12 @@ export class PostprocessingPass {
             this.ssaoDepthTexture.define(sw, sh);
             this.ssaoDepthBlurProxyTexture.define(sw, sh);
 
-            const hw = Math.floor(sw * 0.5);
-            const hh = Math.floor(sh * 0.5);
+            const hw = Math.max(1, Math.floor(sw * 0.5));
+            const hh = Math.max(1, Math.floor(sh * 0.5));
             this.depthHalfTarget.setSize(hw, hh);
 
-            const qw = Math.floor(sw * 0.25);
-            const qh = Math.floor(sh * 0.25);
+            const qw = Math.max(1, Math.floor(sw * 0.25));
+            const qh = Math.max(1, Math.floor(sh * 0.25));
             this.depthQuarterTarget.setSize(qw, qh);
 
             ValueCell.update(this.renderable.values.uTexSize, Vec2.set(this.renderable.values.uTexSize.ref.value, width, height));
-- 
GitLab