Without TSL.
Thank you in advance.
Without TSL.
Thank you in advance.
I havenât worked with TSL at all, but from reading the documentation, it seems like it is.
NodeMaterial has vertexNode and fragmentNode properties. It seems that you can write the entire shader within them, with some caveats (you still need to initialize and include the uniform nodes for example).
This, to me seems the same as:
const m = new ShaderMaterial()
m.vertexShader = ââŚâ
m.fragmentShader = ââŚâ
Basically its
const m = new NodeMaterial()
m.vertexNode = WgslFn('...')
m.fragmentNode = WgslFn('...')
With some gotchas on how you include the varyings and the uniforms (still TSL).
Again, i have never used TSL, these are just my assumptions. They could be completely and uterly wrong, because it does seem that no one has ever said that even something similar to ShaderMaterial will exist in the future versions of three. But judging from this documentation, i donât think i can be terribly wrong here ![]()
Yes thatâs how itâs done. Sadly it doesnât really work âwithout TSLâ
Itâs also the most unpractical hybrid solution since you need both TSL features on top of your mandatory WGSL declaration to make it work smoothly. Maybe still useful as a starting point to learn pure WGSL?
very basic attempt using fragmentNode and passing some values
https://codepen.io/William-J-Jones/pen/raLgBqN?editors=1111
Maybe some imports from TSL are not needed (at least in this case)?
const resolution = new THREE.Vector2(innerWidth, innerHeight); // no vec2
const mat = new THREE.MeshBasicNodeMaterial();
mat.fragmentNode = customFragment(screenCoord, resolution); // no vec4
fixed
it also confirm you can mix the two
probably only WgslFn is mandatory, but iâm too lazy to look for a raw version of screenCoordinate
Whats custom fragment?
This is the name of the WGSL function/node. Itâs not a class, just a regular call, rename it as you wish.
const customFragment = wgslFn(`
fn customFragment(screenCoord: vec2<f32>, resolution: vec2<f32>) -> vec3<f32> {
I wonder why this isnât being advertised.
You can use WGSL in Three.js very well without TSL. Itâs not completely native, but in my view thatâs not a disadvantage. I have a smaller repo here that shows how I use WGSL code.