Created
June 13, 2023 14:19
-
-
Save phxtho/91a225b94ecfebe095ce9dae51389641 to your computer and use it in GitHub Desktop.
Fragment shader recreating lászló moholy-nagy's am 7 (26)
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
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
#define PI 3.14159265359 | |
#define TWO_PI 6.28318530718 | |
uniform vec2 u_resolution; | |
uniform vec2 u_mouse; | |
uniform float u_time; | |
float circle(vec2 st, vec2 center, float radius) { | |
vec2 dist = st - center; | |
return 1.0 - smoothstep(radius, radius + 0.002, length(dist)); | |
} | |
mat2 rotate2d(float _deg) { | |
float _angle = radians(_deg); | |
return mat2(cos(_angle), -sin(_angle), sin(_angle), cos(_angle)); | |
} | |
float square(in vec2 st, vec2 center, float radius, float rotation) { | |
// Rotate space | |
st -= vec2(0.5); | |
st = rotate2d(rotation) * st; | |
st += vec2(0.5); | |
vec2 dist = st - center; | |
return 1.0 - smoothstep(radius, radius + 0.002, max(abs(dist.x), abs(dist.y))); | |
} | |
void main() { | |
vec2 st = gl_FragCoord.xy / u_resolution.xy; | |
st.x *= u_resolution.x / u_resolution.y; | |
vec3 color = vec3(0.0); | |
// normalise mouse position | |
vec2 mouse_pos = u_mouse / u_resolution; | |
// Draw circle | |
float circle1 = circle(st, vec2(0.4, 0.45) - mouse_pos * 0.04, 0.35); | |
vec3 light_blue = vec3(168., 179., 195.) / 255.0; | |
color += vec3(circle1) * light_blue; | |
float circle2 = circle(st, vec2(0.3, 0.28) + mouse_pos * 0.08, 0.1); | |
vec3 white = vec3(1., 1., 1.); | |
color -= vec3(circle2) * white; | |
float circle3 = circle(st, vec2(0.9, 0.7) - vec2(0.5, 0.05) * mouse_pos, 0.08); | |
color += vec3(circle3) * light_blue; | |
// Draw squares | |
float square0 = square(st, vec2(1, 1), 0.45, sin(u_time * 0.5) * 10.); | |
vec3 orange = vec3(242., 71., 22.) / 255.0; | |
color += vec3(square0) * orange; | |
float square1 = square(st, vec2(0.15, 0.), .3, -5.); | |
vec3 light_gray = vec3(211., 211., 207.) / 255.0; | |
color += vec3(square1) * light_gray; | |
float square2 = square(st, vec2(sin(u_time * 0.5) * 0.1 + 0.9, 0.), .3, -5.); | |
vec3 dark_gray = vec3(62., 60., 74.) / 255.0; | |
color += vec3(square2) * dark_gray; | |
gl_FragColor = vec4(color, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment