Skip to content

Commit 23f2a9f

Browse files
committed
Add extra random number
1 parent 0e60138 commit 23f2a9f

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

lib/src/shaders/update-vert.glsl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#version 300 es
22

33
uniform float dt;/** time delta */
4+
uniform float e; /** Extra random number to increase entropy */
45
uniform sampler2D rg; /** random rg */
56
uniform vec2 g; /** gravity - forceField */
67
uniform vec2 o; /** origin*/
@@ -18,15 +19,12 @@ out vec2 oV;
1819

1920
void main() {
2021
if(l <= 0.f) {
21-
int i = gl_VertexID + 1000 * int(dt);
22-
vec2 q = texelFetch(rg, ivec2((i + 2) % 200, 0), 0).rg;
22+
int i = gl_VertexID + int(200.f * e);
2323
vec2 r = texelFetch(rg, ivec2(i % 200, i / 200), 0).rg;
24-
float th = aR.x + r.r * (aR.y - aR.x);
25-
float x = cos(th);
26-
float y = sin(th);
24+
float a = aR.x + r.r * (aR.y - aR.x);
2725
oP = o;
28-
oL = lR.x + q.r * (lR.y - lR.x);
29-
oV = vec2(x, y) * (sR.x + r.g * (sR.y - sR.x));
26+
oL = lR.x + e * r.r * (lR.y - lR.x);
27+
oV = vec2(cos(a), sin(a)) * (sR.x + r.g * (sR.y - sR.x));
3028
} else {
3129
oP = p + v * dt;
3230
oL = l - dt;

lib/src/simulator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const random = Math.random;
99
/** shader names */
1010
// Uniforms
1111
const U_DT = "dt";
12-
const U_RANDOM_RG = "rg";
12+
const U_EXTRA_RANDOM = "e";
1313
const U_FORCE_FIELD = "g"; /** gravity */
1414
const U_ORIGIN = "o";
1515
const U_ANGLE_RANGE = "aR";
@@ -255,6 +255,7 @@ const simulate = (
255255
gl.useProgram(updateProgram);
256256

257257
setUpdateUniform(U_DT, dt / 1000);
258+
setUpdateUniform(U_EXTRA_RANDOM, random());
258259
// skipcq: JS-0339 -- forcefield is always set by the default options
259260
setUpdateUniform(U_FORCE_FIELD, ...options.forceField!);
260261
setUpdateUniform(U_ORIGIN, mouseX, mouseY);

0 commit comments

Comments
 (0)