There is an example on how to use pc.TransformFeedback here
I tried to follow it, but without using mesh API and manually creating a vertex buffer. In my example below, the vertex shader should reset the vertex position values to zero. However, the output buffer still shows them as 0.5 after processing. What am I missing?
// pseudo code
// shader
attribute vec4 vertex_position;
varying vec4 out_vertex_position;
void main(void)
{
out_vertex_position = vec4(0.);
}
// initialize
const vertexFormat = new pc.VertexFormat(device, [
{ semantic: pc.SEMANTIC_POSITION, components: 4, type: pc.TYPE_FLOAT32 }
]);
const pos = new Float32Array([0.5, 0.5, 0.5, 0.5]);
const vb = new pc.VertexBuffer(device, vertexFormat, 1, pc.BUFFER_DYNAMIC, pos.buffer);
tf = new pc.TransformFeedback(vb);
const shader = pc.TransformFeedback.createShader(
device, shader, "test"
);
// update
tf.process(shader);
const output = tf.outputBuffer.lock();
new Float32Array(output); // [ 0.5, 0.5, 0.5, 0.5 ]