Skip to content

TSL: Inconsistent chaining for step vs smoothstep #31205

@boytchev

Description

@boytchev

Description

The chaining of step and smoothstep are inconsistent with each other. smoothstep chains the last parameter, which is OK, but steps chains the first parameter - this is inconsistent with smoothstep, but consistent with most other chaining, where the first parameter got chained.

  • smoothstep( e0, e1, x )x.smoothstep( e0, e1 ) -- this is OK
  • step( edge, x )edge.step( x ) -- this is inconsistent

Two suggestions:

  • Making step consistent with smoothstep and chain its last parameter x.step( edge )
  • Adding documentation about what parameter is chained, e.g. always the fisrt, except for step, smoothstep...

Issues:

  • Such change will break already existing TSL-based code

Reproduction steps

  1. Place the code form [Code] section in the TSL Editor
  2. Uncomment one of the lines 5..9 to see the effect
  3. Lines 5, 6 and 7 work fine
  4. Line 8 should result as 7, but it is not
  5. Line 9 just tests that step chains the first parameter

Code

const { float, vec4, uv, step, smoothstep } = await import( 'three/tsl' );

const x = uv().x;

//const r = smoothstep( 0.25, 0.75, x );
//const r = x.smoothstep( 0.25, 0.75 );
//const r = step( 0.5, x );
const r = x.step( 0.5 );
//const r = float( 0.5 ).step( x );

output = vec4( r, 0, 0, 1 );

Live example

(not provided)

Screenshots

Left two snapshots show that smoothstep chains the last parameter.
Right three snapshots show that step chains the first parameter.

Image

Version

r176

Device

Desktop

Browser

Chrome

OS

Windows

Metadata

Metadata

Assignees

Labels

TSLThree.js Shading Language

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions