@@ -297,7 +297,7 @@ fn sdf_arc_filled(
297
297
}
298
298
}
299
299
300
- SDFValue ( sdf_value)
300
+ SDFValue :: new ( sdf_value)
301
301
}
302
302
303
303
/// Computes a circular angular fade-out based on direction from center.
@@ -355,6 +355,11 @@ fn arc_fade_out(
355
355
}
356
356
rel_angle = rel_angle. clamp ( 0.0 , effective_arc_length_angle) ;
357
357
358
+ if opaque_percentage >= 1.0 - EPSILON {
359
+ // If the opaque percentage is effectively 100%, we return 1.0.
360
+ return 1.0 ;
361
+ }
362
+
358
363
let norm_angle = rel_angle / effective_arc_length_angle;
359
364
360
365
let fade_center = fade_center_angle. rem_euclid ( TWO_PI ) ;
@@ -401,7 +406,7 @@ fn arc_fade_out(
401
406
/// * `opaque_percentage`: Percentage of the arc that is opaque.
402
407
/// The fade starts at the edges of the opaque region.
403
408
///
404
- /// Returns a `Vec2` with the first component being the SDF value
409
+ /// Returns a `Vec2` with the first component being the [`SDFValue`] for the arc outline,
405
410
/// and the second component being the fade intensity.
406
411
fn sdf_arc_outline (
407
412
uv : Vec2 ,
@@ -414,14 +419,6 @@ fn sdf_arc_outline(
414
419
fade_center_angle : f32 ,
415
420
opaque_percentage : f32 ,
416
421
) -> ( SDFValue , f32 ) {
417
- let sdf_inner = sdf_arc_filled (
418
- uv,
419
- center_shape,
420
- start_angle,
421
- end_angle,
422
- spine_radius,
423
- inner_radius * 2.0 ,
424
- ) ;
425
422
let sdf_outer = sdf_arc_filled (
426
423
uv,
427
424
center_shape,
@@ -430,8 +427,7 @@ fn sdf_arc_outline(
430
427
spine_radius,
431
428
outer_radius * 2.0 ,
432
429
) ;
433
- // remove m_inner from m_outer
434
- let sdf_value = sdf_outer. difference ( sdf_inner) ;
430
+ let sdf_value = sdf_outer. to_outline_asym ( outer_radius - inner_radius, 0.0 ) ;
435
431
let fade_intensity = arc_fade_out (
436
432
uv,
437
433
center_shape,
@@ -445,22 +441,19 @@ fn sdf_arc_outline(
445
441
( sdf_value, fade_intensity)
446
442
}
447
443
448
- fn sdf_circle_outline ( uv : Vec2 , center : Vec2 , radius : f32 , stroke : f32 ) -> f32 {
449
- // Compute distance from pixel to circle center.
450
- let dist = ( uv - center) . length ( ) ;
451
- // Half stroke for symmetric band.
452
- let half_th = stroke * 0.5 ;
453
- // Return 1 if pixel is within the stroke band.
454
- ( dist - radius) . abs ( ) . step ( half_th)
455
- }
456
-
457
- fn sdf_circle ( uv : Vec2 , center : Vec2 , inner_radius : f32 , outer_radius : f32 ) -> f32 {
458
- // Compute distance from pixel to circle center.
459
- let dist = ( uv - center) . length ( ) ;
460
- // Return 1 if pixel is within the stroke band.
461
- ( dist - inner_radius)
462
- . abs ( )
463
- . step ( outer_radius - inner_radius)
444
+ /// SDF for a filled circle.
445
+ ///
446
+ /// * `uv`: The coordinates relative to the center of the circle.
447
+ /// * `center`: The center of the circle.
448
+ /// * `radius`: The radius of the circle.
449
+ ///
450
+ /// Returns the [`SDFValue`] for the circle.
451
+ fn sdf_circle_filled ( uv : Vec2 , center : Vec2 , radius : f32 ) -> SDFValue {
452
+ let p = uv - center;
453
+ let d = p. length ( ) - radius;
454
+ let outside_distance = d. max ( 0.0 ) ;
455
+ let inside_distance = d. min ( 0.0 ) ;
456
+ SDFValue :: new ( outside_distance + inside_distance)
464
457
}
465
458
466
459
/// Returns a value along an exponential curve shaped by `c`.
@@ -938,13 +931,13 @@ impl Inputs {
938
931
. position ;
939
932
let middle_circle_radius = middle_circle_position. y . abs ( ) . max ( target_radius) ;
940
933
941
- let m_middle_circle_position_path = sdf_circle_outline (
934
+ let m_middle_circle_position_path = sdf_circle_filled (
942
935
uv,
943
936
middle_circle_start_position / 2.0 ,
944
937
middle_circle_start_radius / 2.0 ,
945
- target_stroke / 2.0 ,
946
- ) ;
947
- debug_blue_alpha = debug_blue_alpha. max ( m_middle_circle_position_path) ;
938
+ )
939
+ . to_outline ( target_stroke / 2.0 ) ;
940
+ debug_blue_alpha = debug_blue_alpha. max ( m_middle_circle_position_path. to_alpha ( ) ) ;
948
941
949
942
let middle_circle_moved_distance =
950
943
( middle_circle_start_position - middle_circle_position) . length ( ) ;
@@ -958,23 +951,17 @@ impl Inputs {
958
951
//middle_circle_position.y -=
959
952
// (middle_circle_position.y + middle_circle_radius) * (1.0 - t_master);
960
953
961
- let m_start_circle = sdf_circle_outline ( uv, Vec2 :: ZERO , target_radius, target_stroke) ;
962
- debug_red_alpha = debug_red_alpha. max ( m_start_circle) ;
963
- let m_middle_circle_path = sdf_circle_outline (
964
- uv,
965
- middle_circle_start_position,
966
- middle_circle_start_radius,
967
- target_stroke / 2.0 ,
968
- ) ;
969
- debug_red_alpha = debug_red_alpha. max ( m_middle_circle_path) ;
954
+ let m_start_circle = sdf_circle_filled ( uv, Vec2 :: ZERO , target_radius) . to_outline ( target_stroke) ;
955
+ debug_red_alpha = debug_red_alpha. max ( m_start_circle. to_alpha ( ) ) ;
956
+ let m_middle_circle_path =
957
+ sdf_circle_filled ( uv, middle_circle_start_position, middle_circle_start_radius)
958
+ . to_outline ( target_stroke / 2.0 ) ;
959
+ debug_red_alpha = debug_red_alpha. max ( m_middle_circle_path. to_alpha ( ) ) ;
970
960
971
- let m_middle_circle_outline = sdf_circle_outline (
972
- uv,
973
- middle_circle_position,
974
- middle_circle_radius,
975
- target_stroke / 2.0 ,
976
- ) ;
977
- debug_blue_alpha = debug_blue_alpha. max ( m_middle_circle_outline) ;
961
+ let m_middle_circle_outline =
962
+ sdf_circle_filled ( uv, middle_circle_position, middle_circle_radius)
963
+ . to_outline ( target_stroke / 2.0 ) ;
964
+ debug_blue_alpha = debug_blue_alpha. max ( m_middle_circle_outline. to_alpha ( ) ) ;
978
965
979
966
for i in 0 ..num_circles {
980
967
// Compute the position of the circle based on the angle and radius.
@@ -1002,13 +989,9 @@ impl Inputs {
1002
989
black_alpha = black_alpha. max ( m. 0 . to_alpha ( ) * ( m. 1 + t_assist_circle) . min ( 1.0 ) ) ;
1003
990
// * (m.y + 6.0 / 256.0));
1004
991
1005
- let m = sdf_circle_outline (
1006
- uv,
1007
- middle_circle_position,
1008
- middle_circle_radius,
1009
- outer_circle_outer_radius * 2.0 ,
1010
- ) ;
1011
- black_alpha = black_alpha. max ( ( smoothstep ( 0.0 , aa_width, m) ) * t_assist_circle) ;
992
+ let m = sdf_circle_filled ( uv, middle_circle_position, middle_circle_radius)
993
+ . to_outline ( outer_circle_outer_radius * 2.0 ) ;
994
+ black_alpha = black_alpha. max ( m. to_alpha ( ) * t_assist_circle) ;
1012
995
}
1013
996
1014
997
if DEBUG {
@@ -1019,7 +1002,7 @@ impl Inputs {
1019
1002
PI / 4.0 ,
1020
1003
1.0 ,
1021
1004
0.1 ,
1022
- 0.3 ,
1005
+ 0.5 ,
1023
1006
-PI / 4.0 ,
1024
1007
1.0 ,
1025
1008
) ;
0 commit comments