-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
54 lines (50 loc) · 1.56 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Homepage: https://github.com/ananthvk/cpp-raytracer
#include "camera.hpp"
#include "colors.hpp"
#include "config.h"
#include "frombook.hpp"
#include "image.hpp"
#include "progressbar.hpp"
#include "raytracer.hpp"
#include "scene.hpp"
#include <functional>
#include <iostream>
#include <thread>
void gammacorrect(image &img, int gamma)
{
for (auto &i : img)
{
for (auto &j : i)
{
j = gamma_correction(j, gamma);
}
}
}
int main()
{
// TODO: Modify the random code so that each thread has a different random generator.
// TODO: Set VT terminal when compiling on windows
Config cfg;
cfg.samples_per_pixel = 100;
cfg.image_width = 400;
cfg.image_height = cfg.image_width * (9.0 / 16.0);
cfg.filename = "render.png";
MovableCamera cam(cfg);
Scene scene;
cam.debug_info(std::cout);
image rendered_img;
// A multi threaded render
int number_of_threads = std::max(std::thread::hardware_concurrency(), (unsigned int)1);
rendered_img = multi_threaded_render(cfg, cam, scene, number_of_threads);
gammacorrect(rendered_img, cfg.gamma);
std::cout << "Writing to disk....." << std::endl;
write_to_file(cfg.filename, rendered_img);
// A single threaded render
// cfg.filename = "output2-single.png";
// // cfg.samples_per_pixel *= number_of_threads;
// rendered_img = Renderer(cfg).render(cam, scene, true);
// gammacorrect(rendered_img, cfg.gamma);
// std::cout << "Writing to disk....." << std::endl;
// write_to_file(cfg.filename, rendered_img);
return 0;
}