[WebGPU] Shadow casters re-upload their uniform block every frame when the light moves
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- computer-graphics, performance
Hướng nghiên cứu
Start in Lights/Shadows/shadowGenerator.js at _renderSubMeshForShadowMap, then read ShadersWGSL/ShadersInclude/shadowMapVertexNormalBias.js and the related shader declarations. Use the linked WebGPU playground to compare buffer writes with a stationary and moving directional light; verify the visual result remains consistent and per-caster writes are reduced.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
ShadowGenerator writes biasAndScaleSM, lightDataSM and depthValuesSM into each shadow-caster effect's own "leftover" uniform buffer on every shadow draw.
- On WebGPU those buffers have one slot per draw context.
- For a directional light,
lightDataSMis the light direction. - So when the light direction changes every frame (a day/night cycle, or a moving sun), every caster's block is re-uploaded every frame, once per caster.
The value is the same for every caster in the pass, so it doesn't need to live in per-draw blocks.
Where
Lights/Shadows/shadowGenerator.js:948-956, in_renderSubMeshForShadowMap:effect.setFloat3("biasAndScaleSM", this.bias, this.normalBias, this.depthScale); if (this.getLight().getTypeID() === Light.LIGHTTYPEID_DIRECTIONALLIGHT) { effect.setVector3("lightDataSM", this._cachedDirection); } ... effect.setFloat2("depthValuesSM", ...);- Shader use:
ShadersWGSL/ShadersInclude/shadowMapVertexNormalBias.js, wherenormalize(-uniforms.lightDataSM.xyz)is used for the normal bias whenSM_DIRECTIONINLIGHTDATA == 1.
Repro: https://playground.babylonjs.com/#WOKT22 (WebGPU). With 50 shadow casters: 3.0 writeBuffer calls per frame with the light still, 55.0 with it rotating 0.01 degree per frame.
Measured in the game
CascadedShadowGenerator with 4 cascades, about 73 caster draws per frame, and the sun direction changing slightly every frame (race clock). queue.writeBuffer calls dropped from about 221 to about 111 per frame once lightDataSM stopped changing per draw. Almost all of the removed writes were 48- and 112-byte shadow-map leftover blocks. CPU gain is small (about 0.03–0.05 ms per frame). The bigger benefit is about 110 fewer queued commands per frame for the browser's GPU process.
Suggested fix (either)
- Move
lightDataSM,biasAndScaleSManddepthValuesSMinto the per-pass scene uniform buffer the shadow generator already owns, or into a small per-generator uniform buffer, like the 9.32 CSM receiver cascades buffer. - For directional lights, derive the normal-bias direction in the shader from the pass's view matrix. The cascade camera looks along the light, so
-vec3(view[0].z, view[1].z, view[2].z)is the normalized direction, andlightDataSMdoesn't need to be declared.
Workaround we use
At startup, override the two WGSL includes in ShaderStore.IncludesShadersStoreWGSL:
shadowMapVertexExtraDeclaration: declarelightDataSMonly whenSM_DIRECTIONINLIGHTDATA == 0.shadowMapVertexNormalBias: read the direction fromscene.view.
The WebGPU pipeline context's setFloat3 already skips undeclared uniforms, so the per-draw write becomes a no-op. Frozen-frame captures were pixel-identical before and after in 9 of 10 test scenes, and the tenth differed only within that scene's normal run-to-run flicker.
- Ngôn ngữ chính
- TypeScript
- Star
- 26.6k
- Fork
- 3.8k
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 112
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của BabylonJS/Babylon.js
-
WebGPU: Geometry._invalidateVertexBuffers throws 'mesh.subMeshes is not iterable' for a mesh without sub-meshesCó thể đã có người làm @vladosskins178 đã nhận 14 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
BabylonJS/Babylon.js#19188 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
WebGPU compressed cube readback feeds encoded blocks to diffuse irradiance calculationCó thể đã có người làm @yucheng-du đã nhận hôm nay. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 54/100
BabylonJS/Babylon.js#19278 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[WebGPU] A render effect whose WGSL fails to compile never reaches onError: isReady() is true and every draw fails on an invalid pipelineCó thể đã có người làm @Popov72 đã nhận hôm nay. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
BabylonJS/Babylon.js#19224 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
in progress
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
BabylonJS/Babylon.js#19212 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement Gaussian Splatting native
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 43/100
BabylonJS/Babylon.js#19145 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của BabylonJS/Babylon.js
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
ardia-browser/ardia#6391 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Feature:Actions/ConnectorTypes Team:ResponseOps
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
elastic/kibana#309028 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🔨 tool 🧰 library
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Orange-OpenSource/Orange-Boosted-Bootstrap#4035 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Ajouter la page Plan du siteĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
DISIC/teleservice-conformite#230 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
rothgar/rabble.radio#410 ·
Maintainer thường phản hồi trong vòng 1 ngày