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

Add frustum to shader View #10306

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -642,6 +643,7 @@ pub fn extract_cameras(
&CameraRenderGraph,
&GlobalTransform,
&VisibleEntities,
&Frustum,
Option<&ColorGrading>,
Option<&TemporalJitter>,
Option<&RenderLayers>,
Expand All @@ -657,6 +659,7 @@ pub fn extract_cameras(
camera_render_graph,
transform,
visible_entities,
frustum,
color_grading,
temporal_jitter,
render_layers,
Expand Down Expand Up @@ -714,6 +717,7 @@ pub fn extract_cameras(
color_grading,
},
visible_entities.clone(),
*frustum,
));

if let Some(temporal_jitter) = temporal_jitter {
Expand Down
19 changes: 18 additions & 1 deletion crates/bevy_render/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -352,6 +354,7 @@ pub fn prepare_view_uniforms(
views: Query<(
Entity,
&ExtractedView,
Option<&Frustum>,
Option<&TemporalJitter>,
Option<&MipBias>,
)>,
Expand All @@ -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;
Expand All @@ -386,6 +389,19 @@ pub fn prepare_view_uniforms(
.unwrap_or_else(|| projection * inverse_view)
};

let frustum = frustum
.map(|frustum| {
[
frustum.half_spaces[0].normal_d(),
frustum.half_spaces[1].normal_d(),
frustum.half_spaces[2].normal_d(),
frustum.half_spaces[3].normal_d(),
frustum.half_spaces[4].normal_d(),
frustum.half_spaces[5].normal_d(),
]
})
JMS55 marked this conversation as resolved.
Show resolved Hide resolved
.unwrap_or([Vec4::ZERO; 6]);

let view_uniforms = ViewUniformOffset {
offset: writer.write(&ViewUniform {
view_proj,
Expand All @@ -397,6 +413,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,
}),
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_render/src/view/view.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};