Swizzling work on the returned value of overloaded function

Swizzling a node returned from an overloaded TSL function doesn’t work correctly. It always resolves the node type to that of the first function provided to overloadingFn.

const f = overloadingFn([
  // Swapping the functions produces different results.
  Fn(([x]) => x.mul(2)).setLayout({
    name: 'f_float',
    type: 'float',
    inputs: [{ name: 'x', type: 'float' }]
  }),
  Fn(([x]) => x.mul(2)).setLayout({
    name: 'f_vec3',
    type: 'vec3',
    inputs: [{ name: 'x', type: 'vec3' }]
  })
])

// Outputs: vec4<f32>( f_vec3( vec3<f32>( 1.0, 1.0, 1.0 ) ), 1.0 )
// Expected: vec4<f32>( f_vec3( vec3<f32>( 1.0, 1.0, 1.0 ) ).x )
output = f(vec3(1)).x

Also, swizzling a variable created from the returned node always selects the x element.

// Outputs: f_vec3( vec3<f32>( 1.0, 1.0, 1.0 ) ).x
// Expected: f_vec3( vec3<f32>( 1.0, 1.0, 1.0 ) ).z
output = f(vec3(1)).toVar().z

Leave a comment

Your email address will not be published. Required fields are marked *