Skip to content

Instantly share code, notes, and snippets.

@jt0dd
Last active September 3, 2018 02:06
Show Gist options
  • Save jt0dd/7b2efb3f2e64f2d60d15acd4240b374f to your computer and use it in GitHub Desktop.
Save jt0dd/7b2efb3f2e64f2d60d15acd4240b374f to your computer and use it in GitHub Desktop.
this.gpuRender = this.gpu
.createKernel(
function(scene, sceneLength, bufferWidth) {
var channel = this.thread.x % 4;
if (channel === 3) {
return 255;
}
var x = this.thread.x % bufferWidth;
var y = this.thread.x / bufferWidth;
for (let i1 = 0; i1 < sceneLength; i1 += 7) {
var id1 = scene[i1 + 1];
var x1 = scene[i1 + 2];
var y1 = scene[i1 + 3];
var w1 = scene[i1 + 4];
var h1 = scene[i1 + 5];
var r1 = scene[i1 + 6];
var offsetX1 = x1 - x;
if (offsetX1 > 0 && offsetX1 < w1) {
var offsetY1 = y1 - y;
if (offsetY1 > 0 && offsetY1 < h1) {
if (
this.constants[id1][offsetX1][offsetY1][3] !== 0 &&
z1 > z
) {
return this.constants[id1][offsetX1][offsetY1][channel];
}
}
}
}
return 0;
},
{
constants: storageObj
}
)
.setOutput([this.smallWidth * this.smallHeight * 4])
.setOutputToTexture(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment