halfway to raytracing
This commit is contained in:
parent
15a94c2f93
commit
3f4656939c
7 changed files with 222 additions and 42 deletions
src/scene
|
@ -1,5 +1,6 @@
|
|||
mod oct_tree;
|
||||
mod empty_volume;
|
||||
mod light;
|
||||
|
||||
use anyhow::Ok;
|
||||
use vulkanalia::prelude::v1_0::*;
|
||||
|
@ -10,6 +11,7 @@ use cgmath::{vec2, vec3};
|
|||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::app_data;
|
||||
use crate::app_data::AppData;
|
||||
use crate::buffer;
|
||||
use crate::vertex;
|
||||
|
@ -17,6 +19,7 @@ use crate::primitives::cube::Cube;
|
|||
use crate::primitives::drawable::Drawable;
|
||||
use crate::scene::oct_tree::{OctTree, OctTreeIter, CHUNK_SIZE};
|
||||
use crate::scene::empty_volume::EmptyVolume;
|
||||
use crate::scene::light::PointLight;
|
||||
|
||||
extern crate rand;
|
||||
use rand::Rng;
|
||||
|
@ -50,6 +53,8 @@ pub struct Scene {
|
|||
pub index_buffer_memory_quad: vk::DeviceMemory,
|
||||
|
||||
pub rt_memory: Vec<u32>,
|
||||
|
||||
pub point_lights: Vec<PointLight>,
|
||||
}
|
||||
|
||||
impl Scene {
|
||||
|
@ -82,6 +87,8 @@ impl Scene {
|
|||
|
||||
oct_tree.set_cube(cube.clone());
|
||||
|
||||
self.point_lights.push(PointLight { pos: vec3(11.0, 11.0, 11.0), color: vec3(1.0, 1.0, 1.0), memory_start: 0 });
|
||||
|
||||
let mut empty_volumes: Vec<Rc<RefCell<EmptyVolume>>>;
|
||||
(empty_volumes, _) = EmptyVolume::from_oct_tree(&oct_tree);
|
||||
println!("number of empty volumes is {}", empty_volumes.len());
|
||||
|
@ -112,9 +119,14 @@ impl Scene {
|
|||
}
|
||||
|
||||
let mut memory_index = 1; // zero should be the location for the overall length (also will be the invalid memory allocation for pointing to a nonexistant neighbor)
|
||||
for light in &mut self.point_lights {
|
||||
light.memory_start = memory_index;
|
||||
memory_index += light.get_buffer_mem_size() as usize;
|
||||
}
|
||||
|
||||
for volume in &empty_volumes {
|
||||
volume.borrow_mut().memory_start = memory_index;
|
||||
memory_index += volume.borrow().get_buffer_mem_size() as usize;
|
||||
memory_index += volume.borrow().get_buffer_mem_size(data.num_lights_per_volume) as usize;
|
||||
|
||||
}
|
||||
for volume in &empty_volumes {
|
||||
|
@ -124,18 +136,15 @@ impl Scene {
|
|||
}
|
||||
}
|
||||
println!("Memory size is {} kB, max indes is {}", memory_index * 32 / 8 /1024 + 1, memory_index);
|
||||
let mut volume_vec = vec![memory_index as u32; memory_index];
|
||||
let mut volume_vec = vec![data.num_lights_per_volume; memory_index];
|
||||
for volume in &empty_volumes {
|
||||
volume_vec = volume.borrow().insert_into_memory(volume_vec);
|
||||
volume_vec = volume.borrow().insert_into_memory(volume_vec, data.num_lights_per_volume, &self.point_lights);
|
||||
}
|
||||
for light in &self.point_lights {
|
||||
volume_vec = light.insert_into_memory(volume_vec);
|
||||
}
|
||||
println!("volume_vec print {:?}", volume_vec);
|
||||
let mut empty_count = 0;
|
||||
for element in &volume_vec {
|
||||
if *element == memory_index as u32 {
|
||||
empty_count += 1;
|
||||
}
|
||||
}
|
||||
println!("empty elements count is {}", empty_count);
|
||||
|
||||
self.rt_memory = volume_vec;
|
||||
data.scene_rt_memory_size = (self.rt_memory.len() * 4) as u64; // size of the needed buffer size in bytes
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue