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’?
Mugen87
February 17, 2025, 9:35am
3
The below PR should fix the issue in the TSL Transpiler:
dev
← Mugen87:dev1
opened 09:34AM - 17 Feb 25 UTC
Related issue: https://discourse.threejs.org/t/how-to-use-discard-in-tsl/78217/2…
**Description**
The TSL Transpiler can now transpile the `discard` syntax in GLSL to TSL:
```
if ( finalColor.a <= 0.0 ) discard;
````
is converted to:
```js
import { Discard, If } from 'three/tsl';
If( finalColor.a.lessThanEqual( 0.0 ), () => {
Discard();
} );
```
That said, there is a more compact way in writing the above statement in TSL without the `If`:
```js
finalColor.a.lessThanEqual( 0.0 ).discard();
```
But I think the above should be okay for transpiled code.
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