Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 437623c

Browse files
authored
Don't duplicate SkSL builtin function 'saturate' (#108946)
1 parent f5cecd0 commit 437623c

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

packages/flutter/lib/src/material/shaders/ink_sparkle.frag

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ const float PI_ROTATE_LEFT = PI * -0.0078125;
3434
const float ONE_THIRD = 1./3.;
3535
const vec2 TURBULENCE_SCALE = vec2(0.8);
3636

37-
float saturate(float x) {
38-
return clamp(x, 0.0, 1.0);
39-
}
40-
4137
float triangle_noise(highp vec2 n) {
4238
n = fract(n * vec2(5.3987, 5.4421));
4339
n += dot(n.yx, n.xy + vec2(21.5351, 14.3137));
@@ -62,7 +58,7 @@ float soft_circle(vec2 uv, vec2 xy, float radius, float blur) {
6258
float soft_ring(vec2 uv, vec2 xy, float radius, float thickness, float blur) {
6359
float circle_outer = soft_circle(uv, xy, radius + thickness, blur);
6460
float circle_inner = soft_circle(uv, xy, max(radius - thickness, 0.0), blur);
65-
return saturate(circle_outer - circle_inner);
61+
return clamp(circle_outer - circle_inner, 0.0, 1.0);
6662
}
6763

6864
float circle_grid(vec2 resolution, vec2 p, vec2 xy, vec2 rotation, float cell_diameter) {
@@ -79,7 +75,7 @@ float sparkle(vec2 uv, float t) {
7975
s += threshold(n + sin(PI * (t + 0.35)), 0.1, 0.15);
8076
s += threshold(n + sin(PI * (t + 0.7)), 0.2, 0.25);
8177
s += threshold(n + sin(PI * (t + 1.05)), 0.3, 0.35);
82-
return saturate(s) * 0.55;
78+
return clamp(s, 0.0, 1.0) * 0.55;
8379
}
8480

8581
float turbulence(vec2 uv) {
@@ -88,7 +84,7 @@ float turbulence(vec2 uv) {
8884
float g2 = circle_grid(TURBULENCE_SCALE, uv_scale, u_circle2, u_rotation2, 0.2);
8985
float g3 = circle_grid(TURBULENCE_SCALE, uv_scale, u_circle3, u_rotation3, 0.275);
9086
float v = (g1 * g1 + g2 - g3) * 0.5;
91-
return saturate(0.45 + 0.8 * v);
87+
return clamp(0.45 + 0.8 * v, 0.0, 1.0);
9288
}
9389

9490
void main() {

0 commit comments

Comments
 (0)