Skip to content

Commit

Permalink
Dynamic shadow config in example
Browse files Browse the repository at this point in the history
  • Loading branch information
JMS55 committed May 29, 2024
1 parent 4557879 commit c746a5f
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions examples/3d/meshlet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod camera_controller;
use bevy::{
pbr::{
experimental::meshlet::{MaterialMeshletMeshBundle, MeshletPlugin},
CascadeShadowConfigBuilder, DirectionalLightShadowMap,
CascadeShadowConfig, CascadeShadowConfigBuilder, DirectionalLightShadowMap,
},
prelude::*,
render::render_resource::AsBindGroup,
Expand All @@ -29,6 +29,7 @@ fn main() {
CameraControllerPlugin,
))
.add_systems(Startup, setup)
.add_systems(Update, set_shadow_map_config)
.run();
}

Expand Down Expand Up @@ -59,12 +60,6 @@ fn setup(
shadows_enabled: true,
..default()
},
cascade_shadow_config: CascadeShadowConfigBuilder {
num_cascades: 1,
maximum_distance: 10.0,
..default()
}
.build(),
transform: Transform::from_rotation(Quat::from_euler(
EulerRot::ZYX,
0.0,
Expand Down Expand Up @@ -121,6 +116,20 @@ fn setup(
});
}

fn set_shadow_map_config(
mut shadow_confg: Query<&mut CascadeShadowConfig>,
camera: Query<&Transform, With<Camera3d>>,
) {
let camera_transform = camera.get_single().unwrap();
let mut shadow_config = shadow_confg.get_single_mut().unwrap();
*shadow_config = CascadeShadowConfigBuilder {
num_cascades: 1,
maximum_distance: camera_transform.translation.y + 3.0,
..default()
}
.build();
}

#[derive(Asset, TypePath, AsBindGroup, Clone, Default)]
struct MeshletDebugMaterial {
_dummy: (),
Expand Down

0 comments on commit c746a5f

Please sign in to comment.