I’ve got what seems like a simple TSL setup:
import {smoothstep, fwidth, uv, If, Discard} from ‘three/tsl’
// …
const mat = new THREE.MeshPhysicalMaterial(params)
const nodeMat = new THREE.MeshPhysicalNodeMaterial().copy(mat)
const antiAliasClippingNode = () => {
const mapUv = uv()
const edgePos = mapUv.x
const pixelWidth = fwidth(edgePos)
const fade = pixelWidth.mul(1.5)
const alphaFactor = smoothstep(fade.negate(), 0.0, edgePos)
If(alphaFactor.lessThanEqual(0.0), () => Discard())
return alphaFactor
}
nodeMat.opacityNode = antiAliasClippingNode()
When I run this, I get an error saying
TypeError: Cannot read properties of null (reading 'If')
on a line that looks like this,
export const If = ( ...params ) => currentStack.If( ...params );
from TSLCore.js.
What am I missing?