-
Notifications
You must be signed in to change notification settings - Fork 1
/
Functions_&_Curves_I.frag
63 lines (48 loc) · 1.68 KB
/
Functions_&_Curves_I.frag
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
// Author: Jeremy Rotsztain
// Workshop: Generating Images with Shaders @ InterAccess, 2020
// Title: Functions & Curves
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
#define PI 3.1415926535
#define TWO_PI 6.283185307
float plot( vec2 xy, float amt){
if( amt > xy.y - 0.006 && amt < xy.y + 0.006) return 1.0;
return 0.;
}
void main() {
// get the xy coordinate & normalize to [0, 1] range
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
// linear curve
// increases at a constant rate
float amt = st.x;
// pow (exponential curve)
// multiplies value by itself n times
//amt = pow( st.x, 2.); // same as color.r = st.x * st.x
// fract
// computes fractional value (i.e. 2.137 => 0.137 )
//amt = fract(st.x*2.);
// step
// threshold ... pixels greater than value
//amt = step( 0.5, st.x);
// smoothstep
// smooth threshold ... interpolate between [0, 1] while in range of val 1 and 2
// if less, 0. if greater 1.
// uses cubic interpolation
//amt = smoothstep(0.15, 0.85, st.x);
// sin
// repeating sinusodal curve
// note: values range [-1, 1]
//amt = sin( st.x * TWO_PI);
//amt = sin( st.x * TWO_PI ) * 0.5 + 0.5; // scale into [0, 1] range
//amt = sin( u_time + st.x * TWO_PI ) * 0.5 + 0.5; // animate with time as phase
// visualize 'amt' as red value
vec3 color = vec3( amt, 0.2, 0.4);
// graph the value using plot
color.rgb = mix( color.rgb, vec3(0.0, 1.0, 0.0), plot( st, color.r));
gl_FragColor = vec4(color, 1.0);
}