-
Notifications
You must be signed in to change notification settings - Fork 7
/
denoiser.rs
648 lines (587 loc) · 22.9 KB
/
denoiser.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
use image::Rgb;
use luisa::runtime::extension::DenoiserInput;
use luisa::runtime::DeviceExtensions;
use luisa_compute_api_types::denoiser_ext::{ImageColorSpace, ImageFormat, PrefilterMode};
use luisa_compute_api_types::StreamTag;
use rand::Rng;
use std::time::Instant;
use winit::event::{Event as WinitEvent, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop};
use luisa::lang::types::vector::alias::*;
use luisa::lang::types::vector::*;
use luisa::prelude::*;
use luisa::rtx::{
offset_ray_origin, Accel, AccelBuildRequest, AccelOption, AccelVar, Index, Ray, RayComps,
};
use luisa_compute as luisa;
use std::{env::current_exe, process::exit};
fn main() {
luisa::init_logger_verbose();
let args: Vec<String> = std::env::args().collect();
assert!(
args.len() <= 2,
"Usage: {} <backend>. <backend>: cpu, cuda, dx, metal, remote",
args[0]
);
let ctx = Context::new(current_exe().unwrap());
let device = ctx.create_device(if args.len() == 2 {
args[1].as_str()
} else {
"cpu"
});
if cfg!(not(feature = "oidn")) {
eprintln!("Please enable oidn feature to run this example");
exit(1);
} else {
run_pt(device);
}
}
#[derive(Value, Clone, Copy)]
#[repr(C)]
#[value_new(pub)]
pub struct Onb {
tangent: Float3,
binormal: Float3,
normal: Float3,
}
impl OnbExpr {
#[tracked]
fn to_world(&self, v: Expr<Float3>) -> Expr<Float3> {
self.tangent * v.x + self.binormal * v.y + self.normal * v.z
}
}
const CBOX_OBJ: &'static str = "
# The original Cornell Box in OBJ format.
# Note that the real box is not a perfect cube, so
# the faces are imperfect in this data set.
#
# Created by Guedis Cardenas and Morgan McGuire at Williams College, 2011
# Released into the Public Domain.
#
# http://graphics.cs.williams.edu/data
# http://www.graphics.cornell.edu/online/box/data.html
#
mtllib CornellBox-Original.mtl
g floor
v -1.01 0.00 0.99
v 1.00 0.00 0.99
v 1.00 0.00 -1.04
v -0.99 0.00 -1.04
f -4 -3 -2 -1
g ceiling
v -1.02 1.99 0.99
v -1.02 1.99 -1.04
v 1.00 1.99 -1.04
v 1.00 1.99 0.99
f -4 -3 -2 -1
g backWall
v -0.99 0.00 -1.04
v 1.00 0.00 -1.04
v 1.00 1.99 -1.04
v -1.02 1.99 -1.04
f -4 -3 -2 -1
g rightWall
v 1.00 0.00 -1.04
v 1.00 0.00 0.99
v 1.00 1.99 0.99
v 1.00 1.99 -1.04
f -4 -3 -2 -1
g leftWall
v -1.01 0.00 0.99
v -0.99 0.00 -1.04
v -1.02 1.99 -1.04
v -1.02 1.99 0.99
f -4 -3 -2 -1
g shortBox
# Top Face
v 0.53 0.60 0.75
v 0.70 0.60 0.17
v 0.13 0.60 0.00
v -0.05 0.60 0.57
f -4 -3 -2 -1
# Left Face
v -0.05 0.00 0.57
v -0.05 0.60 0.57
v 0.13 0.60 0.00
v 0.13 0.00 0.00
f -4 -3 -2 -1
# Front Face
v 0.53 0.00 0.75
v 0.53 0.60 0.75
v -0.05 0.60 0.57
v -0.05 0.00 0.57
f -4 -3 -2 -1
# Right Face
v 0.70 0.00 0.17
v 0.70 0.60 0.17
v 0.53 0.60 0.75
v 0.53 0.00 0.75
f -4 -3 -2 -1
# Back Face
v 0.13 0.00 0.00
v 0.13 0.60 0.00
v 0.70 0.60 0.17
v 0.70 0.00 0.17
f -4 -3 -2 -1
# Bottom Face
v 0.53 0.00 0.75
v 0.70 0.00 0.17
v 0.13 0.00 0.00
v -0.05 0.00 0.57
f -4 -3 -2 -1
g tallBox
# Top Face
v -0.53 1.20 0.09
v 0.04 1.20 -0.09
v -0.14 1.20 -0.67
v -0.71 1.20 -0.49
f -4 -3 -2 -1
# Left Face
v -0.53 0.00 0.09
v -0.53 1.20 0.09
v -0.71 1.20 -0.49
v -0.71 0.00 -0.49
f -4 -3 -2 -1
# Back Face
v -0.71 0.00 -0.49
v -0.71 1.20 -0.49
v -0.14 1.20 -0.67
v -0.14 0.00 -0.67
f -4 -3 -2 -1
# Right Face
v -0.14 0.00 -0.67
v -0.14 1.20 -0.67
v 0.04 1.20 -0.09
v 0.04 0.00 -0.09
f -4 -3 -2 -1
# Front Face
v 0.04 0.00 -0.09
v 0.04 1.20 -0.09
v -0.53 1.20 0.09
v -0.53 0.00 0.09
f -4 -3 -2 -1
# Bottom Face
v -0.53 0.00 0.09
v 0.04 0.00 -0.09
v -0.14 0.00 -0.67
v -0.71 0.00 -0.49
f -4 -3 -2 -1
g light
v -0.24 1.98 0.16
v -0.24 1.98 -0.22
v 0.23 1.98 -0.22
v 0.23 1.98 0.16
f -4 -3 -2 -1";
pub const SPP_PER_DISPATCH: u32 = 1;
fn run_pt(device: Device) {
let mut buf = std::io::BufReader::new(CBOX_OBJ.as_bytes());
let (models, _) = tobj::load_obj_buf(
&mut buf,
&tobj::LoadOptions {
triangulate: true,
..Default::default()
},
|p| tobj::load_mtl(p),
)
.unwrap();
let vertex_heap = device.create_bindless_array(65536);
let index_heap = device.create_bindless_array(65536);
let mut vertex_buffers: Vec<Buffer<[f32; 3]>> = vec![];
let mut index_buffers: Vec<Buffer<Index>> = vec![];
let accel = device.create_accel(AccelOption::default());
let stream = device.create_stream(StreamTag::Graphics);
stream.with_scope(|s| {
let mut cmds = vec![];
for (index, model) in models.iter().enumerate() {
let vertex_buffer = device.create_buffer(model.mesh.positions.len() / 3);
let index_buffer = device.create_buffer(model.mesh.indices.len() / 3);
let mesh = device.create_mesh(
vertex_buffer.view(..),
index_buffer.view(..),
AccelOption::default(),
);
cmds.push(vertex_buffer.view(..).copy_from_async(unsafe {
let vertex_ptr = model.mesh.positions.as_ptr();
std::slice::from_raw_parts(
vertex_ptr as *const [f32; 3],
model.mesh.positions.len() / 3,
)
}));
cmds.push(index_buffer.view(..).copy_from_async(unsafe {
let index_ptr = model.mesh.indices.as_ptr();
std::slice::from_raw_parts(index_ptr as *const Index, model.mesh.indices.len() / 3)
}));
vertex_buffers.push(vertex_buffer);
index_buffers.push(index_buffer);
vertex_heap.emplace_buffer_async(index, vertex_buffers.last().unwrap());
index_heap.emplace_buffer_async(index, index_buffers.last().unwrap());
cmds.push(mesh.build_async(AccelBuildRequest::ForceBuild));
accel.push_mesh(&mesh, Mat4::identity(), 255, true);
}
cmds.push(vertex_heap.update_async());
cmds.push(index_heap.update_async());
cmds.push(accel.build_async(AccelBuildRequest::ForceBuild));
s.submit(cmds);
s.synchronize();
});
// use create_kernel_async to compile multiple kernels in parallel
let path_tracer = Kernel::<
fn(Tex2d<Float4>, Tex2d<Float4>, Tex2d<Float4>, Tex2d<u32>, Accel, Uint2),
>::new_async(
&device,
&track!(|image: Tex2dVar<Float4>,
albedo_image: Tex2dVar<Float4>,
normal_image: Tex2dVar<Float4>,
seed_image: Tex2dVar<u32>,
accel: AccelVar,
resolution: Expr<Uint2>| {
set_block_size([16u32, 16u32, 1u32]);
let cbox_materials = ([
Float3::new(0.725f32, 0.710f32, 0.680f32), // floor
Float3::new(0.725f32, 0.710f32, 0.680f32), // ceiling
Float3::new(0.725f32, 0.710f32, 0.680f32), // back wall
Float3::new(0.140f32, 0.450f32, 0.091f32), // right wall
Float3::new(0.630f32, 0.065f32, 0.050f32), // left wall
Float3::new(0.725f32, 0.710f32, 0.680f32), // short box
Float3::new(0.725f32, 0.710f32, 0.680f32), // tall box
Float3::new(0.000f32, 0.000f32, 0.000f32), // light
])
.expr();
let lcg = |state: Var<u32>| -> Expr<f32> {
let lcg = Callable::<fn(Var<u32>) -> Expr<f32>>::new_static(|state: Var<u32>| {
const LCG_A: u32 = 1664525u32;
const LCG_C: u32 = 1013904223u32;
*state = LCG_A * state + LCG_C;
(state & 0x00ffffffu32).as_f32() * (1.0f32 / 0x01000000u32 as f32)
});
lcg.call(state)
};
let make_ray =
|o: Expr<Float3>, d: Expr<Float3>, tmin: Expr<f32>, tmax: Expr<f32>| -> Expr<Ray> {
Ray::from_comps_expr(RayComps {
orig: o.into(),
tmin: tmin,
dir: d.into(),
tmax: tmax,
})
};
let generate_ray = |p: Expr<Float2>| -> Expr<Ray> {
let fov = escape!({
const FOV: f32 = 27.8f32 * std::f32::consts::PI / 180.0f32;
FOV
});
let origin = Float3::expr(-0.01f32, 0.995f32, 5.0f32);
let pixel = origin
+ Float3::expr(
p.x * escape!(f32::tan(0.5f32 * fov)),
p.y * escape!(f32::tan(0.5f32 * fov)),
-1.0f32,
);
let direction = (pixel - origin).normalize();
make_ray(origin, direction, 0.0f32.expr(), f32::MAX.expr())
};
let balanced_heuristic =
|pdf_a: Expr<f32>, pdf_b: Expr<f32>| pdf_a / luisa::max(pdf_a + pdf_b, 1e-4f32);
let make_onb = |normal: Expr<Float3>| -> Expr<Onb> {
let binormal = if normal.x.abs() > normal.z.abs() {
Float3::expr(-normal.y, normal.x, 0.0f32)
} else {
Float3::expr(0.0f32, -normal.z, normal.y)
};
let tangent = binormal.cross(normal).normalize();
Onb::new_expr(tangent, binormal, normal)
};
let cosine_sample_hemisphere = |u: Expr<Float2>| {
let r = u.x.sqrt();
let phi = 2.0f32 * std::f32::consts::PI * u.y;
Float3::expr(r * phi.cos(), r * phi.sin(), (1.0f32 - u.x).sqrt())
};
let coord = dispatch_id().xy();
let frame_size = luisa::min(resolution.x, resolution.y).as_f32();
let state = Var::<u32>::zeroed();
state.store(seed_image.read(coord));
let rx = lcg(state);
let ry = lcg(state);
let pixel = (coord.as_float2() + Float2::expr(rx, ry)) / frame_size * 2.0f32 - 1.0f32;
let radiance = Var::<Float3>::zeroed();
radiance.store(Float3::expr(0.0f32, 0.0f32, 0.0f32));
for _ in 0..SPP_PER_DISPATCH as u32 {
let init_ray = generate_ray(pixel * Float2::expr(1.0f32, -1.0f32));
let ray = Var::<Ray>::zeroed();
ray.store(init_ray);
let beta = Var::<Float3>::zeroed();
beta.store(Float3::expr(1.0f32, 1.0f32, 1.0f32));
let pdf_bsdf = Var::<f32>::zeroed();
pdf_bsdf.store(0.0f32);
let light_position = Float3::expr(-0.24f32, 1.98f32, 0.16f32);
let light_u = Float3::expr(-0.24f32, 1.98f32, -0.22f32) - light_position;
let light_v = Float3::expr(0.23f32, 1.98f32, 0.16f32) - light_position;
let light_emission = Float3::expr(17.0f32, 12.0f32, 4.0f32);
let light_area = light_u.cross(light_v).length();
let light_normal = light_u.cross(light_v).normalize();
let depth = Var::<u32>::zeroed();
while depth < 10u32 {
let hit = accel.trace_closest(**ray);
if !hit.valid() {
break;
}
let vertex_buffer = vertex_heap.var().buffer::<[f32; 3]>(hit.inst_id);
let triangle = index_heap
.var()
.buffer::<Index>(hit.inst_id)
.read(hit.prim_id);
let p0: Expr<Float3> = vertex_buffer.read(triangle[0]).into();
let p1: Expr<Float3> = vertex_buffer.read(triangle[1]).into();
let p2: Expr<Float3> = vertex_buffer.read(triangle[2]).into();
let p = p0 * (1.0f32 - hit.u - hit.v) + p1 * hit.u + p2 * hit.v;
let n = (p1 - p0).cross(p2 - p0).normalize();
let origin: Expr<Float3> = (**ray.orig).into();
let direction: Expr<Float3> = (**ray.dir).into();
let cos_wi = -direction.dot(n);
if cos_wi < 1e-4f32 {
break;
}
let pp = offset_ray_origin(p, n);
let albedo = cbox_materials.read(hit.inst_id);
if depth == 0 {
albedo_image
.write(coord, Float4::expr(albedo.x, albedo.y, albedo.z, 1.0f32));
normal_image.write(coord, Float4::expr(n.x, n.y, n.z, 1.0f32));
}
// hit light
if hit.inst_id == 7u32 {
if depth == 0u32 {
radiance.store(radiance + light_emission);
} else {
let pdf_light = (p - origin).length_squared() / (light_area * cos_wi);
let mis_weight = balanced_heuristic(**pdf_bsdf, pdf_light);
radiance.store(radiance + mis_weight * beta * light_emission);
}
break;
} else {
// sample light
let ux_light = lcg(state);
let uy_light = lcg(state);
let p_light = light_position + ux_light * light_u + uy_light * light_v;
let pp_light = offset_ray_origin(p_light, light_normal);
let d_light = (pp - pp_light).length();
let wi_light = (pp_light - pp).normalize();
let shadow_ray =
make_ray(offset_ray_origin(pp, n), wi_light, 0.0f32.expr(), d_light);
let occluded = accel.trace_any(shadow_ray);
let cos_wi_light = wi_light.dot(n);
let cos_light = -light_normal.dot(wi_light);
if !occluded && cos_wi_light > 1e-4f32 && cos_light > 1e-4f32 {
let pdf_light = (d_light * d_light) / (light_area * cos_light);
let pdf_bsdf = cos_wi_light * std::f32::consts::FRAC_1_PI;
let mis_weight = balanced_heuristic(pdf_light, pdf_bsdf);
let bsdf = albedo * std::f32::consts::FRAC_1_PI * cos_wi_light;
*radiance += beta * bsdf * mis_weight * light_emission
/ luisa::max(pdf_light, 1e-4f32);
}
}
// sample BSDF
let onb = make_onb(n);
let ux = lcg(state);
let uy = lcg(state);
let new_direction =
onb.to_world(cosine_sample_hemisphere(Float2::expr(ux, uy)));
let cos_wi = new_direction.dot(n).abs();
*ray = make_ray(pp, new_direction, 0.0f32.expr(), std::f32::MAX.expr());
*beta *= albedo;
pdf_bsdf.store(cos_wi * std::f32::consts::FRAC_1_PI);
// russian roulette
let l = Float3::expr(0.212671f32, 0.715160f32, 0.072169f32).dot(beta);
if l == 0.0f32 {
break;
}
let q = luisa::max(l, 0.05f32);
let r = lcg(state);
if r > q {
break;
}
*beta = beta / q;
*depth += 1;
}
}
radiance.store(radiance / SPP_PER_DISPATCH as f32);
seed_image.write(coord, state);
if radiance.is_nan().any() {
radiance.store(Float3::expr(0.0f32, 0.0f32, 0.0f32));
}
let radiance = radiance.clamp(
Float3::splat_expr(0.0f32.expr()),
Float3::splat_expr(30.0f32.expr()),
);
let old = image.read(dispatch_id().xy());
let spp = old.w;
let radiance = radiance + old.xyz();
image.write(
dispatch_id().xy(),
Float4::expr(radiance.x, radiance.y, radiance.z, spp + 1.0f32),
);
}),
);
let img_w = 1024u32;
let img_h = 1024u32;
let color_buf = device.create_buffer::<Float4>((img_w * img_h) as usize);
let albedo_buf = device.create_buffer::<Float4>((img_w * img_h) as usize);
let normal_buf = device.create_buffer::<Float4>((img_w * img_h) as usize);
let output_buf = device.create_buffer::<Float4>((img_w * img_h) as usize);
let ext = device
.denoiser_ext()
.unwrap_or_else(|| panic!("denoiser not available on current device"));
let mut denoiser = ext.create(&device.default_stream());
{
let mut inputs = DenoiserInput::new(img_w, img_h);
inputs.push_noisy_image(
&color_buf.view(..),
&output_buf.view(..),
ImageFormat::Float3,
ImageColorSpace::Hdr,
None,
);
inputs.push_feature_image(
"albedo",
&albedo_buf.view(..),
ImageFormat::Float3,
ImageColorSpace::Hdr,
);
inputs.push_feature_image(
"normal",
&normal_buf.view(..),
ImageFormat::Float3,
ImageColorSpace::Hdr,
);
inputs.noisy_features(false);
inputs.prefilter_mode(PrefilterMode::None);
denoiser.init(inputs);
}
let acc_to_hdr = Kernel::<fn(Tex2d<Float4>, Tex2d<Float4>)>::new_async(
&device,
&track!(|acc, hdr| {
set_block_size([16, 16, 1]);
let coord = dispatch_id().xy();
let radiance = acc.read(coord);
let spp = radiance.w;
let radiance = radiance.xyz() / spp;
hdr.write(
coord,
Float4::expr(radiance.x, radiance.y, radiance.z, 1.0f32),
);
}),
);
let display = Kernel::<fn(Tex2d<Float4>, Tex2d<Float4>)>::new_async(
&device,
&track!(|hdr, display| {
set_block_size([16, 16, 1]);
let coord = dispatch_id().xy();
let radiance = hdr.read(coord).xyz();
let r = 1.055f32 * radiance.powf(1.0 / 2.4f32) - 0.055;
let srgb = radiance.lt(0.0031308).select(radiance * 12.92, r);
display.write(coord, Float4::expr(srgb.x, srgb.y, srgb.z, 1.0f32));
}),
);
let albedo_img = device.create_tex2d::<Float4>(PixelStorage::Float4, img_w, img_h, 1);
let normal_img = device.create_tex2d::<Float4>(PixelStorage::Float4, img_w, img_h, 1);
let hdr_img = device.create_tex2d::<Float4>(PixelStorage::Float4, img_w, img_h, 1);
let acc_img = device.create_tex2d::<Float4>(PixelStorage::Float4, img_w, img_h, 1);
let seed_img = device.create_tex2d::<u32>(PixelStorage::Int1, img_w, img_h, 1);
{
let mut rng = rand::thread_rng();
let seed_buffer = (0..img_w * img_h)
.map(|_| rng.gen::<u32>())
.collect::<Vec<_>>();
seed_img.view(0).copy_from(&seed_buffer);
}
let event_loop = EventLoop::new().unwrap();
let window = winit::window::WindowBuilder::new()
.with_title("Luisa Compute Rust - Ray Tracing")
.with_inner_size(winit::dpi::LogicalSize::new(img_w, img_h))
.with_resizable(false)
.build(&event_loop)
.unwrap();
let swapchain = device.create_swapchain(
&window,
&device.default_stream(),
img_w,
img_h,
false,
false,
3,
);
let display_img = device.create_tex2d::<Float4>(swapchain.pixel_storage(), img_w, img_h, 1);
event_loop.set_control_flow(ControlFlow::Poll);
event_loop
.run(move |event, elwt| {
match event {
WinitEvent::WindowEvent {
event: WindowEvent::CloseRequested,
window_id,
} if window_id == window.id() => {
// FIXME: support half4 pixel storage
let mut img_buffer = vec![[0u8; 4]; (img_w * img_h) as usize];
{
let scope = device.default_stream().scope();
scope.submit([display_img.view(0).copy_to_async(&mut img_buffer)]);
}
{
let img = image::RgbImage::from_fn(img_w, img_h, |x, y| {
let i = x + y * img_w;
let px = img_buffer[i as usize];
Rgb([px[0], px[1], px[2]])
});
img.save("cbox.png").unwrap();
}
elwt.exit();
}
WinitEvent::AboutToWait => {
window.request_redraw();
}
WinitEvent::WindowEvent {
event: WindowEvent::RedrawRequested,
window_id,
} if window_id == window.id() => {
let tic = Instant::now();
{
let scope = device.default_stream().scope();
scope.present(&swapchain, &display_img);
scope.submit([
path_tracer.dispatch_async(
[img_w, img_h, 1],
&acc_img,
&albedo_img,
&normal_img,
&seed_img,
&accel,
&Uint2::new(img_w, img_h),
),
acc_to_hdr.dispatch_async([img_w, img_h, 1], &acc_img, &hdr_img),
hdr_img.view(0).copy_to_buffer_async(&color_buf.view(..)),
albedo_img
.view(0)
.copy_to_buffer_async(&albedo_buf.view(..)),
normal_img
.view(0)
.copy_to_buffer_async(&normal_buf.view(..)),
]);
denoiser.execute(true);
scope.submit([
hdr_img.view(0).copy_from_buffer_async(&output_buf.view(..)),
display.dispatch_async([img_w, img_h, 1], &hdr_img, &display_img),
]);
}
let toc = Instant::now();
let elapsed = (toc - tic).as_secs_f32();
log::info!(
"time: {}ms {}ms/spp",
elapsed * 1e3,
elapsed * 1e3 / SPP_PER_DISPATCH as f32
);
window.request_redraw();
}
_ => (),
}
})
.unwrap();
}