MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / render

Method render

examples/cuda/cpu/path_tracer/src/renderer.rs:50–141  ·  view source on GitHub ↗

Renders the scene and returns a final image buffer that can be displayed.

(&mut self, ui: &Ui)

Source from the content-addressed store, hash-verified

48
49 /// Renders the scene and returns a final image buffer that can be displayed.
50 pub fn render(&mut self, ui: &Ui) -> &[u8] {
51 self.cuda.info(ui);
52 self.cpu.info(ui, &self.system);
53 self.accumulated_samples += 1;
54
55 ui.separator();
56 ui.text(format!("Camera Pos: {:?}", self.camera.origin));
57 ui.text(format!("Camera Lookat: {:?}", self.camera.lookat));
58 ui.new_line();
59 ui.separator();
60 ui.text(format!("Current Sample: {}", self.accumulated_samples));
61 ui.separator();
62
63 let switched = ui.checkbox("Use CUDA", &mut self.running_on_gpu);
64
65 if switched {
66 self.clear_view(true);
67 }
68
69 if self.running_on_gpu {
70 ui.separator();
71 ui.text("Running on GPU");
72 ui.checkbox("Use OptiX", &mut self.use_optix);
73 ui.checkbox("OptiX Denoise", &mut self.denoise);
74 ui.separator();
75
76 let duration = self
77 .cuda
78 .render(self.use_optix)
79 .expect("Failed to render using CUDA backend");
80
81 ui.text(format!(
82 "Sampling time: {:.2}ms",
83 duration.as_secs_f32() * 1000.0
84 ));
85
86 let (output, denoising_time, postprocessing_time) = self
87 .cuda
88 .final_image(self.accumulated_samples, self.denoise)
89 .expect("Failed to get final image");
90
91 if self.denoise {
92 ui.text(format!(
93 "Denoising time: {:.2}ms",
94 denoising_time.as_secs_f32() * 1000.0
95 ));
96 } else {
97 ui.text("Denoising time: N/A");
98 }
99
100 ui.text(format!(
101 "Postprocessing time: {:.2}ms",
102 postprocessing_time.as_secs_f32() * 1000.0
103 ));
104
105 ui.text(format!(
106 "Total: {:.2}ms",
107 (postprocessing_time.as_secs_f32()

Callers

nothing calls this directly

Calls 8

clear_viewMethod · 0.80
as_ptrMethod · 0.80
from_raw_partsFunction · 0.50
infoMethod · 0.45
expectMethod · 0.45
final_imageMethod · 0.45
castMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected