Skip to content

Commit

Permalink
Bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
gents83 committed Feb 23, 2024
1 parent c831bba commit cfba52d
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 21 deletions.
9 changes: 8 additions & 1 deletion crates/graphics/src/common/render_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,16 @@ impl RenderContext {
} else {
wgpu::Backends::all()
};
#[allow(unused_assignments)]
let mut flags = wgpu::InstanceFlags::empty();
#[cfg(not(target_arch = "wasm32"))]
#[cfg(debug_assertions)]
{
flags = wgpu::InstanceFlags::debugging();
}
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends,
flags: wgpu::InstanceFlags::empty(),
flags,
..Default::default()
});
let surface = Self::create_surface(&instance, handle.clone());
Expand Down
2 changes: 1 addition & 1 deletion crates/graphics/src/common/shapes2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn create_quad_with_texture(rect: Vector4, z: f32, tex_coords: Vector4) -> M
[1., -1., 0.].into(),
[tex_coords.z, tex_coords.y].into(),
);
mesh_data.indices = [0, 1, 2, 3, 0, 2].to_vec();
mesh_data.indices = [0, 3, 2, 2, 1, 0].to_vec();

let meshlet = MeshletData {
indices_count: mesh_data.index_count() as _,
Expand Down
2 changes: 1 addition & 1 deletion crates/graphics/src/data/mesh_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl MeshData {
let vertex_offset = self.vertex_count() as u32;
let index_offset = self.index_count() as u32;

if as_separate_meshlet || self.meshlets.is_empty() {
if as_separate_meshlet || self.meshlets[lod_level].is_empty() {
let meshlet = MeshletData {
indices_offset: index_offset as _,
indices_count: mesh_data.index_count() as _,
Expand Down
1 change: 0 additions & 1 deletion crates/graphics/src/data/vertex_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub enum VertexAttributeLayout {
HasUV2 = 1 << 4, // 1 packed u32 with uv in 2f16 (at runtime then 2 float)
HasUV3 = 1 << 5, // 1 packed u32 with uv in 2f16 (at runtime then 2 float)
HasUV4 = 1 << 6, // 1 packed u32 with uv in 2f16 (at runtime then 2 float)
MaxAttributesShift = 7,
}

impl VertexAttributeLayout {
Expand Down
15 changes: 6 additions & 9 deletions crates/plugins/binarizer/src/compilers/gltf_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{

use crate::{
adjacency::{build_meshlets_adjacency, group_meshlets_with_metis},
mesh::{compute_clusters, compute_meshlets, create_mesh_data, optimize_mesh, MeshVertex},
mesh::{compute_clusters, compute_meshlets, create_mesh_data, MeshVertex},
need_to_binarize, to_local_path, ExtensionHandler,
};
use gltf::{
Expand Down Expand Up @@ -371,16 +371,13 @@ impl GltfCompiler {
let mut geometry = GltfGeometry { vertices, indices };
generate_tangents(&mut geometry);

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(&geometry_vertices, &geometry_indices, 0);
compute_meshlets(&geometry.vertices, &geometry.indices, 0);

let mut is_meshlet_tree_created = meshlets.len() <= 1;
let mut is_meshlet_tree_created = true;//meshlets.len() <= 1;
meshlets_per_lod.push(meshlets);
mesh_indices_offset += mesh_indices.len();

Expand All @@ -389,7 +386,7 @@ impl GltfCompiler {
let previous_lod_meshlets = meshlets_per_lod.last_mut().unwrap();
let meshlets_adjacency = build_meshlets_adjacency(
previous_lod_meshlets,
&geometry_vertices,
&geometry.vertices,
&mesh_indices,
);
let groups = group_meshlets_with_metis(&meshlets_adjacency);
Expand All @@ -400,7 +397,7 @@ impl GltfCompiler {
previous_lod_meshlets,
previous_meshlets_starting_offset,
mesh_indices_offset,
&geometry_vertices,
&geometry.vertices,
&mesh_indices,
);

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

let mut mesh_data = create_mesh_data(&geometry_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
1 change: 1 addition & 0 deletions crates/plugins/binarizer/src/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl meshopt::DecodePosition for LocalVertex {
}
}

#[allow(dead_code)]
pub fn optimize_mesh<T>(vertices: &[T], indices: &[u32]) -> (Vec<T>, Vec<u32>)
where
T: Clone + Default + DecodePosition,
Expand Down
4 changes: 3 additions & 1 deletion crates/plugins/viewer/src/systems/viewer_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ impl ViewerSystem {
camera_object
.get_mut()
.set_position(Vector3::new(0.0, 0.0, -50.0));
camera_object.get_mut().look_at(Vector3::new(0.0, 0.0, 0.0));
camera_object
.get_mut()
.look_towards(Vector3::new(0.0, 0.0, -1.0));
let camera = camera_object.get_mut().add_default_component::<Camera>(
self.context.shared_data(),
self.context.message_hub(),
Expand Down
12 changes: 6 additions & 6 deletions data_raw/shaders/wgsl/texture_utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ fn sample_texture(tex_coords_and_texture_index: vec3<f32>) -> vec4<f32> {
}
let texture = &textures.data[texture_data_index];
var texture_index = (*texture).texture_and_layer_index;
let min = unpack2x16float((*texture).min);
let max = unpack2x16float((*texture).max);
let size = unpack2x16float((*texture).size);
let area_start = unpack2x16float((*texture).min);
let area_size = unpack2x16float((*texture).max);
let total_size = unpack2x16float((*texture).size);
if (texture_index < 0) {
texture_index *= -1;
}
let atlas_index = u32(texture_index >> 3);
let layer_index = i32(texture_index & 0x00000007);
let layer_index = i32(texture_index & 0x00000007);

tex_coords.x = (f32(min.x) + mod_f32(tex_coords_and_texture_index.x, 1.) * f32(max.x)) / f32(size.x);
tex_coords.y = (f32(min.y) + mod_f32(tex_coords_and_texture_index.y, 1.) * f32(max.y)) / f32(size.y);
tex_coords.x = (f32(area_start.x) + mod_f32(tex_coords_and_texture_index.x, 1.) * f32(area_size.x)) / f32(total_size.x);
tex_coords.y = (f32(area_start.y) + mod_f32(tex_coords_and_texture_index.y, 1.) * f32(area_size.y)) / f32(total_size.y);
tex_coords.z = f32(layer_index);

#ifdef FEATURES_TEXTURE_BINDING_ARRAY
Expand Down
2 changes: 1 addition & 1 deletion data_raw/shaders/wgsl/visibility_utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn visibility_to_gbuffer(visibility_id: u32, hit_point: vec3<f32>) -> PixelData
let material_id = u32((*mesh).material_index);
let position_offset = (*mesh).vertices_position_offset;
let attributes_offset = (*mesh).vertices_attribute_offset;
let vertex_layout = (*mesh).flags_and_vertices_attribute_layout;
let vertex_layout = (*mesh).flags_and_vertices_attribute_layout & 0x0000FFFFu;
let orientation = (*mesh).orientation;
let vertex_attribute_stride = vertex_layout_stride(vertex_layout);
let offset_color = vertex_attribute_offset(vertex_layout, VERTEX_ATTRIBUTE_HAS_COLOR);
Expand Down

0 comments on commit cfba52d

Please sign in to comment.