Skip to content

Instantly share code, notes, and snippets.

let chunkSize = 15;
let inputWidth = 25;
let image.dims = {
w: 1920,
h: 1080
}
const getInput = gpu.createKernel(function(imageTexture, imageWidth, x1, y1, x2, y2) {
let x1 = this.thread.x * chunkSize;
let y1 = this.thread.y * chunkSize;
let edge = this.gpu
.createKernel(function(data, channelWidth) {
let threshold = 124;
let remainder = this.thread.x % 4;
let sourceIndex = this.thread.x - remainder;
let x = (sourceIndex % channelWidth) / 4;
let y = Math.floor((sourceIndex / channelWidth) / 4);
let sourceR = data[sourceIndex];
let sourceG = data[sourceIndex + 1];
let sourceB = data[sourceIndex + 2];
let edge = this.gpu
.createKernel(function(data, channelWidth) {
let threshold = 124;
let remainder = this.thread.x % 4;
let sourceIndex = this.thread.x - remainder;
let x = (sourceIndex % channelWidth) / 4;
let y = Math.floor((sourceIndex / channelWidth) / 4);
let sourceR = data[sourceIndex];
let sourceG = data[sourceIndex + 1];
let sourceB = data[sourceIndex + 2];
let edge = this.gpu
.createKernel(function(data, channelWidth) {
let threshold = 124;
let remainder = this.thread.x % 4;
let sourceIndex = this.thread.x - remainder;
let x = (sourceIndex % channelWidth) / 4;
let y = Math.floor((sourceIndex / channelWidth) / 4);
let sourceR = data[sourceIndex];
let sourceG = data[sourceIndex + 1];
let sourceB = data[sourceIndex + 2];
const gl = document.createElement('canvas').getContext('webgl');
gl.canvas.width = 2048;
gl.canvas.width = 2048;
twgl.addExtensionsToContext(gl);
const vs = `
attribute vec4 position;
void main() {
gl_Position = position;
}
`;
C:\Users\Jonathan\Documents\GitHub\gpu.js>npm install
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
audited 7280 packages in 5.767s
found 11 vulnerabilities (4 low, 1 moderate, 6 high)
run `npm audit fix` to fix them, or `npm audit` for details
C:\Users\Jonathan\Documents\GitHub\gpu.js>npm install
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
audited 7280 packages in 5.767s
found 11 vulnerabilities (4 low, 1 moderate, 6 high)
run `npm audit fix` to fix them, or `npm audit` for details
const matMult = gpu.createKernel(function(a, b) {
var sum = 0;
for (var i = 0; i < 512; i++) {
sum += a[this.thread.y][i] * b[i][this.thread.x];
}
return sum;
}).setOutput([512, 512]);
// a set of Textures output by a previous batch, ready for further processing
const inputs = [ 1 : [ 1 : Texture, 2: Texture, /* ... */ 1000: texture ], /* ... */ 1000 : [ 1 : Texture, 2: Texture, /* ... */ 1000: texture ] ]
C:\Users\Jonathan\Documents\GitHub\brain.js>npm install
> gl@4.2.2 install C:\Users\Jonathan\Documents\GitHub\brain.js\node_modules\gl
> prebuild-install || node-gyp rebuild
prebuild-install WARN install No prebuilt binaries found (target=10.15.3 runtime=node arch=x64 libc= platform=win32)
C:\Users\Jonathan\Documents\GitHub\brain.js\node_modules\gl>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\Users\Jonathan\AppData\Local\Programs\Python\Python37\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
C:\Users\Jonathan\Documents\GitHub\brain.js>npm i
> deasync@0.1.14 install C:\Users\Jonathan\Documents\GitHub\brain.js\node_modules\deasync
> node ./build.js
`win32-x64-node-10` exists; testing
Binary is fine; exiting
> gl@4.2.2 install C:\Users\Jonathan\Documents\GitHub\brain.js\node_modules\gl
> prebuild-install || node-gyp rebuild