diff options
author | David Robillard <d@drobilla.net> | 2019-12-07 15:54:01 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-12-11 22:59:50 +0100 |
commit | 13f9ef04aaf5f3583ef83bffc094758f0d640634 (patch) | |
tree | 234967ce962d3e1033634569e7a40c80c974abd9 /shaders/rect.frag | |
parent | 91773de7ac4e07643fc47f1f0c1fdb6a255f53d2 (diff) | |
download | pugl-13f9ef04aaf5f3583ef83bffc094758f0d640634.tar.gz pugl-13f9ef04aaf5f3583ef83bffc094758f0d640634.tar.bz2 pugl-13f9ef04aaf5f3583ef83bffc094758f0d640634.zip |
GL3 Test: Move shaders to separate files
Diffstat (limited to 'shaders/rect.frag')
-rw-r--r-- | shaders/rect.frag | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/shaders/rect.frag b/shaders/rect.frag new file mode 100644 index 0000000..d128f37 --- /dev/null +++ b/shaders/rect.frag @@ -0,0 +1,36 @@ +#version 330 + +/* The fragment shader uses the UV coordinates to calculate whether it is in + the T, R, B, or L border. These are then mixed with the border color, and + their inverse is mixed with the fill color, to calculate the fragment color. + For example, if we are in the top border, then T=1, so the border mix factor + TRBL=1, and the fill mix factor (1-TRBL) is 0. + + The use of pixel units here is handy because the border width can be + specified precisely in pixels to draw sharp lines. The border width is just + hardcoded, but could be made a uniform or vertex attribute easily enough. */ + +uniform vec2 u_size; +uniform vec4 u_borderColor; +uniform vec4 u_fillColor; + +noperspective in vec2 f_uv; + +layout(location = 0) out vec4 FragColor; + +void +main() +{ + const float border_width = 2.0; + + float t = step(border_width, f_uv[1]); + float r = step(border_width, u_size.x - f_uv[0]); + float b = step(border_width, u_size.y - f_uv[1]); + float l = step(border_width, f_uv[0]); + float fill_mix = t * r * b * l; + float border_mix = 1.0 - fill_mix; + vec4 fill = fill_mix * u_fillColor; + vec4 border = border_mix * u_borderColor; + + FragColor = fill + border; +} |