Skip to content

fix(shader): select scene depth decode via CAPS_TEXTURE_FLOAT_RENDERABLE#8856

Merged
mvaligursky merged 1 commit into
mainfrom
mv-scene-depth-caps-define
Jun 8, 2026
Merged

fix(shader): select scene depth decode via CAPS_TEXTURE_FLOAT_RENDERABLE#8856
mvaligursky merged 1 commit into
mainfrom
mv-scene-depth-caps-define

Conversation

@mvaligursky

Copy link
Copy Markdown
Contributor

Materials sampling scene depth via the screenDepthPS chunk decoded it in the wrong format on textureFloatRenderable devices, producing zebra/banding artifacts (e.g. the ground-fog effect and StandardMaterial paths reading uSceneDepthMap).

This is an alternative to #8851. Rather than injecting a SCENE_DEPTHMAP_FLOAT define onto the material path, it removes that define entirely and selects the decode in the chunk from the global CAPS_TEXTURE_FLOAT_RENDERABLE define instead.

Root cause:
RenderPassPrepass allocates the linear depth texture as R32F when device.textureFloatRenderable (packed RGBA8 otherwise), but the screenDepthPS decode was gated by a separate SCENE_DEPTHMAP_FLOAT define that the material path (ShaderUtils.getCoreDefines) never set — so the shader took the packed-RGBA8 branch against an R32F texture. The two were independent flags that could disagree.

Changes:

  • screenDepth GLSL chunk now selects the float vs packed-RGBA8 decode using CAPS_TEXTURE_FLOAT_RENDERABLE, which initCapsDefines already emits into every shader from the same device.textureFloatRenderable flag the prepass uses. Format and decode now share a single source of truth and can never disagree.
  • Removed the SCENE_DEPTHMAP_FLOAT define and dropped the device.textureFloatRenderable branch (plus the now-unused device param) from ShaderUtils.addScreenDepthChunkDefines, which now only sets the camera-specific SCENE_DEPTHMAP_LINEAR.
  • Updated the four post-process passes (coc, taa, ssao, depth-aware-blur) to the new addScreenDepthChunkDefines signature.

The WGSL chunk was unaffected — it never had a float branch.

Materials sampling scene depth via screenDepthPS decoded it in the wrong
format on textureFloatRenderable devices. The prepass allocates the linear
depth texture as R32F when device.textureFloatRenderable (packed RGBA8
otherwise), but the chunk's decode was gated by a separate SCENE_DEPTHMAP_FLOAT
define that the material path never set.

Select the decode in the chunk from the global CAPS_TEXTURE_FLOAT_RENDERABLE
define instead, so the texture format and the shader decode share a single
source of truth. Removes SCENE_DEPTHMAP_FLOAT and the device branch (and unused
device param) from addScreenDepthChunkDefines, and updates its four callers.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect scene-depth decoding in GLSL screenDepthPS on textureFloatRenderable devices by making the decode path follow the same single source of truth used to choose the prepass depth texture format (CAPS_TEXTURE_FLOAT_RENDERABLE). This prevents float-vs-packed format disagreement that caused zebra/banding artifacts in materials and effects sampling uSceneDepthMap.

Changes:

  • Updated the GLSL screenDepth chunk to select R32F vs packed RGBA8 decode via CAPS_TEXTURE_FLOAT_RENDERABLE instead of SCENE_DEPTHMAP_FLOAT.
  • Removed SCENE_DEPTHMAP_FLOAT emission and simplified ShaderUtils.addScreenDepthChunkDefines (dropped device parameter; now only adds SCENE_DEPTHMAP_LINEAR based on camera params).
  • Updated affected post-process passes (TAA, SSAO, CoC, depth-aware blur) to the new addScreenDepthChunkDefines signature.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/scene/shader-lib/shader-utils.js Removes SCENE_DEPTHMAP_FLOAT define emission and updates helper signature to rely on global caps define.
src/scene/shader-lib/glsl/chunks/common/frag/screenDepth.js Switches float-vs-packed depth decode selection to CAPS_TEXTURE_FLOAT_RENDERABLE.
src/extras/render-passes/render-pass-taa.js Updates helper invocation to new signature.
src/extras/render-passes/render-pass-ssao.js Updates helper invocation to new signature.
src/extras/render-passes/render-pass-depth-aware-blur.js Updates helper invocation to new signature.
src/extras/render-passes/render-pass-coc.js Updates helper invocation to new signature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mvaligursky mvaligursky merged commit 124fa88 into main Jun 8, 2026
9 checks passed
@mvaligursky mvaligursky deleted the mv-scene-depth-caps-define branch June 8, 2026 08:51
mvaligursky added a commit that referenced this pull request Jun 8, 2026
…BLE (#8856)

Materials sampling scene depth via screenDepthPS decoded it in the wrong
format on textureFloatRenderable devices. The prepass allocates the linear
depth texture as R32F when device.textureFloatRenderable (packed RGBA8
otherwise), but the chunk's decode was gated by a separate SCENE_DEPTHMAP_FLOAT
define that the material path never set.

Select the decode in the chunk from the global CAPS_TEXTURE_FLOAT_RENDERABLE
define instead, so the texture format and the shader decode share a single
source of truth. Removes SCENE_DEPTHMAP_FLOAT and the device branch (and unused
device param) from addScreenDepthChunkDefines, and updates its four callers.

Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: graphics Graphics related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants