Skip to content

Commit

Permalink
Removing traverse breda useless changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gents83 committed Feb 7, 2024
1 parent 8e8ea26 commit 2264609
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 27 deletions.
4 changes: 2 additions & 2 deletions crates/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ web-sys = { version = "0.3.66", features = [
"PerformanceTiming"
] }

[patch."https://github.com/gwihlidal/meshopt-rs"]
meshopt = { git = "https://github.com/gents83/meshopt-rs", branch = "traverse_breda_vertex_lock" }
#[patch."https://github.com/gwihlidal/meshopt-rs"]
#meshopt = { git = "https://github.com/gents83/meshopt-rs", branch = "traverse_breda_vertex_lock" }

[patch."https://github.com/Wumpf/wgpu-profiler"]
wgpu-profiler = { git = "https://github.com/gents83/wgpu-profiler.git", branch = "wgpu-updated"}
Expand Down
1 change: 1 addition & 0 deletions crates/plugins/binarizer/src/adjacency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub(crate) struct MeshletAdjacency {
adjacent_meshlets: Vec<(u32, usize)>,
}

#[allow(dead_code)]
pub fn find_border_vertices(indices: &[u32]) -> Vec<u32> {
let mut border_vertices = Vec::with_capacity(indices.len());
let num_triangles = indices.len() / 3;
Expand Down
10 changes: 5 additions & 5 deletions crates/plugins/binarizer/src/compilers/gltf_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,13 @@ impl GltfCompiler {
let mut geometry = GltfGeometry { vertices, indices };
generate_tangents(&mut geometry);

let (mesh_vertices, geometry_indices) =
let (geometry_vertices, geometry_indices) =
optimize_mesh(&geometry.vertices, &geometry.indices);

let mut mesh_indices_offset = 0;
let mut previous_meshlets_starting_offset = 0;
let mut meshlets_per_lod = Vec::new();
let (meshlets, mut mesh_indices) = compute_meshlets(&mesh_vertices, &geometry_indices);
let (meshlets, mut mesh_indices) = compute_meshlets(&geometry_vertices, &geometry_indices);

let mut is_meshlet_tree_created = meshlets.len() <= 1;
meshlets_per_lod.push(meshlets);
Expand All @@ -381,7 +381,7 @@ impl GltfCompiler {
while !is_meshlet_tree_created {
let previous_lod_meshlets = meshlets_per_lod.last_mut().unwrap();
let meshlets_adjacency =
build_meshlets_adjacency(previous_lod_meshlets, &mesh_vertices, &mesh_indices);
build_meshlets_adjacency(previous_lod_meshlets, &geometry_vertices, &mesh_indices);
let groups = group_meshlets(&meshlets_adjacency);
level += 1;

Expand All @@ -390,7 +390,7 @@ impl GltfCompiler {
previous_lod_meshlets,
previous_meshlets_starting_offset,
mesh_indices_offset,
&mesh_vertices,
&geometry_vertices,
&mesh_indices,
);

Expand All @@ -402,7 +402,7 @@ impl GltfCompiler {
is_meshlet_tree_created = groups.len() == 1 || level >= (MAX_LOD_LEVELS - 1);
}

let mut mesh_data = create_mesh_data(&mesh_vertices, &mesh_indices);
let mut mesh_data = create_mesh_data(&geometry_vertices, &mesh_indices);
mesh_data.meshlets = meshlets_per_lod;
mesh_data.meshlets_bvh.clear();
mesh_data.material = material_path.to_path_buf();
Expand Down
25 changes: 6 additions & 19 deletions crates/plugins/binarizer/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ use inox_math::{VecBase, Vector2, Vector3, Vector4};
use inox_resources::to_slice;
use meshopt::DecodePosition;

use crate::adjacency::find_border_vertices;

#[derive(Debug, Clone, Copy)]
pub struct MeshVertex {
pub pos: Vector3,
Expand Down Expand Up @@ -80,15 +78,6 @@ where
meshopt::remap_index_buffer(Some(indices), num_vertices, vertices_remap_table.as_slice());

let mut new_indices = meshopt::optimize_vertex_cache(&remapped_indices, num_vertices);

let vertices_bytes = to_slice(&positions);
let vertex_stride = size_of::<[f32; 3]>();
let vertex_data_adapter = meshopt::VertexDataAdapter::new(vertices_bytes, vertex_stride, 0);
meshopt::optimize_overdraw_in_place(
&mut new_indices,
vertex_data_adapter.as_ref().unwrap(),
1.05,
);
let new_vertices = meshopt::optimize_vertex_fetch(&mut new_indices, &new_vertices);

(new_vertices, new_indices)
Expand Down Expand Up @@ -232,28 +221,26 @@ pub fn compute_clusters(
aabb_min = aabb_min.min(meshlet.aabb_min);
});

let (optimized_vertices, optimized_indices) = (group_vertices, group_indices);
//optimize_mesh(&group_vertices, &group_indices);
let (optimized_vertices, optimized_indices) =
optimize_mesh(&group_vertices, &group_indices);

let target_count = (optimized_indices.len() as f32 * 0.5) as usize;
let target_error = 0.01;

let border_vertices = find_border_vertices(&optimized_indices);
let mut simplified_indices = meshopt::simplify_decoder(
&optimized_indices,
&optimized_vertices,
target_count,
target_error,
0,
Some(&border_vertices),
meshopt::SimplifyOptions::LockBorder,
None,
);

if simplified_indices.len() >= optimized_indices.len() {
inox_log::debug_log!(
"No simplification happened [from {} to {}] even if only {} locked_vertices",
"No simplification happened [from {} to {}]",
optimized_indices.len(),
simplified_indices.len(),
border_vertices.len()
);
}

Expand Down Expand Up @@ -321,7 +308,7 @@ fn simplify_test() {
&vertices,
target_count,
target_error,
1, //meshopt::SimplifyOptions::LockBorder,
meshopt::SimplifyOptions::LockBorder,
None,
);

Expand Down
2 changes: 1 addition & 1 deletion data_raw/shaders/wgsl/compute_culling.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn main(
let screen_min = clip_to_normalized(ncd_min.xy / ncd_min.w);
var ncd_max = clip_mvp * vec4<f32>(max, 1.);
let screen_max = clip_to_normalized(ncd_max.xy / ncd_max.w);
let screen_diff = screen_max - screen_min;
let screen_diff = max(screen_max, screen_min) - min(screen_max, screen_min);
let screen_size = saturate(max(screen_diff.x, screen_diff.y));
let size_lod_level = min(u32(max(screen_size * (f32(MAX_LOD_LEVELS) * 1.25), 0.0)), MAX_LOD_LEVELS - 1u);
desired_lod_level = i32(size_lod_level);
Expand Down

0 comments on commit 2264609

Please sign in to comment.