adds multilight handling
This commit is contained in:
parent
4c4b8288d5
commit
729fcb8559
4 changed files with 43 additions and 6 deletions
Binary file not shown.
|
@ -149,7 +149,8 @@ void main() {
|
||||||
uint volume_pos_y = scene_info.infos[volume_index + 1];
|
uint volume_pos_y = scene_info.infos[volume_index + 1];
|
||||||
uint volume_pos_z = scene_info.infos[volume_index + 2];
|
uint volume_pos_z = scene_info.infos[volume_index + 2];
|
||||||
|
|
||||||
uint light_index = scene_info.infos[volume_index + 6];
|
// setup light info
|
||||||
|
uint light_index = scene_info.infos[fragVolumeStart + 6 + light_num];
|
||||||
vec3 light_direction = get_light_position(light_index) - origPosition;
|
vec3 light_direction = get_light_position(light_index) - origPosition;
|
||||||
vec3 light_color = get_light_color(light_index);
|
vec3 light_color = get_light_color(light_index);
|
||||||
|
|
||||||
|
@ -162,6 +163,7 @@ void main() {
|
||||||
bool z_pos = light_direction.z > 0.0;
|
bool z_pos = light_direction.z > 0.0;
|
||||||
bool z_null = (light_direction.z == 0.0);
|
bool z_null = (light_direction.z == 0.0);
|
||||||
|
|
||||||
|
// initialize color
|
||||||
vec3 color_sum = vec3(0.0, 0.0, 0.0) + (orig_color_sample.xyz * 0.01);
|
vec3 color_sum = vec3(0.0, 0.0, 0.0) + (orig_color_sample.xyz * 0.01);
|
||||||
|
|
||||||
uint max_iterations = max_light_num * 20;
|
uint max_iterations = max_light_num * 20;
|
||||||
|
@ -188,7 +190,7 @@ void main() {
|
||||||
|
|
||||||
if ((x_factor >= 1.0) && (y_factor >= 1.0) && (z_factor >= 1.0)) {
|
if ((x_factor >= 1.0) && (y_factor >= 1.0) && (z_factor >= 1.0)) {
|
||||||
// no hit, add light color result
|
// no hit, add light color result
|
||||||
color_sum += (orig_color_sample.xyz * light_color) / ((0.01 * light_direction.length() * light_direction.length()) + 1.0);
|
color_sum += (orig_color_sample.xyz * light_color) / ((0.1 * light_direction.length() * light_direction.length()) + 1.0);
|
||||||
needs_next_light = true;
|
needs_next_light = true;
|
||||||
} else {
|
} else {
|
||||||
// if there is a border hit before reaching the light
|
// if there is a border hit before reaching the light
|
||||||
|
@ -249,7 +251,32 @@ void main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (needs_next_light) {
|
if (needs_next_light) {
|
||||||
break;
|
light_num += 1;
|
||||||
|
if (light_num >= max_light_num) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// set up the new light
|
||||||
|
light_index = scene_info.infos[fragVolumeStart + 6 + light_num];
|
||||||
|
if (light_index == 0) {
|
||||||
|
// abort if there is no new light
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
light_direction = get_light_position(light_index) - origPosition;
|
||||||
|
light_color = get_light_color(light_index);
|
||||||
|
|
||||||
|
x_pos = light_direction.x > 0.0;
|
||||||
|
x_null = (light_direction.x == 0.0);
|
||||||
|
|
||||||
|
y_pos = light_direction.y > 0.0;
|
||||||
|
y_null = (light_direction.y == 0.0);
|
||||||
|
|
||||||
|
z_pos = light_direction.z > 0.0;
|
||||||
|
z_null = (light_direction.z == 0.0);
|
||||||
|
// reset volume info
|
||||||
|
volume_index = fragVolumeStart;
|
||||||
|
volume_pos_x = scene_info.infos[volume_index + 0];
|
||||||
|
volume_pos_y = scene_info.infos[volume_index + 1];
|
||||||
|
volume_pos_z = scene_info.infos[volume_index + 2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
outColor = vec4(color_sum, 1.0);
|
outColor = vec4(color_sum, 1.0);
|
||||||
|
|
|
@ -178,7 +178,7 @@ impl App {
|
||||||
let entry = Entry::new(loader).map_err(|b| anyhow!("{}", b))?;
|
let entry = Entry::new(loader).map_err(|b| anyhow!("{}", b))?;
|
||||||
let mut data = app_data::AppData::default();
|
let mut data = app_data::AppData::default();
|
||||||
data.use_geometry_shader = false;
|
data.use_geometry_shader = false;
|
||||||
data.num_lights_per_volume = 1;
|
data.num_lights_per_volume = 2;
|
||||||
let mut scene_handler = scene::Scene::default();
|
let mut scene_handler = scene::Scene::default();
|
||||||
|
|
||||||
//load_model::load_model(&mut data)?;
|
//load_model::load_model(&mut data)?;
|
||||||
|
|
|
@ -88,7 +88,8 @@ impl Scene {
|
||||||
|
|
||||||
oct_tree.set_cube(cube.clone());
|
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 });
|
self.point_lights.push(PointLight { pos: vec3(11.0, 11.0, 11.0), color: vec3(0.5, 0.5, 0.5), memory_start: 0 });
|
||||||
|
self.point_lights.push(PointLight { pos: vec3(9.0, 9.0, 11.0), color: vec3(0.5, 0.5, 0.5), memory_start: 0 });
|
||||||
|
|
||||||
let mut empty_volumes: Vec<Rc<RefCell<EmptyVolume>>>;
|
let mut empty_volumes: Vec<Rc<RefCell<EmptyVolume>>>;
|
||||||
(empty_volumes, _) = EmptyVolume::from_oct_tree(&oct_tree);
|
(empty_volumes, _) = EmptyVolume::from_oct_tree(&oct_tree);
|
||||||
|
@ -113,7 +114,7 @@ impl Scene {
|
||||||
else {
|
else {
|
||||||
cube.draw(&data.topology, index, self);
|
cube.draw(&data.topology, index, self);
|
||||||
}*/
|
}*/
|
||||||
cube.draw(&data.topology, index, self);
|
//cube.draw(&data.topology, index, self);
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
@ -128,6 +129,15 @@ impl Scene {
|
||||||
let index = self.sized_vertices.len();
|
let index = self.sized_vertices.len();
|
||||||
cube.draw(&data.topology, index, self);
|
cube.draw(&data.topology, index, self);
|
||||||
|
|
||||||
|
let cube = Cuboid {
|
||||||
|
pos: vec3(9.0, 9.0, 11.0),
|
||||||
|
color: vec3(shade, 1.0, shade),
|
||||||
|
tex_coord: vec2(0.0, 0.0),
|
||||||
|
size: Vector3 {x: 0.5, y: 0.5, z: 0.5}
|
||||||
|
};
|
||||||
|
let index = self.sized_vertices.len();
|
||||||
|
cube.draw(&data.topology, index, self);
|
||||||
|
|
||||||
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)
|
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 {
|
for light in &mut self.point_lights {
|
||||||
light.memory_start = memory_index;
|
light.memory_start = memory_index;
|
||||||
|
|
Loading…
Add table
Reference in a new issue