Skip to content

Commit f68fada

Browse files
committed
parametrize some particle constants
1 parent 9c05017 commit f68fada

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

demo/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ getJSON('https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_110m_coastl
2424
canvas.height = canvas.clientHeight;
2525

2626
var ctx = canvas.getContext('2d');
27-
ctx.lineWidth = 3;
27+
ctx.lineWidth = 2;
2828
ctx.lineJoin = ctx.lineCap = 'round';
2929
ctx.strokeStyle = 'white';
3030
ctx.beginPath();

src/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export class WindGL {
2424
constructor(gl) {
2525
this.gl = gl;
2626

27+
this.fadeOpacity = 0.999;
28+
this.speedFactor = 0.2;
29+
this.dropRate = 0.003;
30+
this.dropRateBump = 0.01;
31+
2732
this.drawProgram = util.createProgram(gl, drawVert, drawFrag);
2833
this.screenProgram = util.createProgram(gl, quadVert, screenFrag);
2934
this.updateProgram = util.createProgram(gl, quadVert, updateFrag);
@@ -86,7 +91,7 @@ export class WindGL {
8691
util.bindFramebuffer(gl, this.framebuffer, this.screenTexture);
8792
gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
8893

89-
this.drawTexture(this.backgroundTexture, 0.999);
94+
this.drawTexture(this.backgroundTexture, this.fadeOpacity);
9095
this.drawParticles();
9196

9297
util.bindFramebuffer(gl, null);
@@ -149,6 +154,9 @@ export class WindGL {
149154
gl.uniform2f(program.u_wind_res, this.windData.width, this.windData.height);
150155
gl.uniform2f(program.u_wind_min, this.windData.uMin, this.windData.vMin);
151156
gl.uniform2f(program.u_wind_max, this.windData.uMax, this.windData.vMax);
157+
gl.uniform1f(program.u_speed_factor, this.speedFactor);
158+
gl.uniform1f(program.u_drop_rate, this.dropRate);
159+
gl.uniform1f(program.u_drop_rate_bump, this.dropRateBump);
152160

153161
gl.drawArrays(gl.TRIANGLES, 0, 6);
154162

src/shaders/update.frag.glsl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ uniform vec2 u_wind_res;
66
uniform vec2 u_wind_min;
77
uniform vec2 u_wind_max;
88
uniform float u_rand_seed;
9+
uniform float u_speed_factor;
10+
uniform float u_drop_rate;
11+
uniform float u_drop_rate_bump;
912

1013
varying vec2 v_tex_pos;
1114

@@ -36,11 +39,12 @@ void main() {
3639
float speed_t = length(velocity) / length(u_wind_max);
3740

3841
float distortion = max(0.1, cos(radians(pos.y * 180.0 - 90.0)));
39-
vec2 offset = vec2(velocity.x / distortion, -velocity.y) * 0.00002;
42+
vec2 offset = vec2(velocity.x / distortion, -velocity.y) * 0.0001 * u_speed_factor;
4043

4144
vec2 seed = (pos + v_tex_pos) * u_rand_seed;
4245

43-
float drop = step(0.997 - speed_t * 0.01, rand(seed));
46+
float dropRate = u_drop_rate + speed_t * u_drop_rate_bump;
47+
float drop = step(1.0 - dropRate, rand(seed));
4448
pos = mix(fract(1.0 + pos + offset), vec2(rand(seed + 1.3), rand(seed + 2.1)), drop);
4549

4650
gl_FragColor = vec4(

0 commit comments

Comments
 (0)