Support dynamic cookie textures with clustered lighting#8930
Merged
Conversation
The clustered lighting cookie atlas assumed cookie textures were static and only blitted a cookie into the atlas when its slot was (re)assigned, so video or procedurally updated cookies were frozen at their first frame. Texture now stamps an uploadVersion (device.renderVersion) on every content upload, and each light tracks the uploadVersion it last copied into the atlas, so the cookie renderer re-blits when the content changes.
Build size reportThis PR changes the size of the minified bundles.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes clustered-lighting cookie atlasing for dynamic cookie textures (e.g. video textures or procedurally updated textures). It introduces a content-change version stamp on Texture uploads and uses it to decide when a light’s cookie needs re-blitting into the shared cookie atlas, removing the previous “static cookie” assumption.
Changes:
- Add
Texture.uploadVersion, stamped on every content upload (markForUpload()), to detect pixel-content changes independent ofrenderVersionDirty. - Track per-light
cookieRenderVersionand re-blit a cookie into the atlas when the cookie texture’suploadVersionchanges (plus existing slot reassignment / device restore paths). - Add a new example demonstrating both procedural and video cookies updating correctly under clustered lighting.
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/scene/renderer/render-pass-cookie-renderer.js | Re-blits cookies into the clustered cookie atlas when texture content changes (via uploadVersion), not just on slot reassignment / force copy. |
| src/scene/light.js | Adds per-light cookieRenderVersion to remember which cookie content version was last copied into the atlas. |
| src/platform/graphics/texture.js | Adds uploadVersion and stamps it in markForUpload() so content uploads can be detected by downstream systems. |
| examples/src/examples/graphics/clustered-light-cookies.example.mjs | New example showcasing dynamic cookies (procedural + video) updating in the clustered cookie atlas. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4926. The clustered lighting cookie atlas assumed cookie textures were static — a cookie was only copied into the shared atlas when the light's atlas slot was (re)assigned. Dynamic cookies such as a video or a procedurally updated texture were therefore frozen at their first frame (the documented workaround was to disable clustered lighting).
Changes:
Texturenow stamps anuploadVersion(fromdevice.renderVersion) on every content upload inmarkForUpload(), so content changes — including same-size video frame uploads — are detectable.renderVersionDirtyonly tracks property/bind-group changes and never fires for plain content uploads, so a new counter was needed.Lightrecords theuploadVersionit last copied into the cookie atlas. The cookie render pass re-blits a cookie whenever its texture'suploadVersiondiffers from that, in addition to the existing slot-reassignment and device-restore cases. Tracking is per-light (not a single global high-water mark) so a cookie that animates while its light is off-screen or unallocated is not permanently skipped.Examples:
graphics/clustered-light-cookies: four spot lights project cookies onto a chess board, two using a procedurally generated cookie regenerated every few frames and two using a video cookie uploaded every frame. The shared cookie atlas is drawn in the corner to show it re-rendering as the content changes.Performance: