Skip to content

🧪 Extract non-pbr logic from bevy_pbr #18637

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ default = [
"bevy_pbr",
"bevy_picking",
"bevy_render",
"bevy_render_3d",
"bevy_scene",
"bevy_sprite",
"bevy_sprite_picking_backend",
Expand Down Expand Up @@ -242,6 +243,9 @@ bevy_picking = ["bevy_internal/bevy_picking"]
# Provides rendering functionality
bevy_render = ["bevy_internal/bevy_render", "bevy_color"]

# Provides functionality for rendering in 3d
bevy_render_3d = ["bevy_internal/bevy_render_3d"]

# Provides scene functionality
bevy_scene = ["bevy_internal/bevy_scene", "bevy_asset"]

Expand Down Expand Up @@ -475,7 +479,7 @@ pbr_multi_layer_material_textures = [
pbr_anisotropy_texture = ["bevy_internal/pbr_anisotropy_texture"]

# Enable support for PCSS, at the risk of blowing past the global, per-shader sampler limit on older/lower-end GPUs
experimental_pbr_pcss = ["bevy_internal/experimental_pbr_pcss"]
experimental_pcss = ["bevy_internal/experimental_pcss"]

# Enable support for specular textures in the `StandardMaterial`, at the risk of blowing past the global, per-shader texture limit on older/lower-end GPUs
pbr_specular_textures = ["bevy_internal/pbr_specular_textures"]
Expand Down Expand Up @@ -4111,7 +4115,7 @@ wasm = true
name = "pcss"
path = "examples/3d/pcss.rs"
doc-scrape-examples = true
required-features = ["experimental_pbr_pcss"]
required-features = ["experimental_pcss"]

[package.metadata.example.pcss]
name = "Percentage-closer soft shadows"
Expand Down
21 changes: 20 additions & 1 deletion crates/bevy_asset/src/id.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{Asset, AssetIndex};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_reflect::{std_traits::ReflectDefault, Reflect, TypePath};
use serde::{Deserialize, Serialize};
use uuid::Uuid;

Expand Down Expand Up @@ -261,6 +261,25 @@ impl UntypedAssetId {
UntypedAssetId::Uuid { uuid, .. } => InternalAssetId::Uuid(uuid),
}
}

/// Checks if [`UntypedAssetId`] has an invalid [`Uuid`].
/// This is weaker than comparing equality with the untyped asset id returned
/// by `AssetId::invalid().untyped()` because the [`TypeId`] is ignored.
pub fn is_invalid(&self) -> bool {
#[derive(Asset, TypePath)]
struct DummyAsset;

match self {
Self::Index {
type_id: _,
index: _,
} => false,
Self::Uuid {
type_id: _,
uuid: asset_uuid,
} => asset_uuid == &AssetId::<DummyAsset>::INVALID_UUID,
}
}
}

impl Display for UntypedAssetId {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_gizmos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ bevy_render = ["dep:bevy_render", "bevy_core_pipeline"]

[dependencies]
# Bevy
bevy_pbr = { path = "../bevy_pbr", version = "0.16.0-dev", optional = true }
bevy_sprite = { path = "../bevy_sprite", version = "0.16.0-dev", optional = true }
bevy_app = { path = "../bevy_app", version = "0.16.0-dev" }
bevy_color = { path = "../bevy_color", version = "0.16.0-dev" }
Expand All @@ -24,6 +23,7 @@ bevy_image = { path = "../bevy_image", version = "0.16.0-dev" }
bevy_math = { path = "../bevy_math", version = "0.16.0-dev" }
bevy_asset = { path = "../bevy_asset", version = "0.16.0-dev" }
bevy_render = { path = "../bevy_render", version = "0.16.0-dev", optional = true }
bevy_render_3d = { path = "../bevy_render_3d", version = "0.16.0-dev", optional = true }
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev" }
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.16.0-dev", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_gizmos/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub use bevy_gizmos_macros::GizmoConfigGroup;

#[cfg(all(
feature = "bevy_render",
any(feature = "bevy_pbr", feature = "bevy_sprite")
any(feature = "bevy_render_3d", feature = "bevy_sprite")
))]
use {crate::GizmoAsset, bevy_asset::Handle, bevy_ecs::component::Component};

Expand Down Expand Up @@ -246,7 +246,7 @@ impl Default for GizmoLineConfig {

#[cfg(all(
feature = "bevy_render",
any(feature = "bevy_pbr", feature = "bevy_sprite")
any(feature = "bevy_render_3d", feature = "bevy_sprite")
))]
#[derive(Component)]
pub(crate) struct GizmoMeshConfig {
Expand Down
34 changes: 17 additions & 17 deletions crates/bevy_gizmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub enum GizmoRenderSystem {
#[cfg(feature = "bevy_sprite")]
QueueLineGizmos2d,
/// Adds gizmos to the [`Transparent3d`](bevy_core_pipeline::core_3d::Transparent3d) render phase
#[cfg(feature = "bevy_pbr")]
#[cfg(feature = "bevy_render_3d")]
QueueLineGizmos3d,
}

Expand All @@ -47,12 +47,12 @@ pub mod primitives;
pub mod retained;
pub mod rounded_box;

#[cfg(all(feature = "bevy_pbr", feature = "bevy_render"))]
#[cfg(all(feature = "bevy_render_3d", feature = "bevy_render"))]
pub mod light;

#[cfg(all(feature = "bevy_sprite", feature = "bevy_render"))]
mod pipeline_2d;
#[cfg(all(feature = "bevy_pbr", feature = "bevy_render"))]
#[cfg(all(feature = "bevy_render_3d", feature = "bevy_render"))]
mod pipeline_3d;

/// The gizmos prelude.
Expand All @@ -74,7 +74,7 @@ pub mod prelude {
AppGizmoBuilder, GizmoAsset,
};

#[cfg(all(feature = "bevy_pbr", feature = "bevy_render"))]
#[cfg(all(feature = "bevy_render_3d", feature = "bevy_render"))]
pub use crate::light::{LightGizmoColor, LightGizmoConfigGroup, ShowLightGizmo};
}

Expand All @@ -89,7 +89,7 @@ use bevy_reflect::TypePath;

#[cfg(all(
feature = "bevy_render",
any(feature = "bevy_pbr", feature = "bevy_sprite")
any(feature = "bevy_render_3d", feature = "bevy_sprite")
))]
use crate::config::GizmoMeshConfig;

Expand Down Expand Up @@ -127,7 +127,7 @@ use {

#[cfg(all(
feature = "bevy_render",
any(feature = "bevy_pbr", feature = "bevy_sprite"),
any(feature = "bevy_render_3d", feature = "bevy_sprite"),
))]
use bevy_render::render_resource::{VertexAttribute, VertexBufferLayout, VertexStepMode};
use bevy_time::Fixed;
Expand All @@ -137,7 +137,7 @@ use config::GizmoLineJoint;
use config::{DefaultGizmoConfigGroup, GizmoConfig, GizmoConfigGroup, GizmoConfigStore};
use core::{any::TypeId, marker::PhantomData, mem};
use gizmos::{GizmoStorage, Swap};
#[cfg(all(feature = "bevy_pbr", feature = "bevy_render"))]
#[cfg(all(feature = "bevy_render_3d", feature = "bevy_render"))]
use light::LightGizmoPlugin;

#[cfg(feature = "bevy_render")]
Expand All @@ -148,7 +148,7 @@ const LINE_JOINT_SHADER_HANDLE: Handle<Shader> =

/// A [`Plugin`] that provides an immediate mode drawing api for visual debugging.
///
/// Requires to be loaded after [`PbrPlugin`](bevy_pbr::PbrPlugin) or [`SpritePlugin`](bevy_sprite::SpritePlugin).
/// Requires to be loaded after [`MeshPipelinePlugin`](bevy_render_3d::MeshPipelinePlugin) or [`SpritePlugin`](bevy_sprite::SpritePlugin).
#[derive(Default)]
pub struct GizmoPlugin;

Expand Down Expand Up @@ -178,7 +178,7 @@ impl Plugin for GizmoPlugin {
.add_plugins(UniformComponentPlugin::<LineGizmoUniform>::default())
.add_plugins(RenderAssetPlugin::<GpuLineGizmo>::default());

#[cfg(all(feature = "bevy_pbr", feature = "bevy_render"))]
#[cfg(all(feature = "bevy_render_3d", feature = "bevy_render"))]
app.add_plugins(LightGizmoPlugin);

#[cfg(feature = "bevy_render")]
Expand All @@ -196,11 +196,11 @@ impl Plugin for GizmoPlugin {
} else {
tracing::warn!("bevy_sprite feature is enabled but bevy_sprite::SpritePlugin was not detected. Are you sure you loaded GizmoPlugin after SpritePlugin?");
}
#[cfg(feature = "bevy_pbr")]
if app.is_plugin_added::<bevy_pbr::PbrPlugin>() {
#[cfg(feature = "bevy_render_3d")]
if app.is_plugin_added::<bevy_render_3d::MeshPipelinePlugin>() {
app.add_plugins(pipeline_3d::LineGizmo3dPlugin);
} else {
tracing::warn!("bevy_pbr feature is enabled but bevy_pbr::PbrPlugin was not detected. Are you sure you loaded GizmoPlugin after PbrPlugin?");
tracing::warn!("bevy_render_3d feature is enabled but bevy_render_3d::PbrPlugin was not detected. Are you sure you loaded GizmoPlugin after PbrPlugin?");
}
} else {
tracing::warn!("bevy_render feature is enabled but RenderApp was not detected. Are you sure you loaded GizmoPlugin after RenderPlugin?");
Expand Down Expand Up @@ -474,7 +474,7 @@ fn extract_gizmo_data(
#[cfg(feature = "webgl")]
_padding: Default::default(),
},
#[cfg(any(feature = "bevy_pbr", feature = "bevy_sprite"))]
#[cfg(any(feature = "bevy_render_3d", feature = "bevy_sprite"))]
GizmoMeshConfig {
line_perspective: config.line.perspective,
line_style: config.line.style,
Expand Down Expand Up @@ -655,7 +655,7 @@ impl<const I: usize, P: PhaseItem> RenderCommand<P> for SetLineGizmoBindGroup<I>
struct DrawLineGizmo<const STRIP: bool>;
#[cfg(all(
feature = "bevy_render",
any(feature = "bevy_pbr", feature = "bevy_sprite")
any(feature = "bevy_render_3d", feature = "bevy_sprite")
))]
impl<P: PhaseItem, const STRIP: bool> RenderCommand<P> for DrawLineGizmo<STRIP> {
type Param = SRes<RenderAssets<GpuLineGizmo>>;
Expand Down Expand Up @@ -718,7 +718,7 @@ impl<P: PhaseItem, const STRIP: bool> RenderCommand<P> for DrawLineGizmo<STRIP>
struct DrawLineJointGizmo;
#[cfg(all(
feature = "bevy_render",
any(feature = "bevy_pbr", feature = "bevy_sprite")
any(feature = "bevy_render_3d", feature = "bevy_sprite")
))]
impl<P: PhaseItem> RenderCommand<P> for DrawLineJointGizmo {
type Param = SRes<RenderAssets<GpuLineGizmo>>;
Expand Down Expand Up @@ -791,7 +791,7 @@ impl<P: PhaseItem> RenderCommand<P> for DrawLineJointGizmo {

#[cfg(all(
feature = "bevy_render",
any(feature = "bevy_pbr", feature = "bevy_sprite")
any(feature = "bevy_render_3d", feature = "bevy_sprite")
))]
fn line_gizmo_vertex_buffer_layouts(strip: bool) -> Vec<VertexBufferLayout> {
use VertexFormat::*;
Expand Down Expand Up @@ -849,7 +849,7 @@ fn line_gizmo_vertex_buffer_layouts(strip: bool) -> Vec<VertexBufferLayout> {

#[cfg(all(
feature = "bevy_render",
any(feature = "bevy_pbr", feature = "bevy_sprite")
any(feature = "bevy_render_3d", feature = "bevy_sprite")
))]
fn line_joint_gizmo_vertex_buffer_layouts() -> Vec<VertexBufferLayout> {
use VertexFormat::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_gizmos/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use bevy_math::{
primitives::{Cone, Sphere},
Isometry3d, Quat, Vec3,
};
use bevy_pbr::{DirectionalLight, PointLight, SpotLight};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_render_3d::{DirectionalLight, PointLight, SpotLight};
use bevy_transform::{components::GlobalTransform, TransformSystem};

use crate::{
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_gizmos/src/pipeline_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use bevy_ecs::{
world::{FromWorld, World},
};
use bevy_image::BevyDefault as _;
use bevy_pbr::{MeshPipeline, MeshPipelineKey, SetMeshViewBindGroup};
use bevy_render::sync_world::MainEntity;
use bevy_render::{
render_asset::{prepare_assets, RenderAssets},
Expand All @@ -32,6 +31,7 @@ use bevy_render::{
view::{ExtractedView, Msaa, RenderLayers, ViewTarget},
Render, RenderApp, RenderSet,
};
use bevy_render_3d::{MeshPipeline, MeshPipelineKey, SetMeshViewBindGroup};
use tracing::error;

pub struct LineGizmo3dPlugin;
Expand All @@ -51,7 +51,7 @@ impl Plugin for LineGizmo3dPlugin {
Render,
GizmoRenderSystem::QueueLineGizmos3d
.in_set(RenderSet::Queue)
.ambiguous_with(bevy_pbr::queue_material_meshes::<bevy_pbr::StandardMaterial>),
.ambiguous_with(RenderSet::QueueMeshes),
)
.add_systems(
Render,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_gizmos/src/retained.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub(crate) fn extract_linegizmos(
#[cfg(feature = "webgl")]
_padding: Default::default(),
},
#[cfg(any(feature = "bevy_pbr", feature = "bevy_sprite"))]
#[cfg(any(feature = "bevy_render_3d", feature = "bevy_sprite"))]
crate::config::GizmoMeshConfig {
line_perspective: gizmo.line_config.perspective,
line_style: gizmo.line_config.style,
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_gltf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bevy_mesh = { path = "../bevy_mesh", version = "0.16.0-dev" }
bevy_pbr = { path = "../bevy_pbr", version = "0.16.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev" }
bevy_render = { path = "../bevy_render", version = "0.16.0-dev" }
bevy_render_3d = { path = "../bevy_render_3d", version = "0.16.0-dev" }
bevy_scene = { path = "../bevy_scene", version = "0.16.0-dev", features = [
"bevy_render",
] }
Expand Down
5 changes: 2 additions & 3 deletions crates/bevy_gltf/src/loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ use bevy_mesh::{
skinning::{SkinnedMesh, SkinnedMeshInverseBindposes},
Indices, Mesh, MeshVertexAttribute, PrimitiveTopology, VertexAttributeValues,
};
use bevy_pbr::StandardMaterial;
#[cfg(feature = "pbr_transmission_textures")]
use bevy_pbr::UvChannel;
use bevy_pbr::{
DirectionalLight, MeshMaterial3d, PointLight, SpotLight, StandardMaterial, MAX_JOINTS,
};
use bevy_platform_support::collections::{HashMap, HashSet};
use bevy_render::{
camera::{Camera, OrthographicProjection, PerspectiveProjection, Projection, ScalingMode},
Expand All @@ -43,6 +41,7 @@ use bevy_render::{
render_resource::Face,
view::Visibility,
};
use bevy_render_3d::{DirectionalLight, MeshMaterial3d, PointLight, SpotLight, MAX_JOINTS};
use bevy_scene::Scene;
#[cfg(not(target_arch = "wasm32"))]
use bevy_tasks::IoTaskPool;
Expand Down
Loading