This file contains 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
_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': |
This file contains 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
// 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 | |
} |
This file contains 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
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' | |
) |
This file contains 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
_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': |
This file contains 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
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 |
This file contains 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
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]); |
This file contains 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 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) { |
This file contains 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 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]); |
This file contains 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 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 ... ] |
This file contains 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.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; |
OlderNewer