3
votes

I am changing the positions of some vertices inside a vertex shader but i can't find a way to get those new updated vertices positions back inside js (i'm currently using THREE.js : the vertex position of my mesh's vertices always remains the same). I found this link Retrieve Vertices Data in THREE.js, but glGetTexImage doesn't exist in webgl (and i'm quite skeptical about this floating-point texture method as well). Thanks for your help !

1
Please include the code that you've tried.Jason D

1 Answers

0
votes

If reading the data from the buffer is the only problem, you can do that like this:

//render the pass into the buffer
renderer.render( rttScene, rttCamera, rttTexture, true );

// ...


//allocate an array to take the data from the buffer
var width = rttTexture.width;
var height = rttTexture.height;
var pixels = new Uint8Array(4 * width * height); 


//get gl context bind buffers, read pixels
var gl = renderer.context; 
var framebuffer = rttTexture.__webglFramebuffer;
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);        
gl.viewport(0, 0, width, height);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);

WebGL - reading pixel data from render buffer

But setting all this up is complicated, and reading the texture might be slow, why not do this on the cpu?