From 8801f473fa460f5efd260f44c3478f8ac51b62bc Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sun, 22 Oct 2023 00:20:41 -0700 Subject: [PATCH] Configurable flight speed and debug position consistency --- blade-render/code/fill-gbuf.wgsl | 13 +++++++++---- examples/scene/data/scene.ron | 1 + examples/scene/main.rs | 5 ++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/blade-render/code/fill-gbuf.wgsl b/blade-render/code/fill-gbuf.wgsl index c1afc236..29fbfd3f 100644 --- a/blade-render/code/fill-gbuf.wgsl +++ b/blade-render/code/fill-gbuf.wgsl @@ -3,6 +3,8 @@ #include "debug.inc.wgsl" #include "debug-param.inc.wgsl" +const DEBUG_CONSISTENCY: bool = false; + // Has to match the host! struct Vertex { pos: vec3, @@ -117,6 +119,7 @@ fn main(@builtin(global_invocation_id) global_id: vec3) { let normal = qrot(geo_to_world_rot, tangent_space_geo * normal_local); basis = shortest_arc_quat(vec3(0.0, 0.0, 1.0), normalize(normal)); + let hit_position = camera.position + intersection.t * ray_dir; if (enable_debug) { debug_buf.entry.tex_coords = tex_coords; debug_buf.entry.base_color_texture = entry.base_color_texture; @@ -129,15 +132,14 @@ fn main(@builtin(global_invocation_id) global_id: vec3) { debug_line(positions[2].xyz, positions[0].xyz, 0x00FFFFu); let poly_center = (positions[0].xyz + positions[1].xyz + positions[2].xyz) / 3.0; debug_line(poly_center, poly_center + 0.2 * debug_len * flat_normal, 0xFF00FFu); - let pos_world = camera.position + intersection.t * ray_dir; // note: dynamic indexing into positions isn't allowed by WGSL yet debug_raw_normal(positions[0].xyz, vertices[0].normal, geo_to_world_rot, 0.5*debug_len, 0xFFFF00u); debug_raw_normal(positions[1].xyz, vertices[1].normal, geo_to_world_rot, 0.5*debug_len, 0xFFFF00u); debug_raw_normal(positions[2].xyz, vertices[2].normal, geo_to_world_rot, 0.5*debug_len, 0xFFFF00u); // draw tangent space - debug_line(pos_world, pos_world + debug_len * qrot(basis, vec3(1.0, 0.0, 0.0)), 0x0000FFu); - debug_line(pos_world, pos_world + debug_len * qrot(basis, vec3(0.0, 1.0, 0.0)), 0x00FF00u); - debug_line(pos_world, pos_world + debug_len * qrot(basis, vec3(0.0, 0.0, 1.0)), 0xFF0000u); + debug_line(hit_position, hit_position + debug_len * qrot(basis, vec3(1.0, 0.0, 0.0)), 0x0000FFu); + debug_line(hit_position, hit_position + debug_len * qrot(basis, vec3(0.0, 1.0, 0.0)), 0x00FF00u); + debug_line(hit_position, hit_position + debug_len * qrot(basis, vec3(0.0, 0.0, 1.0)), 0xFF0000u); } let base_color_factor = unpack4x8unorm(entry.base_color_factor); @@ -147,6 +149,9 @@ fn main(@builtin(global_invocation_id) global_id: vec3) { let base_color_sample = textureSampleLevel(textures[entry.base_color_texture], sampler_linear, tex_coords, lod); albedo = (base_color_factor * base_color_sample).xyz; } + if (DEBUG_CONSISTENCY) { + albedo = vec3(length(positions * barycentrics - hit_position)); + } } else { if (enable_debug) { debug_buf.entry = DebugEntry(); diff --git a/examples/scene/data/scene.ron b/examples/scene/data/scene.ron index 19f34856..b5afd906 100644 --- a/examples/scene/data/scene.ron +++ b/examples/scene/data/scene.ron @@ -4,6 +4,7 @@ orientation: (-0.04, 0.92, -0.05, -0.37), fov_y: 1.0, max_depth: 100.0, + speed: 1000.0, ), average_luminocity: 0.3, models: [ diff --git a/examples/scene/main.rs b/examples/scene/main.rs index 5811fc1f..9ade5f47 100644 --- a/examples/scene/main.rs +++ b/examples/scene/main.rs @@ -34,6 +34,7 @@ struct ConfigCamera { orientation: [f32; 4], fov_y: f32, max_depth: f32, + speed: f32, } fn default_transform() -> [[f32; 4]; 3] { @@ -75,6 +76,7 @@ struct Example { asset_hub: AssetHub, context: Arc, camera: blade_render::Camera, + fly_speed: f32, debug: blade_render::DebugConfig, need_accumulation_reset: bool, is_debug_drawing: bool, @@ -215,6 +217,7 @@ impl Example { asset_hub, context, camera, + fly_speed: config_scene.camera.speed, debug: blade_render::DebugConfig::default(), need_accumulation_reset: true, is_debug_drawing: false, @@ -660,7 +663,7 @@ fn main() { *control_flow = winit::event_loop::ControlFlow::Poll; let delta = last_event.elapsed().as_secs_f32(); last_event = time::Instant::now(); - let move_speed = 2000.0 * delta; + let move_speed = example.fly_speed * delta; let rotate_speed = 0.01f32; let rotate_speed_z = 200.0 * delta;