17
17
#include " camera.h"
18
18
19
19
struct Progress {
20
- int num;
20
+ int num = 0 ;
21
21
int total;
22
22
std::chrono::system_clock::time_point start;
23
23
double delta_t = 0 ;
24
+ double previous_elapsed_time = 0 ;
25
+ int count = 0 ;
26
+ int unit;
24
27
25
- Progress (int total) : num(0 ), total(total) , start(std::chrono::system_clock::now()){}
28
+ Progress (int total) : total(total), start(std::chrono::system_clock::now()), previous_elapsed_time(elapsed()),
29
+ unit (total / 400 ) {}
26
30
27
31
void show () {
28
- double percent = (double )num / total * 100 ;
29
- delta_t += 1 . / std::max (elapsed (), 1 .) * (elapsed () / std::max (num, 1 ) - delta_t );
32
+ double elapsed_time = elapsed ();
33
+ double percent = (double ) num / total * 100 ;
34
+
35
+ double recently_delta_t = num ? (elapsed_time - previous_elapsed_time) / (num - unit * count) : 0 ;
36
+ if (num >= unit * (count + 1 )) {
37
+ count = num / unit;
38
+ previous_elapsed_time = elapsed_time;
39
+ }
40
+ delta_t += 0.005 / std::max (elapsed_time, 1 .) * (recently_delta_t - delta_t );
30
41
double remain = delta_t * (total - num);
31
42
std::cout << " \r " << std::fixed << std::setprecision (2 ) <<
32
- percent << " %\t remain: " << (int )remain << " [s]" << std::flush;
43
+ percent << " %\t remain: " << (int ) remain << " [s] \t total: " << elapsed_time << " [s]" << std::flush;
33
44
}
34
45
35
46
double elapsed () {
36
- return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now () - start).count () / 1000 .;
47
+ return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now () - start).count () /
48
+ 1000 .;
37
49
}
38
50
39
51
void end () {
@@ -42,35 +54,37 @@ struct Progress {
42
54
};
43
55
44
56
int main () {
45
- Image img (512 , 512 );
57
+ Image img (256 , 256 );
46
58
47
- // コーネルボックス
59
+ // コーネルボックス
48
60
// std::vector<std::shared_ptr<ShapeBase>> shapes{
49
- // std::make_shared<Sphere>(Vector3(0, 10003.5, 0), 10000, Vector3(), Diffuse(Vector3(0.75))), // 上壁
50
- // std::make_shared<Sphere>(Vector3(10004, 0, 0), 10000, Vector3(), Diffuse(Vector3(0.25, 0.25, 0.75))) , //右壁
51
- // std::make_shared<Sphere>(Vector3(0, -10003.5, 0), 10000, Vector3(), Diffuse(Vector3(0.75))), // 下壁
52
- // std::make_shared<Sphere>(Vector3(-10004, 0, 0), 10000, Vector3(), Diffuse(Vector3(0.75, 0.25, 0.25))), // 左壁
53
- // std::make_shared<Sphere>(Vector3(0, 0, 10004), 10000, Vector3(0), Diffuse(Vector3(0.75))), // 奥壁
54
- // std::make_shared<Sphere>(Vector3(0, 23.48, 2), 20, Vector3(12), Diffuse(Vector3())), // ライト
61
+ // std::make_shared<Sphere>(Vector3(0, 10003.5, 0), 10000, Vector3(), Diffuse(Vector3(0.75))), // 上壁
62
+ // std::make_shared<Sphere>(Vector3(10004, 0, 0), 10000, Vector3(), Diffuse(Vector3(0.25, 0.25, 0.75))), //右壁
63
+ // std::make_shared<Sphere>(Vector3(0, -10003.5, 0), 10000, Vector3(), Diffuse(Vector3(0.75))), // 下壁
64
+ // std::make_shared<Sphere>(Vector3(-10004, 0, 0), 10000, Vector3(), Diffuse(Vector3(0.75, 0.25, 0.25))), // 左壁
65
+ // std::make_shared<Sphere>(Vector3(0, 0, 10004), 10000, Vector3(0), Diffuse(Vector3(0.75))), // 奥壁
66
+ // std::make_shared<Sphere>(Vector3(0, 23.48, 2), 20, Vector3(12), Diffuse(Vector3())), // ライト
55
67
//
56
- // std::make_shared<Sphere>(Vector3(-2, -2.3, 3), 1.2, Vector3(), Diffuse(Vector3(0.999))),
57
- // std::make_shared<Sphere>(Vector3(2, -2.3, 2), 1.2, Vector3(), Diffuse(Vector3(0.25, 0.75, 0.25))),
58
- // };
68
+ // std::make_shared<Sphere>(Vector3(-2, -2.3, 3), 1.2, Vector3(), Diffuse(Vector3(0.999))),
69
+ // std::make_shared<Sphere>(Vector3(2, -2.3, 2), 1.2, Vector3(), Diffuse(Vector3(0.25, 0.75, 0.25))),
70
+ // std::make_shared<ParallelLight>(Vector3(0, 0, -1), M_PI * 15/180, Vector3(1), Diffuse(Vector3(0))),
71
+ // };
59
72
60
73
// 球
61
74
std::vector<std::shared_ptr<ShapeBase>> shapes{
62
75
std::make_shared<Sphere>(Vector3 (0 , -10004 , 0 ), 10000 , Vector3 (), Diffuse (Vector3 (0.75 ))),
63
76
std::make_shared<Sphere>(Vector3 (-2 , -2.8 , 3 ), 1.2 , Vector3 (), Diffuse (Vector3 (0.999 ))),
64
77
std::make_shared<Sphere>(Vector3 (2 , -2.8 , 2 ), 1.2 , Vector3 (), Diffuse (Vector3 (0.25 , 0.75 , 0.25 ))),
65
78
std::make_shared<Sphere>(Vector3 (0 , -3 , 6 ), 1 , Vector3 (), Fuzz (Vector3 (0.75 ), 0.2 * M_PI)),
66
- std::make_shared<ParallelLight>(Vector3 (1 , 2 , 1 ), M_PI * 30 /180 , Vector3 (2 ), Diffuse (Vector3 (0 ))) // 太陽の半頂角
79
+ std::make_shared<ParallelLight>(Vector3 (1 , 2 , 1 ), M_PI * 15 /180 , Vector3 (1 ), Diffuse (Vector3 (0 ))),
67
80
};
68
81
69
- Scene scene (shapes, Vector3 (0.5 , 0.6 , 0.9 ), 1024 , 100 );
70
- std::shared_ptr<CameraBase> camera = std::make_shared<NormalCamera>(img, Vector3 (0 , 0 , -6 ), Vector3 (0 ), M_PI*3 /8 );
82
+ Scene scene (shapes, Vector3 (0.15 , 0.2 , 0.35 ), 4 *1000 , 1e5 );
83
+ std::shared_ptr<CameraBase> camera = std::make_shared<NormalCamera>(
84
+ img, Vector3 (0 , 0 , -6 ), Vector3 (0 ), M_PI * 3 / 8 );
71
85
Progress progress (img.size );
72
86
73
- #pragma omp parallel for schedule(auto )
87
+ #pragma omp parallel for schedule(dynamic, 1 )
74
88
for (int x = 0 ; x < img.width ; ++x) {
75
89
for (int y = 0 ; y < img.height ; ++y) {
76
90
#ifdef NDEBUG
@@ -89,7 +103,6 @@ int main() {
89
103
img.set_pixel (x, y, L / scene.spp );
90
104
}
91
105
}
92
-
93
106
img.output_ppm (" ./result.ppm" );
94
107
progress.end ();
95
108
return 0 ;
0 commit comments