Last active
August 29, 2015 14:02
-
-
Save henkboom/7212b480d344f34dd3e6 to your computer and use it in GitHub Desktop.
two squares in a circle
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
// uses love2d 'effect' entry point | |
uniform float time = 0.0f; | |
float pi = 3.14159; | |
float intersect(float value1, float value2) | |
{ | |
return value1 * value2; | |
} | |
float merge(float value1, float value2) | |
{ | |
return 1-((1-value1) * (1-value2)); | |
} | |
float halfspace(vec2 origin, vec2 direction, float feather, vec2 point) | |
{ | |
return smoothstep( | |
feather/2, | |
-feather/2, | |
dot(point - origin, direction)); | |
} | |
vec2 rotate(vec2 v, float a) | |
{ | |
float cos_a = cos(a); | |
float sin_a = sin(a); | |
return vec2( | |
cos_a * v.x - sin_a * v.y, | |
cos_a * v.y + sin_a * v.x); | |
} | |
float square(vec2 point, float size, float feather) | |
{ | |
return | |
halfspace(vec2(size/2, 0), vec2(1, 0), feather, point) * | |
halfspace(vec2(0, size/2), vec2(0, 1), feather, point) * | |
halfspace(vec2(-size/2, 0), vec2(-1, 0), feather, point) * | |
halfspace(vec2(0, -size/2), vec2(0, -1), feather, point); | |
} | |
float circle(vec2 point, float feather) | |
{ | |
return smoothstep(-feather/2, feather/2, 0.8 - length(point)); | |
} | |
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) | |
{ | |
vec2 point = texture_coords.xy * 2 - vec2(1, 1); | |
vec2 axle = vec2(cos(-time*2*pi/6), sin(-time*2*pi/6)); | |
float value = merge( | |
square(rotate(point - 0.2*axle, -time*2*pi/4 / 3), 0.7, 0.2), | |
square(rotate(point + 0.3*axle, time*2*pi/4 / 1.5), 0.5, 0.2)); | |
value = merge(value, circle(point, 0.2)/2); | |
return vec4(color.xyz, | |
smoothstep(0.15, 0.25, value) * | |
smoothstep(0.85, 0.75, value)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment