mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
101.89k stars 35.32k forks source link

Nodes: Line2NodeMaterial dash mode broken #28884

Open aardgoose opened 2 months ago

aardgoose commented 2 months ago

Description

The PR #28585 appears to have broken Line2NodeMaterial. Reverting the PR fixes the error.

In dashed mode, the fragment shader fails to compile with the error in

https://github.com/mrdoob/three.js/blob/0679c557066907c19659697deaa3d2d0b0c7e724/src/nodes/materials/Line2NodeMaterial.js#L269

If the multiplications within the cond() expression are removed, the shader compiles as expected.

Reproduction steps

  1. run the example webgpu_lines_fat
  2. select 'dashed' to enable dashed line mode.

Code

n/a

Live example

Line2NodeMaterials example

Screenshots

No response

Version

166

Device

No response

Browser

No response

OS

No response

Mugen87 commented 2 months ago

I had a few issues with cond() as well when porting code to TSL. Out of curiosity, does it work if the code is change to the following?

const lineDistance = float( 0 ).toVar();

If( positionGeometry.y.lessThan( 0.5 ), () => {

    lineDistance.assign( dashScaleNode.mul( instanceDistanceStart ) );

} ).else( () => {

    lineDistance.assign( materialLineScale.mul( instanceDistanceEnd ) );

} );
aardgoose commented 2 months ago

Yes and no (with a float( 0 ).toVar();

It doesn't produce an invalid shader, but doesn't work as expected. Presumably because If() uses cond() internally.

Mugen87 commented 2 months ago

Ah yes, the toVar() is required in this case.

In any event, this was just intended as a possible workaround. Of course it's best to make the normal cond() usage work.