Skip to content

Fix HALFRES compositer darkening background behind transparent geometry#50

Open
coobeeyon wants to merge 1 commit intoN8python:masterfrom
coobeeyon:fix/halfres-compositer-background-occlusion
Open

Fix HALFRES compositer darkening background behind transparent geometry#50
coobeeyon wants to merge 1 commit intoN8python:masterfrom
coobeeyon:fix/halfres-compositer-background-occlusion

Conversation

@coobeeyon
Copy link
Copy Markdown

Problem

When halfRes is enabled, the EffectCompositer's HALFRES code path hardcodes vec4(0.0, 0.0, 0.0, 1.0) for far-plane pixels (depth == 1.0). The R channel value of 0.0 is interpreted as full ambient occlusion, which darkens the entire background when transparent objects with depthWrite disabled leave far-plane depth values in the depth buffer.

Fix

Replace the hardcoded constant with texture2D(tDiffuse, vUv), which bilinearly samples the AO buffer. For background pixels the AO pass already writes 1.0 (no occlusion) via the early return in the EffectShader, so the sampled value is correct. This also provides smooth edge transitions at geometry boundaries — the hardcoded constant created a visible halo where the binary depth == 1.0 check met the upsampled AO values.

Reproduction

  1. Render a scene with halfRes: true
  2. Set some geometry to transparent with depthWrite: false
  3. Observe the background behind transparent geometry is darkened
  4. With halfRes: false, the background renders correctly

Change

One-line change in src/EffectCompositer.js:

-            texel = vec4(0.0, 0.0, 0.0, 1.0);
+            texel = texture2D(tDiffuse, vUv);

The HALFRES code path in the EffectCompositer hardcodes
vec4(0.0, 0.0, 0.0, 1.0) for far-plane pixels (depth == 1.0). The R
channel (0.0) is interpreted as full ambient occlusion, which darkens
the entire background when transparent objects with depthWrite disabled
leave far-plane depth values in the depth buffer.

Replace the hardcoded constant with texture2D(tDiffuse, vUv), which
bilinearly samples the AO buffer. For background pixels the AO pass
already writes 1.0 (no occlusion), so the result is correct while also
providing smooth edge transitions at geometry boundaries — avoiding the
visible halo that a hard constant produces.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant