use crate::runner::{SUN_NAME, lookup_named};
use nightshade::prelude::*;
pub fn point_light(world: &mut World, position: Vec3, color: [f32; 3], intensity: f32) -> Entity {
let entity = spawn_light_entity(world, position, "api::light::point");
world.core.set_light(
entity,
Light {
light_type: LightType::Point,
color: Vec3::new(color[0], color[1], color[2]),
intensity,
range: 30.0,
cast_shadows: false,
shadow_bias: 0.007,
..Default::default()
},
);
entity
}
pub fn spot_light(
world: &mut World,
position: Vec3,
target: Vec3,
color: [f32; 3],
intensity: f32,
) -> Entity {
let entity = spawn_light_entity(world, position, "api::light::spot");
if let Some(transform) = mutate_local_transform(world, entity) {
transform.rotation = camera_look_rotation(position, target, 0.0);
}
world.core.set_light(
entity,
Light {
light_type: LightType::Spot,
color: Vec3::new(color[0], color[1], color[2]),
intensity,
range: 50.0,
inner_cone_angle: 0.3,
outer_cone_angle: 0.5,
cast_shadows: true,
shadow_bias: 0.0001,
..Default::default()
},
);
entity
}
pub fn set_sun(world: &mut World, color: [f32; 3], intensity: f32) {
if let Some(sun) = lookup_named(world, SUN_NAME)
&& let Some(light) = world.core.get_light_mut(sun)
{
light.color = Vec3::new(color[0], color[1], color[2]);
light.intensity = intensity;
}
}