remove DeterministicRenderingConfig (#12811)

# Objective

- Since #12453, `DeterministicRenderingConfig` doesn't do anything

## Solution

- Remove it

---

## Migration Guide

- Removed `DeterministicRenderingConfig`. There shouldn't be any z
fighting anymore in the rendering even without setting
`stable_sort_z_fighting`
This commit is contained in:
François Mockers 2024-04-01 11:32:47 +02:00 committed by GitHub
parent 9084526794
commit 93fd02e8ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 0 additions and 129 deletions

View file

@ -673,17 +673,6 @@ description = "Showcases different blend modes"
category = "3D Rendering"
wasm = true
[[example]]
name = "deterministic"
path = "examples/3d/deterministic.rs"
doc-scrape-examples = true
[package.metadata.example.deterministic]
name = "Deterministic rendering"
description = "Stop flickering from z-fighting at a performance cost"
category = "3D Rendering"
wasm = true
[[example]]
name = "lighting"
path = "examples/3d/lighting.rs"

View file

@ -1,14 +0,0 @@
use bevy_ecs::system::Resource;
/// Configure deterministic rendering to fix flickering due to z-fighting.
#[derive(Resource, Default)]
pub struct DeterministicRenderingConfig {
/// Sort visible entities by id before rendering to avoid flickering.
///
/// Render is parallel by default, and if there's z-fighting, it may cause flickering.
/// Default fix for the issue is to set `depth_bias` per material.
/// When it is not possible, entities sorting can be used.
///
/// This option costs performance and disabled by default.
pub stable_sort_z_fighting: bool,
}

View file

@ -15,7 +15,6 @@ extern crate core;
pub mod alpha;
pub mod batching;
pub mod camera;
pub mod deterministic;
pub mod diagnostic;
pub mod extract_component;
pub mod extract_instances;
@ -62,7 +61,6 @@ use bevy_window::{PrimaryWindow, RawHandleWrapper};
use globals::GlobalsPlugin;
use renderer::{RenderAdapter, RenderAdapterInfo, RenderDevice, RenderQueue};
use crate::deterministic::DeterministicRenderingConfig;
use crate::renderer::WgpuWrapper;
use crate::{
camera::CameraPlugin,
@ -238,8 +236,6 @@ pub const MATHS_SHADER_HANDLE: Handle<Shader> = Handle::weak_from_u128(106653563
impl Plugin for RenderPlugin {
/// Initializes the renderer, sets up the [`RenderSet`] and creates the rendering sub-app.
fn build(&self, app: &mut App) {
app.init_resource::<DeterministicRenderingConfig>();
app.init_asset::<Shader>()
.init_asset_loader::<ShaderLoader>();

View file

@ -11,7 +11,6 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_transform::{components::GlobalTransform, TransformSystem};
use bevy_utils::Parallel;
use crate::deterministic::DeterministicRenderingConfig;
use crate::{
camera::{
camera_system, Camera, CameraProjection, OrthographicProjection, PerspectiveProjection,
@ -387,7 +386,6 @@ pub fn check_visibility(
&GlobalTransform,
Has<NoFrustumCulling>,
)>,
deterministic_rendering_config: Res<DeterministicRenderingConfig>,
) {
for (mut visible_entities, frustum, maybe_view_mask, camera) in &mut view_query {
if !camera.is_active {
@ -446,11 +444,6 @@ pub fn check_visibility(
visible_entities.entities.clear();
thread_queues.drain_into(&mut visible_entities.entities);
if deterministic_rendering_config.stable_sort_z_fighting {
// We can use the faster unstable sort here because
// the values (`Entity`) are guaranteed to be unique.
visible_entities.entities.sort_unstable();
}
}
}

View file

@ -1,92 +0,0 @@
//! Shows how to enable deterministic rendering which helps with flickering due to z-fighting.
//! Rendering is not deterministic by default.
//! Note most users don't need rendering to be deterministic, and should rely on depth bias instead.
use bevy::app::App;
use bevy::app::Startup;
use bevy::prelude::*;
use bevy::render::deterministic::DeterministicRenderingConfig;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, (keys, update_help).chain())
.run();
}
fn setup(
mut commands: Commands,
mut materials: ResMut<Assets<StandardMaterial>>,
mut meshes: ResMut<Assets<Mesh>>,
mut deterministic_rendering_config: ResMut<DeterministicRenderingConfig>,
) {
// Safe default.
deterministic_rendering_config.stable_sort_z_fighting = true;
// Help message will be rendered there.
commands.spawn(TextBundle::default().with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(12.0),
left: Val::Px(12.0),
..default()
}));
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(3.0, 3.0, 3.0).looking_at(Vec3::new(0., 0., 0.), Vec3::Y),
..default()
});
let mesh = meshes.add(Plane3d::default().mesh().size(2.0, 2.0));
let nb_plane = 10;
for i in 0..nb_plane {
let color = Color::hsl(i as f32 * 360.0 / nb_plane as f32, 1.0, 0.5);
commands.spawn(PbrBundle {
mesh: mesh.clone(),
material: materials.add(StandardMaterial {
base_color: color,
// Setting depth bias would be a default choice to fix z-fighting.
// When it is not possible, deterministic rendering can be used.
// Here we intentionally don't use depth bias to demonstrate the issue.
depth_bias: 0.0,
unlit: true,
..Default::default()
}),
..default()
});
}
}
fn keys(
mut deterministic_rendering_config: ResMut<DeterministicRenderingConfig>,
keyboard_input: Res<ButtonInput<KeyCode>>,
) {
if keyboard_input.just_pressed(KeyCode::KeyD) {
deterministic_rendering_config.stable_sort_z_fighting ^= true;
}
}
fn update_help(
mut text: Query<&mut Text>,
deterministic_rendering_config: Res<DeterministicRenderingConfig>,
) {
if deterministic_rendering_config.is_changed() {
*text.single_mut() = Text::from_section(
format!(
"\
Press D to enable/disable deterministic rendering\n\
\n\
Deterministic rendering: {}\n\
\n\
When rendering is not deterministic, you may notice flickering due to z-fighting\n\
\n\
Warning: may cause seizures for people with photosensitive epilepsy",
deterministic_rendering_config.stable_sort_z_fighting
),
TextStyle {
font_size: 20.,
..default()
},
);
}
}

View file

@ -129,7 +129,6 @@ Example | Description
[Atmospheric Fog](../examples/3d/atmospheric_fog.rs) | A scene showcasing the atmospheric fog effect
[Blend Modes](../examples/3d/blend_modes.rs) | Showcases different blend modes
[Deferred Rendering](../examples/3d/deferred_rendering.rs) | Renders meshes with both forward and deferred pipelines
[Deterministic rendering](../examples/3d/deterministic.rs) | Stop flickering from z-fighting at a performance cost
[Fog](../examples/3d/fog.rs) | A scene showcasing the distance fog effect
[Generate Custom Mesh](../examples/3d/generate_custom_mesh.rs) | Simple showcase of how to generate a custom mesh with a custom texture
[Irradiance Volumes](../examples/3d/irradiance_volumes.rs) | Demonstrates irradiance volumes