Skip to content

Instantly share code, notes, and snippets.

_getMainConstantsString() {
const result = [];
if (this.constants) {
for (let name in this.constants) {
if (!this.constants.hasOwnProperty(name)) continue;
let value = this.constants[name];
let type = utils.getArgumentType(value);
console.log("Constant detected of type:", type);
switch (type) {
case 'Integer':
// fragment shaders don't have a default precision so we need
// to pick one. mediump is a good default. It means "medium precision"
precision mediump float;
void main() {
// gl_FragColor is a special variable a fragment shader
// is responsible for setting
gl_FragColor = vec4(1, 0, 0.5, 1); // return redish-purple
}
astMemberExpression(mNode, retArr) {
debugLog("[in] astMemberExpression " + mNode.object.type);
if (mNode.computed) {
if (mNode.object.type === 'Identifier' ||
(
mNode.object.type === 'MemberExpression' &&
mNode.object.object.object &&
mNode.object.object.object.type === 'ThisExpression' &&
mNode.object.object.property.name === 'constants'
)
_getMainConstantsString() {
const result = [];
if (this.constants) {
for (let name in this.constants) {
if (!this.constants.hasOwnProperty(name)) continue;
let value = this.constants[name];
let type = utils.getArgumentType(value);
console.log("Constant detected of type:", type);
switch (type) {
case 'Integer':
key: 'build',
value: function build() {
this.validateOptions();
this.setupParams(arguments);
this.updateMaxTexSize();
var texSize = this.texSize;
var gl = this._webGl;
var canvas = this._canvas;
gl.enable(gl.SCISSOR_TEST); // gl undefined
var tryConst = gpu.createKernel(
function() {
var pixel = this.constants.image[this.thread.x][this.thread.y];
this.color(pixel.r, pixel.g, pixel.b, pixel.a);
},
{
constants: { image }
}
).setOutput([width, height]);
const gpu = new GPU();
const createTexture = gpu.createKernel(function() {
this.color(55, 55, 55, 255);
}).setOutput([1920,1080]).setOutputToTexture(true);
var texture1 = createTexture();
const kernel = gpu.createKernel(function() {
var pixel = this.constants.texture1[this.thread.x][this.thread.y];
var color = 0;
var channel = this.thread.z;
if (channel === 0) {
const gpuTexturize = graphics.gpu
.createKernel(function(buffer, width) {
var channel = buffer[((this.thread.z * width * 4) + this.thread.y * 4) + this.thread.x]
return channel;
})
.setOutput([4, image.width, image.height]);
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 ... ]
@jt0dd
jt0dd / kernel.js
Last active September 3, 2018 02:06
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;