Made light attenuation nicer, fixed campfire light offset

This commit is contained in:
Joshua Barretto 2020-08-30 13:24:25 +01:00
parent 2a64a75a0f
commit 4405227ffb
5 changed files with 28 additions and 13 deletions

View File

@ -142,13 +142,13 @@ float lights_at(vec3 wpos, vec3 wnorm, vec3 /*cam_to_frag*/view_dir, vec3 mu, ve
// float strength = attenuation_strength(difference);// pow(attenuation_strength(difference), 0.6);
// // NOTE: This normalizes strength to 1.0 at the center of the point source.
// float strength = 1.0 / (1.0 + distance_2);
float strength = 1.0 / distance_2;
float strength = 1.0 / (1 + distance_2);
// Multiply the vec3 only once
const float PI = 3.1415926535897932384626433832795;
const float PI_2 = 2 * PI;
float square_factor = /*2.0 * PI_2 * *//*2.0 * */L.light_col.a;
vec3 color = /*srgb_to_linear*/L.light_col.rgb;
vec3 color = /*srgb_to_linear*/L.light_col.rgb * vec3(1, 1, 1);
// // Only access the array once
// Shadow S = shadows[i];

View File

@ -21,6 +21,7 @@ use serde::{Deserialize, Serialize};
use specs::{Component, FlaggedStorage};
use specs_idvs::IdvStorage;
use std::{fs::File, io::BufReader};
use vek::*;
make_case_elim!(
body,
@ -505,6 +506,14 @@ impl Body {
Body::QuadrupedLow(_) => 4.5,
}
}
pub fn default_light_offset(&self) -> Vec3<f32> {
// TODO: Make this a manifest
match self {
Body::Object(_) => Vec3::unit_z() * 0.5,
_ => Vec3::unit_z(),
}
}
}
impl Component for Body {

View File

@ -119,16 +119,12 @@ pub fn handle_create_waypoint(server: &mut Server, pos: Vec3<f32>) {
.state
.create_object(Pos(pos), comp::object::Body::CampfireLit)
.with(LightEmitter {
col: Rgb::new(1.0, 0.8, 0.0),
strength: 8.0,
col: Rgb::new(1.0, 0.6, 0.0),
strength: 5.0,
flicker: 1.0,
animated: true,
})
.with(LightAnimation {
offset: Vec3::new(0.0, 0.0, 2.0),
col: Rgb::new(1.0, 0.8, 0.0),
strength: 8.0,
})
.with(WaypointArea::default())
.with(comp::Mass(100000.0))
.build();
}

View File

@ -41,7 +41,7 @@ pub fn handle_lantern(server: &mut Server, entity: EcsEntity) {
.insert(entity, comp::LightEmitter {
col: lantern.color(),
strength: lantern.strength(),
flicker: 1.0,
flicker: 0.35,
animated: true,
});
}

View File

@ -43,6 +43,7 @@ use guillotiere::AtlasAllocator;
use hashbrown::HashMap;
use specs::{Entity as EcsEntity, Join, LazyUpdate, WorldExt};
use treeculler::{BVol, BoundingSphere};
use vek::*;
const DAMAGE_FADE_COEFFICIENT: f64 = 5.0;
const MOVING_THRESHOLD: f32 = 0.7;
@ -363,13 +364,22 @@ impl FigureMgr {
// TODO: Pending review in #587
pub fn update_lighting(&mut self, scene_data: &SceneData) {
let ecs = scene_data.state.ecs();
for (entity, light_emitter) in (&ecs.entities(), &ecs.read_storage::<LightEmitter>()).join()
{
for (
entity,
body,
light_emitter,
) in (
&ecs.entities(),
ecs.read_storage::<common::comp::Body>().maybe(),
&ecs.read_storage::<LightEmitter>(),
).join() {
// Add LightAnimation for objects with a LightEmitter
let mut anim_storage = ecs.write_storage::<LightAnimation>();
if let None = anim_storage.get_mut(entity) {
let anim = LightAnimation {
offset: vek::Vec3::zero(),
offset: body
.map(|b| b.default_light_offset())
.unwrap_or_else(Vec3::zero),
col: light_emitter.col,
strength: 0.0,
};