Description
Description
I need access to certain aspects of 3js like TransformFeedback/Compute with WebGL, To do so I need to run things with WebGPURenderer with forceWebGL set to true. The hitch is that RawShaderMaterial or something like it is no longer supported. This is a requirement because I have almost a decade worth of raw shaders plus, I need a simple way to keep shader code free & portable. TSL isn't a solution when there is a need to work in various webGL/openGL environments, be it shadertoys, pixiJS, babylonjs, godot, etc. I've even grabbed raw glsl code out of the blender project to use in 3js projects.
So far, the furthest I've managed to get TSL to work with raw shaders doesn't really work. Even using uniforms seems broken as even though I gave it a name, it changed its name plus threw it in a UBO of an unknown name instead of a simple uniform. I understand the idea to match how webgpu works, but there should be more control over uniforms in general that is predictable & known without having to output the GLSL code to see what really was created.
I dont know what the final solution should be, just bring back raw shaders for both GLSL & WGSL or provide some nodes that allows just a big text dump containing code, uniforms, attributes, varying. Also be nice to still have easy access to some of the main matrices like model, view & perspective plus cameraPosition was always nice to have around. I do want to use UBOs more but I want it to be optional if possible to better match WebGL / OpenGL shader standards.
As a side note, I even tried to extend nodeMaterial to see if I can hijack the builder to swop out the vertex/fragment shader before they're compiled into a program but that wasn't successful either.
const uColor = THREE.uniform( new THREE.Color( 0x00ff00 ) );
uColor.name = 'uColor';
const fCode = THREE.code( `
vec4 test2(){
return vec4( 0.0, 1.0, 0.0, 1.0 ); // vec4( uColor, 1.0 );
}
`);
const fMain = THREE.glslFn(`
vec4 vertMain(){
return vec4( 1.0, 0.0, 0.0, 1.0 ); // test2();
}
`, [ fCode, uColor ] );
const mat = new THREE.NodeMaterial();
mat.fragmentNode = fMain();
const geo = new THREE.PlaneGeometry( 1, 1 );
const mesh = new THREE.Mesh( geo, mat );
App.debugMaterial( mesh ).then( sh=>console.log( sh.fragmentShader ) );
Outputs
layout( std140 ) uniform fragment_object {
vec3 f_uColor;
};
vec4 test2(){
return vec4( 0.0, 1.0, 0.0, 1.0 ); // vec4( uColor, 1.0 );
}
vec4 vertMain ( ){
return vec4( 1.0, 0.0, 0.0, 1.0 ); // test2();
}
layout( location = 0 ) out vec4 fragColor;
void main() {
fragColor = vertMain( );
}
Solution
xxx
Alternatives
xxx
Additional context
No response