Anyone know how to exit a TSL Loop?

I need to use a while loop in TSL. Can you exit a Loop based on a condition?

This may have been recently asked and solved in this thread How to exit early from a TSL node? - #2 by torrent

1 Like

The documentation is incomplete, so in such cases I just look for the original code whether it contains something. For example, when I searched for Loop I found this fragment:

Loop( { type: 'float', start: bounds.x, end: bounds.y, update: '+= delta' }, () => {
	const d = property( 'float', 'd' ).assign( map.uv( p.add( 0.5 ) ).r );
	if ( this.testNode !== null ) {
		this.testNode( { map: map, mapValue: d, probe: p, finalColor: ac } ).append();
	} else {
		// default to show surface of mesh
		ac.a.assign( 1 );
		Break();
	}
	p.addAssign( rayDir.mul( delta ) );
} );

Maybe the Break() command exits from a Loop?

3 Likes

We discussed this once before but I’m not sure if I understood it. These can compile to glsl and wgsl. They can compile back from them too? Is it possible to write a loop with a break in wgsl, since it’s documented, and then convert back to tsl to see what it needed?

2 Likes

This may be a work in progress…?

2 Likes

I used Break(). Can’t be sure but it seemed to work.

1 Like