Skip to content

Commit c8492ed

Browse files
committed
Move double-sided mesh support into separate OutlineFace component.
1 parent ddb6ad5 commit c8492ed

5 files changed

Lines changed: 43 additions & 26 deletions

File tree

examples/ui_mode.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,14 @@ fn change_mode(
267267
commands
268268
.entity(entity)
269269
.insert(match event.entered.unwrap() {
270-
DrawMethod::Extrude => OutlineMode::ExtrudeFlat,
271-
DrawMethod::ExtrudeDoubleSided => OutlineMode::ExtrudeFlatDoubleSided,
272-
DrawMethod::JumpFlood => OutlineMode::FloodFlat,
273-
DrawMethod::JumpFloodDoubleSided => OutlineMode::FloodFlatDoubleSided,
270+
DrawMethod::Extrude => (OutlineMode::ExtrudeFlat, OutlineFace::Front),
271+
DrawMethod::ExtrudeDoubleSided => {
272+
(OutlineMode::ExtrudeFlat, OutlineFace::DoubleSided)
273+
}
274+
DrawMethod::JumpFlood => (OutlineMode::FloodFlat, OutlineFace::Front),
275+
DrawMethod::JumpFloodDoubleSided => {
276+
(OutlineMode::FloodFlat, OutlineFace::DoubleSided)
277+
}
274278
});
275279
}
276280
}

src/computed.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use bevy::{camera::visibility::RenderLayers, ecs::query::QueryItem, prelude::*};
33
use crate::{
44
pipeline_key::ComputedOutlineKey,
55
uniforms::{DepthMode, DrawMode},
6-
InheritOutline, OutlineAlphaMask, OutlineMode, OutlinePlaneDepth, OutlineRenderLayers,
7-
OutlineStencil, OutlineStencilEnabled, OutlineVolume, OutlineWarmUp,
6+
InheritOutline, OutlineAlphaMask, OutlineFace, OutlineMode, OutlinePlaneDepth,
7+
OutlineRenderLayers, OutlineStencil, OutlineStencilEnabled, OutlineVolume, OutlineWarmUp,
88
};
99

1010
#[derive(Clone)]
@@ -24,6 +24,10 @@ pub(crate) struct ComputedStencil {
2424
pub(crate) struct ComputedMode {
2525
pub(crate) depth_mode: DepthMode,
2626
pub(crate) draw_mode: DrawMode,
27+
}
28+
29+
#[derive(Clone)]
30+
pub(crate) struct ComputedFace {
2731
pub(crate) double_sided: bool,
2832
}
2933

@@ -124,6 +128,7 @@ pub(crate) struct ComputedInternal {
124128
pub(crate) volume: Sourced<ComputedVolume>,
125129
pub(crate) stencil: Sourced<ComputedStencil>,
126130
pub(crate) mode: Sourced<ComputedMode>,
131+
pub(crate) face: Sourced<ComputedFace>,
127132
pub(crate) depth: Sourced<ComputedDepth>,
128133
pub(crate) layers: Sourced<RenderLayers>,
129134
pub(crate) alpha_mask: Sourced<OutlineAlphaMask>,
@@ -141,6 +146,7 @@ type OutlineComponents<'a> = (
141146
Option<Ref<'a, OutlineVolume>>,
142147
Option<Ref<'a, OutlineStencil>>,
143148
Option<Ref<'a, OutlineMode>>,
149+
Option<Ref<'a, OutlineFace>>,
144150
Option<Ref<'a, OutlinePlaneDepth>>,
145151
Option<Ref<'a, OutlineRenderLayers>>,
146152
Option<Ref<'a, RenderLayers>>,
@@ -220,6 +226,7 @@ fn update_computed_outline(
220226
volume,
221227
stencil,
222228
mode,
229+
face,
223230
depth,
224231
layers,
225232
fallback_layers,
@@ -239,6 +246,7 @@ fn update_computed_outline(
239246
|| computed.volume.is_changed(&volume, has_parent)
240247
|| computed.stencil.is_changed(&stencil, has_parent)
241248
|| computed.mode.is_changed(&mode, has_parent)
249+
|| computed.face.is_changed(&face, has_parent)
242250
|| computed.depth.is_changed(&depth, has_parent)
243251
|| computed
244252
.layers
@@ -279,32 +287,25 @@ fn update_computed_outline(
279287
OutlineMode::ExtrudeFlat => ComputedMode {
280288
depth_mode: DepthMode::Flat,
281289
draw_mode: DrawMode::Extrude,
282-
double_sided: false,
283-
},
284-
OutlineMode::ExtrudeFlatDoubleSided => ComputedMode {
285-
depth_mode: DepthMode::Flat,
286-
draw_mode: DrawMode::Extrude,
287-
double_sided: true,
288290
},
289291
OutlineMode::ExtrudeReal => ComputedMode {
290292
depth_mode: DepthMode::Real,
291293
draw_mode: DrawMode::Extrude,
292-
double_sided: false,
293294
},
294295
#[cfg(feature = "flood")]
295296
OutlineMode::FloodFlat => ComputedMode {
296297
depth_mode: DepthMode::Flat,
297298
draw_mode: DrawMode::JumpFlood,
298-
double_sided: false,
299-
},
300-
#[cfg(feature = "flood")]
301-
OutlineMode::FloodFlatDoubleSided => ComputedMode {
302-
depth_mode: DepthMode::Flat,
303-
draw_mode: DrawMode::JumpFlood,
304-
double_sided: true,
305299
},
306300
},
307301
),
302+
face: Sourced::set(
303+
face,
304+
parent_computed.map(|p| p.face.value.clone()),
305+
|face| ComputedFace {
306+
double_sided: matches!(face, OutlineFace::DoubleSided),
307+
},
308+
),
308309
depth: Sourced::set(
309310
depth,
310311
parent_computed.map(|p| p.depth.value.clone()),

src/lib.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,24 @@ pub enum OutlineMode {
268268
/// Vertex extrusion flattened into a billboard. (default)
269269
#[default]
270270
ExtrudeFlat,
271-
/// Vertex extrusion flattened into a double-sided billboard.
272-
ExtrudeFlatDoubleSided,
273271
/// Vertex extrusion in real model-space.
274272
ExtrudeReal,
275273
// Jump-flood into a billboard.
276274
#[cfg(feature = "flood")]
277275
FloodFlat,
278-
// Jump-flood into a double-sided billboard.
279-
#[cfg(feature = "flood")]
280-
FloodFlatDoubleSided,
276+
}
277+
278+
/// A component which controls which faces of an outline are rendered.
279+
#[derive(Clone, Component, Default)]
280+
#[cfg_attr(feature = "reflect", derive(Reflect))]
281+
#[cfg_attr(feature = "reflect", reflect(Component, Default))]
282+
#[non_exhaustive]
283+
pub enum OutlineFace {
284+
/// Render only the front face of the outline. (default)
285+
#[default]
286+
Front,
287+
/// Render both the front and back faces of the outline.
288+
DoubleSided,
281289
}
282290

283291
/// A component which controls the depth sorting of flat outlines and stencils.
@@ -553,6 +561,7 @@ impl Plugin for OutlinePlugin {
553561
.register_type::<OutlineVolume>()
554562
.register_type::<OutlineRenderLayers>()
555563
.register_type::<OutlineMode>()
564+
.register_type::<OutlineFace>()
556565
.register_type::<OutlineAlphaMask>()
557566
.register_type::<InheritOutline>()
558567
.register_type::<OutlineMsaa>();

src/pipeline.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ impl SpecializedMeshPipeline for OutlinePipeline {
155155
vertex_defs.push(val.clone());
156156
fragment_defs.push(val);
157157
};
158+
if key.depth_mode() == DepthMode::Real && key.double_sided() {
159+
warn!("OutlineFace::DoubleSided is incompatible with OutlineMode::ExtrudeReal");
160+
}
158161
let cull_mode = match (key.pass_type(), key.depth_mode()) {
159162
(PassType::Stencil, DepthMode::Real) => Some(Face::Back),
160163
(PassType::Volume, DepthMode::Real) => Some(Face::Front),

src/pipeline_key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub(crate) fn compute_outline_key(
293293
.with_vertex_offset_zero(outline.volume.value.offset == 0.0)
294294
.with_stencil_vertex_offset_zero(outline.stencil.value.offset == 0.0)
295295
.with_plane_offset_zero(outline.depth.value.world_plane_offset == Vec3::ZERO)
296-
.with_double_sided(outline.mode.value.double_sided)
296+
.with_double_sided(outline.face.value.double_sided)
297297
.with_alpha_mask_texture(outline.alpha_mask.value.texture.is_some())
298298
.with_alpha_mask_channel(outline.alpha_mask.value.channel);
299299
}

0 commit comments

Comments
 (0)