summaryrefslogtreecommitdiff
path: root/engine/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-05-24 19:18:32 +0200
committerHampusM <hampus@hampusmat.com>2024-05-24 19:18:32 +0200
commit7756fdab0522c52b81f3bc70e2458a3b683f0a20 (patch)
tree9227af67d0c36e81c4864906a8155a050542bd9f /engine/src
parent8af5413b0fd2b06f71098c1230f79b3e6beb037d (diff)
refactor(engine): make PointLight have a position
Diffstat (limited to 'engine/src')
-rw-r--r--engine/src/lighting.rs2
-rw-r--r--engine/src/renderer/opengl.rs22
2 files changed, 12 insertions, 12 deletions
diff --git a/engine/src/lighting.rs b/engine/src/lighting.rs
index 398161f..81dc475 100644
--- a/engine/src/lighting.rs
+++ b/engine/src/lighting.rs
@@ -10,6 +10,7 @@ builder! {
#[non_exhaustive]
pub struct PointLight
{
+ pub position: Vec3<f32>,
pub diffuse: Color<f32>,
pub specular: Color<f32>,
pub attenuation_params: AttenuationParams,
@@ -29,6 +30,7 @@ impl Default for PointLight
fn default() -> Self
{
Self {
+ position: Vec3::default(),
diffuse: Color { red: 0.5, green: 0.5, blue: 0.5 },
specular: Color { red: 1.0, green: 1.0, blue: 1.0 },
attenuation_params: AttenuationParams::default(),
diff --git a/engine/src/renderer/opengl.rs b/engine/src/renderer/opengl.rs
index 3fe3388..8cafe0d 100644
--- a/engine/src/renderer/opengl.rs
+++ b/engine/src/renderer/opengl.rs
@@ -2,6 +2,7 @@
use std::collections::HashMap;
use std::ffi::{c_void, CString};
+use std::ops::Deref;
use std::process::abort;
use cstr::cstr;
@@ -100,7 +101,7 @@ fn render(
Option<MaterialFlags>,
Transform,
)>,
- point_light_query: Query<(PointLight, Transform)>,
+ point_light_query: Query<(PointLight,)>,
directional_lights: Query<(DirectionalLight,)>,
camera_query: Query<(Camera,)>,
window: Single<Window>,
@@ -120,11 +121,9 @@ fn render(
return;
};
- // TODO: Maybe find a way to not clone here? Cloning here is needed since a transform
- // can be in both the object query and the light source query
let point_lights = point_light_query
.iter()
- .map(|(point_light, transform)| ((*point_light).clone(), (*transform).clone()))
+ .map(|(point_light,)| point_light)
.collect::<Vec<_>>();
let directional_lights = directional_lights.iter().collect::<Vec<_>>();
@@ -361,15 +360,16 @@ fn apply_transformation_matrices(
gl_shader_program.set_uniform_matrix_4fv(cstr!("projection"), &projection);
}
-fn apply_light(
+fn apply_light<PointLightHolder>(
material: &Material,
material_flags: &MaterialFlags,
global_light: &GlobalLight,
gl_shader_program: &mut GlShaderProgram,
- point_lights: &[(PointLight, Transform)],
+ point_lights: &[PointLightHolder],
directional_lights: &[&DirectionalLight],
camera: &Camera,
-)
+) where
+ PointLightHolder: Deref<Target = PointLight>,
{
debug_assert!(
point_lights.len() < 64,
@@ -404,19 +404,17 @@ fn apply_light(
directional_lights.len() as i32,
);
- for (point_light_index, (point_light, point_light_transform)) in
- point_lights.iter().enumerate()
- {
+ for (point_light_index, point_light) in point_lights.iter().enumerate() {
gl_shader_program.set_uniform_vec_3fv(
&create_light_uniform_name("point_lights", point_light_index, "position"),
- &point_light_transform.position,
+ &point_light.position,
);
set_light_phong_uniforms(
gl_shader_program,
"point_lights",
point_light_index,
- point_light,
+ &**point_light,
);
set_light_attenuation_uniforms(