Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2D depth stencil not set properly on render #407

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 22 additions & 29 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,43 +1179,22 @@ impl SpecializedRenderPipeline for ParticlesRenderPipeline {
shader_defs.push("RIBBONS".into());
}

#[cfg(all(feature = "2d", feature = "3d"))]
assert_eq!(CORE_2D_DEPTH_FORMAT, CORE_3D_DEPTH_FORMAT);
#[cfg(all(feature = "2d", feature = "3d"))]
let depth_stencil = match key.pipeline_mode {
// Bevy's Transparent2d render phase doesn't support a depth-stencil buffer.
PipelineMode::Camera2d => None,
PipelineMode::Camera3d => Some(DepthStencilState {
format: CORE_3D_DEPTH_FORMAT,
// Use depth buffer with alpha-masked or opaque particles, not
// with transparent ones
depth_write_enabled: matches!(
key.alpha_mask,
ParticleRenderAlphaMaskPipelineKey::AlphaMask
| ParticleRenderAlphaMaskPipelineKey::Opaque
),
// Bevy uses reverse-Z, so GreaterEqual really means closer
depth_compare: CompareFunction::GreaterEqual,
stencil: StencilState::default(),
bias: DepthBiasState::default(),
}),
};

#[cfg(all(feature = "2d", not(feature = "3d")))]
let depth_stencil = Some(DepthStencilState {
#[cfg(feature = "2d")]
let depth_stencil_2d = DepthStencilState {
format: CORE_2D_DEPTH_FORMAT,
// Use depth buffer with alpha-masked particles, not with transparent ones
depth_write_enabled: false, // TODO - opaque/alphamask 2d
// Bevy uses reverse-Z, so GreaterEqual really means closer
depth_compare: CompareFunction::GreaterEqual,
stencil: StencilState::default(),
bias: DepthBiasState::default(),
});
};

#[cfg(all(feature = "3d", not(feature = "2d")))]
let depth_stencil = Some(DepthStencilState {
#[cfg(feature = "3d")]
let depth_stencil_3d = DepthStencilState {
format: CORE_3D_DEPTH_FORMAT,
// Use depth buffer with alpha-masked particles, not with transparent ones
// Use depth buffer with alpha-masked or opaque particles, not
// with transparent ones
depth_write_enabled: matches!(
key.alpha_mask,
ParticleRenderAlphaMaskPipelineKey::AlphaMask
Expand All @@ -1225,7 +1204,21 @@ impl SpecializedRenderPipeline for ParticlesRenderPipeline {
depth_compare: CompareFunction::GreaterEqual,
stencil: StencilState::default(),
bias: DepthBiasState::default(),
});
};

#[cfg(all(feature = "2d", feature = "3d"))]
assert_eq!(CORE_2D_DEPTH_FORMAT, CORE_3D_DEPTH_FORMAT);
#[cfg(all(feature = "2d", feature = "3d"))]
let depth_stencil = match key.pipeline_mode {
PipelineMode::Camera2d => Some(depth_stencil_2d),
PipelineMode::Camera3d => Some(depth_stencil_3d),
};

#[cfg(all(feature = "2d", not(feature = "3d")))]
let depth_stencil = Some(depth_stencil_2d);

#[cfg(all(feature = "3d", not(feature = "2d")))]
let depth_stencil = Some(depth_stencil_3d);

let format = if key.hdr {
ViewTarget::TEXTURE_FORMAT_HDR
Expand Down
Loading