From f337a6024c59aaff89a78c18641d9644fed75778 Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 16 Mar 2024 23:37:18 +0100 Subject: [PATCH] add directional light, disable ambient light --- src/world.rs | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/src/world.rs b/src/world.rs index 0e526f9..b6edc4f 100644 --- a/src/world.rs +++ b/src/world.rs @@ -3,6 +3,8 @@ use bevy::prelude::*; use bevy::core_pipeline::Skybox; use bevy::asset::LoadState; use bevy::render::render_resource::{TextureViewDescriptor, TextureViewDimension}; +use bevy::pbr::CascadeShadowConfigBuilder; +use std::f32::consts::PI; #[derive(Resource)] pub struct Cubemap { @@ -16,6 +18,7 @@ pub fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, + mut ambient_light: ResMut, asset_server: Res, ) { // Add skybox @@ -37,10 +40,10 @@ pub fn setup( }); // Add spheres - let sphere_radius = 0.25; + let sphere_radius = 1.0; let sphere_handle = meshes.add(Sphere::new(sphere_radius)); let white_handle = materials.add(StandardMaterial { - base_color: Color::WHITE, + base_color: Color::GRAY, perceptual_roughness: 1.0, ..default() }); @@ -54,6 +57,43 @@ pub fn setup( ), ..default() }); + + // Space is DARK + ambient_light.brightness = 0.0; + + // Add Light + commands.spawn(PointLightBundle { + transform: Transform::from_xyz(5.0, 5.0, 0.0), + point_light: PointLight { + intensity: 0.0, + range: 500.0, + color: Color::WHITE, + shadows_enabled: true, + ..default() + }, + ..default() + }); + + commands.spawn(DirectionalLightBundle { + directional_light: DirectionalLight { + illuminance: light_consts::lux::OVERCAST_DAY, + shadows_enabled: true, + ..default() + }, + transform: Transform::from_rotation(Quat::from_euler( + EulerRot::ZYX, + 0.0, + PI / 2., + -PI / 4., + )), + cascade_shadow_config: CascadeShadowConfigBuilder { + first_cascade_far_bound: 7.0, + maximum_distance: 25.0, + ..default() + } + .into(), + ..default() + }); } pub fn load_cubemap_asset(