GPU.js is a JavaScript Acceleration library

GPU.js is a JavaScript Acceleration library
Average rating: 0
(0 votes)

We are never tired of JavaScript. Actually, we might be tired sometimes, but who cares? The point is we love JS and even more we like to be the pilgrims of new JS discoveries. What about you? Do you want to know something new we found? GPU.js is a JavaScript Acceleration library for GPGPU (General purpose computing on GPUs) in JavaScript. Excited?

GPU.js will automatically compile simple JavaScript functions into shader language and run them on the GPU. In case a GPU is not available, the functions will still run in regular JavaScript.

Settings are an object used to create an instance of GPU. Example: new GPU(settings)

  • canvasHTMLCanvasElement. Optional. For sharing canvas. Example: use THREE.js and GPU.js on same canvas.
  • webGlWebGL2RenderingContext or WebGLRenderingContext. For sharing rendering context. Example: use THREE.js and GPU.js on same rendering context.

Sometimes, you want to produce a canvas image instead of doing numeric computations. To achieve this, set the graphicalflag to true and the output dimensions to . The thread identifiers will now refer to the x and y coordinate of the pixel you are producing. Inside your kernel function, use this.color(r,g,b) or this.color(r,g,b,a) to specify the color of the pixel.

To strongly type a function you may use settings. Settings take an optional hash values: returnType: optional, defaults to float, the value you’d like to return from the function argumentTypes: optional, defaults to float for each param, a hash of param names with values of the return types.

Please find many more examples here.

Learn all you need to know about JavaScript in the Complete JavaScript Handbook by Flavio Copes. And explore our monthly JS digests we issue! Soon we will make a new one! Stay tuned!

Rate this article, if you like it

Thanks! You’ve rated this material!

Got a project? Let's discuss it!

*By submitting this form you agree with our Privacy Policy.

Mailing & Legal Address

Syndicode Inc. 340 S Lemon Ave #3299, Walnut CA, 91789, USA

Visiting & Headquarters address
Kyiv Sofiivska 1/2a, 01001, Kyiv, Ukraine
Dnipro Hlinky 2, of. 1003, 49000, Dnipro, Ukraine
Email info@syndicode.com
Phone (+1) 9035021111