From b8751a73749d7c91feb296cf8b9516097ffc8db7 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Fri, 10 Mar 2023 11:45:01 -0800 Subject: [PATCH] neuter glamor --- Cargo.toml | 2 +- src/camera.rs | 17 ++++++++ src/glamor.rs | 73 +------------------------------- src/lights.rs | 112 ++++---------------------------------------------- src/main.rs | 14 ++++--- src/planet.rs | 8 ++-- 6 files changed, 42 insertions(+), 184 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 60fd637..430899b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ features = [ "bevy_ui", "bevy_text", "bevy_gltf", - "bevy_sprite" + "bevy_sprite", ] [dependencies.bevy_rapier3d] diff --git a/src/camera.rs b/src/camera.rs index 7ac4da6..1e23e2d 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -43,15 +43,32 @@ fn setup_cybercams(mut commands: Commands) { fov: std::f32::consts::FRAC_PI_3, ..Default::default() }; + + let fog_settings = FogSettings { + color: Color::rgba(0.1, 0.2, 0.4, 1.0), + directional_light_color: Color::rgba(1.0, 0.95, 0.75, 0.5), + directional_light_exponent: 30.0, + falloff: FogFalloff::from_visibility_colors( + 350.0, /* distance in world units up to which objects retain visibility (>= 5% + * contrast) */ + Color::rgb(0.35, 0.5, 0.66), /* atmospheric extinction color (after light is lost + * due to absorption by atmospheric particles) */ + Color::rgb(0.8, 0.844, 1.0), /* atmospheric inscattering color (light gained due to + * scattering from the sun) */ + ), + }; + commands .spawn(Camera3dBundle { projection: bevy::render::camera::Projection::Perspective(hero_projection), ..Default::default() }) + .insert(fog_settings.clone()) .insert(CyberCameras::Hero); commands .spawn(Camera3dBundle::default()) + .insert(fog_settings) .insert(CyberCameras::Debug); } diff --git a/src/glamor.rs b/src/glamor.rs index 48acb25..fef9d57 100644 --- a/src/glamor.rs +++ b/src/glamor.rs @@ -1,80 +1,13 @@ -use bevy::{ - prelude::*, - render::mesh::{Indices, VertexAttributeValues}, -}; -// use bevy_polyline::prelude::{Polyline, PolylineBundle, PolylineMaterial, PolylinePlugin}; -use rand::{thread_rng, Rng}; +use bevy::prelude::{App, Color, Plugin}; -use crate::{lights::AnimateCyberLightWireframe, planet::CyberPlanet}; +// use crate::planet::CyberPlanet; pub const BISEXY_COLOR: Color = Color::hsla(292.0, 0.9, 0.60, 1.1); -// fn wireframe_planet( -// mut commands: Commands, -// mut meshes: ResMut>, -// mut polylines: ResMut>, -// mut polymats: ResMut>, -// query: Query<&Handle, With>, -// ) { -// let handle = query.single(); -// let mesh = meshes.get_mut(handle).unwrap(); -// let vertices = mesh.attribute(Mesh::ATTRIBUTE_POSITION).unwrap(); - -// let mut pts = Vec::with_capacity(vertices.len()); - -// if let VertexAttributeValues::Float32x3(verts) = vertices { -// let indices = mesh.indices().unwrap(); -// if let Indices::U32(indices) = indices { -// for i in indices.iter() { -// let v = verts[*i as usize]; -// let v = Vec3::from_slice(&v); -// pts.push(v); -// } -// } -// } - -// let mut verts = Vec::with_capacity((pts.len() as f32 * 1.4) as usize); -// for pts in pts.chunks(3) { -// if pts.len() > 1 { -// verts.extend_from_slice(pts); -// verts.push(Vec3::NAN); -// } -// } - -// // don't need the indices anymore -// mesh.duplicate_vertices(); -// mesh.compute_flat_normals(); - -// commands.spawn(PolylineBundle { -// polyline: polylines.add(Polyline { vertices: verts }), -// material: polymats.add(PolylineMaterial { -// width: 101.0, -// color: BISEXY_COLOR, -// perspective: true, -// depth_bias: -0.001, -// }), -// ..Default::default() -// }); -// } - -fn wireframify_lights(mut lights: Query<&mut AnimateCyberLightWireframe>) { - let chance = 0.005; - - let rng = &mut thread_rng(); - - for mut light in lights.iter_mut() { - if rng.gen::() < chance { - let new = !light.wired; - light.wired = new; - } - } -} - // public plugin pub struct CyberGlamorPlugin; impl Plugin for CyberGlamorPlugin { fn build(&self, app: &mut App) { - #[cfg(feature = "inspector")] { use bevy_rapier3d::render::{ DebugRenderMode, DebugRenderStyle, RapierDebugRenderPlugin, @@ -97,7 +30,5 @@ impl Plugin for CyberGlamorPlugin { app.add_plugin(rplugin); } - - app.add_system(wireframify_lights); } } diff --git a/src/lights.rs b/src/lights.rs index fe29d44..031514c 100644 --- a/src/lights.rs +++ b/src/lights.rs @@ -1,99 +1,9 @@ -use std::f32::consts::TAU; - -use bevy::prelude::*; -use rand::prelude::*; +use bevy::{pbr::CascadeShadowConfigBuilder, prelude::*}; use crate::planet::PLANET_RADIUS; pub const LIGHT_RANGE: f32 = 90.0; -#[derive(Component)] -struct AnimatedCyberLight { - axis: Vec3, - rate: f32, -} - -#[derive(Component, Default)] -pub(crate) struct AnimateCyberLightWireframe { - pub wired: bool, -} - -fn spawn_moving_lights( - mut commands: Commands, - mut meshes: ResMut>, - mut materials: ResMut>, -) { - let rng = &mut thread_rng(); - // spawn orbiting bisexual lights - for _ in 0..655 { - // mechanics - let axis = crate::random_unit_vec(rng); - let angle = rng.gen_range(0.0..TAU); - let rate: f32 = rng.gen_range(7.0..10.0); - let rate = rate.to_radians(); - let rotation = Quat::from_axis_angle(axis, angle); - let altitude = PLANET_RADIUS + rng.gen_range(8.0..20.0); - let perp = axis.any_orthonormal_vector(); - let translation = perp * altitude; - let transform = Transform::from_translation(translation); - - // optics - let hue = rng.gen_range(240.0..300.0); - let saturation = rng.gen_range(0.85..0.99); - let lightness = rng.gen_range(0.3..0.7); - let color = Color::hsl(hue, saturation, lightness); - let intensity = rng.gen_range(900.0..1300.0); - let radius = rng.gen::() * 2.2; // why can't this infer the gen type? - let point_light = PointLight { - intensity, - range: LIGHT_RANGE, - color, - radius: radius - 0.1, - shadows_enabled: true, - ..Default::default() - }; - - let sbundle = SpatialBundle { - transform: Transform::from_rotation(rotation), - ..Default::default() - }; - commands - // first, spawn an entity with a transform we can rotate - .spawn((AnimatedCyberLight { axis, rate },)) - .insert(sbundle) - .with_children(|parent| { - parent - // now spawn a child entity with a pointlight, and a relative transform that's - // just translation from the parent - .spawn(PointLightBundle { - transform, - point_light, - ..Default::default() - }) - .with_children(|builder| { - builder - // now a simple mesh to show a wireframe. - .spawn(PbrBundle { - mesh: meshes.add( - Mesh::try_from(shape::Icosphere { - radius, - subdivisions: 1, - }) - .unwrap(), - ), - material: materials.add(StandardMaterial { - base_color: Color::hsla(272.0, 0.7, 0.56, 0.7), - emissive: color, - ..Default::default() - }), - ..Default::default() - }) - .insert(AnimateCyberLightWireframe::default()); - }); // mesh child - }); // light child - } -} - fn spawn_static_lights( mut commands: Commands, mut meshes: ResMut>, @@ -122,6 +32,13 @@ fn spawn_static_lights( brightness: 0.2, }); + let _cascade_shadow_config = CascadeShadowConfigBuilder { + first_cascade_far_bound: 0.3, + maximum_distance: 3.0, + ..default() + } + .build(); + // up light commands .spawn(PointLightBundle { @@ -172,20 +89,9 @@ fn spawn_static_lights( }); } -fn orbit_lights(time: Res