Skip to content

TSL: If statement produces WGSL error. #28794

@Mugen87

Description

@Mugen87

Description

I'm currently trying to port the FXAA shader to TSL. The code uses more than one return statement to return a color value computed in its FxaaPixelShader() function.

Using an If() statement in TSL to determine if a return is required produces a WGSL error though.

Error while parsing WGSL: :40:3 error: return statement type must match its function return type, returned 'vec4', expected 'OutputStruct'
return vec4( 1.0, 0.0, 0.0, 1.0 );
^^^^^^

I have reproduce the issue with a live example by writing a simple effect that output just two colors depending on how an if statement evaluates.

Reproduction steps

  1. Go to https://jsfiddle.net/pq2dtag3/
  2. Check browser console.

Code

class CustomEffectNode extends TempNode {

	constructor() {

		super();

	}

	setup() {

		const effect = tslFn( () => {

			If( uv().x.lessThan( 0.5 ), () => {

     				return vec4( 1, 0, 0, 1 );

    			} );

			return vec4( 0, 0, 1, 1 );


		} );

		const outputNode = effect();

		return outputNode;

	}

}

Live example

https://jsfiddle.net/pq2dtag3/

Screenshots

No response

Version

r167dev

Device

Desktop

Browser

Chrome

OS

MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    TSLThree.js Shading Language

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions