diff --git a/blade-render/code/gbuf.inc.wgsl b/blade-render/code/gbuf.inc.wgsl index 374aa708..1f4d84a1 100644 --- a/blade-render/code/gbuf.inc.wgsl +++ b/blade-render/code/gbuf.inc.wgsl @@ -1,3 +1,5 @@ +#use DEBUG_MODE + const MOTION_SCALE: f32 = 0.02; const USE_MOTION_VECTORS: bool = true; -const WRITE_DEBUG_IMAGE: bool = false; +const WRITE_DEBUG_IMAGE: bool = DEBUG_MODE; diff --git a/blade-render/code/ray-trace.wgsl b/blade-render/code/ray-trace.wgsl index a51931ef..6f0a1f95 100644 --- a/blade-render/code/ray-trace.wgsl +++ b/blade-render/code/ray-trace.wgsl @@ -514,7 +514,7 @@ fn main(@builtin(global_invocation_id) global_id: vec3) { var rng = random_init(global_index, parameters.frame_index); let surface = read_surface(vec2(global_id.xy)); - let enable_debug = all(global_id.xy == debug.mouse_pos); + let enable_debug = DEBUG_MODE && all(global_id.xy == debug.mouse_pos); let enable_restir_debug = (debug.draw_flags & DebugDrawFlags_RESTIR) != 0u && enable_debug; let ro = compute_restir(surface, vec2(global_id.xy), &rng, enable_restir_debug); let color = ro.radiance; diff --git a/blade-render/src/asset_hub.rs b/blade-render/src/asset_hub.rs index 4245d5d3..98b49533 100644 --- a/blade-render/src/asset_hub.rs +++ b/blade-render/src/asset_hub.rs @@ -34,6 +34,7 @@ impl AssetHub { ); let mut sh_baker = crate::shader::Baker::new(gpu_context); + sh_baker.register_bool("DEBUG_MODE", cfg!(debug_assertions)); sh_baker.register_enum::(); sh_baker.register_bitflags::(); sh_baker.register_bitflags::(); diff --git a/blade-render/src/shader.rs b/blade-render/src/shader.rs index d99c9de3..69a14f72 100644 --- a/blade-render/src/shader.rs +++ b/blade-render/src/shader.rs @@ -19,17 +19,20 @@ pub struct Shader { pub raw: Result, } -pub struct Expansion(HashMap); +pub enum Expansion { + Values(HashMap), + Bool(bool), +} impl Expansion { pub fn from_enum>() -> Self { - Self( + Self::Values( E::iter() .map(|variant| (format!("{variant:?}"), variant.into())) .collect(), ) } pub fn from_bitflags>() -> Self { - Self( + Self::Values( F::FLAGS .iter() .map(|flag| (flag.name().to_string(), flag.value().bits())) @@ -64,6 +67,11 @@ impl Baker { pub fn register_bitflags>(&mut self) { self.register::(Expansion::from_bitflags::()); } + + pub fn register_bool(&mut self, name: &str, value: bool) { + self.expansions + .insert(name.to_string(), Expansion::Bool(value)); + } } fn parse_impl( @@ -93,8 +101,16 @@ fn parse_impl( ); } else if line.starts_with("#use") { let type_name = line.split_whitespace().last().unwrap(); - for (key, value) in expansions[type_name].0.iter() { - writeln!(text_out, "const {}_{}: u32 = {}u;", type_name, key, value).unwrap(); + match expansions[type_name] { + Expansion::Values(ref map) => { + for (key, value) in map.iter() { + writeln!(text_out, "const {}_{}: u32 = {}u;", type_name, key, value) + .unwrap(); + } + } + Expansion::Bool(value) => { + writeln!(text_out, "const {}: bool = {};", type_name, value).unwrap(); + } } } else { *text_out += line;