Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从三个js中的计算纹理中获取像素?_Javascript_Three.js - Fatal编程技术网

Javascript 如何从三个js中的计算纹理中获取像素?

Javascript 如何从三个js中的计算纹理中获取像素?,javascript,three.js,Javascript,Three.js,我需要计算多维数据数组,我认为GPUComputionRenderer是一个很好的解决方案 我从一个示例项目开始,并一直坚持这一点: var gpuCompute = new GPUComputationRenderer( 100, 100, this.renderer ); var dtPosition = gpuCompute.createTexture(); var dtVelocity = gpuCompute.createTexture(); var velocityVariabl

我需要计算多维数据数组,我认为GPUComputionRenderer是一个很好的解决方案

我从一个示例项目开始,并一直坚持这一点:

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上读过一些例子:

另外,我读过这个堆栈溢出,但没有解决方案,只有指向webGL的链接

我错过什么了吗?
请提供一个例子或描述我做错了什么

你不必把它拿回来

WebGLRenderer.readRenderTargetPixels无法工作,因为GPUComputionRenderer不会渲染到WebGLRenderer本身。它使用WebGLRenderTargets(类似于屏幕外的“不可见”画布)

您指向的堆栈溢出线程说明了一切;这真的不可能。除非你做一些奇怪的数学运算并将浮点纹理转换/打包为整数纹理。。因此,一旦将数据传输到gpu/glsl端,就几乎不可能将其返回到cpu/javascript端

就像我说的,你不必把它拿回来。我相信我在您的代码中看到您熟悉顶点/片段着色器?我以前用点云做过


您可以将dtPositions(或dtPositions.texture)作为一个统一体传递到“显示”网格上的shadermaterial中,并使用着色器从纹理中获取位置,然后将顶点移动到该位置

也许吧?你好@gman!我试过这个。它只返回填充了0的数组