Skip to content

Commit 9e524b3

Browse files
committed
Change scene
1 parent 2153ea9 commit 9e524b3

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

docs/raytracer.png

572 KB
Loading

src/Raytracer.cpp

+16-36
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,20 @@ namespace {
2828
return hit;
2929
}
3030

31-
[[nodiscard]] auto make_random_scene() noexcept
31+
[[nodiscard]] auto make_scene() noexcept
3232
{
3333
auto scene = Scene();
3434

3535
// 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 } });
3737

3838
// 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 });
6545

6646
return scene;
6747
}
@@ -101,31 +81,31 @@ int main()
10181
{
10282
// Define constants
10383
constexpr auto aspect_ratio = 3.f / 2;
104-
constexpr auto image_height = 360;
84+
constexpr auto image_height = 640;
10585
constexpr auto image_width = int(aspect_ratio * image_height);
10686

10787
// Make image
10888
auto image = sf::Image();
10989
image.create({ image_width, image_height });
11090

11191
// Make scene
112-
const auto scene = make_random_scene();
92+
const auto scene = make_scene();
11393

11494
// Make camera
11595
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);
11898
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();
122102
return Camera(look_from, look_at, vup, fov, aspect_ratio, aperture, focus_distance);
123103
}();
124104

125105
// Set up rendering logic
126106
const auto render_rows = [&image, &scene, camera](const size_t thread_count) noexcept {
127107
// Tuning parameters
128-
static constexpr auto samples_per_pixel = 50;
108+
static constexpr auto samples_per_pixel = 100;
129109
static constexpr auto max_depth = 10;
130110

131111
static auto current_row = std::atomic<unsigned>(0);

0 commit comments

Comments
 (0)