Skip to content

TSL: Normal accessors break when called in both ends of the select node #29489

@njarraud

Description

@njarraud

Description

The glsl or wgsl code generated by a select node using the same normal accessor on both ends is not correct. e.g. normalLocal

The following code select(equal(1, 0), normalLocal, normalLocal)generates the following glsl code (similar to wgsl code) -

// vars
vec3 nodeVar0;
vec3 normalLocal;

// flow
// code

if ( ( 1.0 == 0.0 ) ) {
    normalLocal = nodeVarying1;
    nodeVar0 = normalLocal;
} else {
    nodeVar0 = normalLocal;
}

In the second section of the condition, we can see that nodeVar0 is assigned to normalLocal but normalLocal is never assigned to nodeVarying1 which holds the correct data. Hence the target in my tsl editor example remains black and is incorrect.

This is obviously a simplified example to pin point the issue. If the same accessor is used, even in nested functions, on both side of the ternary operator, it fails. A real life example would be to switch between two different triplanarTexture nodes. This is currently not possible.

Reproduction steps

  1. Open the threejs tsl editor
  2. Copy and paste the code below

Code

const {  vec4, normalLocal, select, equal, color } = THREE;

// Condition is false, second normalLocal is called - target is black - NOT OK
output = vec4( select(equal(1, 0), normalLocal, normalLocal), 1 );

// Condition is true, first normalLocal is called - target is blue - OK
// output = vec4( select(equal(0, 0), normalLocal, normalLocal), 1 );

Live example

Screenshots

No response

Version

r169dev

Device

No response

Browser

No response

OS

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugTSLThree.js Shading Language

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions