Skip to content

fix(core,shader): 统一 DepthOnly 预通道复用 renderQueueType 并移除冗余队列属性(生产代码 +7/-22) - #3356

Open
sun-nocat wants to merge 1 commit into
dev/2.0from
fix/depth-only-render-queue-reopen
Open

sun-nocat wants to merge 1 commit into
dev/2.0from
fix/depth-only-render-queue-reopen

Conversation

@sun-nocat

@sun-nocat sun-nocat commented Dec 4, 2026 •

Copy link
Copy Markdown

说明:因原 PR #3337 在等待复核前被提前合入并已通过 #3354 回滚,本 PR 基于回滚后的最新 dev/2.0(051075346)原样重提(已包含原 PR #3337 中对 @cptbtptpbcptdtptp 全部 3 条评审意见的修复,逐字节一致),等待正式审核后再由人工合入。

1. 背景与问题

当前 Pipeline/DepthOnly.shader 使用独立的 material_DepthOnlyRenderQueue 控制深度预通道的渲染队列,而不是与 Forward Pass 共用 renderQueueType。

这源于 #2820(ShaderLab 迁移之前):当时 Forward Pass 的队列保存在 JS 对象 material.renderStates[0].renderQueueType 上,共享的 DepthOnly Pass 无法从 ShaderData 读取,因此被迫在 BaseMaterial 中镜像了一份 material_DepthOnlyRenderQueue。

在 #2961 迁移至 ShaderLab 后,所有内置材质的 Forward Pass 已改为从 ShaderData 读取 RenderQueueType = renderQueueType;。但 DepthOnly 仍保留了 material_DepthOnlyRenderQueue 副本,导致同一份语义在两处维护并出现多条漏同步路径:

  1. PBRMaterial.transmission > 0(isTransparent = false):PBRMaterial 仅将 renderQueueType 设为 Transparent 以确保在 camera_OpaqueTexture 之后渲染,未同步 material_DepthOnlyRenderQueue,导致透射材质(含 glTF KHR_materials_transmission)在 DepthOnly 阶段仍落入 Opaque 队列,错误写入 camera_DepthTexture 并污染 SAO / 下游深度消费方。
  2. 直接调用 BaseMaterial.setIsTransparent():该方法只更新 renderQueueType,未更新 material_DepthOnlyRenderQueue;此外 PBRMaterial 此前只覆写了 isTransparent setter 未覆写 setIsTransparent(),直接调用 setIsTransparent(false) 时会绕过透射材质的 Transparent 队列约束。
  3. .mat 资产与自定义 ShaderLab:通过 MaterialLoader 加载的材质实例化为基类 Material(不经过 PBRMaterial setter),自定义 ShaderLab 按官方文档也只维护 renderQueueType;一旦未额外双写 @internal 的 material_DepthOnlyRenderQueue,透明材质仍会误写入深度预通道。
  4. 透射材质退出深度预通道后的 SAO 采样保护:透射材质(transmission > 0, isTransparent = false)不再写入 camera_DepthTexture 后,PBR Forward 中 evaluateAmbientOcclusion 仅对 MATERIAL_IS_TRANSPARENT 返回 1.0,会导致透射表面误采背景的 camera_AOTexture 衰减自身间接光(含环境镜面反射)。

对比之下,material_ShadowCasterRenderQueue 确实具有独立语义(isTransparent = true 时 Forward 走 Transparent,而 ShadowCaster 仍需走 AlphaTest 以支持透明抖动阴影),因此继续保留;而 DepthOnly 在引擎所有状态下都应与 renderQueueType 严格一致。


2. 改动内容

  • packages/shader/src/Shaders/Pipeline/DepthOnly.shader:将 RenderQueueType 绑定从 material_DepthOnlyRenderQueue 改为直接复用 renderQueueType。
  • packages/core/src/material/BaseMaterial.ts:移除冗余的 @internal 静态属性 _depthOnlyRenderQueueProp 及构造函数、_seIsTransparent、_setAlphaCutoff 中的重复写入。
  • packages/core/src/material/PBRMaterial.ts:将透射材质维持 RenderQueueType.Transparent 的约束下沉至 override setIsTransparent(isTransparent)(移除外层多余的 override get/set isTransparent),统一覆盖 isTransparent 属性赋值与直接调用 setIsTransparent(false)。
  • packages/shader/src/ShaderLibrary/PBR/BSDF.glsl:evaluateAmbientOcclusion 的屏幕空间 AO 跳过保护扩展为 #if defined(MATERIAL_IS_TRANSPARENT) || defined(MATERIAL_ENABLE_TRANSMISSION),保留材质自身 occlusionTexture 采样。
  • 单元测试:
    • 更新 tests/src/core/material/BaseMaterial.test.ts:将原有 material_DepthOnlyRenderQueue 断言改为通过 DepthOnly Pass 解析队列,并补充 setIsTransparent() 直接调用校验。
    • 更新 tests/src/core/material/PBRMaterial.test.ts:在首次设置 transmission = 0.8 后立即断言 DepthOnly 队列,并覆盖 isTransparent = true → setIsTransparent(false)、属性赋值、alphaCutoff 与归零恢复链路。

3. 兼容性与验证

Summary by CodeRabbit

  • Bug Fixes
    • Improved rendering consistency for transparent, opaque, and alpha-cutoff materials, including their depth and shadow passes.
    • Corrected how transmission materials respond to transparency changes.
    • Transmission-enabled materials now bypass ambient occlusion texture sampling.

…d transmissive SAO

Re-submit #3337 after revert #3354 on dev/2.0:
- Bind RenderQueueType = renderQueueType in Pipeline/DepthOnly.shader.
- Remove redundant BaseMaterial._depthOnlyRenderQueueProp and duplicate writes.
- Move PBRMaterial transmission Transparent-queue guard into override setIsTransparent().
- Skip camera_AOTexture sampling for MATERIAL_ENABLE_TRANSMISSION in PBR BSDF.
- Update BaseMaterial.test.ts and PBRMaterial.test.ts.
@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The DepthOnly pass now uses its render queue type instead of a separate material property. PBR material queue handling accounts for transmission when transparency changes. Ambient-occlusion evaluation bypasses the AO texture for transmission materials.

Changes

DepthOnly render queue

Layer / File(s) Summary
Use pass state for DepthOnly queues
packages/core/src/material/BaseMaterial.ts, packages/shader/src/Shaders/Pipeline/DepthOnly.shader, tests/src/core/material/BaseMaterial.test.ts
BaseMaterial no longer maintains a separate DepthOnly queue. The DepthOnly pass uses renderQueueType. Tests derive the DepthOnly queue from the pass render state and check transparency and alpha-cutoff changes.
Handle transmission in PBR queues
packages/core/src/material/PBRMaterial.ts, tests/src/core/material/PBRMaterial.test.ts
PBRMaterial delegates transparency changes to BaseMaterial. When transparency is disabled while transmission is positive, it sets the queue to Transparent. Tests cover queue changes across transmission, transparency, and alpha-cutoff settings.

Transmission ambient occlusion

Layer / File(s) Summary
Bypass AO texture for transmission
packages/shader/src/ShaderLibrary/PBR/BSDF.glsl
Ambient-occlusion evaluation returns 1.0 when MATERIAL_ENABLE_TRANSMISSION is defined.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Suggested labels: bug, rendering

Suggested reviewers: guolei1990, zhuxudong, hhhhkrx

Merge Risk: Minimal · up to b96aa

This change aligns the depth prepass queue with the forward pass queue and handles transmissive materials consistently. No concrete merge-blocking defect was found, and tests cover the transition cases.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two main areas of the change: DepthOnly prepass reuse of renderQueueType and removal of the redundant queue property in core and shader. The title is in Chinese, which does not cha…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the two main areas of the change: DepthOnly prepass reuse of renderQueueType and removal of the redundant queue property in core and shader. The title is in Chinese, which does not change its relevance. The changeset matches it: BaseMaterial drops the depth-only queue property, DepthOnly.shader binds RenderQueueType to renderQueueType, and PBRMaterial moves the transmission queue logic into setIsTransparent. The title also states a production diff size (+7/-22) that the changeset summary does not confirm, and the title is long at 75 characters. These points are minor and do not make the title unrelated or vague.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the queues at dawn,
The depth pass finds its state and carries on.
Through glass, the AO samples rest,
While cutoff tests confirm the quest.
The rabbit hops, its work complete,
And leaves neat footprints by the feet.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6781d414-987f-4072-8e6a-adc272fd0d44
Commits

Reviewing files that changed from the base of the PR and between 0510753 and b96aac3.

Files selected for processing: 6

  • packages/core/src/material/BaseMaterial.ts
  • packages/core/src/material/PBRMaterial.ts
  • packages/shader/src/ShaderLibrary/PBR/BSDF.glsl
  • packages/shader/src/Shaders/Pipeline/DepthOnly.shader
  • tests/src/core/material/BaseMaterial.test.ts
  • tests/src/core/material/PBRMaterial.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

@codecov

codecov Bot commented Dec 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.61%. Comparing base (0510753) to head (b96aac3).

Additional details and impacted files
@@             Coverage Diff             @@
##           dev/2.0    #3356      +/-   ##
===========================================
+ Coverage    90.60%   90.61%   +0.01%     
===========================================
  Files          944      944              
  Lines       116286   116271      -15     
  Branches     18348    18351       +3     
===========================================
+ Hits        105357   105360       +3     
+ Misses       10805    10787      -18     
  Partials       124      124              
Flag Coverage Δ
unittests 90.61% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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