diff options
Diffstat (limited to 'shaders')
-rw-r--r-- | shaders/circle_mask.glsl | 20 | ||||
-rw-r--r-- | shaders/rounded_rectangle.glsl | 15 |
2 files changed, 30 insertions, 5 deletions
diff --git a/shaders/circle_mask.glsl b/shaders/circle_mask.glsl index 9f82591..0266d2c 100644 --- a/shaders/circle_mask.glsl +++ b/shaders/circle_mask.glsl @@ -1,9 +1,19 @@ uniform sampler2D texture; +uniform vec2 resolution; + +vec4 circle(vec2 uv, vec2 pos, float rad, vec4 color) { + float d = length(pos - uv) - rad; + float t = clamp(d, 0.0, 1.0); + return vec4(color.rgb, color.a * (1.0 - t)); +} void main() { - vec4 pixel = texture2D(texture, gl_TexCoord[0].xy); - vec2 pixelOffset = gl_TexCoord[0].xy - vec2(0.5, 0.5); - float dist = sqrt(dot(pixelOffset, pixelOffset)); - dist = smoothstep(0.47, 0.5, dist); - gl_FragColor = gl_Color * pixel * vec4(1.0, 1.0, 1.0, 1.0 - dist); + vec2 uv = gl_TexCoord[0].xy * resolution; + vec2 center = resolution * 0.5; + float radius = 0.49 * resolution.y; + + vec4 texture_color = texture2D(texture, gl_TexCoord[0].xy); + vec4 layer1 = vec4(0.0, 0.0, 0.0, 0.0); + vec4 layer2 = circle(uv, center, radius, texture_color); + gl_FragColor = mix(layer1, layer2, layer2.a); } diff --git a/shaders/rounded_rectangle.glsl b/shaders/rounded_rectangle.glsl new file mode 100644 index 0000000..7da0826 --- /dev/null +++ b/shaders/rounded_rectangle.glsl @@ -0,0 +1,15 @@ +uniform float radius; +uniform vec2 resolution; + +float rounded_rect(vec2 coord, vec2 size, float r) { + return length(max(abs(coord) - size, 0.0)) - r; +} + +void main() { + vec2 uv = gl_TexCoord[0].xy * resolution; + vec2 center = resolution * 0.5; + vec2 size = resolution * 0.5; + vec4 background_color = vec4(0.0, 0.0, 0.0, 0.0); + float a = clamp(rounded_rect(uv - center, size - radius, radius), 0.0, 1.0); + gl_FragColor = mix(gl_Color, background_color, a); +}
\ No newline at end of file |