I’m trying to implement a custom vertex shader in WGSL. I can do the following:
const params = {
position: Nodes.attribute('position', 'vec3'),
};
const myPositionNode = Nodes.wgslFn(`
fn getPosition(position: vec3<f32>) -> vec4<f32> {
// Do my custom vertex shader calculations
return vec4(...);
}
`);
myNodeMaterial.positionNode = myPositionNode(params);
This works, but it applies the usual modelview and projection transformations on my output - after I return it, outside of my control. When inspecting the generated WGSL, this is what the main function looks like:
@vertex
fn main( @location( 0 ) position : vec3<f32> ) -> NodeVaryingsStruct {
// system
var NodeVaryings: NodeVaryingsStruct;
// vars
var nodeVar0 : vec4<f32>;
var nodeVarying0 : vec3<f32>;
var nodeVarying2 : vec3<f32>;
// flow
// code
nodeVarying0 = position;
nodeVarying0 = getPosition( position ).xyz;
nodeVarying2 = vec3<f32>( 0.0, 0.0, 0.0 );
NodeVaryings.nodeVarying1 = ( NodeUniforms.nodeUniform0 * nodeVarying2 );
nodeVar0 = ( ( NodeUniforms.projectionMatrix * NodeUniforms.modelViewMatrix ) * vec4<f32>( nodeVarying0, 1.0 ) );
// result
NodeVaryings.Vertex = nodeVar0;
return NodeVaryings;
}
So my question is, is there a way to avoid those transformations that are applied after my getPosition()
function is called? Or is there a way to do this without a positionNode
? For example, if I am working in clip space for some custom objects.
Also I’m still on r157, so I apologize if this has already had time to change in r158-r159, but I would be happy to know if that is the case. I was not able to find anything on this in the examples.