@@ -121,37 +121,69 @@ pub enum NodeOutline {
121121 EndOutlinePasses ,
122122}
123123
124+ /// Specifies when a stencil should be rendered.
125+ #[ derive( Copy , Clone , Default , Debug , PartialEq , Eq ) ]
126+ #[ cfg_attr( feature = "reflect" , derive( Reflect ) ) ]
127+ #[ cfg_attr( feature = "reflect" , reflect( Default ) ) ]
128+ pub enum OutlineStencilEnabled {
129+ /// Always render a stencil
130+ #[ default]
131+ Always ,
132+ /// Only render a stencil if the volume is visible
133+ IfVolume ,
134+ /// Never render a stencil
135+ Never ,
136+ }
137+
138+ impl OutlineStencilEnabled {
139+ pub ( crate ) fn is_enabled ( & self , volume_enabled : bool ) -> bool {
140+ match self {
141+ OutlineStencilEnabled :: Always => true ,
142+ OutlineStencilEnabled :: IfVolume => volume_enabled,
143+ OutlineStencilEnabled :: Never => false ,
144+ }
145+ }
146+ }
147+
124148/// A component for stenciling meshes during outline rendering.
125149///
126150/// Stencils are used both to prevent entities with outlines from being
127151/// covered by their own outline volumes and to allow entities to occlude
128152/// any outlines behind them.
129- #[ derive( Clone , Component ) ]
153+ #[ derive( Clone , Component , Default ) ]
130154#[ cfg_attr( feature = "reflect" , derive( Reflect ) ) ]
131155#[ cfg_attr( feature = "reflect" , reflect( Component , Default ) ) ]
132156pub struct OutlineStencil {
133- /// Enable rendering of the stencil
134- pub enabled : bool ,
157+ /// Controls when the stencil should be rendered
158+ pub enabled : OutlineStencilEnabled ,
135159 /// Offset of the stencil in logical pixels
136160 pub offset : f32 ,
137161}
138162
139- impl Default for OutlineStencil {
140- fn default ( ) -> Self {
141- OutlineStencil {
142- enabled : true ,
143- offset : 0.0 ,
144- }
145- }
163+ impl OutlineStencil {
164+ pub ( crate ) const INHERIT_DEFAULT : OutlineStencil = OutlineStencil {
165+ enabled : OutlineStencilEnabled :: IfVolume ,
166+ offset : 0.0 ,
167+ } ;
146168}
147169
148- fn lerp_bool ( this : bool , other : bool , scalar : f32 ) -> bool {
170+ fn lerp_stencil_enabled (
171+ this : OutlineStencilEnabled ,
172+ other : OutlineStencilEnabled ,
173+ scalar : f32 ,
174+ ) -> OutlineStencilEnabled {
149175 if scalar <= 0.0 {
150176 this
151177 } else if scalar >= 1.0 {
152178 other
153179 } else {
154- this | other
180+ match ( this, other) {
181+ ( OutlineStencilEnabled :: Always , _) => OutlineStencilEnabled :: Always ,
182+ ( _, OutlineStencilEnabled :: Always ) => OutlineStencilEnabled :: Always ,
183+ ( OutlineStencilEnabled :: IfVolume , _) => OutlineStencilEnabled :: IfVolume ,
184+ ( _, OutlineStencilEnabled :: IfVolume ) => OutlineStencilEnabled :: Never ,
185+ _ => OutlineStencilEnabled :: Never ,
186+ }
155187 }
156188}
157189
@@ -176,7 +208,7 @@ macro_rules! impl_lerp {
176208
177209fn lerp_stencil ( start : & OutlineStencil , end : & OutlineStencil , t : f32 ) -> OutlineStencil {
178210 OutlineStencil {
179- enabled : lerp_bool ( start. enabled , end. enabled , t) ,
211+ enabled : lerp_stencil_enabled ( start. enabled , end. enabled , t) ,
180212 offset : start. offset . lerp ( end. offset , t) ,
181213 }
182214}
@@ -196,6 +228,16 @@ pub struct OutlineVolume {
196228 pub colour : Color ,
197229}
198230
231+ fn lerp_bool ( this : bool , other : bool , t : f32 ) -> bool {
232+ if t <= 0.0 {
233+ this
234+ } else if t >= 1.0 {
235+ other
236+ } else {
237+ this || other
238+ }
239+ }
240+
199241fn lerp_volume ( start : & OutlineVolume , end : & OutlineVolume , t : f32 ) -> OutlineVolume {
200242 OutlineVolume {
201243 visible : lerp_bool ( start. visible , end. visible , t) ,
0 commit comments