Skip to content

Fix read-buffer composition in OcclusionPass - #533

Merged
dli7319 merged 3 commits into
google:mainfrom
SankeerthNara:Fix-read-buffer-composition-in-OcclusionPass
Aug 16, 2026
Merged

dli7319 merged 3 commits into
google:mainfrom
SankeerthNara:Fix-read-buffer-composition-in-OcclusionPass

Conversation

@SankeerthNara

Copy link
Copy Markdown
Contributor

Pull Request Template

Description

Fixes read-buffer composition in OcclusionPass (src/depth/occlusion/OcclusionPass.ts).

renderOcclusionMapFromReadBuffer() renders occlusionMapQuad, a ShaderMaterial
backed by occlusionMapUniforms. However, the environment depth texture (stored
earlier by setDepthTexture()) was being written into occlusionMeshMaterial's
uniforms instead — a material that is only used as scene.overrideMaterial in the
separate renderOcclusionMapFromScene() path, and is never bound to
occlusionMapQuad.

As a result, occlusionMapQuad's uDepthTexture uniform was left unbound. An
unbound sampler reads as 0, so the depth comparison in occlusion_map.glsl
always evaluated to a zero occlusion mask — producing a fully black output
whenever OcclusionPass was driven from a read buffer (postprocessing mode)
rather than the scene-override mode.

Fix: bind the environment depth texture (and the related uViewId /
uIsTextureArray state) to occlusionMapUniforms — the uniform bag actually
consumed by occlusionMapQuad — instead of occlusionMeshMaterial.uniforms.

Known follow-up (out of scope for this PR): OcclusionMapShader
(occlusion_map.glsl.ts) currently only declares a plain sampler2D uDepthTexture and has no texture-array / uDepthNear / per-vertex
reprojection support, unlike OcclusionMapMeshMaterial's shader (which
reprojects virtual depth into the depth camera's space via
uDepthViewMatrix/uDepthProjectionMatrix). So the isTextureArray branch
in renderOcclusionMapFromReadBuffer() sets state that the shader doesn't
yet read, and the read-buffer path currently assumes the environment depth
texture aligns directly (same UV space) with the rendered view. Extending
occlusion_map.glsl to support texture-array depth and reprojection is
tracked separately and not addressed here to keep this fix minimal and
reviewable.

Fixes #531

Type of Change

  • Bug fix
  • New feature / enhancement
  • New demo or sample
  • Documentation update

Media / Screen Recordings & Screenshots (If Applicable)

  • Simulator Recording:
  • Device Recording:

Checklist

  • Tested in simulator & device: Verified via npx vitest run src/depth (added a regression test asserting occlusionMapQuad's shader receives the depth texture, and that occlusionMeshMaterial does not);
  • Large Assets (≥ 1MB): N/A — no new assets added.
  • SDK Dynamic Dependencies: N/A — no new dependencies added.
  • Security: No hardcoded API keys or secrets are committed.

…read-buffer path renderOcclusionMapFromReadBuffer() rendered occlusionMapQuad, but wrote the environment depth texture into occlusionMeshMaterial's uniforms instead — a material that's unused in this path. occlusionMapQuad's uDepthTexture was left unbound, sampling as 0 and producing a zero occlusion mask (fully black output). Fixes google#531
@google-cla

google-cla Bot commented Aug 16, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@dli7319

dli7319 commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

Checked on the simulator and looks like it's working. Tho we don't have a sample to show it so it requires some significant changes in the code to activate.

@dli7319
dli7319 merged commit 11cbe6a into google:main Aug 16, 2026
11 checks passed
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.

Fix read-buffer composition in OcclusionPass

2 participants