diff options
author | HampusM <hampus@hampusmat.com> | 2024-04-21 16:03:47 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-04-21 16:03:47 +0200 |
commit | ad67712586cfcfe5236efda93b9e15aefdc9fcf5 (patch) | |
tree | e8395fd4e98cbfcebc6248f0a2b7d1ba68e49838 /engine/src/renderer/mod.rs | |
parent | 4ce4a04992c076ece78f55837764d055429a7197 (diff) |
refactor(engine): remove LightSource position field
Diffstat (limited to 'engine/src/renderer/mod.rs')
-rw-r--r-- | engine/src/renderer/mod.rs | 30 |
1 files changed, 19 insertions, 11 deletions
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(), |