From dd568a75e33f7f425a227cdd431f4b529f9a6aa1 Mon Sep 17 00:00:00 2001 From: zomseffen Date: Mon, 13 Jan 2025 16:18:05 +0100 Subject: [PATCH] pre facing switch --- shaders/compiled/frag_rt_quad.spv | Bin 11068 -> 23196 bytes shaders/rt_quad.frag | 106 +++++++++++++++++++++++++----- src/scene/empty_volume.rs | 24 +++---- src/scene/light.rs | 8 +-- src/scene/mod.rs | 12 +++- 5 files changed, 117 insertions(+), 33 deletions(-) diff --git a/shaders/compiled/frag_rt_quad.spv b/shaders/compiled/frag_rt_quad.spv index 15b4f814b512aeb94222088c611fa16f462fe90c..16608e1a0c74a7c99e5cd0ccce2329ec41aaa49d 100644 GIT binary patch literal 23196 zcmaKz2b^40*@p*GrT3x)2q0Y)q$3bO2ucS*5OLWgo3N7XhAkmPqz0uI2`yAX>Cy$H zOI1)oQEaHFs3<5Xhy}~{Ja^`wIeW8y^UL|2e>v}a%02hanc2yRMb{qFXe`oLys>2C znGucZwQOTilm^=9s-C##0ef!JKQLvJ&A0e~4VG#&8`@^+#$t_;)Rq~Y-91!|0~c*H zK2AB9avtRgnlD3)ZRiX%f*u-;M@cY}_=$UVOx$OmiF@waF?r_9j{bpTrgwEr@9yd9 zn9|+XHF==abUUQR zDEeQFdRFIj@RE(?!Tp^xX3}j>SNF6dCiV7pOzrEP(a}G-i&1p8-S8)RAX7{zRv!EuD*_$z5UI;mP4Cb`AalbrEc|Ajp_gE$bMF$ z{c!!Pj9%|&6|`nQV;gILr*#dmj?<19a46ja-Mu}{6>yxZ<2SwTo+(|kQN}dZ8WPi9 zGTV<|sQt*sI%urnrc|^T+1Q}THw)jS$v+q_p#A1eKBln)ptG;9^O%k)UHy~$7A&Om z-UaUfm;WQI{?3C_r*`$Bj;eIyy(la%%BaS!)a^^9Hm0!$T62M$J>(+k?SnVaJF~ed zI{Lfkbaf0ORdEL_?9GaI2w+n0zyLd=nYtBf&W>TdSyfK9Z)1Ab)PbQ<&Hj!Y#oT@+l{uU1Sr4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w+a_zM{cbHuy+`Pd50P24C0UmpAxT4Sr37`+pbZ_-|G-@T+3{{`T7j`rUSPKT!-+TwQx zSerTAfAZK~11{S<6Rzf)lkvS4oV?l-dlp!mdELkI*j@)N^Dc#}Eukdu>%qyZJ+Wtl zwVBuRAdl@FaGCcFaJBL~_8Z~Jt39!A0&6p`=Sm*io55w?Zn)Zcl=Sy4;N;bw*dDMp z^Dd{B$JPrj^Y+8l`Y6de08U=*i5&!MGq2}d9@`MO%==cjTDdRJhbOQ0#14bCnb-S5 z9@{9m%sUQO8>6JZ7l4yjdtxWR+RW>{BadwgT;^Q`SDU6J@7uu1t39!+!P?C0{UwiW zEx62k5nSy;O7gxPoV?l-`wp-+^Lh`;W4jn!=6xqz?Gj4zUJ6cL?TNh%tj)aZsO7P} z3tZ;C60UXyC3)WsPG0SaeGgchc`v7y$M#-unfHBgwW}$~`+jipYESG3z}n1v6}3FJ z4}#0QAA+l0OG(}jgOgW#Vy^>hGw(Ij^4LBCo?q~ff)`TqyY^#XebkM=o?0#O9|tck z_$R>2D2e|hSRZxcZ=hC7{7vBH1^*P-GnV*IgKwg!8-F9UTHnZQR*V1bVE1zP9borh;y(k{N8R}K)N1j+3+&zszZ>kHNc?BP`luU!C$(Dq?*-2* z_~*boQtslr;{DVQP}J_D) z{S^=)VB6J}Hh%yv+x#J1 z?L11_d-9xRG_J0DNU+_NzFE03>gUj>x7x0yZ z{V&1g`S>Z^{l1uASx->^jA9$+HJ9hbw!u)6WjQp;oe7qDxV_Wu<;n{po|KK}+*5C3~8G~%%>Zl5-v(!b)ncCo zHc#f@g>W_JE4jCVC%5**ZVlF!+}nWFV&4{A=H3pjwxr0tJv_O!Cw2$0w&b1-R$I(p TMVzM{!H&f?wK 0.0; - bool x_null = light_direction.x == 0.0; + bool x_null = (light_direction.x == 0.0); bool y_pos = light_direction.y > 0.0; - bool y_null = light_direction.y == 0.0; + bool y_null = (light_direction.y == 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); - uint max_iterations = max_light_num * 20; + vec3 color_sum = vec3(0.0, 0.0, 0.0) + (color_sample.xyz * 0.01); + + uint max_iterations = 2; //max_light_num * 20; for (int i = 0; i < max_iterations; i++) { - float x_border = float(scene_info.infos[volume_index + 0] + scene_info.infos[volume_index + 3] * uint(x_pos)); - float y_border = float(scene_info.infos[volume_index + 1] + scene_info.infos[volume_index + 4] * uint(y_pos)); - float z_border = float(scene_info.infos[volume_index + 2] + scene_info.infos[volume_index + 5] * uint(z_pos)); + float x_border = float(volume_pos_x + (scene_info.infos[volume_index + 3]) * uint(x_pos)) - 0.5; + float y_border = float(volume_pos_y + (scene_info.infos[volume_index + 4]) * uint(y_pos)) - 0.5; + float z_border = float(volume_pos_z + (scene_info.infos[volume_index + 5]) * uint(z_pos)) - 0.5; + + bool needs_next_light = false; // 2 is way behind the light position and should result in no collision being detected float x_factor = 2.0; @@ -172,17 +179,84 @@ void main() { x_factor = (x_border - origPosition.x) / light_direction.x; } if (!y_null) { - float y_factor = (y_border - origPosition.y) / light_direction.y; + y_factor = (y_border - origPosition.y) / light_direction.y; } if (!z_null) { - float z_factor = (z_border - origPosition.z) / light_direction.z; + z_factor = (z_border - origPosition.z) / light_direction.z; } - + if ((x_factor >= 0.999 && y_factor >= 0.999 && z_factor >= 0.999)) { + // no hit, add light color result + color_sum += (color_sample.xyz * light_color) / (0.01 * light_direction.length() * light_direction.length() + 1.0); + needs_next_light = true; + } else { + // if there is a border hit before reaching the light + // change to the relevant next volume + // Todo: look into removing ifs from this + uint hit_facing = 0; + uint u = 0; + uint v = 0; + if (x_factor <= y_factor && x_factor <= z_factor) { + if (x_pos) { + hit_facing = 3; + } else { + hit_facing = 2; + } + vec3 intersection_pos = origPosition + x_factor * light_direction; + u = uint(ceil(intersection_pos.y)) - volume_pos_y; + v = uint(ceil(intersection_pos.z)) - volume_pos_z; + } + + if (y_factor <= x_factor && y_factor <= z_factor) { + if (y_pos) { + hit_facing = 5; + } else { + hit_facing = 4; + } + vec3 intersection_pos = origPosition + y_factor * light_direction; + u = uint(ceil(intersection_pos.x)) - volume_pos_x; + v = uint(ceil(intersection_pos.z)) - volume_pos_z; + } + + if (z_factor <= x_factor && z_factor <= y_factor) { + if (y_pos) { + hit_facing = 0; + } else { + hit_facing = 1; + } + vec3 intersection_pos = origPosition + z_factor * light_direction; + u = uint(ceil(intersection_pos.x)) - volume_pos_x; + v = uint(ceil(intersection_pos.y)) - volume_pos_y; + } + uint next_neighbor = sample_neighbor_from_scene_info(volume_index, uvec2(u, v), hit_facing); + uvec4 color_sample = sample_color_from_scene_info(volume_index, uvec2(u, v), hit_facing); + + if (color_sample == uvec4(0, 0, 0, 0)) { + // not a color hit, so check neighbor + if (next_neighbor != 0) { + color_sum = vec3(1.0, 0.0, 0.0); + volume_index = next_neighbor; + uint volume_pos_x = scene_info.infos[volume_index + 0]; + uint volume_pos_y = scene_info.infos[volume_index + 1]; + uint volume_pos_z = scene_info.infos[volume_index + 2]; + } else { + color_sum = vec3(0.0, 0.0, 1.0); + // neightbor miss, shouldn't happen with a light inside of a volume. Might happen with ambient light. For now move on to next light. + needs_next_light = true; + } + } else { + color_sum = vec3(1.0, 0.0, 1.0); + // color hit, move on to next light (may change once transparents are implemnted) + needs_next_light = true; + } + } + if (needs_next_light) { + break; + } } - - outColor = color_sample; + // todo light color memory index does not contain the expected values -> check + outColor = vec4(color_sum, 1.0); /*if (scene_info.infos[1] == 16) { outColor = vec4(0, 1, 0, 1); diff --git a/src/scene/empty_volume.rs b/src/scene/empty_volume.rs index cbe73bb..d6407f6 100644 --- a/src/scene/empty_volume.rs +++ b/src/scene/empty_volume.rs @@ -216,8 +216,8 @@ impl EmptyVolume { bottom_roughness.push(128); } else { - bottom_colors.push(Vector3 { x: 255, y: 255, z: 255 }); - bottom_roughness.push(255); + bottom_colors.push(Vector3 { x: 0, y: 0, z: 0 }); + bottom_roughness.push(0); } } } @@ -242,8 +242,8 @@ impl EmptyVolume { top_roughness.push(128); } else { - top_colors.push(Vector3 { x: 255, y: 255, z: 255 }); - top_roughness.push(255); + top_colors.push(Vector3 { x: 0, y: 0, z: 0 }); + top_roughness.push(0); } } } @@ -269,8 +269,8 @@ impl EmptyVolume { back_roughness.push(128); } else { - back_colors.push(Vector3 { x: 255, y: 255, z: 255 }); - back_roughness.push(255); + back_colors.push(Vector3 { x: 0, y: 0, z: 0 }); + back_roughness.push(0); } } } @@ -296,8 +296,8 @@ impl EmptyVolume { front_roughness.push(128); } else { - front_colors.push(Vector3 { x: 255, y: 255, z: 255 }); - front_roughness.push(255); + front_colors.push(Vector3 { x: 0, y: 0, z: 0 }); + front_roughness.push(0); } } } @@ -323,8 +323,8 @@ impl EmptyVolume { left_roughness.push(128); } else { - left_colors.push(Vector3 { x: 255, y: 255, z: 255 }); - left_roughness.push(255); + left_colors.push(Vector3 { x: 0, y: 0, z: 0 }); + left_roughness.push(0); } } } @@ -350,8 +350,8 @@ impl EmptyVolume { right_roughness.push(128); } else { - right_colors.push(Vector3 { x: 255, y: 255, z: 255 }); - right_roughness.push(255); + right_colors.push(Vector3 { x: 0, y: 0, z: 0 }); + right_roughness.push(0); } } } diff --git a/src/scene/light.rs b/src/scene/light.rs index a83b754..4893dd3 100644 --- a/src/scene/light.rs +++ b/src/scene/light.rs @@ -11,7 +11,7 @@ pub struct PointLight{ impl PointLight { pub fn get_buffer_mem_size(&self) -> u32 { - 4 * 3 + 4 * 3 + 3 + 3 } pub fn insert_into_memory(&self, mut v: Vec) -> Vec { @@ -19,9 +19,9 @@ impl PointLight { 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[self.memory_start + 3] = (self.color.x * 255.0) as u32; + v[self.memory_start + 4] = (self.color.y * 255.0) as u32; + v[self.memory_start + 5] = (self.color.z * 255.0) as u32; v } diff --git a/src/scene/mod.rs b/src/scene/mod.rs index 7d710ff..e241b51 100644 --- a/src/scene/mod.rs +++ b/src/scene/mod.rs @@ -6,7 +6,7 @@ use anyhow::Ok; use vulkanalia::prelude::v1_0::*; use anyhow::Result; -use cgmath::{vec2, vec3}; +use cgmath::{vec2, vec3, Vector3}; use std::cell::RefCell; use std::rc::Rc; @@ -14,6 +14,7 @@ use std::rc::Rc; use crate::app_data; use crate::app_data::AppData; use crate::buffer; +use crate::primitives::rec_cuboid::Cuboid; use crate::vertex; use crate::primitives::cube::Cube; use crate::primitives::drawable::Drawable; @@ -117,6 +118,15 @@ impl Scene { None => {} } } + + let cube = Cuboid { + pos: vec3(11.0, 11.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 {