prior normal check for lights
This commit is contained in:
parent
f3098d8061
commit
e3829a73e4
4 changed files with 80 additions and 8 deletions
|
@ -224,8 +224,8 @@ impl App {
|
||||||
image::create_texture_image_view(&device, &mut data)?;
|
image::create_texture_image_view(&device, &mut data)?;
|
||||||
image::create_texture_sampler(&device, &mut data)?;
|
image::create_texture_sampler(&device, &mut data)?;
|
||||||
|
|
||||||
let cur_pos = generators::generate_test_scene(&mut scene_handler, &mut data)?;
|
//let cur_pos = generators::generate_test_scene(&mut scene_handler, &mut data)?;
|
||||||
//let cur_pos = generators::generate_test_scene2(&mut scene_handler, &mut data, 21, 21,1, 5)?;
|
let cur_pos = generators::generate_test_scene2(&mut scene_handler, &mut data, 31, 31,1, 5)?;
|
||||||
scene_handler.prepare_data(&instance, &device, &mut data)?;
|
scene_handler.prepare_data(&instance, &device, &mut data)?;
|
||||||
|
|
||||||
buffer::create_uniform_buffers(&instance, &device, &mut data)?;
|
buffer::create_uniform_buffers(&instance, &device, &mut data)?;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use cgmath::{ElementWise, Vector3};
|
use cgmath::{ElementWise, InnerSpace, Vector3};
|
||||||
|
|
||||||
use std::cell::{RefCell, Ref};
|
use std::cell::{RefCell, Ref};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -979,6 +979,69 @@ impl EmptyVolume {
|
||||||
pub fn select_lights(&self, lights: LightsIter, light_number: u32, min_light_weight: f32) -> Vec<u32> {
|
pub fn select_lights(&self, lights: LightsIter, light_number: u32, min_light_weight: f32) -> Vec<u32> {
|
||||||
let mut weighted_indices = vec![];
|
let mut weighted_indices = vec![];
|
||||||
for light in lights {
|
for light in lights {
|
||||||
|
let mut has_hitable_side = false;
|
||||||
|
if self.color_bottom.len() > 0 {
|
||||||
|
let center = self.real_position + Vector3{x: self.size_x as f32 * 0.5, y: self.size_y as f32 * 0.5, z: self.size_z as f32 * 0.0 - 0.5} * self.scale;
|
||||||
|
let normal = Vector3 {x: 0.0, y: 0.0, z: 1.0};
|
||||||
|
|
||||||
|
let dir = light.borrow().get_direction(center);
|
||||||
|
if normal.dot(dir) < 0.0 {
|
||||||
|
has_hitable_side = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if self.color_top.len() > 0 {
|
||||||
|
let center = self.real_position + Vector3{x: self.size_x as f32 * 0.5, y: self.size_y as f32 * 0.5, z: self.size_z as f32 * 1.0 - 0.5} * self.scale;
|
||||||
|
let normal = Vector3 {x: 0.0, y: 0.0, z: -1.0};
|
||||||
|
|
||||||
|
let dir = light.borrow().get_direction(center);
|
||||||
|
if normal.dot(dir) < 0.0 {
|
||||||
|
has_hitable_side = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.color_front.len() > 0 {
|
||||||
|
let center = self.real_position + Vector3{x: self.size_x as f32 * 0.5, y: self.size_y as f32 * 0.0 - 0.5, z: self.size_z as f32 * 0.5} * self.scale;
|
||||||
|
let normal = Vector3 {x: 0.0, y: 1.0, z: 0.0};
|
||||||
|
|
||||||
|
let dir = light.borrow().get_direction(center);
|
||||||
|
if normal.dot(dir) < 0.0 {
|
||||||
|
has_hitable_side = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.color_back.len() > 0 {
|
||||||
|
let center = self.real_position + Vector3{x: self.size_x as f32 * 0.5, y: self.size_y as f32 * 1.0 - 0.5, z: self.size_z as f32 * 0.5} * self.scale;
|
||||||
|
let normal = Vector3 {x: 0.0, y: -1.0, z: 0.0};
|
||||||
|
|
||||||
|
let dir = light.borrow().get_direction(center);
|
||||||
|
if normal.dot(dir) < 0.0 {
|
||||||
|
has_hitable_side = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.color_left.len() > 0 {
|
||||||
|
let center = self.real_position + Vector3{x: self.size_x as f32 * 0.0 - 0.5, y: self.size_y as f32 * 0.5, z: self.size_z as f32 * 0.5} * self.scale;
|
||||||
|
let normal = Vector3 {x: 1.0, y: 0.0, z: 0.0};
|
||||||
|
|
||||||
|
let dir = light.borrow().get_direction(center);
|
||||||
|
if normal.dot(dir) < 0.0 {
|
||||||
|
has_hitable_side = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.color_right.len() > 0 {
|
||||||
|
let center = self.real_position + Vector3{x: self.size_x as f32 * 1.0 - 0.5, y: self.size_y as f32 * 0.5, z: self.size_z as f32 * 0.5} * self.scale;
|
||||||
|
let normal = Vector3 {x: -1.0, y: 0.0, z: 0.0};
|
||||||
|
|
||||||
|
let dir = light.borrow().get_direction(center);
|
||||||
|
if normal.dot(dir) < 0.0 {
|
||||||
|
has_hitable_side = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !has_hitable_side {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
let weight = light.borrow().weighted_distance(self.real_position, Vector3{x: self.size_x as f32, y: self.size_y as f32, z: self.size_z as f32} * self.scale);
|
let weight = light.borrow().weighted_distance(self.real_position, Vector3{x: self.size_x as f32, y: self.size_y as f32, z: self.size_z as f32} * self.scale);
|
||||||
if weight >= min_light_weight {
|
if weight >= min_light_weight {
|
||||||
weighted_indices.push((weight, light.borrow().get_memory_start()));
|
weighted_indices.push((weight, light.borrow().get_memory_start()));
|
||||||
|
|
|
@ -58,8 +58,8 @@ pub fn generate_test_scene(scene: &mut Scene, data: &mut AppData) -> Result<(Poi
|
||||||
pos: vec3(10.0, 10.0, 10.0),
|
pos: vec3(10.0, 10.0, 10.0),
|
||||||
color: vec3(0.0, 0.0, 0.9),
|
color: vec3(0.0, 0.0, 0.9),
|
||||||
tex_coord: vec2(0.0, 0.0),
|
tex_coord: vec2(0.0, 0.0),
|
||||||
transparent: true,
|
transparent: false,
|
||||||
roughness: 32,
|
roughness: 128,
|
||||||
};
|
};
|
||||||
oct_tree1.set_cube(cube.clone());
|
oct_tree1.set_cube(cube.clone());
|
||||||
|
|
||||||
|
@ -67,8 +67,8 @@ pub fn generate_test_scene(scene: &mut Scene, data: &mut AppData) -> Result<(Poi
|
||||||
pos: vec3(10.0, 10.0, 9.0),
|
pos: vec3(10.0, 10.0, 9.0),
|
||||||
color: vec3(0.0, 0.0, 0.9),
|
color: vec3(0.0, 0.0, 0.9),
|
||||||
tex_coord: vec2(0.0, 0.0),
|
tex_coord: vec2(0.0, 0.0),
|
||||||
transparent: true,
|
transparent: false,
|
||||||
roughness: 32,
|
roughness: 128,
|
||||||
};
|
};
|
||||||
oct_tree1.set_cube(cube.clone());
|
oct_tree1.set_cube(cube.clone());
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ pub enum LightType {
|
||||||
pub trait Light {
|
pub trait Light {
|
||||||
fn get_light_type(&self) -> LightType;
|
fn get_light_type(&self) -> LightType;
|
||||||
fn weighted_distance(&self, pos: Vector3<f32>, size: Vector3<f32>) -> f32;
|
fn weighted_distance(&self, pos: Vector3<f32>, size: Vector3<f32>) -> f32;
|
||||||
|
fn get_direction(&self, pos: Vector3<f32>) -> Vector3<f32>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait LightSource: Light + Memorizable {}
|
pub trait LightSource: Light + Memorizable {}
|
||||||
|
@ -109,6 +110,10 @@ impl Light for PointLight {
|
||||||
|
|
||||||
light_intensity / distance.powf(2.0)
|
light_intensity / distance.powf(2.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_direction(&self, pos: Vector3<f32>) -> Vector3<f32> {
|
||||||
|
(pos - self.pos).normalize()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LightSource for PointLight {}
|
impl LightSource for PointLight {}
|
||||||
|
@ -157,6 +162,10 @@ impl Light for DirectionalLight {
|
||||||
|
|
||||||
light_intensity
|
light_intensity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_direction(&self, pos: Vector3<f32>) -> Vector3<f32> {
|
||||||
|
self.direction.clone().normalize()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LightSource for DirectionalLight {}
|
impl LightSource for DirectionalLight {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue