git.lucas.co / cce-gallery
widget gallery and compositor test bench

commitf9350cee3ab8cd24db3a01d0e7b3a6fafe798a89
parent77cf913909
authorLucas Galante <[email protected]>
date2026-07-04 21:39
Refactor bevel corners rendering using trigonometric physical shading model

 src/main.rs | 93 ++++++++++++++++++++++---------------------------------------
 1 file changed, 34 insertions(+), 59 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 5a09f9b..629ca72 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -176,70 +176,45 @@ fn push_bevel_slice_corners(
     r_offset: f32,
     slice_w: f32,
     sw: f32, sh: f32,
-    light_color: [f32; 4],
-    dark_color: [f32; 4],
+    border_color: [f32; 4],
+    color_offset: f32,
     verts: &mut Vec<Vertex>,
 ) {
     if r_offset <= 0.0 {
         return;
     }
     let segments = 32;
-    // Top-Left: uniform light_color
-    cce_ui::backend::window_runner::push_arc_background_vertices(
-        wx + r, wy + r, r_offset, slice_w,
-        std::f32::consts::PI, 1.5 * std::f32::consts::PI,
-        sw, sh, light_color, segments, [0.0, 0.0, -1.0],
-        verts
-    );
-
-    // Top-Right: transitions from light_color (at 1.5 * PI) to dark_color (at 2.0 * PI)
-    let tr_start = 1.5 * std::f32::consts::PI;
-    let tr_end = 2.0 * std::f32::consts::PI;
-    for j in 0..segments {
-        let theta1 = tr_start + (j as f32) * (tr_end - tr_start) / (segments as f32);
-        let theta2 = tr_start + ((j + 1) as f32) * (tr_end - tr_start) / (segments as f32);
-        let t_val = (j as f32 + 0.5) / (segments as f32);
-        let segment_color = [
-            light_color[0] + t_val * (dark_color[0] - light_color[0]),
-            light_color[1] + t_val * (dark_color[1] - light_color[1]),
-            light_color[2] + t_val * (dark_color[2] - light_color[2]),
-            light_color[3],
-        ];
-        cce_ui::backend::window_runner::push_arc_background_vertices(
-            wx + ww - r, wy + r, r_offset, slice_w,
-            theta1, theta2,
-            sw, sh, segment_color, 1, [0.0, 0.0, -1.0],
-            verts
-        );
-    }
 
-    // Bottom-Right: uniform dark_color
-    cce_ui::backend::window_runner::push_arc_background_vertices(
-        wx + ww - r, wy + wh - r, r_offset, slice_w,
-        0.0, 0.5 * std::f32::consts::PI,
-        sw, sh, dark_color, segments, [0.0, 0.0, -1.0],
-        verts
-    );
-
-    // Bottom-Left: transitions from dark_color (at 0.5 * PI) to light_color (at 1.0 * PI)
-    let bl_start = 0.5 * std::f32::consts::PI;
-    let bl_end = std::f32::consts::PI;
-    for j in 0..segments {
-        let theta1 = bl_start + (j as f32) * (bl_end - bl_start) / (segments as f32);
-        let theta2 = bl_start + ((j + 1) as f32) * (bl_end - bl_start) / (segments as f32);
-        let t_val = (j as f32 + 0.5) / (segments as f32);
-        let segment_color = [
-            dark_color[0] + t_val * (light_color[0] - dark_color[0]),
-            dark_color[1] + t_val * (light_color[1] - dark_color[1]),
-            dark_color[2] + t_val * (light_color[2] - dark_color[2]),
-            dark_color[3],
-        ];
-        cce_ui::backend::window_runner::push_arc_background_vertices(
-            wx + r, wy + wh - r, r_offset, slice_w,
-            theta1, theta2,
-            sw, sh, segment_color, 1, [0.0, 0.0, -1.0],
-            verts
-        );
+    let corners = [
+        (wx + r, wy + r, std::f32::consts::PI, 1.5 * std::f32::consts::PI), // Top-Left
+        (wx + ww - r, wy + r, 1.5 * std::f32::consts::PI, 2.0 * std::f32::consts::PI), // Top-Right
+        (wx + ww - r, wy + wh - r, 0.0, 0.5 * std::f32::consts::PI), // Bottom-Right
+        (wx + r, wy + wh - r, 0.5 * std::f32::consts::PI, std::f32::consts::PI), // Bottom-Left
+    ];
+
+    for &(cx, cy, start_angle, end_angle) in &corners {
+        for j in 0..segments {
+            let theta1 = start_angle + (j as f32) * (end_angle - start_angle) / (segments as f32);
+            let theta2 = start_angle + ((j + 1) as f32) * (end_angle - start_angle) / (segments as f32);
+            let theta_mid = 0.5 * (theta1 + theta2);
+
+            let factor = -(theta_mid.cos() + theta_mid.sin());
+            let offset = factor * color_offset;
+
+            let segment_color = [
+                (border_color[0] + offset).clamp(0.0, 1.0),
+                (border_color[1] + offset).clamp(0.0, 1.0),
+                (border_color[2] + offset).clamp(0.0, 1.0),
+                border_color[3],
+            ];
+
+            cce_ui::backend::window_runner::push_arc_background_vertices(
+                cx, cy, r_offset, slice_w,
+                theta1, theta2,
+                sw, sh, segment_color, 1, [0.0, 0.0, -1.0],
+                verts
+            );
+        }
     }
 }
 
@@ -814,7 +789,7 @@ cascades in cce."
                                 push_bevel_slice_corners(
                                     wx, wy, ww, wh,
                                     r, r_offset, slice_w,
-                                    sw, sh, light_color, dark_color,
+                                    sw, sh, border_color, color_offset,
                                     &mut verts
                                 );
                             }
@@ -975,7 +950,7 @@ cascades in cce."
                                 push_bevel_slice_corners(
                                     wx, wy, ww, wh,
                                     r, r_offset, slice_w,
-                                    sw, sh, light_color, dark_color,
+                                    sw, sh, border_color, color_offset,
                                     &mut verts
                                 );
                         }