7DRL2015/data/shaders/ui_fs.glsl

36 lines
1.3 KiB
GLSL

#version 150
// uniforms
uniform sampler2D texture_sampler;
uniform float transparency;
uniform float vertical_fade;
// input
varying vec2 frag_uv;
void main() {
gl_FragColor = texture2D(texture_sampler, frag_uv);
// grossly outline the UI element
if (gl_FragColor.a < 0.1 && frag_uv.x >= 0.001 && frag_uv.x <= 0.999 && frag_uv.y >= 0.001 && frag_uv.y <= 0.999) {
vec4 t = texture2D(texture_sampler, frag_uv + vec2( 0.0f, -0.0025f ));
vec4 b = texture2D(texture_sampler, frag_uv + vec2( 0.0f, 0.0025f ));
vec4 l = texture2D(texture_sampler, frag_uv + vec2( -0.0025f, 0.0f ));
float c = 0.0f;
if (t.a > 0.75) {
gl_FragColor = vec4(0.5 - t.r, 0.5 - t.g, 0.5 - t.b, 1.0 - transparency);
} else if (b.a > 0.75) {
gl_FragColor = vec4(0.5 - b.r, 0.5 - b.g, 0.5 - b.b, 1.0 - transparency);
} else if (l.a > 0.75) {
gl_FragColor = vec4(0.5 - l.r, 0.5 - l.g, 0.5 - l.b, 1.0 - transparency);
}
} else {
gl_FragColor.a -= transparency;
gl_FragColor.a -= 0.10;
}
// modify alpha/color based on UV offsets.
if (vertical_fade > 0) {
//gl_FragColor.a -= 0.35 - frag_uv.y; // this increases alpha towards top
gl_FragColor.rgb -= (0.35 - frag_uv.y/2); // this darkens rgb towards top
}
if (gl_FragColor.a == 0.0) discard;
//gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}