2015-10-06 56 views
2

我正在改變頂點着色器內某些頂點的位置,但是我找不到一種方法讓這些新的更新頂點位置回到js中(我目前正在使用THREE.js:我的網格頂點的頂點位置始終保持不變)。 我發現這個鏈接Retrieve Vertices Data in THREE.js,但glGetTexImage不存在於webgl(我也很懷疑這個浮點紋理方法)。 感謝您的幫助!在THREE.js頂點着色器之後得到變換後的頂點位置

+0

請包含您嘗試過的代碼。 –

回答

0

如果從緩衝區中讀取的數據是唯一的問題,你可以是這樣做的:

//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

但設置這一切起來是複雜的,和讀取紋理可能很慢,爲什麼不在CPU上做這件事?

+0

感謝您的回覆。即使我沒有測試從緩衝區讀取數據,我明白我的方法是錯誤的(從我到處都是我的搜索,我仍然不確定我是否可能錯過了有關gpu/cpu關係的內容)。無論如何,我接受你的答案。 – user3018088

相關問題