如何将 three.js 的纹理转换为 WebGL

How to transform texture of three.js to WebGL

我得到了位置和法线两个纹理对象,比方说,

var tx1 = gpuCompute.getCurrentRenderTarget( positionVariable ).texture;
var tx2 = gpuCompute.getCurrentRenderTarget( normalVariable ).texture;

GPUComputationRendererthree.js计算得到(参考例子gpgpu/protoplanet(一))

我想将其转换为 WebGLBuffer 对象进行渲染,例如:

gl.bindBuffer(gl.ARRAY_BUFFER, tx1);
gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 3, gl.FLOAT, false, 0, 0);

gl.bindBuffer(gl.ARRAY_BUFFER, tx2);
gl.vertexAttribPointer(shaderProgram.vertexNormalAttribute, 3, gl.FLOAT, false, 0, 0);

但是直接赋值不行。

想请教一下有没有什么办法。这两个对象的格式快照如下所示(tx1来自threejs,tx3来自WebGL)。谢谢。

(1) https://threejs.org/examples/#webgl_gpgpu_protoplanet

您不能直接将纹理复制到缓冲区中。为什么不直接将它们用作纹理?这是一个从纹理中渲染位置的示例。