Skip to content

TSL: Use local declarations for cached values and variable intents - #34637

Merged
sunag merged 4 commits into
mrdoob:devfrom
sunag:dev-let
Sep 23, 2026
Merged

sunag merged 4 commits into
mrdoob:devfrom
sunag:dev-let

Conversation

@sunag

@sunag sunag commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Related issue: #33302

Description

Generate local shader declarations for automatically cached values and toVarIntent(), while preserving global declarations for explicit .toVar() calls.

  • Add generateLetStatement() and a local option to getVarFromNode().
  • Preserve mutability through element and struct member assignments.
  • Isolate loop caches and prevent duplicate declarations across blocks.

Minimalist example to test using webgpu_tsl_editor

const { vec3, Fn, time } = await import( 'three/tsl' );

output = Fn( () => {

    const scaledTime = vec3( time.mul( .5 ) ); // add `toVar()` to use global definition
    //scaledTime.addAssign( 1 ) // the statement will use `var` instead of `let`
    const testValue = scaledTime.add( scaledTime );

    return testValue;

} )();

@sunag sunag added this to the r187 milestone Sep 23, 2026
@github-actions

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
Core 389.92
102.29
389.92
102.29
+0 B
+0 B
WebGL 372.98
87.29
372.98
87.29
+0 B
+0 B
WebGPU 425.45
114.61
425.62
114.69
+174 B
+88 B
WebGPU Nodes 711.06
195.32
711.52
195.49
+465 B
+169 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 517.61
124.39
517.61
124.39
+0 B
+0 B
WebGPU 764.66
204.88
765.13
205.06
+465 B
+172 B
WebGPU Nodes 710.66
191.46
711.13
191.64
+465 B
+179 B

@sunag
sunag marked this pull request as ready for review September 23, 2026 14:20
@sunag
sunag merged commit eac578d into mrdoob:dev Sep 23, 2026
10 checks passed
@sunag
sunag deleted the dev-let branch September 23, 2026 16:23
vibegameengine pushed a commit to vibegameengine/three.js that referenced this pull request Oct 23, 2026
…there again

r186 builds If/ElseIf/Else branches that share a node with the first branch's
assignment only: the next branch read the variable unset. The deferred light response
reads its surface terms that way, and every pixel past the first branch lost its sun.
A TempNode reused from its cached property now goes through the same flow-code
hierarchy Node.build already uses (upstream later unified this in mrdoob#34607/mrdoob#34637).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HSkeX8VxSD7ytzMLDx4ucf
vibegameengine pushed a commit to vibegameengine/three.js that referenced this pull request Oct 23, 2026
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