How can I access the values given by gpu.js

340 Views Asked by At

I am learning to use gpu.js to do calculations in the GPU. I am able to do my calculations for two JavaScript matrices a and b and to display the result as a canvas image.

Question: How can I access the calculated numerical values? The values are generated by

const render = gpu.createKernel(function(a,b) {
        this.color(
    Math.sqrt(-2*Math.log(a[this.thread.y][this.thread.x]))*Math.cos(2*3.14*b[this.thread.y][this.thread.x]), 
    Math.sqrt(-2*Math.log(a[this.thread.y][this.thread.x]))*Math.sin(2*3.14*b[this.thread.y][this.thread.x]),
     0, 1);
}).setOutput([512, 512]).setGraphical(true);

Perhaps there is another setting instead of .setGraphical(true) which creates a standard JavaScript array, which I can then access.

Or perhaps (I don't think this is the right way) I should access the values of the canvas with some code like

var ctx = canvas.getContext("2d");
var p = ctx.getImageData(x, y, 1, 1).data;

as in Get pixel color from canvas, on mousemove

My code is at http://integraali.com/jsxgraph/kuvat/turbojs/kuvasta4.html (I tried to put my code to JSFiddle, but the code did not work there. Perhaps JSFiddle does not allow to load gpu.js, I don't know what is the issue.)

1

There are 1 best solutions below

0
On