Reputation: 56
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.)
Upvotes: 1
Views: 371
Reputation: 56
After 3 hours, I found the answer from here: https://gist.github.com/globalpolicy/bb74dbbe7500b9d51da00b4797c7064d
Works in my website: http://integraali.com/jsxgraph/kuvat/gpujs/index.html
Upvotes: 1