Skip to content

Instantly share code, notes, and snippets.

const gpu1 = new GPU();
const createTexture = gpu1.createKernel(function() {
return 55;
}).setOutput([4, 100, 100]).setOutputToTexture(true);
console.time('texture');
const texture1 = createTexture();
const texture2 = createTexture();
const texture3 = createTexture();
const useTexture = gpu1.createKernel(function() {
var index = 0;
#version 300 es
precision highp float;
precision highp int;
precision highp sampler2D;
const float LOOP_MAX = 1000.0;
uniform ivec3 uOutputDim;
uniform ivec2 uTexSize;
static flatten2dArrayTo(array, target) {
let offset = 0;
for (let y = 0; y < array.length; y++) {
target.set(array[y], offset);
offset += array[y].length;
}
}
this.gpuDraw = this.gpu
.createKernel(function(buffer, sprite, x, y, w, h, bufferWidth) {
var subBufferWidth = w * 4;
var cy = Math.floor(this.thread.x / bufferWidth);
var cx = this.thread.x % bufferWidth;
var dx = x - cx;
var dy = y - cy;
var dz = this.thread.x % 4;
if (dx > 0 && dx < w && dy > 0 && dy < h) {
return sprite[dx][dy][dz]; // even using [0][0][0] throws an error
this.gpuDraw = this.gpu
.createKernel(function(buffer, sprite, x, y, w, h, bufferWidth) {
var subBufferWidth = w * 4;
var cy = Math.floor(this.thread.x / bufferWidth);
var cx = this.thread.x % bufferWidth;
var dx = x - cx;
var dy = y - cy;
var dz = this.thread.x % 4;
if (dx > 0 && dx < w && dy > 0 && dy < h) {
//console.log(dx, dy, dz); //these are logging fine btw
@jt0dd
jt0dd / kernel
Created September 9, 2018 19:12
uniform highp sampler2D user_buffer;
uniform highp ivec2 user_bufferSize;
uniform highp ivec3 user_bufferDim;
uniform highp int user_bufferBitRatio;
uniform highp sampler2D user_sprite;
uniform highp ivec2 user_spriteSize;
uniform highp ivec3 user_spriteDim;
uniform highp int user_spriteBitRatio;
uniform float user_x;
uniform float user_y;
uniform highp sampler2D user_inputBuffer;
uniform highp ivec2 user_inputBufferSize;
uniform highp ivec3 user_inputBufferDim;
uniform highp int user_inputBufferBitRatio;
out vec4 data0;
float kernelResult = 0.0;
void kernel() {
float user_pixel=get(user_inputBuffer, ivec2(user_inputBufferSize[0],user_inputBufferSize[1]), ivec3(user_inputBufferDim[0],user_inputBufferDim[1],user_inputBufferDim[2]), user_inputBufferBitRatio, threadId.x,threadId.y);
color(get(user_pixel, ivec2(user_pixelSize[0],user_pixelSize[1]), ivec3(user_pixelDim[0],user_pixelDim[1],user_pixelDim[2]), user_pixelBitRatio, 0), get(user_pixel, ivec2(user_pixelSize[0],user_pixelSize[1]), ivec3(user_pixelDim[0],user_pixelDim[1],user_pixelDim[2]), user_pixelBitRatio, 1), get(user_pixel, ivec2(user_pixelSize[0],user_pixelSize[1]), ivec3(user_pixelDim[0],user_pixelDim[1],user_pixelDim[2]), user_pixelBitRatio, 2));
(function() {
function constrainTest(mode) {
var gpu = new GPU({ mode: mode });
var f = gpu.createKernel(function() {
return 255;
}, {
output : [4, 4, 3]
});
let x = 2;
let y = 2;
// the way I see this done in one example is like:
vbuffer = _gl.createBuffer();
_gl.bindBuffer(ARRAY_BUFFER, vbuffer);
_gl.bufferData(ARRAY_BUFFER, vertices, STATIC_DRAW);
numItems = vertices.length ~/ 2;
tbuffer = _gl.createBuffer();
_gl.bindBuffer(ARRAY_BUFFER, tbuffer);
_gl.bufferData(ARRAY_BUFFER, textureCoords, STATIC_DRAW);
@jt0dd
jt0dd / notes.js
Last active March 26, 2019 16:25
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;