-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshaping.glsl
More file actions
134 lines (99 loc) · 2.81 KB
/
Copy pathshaping.glsl
File metadata and controls
134 lines (99 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Implemented and/or adapted from:
// Polynomial Shaping Functions: www.flong.com/archive/texts/code/shapers_poly
// Exponential Shaping Functions: www.flong.com/archive/texts/code/shapers_exp
// Circular & Elliptical Shaping Functions: www.flong.com/archive/texts/code/shapers_circ
// Bezier and Other Parametric Shaping Functions: www.flong.com/archive/texts/code/shapers_bez
// via Book of Shaders (unless otherwise noted).
//=============================================================================================
#define PI 3.14159265358
float edgeBuild(vec2 st, float y, float d){
// From Book of Shaders
return smoothstep(y-d, y, st.t)-smoothstep(y, y+d, vUV.t);
}
float doubleCuebicSeat(float x, float a, float b){
if (x<=a) {
return b - b*pow((1-x/a), 2*n+1);
} else {
return b + (1-b)*pow((x-a)/(1-a),2*n+1);
}
}
float quadraticThroughPoint(float x, float a, float b){
float term1 = ((1-b)/(1-a) - b/a);
float term2 = (((1-b)/(1-a) - b/a) - b)/a;
return term1*pow(x,2) - term2*x;
}
float safePow(float a, float b){
// From tim.yfx in Touchdesigner's Discord (all errors mine).
return (a<0.0 && fract(b)==0) ? sign(a) * pow(abs(a),b) : pow(a,b);
}
float doublePolynomialSigmoid(float x, int n){
if (mod(n, 2) == 0) {
// even exponent
if (x<=0.5) {
return pow(2.0*x, 2*n)/2.0;
} else {
return 1.0 - safePow(2.0*(x-1.0), 2.0*n)/2.0;
}
} else {
// odd exponent
if (x<=0.5) {
return pow(2.0*x, 2*n+1)/2.0;
} else {
return 1.0 + safePow(2.0*(x-1.0), 2.0*n+1)/2.0;
}
}
}
float exponentialEaseIn(float x, float a){
return pow(x, 1.0/a);
}
float doubleExponentialSigmoid(float x, float a){
if(x<=0.5){
return pow(2.0*x, 1.0/a)/2.0;
} else {
return 1 - pow(2.0*(1.0-x), 1.0/a)/2.0;
}
}
float logisticSigmoid(float x, float a){
float A = 1/(1+exp(-2.0*a*(x-0.5)));
float B = 1/(1+exp(a));
float C = 1/(1+exp(-a));
return (A-B)/(C-B);
}
float circularEaseOut(float x){
return sqrt(1-pow(1-x, 2));
}
float doubleCircleSeat(float x, float a){
if(x<=a){
return sqrt(a*a - pow(x-a, 2));
} else {
return 1 - sqrt(pow(1-a, 2) - pow(x-a, 2));
}
}
float doubleCircleSigmoid(float x, float a){
if(x<=a){
return a - sqrt(a*a - x*x);
} else {
return a + sqrt(pow(1-a, 2) - pow(x-1, 2));
}
}
float doubleEllipticSeat(float x, float a, float b){
if(x<=a){
return b/a * sqrt(a*a - pow(x-a, 2));
} else {
return 1 - (1-b)/(1-a) * sqrt(pow(1-a, 2) - pow(x-a, 2));
}
}
float quadraticBezier(float x, float a, float b){
float t = (sqrt(a*a + (1-2.0*a)*x) - a)/(1 - 2.0*a);
return (1-2.0*b)*t*t + 2.0*b*t;
}
float normalizeRange(float x){
// Remap -1-1 to 0-1, use with shape{1,2} below.
return (x*2.0)-1;
}
float tDistShape(float x){
return 1 - pow(abs(sin(PI*x/2.0)),2);
}
float tDistShapeTrunc(float x){
return 1 - pow(max(0.0, 2.0*abs(x)-1.0),1.5);
}