Skip to content

Instantly share code, notes, and snippets.

@jt0dd
Created September 2, 2018 19:20
Show Gist options
  • Save jt0dd/d0407280d073a831a50cca2f25328f5c to your computer and use it in GitHub Desktop.
Save jt0dd/d0407280d073a831a50cca2f25328f5c to your computer and use it in GitHub Desktop.
const gpuTexturize = graphics.gpu
.createKernel(function(buffer, width) {
var channel = buffer[((this.thread.y * width * 4) // calculate the index on the flat array buffer for the y index
+ this.thread.x * 4) // add the x which is the current row
+ this.thread.z] // add z which is the current channel
return channel;
})
.setOutput([image.width, image.height, 4]);
// would expect this to output [[[255, 255, 255, 255], [255, 255, 255, 255], [255, 255, 255, 255], [255, 255, 255, 255], ... and so on for each width pixel ... ], [...], [...], [...], [...], [...], [...] ... and so on for each height pixel ... ]
// (it doesnt work this way, the output here would actually be [[], [], [], []] structured by the z axis which is the color channel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment