This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #version 300 es | |
| precision highp float; | |
| precision highp int; | |
| precision highp sampler2D; | |
| const float LOOP_MAX = 1000.0; | |
| uniform ivec3 uOutputDim; | |
| uniform ivec2 uTexSize; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |