3

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 !

Community
  • 1
  • 1

1 Answers1

0

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?

Community
  • 1
  • 1
pailhead
  • 5,162
  • 2
  • 25
  • 46
  • Thanks for your reply. Even tho i didn't test reading the data from the buffer, i understood my approach was wrong (from all my searches everywhere i still wasn't very sure if i could have missed something about the gpu/cpu relationship). Anyway i accepted your answer. – user3018088 Oct 07 '15 at 13:47
  • @user3018088 What was wrong with your approach and how did you fix it? – imbrizi Aug 05 '18 at 07:58