Skip to content

Instantly share code, notes, and snippets.

@jt0dd
Last active March 26, 2019 16:25
Show Gist options
  • Select an option

  • Save jt0dd/d1c0b13122d16e7774c2c8b2e7d173a7 to your computer and use it in GitHub Desktop.

Select an option

Save jt0dd/d1c0b13122d16e7774c2c8b2e7d173a7 to your computer and use it in GitHub Desktop.
let chunkSize = 15;
let inputWidth = 25;
let image.dims = {
w: 1920,
h: 1080
}
const myFunc = gpu.createKernel(function(imageTexture, imageWidth, x1, y1, x2, y2) {
let x1 = this.thread.x * chunkSize;
let y1 = this.thread.y * chunkSize;
let x2 = x1 + inputWidth;
let y2 = y1 + inputWidth;
let input = [];
for (let x = x1; x < x2; x++) {
for (let y = y1; y < y2; y++) {
let index = (y * imageWidth) + x;
input.push(imageTexture[index]);
}
}
return input;
}).setOutput([inputWidth, inputWidth]);
let matchLocations = [];
for (let x1 = 0; x1 < image.dims.w - chunkSize; x1 += chunkSize){
for (let y1 = 0; y1 < image.dims.y - chunkSize; y1 += chunkSize){
let x2 = x1 + inputWidth;
let y2 = y1 + inputWidth;
if (subKernelThatRepresentsNetwork(myFunc(imageTexture, image.dims.w, x1, y1, x2, y2))[0] === 1){
matchLocations.push([x1, y1]);
}
}
}
@robertleeplummerjr

Copy link
Copy Markdown

Move return subKernelThatRepresentsNetwork(imageTexture, x1, y1, x2, y2); //outputs 0 or 1 to outside of this function, and then simply do subKernelThatRepresentsNetwork(myFunc(imageTexture, x1, y1, x2, y2));

@robertleeplummerjr

Copy link
Copy Markdown

Don't forget to use (renamed from outputToTexture in v2 of GPU.js) pipeline: true, in the options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment