How to use Discard in TSL;

I have this line of code: if (gl_fragColor. a<=0.0) discard; I haven’t found the ‘discard’ function in the documentation. How can I translate it into ‘tsl’?

The below PR should fix the issue in the TSL Transpiler:

You can write the statement like so:

import { Discard, If } from 'three/tsl';

If( gl_FragColor.a.lessThanEqual( 0.0 ), () => {

	Discard();

} );

A more compact option without the If statement is:

gl_FragColor.a.lessThanEqual( 0.0 ).discard();
3 Likes