Skip to content

Commit

Permalink
Consume motion in ReSTIR
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Nov 21, 2023
1 parent ce0eefc commit a538edb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion blade-render/code/gbuf.inc.wgsl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const MOTION_SCALE: f32 = 0.05;
const MOTION_SCALE: f32 = 0.02;
6 changes: 5 additions & 1 deletion blade-render/code/ray-trace.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "debug-param.inc.wgsl"
#include "camera.inc.wgsl"
#include "surface.inc.wgsl"
#include "gbuf.inc.wgsl"

//TODO: use proper WGSL
const RAY_FLAG_CULL_NO_OPAQUE: u32 = 0x80u;
Expand Down Expand Up @@ -141,6 +142,7 @@ var t_basis: texture_2d<f32>;
var t_prev_basis: texture_2d<f32>;
var t_flat_normal: texture_2d<f32>;
var t_prev_flat_normal: texture_2d<f32>;
var t_motion: texture_2d<f32>;
var out_diffuse: texture_storage_2d<rgba16float, write>;
var out_debug: texture_storage_2d<rgba8unorm, write>;

Expand Down Expand Up @@ -362,7 +364,9 @@ fn compute_restir(surface: Surface, pixel: vec2<i32>, rng: ptr<function, RandomS
}
}

let prev_pixel = get_projected_pixel(prev_camera, position);
let motion = textureLoad(t_motion, pixel, 0).xy / MOTION_SCALE;
//TODO: find best match in a 2x2 grid
let prev_pixel = pixel + vec2<i32>(motion + vec2<f32>(0.5));

// First, gather the list of reservoirs to merge with
var accepted_reservoir_indices = array<i32, MAX_RESERVOIRS>();
Expand Down
2 changes: 2 additions & 0 deletions blade-render/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ struct MainData {
t_prev_basis: blade_graphics::TextureView,
t_flat_normal: blade_graphics::TextureView,
t_prev_flat_normal: blade_graphics::TextureView,
t_motion: blade_graphics::TextureView,
debug_buf: blade_graphics::BufferPiece,
reservoirs: blade_graphics::BufferPiece,
prev_reservoirs: blade_graphics::BufferPiece,
Expand Down Expand Up @@ -1134,6 +1135,7 @@ impl Renderer {
t_prev_basis: self.targets.basis.views[prev],
t_flat_normal: self.targets.flat_normal.views[cur],
t_prev_flat_normal: self.targets.flat_normal.views[prev],
t_motion: self.targets.motion.views[0],
debug_buf: self.debug.buffer_resource(),
reservoirs: self.targets.reservoir_buf[cur].into(),
prev_reservoirs: self.targets.reservoir_buf[prev].into(),
Expand Down
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Changelog for Blade

## (TBD)
- support object motion

## blade-graphics-0.3, blade-render-0.2 (17 Nov 2023)
- tangent space generation
- spatio-temporal resampling
Expand Down

0 comments on commit a538edb

Please sign in to comment.