[WebGPU] Shadow casters re-upload their uniform block every frame when the light moves
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- typescript
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- TypeScript
- スター
- 26.6k
- フォーク
- 3.8k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 112
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
BabylonJS/Babylon.js のほかの issue
-
WebGPU: Geometry._invalidateVertexBuffers throws 'mesh.subMeshes is not iterable' for a mesh without sub-meshes対応中かも @vladosskins178 が 14 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
BabylonJS/Babylon.js#19188 ·
メンテナーはふだん 1 日以内に返信
-
WebGPU compressed cube readback feeds encoded blocks to diffuse irradiance calculation対応中かも @yucheng-du が今日担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 54/100
BabylonJS/Babylon.js#19278 ·
メンテナーはふだん 1 日以内に返信
-
[WebGPU] A render effect whose WGSL fails to compile never reaches onError: isReady() is true and every draw fails on an invalid pipeline対応中かも @Popov72 が今日担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
BabylonJS/Babylon.js#19224 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
in progress
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
BabylonJS/Babylon.js#19212 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
enhancement Gaussian Splatting native
難易度 4/5 3〜5日 初心者へのやさしさ 43/100
BabylonJS/Babylon.js#19145 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
BabylonJS/Babylon.js の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
ardia-browser/ardia#6391 ·
メンテナーはふだん 1 日以内に返信
-
Feature:Actions/ConnectorTypes Team:ResponseOps
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
elastic/kibana#309028 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
🔨 tool 🧰 library
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Orange-OpenSource/Orange-Boosted-Bootstrap#4035 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
DISIC/teleservice-conformite#230 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
rothgar/rabble.radio#410 ·
メンテナーはふだん 1 日以内に返信