examples: improve progressbar in path_tracing.v

pull/10772/head
Delyan Angelov 2021-07-12 07:53:22 +03:00
parent 719bf63f16
commit de9aa987bc
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 7 additions and 2 deletions

View File

@ -28,6 +28,7 @@ import os
import math import math
import rand import rand
import time import time
import term
const ( const (
inf = 1e+10 inf = 1e+10
@ -366,6 +367,7 @@ const (
fn radiance(r Ray, depthi int, scene_id int) Vec { fn radiance(r Ray, depthi int, scene_id int) Vec {
if depthi > 1024 { if depthi > 1024 {
eprintln('depthi: $depthi') eprintln('depthi: $depthi')
eprintln('')
return Vec{} return Vec{}
} }
mut depth := depthi // actual depth in the reflection tree mut depth := depthi // actual depth in the reflection tree
@ -506,7 +508,8 @@ fn ray_trace(w int, h int, samps int, file_name string, scene_id int) Image {
// OpenMP injection point! #pragma omp parallel for schedule(dynamic, 1) shared(c) // OpenMP injection point! #pragma omp parallel for schedule(dynamic, 1) shared(c)
for y := 0; y < h; y++ { for y := 0; y < h; y++ {
eprint('\rRendering (${samps * 4} spp) ${(100.0 * f64(y)) / (f64(h) - 1.0):5.2f}%') term.cursor_up(1)
eprintln('Rendering (${samps * 4} spp) ${(100.0 * f64(y)) / (f64(h) - 1.0):5.2f}%')
for x in 0 .. w { for x in 0 .. w {
i := (h - y - 1) * w + x i := (h - y - 1) * w + x
mut ivec := unsafe { &image.data[i] } mut ivec := unsafe { &image.data[i] }
@ -566,10 +569,12 @@ fn main() {
t1 := time.ticks() t1 := time.ticks()
eprintln('Path tracing samples: $samples, file_name: $file_name, scene_id: $scene_id, width: $width, height: $height')
eprintln('')
image := ray_trace(width, height, samples, file_name, scene_id) image := ray_trace(width, height, samples, file_name, scene_id)
t2 := time.ticks() t2 := time.ticks()
eprintln('\nRendering finished. Took: ${(t2 - t1):5}ms') eprintln('Rendering finished. Took: ${(t2 - t1):5}ms')
image.save_as_ppm(file_name) image.save_as_ppm(file_name)
t3 := time.ticks() t3 := time.ticks()