Skip to content

refactor(particles): drop redundant material reset on camera change#8928

Merged
mvaligursky merged 1 commit into
mainfrom
mv-particle-camera-reset
Jun 19, 2026
Merged

refactor(particles): drop redundant material reset on camera change#8928
mvaligursky merged 1 commit into
mainfrom
mv-particle-camera-reset

Conversation

@mvaligursky

Copy link
Copy Markdown
Contributor

Removes a vestigial per-frame material reset in the particle emitter that no longer does anything useful.

The emitter cached the scene's active camera in addTime() and, on any change, called onChangeCamera()resetMaterial(). This was meaningful when onChangeCamera() also ran regenShader() and the particle shader was built eagerly from camera state (the wrong variant could compile before a camera was assigned — see issue #6700). Since #6804 moved particle shader creation to on-demand getShaderVariant(), keyed on the rendering camera's output gamma/tonemapping at draw time, regenShader() was removed — but the now-pointless resetMaterial() call was left behind.

resetMaterial() only re-uploads camera-independent uniforms, so re-running it whenever the active camera changes is wasted work, and it fires every frame when multiple/alternating cameras render the same emitter.

Changes:

  • Remove the onChangeCamera()resetMaterial() call from the per-frame camera-tracking in addTime(); the active camera is still cached for the CPU distance sorter (its only consumer).
  • Delete the now-empty onChangeCamera() method.
  • resetMaterial() remains as the one-time setup in rebuild().

No behavior change: the only consumer of the cached camera is the CPU sorter (assignment preserved); screen-facing billboarding uses the rendering camera in-shader; and output gamma/tonemapping is still handled by getShaderVariant().

Performance:

  • Eliminates a redundant ~20-uniform material re-upload on every active-camera change (every frame in multi-camera scenes).

The particle emitter re-ran resetMaterial() (via onChangeCamera()) every time
the scene's active camera changed. That made sense when onChangeCamera() also
regenerated the shader and the shader was built eagerly from camera state
(wrong variant compiled before a camera was known). Since #6804 moved particle
shader creation to on-demand getShaderVariant() — keyed on the rendering
camera's output gamma/tonemapping at draw time — regenShader() was removed, but
the now-pointless resetMaterial() call was left behind.

resetMaterial() only re-uploads camera-independent uniforms, so re-running it on
camera change is wasted work (and fires every frame under multiple/alternating
cameras). The active camera is still cached for the CPU distance sorter, which
is its only consumer. Remove the onChangeCamera() indirection.
@github-actions

Copy link
Copy Markdown

Build size report

This PR changes the size of the minified bundles.

Bundle Minified Gzip Brotli
playcanvas.min.js 2275.6 KB (−0.1 KB, −0.00%) 584.4 KB (−0.0 KB, −0.01%) 454.1 KB (−0.0 KB, −0.00%)
playcanvas.min.mjs 2273.0 KB (−0.1 KB, −0.00%) 583.5 KB (−0.0 KB, −0.01%) 453.6 KB (−0.1 KB, −0.02%)

@mvaligursky mvaligursky merged commit 85b00db into main Jun 19, 2026
10 checks passed
@mvaligursky mvaligursky deleted the mv-particle-camera-reset branch June 19, 2026 08:42
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