Last active
April 16, 2023 13:09
-
-
Save arvidsson/279ca9c4b2fde5b0bccae2753483083f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define PI 3.14159265359 | |
#define TWOPI 6.28318530718 | |
#define HALF_PI 1.57079632679 | |
float lerp(float a, float b, float t) | |
{ | |
return (a * (1.0 - t)) + (b * t); | |
} | |
// step functions | |
float invstep(float edge, float value) | |
{ | |
return 1.0 - step(edge, value); | |
} | |
float linearstep(float edge0, float edge1, float x) | |
{ | |
return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0); | |
} | |
float smootherstep(float edge0, float edge1, float x) | |
{ | |
x = clamp((x - edge0)/(edge1 - edge0), 0.0, 1.0); | |
return x * x * x * (x * (x * 6.0 - 15.0) + 10.0); | |
} | |
float bumpstep(float edge0, float edge1, float x) | |
{ | |
return 1.0 - abs(clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0) - 0.5) * 2.0; | |
} | |
float smoothbumpstep(float edge0, float edge1, float x) | |
{ | |
x = 1.0 - abs(clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0) - 0.5) * 2.0; | |
return x * x * (3.0 - x - x); | |
} | |
// draw functions | |
float plot(vec2 r, float pct, float width) | |
{ | |
return smoothstep(pct - width, pct, r.y) - smoothstep(pct, pct + width, r.y); | |
} | |
void disk(vec2 r, vec2 center, float radius, vec3 color, inout vec3 pixel) | |
{ | |
if (length(r - center) < radius) { | |
pixel = color; | |
} | |
} | |
// ease functions | |
float linear(float t) { | |
return t; | |
} | |
float ease_in_sine(float t) | |
{ | |
return 1.0 - cos((t * PI) / 2.0); | |
} | |
float ease_out_sine(float t) | |
{ | |
return sin((t * PI) / 2.0); | |
} | |
float ease_inout_sine(float t) | |
{ | |
return -(cos(PI * t) - 1.0) / 2.0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment