Skip to content

Instantly share code, notes, and snippets.

@robertleeplummerjr
Created March 19, 2019 18:27
Show Gist options
  • Save robertleeplummerjr/7593a0b8c929d5ea7dfc824789bc7fcf to your computer and use it in GitHub Desktop.
Save robertleeplummerjr/7593a0b8c929d5ea7dfc824789bc7fcf to your computer and use it in GitHub Desktop.
const { GPU } = require('gpu.js');
const gpu = new GPU();
gpu.addFunction(function hash3D(x, y, z) {
const ix = (Math.floor(x/this.output.x)) + 1e5,
iy = (Math.floor(y/this.output.x)) + 1e5,
iz = (Math.floor(z/this.output.x)) + 1e5;
return ((ix * 10223) + (iy * 12919) + (iz * 16127)) % 1e6;
});
const kernel = gpu.createKernel(function() {
return hash3D(this.thread.x, this.thread.y, this.thread.z);
}, { output: [2, 2, 2] });
console.log(kernel());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment