I'm trying to make a ui button shader by overlaping a rounded rectangle on another rounded rectangle but with different size and gradient color. This way I'll have a small outline of a color (e.g. grey) and the body with a grey-ish gradient.
This is how my fragment code looks so far:
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
const float PI = 3.14159265;
// from http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
float rect( vec2 p, vec2 size, float r ) {
return length(max(abs(p)-size+r,0.0))-r;
}
void main() {
vec2 halfRes = 0.5 * u_resolution.xy;
float aspect = u_resolution.y/u_resolution.x;
// compute box
float b = rect(gl_FragCoord.xy - halfRes, halfRes, 30.0);
b *= rect(gl_FragCoord.xy - halfRes, halfRes * vec2(0.99, 0.96), 30.0);
// colorize (red / black )
vec4 c = mix( vec4(0.326,0.603,1.000,1.000), vec4(0.0), smoothstep(0.0, 13.264,b) );
gl_FragColor = c;
}
You can modify it directly here by cp http://editor.thebookofshaders.com/
EDIT: I've managed to get the border, now I'll only need to fill the hollow..
