shader/rectangle_frag.glsl

changeset 159
da7ebfcdd159
parent 158
f650994ec543
--- a/shader/rectangle_frag.glsl	Tue Jun 17 20:11:53 2025 +0200
+++ b/shader/rectangle_frag.glsl	Wed Jun 18 23:55:08 2025 +0200
@@ -1,10 +1,13 @@
 layout(location = 0) out vec4 diffuse;
 in vec2 uvcoord;
 
+uniform vec2 size;
+#ifdef FILL
 uniform vec4 color;
-uniform vec2 size;
-#ifndef FILL
+#endif
+#ifdef BORDER
 uniform float thickness;
+uniform vec4 border_color;
 #endif
 #ifdef ROUNDED_CORNERS
 uniform float radius;
@@ -50,7 +53,7 @@
         }
     }
 
-    #ifdef FILL
+    #ifndef BORDER
     // For filled rectangle with rounded corners
     if (in_corner_region) {
         float dist = length(corner_distances[corner_idx]);
@@ -58,39 +61,57 @@
             discard; // Outside the rounded corner
         }
     } else if (uvcoord.x < 0.0 || uvcoord.y < 0.0 || uvcoord.x > size.x || uvcoord.y > size.y) {
+        // TODO: at the moment we don't have fragments here, but we will with glow
         discard; // Outside the rectangle
     }
     diffuse = color;
-    #else  // no FILL
+    #else  // BORDER
     // For outlined rectangle with rounded corners
     if (in_corner_region) {
         float dist = length(corner_distances[corner_idx]);
         if (dist > radius) {
             discard; // Outside the rounded corner
         } else if (dist < radius - thickness) {
-            discard; // Inside the outline
+            // Inside the outline
+            #ifdef FILL
+            diffuse = color;
+            #else
+            discard;
+            #endif
+        } else {
+            // the corner outline
+            diffuse = border_color;
         }
-        diffuse = color;
     } else if (any(lessThan(uvcoord, vec2(thickness))) || any(greaterThan(uvcoord, size - thickness))) {
         // On a straight edge
         if (uvcoord.x >= 0.0 && uvcoord.y >= 0.0 && uvcoord.x <= size.x && uvcoord.y <= size.y) {
-            diffuse = color;
+            diffuse = border_color;
         } else {
             discard;
         }
     } else {
-        discard; // Inside the outline
+        // Inside the outline
+        #ifdef FILL
+        diffuse = color;
+        #else
+        discard;
+        #endif
     }
-    #endif // FILL
+    #endif // BORDER
 #else // no ROUNDED_CORNERS
-    #ifdef FILL
+    #ifdef BORDER
+    if (any(notEqual(1.0-step(thickness, uvcoord)+step(size-thickness, uvcoord), vec2(0.0)))) {
+        diffuse = border_color;
+    } else {
+        // Inside the outline
+        #ifdef FILL
+        diffuse = color;
+        #else
+        discard;
+        #endif
+    }
+    #else // no BORDER
     diffuse = color;
-    #else // no FILL
-    if (any(notEqual(1.0-step(thickness, uvcoord)+step(size-thickness, uvcoord), vec2(0.0)))) {
-        diffuse = color;
-    } else {
-        discard;
-    }
-    #endif // FILL
+    #endif // BORDER
 #endif // ROUNDED_CORNERS
 }

mercurial