Skip to content

TSL: toVar inside IF triggers incorrect warning "Declaration name '...' of 'vec3' already in use. Renamed to '...'" #33838

Description

@plotta-boop-beep123

Description

The code below triggers an "already in use" warning in the console, even though the variable is defined only once (and renaming it doesn't change the behavior). If THREE.TSL.If(THREE.TSL.bool(true), () => { is removed (making the code unconditional), the warning disappears. The same happens if "toVar()" is removed.

I get the following output in the console after running the code (for some reason, there are 2 logs from the debug node):

THREE.// #--- TSL debug - vertex shader ---#

if ( true ) {

	POSITION_origin = POSITION_v_positionWorld;
	positionLocal = ( POSITION_v_positionWorld - POSITION_origin );

/* ... */ positionLocal /* ... */
// #---------------------------------#
_display:62:35
THREE.TSL: Declaration name 'origin' of 'vec3' already in use. Renamed to 'origin_1'. Stack trace not available. Enable "THREE.Node.captureStackTrace" to capture stack traces. _display:72:36
THREE.// #--- TSL debug - vertex shader ---#
modelViewMatrix = ( render.cameraViewMatrix * object.nodeUniform0 );

if ( true ) {

	positionLocal = ( v_positionWorld - origin );

/* ... */ positionLocal /* ... */
// #---------------------------------#

Reproduction steps

Code

I am not entirely sure if it's a bug or I don't know how to use TSL properly. Minimal example:

import * as THREE from 'https://unpkg.com/three@0.184.0/build/three.webgpu.js';

const renderer = new THREE.WebGPURenderer();
const camera = new THREE.PerspectiveCamera(55, 1, 0.01, 100);
const scene = new THREE.Scene();
 
const geometry = new THREE.BufferGeometry();
geometry.setAttribute('position', new THREE.Float32BufferAttribute([0,1,2, 3,4,5, 6,7,8, 9,10,11, 12,13,14], 3));

scene.add(new THREE.Points(geometry, new THREE.PointsNodeMaterial({

  positionNode: THREE.TSL.Fn(() => {
    const output = THREE.TSL.positionLocal;
 
    THREE.TSL.If(THREE.TSL.bool(true), () => { 
      const origin = THREE.TSL.positionWorld.toVar('origin'); // <===============================
      output.xyz.assign(THREE.TSL.positionWorld.sub(origin)).debug();
    });

    return output;
  })() 

})));

renderer.init().then(() => renderer.render(scene, camera));

Live example

Screenshots

No response

Version

r184

Device

Desktop

Browser

Firefox

OS

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    TSLThree.js Shading Language

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions