Skip to content

Instantly share code, notes, and snippets.

@vorg
Created July 27, 2022 08:03
Show Gist options
  • Save vorg/1bb063d11cd13a19d419bbb461c2c78e to your computer and use it in GitHub Desktop.
Save vorg/1bb063d11cd13a19d419bbb461c2c78e to your computer and use it in GitHub Desktop.
module.exports = (node, graph) => {
const triggerIn = node.triggerIn("in");
const triggerOut = node.triggerOut("out");
const timeIn = node.in("time", 0);
const textureIn = node.in("texture", null);
const rotationIn = node.in("rotation", 0)
const ctx = graph.ctx;
const drawCmd = {
pipeline: ctx.pipeline({
vert: /*glsl*/`
attribute vec2 aPosition;
attribute vec2 aTexCoord;
varying vec2 vTexCoord;
void main () {
vTexCoord = aTexCoord;
gl_Position = vec4(aPosition, 0.0, 1.0);
}
`,
frag: /*glsl*/`
precision highp float;
varying vec2 vTexCoord;
uniform float uTime;
uniform sampler2D uTexture;
uniform float uAspect;
uniform float uRotation;
void main () {
float x = vTexCoord.x * 2.0 - 1.0;
float y = vTexCoord.y * 2.0 - 1.0;
x *= uAspect;
float a = atan( y, x );
a += uRotation;
float r = 1.0;
float u = x * cos(2.0 * r) - y;
u += 0.5 * a / 3.14;
gl_FragColor = texture2D(uTexture, vec2(fract(u + uTime / 5.0), 0.5));
}
`,
}),
attributes: {
aPosition: ctx.vertexBuffer([
[-1, -1],
[1, -1],
[1, 1],
[-1, 1],
]),
aTexCoord: ctx.vertexBuffer([
[0, 0],
[1, 0],
[1, 1],
[0, 1],
]),
},
indices: ctx.indexBuffer([
[0, 1, 2],
[0, 2, 3],
]),
};
triggerIn.onTrigger = (props) => {
const aspect = ctx.gl.drawingBufferWidth / ctx.gl.drawingBufferHeight;
if (!textureIn.value) return;
ctx.submit(drawCmd, {
uniforms: {
uTime: timeIn.value,
uTexture: textureIn.value,
uAspect: aspect,
uRotation: rotationIn.value
},
});
triggerOut.trigger(props);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment