@@ -825,16 +825,27 @@ fn draw_time_bar_discrete(
825
825
/// Alpha compositing using "over" operator.
826
826
/// https://en.wikipedia.org/wiki/Alpha_compositing
827
827
fn composite_layers < const N : usize > ( overlay_colors : & [ Vec4 ; N ] ) -> Vec4 {
828
- let mut result = Vec4 :: ZERO ;
829
- for i in ( 0 ..overlay_colors. len ( ) ) . rev ( ) {
830
- let color = overlay_colors[ i] ;
831
- let alpha = color. w ;
832
- if alpha > 0.0 {
833
- result = result + ( color * alpha * ( 1.0 - result. w ) ) ;
834
- result. w += alpha * ( 1.0 - result. w ) ;
828
+ // Start with a fully opaque black background.
829
+ let mut color_bg = Vec4 :: new ( 0.0 , 0.0 , 0.0 , 1.0 ) ;
830
+ for i in 0 ..overlay_colors. len ( ) {
831
+ let color_fg = overlay_colors[ i] ;
832
+ let color_fg_rgb = color_fg. xyz ( ) ;
833
+ let alpha_fg = color_fg. w ;
834
+ if alpha_fg <= 0.0 {
835
+ continue ; // Skip fully transparent layers.
835
836
}
837
+
838
+ let color_bg_rgb = color_bg. xyz ( ) ;
839
+ let alpha_bg = color_bg. w ;
840
+
841
+ let alpha_final = alpha_bg + alpha_fg - alpha_bg * alpha_fg;
842
+
843
+ // Composite using the "over" operator.
844
+ color_bg = ( ( color_fg_rgb * alpha_fg + color_bg_rgb * alpha_bg * ( 1.0 - alpha_fg) )
845
+ / alpha_final)
846
+ . extend ( alpha_final) ;
836
847
}
837
- return result ;
848
+ return color_bg ;
838
849
}
839
850
840
851
const SHOW_TIME_BAR : bool = true ;
@@ -1003,7 +1014,7 @@ impl Inputs {
1003
1014
// * (m.y + 6.0 / 256.0));
1004
1015
1005
1016
let m = sdf_circle_filled ( uv, middle_circle_position, middle_circle_radius)
1006
- . to_outline ( outer_circle_outer_radius * 2.0 ) ;
1017
+ . to_outline ( outer_circle_outer_radius) ;
1007
1018
black_alpha = black_alpha. max ( m. to_alpha ( ) * t_assist_circle) ;
1008
1019
}
1009
1020
0 commit comments