Skip to content

Commit

Permalink
Fixing geom_utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gents83 committed Feb 24, 2024
1 parent cfba52d commit d84f377
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions crates/graphics/src/common/global_buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
36 changes: 20 additions & 16 deletions crates/graphics/src/data/constant_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions crates/graphics/src/resources/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 2 additions & 0 deletions crates/graphics/src/systems/update_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/plugins/binarizer/src/compilers/gltf_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions data_raw/shaders/wgsl/common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
4 changes: 2 additions & 2 deletions data_raw/shaders/wgsl/geom_utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn clip_to_normalized(clip_coords: vec2<f32>) -> vec2<f32> {

fn pixel_to_clip(image_pixel: vec2<u32>, image_size: vec2<u32>) -> vec2<f32> {
var clip_coords = 2. * pixel_to_normalized(image_pixel, image_size) - vec2<f32>(1.);
clip_coords.y = -clip_coords.y;
clip_coords.y *= -1.;
return clip_coords;
}

Expand All @@ -25,7 +25,7 @@ fn pixel_to_world(image_pixel: vec2<u32>, image_size: vec2<u32>, depth: f32) ->

fn clip_to_world(clip_coords: vec2<f32>, depth: f32) -> vec3<f32> {
var world_pos = constant_data.inverse_view_proj * vec4<f32>(clip_coords, depth, 1.);
world_pos /= -world_pos.w;
world_pos /= world_pos.w;
return world_pos.xyz;
}

Expand Down

0 comments on commit d84f377

Please sign in to comment.