summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/src/lighting.rs3
-rw-r--r--engine/src/renderer/mod.rs30
2 files changed, 19 insertions, 14 deletions
diff --git a/engine/src/lighting.rs b/engine/src/lighting.rs
index c5369db..e0608ef 100644
--- a/engine/src/lighting.rs
+++ b/engine/src/lighting.rs
@@ -1,12 +1,10 @@
use ecs::Component;
use crate::color::Color;
-use crate::vector::Vec3;
#[derive(Debug, Clone, Component)]
pub struct LightSource
{
- pub position: Vec3<f32>,
pub ambient: Color<f32>,
pub diffuse: Color<f32>,
pub specular: Color<f32>,
@@ -17,7 +15,6 @@ impl Default for LightSource
fn default() -> Self
{
Self {
- position: Vec3::default(),
ambient: Color { red: 0.2, green: 0.2, blue: 0.2 },
diffuse: Color { red: 0.5, green: 0.5, blue: 0.5 },
specular: Color { red: 1.0, green: 1.0, blue: 1.0 },
diff --git a/engine/src/renderer/mod.rs b/engine/src/renderer/mod.rs
index afed816..cb7066f 100644
--- a/engine/src/renderer/mod.rs
+++ b/engine/src/renderer/mod.rs
@@ -92,7 +92,7 @@ fn initialize(window: Single<Window>)
fn render(
query: Query<(Mesh, TextureMap, ShaderProgram, Material, Transform)>,
- light_source_query: Query<(LightSource,)>,
+ light_source_query: Query<(LightSource, Transform)>,
camera_query: Query<(Camera,)>,
window: Single<Window>,
mut gl_objects: Local<GlObjects>,
@@ -110,10 +110,7 @@ fn render(
return;
};
- let light_source = light_source_query
- .iter()
- .next()
- .map(|(light_source,)| light_source);
+ let light_source = light_source_query.iter().next();
let GlObjects {
shader_programs: gl_shader_programs,
@@ -134,7 +131,16 @@ fn render(
window.size().expect("Failed to get window size"),
);
- apply_light(&material, shader_program, light_source.as_deref(), &camera);
+ apply_light(
+ &material,
+ shader_program,
+ light_source
+ .as_ref()
+ .map(|(light_source, light_source_transform)| {
+ (&**light_source, &**light_source_transform)
+ }),
+ &camera,
+ );
for texture in &texture_list.list {
let gl_texture = gl_textures
@@ -334,19 +340,21 @@ fn apply_transformation_matrices(
fn apply_light(
material: &Material,
gl_shader_program: &mut GlShaderProgram,
- light_source: Option<&LightSource>,
+ light_source: Option<(&LightSource, &Transform)>,
camera: &Camera,
)
{
gl_shader_program.set_uniform_vec_3fv(
cstr!("light.position"),
- &light_source.map_or_else(Vec3::default, |light_source| light_source.position),
+ &light_source.map_or_else(Vec3::default, |(_, light_source_transform)| {
+ light_source_transform.position
+ }),
);
gl_shader_program.set_uniform_vec_3fv(
cstr!("light.ambient"),
&light_source
- .map_or(Color::WHITE_F32, |light_source| {
+ .map_or(Color::WHITE_F32, |(light_source, _)| {
light_source.ambient.clone()
})
.into(),
@@ -355,7 +363,7 @@ fn apply_light(
gl_shader_program.set_uniform_vec_3fv(
cstr!("light.diffuse"),
&light_source
- .map_or(Color::WHITE_F32, |light_source| {
+ .map_or(Color::WHITE_F32, |(light_source, _)| {
light_source.diffuse.clone()
})
.into(),
@@ -364,7 +372,7 @@ fn apply_light(
gl_shader_program.set_uniform_vec_3fv(
cstr!("light.specular"),
&light_source
- .map_or(Color::WHITE_F32, |light_source| {
+ .map_or(Color::WHITE_F32, |(light_source, _)| {
light_source.specular.clone()
})
.into(),