diff --git a/.vscode/launch.json b/.vscode/launch.json index 4a0a6abf..1b1b9847 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -74,9 +74,9 @@ //"models/cornell_box/cornell_box.scene" //"models/MetalRoughSpheresNoTextures/MetalRoughSpheresNoTextures.scene" //"models/NormalTangent/NormalTangent.scene" - //"models/DamagedHelmet/DamagedHelmet.scene" + "models/DamagedHelmet/DamagedHelmet.scene" //"models/craftman/craftman.scene" - "models/stanford_bunny/stanford_bunny.scene" + //"models/stanford_bunny/stanford_bunny.scene" //"models/bunnies/bunnies.scene" //"models/girl/girl.scene" //"models/suzanne/suzanne.scene" diff --git a/crates/graphics/src/common/global_buffers.rs b/crates/graphics/src/common/global_buffers.rs index 59867983..2c3a1dbb 100644 --- a/crates/graphics/src/common/global_buffers.rs +++ b/crates/graphics/src/common/global_buffers.rs @@ -511,15 +511,15 @@ impl GlobalBuffers { &self, view: Matrix4, proj: Matrix4, + near: f32, + far: f32, screen_size: Vector2, debug_coords: Vector2, ) { inox_profiler::scoped_profile!("render_context::update_constant_data"); self.constant_data.write().unwrap().update( - view, - proj, - screen_size, - debug_coords, + (view, proj, near, far), + (screen_size, debug_coords), self.tlas_start_index .read() .unwrap() diff --git a/crates/graphics/src/data/constant_data.rs b/crates/graphics/src/data/constant_data.rs index 1835cea0..6a135dc9 100644 --- a/crates/graphics/src/data/constant_data.rs +++ b/crates/graphics/src/data/constant_data.rs @@ -48,8 +48,8 @@ struct Data { pub env_map_texture_index: u32, pub num_lights: u32, pub forced_lod_level: i32, - pub _empty1: u32, - pub _empty2: u32, + pub camera_near: f32, + pub camera_far: f32, pub _empty3: u32, } @@ -72,8 +72,8 @@ impl Default for Data { env_map_texture_index: 0, num_lights: 0, forced_lod_level: -1, - _empty1: 0, - _empty2: 0, + camera_near: 0., + camera_far: 0., _empty3: 0, } } @@ -183,27 +183,31 @@ impl ConstantData { } pub fn update( &mut self, - view: Matrix4, - proj: Matrix4, - screen_size: Vector2, - debug_coords: Vector2, + view_proj_near_far: (Matrix4, Matrix4, f32, f32), + screen_size_and_debug_coords: (Vector2, Vector2), tlas_starting_index: u32, ) -> bool { - let v = matrix4_to_array(view); - let p = matrix4_to_array(proj); + let v = matrix4_to_array(view_proj_near_far.0); + let p = matrix4_to_array(view_proj_near_far.1); if self.data.view != v || self.data.proj != p - || self.data.screen_size[0] != screen_size.x - || self.data.screen_size[1] != screen_size.y + || self.data.screen_size[0] != screen_size_and_debug_coords.0.x + || self.data.screen_size[1] != screen_size_and_debug_coords.0.y { self.data.frame_index = 0; } self.data.view = v; self.data.proj = p; - self.data.view_proj = matrix4_to_array(proj * view); - self.data.inverse_view_proj = matrix4_to_array((proj * view).inverse()); - self.data.screen_size = screen_size.into(); - self.data.debug_uv_coords = (debug_coords.div(screen_size)).into(); + self.data.camera_near = view_proj_near_far.2; + self.data.camera_far = view_proj_near_far.3; + self.data.view_proj = matrix4_to_array(view_proj_near_far.1 * view_proj_near_far.0); + self.data.inverse_view_proj = + matrix4_to_array((view_proj_near_far.1 * view_proj_near_far.0).inverse()); + self.data.screen_size = screen_size_and_debug_coords.0.into(); + self.data.debug_uv_coords = (screen_size_and_debug_coords + .1 + .div(screen_size_and_debug_coords.0)) + .into(); self.data.tlas_starting_index = tlas_starting_index; if self.data.flags & CONSTANT_DATA_FLAGS_DISPLAY_PATHTRACE == 0 { self.data.frame_index += 1; diff --git a/crates/graphics/src/resources/view.rs b/crates/graphics/src/resources/view.rs index e3f3a9ea..845c49c3 100644 --- a/crates/graphics/src/resources/view.rs +++ b/crates/graphics/src/resources/view.rs @@ -79,6 +79,12 @@ impl View { pub fn proj(&self) -> Matrix4 { self.proj } + pub fn near(&self) -> f32 { + DEFAULT_NEAR + } + pub fn far(&self) -> f32 { + DEFAULT_FAR + } pub fn fov_in_radians(&self) -> Radians { self.fov_in_degrees.into() } diff --git a/crates/graphics/src/systems/update_system.rs b/crates/graphics/src/systems/update_system.rs index b8e3b136..10ae4507 100644 --- a/crates/graphics/src/systems/update_system.rs +++ b/crates/graphics/src/systems/update_system.rs @@ -218,6 +218,8 @@ impl System for UpdateSystem { self.render_context.global_buffers().update_constant_data( self.view.get().view(), self.view.get().proj(), + self.view.get().near(), + self.view.get().far(), screen_size, self.mouse_coords, ); diff --git a/crates/plugins/binarizer/src/compilers/gltf_compiler.rs b/crates/plugins/binarizer/src/compilers/gltf_compiler.rs index d74b5620..f7020b85 100644 --- a/crates/plugins/binarizer/src/compilers/gltf_compiler.rs +++ b/crates/plugins/binarizer/src/compilers/gltf_compiler.rs @@ -377,7 +377,7 @@ impl GltfCompiler { let (meshlets, mut mesh_indices) = compute_meshlets(&geometry.vertices, &geometry.indices, 0); - let mut is_meshlet_tree_created = true;//meshlets.len() <= 1; + let mut is_meshlet_tree_created = meshlets.len() <= 1; meshlets_per_lod.push(meshlets); mesh_indices_offset += mesh_indices.len(); diff --git a/data_raw/shaders/wgsl/common.inc b/data_raw/shaders/wgsl/common.inc index b4b705ec..0e0519ec 100644 --- a/data_raw/shaders/wgsl/common.inc +++ b/data_raw/shaders/wgsl/common.inc @@ -114,8 +114,8 @@ struct ConstantData { environment_map_texture_index: u32, num_lights: u32, forced_lod_level: i32, - _empty1: u32, - _empty2: u32, + camera_near: f32, + camera_far: f32, _empty3: u32, }; diff --git a/data_raw/shaders/wgsl/geom_utils.inc b/data_raw/shaders/wgsl/geom_utils.inc index 4e993c75..1a724c59 100644 --- a/data_raw/shaders/wgsl/geom_utils.inc +++ b/data_raw/shaders/wgsl/geom_utils.inc @@ -13,7 +13,7 @@ fn clip_to_normalized(clip_coords: vec2) -> vec2 { fn pixel_to_clip(image_pixel: vec2, image_size: vec2) -> vec2 { var clip_coords = 2. * pixel_to_normalized(image_pixel, image_size) - vec2(1.); - clip_coords.y = -clip_coords.y; + clip_coords.y *= -1.; return clip_coords; } @@ -25,7 +25,7 @@ fn pixel_to_world(image_pixel: vec2, image_size: vec2, depth: f32) -> fn clip_to_world(clip_coords: vec2, depth: f32) -> vec3 { var world_pos = constant_data.inverse_view_proj * vec4(clip_coords, depth, 1.); - world_pos /= -world_pos.w; + world_pos /= world_pos.w; return world_pos.xyz; }