Skip to content

Instantly share code, notes, and snippets.

@luruke
Last active October 25, 2019 08:57
Show Gist options
  • Save luruke/8506d471b4f7e5042c791008aa0bebff to your computer and use it in GitHub Desktop.
Save luruke/8506d471b4f7e5042c791008aa0bebff to your computer and use it in GitHub Desktop.
const POINTS = 256;
const vertices = new Float32Array(POINTS * 4);
const ids = new Float32Array(POINTS);
for (let i = 0; i < POINTS * 4; i += 4) {
vertices[i + 0] = randomFloat(-5, 5);
vertices[i + 1] = randomFloat(-5, 5);
vertices[i + 2] = randomFloat(-5, 5);
vertices[i + 3] = randomFloat(0, 4); // random ID, for different sizes
}
for (let i = 0; i < POINTS; i++) {
ids[i] = i / POINTS;
}
this.fbo = new FBO({
data: vertices,
width: POINTS,
height: 1,
name: 'particles fbo',
shader: `
precision highp float;
uniform float uTime;
uniform float uSpeed;
uniform sampler2D texture;
uniform vec2 uPointer;
void main() {
vec2 uv = gl_FragCoord.xy / RESOLUTION.xy;
vec4 current = texture2D(texture, uv);
float speed = max(-.004, -uSpeed * 0.05);
current.y += .01 + speed;
if (current.y > 5.0) {
current.y = -5.0;
}
gl_FragColor = current;
}
`,
uniforms: {
uTime: { value: 0.0 },
uPointer: { value: pointer.normalized },
uSpeed: { value: scroll.speed },
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment