Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSL: Wrong compilation of min(...) and max(...) with 3 or more parameters #28728

Open
boytchev opened this issue Jun 23, 2024 · 0 comments
Open
Labels
Enhancement TSL Three.js Shading Language

Comments

@boytchev
Copy link

Description

TSL allows many parameters to functions min(...) and max(...). Using more than 2 parameters, however, fails:

  • Both GLSL and WGSL trigger a syntax error, as they support only two parameters, but the code has 3 parameters
  • The compiled code contains only the first three parameters; the rest are silently ignored

The GLSL error is:

THREE.WebGLBackend: Must have a compiled fragment shader attached:
SHADER_INFO_LOG:
ERROR: 0:56: 'min' : no matching overloaded function found
ERROR: 0:56: 'max' : no matching overloaded function found

The WGSL error is (significantly shortened):

Error while parsing WGSL: no matching call to
'min(abstract-float, abstract-float, abstract-float)'
overload expects 2 arguments, call passed 3 arguments

Suggested solutions

  • compile min(a,b,c,d,...) into min(a,min(b,min(c,...))); and the same for max
  • throw an error message if more than 2 parameters are used
  • describe in the documentation what functions accept multiple parameters and how they are dealt with when the functions are chained

Untested situation

Chained min(...) and max(...) are not tested

Reproduction steps

  1. Use min or max with more than 3 parameters:
mn = min( 11, 12, 13, 14, 15 );
mx = max( 21, 22, 23, 24, 25 );
  1. Observe the error message in the console

Code

(see the live example)

Live example

Minimal code. Does not render anything meaningful, just generates the error messages.

https://codepen.io/boytchev/pen/RwmyQLY

Screenshots

Demonstration that only the first three parameters are compiled:

Using the TSL editor in GLSL mode:

image

Using the TSL editor in WGSL mode:

image

Version

r165

Device

Desktop

Browser

Chrome, Firefox

OS

Windows

@sunag sunag added TSL Three.js Shading Language Enhancement labels Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement TSL Three.js Shading Language
2 participants