[WebGPU] Shadow casters re-upload their uniform block every frame when the light moves
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- computer-graphics, performance
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 26.6k
- Forks
- 3.8k
- Merge medio
- 1 d 9 h
- PR fusionados (30 d)
- 112
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de BabylonJS/Babylon.js
-
WebGPU: Geometry._invalidateVertexBuffers throws 'mesh.subMeshes is not iterable' for a mesh without sub-meshesPosiblemente ocupada @vladosskins178 la tomó hace 14 días. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
BabylonJS/Babylon.js#19188 ·
Los mantenedores suelen responder en 1 día
-
WebGPU compressed cube readback feeds encoded blocks to diffuse irradiance calculationPosiblemente ocupada @yucheng-du la tomó hoy. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 54/100
BabylonJS/Babylon.js#19278 ·
Los mantenedores suelen responder en 1 día
-
[WebGPU] A render effect whose WGSL fails to compile never reaches onError: isReady() is true and every draw fails on an invalid pipelinePosiblemente ocupada @Popov72 la tomó hoy. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
BabylonJS/Babylon.js#19224 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
in progress
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
BabylonJS/Babylon.js#19212 · 1 comentario · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
enhancement Gaussian Splatting native
Dificultad 4/5 3-5 días Aptitud para principiantes 43/100
BabylonJS/Babylon.js#19145 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de BabylonJS/Babylon.js
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
ardia-browser/ardia#6391 ·
Los mantenedores suelen responder en 1 día
-
Feature:Actions/ConnectorTypes Team:ResponseOps
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
elastic/kibana#309028 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
🔨 tool 🧰 library
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Orange-OpenSource/Orange-Boosted-Bootstrap#4035 ·
Los mantenedores suelen responder en 1 día
-
Ajouter la page Plan du siteAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
DISIC/teleservice-conformite#230 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
rothgar/rabble.radio#410 ·
Los mantenedores suelen responder en 1 día