From a92ef95c0acabf31ff22f55434632401fbfa18da Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Fri, 3 Nov 2023 21:53:12 -0700 Subject: [PATCH] Extend DebugEntry, fix debug draw and GLB loading --- blade-render/code/debug.inc.wgsl | 3 +++ blade-render/code/fill-gbuf.wgsl | 9 +++++++++ blade-render/src/model/mod.rs | 2 +- blade-render/src/render/mod.rs | 12 +++++++++--- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/blade-render/code/debug.inc.wgsl b/blade-render/code/debug.inc.wgsl index 00ec256f..cc172456 100644 --- a/blade-render/code/debug.inc.wgsl +++ b/blade-render/code/debug.inc.wgsl @@ -17,6 +17,9 @@ struct DebugEntry { tex_coords: vec2, base_color_texture: u32, normal_texture: u32, + pad: vec2, + position: vec3, + flat_normal: vec3, } struct DebugBuffer { vertex_count: u32, diff --git a/blade-render/code/fill-gbuf.wgsl b/blade-render/code/fill-gbuf.wgsl index 0c53e56b..4da6baa0 100644 --- a/blade-render/code/fill-gbuf.wgsl +++ b/blade-render/code/fill-gbuf.wgsl @@ -129,6 +129,15 @@ fn main(@builtin(global_invocation_id) global_id: vec3) { debug_buf.entry.tex_coords = tex_coords; debug_buf.entry.base_color_texture = entry.base_color_texture; debug_buf.entry.normal_texture = entry.normal_texture; + debug_buf.entry.position = hit_position; + debug_buf.entry.flat_normal = flat_normal; + } + if (enable_debug && (debug.draw_flags & DebugDrawFlags_SPACE) != 0u) { + let normal_len = 0.15 * intersection.t; + let side = 0.05 * intersection.t; + debug_line(hit_position, hit_position + normal_len * normal_geo, 0xFFFFFFu); + debug_line(hit_position - side * tangent_geo, hit_position + side * tangent_geo, 0x808080u); + debug_line(hit_position - side * bitangent_geo, hit_position + side * bitangent_geo, 0x808080u); } if (enable_debug && (debug.draw_flags & DebugDrawFlags_GEOMETRY) != 0u) { let debug_len = intersection.t * 0.2; diff --git a/blade-render/src/model/mod.rs b/blade-render/src/model/mod.rs index 46e53e2e..92cd7db5 100644 --- a/blade-render/src/model/mod.rs +++ b/blade-render/src/model/mod.rs @@ -356,7 +356,7 @@ impl blade_asset::Baker for Baker { ) { match extension { #[cfg(feature = "asset")] - "gltf" => { + "gltf" | "glb" => { use base64::engine::{general_purpose::URL_SAFE as ENCODING_ENGINE, Engine as _}; let gltf::Gltf { document, mut blob } = gltf::Gltf::from_slice(source).unwrap(); diff --git a/blade-render/src/render/mod.rs b/blade-render/src/render/mod.rs index 281f6f49..ce138b59 100644 --- a/blade-render/src/render/mod.rs +++ b/blade-render/src/render/mod.rs @@ -40,8 +40,9 @@ impl Default for DebugMode { bitflags::bitflags! { #[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq, PartialOrd)] pub struct DebugDrawFlags: u32 { - const GEOMETRY = 1; - const RESTIR = 2; + const SPACE = 1; + const GEOMETRY = 2; + const RESTIR = 4; } } @@ -144,6 +145,11 @@ struct DebugEntry { tex_coords: [f32; 2], base_color_texture: u32, normal_texture: u32, + pad: [u32; 2], + position: [f32; 3], + position_w: f32, + normal: [f32; 3], + normal_w: f32, } struct DebugRender { @@ -799,7 +805,7 @@ impl Renderer { buffer_size: sp.debug_buffer_size, }; - let debug_init_data = [2u32, 0, 0, config.max_debug_lines]; + let debug_init_data = [2u32, 0, 0, 0, config.max_debug_lines]; let debug_init_size = debug_init_data.len() * mem::size_of::(); assert!(debug_init_size <= mem::size_of::()); unsafe {