From 4c26f2ef4f2e9790160acec1824a27a0af14c8bb Mon Sep 17 00:00:00 2001 From: hut Date: Wed, 24 Apr 2024 19:54:37 +0200 Subject: [PATCH] implement shadows, tweak world objects for better visibility --- src/camera.rs | 14 ++++++++------ src/commands.rs | 15 ++++++++++++++- src/data/defs.txt | 26 +++++++++++++++++++++++--- src/var.rs | 4 ++++ 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 0b9cb83..99943d1 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -17,7 +17,7 @@ use bevy::input::mouse::{MouseMotion, MouseWheel}; use bevy::window::PrimaryWindow; use bevy::core_pipeline::bloom::{BloomCompositeMode, BloomSettings}; use bevy::core_pipeline::tonemapping::Tonemapping; -use bevy::pbr::CascadeShadowConfigBuilder; +use bevy::pbr::{CascadeShadowConfigBuilder, DirectionalLightShadowMap}; use bevy::transform::TransformSystem; use bevy::math::{DVec3, DQuat}; use bevy_xpbd_3d::prelude::*; @@ -43,6 +43,7 @@ impl Plugin for CameraPlugin { .after(PhysicsSet::Sync) .before(TransformSystem::TransformPropagate)); app.insert_resource(MapCam::default()); + //app.insert_resource(DirectionalLightShadowMap { size: 4096 }); } } @@ -80,6 +81,7 @@ impl Default for MapCam { pub fn setup_camera( mut commands: Commands, + settings: Res, ) { // Add player commands.spawn(( @@ -103,16 +105,16 @@ pub fn setup_camera( commands.spawn(DirectionalLightBundle { directional_light: DirectionalLight { illuminance: 3000.0, - shadows_enabled: false, + shadows_enabled: settings.shadows_sun, ..default() }, transform: Transform::from_rotation(Quat::from_rotation_y(PI/2.0)), cascade_shadow_config: CascadeShadowConfigBuilder { - first_cascade_far_bound: 7.0, - maximum_distance: 25.0, + num_cascades: 4, + minimum_distance: 0.001, + maximum_distance: 250000.0, ..default() - } - .into(), + }.into(), ..default() }); } diff --git a/src/commands.rs b/src/commands.rs index 4762a8d..aa076f3 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -14,7 +14,8 @@ extern crate regex; use bevy::prelude::*; use bevy_xpbd_3d::prelude::*; use bevy::math::DVec3; -use crate::{actor, camera, chat, hud, nature, shading, skeleton, world}; +use bevy::pbr::{NotShadowCaster, NotShadowReceiver}; +use crate::{actor, camera, chat, hud, nature, shading, skeleton, var, world}; use regex::Regex; use std::f32::consts::PI; use std::f64::consts::PI as PI64; @@ -484,6 +485,7 @@ fn spawn_entities( mut materials: ResMut>, mut materials_jupiter: ResMut>, mut id2pos: ResMut, + settings: Res, ) { for state_wrapper in er_spawn.read() { let state = &state_wrapper.0; @@ -591,6 +593,10 @@ fn spawn_entities( unlit: true, ..default() })); + actor.insert(( + NotShadowCaster, + NotShadowReceiver, + )); } if state.is_targeted_on_startup { actor.insert(hud::IsTargeted); @@ -634,6 +640,7 @@ fn spawn_entities( intensity: state.light_brightness, color, range: 2000.0, + shadows_enabled: settings.shadows_pointlights, ..default() }, bevy::pbr::CubemapVisibleEntities::default(), @@ -688,6 +695,8 @@ fn spawn_entities( visibility: Visibility::Hidden, ..default() }, + NotShadowCaster, + NotShadowReceiver, )); skeleton::load(ar_asset_name, &mut entitycmd, &*asset_server); } @@ -701,6 +710,8 @@ fn spawn_entities( visibility: Visibility::Hidden, ..default() }, + NotShadowCaster, + NotShadowReceiver, )); skeleton::load("point_of_interest", &mut entitycmd, &*asset_server); } @@ -721,6 +732,8 @@ fn spawn_entities( Position::new(relative_pos), Rotation::from(Quat::IDENTITY), //Rotation::from(Quat::from_rotation_x(-0.3f32.to_radians())), + NotShadowCaster, + NotShadowReceiver, )); } } diff --git a/src/data/defs.txt b/src/data/defs.txt index 87646fd..65d7f9e 100644 --- a/src/data/defs.txt +++ b/src/data/defs.txt @@ -246,7 +246,7 @@ actor 0 0 0 moonlet scale 83.5e3 angularmomentum 0 0.025 0 -actor 3000 0 0 moonlet +actor 3000 0 -300 moonlet name Moonlet collider mesh relativeto player @@ -335,7 +335,7 @@ actor -3300 10 0 pizzeria density 500 angularmomentum 0 0 0.2 pointofinterest yes - actor -30 100 -23 pizzasign + actor 60 60 -23 pizzasign name "Pizzeria Sign" relativeto pizzeria scale 20 @@ -382,7 +382,7 @@ actor -3300 10 0 pizzeria angularmomentum 0 0 0 pronoun he -actor 60 -15 -40 suitv2 +actor 30 -12 -20 suitv2 relativeto player name Icarus id Icarus @@ -398,6 +398,26 @@ actor 60 -15 -40 suitv2 wants maxrotation 0.5 wants maxvelocity 0 pronoun it + actor 12 -35 -27 lightorb + name "Light Orb 1" + relativeto Icarus + scale 0.25 + light FF8F4A 5000000 + actor -2 -11 -9 lightorb + name "Light Orb 2" + relativeto Icarus + scale 0.25 + light FF8F4A 5000000 + actor 26 -39 4 lightorb + name "Light Orb 3" + relativeto Icarus + scale 0.25 + light FF8F4A 5000000 + actor 1.8 -15.5 16 lightorb + name "Light Orb 4" + relativeto Icarus + scale 0.25 + light FF8F4A 5000000 actor -300 0 40 suitv2 relativeto player diff --git a/src/var.rs b/src/var.rs index ded8b65..6114ad1 100644 --- a/src/var.rs +++ b/src/var.rs @@ -58,6 +58,8 @@ pub struct Settings { pub is_zooming: bool, pub third_person: bool, pub rotation_stabilizer_active: bool, + pub shadows_sun: bool, + pub shadows_pointlights: bool, pub key_selectobject: MouseButton, pub key_zoom: MouseButton, pub key_map: KeyCode, @@ -168,6 +170,8 @@ impl Default for Settings { is_zooming: false, third_person: false, rotation_stabilizer_active: true, + shadows_sun: true, + shadows_pointlights: false, key_selectobject: MouseButton::Left, key_zoom: MouseButton::Right, key_map: KeyCode::KeyM,