Skip to content

Commit

Permalink
Configurable flight speed and debug position consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Oct 22, 2023
1 parent 4af7b87 commit 8801f47
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
13 changes: 9 additions & 4 deletions blade-render/code/fill-gbuf.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -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<f32>,
Expand Down Expand Up @@ -117,6 +119,7 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
let normal = qrot(geo_to_world_rot, tangent_space_geo * normal_local);
basis = shortest_arc_quat(vec3<f32>(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;
Expand All @@ -129,15 +132,14 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
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<f32>(1.0, 0.0, 0.0)), 0x0000FFu);
debug_line(pos_world, pos_world + debug_len * qrot(basis, vec3<f32>(0.0, 1.0, 0.0)), 0x00FF00u);
debug_line(pos_world, pos_world + debug_len * qrot(basis, vec3<f32>(0.0, 0.0, 1.0)), 0xFF0000u);
debug_line(hit_position, hit_position + debug_len * qrot(basis, vec3<f32>(1.0, 0.0, 0.0)), 0x0000FFu);
debug_line(hit_position, hit_position + debug_len * qrot(basis, vec3<f32>(0.0, 1.0, 0.0)), 0x00FF00u);
debug_line(hit_position, hit_position + debug_len * qrot(basis, vec3<f32>(0.0, 0.0, 1.0)), 0xFF0000u);
}

let base_color_factor = unpack4x8unorm(entry.base_color_factor);
Expand All @@ -147,6 +149,9 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
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<f32>(length(positions * barycentrics - hit_position));
}
} else {
if (enable_debug) {
debug_buf.entry = DebugEntry();
Expand Down
1 change: 1 addition & 0 deletions examples/scene/data/scene.ron
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
5 changes: 4 additions & 1 deletion examples/scene/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct ConfigCamera {
orientation: [f32; 4],
fov_y: f32,
max_depth: f32,
speed: f32,
}

fn default_transform() -> [[f32; 4]; 3] {
Expand Down Expand Up @@ -75,6 +76,7 @@ struct Example {
asset_hub: AssetHub,
context: Arc<gpu::Context>,
camera: blade_render::Camera,
fly_speed: f32,
debug: blade_render::DebugConfig,
need_accumulation_reset: bool,
is_debug_drawing: bool,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 8801f47

Please sign in to comment.