diff --git a/shaders/compiled/frag_rt_quad.spv b/shaders/compiled/frag_rt_quad.spv index eafd9b9..32ca9f0 100644 Binary files a/shaders/compiled/frag_rt_quad.spv and b/shaders/compiled/frag_rt_quad.spv differ diff --git a/shaders/rt_quad.frag b/shaders/rt_quad.frag index f47bd82..b6ce9aa 100644 --- a/shaders/rt_quad.frag +++ b/shaders/rt_quad.frag @@ -149,7 +149,8 @@ void main() { uint volume_pos_y = scene_info.infos[volume_index + 1]; 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_color = get_light_color(light_index); @@ -162,6 +163,7 @@ void main() { bool z_pos = 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); 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)) { // 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; } else { // if there is a border hit before reaching the light @@ -249,7 +251,32 @@ void main() { } } 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); diff --git a/src/main.rs b/src/main.rs index 9674aea..5c6dc6b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -178,7 +178,7 @@ impl App { let entry = Entry::new(loader).map_err(|b| anyhow!("{}", b))?; let mut data = app_data::AppData::default(); data.use_geometry_shader = false; - data.num_lights_per_volume = 1; + data.num_lights_per_volume = 2; let mut scene_handler = scene::Scene::default(); //load_model::load_model(&mut data)?; diff --git a/src/scene/mod.rs b/src/scene/mod.rs index 61609bd..2006ece 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -88,7 +88,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 }); + 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>>; (empty_volumes, _) = EmptyVolume::from_oct_tree(&oct_tree); @@ -113,7 +114,7 @@ impl Scene { else { cube.draw(&data.topology, index, self); }*/ - cube.draw(&data.topology, index, self); + //cube.draw(&data.topology, index, self); } None => {} } @@ -127,6 +128,15 @@ impl Scene { }; let index = self.sized_vertices.len(); 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) for light in &mut self.point_lights {