Select

In GLSL, you have both if statements and the ternary operator in order to be able to evaluate which of two expressions should be used. This can be achieved using the select function which works like a ternary operator.


const aboveZero: BooleanNode = attributes.position.y().gt(float(0))
const displacement: FloatNode = select(
    // condition
    aboveZero, 
    // if it is true
    pow(attributes.position.y(), 2), 
    // if it is false
    float(0) 
)

The condition must be of type BooleanNode and the values need to be of the same type.

Last updated