我需要计算多维数据数组,我认为GPUComputationRenderer是一个很好的解决方案。
我从一个示例项目开始,一直坚持这样做:
var gpuCompute = new GPUComputationRenderer( 100, 100, this.renderer );
var dtPosition = gpuCompute.createTexture();
var dtVelocity = gpuCompute.createTexture();
var velocityVariable = gpuCompute.addVariable(
"textureVelocity",
this.compFragmentShader(),
dtVelocity
);
var positionVariable = gpuCompute.addVariable(
"texturePosition",
this.compVertexShader(),
dtPosition
);
gpuCompute.setVariableDependencies(
velocityVariable,
[ positionVariable, velocityVariable ]
);
gpuCompute.setVariableDependencies(
positionVariable,
[ positionVariable, velocityVariable ]
);
gpuCompute.init();
gpuCompute.compute();
//TODO: Get pixels from resulting texture
我在three.js上读过一些例子:
另外,我读过这个堆栈溢出THREE.js read pixels from GPUComputationRenderer texture,但是没有解决方案,只有指向webGL的链接。
我是不是遗漏了什么?请提供一个例子或描述我做错了什么
发布于 2019-11-22 15:44:47
你不用把它拿回来。
WebGLRenderer.readRenderTargetPixels不能工作,因为GPUComputationRenderer没有呈现给WebGLRenderer本身。它使用WebGLRenderTargets (类似于屏幕外的“隐形”画布)。
您所指向的堆栈溢出线程说明了一切;这实际上是不可能的。除非你做了一些奇怪的数学,并将浮动纹理转换/打包成整数纹理。因此,一旦您将数据传输到gpu/glsl端,就几乎不可能将其返回到cpu/javascript端。
就像我说的,你不必把它拿回来。我相信我在您的代码中看到您熟悉顶点/片段着色器吗?我以前用点云做过。
您可以将dtPositions(或者dtPositions.texture )作为统一的内容传递到您的“显示”网格上的着色材料中,并使用着色器将位置从纹理中提取出来,并将顶点移动到该位置。
https://stackoverflow.com/questions/58952744
复制相似问题