Skip to content

[pbr] Create a DirectionalLightBundle #2367

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

Closed
Closed
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
16 changes: 14 additions & 2 deletions crates/bevy_pbr/src/entity.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crate::{light::PointLight, material::StandardMaterial, render_graph::PBR_PIPELINE_HANDLE};
use crate::{
light::{DirectionalLight, PointLight},
material::StandardMaterial,
render_graph::PBR_PIPELINE_HANDLE,
};
use bevy_asset::Handle;
use bevy_ecs::bundle::Bundle;
use bevy_render::{
Expand Down Expand Up @@ -40,10 +44,18 @@ impl Default for PbrBundle {
}
}

/// A component bundle for "light" entities
/// A component bundle for "point light" entities
#[derive(Debug, Bundle, Default)]
pub struct PointLightBundle {
pub point_light: PointLight,
pub transform: Transform,
pub global_transform: GlobalTransform,
}

/// A component bundle for "directional light" entities
#[derive(Debug, Bundle, Default)]
pub struct DirectionalLightBundle {
pub directional_light: DirectionalLight,
pub transform: Transform,
pub global_transform: GlobalTransform,
}
1 change: 1 addition & 0 deletions crates/bevy_pbr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl Plugin for PbrPlugin {
fn build(&self, app: &mut AppBuilder) {
app.add_asset::<StandardMaterial>()
.register_type::<PointLight>()
.register_type::<DirectionalLight>()
.add_system_to_stage(
CoreStage::PostUpdate,
shader::asset_shader_defs_system::<StandardMaterial>.system(),
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_pbr/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl Default for DirectionalLight {
fn default() -> Self {
DirectionalLight {
color: Color::rgb(1.0, 1.0, 1.0),
illuminance: 100000.0,
illuminance: 100_000.0,
direction: Vec3::new(0.0, -1.0, 0.0),
}
}
Expand Down
8 changes: 6 additions & 2 deletions examples/3d/3d_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ fn setup(
..Default::default()
});
// light
commands.spawn_bundle(PointLightBundle {
transform: Transform::from_xyz(4.0, 8.0, 4.0),
let transform = Transform::from_xyz(4.0, 8.0, 4.0).looking_at(Vec3::ZERO, Vec3::Y);
let directional_light = DirectionalLight::new(Color::WHITE, 10_000.0, transform.forward());

commands.spawn_bundle(DirectionalLightBundle {
directional_light,
transform,
..Default::default()
});
// camera
Expand Down