Skip to content

TSL transpiler turns multiplication with signed float into subtractions #31281

Closed
@porst17

Description

@porst17

Description

The GLSL to TSL transpiler turns multiplications with negative numbers into subtractions if they are not surrounded by parenthesis.

The GLSL code

float correct = 1.0 * (-1.0);
float wrong = 1.0 * -1.0;

is transpiled to the obviously wrong result:

// Three.js Transpiler r177

import { float, mul } from 'three/tsl';

const correct = float( mul( 1.0, float( - 1.0 ) ) ).toVar();
const wrong = float( 1.0 - 1.0 ).toVar();

The same issue occurs for vector (and matrix?) data types when they are multiplied by a negative number.

Reproduction steps

  1. Copy the above example into the TSL transpiler.

Code

GLSL code that gives wrong transpilation result:

float correct = 1.0 * (-1.0);
float wrong = 1.0 * -1.0;

Live example

TSL transpiler (copy the code from above).

Screenshots

No response

Version

r177

Device

Desktop

Browser

Firefox

OS

MacOS

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