first implementation, clamp seems to be off?

This commit is contained in:
zomseffen 2025-03-06 18:11:44 +01:00
parent 7a58ba9733
commit b581364f5a
8 changed files with 157 additions and 132 deletions
src/scene

View file

@ -13,7 +13,7 @@ pub enum LightType {
pub trait Light {
fn get_light_type(&self) -> LightType;
fn weighted_distance(&self, pos: Vector3<usize>, size: Vector3<usize>) -> f32;
fn weighted_distance(&self, pos: Vector3<f32>, size: Vector3<f32>) -> f32;
}
pub trait LightSource: Light + Memorizable {}
@ -58,9 +58,9 @@ impl Light for PointLight {
LightType::POINT
}
fn weighted_distance(&self, pos: Vector3<usize>, size: Vector3<usize>) -> f32 {
fn weighted_distance(&self, pos: Vector3<f32>, size: Vector3<f32>) -> f32 {
let low_end = vertex::Vec3{x: pos.x as f32, y: pos.y as f32, z: pos.z as f32};
let high_end = vertex::Vec3{x: (pos.x + size.x) as f32, y: (pos.y + size.y) as f32, z: (pos.z + size.z) as f32};
let high_end = pos + size;
let distance;
if low_end.x <= self.pos.x && self.pos.x <= high_end.x && low_end.y <= self.pos.y && self.pos.y <= high_end.y && low_end.z <= self.pos.z && self.pos.z <= high_end.z {
let diff_low = self.pos - low_end;
@ -152,7 +152,7 @@ impl Light for DirectionalLight {
LightType::DIRECTION
}
fn weighted_distance(&self, pos: Vector3<usize>, size: Vector3<usize>) -> f32 {
fn weighted_distance(&self, pos: Vector3<f32>, size: Vector3<f32>) -> f32 {
let light_intensity = self.color.magnitude();
light_intensity