Skip to content

TSL: Add debug()#30797

Merged
sunag merged 3 commits into
mrdoob:devfrom
sunag:dev-debug
Mar 25, 2025
Merged

TSL: Add debug()#30797
sunag merged 3 commits into
mrdoob:devfrom
sunag:dev-debug

Conversation

@sunag

@sunag sunag commented Mar 25, 2025

Copy link
Copy Markdown
Collaborator

Related issue: #30783 (comment)

Description

Add debug() method to facilitate inspection of the generated code.

const timerScaleNode = time.mul( vec2( - 0.5, 0.1 ) );
const animateUV = uv().add( timerScaleNode );

materialBox.colorNode = checker( animateUV ).toVar().debug();

Alternative

materialBox.colorNode = uv().debug( ( code ) => {

	console.log( code );

} )

WGSL Result

// #--- TSL Debug ---#
nodeVar0 = ( ( nodeVarying3 + ( vec2<f32>( render.nodeUniform0 ) * vec2<f32>( -0.5, 0.1 ) ) ) * vec2<f32>( 2.0 ) );
nodeVar1 = sign( ( ( floor( nodeVar0.x ) + floor( nodeVar0.y ) ) % 2.0 ) );

/* ... */ nodeVar1 /* ... */
// #-----------------#

GLSL Result

// #--- TSL Debug ---#
nodeVar0 = ( ( nodeVarying3 + ( vec2( f_nodeUniform0 ) * vec2( -0.5, 0.1 ) ) ) * vec2( 2.0 ) );
nodeVar1 = sign( mod( ( floor( nodeVar0.x ) + floor( nodeVar0.y ) ), 2.0 ) );

/* ... */ nodeVar1 /* ... */
// #-----------------#

@sunag sunag added this to the r175 milestone Mar 25, 2025
@github-actions

github-actions Bot commented Mar 25, 2025

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 336.08
78.29
336.08
78.29
+0 B
+0 B
WebGPU 530.63
147.4
531.17
147.59
+548 B
+198 B
WebGPU Nodes 530.09
147.29
530.64
147.49
+548 B
+197 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 465.15
112.18
465.15
112.18
+0 B
+0 B
WebGPU 602.3
163.4
602.81
163.54
+513 B
+135 B
WebGPU Nodes 557.34
152.84
557.85
152.97
+513 B
+131 B

@sunag sunag marked this pull request as ready for review March 25, 2025 16:17
@sunag sunag merged commit 30c4024 into mrdoob:dev Mar 25, 2025
@sunag sunag deleted the dev-debug branch March 25, 2025 19:50
@Makio64

Makio64 commented Mar 26, 2025

Copy link
Copy Markdown
Contributor

thanks @sunag ! <3

@brunosimon

Copy link
Copy Markdown
Contributor

Great idea

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.

3 participants