gl-transitions 1.65.0 → 1.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gl-transitions",
3
- "version": "1.65.0",
3
+ "version": "1.67.0",
4
4
  "description": "The open collection of GL Transitions",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
@@ -36,19 +36,20 @@ in vec2 texCoord;
36
36
 
37
37
  const float MIN_AMOUNT = -0.16;
38
38
  const float MAX_AMOUNT = 1.5;
39
- float amount = progress * (MAX_AMOUNT - MIN_AMOUNT) + MIN_AMOUNT;
40
39
 
41
40
  const float PI = 3.141592653589793;
42
41
 
43
42
  const float scale = 512.0;
44
43
  const float sharpness = 3.0;
45
44
 
46
- float cylinderCenter = amount;
47
- // 360 degrees * amount
48
- float cylinderAngle = 2.0 * PI * amount;
49
-
50
45
  const float cylinderRadius = 1.0 / PI / 2.0;
51
46
 
47
+ // These depend on the progress uniform and must be computed per-fragment.
48
+ // Global initializers with uniforms are invalid in GLSL ES and fail on Mesa.
49
+ float amount;
50
+ float cylinderCenter;
51
+ float cylinderAngle;
52
+
52
53
  vec3 hitPoint(float hitAngle, float yc, vec3 point, mat3 rrotation)
53
54
  {
54
55
  float hitPoint = hitAngle / (2.0 * PI);
@@ -79,7 +80,7 @@ float distanceToEdge(vec3 point)
79
80
 
80
81
  vec4 seeThrough(float yc, vec2 p, mat3 rotation, mat3 rrotation)
81
82
  {
82
- float hitAngle = PI - (acos(yc / cylinderRadius) - cylinderAngle);
83
+ float hitAngle = PI - (acos(clamp(yc / cylinderRadius, -1.0, 1.0)) - cylinderAngle);
83
84
  vec3 point = hitPoint(hitAngle, yc, rotation * vec3(p, 1.0), rrotation);
84
85
  if (yc <= 0.0 && (point.x < 0.0 || point.y < 0.0 || point.x > 1.0 || point.y > 1.0))
85
86
  {
@@ -113,25 +114,29 @@ vec4 backside(float yc, vec3 point)
113
114
  {
114
115
  vec4 color = getFromColor(point.xy);
115
116
  float gray = (color.r + color.b + color.g) / 15.0;
116
- gray += (8.0 / 10.0) * (pow(1.0 - abs(yc / cylinderRadius), 2.0 / 10.0) / 2.0 + (5.0 / 10.0));
117
+ gray += (8.0 / 10.0) * (pow(max(0.0, 1.0 - abs(yc / cylinderRadius)), 2.0 / 10.0) / 2.0 + (5.0 / 10.0));
117
118
  color.rgb = vec3(gray);
118
119
  return color;
119
120
  }
120
121
 
121
122
  vec4 behindSurface(vec2 p, float yc, vec3 point, mat3 rrotation)
122
123
  {
123
- float shado = (1.0 - ((-cylinderRadius - yc) / amount * 7.0)) / 6.0;
124
+ float safeAmount = amount >= 0.0 ? max(amount, 1e-4) : min(amount, -1e-4);
125
+ float shado = (1.0 - ((-cylinderRadius - yc) / safeAmount * 7.0)) / 6.0;
124
126
  shado *= 1.0 - abs(point.x - 0.5);
125
127
 
126
128
  yc = (-cylinderRadius - cylinderRadius - yc);
127
129
 
128
- float hitAngle = (acos(yc / cylinderRadius) + cylinderAngle) - PI;
130
+ float hitAngle = (acos(clamp(yc / cylinderRadius, -1.0, 1.0)) + cylinderAngle) - PI;
129
131
  point = hitPoint(hitAngle, yc, point, rrotation);
130
132
 
131
133
  if (yc < 0.0 && point.x >= 0.0 && point.y >= 0.0 && point.x <= 1.0 && point.y <= 1.0 && (hitAngle < PI || amount > 0.5))
132
134
  {
133
- shado = 1.0 - (sqrt(pow(point.x - 0.5, 2.0) + pow(point.y - 0.5, 2.0)) / (71.0 / 100.0));
134
- shado *= pow(-yc / cylinderRadius, 3.0);
135
+ float dx = point.x - 0.5;
136
+ float dy = point.y - 0.5;
137
+ shado = 1.0 - (sqrt(dx * dx + dy * dy) / (71.0 / 100.0));
138
+ float nyc = -yc / cylinderRadius;
139
+ shado *= nyc * nyc * nyc;
135
140
  shado *= 0.5;
136
141
  }
137
142
  else
@@ -142,6 +147,9 @@ vec4 behindSurface(vec2 p, float yc, vec3 point, mat3 rrotation)
142
147
  }
143
148
 
144
149
  vec4 transition(vec2 p) {
150
+ amount = progress * (MAX_AMOUNT - MIN_AMOUNT) + MIN_AMOUNT;
151
+ cylinderCenter = amount;
152
+ cylinderAngle = 2.0 * PI * amount;
145
153
 
146
154
  const float angle = 100.0 * PI / 180.0;
147
155
  float c = cos(-angle);
@@ -175,7 +183,7 @@ vec4 transition(vec2 p) {
175
183
  return getFromColor(p);
176
184
  }
177
185
 
178
- float hitAngle = (acos(yc / cylinderRadius) + cylinderAngle) - PI;
186
+ float hitAngle = (acos(clamp(yc / cylinderRadius, -1.0, 1.0)) + cylinderAngle) - PI;
179
187
 
180
188
  float hitAngleMod = mod(hitAngle, 2.0 * PI);
181
189
  if ((hitAngleMod > PI && amount < 0.5) || (hitAngleMod > PI/2.0 && amount < 0.0))
@@ -195,8 +203,11 @@ vec4 transition(vec2 p) {
195
203
  vec4 otherColor;
196
204
  if (yc < 0.0)
197
205
  {
198
- float shado = 1.0 - (sqrt(pow(point.x - 0.5, 2.0) + pow(point.y - 0.5, 2.0)) / 0.71);
199
- shado *= pow(-yc / cylinderRadius, 3.0);
206
+ float dx2 = point.x - 0.5;
207
+ float dy2 = point.y - 0.5;
208
+ float shado = 1.0 - (sqrt(dx2 * dx2 + dy2 * dy2) / 0.71);
209
+ float nyc2 = -yc / cylinderRadius;
210
+ shado *= nyc2 * nyc2 * nyc2;
200
211
  shado *= 0.5;
201
212
  otherColor = vec4(0.0, 0.0, 0.0, shado);
202
213
  }
@@ -13,7 +13,7 @@ vec4 transition(vec2 uv) {
13
13
  float countTiles = float(tileCount.x * tileCount.y);
14
14
 
15
15
  // Diagonal wave from bottom-left to top-right
16
- float offset = (tileNum.y + tileNum.x * float(tileCount.y)) / (sqrt(countTiles) * 2.0);
16
+ float offset = (tileNum.y + tileNum.x * float(tileCount.y)) / countTiles;
17
17
  float timeOffset = clamp((progress - offset) * countTiles, 0.0, 0.5);
18
18
  float sinTime = 1.0 - abs(cos(fract(timeOffset) * 3.1415926));
19
19
 
@@ -76,7 +76,8 @@ float KeySpline(float aX, float mX1, float mY1, float mX2, float mY2) {
76
76
 
77
77
  // norm distribution
78
78
  float normpdf(float x) {
79
- return exp(-20.*pow(x-.5,2.));
79
+ float d = x - .5;
80
+ return exp(-20.*d*d);
80
81
  }
81
82
 
82
83
  vec2 rotateUv(vec2 uv, float angle, vec2 anchor, float zDirection) {