mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
camera: split 2d and ui camera. remove resource_name mod
This commit is contained in:
parent
51d41b2302
commit
71b3755633
14 changed files with 61 additions and 65 deletions
|
@ -1,7 +1,8 @@
|
||||||
use bevy_render::{
|
use bevy_render::{
|
||||||
|
base_render_graph,
|
||||||
render_graph::{CommandQueue, Node, ResourceSlots, SystemNode},
|
render_graph::{CommandQueue, Node, ResourceSlots, SystemNode},
|
||||||
render_resource::{
|
render_resource::{
|
||||||
resource_name, BufferInfo, BufferUsage, RenderResourceAssignment, RenderResourceAssignments,
|
BufferInfo, BufferUsage, RenderResourceAssignment, RenderResourceAssignments,
|
||||||
},
|
},
|
||||||
renderer::{RenderContext, RenderResources},
|
renderer::{RenderContext, RenderResources},
|
||||||
};
|
};
|
||||||
|
@ -55,10 +56,10 @@ impl SystemNode for LightsNode {
|
||||||
let mut command_queue = self.command_queue.clone();
|
let mut command_queue = self.command_queue.clone();
|
||||||
let max_lights = self.max_lights;
|
let max_lights = self.max_lights;
|
||||||
(move |world: &mut SubWorld,
|
(move |world: &mut SubWorld,
|
||||||
render_resources: Res<RenderResources>,
|
render_resources: Res<RenderResources>,
|
||||||
// TODO: this write on RenderResourceAssignments will prevent this system from running in parallel with other systems that do the same
|
// TODO: this write on RenderResourceAssignments will prevent this system from running in parallel with other systems that do the same
|
||||||
mut render_resource_assignments: ResMut<RenderResourceAssignments>,
|
mut render_resource_assignments: ResMut<RenderResourceAssignments>,
|
||||||
query: &mut Query<(Read<Light>, Read<LocalToWorld>, Read<Translation>)>| {
|
query: &mut Query<(Read<Light>, Read<LocalToWorld>, Read<Translation>)>| {
|
||||||
if !lights_are_dirty {
|
if !lights_are_dirty {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +77,7 @@ impl SystemNode for LightsNode {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
render_resource_assignments.set(
|
render_resource_assignments.set(
|
||||||
resource_name::uniform::LIGHTS,
|
base_render_graph::uniform::LIGHTS,
|
||||||
RenderResourceAssignment::Buffer {
|
RenderResourceAssignment::Buffer {
|
||||||
resource: buffer,
|
resource: buffer,
|
||||||
range: 0..light_uniform_size as u64,
|
range: 0..light_uniform_size as u64,
|
||||||
|
@ -147,6 +148,7 @@ impl SystemNode for LightsNode {
|
||||||
light_count_size as u64,
|
light_count_size as u64,
|
||||||
total_size as u64,
|
total_size as u64,
|
||||||
);
|
);
|
||||||
}).system()
|
})
|
||||||
|
.system()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ use crate::{
|
||||||
texture::{
|
texture::{
|
||||||
Extent3d, Texture, TextureDescriptor, TextureDimension, TextureFormat, TextureUsage,
|
Extent3d, Texture, TextureDescriptor, TextureDimension, TextureFormat, TextureUsage,
|
||||||
},
|
},
|
||||||
Color, render_resource::resource_name,
|
Color,
|
||||||
};
|
};
|
||||||
use bevy_app::GetEventReader;
|
use bevy_app::GetEventReader;
|
||||||
use bevy_asset::AssetEvent;
|
use bevy_asset::AssetEvent;
|
||||||
|
@ -38,6 +38,12 @@ pub mod node {
|
||||||
pub const MAIN_PASS: &str = "main_pass";
|
pub const MAIN_PASS: &str = "main_pass";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod uniform {
|
||||||
|
pub const CAMERA: &str = "Camera";
|
||||||
|
pub const CAMERA2D: &str = "Camera2d";
|
||||||
|
pub const LIGHTS: &str = "Lights";
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for BaseRenderGraphConfig {
|
impl Default for BaseRenderGraphConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
BaseRenderGraphConfig {
|
BaseRenderGraphConfig {
|
||||||
|
@ -72,11 +78,11 @@ impl BaseRenderGraphBuilder for RenderGraph {
|
||||||
TextureCopyNode::new(resources.get_event_reader::<AssetEvent<Texture>>()),
|
TextureCopyNode::new(resources.get_event_reader::<AssetEvent<Texture>>()),
|
||||||
);
|
);
|
||||||
if config.add_3d_camera {
|
if config.add_3d_camera {
|
||||||
self.add_system_node(node::CAMERA, CameraNode::new(resource_name::uniform::CAMERA));
|
self.add_system_node(node::CAMERA, CameraNode::new(uniform::CAMERA));
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.add_2d_camera {
|
if config.add_2d_camera {
|
||||||
self.add_system_node(node::CAMERA2D, CameraNode::new(resource_name::uniform::CAMERA2D));
|
self.add_system_node(node::CAMERA2D, CameraNode::new(uniform::CAMERA2D));
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.add_main_depth_texture {
|
if config.add_main_depth_texture {
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
pass::RenderPass,
|
pass::RenderPass,
|
||||||
pipeline::{PipelineAssignments, PipelineDescriptor},
|
pipeline::{PipelineAssignments, PipelineDescriptor},
|
||||||
render_resource::{
|
render_resource::{
|
||||||
resource_name, EntitiesWaitingForAssets, EntityRenderResourceAssignments,
|
EntitiesWaitingForAssets, EntityRenderResourceAssignments,
|
||||||
RenderResourceAssignments, ResourceInfo,
|
RenderResourceAssignments, ResourceInfo,
|
||||||
},
|
},
|
||||||
renderer::RenderContext,
|
renderer::RenderContext,
|
||||||
|
@ -17,6 +17,10 @@ use crate::{
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct AssignedMeshesDrawTarget;
|
pub struct AssignedMeshesDrawTarget;
|
||||||
|
|
||||||
|
impl AssignedMeshesDrawTarget {
|
||||||
|
pub const NAME: &'static str = "AssignedMeshes";
|
||||||
|
}
|
||||||
|
|
||||||
impl DrawTarget for AssignedMeshesDrawTarget {
|
impl DrawTarget for AssignedMeshesDrawTarget {
|
||||||
fn draw(
|
fn draw(
|
||||||
&self,
|
&self,
|
||||||
|
@ -129,6 +133,6 @@ impl DrawTarget for AssignedMeshesDrawTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_name(&self) -> String {
|
fn get_name(&self) -> String {
|
||||||
resource_name::draw_target::ASSIGNED_MESHES.to_string()
|
AssignedMeshesDrawTarget::NAME.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
mesh::{self, Mesh},
|
mesh::{self, Mesh},
|
||||||
pass::RenderPass,
|
pass::RenderPass,
|
||||||
pipeline::PipelineDescriptor,
|
pipeline::PipelineDescriptor,
|
||||||
render_resource::{resource_name, ResourceInfo},
|
render_resource::ResourceInfo,
|
||||||
Renderable,
|
Renderable,
|
||||||
};
|
};
|
||||||
use bevy_asset::Handle;
|
use bevy_asset::Handle;
|
||||||
|
@ -12,6 +12,10 @@ use legion::prelude::*;
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct MeshesDrawTarget;
|
pub struct MeshesDrawTarget;
|
||||||
|
|
||||||
|
impl MeshesDrawTarget {
|
||||||
|
pub const NAME: &'static str = "Meshes";
|
||||||
|
}
|
||||||
|
|
||||||
impl DrawTarget for MeshesDrawTarget {
|
impl DrawTarget for MeshesDrawTarget {
|
||||||
fn draw(
|
fn draw(
|
||||||
&self,
|
&self,
|
||||||
|
@ -62,6 +66,6 @@ impl DrawTarget for MeshesDrawTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_name(&self) -> String {
|
fn get_name(&self) -> String {
|
||||||
resource_name::draw_target::MESHES.to_string()
|
MeshesDrawTarget::NAME.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{mesh::Mesh, Camera, Renderable, OrthographicCamera, PerspectiveCamera, render_resource::resource_name};
|
use crate::{mesh::Mesh, Camera, Renderable, OrthographicCamera, PerspectiveCamera, base_render_graph};
|
||||||
use bevy_asset::Handle;
|
use bevy_asset::Handle;
|
||||||
use bevy_derive::EntityArchetype;
|
use bevy_derive::EntityArchetype;
|
||||||
use bevy_transform::components::{LocalToWorld, Rotation, Scale, Translation};
|
use bevy_transform::components::{LocalToWorld, Rotation, Scale, Translation};
|
||||||
|
@ -25,7 +25,7 @@ impl Default for PerspectiveCameraEntity {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
PerspectiveCameraEntity {
|
PerspectiveCameraEntity {
|
||||||
camera: Camera {
|
camera: Camera {
|
||||||
name: Some(resource_name::uniform::CAMERA.to_string()),
|
name: Some(base_render_graph::uniform::CAMERA.to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
perspective_camera: Default::default(),
|
perspective_camera: Default::default(),
|
||||||
|
@ -46,8 +46,7 @@ impl OrthographicCameraEntity {
|
||||||
pub fn ui() -> Self {
|
pub fn ui() -> Self {
|
||||||
OrthographicCameraEntity {
|
OrthographicCameraEntity {
|
||||||
camera: Camera {
|
camera: Camera {
|
||||||
// TODO: ui should have its own uniform
|
name: Some("UiCamera".to_string()),
|
||||||
name: Some(resource_name::uniform::CAMERA2D.to_string()),
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
orthographic_camera: Default::default(),
|
orthographic_camera: Default::default(),
|
||||||
|
@ -60,7 +59,7 @@ impl Default for OrthographicCameraEntity {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
OrthographicCameraEntity {
|
OrthographicCameraEntity {
|
||||||
camera: Camera {
|
camera: Camera {
|
||||||
name: Some(resource_name::uniform::CAMERA2D.to_string()),
|
name: Some(base_render_graph::uniform::CAMERA2D.to_string()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
orthographic_camera: Default::default(),
|
orthographic_camera: Default::default(),
|
||||||
|
|
|
@ -4,7 +4,6 @@ mod entity_render_resource_assignments;
|
||||||
mod render_resource;
|
mod render_resource;
|
||||||
mod render_resource_assignments;
|
mod render_resource_assignments;
|
||||||
mod resource_info;
|
mod resource_info;
|
||||||
pub mod resource_name;
|
|
||||||
|
|
||||||
pub use buffer::*;
|
pub use buffer::*;
|
||||||
pub use entities_waiting_for_assets::*;
|
pub use entities_waiting_for_assets::*;
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
pub mod texture {
|
|
||||||
pub const SWAP_CHAIN: &str = "SwapChain";
|
|
||||||
pub const DEPTH: &str = "Depth";
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod uniform {
|
|
||||||
pub const CAMERA: &str = "Camera";
|
|
||||||
pub const CAMERA2D: &str = "Camera2d";
|
|
||||||
pub const LIGHTS: &str = "Lights";
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod buffer {
|
|
||||||
pub const UI_INSTANCES: &str = "UiInstances";
|
|
||||||
pub const TEMP_MESH_VERTEX_BUFFER_NAME: &str = "TempMeshVertexBuffer";
|
|
||||||
pub const TEMP_MESH_INDEX_BUFFER_NAME: &str = "TempMeshIndexBuffer";
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod draw_target {
|
|
||||||
pub const MESHES: &str = "Meshes";
|
|
||||||
pub const ASSIGNED_MESHES: &str = "AssignedMeshes";
|
|
||||||
pub const ASSIGNED_BATCHES: &str = "AssignedBatches";
|
|
||||||
pub const UI: &str = "Ui";
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod pass {
|
|
||||||
pub const MAIN: &str = "Main";
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod pipeline {
|
|
||||||
pub const FORWARD: &str = "Forward";
|
|
||||||
pub const FORWARD_FLAT: &str = "ForwardFlat";
|
|
||||||
pub const UI: &str = "Ui";
|
|
||||||
}
|
|
|
@ -5,7 +5,7 @@ use bevy_render::{
|
||||||
draw_target::AssignedMeshesDrawTarget,
|
draw_target::AssignedMeshesDrawTarget,
|
||||||
pipeline::{state_descriptors::*, PipelineDescriptor},
|
pipeline::{state_descriptors::*, PipelineDescriptor},
|
||||||
render_graph::{
|
render_graph::{
|
||||||
nodes::{AssetUniformNode, PassNode, UniformNode},
|
nodes::{AssetUniformNode, PassNode, UniformNode, CameraNode},
|
||||||
RenderGraph,
|
RenderGraph,
|
||||||
},
|
},
|
||||||
shader::{Shader, ShaderStage, ShaderStages},
|
shader::{Shader, ShaderStage, ShaderStages},
|
||||||
|
@ -61,6 +61,16 @@ pub fn build_ui_pipeline(shaders: &mut Assets<Shader>) -> PipelineDescriptor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod node {
|
||||||
|
pub const COLOR_MATERIAL: &'static str = "color_material";
|
||||||
|
pub const UI_CAMERA: &'static str = "ui_camera";
|
||||||
|
pub const RECT: &'static str = "rect";
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod uniform {
|
||||||
|
pub const UI_CAMERA: &'static str = "UiCamera";
|
||||||
|
}
|
||||||
|
|
||||||
pub trait UiRenderGraphBuilder {
|
pub trait UiRenderGraphBuilder {
|
||||||
fn add_ui_graph(&mut self, resources: &Resources) -> &mut Self;
|
fn add_ui_graph(&mut self, resources: &Resources) -> &mut Self;
|
||||||
}
|
}
|
||||||
|
@ -68,14 +78,20 @@ pub trait UiRenderGraphBuilder {
|
||||||
impl UiRenderGraphBuilder for RenderGraph {
|
impl UiRenderGraphBuilder for RenderGraph {
|
||||||
fn add_ui_graph(&mut self, resources: &Resources) -> &mut Self {
|
fn add_ui_graph(&mut self, resources: &Resources) -> &mut Self {
|
||||||
self.add_system_node(
|
self.add_system_node(
|
||||||
"color_material",
|
node::COLOR_MATERIAL,
|
||||||
AssetUniformNode::<ColorMaterial>::new(false),
|
AssetUniformNode::<ColorMaterial>::new(false),
|
||||||
);
|
);
|
||||||
self.add_node_edge("color_material", base_render_graph::node::MAIN_PASS)
|
self.add_node_edge(node::COLOR_MATERIAL, base_render_graph::node::MAIN_PASS)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
self.add_system_node("rect", UniformNode::<Rect>::new(false));
|
|
||||||
self.add_node_edge("rect", base_render_graph::node::MAIN_PASS)
|
self.add_system_node(node::UI_CAMERA, CameraNode::new(uniform::UI_CAMERA));
|
||||||
|
self.add_node_edge(node::UI_CAMERA, base_render_graph::node::MAIN_PASS)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
self.add_system_node(node::RECT, UniformNode::<Rect>::new(false));
|
||||||
|
self.add_node_edge(node::RECT, base_render_graph::node::MAIN_PASS)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let mut pipelines = resources.get_mut::<Assets<PipelineDescriptor>>().unwrap();
|
let mut pipelines = resources.get_mut::<Assets<PipelineDescriptor>>().unwrap();
|
||||||
let mut shaders = resources.get_mut::<Assets<Shader>>().unwrap();
|
let mut shaders = resources.get_mut::<Assets<Shader>>().unwrap();
|
||||||
pipelines.set(UI_PIPELINE_HANDLE, build_ui_pipeline(&mut shaders));
|
pipelines.set(UI_PIPELINE_HANDLE, build_ui_pipeline(&mut shaders));
|
||||||
|
|
|
@ -6,7 +6,7 @@ layout(location = 2) in vec2 Vertex_Uv;
|
||||||
|
|
||||||
layout(location = 0) out vec2 v_Uv;
|
layout(location = 0) out vec2 v_Uv;
|
||||||
|
|
||||||
layout(set = 0, binding = 0) uniform Camera2d {
|
layout(set = 0, binding = 0) uniform UiCamera {
|
||||||
mat4 ViewProj;
|
mat4 ViewProj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ fn setup(
|
||||||
let texture_handle = asset_server.load("assets/branding/icon.png").unwrap();
|
let texture_handle = asset_server.load("assets/branding/icon.png").unwrap();
|
||||||
command_buffer
|
command_buffer
|
||||||
.build()
|
.build()
|
||||||
.add_entity(OrthographicCameraEntity::default())
|
.add_entity(OrthographicCameraEntity::ui())
|
||||||
.add_entity(SpriteEntity {
|
.add_entity(SpriteEntity {
|
||||||
rect: Rect {
|
rect: Rect {
|
||||||
position: Vec2::new(300.0, 300.0),
|
position: Vec2::new(300.0, 300.0),
|
||||||
|
|
|
@ -25,7 +25,7 @@ fn setup(command_buffer: &mut CommandBuffer, asset_server: Res<AssetServer>) {
|
||||||
command_buffer
|
command_buffer
|
||||||
.build()
|
.build()
|
||||||
// 2d camera
|
// 2d camera
|
||||||
.add_entity(OrthographicCameraEntity::default())
|
.add_entity(OrthographicCameraEntity::ui())
|
||||||
// texture
|
// texture
|
||||||
.add_entity(LabelEntity {
|
.add_entity(LabelEntity {
|
||||||
node: Node::new(
|
node: Node::new(
|
||||||
|
|
|
@ -57,8 +57,8 @@ fn setup(
|
||||||
// )),
|
// )),
|
||||||
// ..Default::default()
|
// ..Default::default()
|
||||||
// })
|
// })
|
||||||
// 2d camera
|
// ui camera
|
||||||
.add_entity(OrthographicCameraEntity::default())
|
.add_entity(OrthographicCameraEntity::ui())
|
||||||
// left vertical fill
|
// left vertical fill
|
||||||
.add_entity(UiEntity {
|
.add_entity(UiEntity {
|
||||||
node: Node::new(
|
node: Node::new(
|
||||||
|
|
|
@ -23,7 +23,7 @@ fn placement_system(
|
||||||
|
|
||||||
fn setup(command_buffer: &mut CommandBuffer, mut materials: ResMut<Assets<ColorMaterial>>) {
|
fn setup(command_buffer: &mut CommandBuffer, mut materials: ResMut<Assets<ColorMaterial>>) {
|
||||||
let mut builder = command_buffer.build();
|
let mut builder = command_buffer.build();
|
||||||
builder.add_entity(OrthographicCameraEntity::default());
|
builder.add_entity(OrthographicCameraEntity::ui());
|
||||||
|
|
||||||
let mut prev = Vec2::default();
|
let mut prev = Vec2::default();
|
||||||
let count = 1000;
|
let count = 1000;
|
||||||
|
|
|
@ -27,7 +27,6 @@ pub use crate::render::{
|
||||||
},
|
},
|
||||||
RenderGraph,
|
RenderGraph,
|
||||||
},
|
},
|
||||||
render_resource::resource_name,
|
|
||||||
shader::{Shader, ShaderDefSuffixProvider, ShaderStage, ShaderStages},
|
shader::{Shader, ShaderDefSuffixProvider, ShaderStage, ShaderStages},
|
||||||
texture::{Texture, TextureType},
|
texture::{Texture, TextureType},
|
||||||
Camera, OrthographicCamera, PerspectiveCamera, Color, ColorSource, Renderable,
|
Camera, OrthographicCamera, PerspectiveCamera, Color, ColorSource, Renderable,
|
||||||
|
|
Loading…
Reference in a new issue