@@ -28,40 +28,20 @@ namespace {
28
28
return hit;
29
29
}
30
30
31
- [[nodiscard]] auto make_random_scene () noexcept
31
+ [[nodiscard]] auto make_scene () noexcept
32
32
{
33
33
auto scene = Scene ();
34
34
35
35
// Add ground
36
- scene.emplace_back (sf::Vector3f (0 , -1000 , 0 ), 1000 .f , Lambertian { { 0.5 , 0.5 , 0.5 } });
36
+ scene.emplace_back (sf::Vector3f (0 , -1000 , 0 ), 1000 .f , Lambertian { { 0 .3f , 0 .6f , 0 .1f } });
37
37
38
38
// Add fixed large spheres
39
- scene.emplace_back (sf::Vector3f (-4 , 1 , 0 ), 1 .f , Lambertian { { 0 .4f , 0 .2f , 0 .1f } });
40
- scene.emplace_back (sf::Vector3f (0 , 1 , 0 ), 1 .f , Dielectric { 1 .5f });
41
- scene.emplace_back (sf::Vector3f (4 , 1 , 0 ), 1 .f , Metal { { 0 .7f , 0 .6f , 0 .5f }, 0 .f });
42
-
43
- // Add random smaller spheres
44
- for (int i = -11 ; i < 11 ; ++i) {
45
- for (int j = -11 ; j < 11 ; ++j) {
46
- const auto center = sf::Vector3f (float (i) + random_float (0 , 0 .9f ), 0 .2f , float (j) + random_float (0 , 0 .9f ));
47
- if ((center - sf::Vector3f (4 , 0 .2f , 0 )).length () <= 0 .9f )
48
- continue ;
49
-
50
- auto material = Material ();
51
- if (std::bernoulli_distribution (0.8 )(rng ())) { // diffuse
52
- const auto albedo = random_vector (0 , 1 ).cwiseMul (random_vector (0 , 1 ));
53
- material = Lambertian { albedo };
54
- } else if (std::bernoulli_distribution (0.95 )(rng ())) { // metal
55
- const auto albedo = random_vector (0 .5f , 1 );
56
- const auto fuzz = random_float (0 , 0 .5f );
57
- material = Metal { albedo, fuzz };
58
- } else { // glass
59
- material = Dielectric { 1 .5f };
60
- }
61
-
62
- scene.emplace_back (center, 0 .2f , material);
63
- }
64
- }
39
+ scene.emplace_back (sf::Vector3f (-4 , 2 , 0 ), 2 .f , Lambertian { { 0 .2f , 0 .3f , 0 .7f } });
40
+ scene.emplace_back (sf::Vector3f (-0 .5f , 1.5 , 1 ), 1 .5f , Metal { { 0 .7f , 0 .4f , 0 .3f }, 1 .f });
41
+ scene.emplace_back (sf::Vector3f (1 .25f , 1 , 1 .5f ), 1 .f , Metal { { 0 .7f , 0 .6f , 0 .5f }, 0 .f });
42
+ scene.emplace_back (sf::Vector3f (3 , 0 .75f , 3 ), 0 .75f , Metal { { 0 .8f , 0 .2f , 0 .1f }, 0 .5f });
43
+ scene.emplace_back (sf::Vector3f (4 , 0 .5f , 5 ), 0 .5f , Metal { { 0 .8f , 0 .7f , 0 .1f }, 0 .f });
44
+ scene.emplace_back (sf::Vector3f (2 , 0.5 , 6 ), 0 .5f , Dielectric { 1 .5f });
65
45
66
46
return scene;
67
47
}
@@ -101,31 +81,31 @@ int main()
101
81
{
102
82
// Define constants
103
83
constexpr auto aspect_ratio = 3 .f / 2 ;
104
- constexpr auto image_height = 360 ;
84
+ constexpr auto image_height = 640 ;
105
85
constexpr auto image_width = int (aspect_ratio * image_height);
106
86
107
87
// Make image
108
88
auto image = sf::Image ();
109
89
image.create ({ image_width, image_height });
110
90
111
91
// Make scene
112
- const auto scene = make_random_scene ();
92
+ const auto scene = make_scene ();
113
93
114
94
// Make camera
115
95
const auto camera = []() {
116
- const auto look_from = sf::Vector3f (13 , 2 , 3 );
117
- const auto look_at = sf::Vector3f (0 , 0 , 0 );
96
+ const auto look_from = sf::Vector3f (5 , 1 . 25f , 10 );
97
+ const auto look_at = sf::Vector3f (0 , 1 , 0 );
118
98
const auto vup = sf::Vector3f (0 , 1 , 0 );
119
- const auto fov = sf::degrees (20 );
120
- const auto aperture = 0 .1f ;
121
- const auto focus_distance = 10 . f ;
99
+ const auto fov = sf::degrees (40 );
100
+ const auto aperture = 0 .04f ;
101
+ const auto focus_distance = (look_at - look_from). length () ;
122
102
return Camera (look_from, look_at, vup, fov, aspect_ratio, aperture, focus_distance);
123
103
}();
124
104
125
105
// Set up rendering logic
126
106
const auto render_rows = [&image, &scene, camera](const size_t thread_count) noexcept {
127
107
// Tuning parameters
128
- static constexpr auto samples_per_pixel = 50 ;
108
+ static constexpr auto samples_per_pixel = 100 ;
129
109
static constexpr auto max_depth = 10 ;
130
110
131
111
static auto current_row = std::atomic<unsigned >(0 );
0 commit comments