Skip to content

TSL: setLayout breaks uniforms in custom Fn #31325

Open
@mdevecka

Description

@mdevecka

Description

Using setLayout with Fn makes uniform usage broken.
Whether uniform is defined within the function or outside is not relevant.
Tested both with WebGPU and WebGL fallback.
Works if setLayout function is not used.

Reproduction steps

See code.

Code

const testColor = Fn(() => {
  const tint = uniform(vec4(1,0,0,1)).label('tint');
  return vec4(1, 1, 1, 1).mul(tint);
}).setLayout({
  name: 'testColor', type: 'vec4',
  inputs: [],
});
...
testMaterial.fragmentNode = testColor();

Result

// Error while parsing WGSL: :23:45 error: unresolved value 'object'

// Three.js r177 - Node System

// global
diagnostic( off, derivative_uniformity );

// structs

struct OutputStruct {
  @location(0) color: vec4<f32>
};
var<private> output : OutputStruct;

// uniforms


// codes
fn testColor (  ) -> vec4<f32> {
  return ( vec4<f32>( 1.0, 1.0, 1.0, 1.0 ) * object.tint );
}

@fragment
fn main(  ) -> OutputStruct {
  // vars
  // flow
  // code
  // result
  output.color = testColor(  );
  return output;
}

Live example

N/A

Screenshots

No response

Version

three 0.177.0

Device

No response

Browser

No response

OS

No response

Metadata

Metadata

Assignees

Labels

TSLThree.js Shading Language

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions