halfway to raytracing
This commit is contained in:
parent
15a94c2f93
commit
3f4656939c
7 changed files with 222 additions and 42 deletions
src/scene
34
src/scene/light.rs
Normal file
34
src/scene/light.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
use cgmath::{InnerSpace, MetricSpace, Vector3};
|
||||
|
||||
use crate::vertex;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct PointLight{
|
||||
pub pos: vertex::Vec3,
|
||||
pub color: vertex::Vec3,
|
||||
pub memory_start: usize,
|
||||
}
|
||||
|
||||
impl PointLight {
|
||||
pub fn get_buffer_mem_size(&self) -> u32 {
|
||||
4 * 3 + 4 * 3
|
||||
}
|
||||
|
||||
pub fn insert_into_memory(&self, mut v: Vec<u32>) -> Vec<u32> {
|
||||
v[self.memory_start] = self.pos.x as u32;
|
||||
v[self.memory_start + 1] = self.pos.y as u32;
|
||||
v[self.memory_start + 2] = self.pos.z as u32;
|
||||
|
||||
v[self.memory_start + 3] = self.color.x as u32;
|
||||
v[self.memory_start + 4] = self.color.y as u32;
|
||||
v[self.memory_start + 5] = self.color.z as u32;
|
||||
v
|
||||
}
|
||||
|
||||
pub fn weighted_distance(&self, center: Vector3<usize>) -> f32 {
|
||||
let distance = self.pos.distance(vertex::Vec3{x: center.x as f32, y: center.y as f32, z: center.z as f32});
|
||||
let light_intensity = self.color.magnitude();
|
||||
|
||||
light_intensity / distance.powf(2.0)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue