I’m trying to recreate my WebGL2 vertexShader in the node system to be able to use WebGPU. Am I correct in using the uniforms and attributes in the node system?
//WebGL2 vertexShader
const VS = `
precision highp float;
precision highp int;
precision highp sampler2D;
uniform mat4 modelMatrix;
uniform mat4 modelViewMatrix;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
uniform vec3 cameraPosition;
uniform sampler2D vertexTexture;
uniform float time;
// Attributes
in vec3 position;
in vec3 normal;
in int vindex;
// Outputs
out vec3 vNormal;
out float idx;
void main() {
idx = float(vindex);
ivec2 texSize = textureSize(vertexTexture, 0);
float texWidth = float(texSize.x);
float texHeight = float(texSize.y);
int colIdx = int(floor(idx / texWidth));
int rowIdx = int(mod(idx, texHeight));
vec3 posData = texelFetch(vertexTexture, ivec2(rowIdx, colIdx), 0).rgb;
vNormal = normalize(normal);
vec3 newPosition = posData + vNormal * 3.;
gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition, 1.0);
}`;
My attempt to replicate this in the node system:
const params = {
vertexTexture: uniform( texture(DataTexture) ); //texture
time: uniform( dt ); //elapsed time
position: attribute('position'); //position attribute
normal: attribute('normal'); //normal attribute
vindex: attribute('vindex'); //custom attribute
}
const customShaderNodePosition = tslFn( ( input ) => {
//code...?
});
const material = new MeshBasicNodeMaterial();
material.positionNode = customShaderNodePosition(params);
Am I on the right track there?