Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions blade-helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,18 @@ mod hud;
pub use blade_render::Camera;
pub use camera::ControlledCamera;
pub use hud::{populate_debug_selection, ExposeHud};

pub fn default_ray_config() -> blade_render::RayConfig {
blade_render::RayConfig {
num_environment_samples: 1,
environment_importance_sampling: false,
temporal_tap: true,
temporal_history: 10,
spatial_taps: 1,
spatial_tap_history: 10,
spatial_radius: 20,
t_start: 0.01,
pairwise_mis: true,
defensive_mis: 0.1,
}
}
4 changes: 3 additions & 1 deletion blade-render/code/gbuf.inc.wgsl
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion blade-render/code/ray-trace.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
var rng = random_init(global_index, parameters.frame_index);

let surface = read_surface(vec2<i32>(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<i32>(global_id.xy), &rng, enable_restir_debug);
let color = ro.radiance;
Expand Down
1 change: 1 addition & 0 deletions blade-render/src/asset_hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<crate::render::DebugMode>();
sh_baker.register_bitflags::<crate::render::DebugDrawFlags>();
sh_baker.register_bitflags::<crate::render::DebugTextureFlags>();
Expand Down
5 changes: 1 addition & 4 deletions blade-render/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,10 +1044,7 @@ impl Renderer {
draw_flags: config.draw_flags.bits(),
texture_flags: config.texture_flags.bits(),
unused: 0,
mouse_pos: match config.mouse_pos {
Some(p) => [p[0], self.surface_size.height as i32 - p[1]],
None => [-1; 2],
},
mouse_pos: config.mouse_pos.unwrap_or([-1; 2]),
}
}

Expand Down
26 changes: 21 additions & 5 deletions blade-render/src/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@ pub struct Shader {
pub raw: Result<blade_graphics::Shader, &'static str>,
}

pub struct Expansion(HashMap<String, u32>);
pub enum Expansion {
Values(HashMap<String, u32>),
Bool(bool),
}
impl Expansion {
pub fn from_enum<E: strum::IntoEnumIterator + fmt::Debug + Into<u32>>() -> Self {
Self(
Self::Values(
E::iter()
.map(|variant| (format!("{variant:?}"), variant.into()))
.collect(),
)
}
pub fn from_bitflags<F: bitflags::Flags<Bits = u32>>() -> Self {
Self(
Self::Values(
F::FLAGS
.iter()
.map(|flag| (flag.name().to_string(), flag.value().bits()))
Expand Down Expand Up @@ -64,6 +67,11 @@ impl Baker {
pub fn register_bitflags<F: bitflags::Flags<Bits = u32>>(&mut self) {
self.register::<F>(Expansion::from_bitflags::<F>());
}

pub fn register_bool(&mut self, name: &str, value: bool) {
self.expansions
.insert(name.to_string(), Expansion::Bool(value));
}
}

fn parse_impl(
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 1 addition & 12 deletions examples/scene/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,7 @@ impl Example {
is_file_hovered: false,
last_render_time: time::Instant::now(),
render_times: VecDeque::with_capacity(FRAME_TIME_HISTORY),
ray_config: blade_render::RayConfig {
num_environment_samples: 1,
environment_importance_sampling: false,
temporal_tap: true,
temporal_history: 10,
spatial_taps: 1,
spatial_tap_history: 10,
spatial_radius: 10,
t_start: 0.1,
pairwise_mis: true,
defensive_mis: 0.0,
},
ray_config: blade_helpers::default_ray_config(),
denoiser_enabled: true,
denoiser_config: blade_render::DenoiserConfig {
num_passes: 3,
Expand Down
13 changes: 1 addition & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,18 +482,7 @@ impl Engine {
reset_variance: false,
reset_reservoirs: true,
},
ray_config: blade_render::RayConfig {
num_environment_samples: 1,
environment_importance_sampling: false,
temporal_tap: true,
temporal_history: 10,
spatial_taps: 1,
spatial_tap_history: 10,
spatial_radius: 10,
t_start: 0.01,
pairwise_mis: true,
defensive_mis: 0.1,
},
ray_config: blade_helpers::default_ray_config(),
denoiser_enabled: true,
denoiser_config: blade_render::DenoiserConfig {
num_passes: 4,
Expand Down