mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 04:33:37 +00:00
Add frustum to shader View (#10306)
# Objective - Work towards GPU-driven culling (https://github.com/bevyengine/bevy/pull/10164) ## Solution - Pass the view frustum to the shader view uniform --- ## Changelog - View Frustums are now extracted to the render world and made available to shaders
This commit is contained in:
parent
d3e41e2ff7
commit
3628e09045
3 changed files with 15 additions and 1 deletions
|
@ -2,6 +2,7 @@ use crate::{
|
|||
camera::CameraProjection,
|
||||
camera::{ManualTextureViewHandle, ManualTextureViews},
|
||||
prelude::Image,
|
||||
primitives::Frustum,
|
||||
render_asset::RenderAssets,
|
||||
render_resource::TextureView,
|
||||
view::{ColorGrading, ExtractedView, ExtractedWindows, RenderLayers, VisibleEntities},
|
||||
|
@ -642,6 +643,7 @@ pub fn extract_cameras(
|
|||
&CameraRenderGraph,
|
||||
&GlobalTransform,
|
||||
&VisibleEntities,
|
||||
&Frustum,
|
||||
Option<&ColorGrading>,
|
||||
Option<&TemporalJitter>,
|
||||
Option<&RenderLayers>,
|
||||
|
@ -657,6 +659,7 @@ pub fn extract_cameras(
|
|||
camera_render_graph,
|
||||
transform,
|
||||
visible_entities,
|
||||
frustum,
|
||||
color_grading,
|
||||
temporal_jitter,
|
||||
render_layers,
|
||||
|
@ -714,6 +717,7 @@ pub fn extract_cameras(
|
|||
color_grading,
|
||||
},
|
||||
visible_entities.clone(),
|
||||
*frustum,
|
||||
));
|
||||
|
||||
if let Some(temporal_jitter) = temporal_jitter {
|
||||
|
|
|
@ -9,6 +9,7 @@ use crate::{
|
|||
camera::{ExtractedCamera, ManualTextureViews, MipBias, TemporalJitter},
|
||||
extract_resource::{ExtractResource, ExtractResourcePlugin},
|
||||
prelude::{Image, Shader},
|
||||
primitives::Frustum,
|
||||
render_asset::RenderAssets,
|
||||
render_phase::ViewRangefinder3d,
|
||||
render_resource::{DynamicUniformBuffer, ShaderType, Texture, TextureView},
|
||||
|
@ -168,6 +169,7 @@ pub struct ViewUniform {
|
|||
world_position: Vec3,
|
||||
// viewport(x_origin, y_origin, width, height)
|
||||
viewport: Vec4,
|
||||
frustum: [Vec4; 6],
|
||||
color_grading: ColorGrading,
|
||||
mip_bias: f32,
|
||||
}
|
||||
|
@ -352,6 +354,7 @@ pub fn prepare_view_uniforms(
|
|||
views: Query<(
|
||||
Entity,
|
||||
&ExtractedView,
|
||||
Option<&Frustum>,
|
||||
Option<&TemporalJitter>,
|
||||
Option<&MipBias>,
|
||||
)>,
|
||||
|
@ -365,7 +368,7 @@ pub fn prepare_view_uniforms(
|
|||
else {
|
||||
return;
|
||||
};
|
||||
for (entity, camera, temporal_jitter, mip_bias) in &views {
|
||||
for (entity, camera, frustum, temporal_jitter, mip_bias) in &views {
|
||||
let viewport = camera.viewport.as_vec4();
|
||||
let unjittered_projection = camera.projection;
|
||||
let mut projection = unjittered_projection;
|
||||
|
@ -386,6 +389,11 @@ pub fn prepare_view_uniforms(
|
|||
.unwrap_or_else(|| projection * inverse_view)
|
||||
};
|
||||
|
||||
// Map Frustum type to shader array<vec4<f32>, 6>
|
||||
let frustum = frustum
|
||||
.map(|frustum| frustum.half_spaces.map(|h| h.normal_d()))
|
||||
.unwrap_or([Vec4::ZERO; 6]);
|
||||
|
||||
let view_uniforms = ViewUniformOffset {
|
||||
offset: writer.write(&ViewUniform {
|
||||
view_proj,
|
||||
|
@ -397,6 +405,7 @@ pub fn prepare_view_uniforms(
|
|||
inverse_projection,
|
||||
world_position: camera.transform.translation(),
|
||||
viewport,
|
||||
frustum,
|
||||
color_grading: camera.color_grading,
|
||||
mip_bias: mip_bias.unwrap_or(&MipBias(0.0)).0,
|
||||
}),
|
||||
|
|
|
@ -18,6 +18,7 @@ struct View {
|
|||
world_position: vec3<f32>,
|
||||
// viewport(x_origin, y_origin, width, height)
|
||||
viewport: vec4<f32>,
|
||||
frustum: array<vec4<f32>, 6>,
|
||||
color_grading: ColorGrading,
|
||||
mip_bias: f32,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue