@@ -66,35 +66,48 @@ impl SDFValue {
66
66
return smoothstep ( AA_WIDTH , -AA_WIDTH , self . 0 ) ;
67
67
}
68
68
69
- /// Creates an outline (hollow shape) from the SDF.
70
- ///
71
- /// * `inner_thickness`: how much to expand inwards to form the inner boundary of the outline.
72
- /// * `outer_thickness`: how much to expand outwards to form the outer boundary of the outline.
73
- ///
74
- /// The resulting SDF is negative *inside the outline material*.
75
- pub fn to_outline_asym ( self , inner_thickness : f32 , outer_thickness : f32 ) -> SDFValue {
76
- return SDFValue ( ( self . 0 - outer_thickness) . max ( -( self . 0 + inner_thickness) ) ) ;
69
+ /// Insets the shape by a given thickness.
70
+ /// This is done by shrinking the shape and then calculating the difference.
71
+ pub fn inset ( self , amount : f32 ) -> Self {
72
+ Self ( self . 0 . max ( -( self . 0 + amount) ) )
73
+ }
74
+
75
+ /// Expands (if amount > 0) or shrinks (if amount < 0) the shape.
76
+ /// This is equivalent to subtracting from the distance value.
77
+ pub fn offset ( & self , amount : f32 ) -> Self {
78
+ Self ( self . 0 - amount)
79
+ }
80
+
81
+ /// Takes the absolute value of the SDF, effectively creating an infinitely thin shell
82
+ /// on the surface of the original shape.
83
+ pub fn shell ( self ) -> Self {
84
+ Self ( self . 0 . abs ( ) )
77
85
}
78
86
79
87
/// Creates an outline (hollow shape) from the SDF.
80
- pub fn to_outline ( self , thickness : f32 ) -> SDFValue {
81
- SDFValue ( self . 0 . abs ( ) - thickness)
88
+ pub fn to_outline ( self , thickness : f32 ) -> Self {
89
+ Self ( self . 0 . abs ( ) - thickness)
82
90
}
83
91
84
92
/// Difference operation (self - other). Result is inside if inside self AND outside other.
85
93
/// Equivalent to Intersection(self, Invert(other)).
86
- pub fn difference ( self , other : SDFValue ) -> SDFValue {
87
- SDFValue ( self . 0 . max ( -other. 0 ) )
94
+ pub fn difference ( self , other : Self ) -> Self {
95
+ Self ( self . 0 . max ( -other. 0 ) )
88
96
}
89
97
90
98
/// Union operation (self U other). Result is inside if inside self OR inside other.
91
- pub fn union ( self , other : SDFValue ) -> SDFValue {
92
- SDFValue ( self . 0 . min ( other. 0 ) )
99
+ pub fn union ( self , other : Self ) -> Self {
100
+ Self ( self . 0 . min ( other. 0 ) )
93
101
}
94
102
95
103
/// Intersection operation (self ∩ other). Result is inside if inside self AND inside other.
96
- pub fn intersection ( self , other : SDFValue ) -> SDFValue {
97
- SDFValue ( self . 0 . max ( other. 0 ) )
104
+ pub fn intersection ( self , other : Self ) -> Self {
105
+ Self ( self . 0 . max ( other. 0 ) )
106
+ }
107
+
108
+ /// Inverts the SDF (inside becomes outside and vice-versa).
109
+ pub fn invert ( self ) -> Self {
110
+ Self ( -self . 0 )
98
111
}
99
112
}
100
113
@@ -427,7 +440,7 @@ fn sdf_arc_outline(
427
440
spine_radius,
428
441
outer_radius * 2.0 ,
429
442
) ;
430
- let sdf_value = sdf_outer. to_outline_asym ( outer_radius - inner_radius, 0.0 ) ;
443
+ let sdf_value = sdf_outer. inset ( outer_radius - inner_radius) ;
431
444
let fade_intensity = arc_fade_out (
432
445
uv,
433
446
center_shape,
@@ -1006,7 +1019,9 @@ impl Inputs {
1006
1019
-PI / 4.0 ,
1007
1020
1.0 ,
1008
1021
) ;
1009
- debug_green_alpha = debug_green_alpha. max ( sdf_arc_test. 0 . to_alpha ( ) * sdf_arc_test. 1 ) ;
1022
+ debug_green_alpha =
1023
+ debug_green_alpha. max ( sdf_arc_test. 0 . offset ( 0.05 ) . to_alpha ( ) * sdf_arc_test. 1 ) ;
1024
+ debug_red_alpha = debug_red_alpha. max ( sdf_arc_test. 0 . to_alpha ( ) * sdf_arc_test. 1 ) ;
1010
1025
}
1011
1026
1012
1027
if !DEBUG {
0 commit comments