-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
89 lines (69 loc) · 1.98 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// Created by disconcision on 16/03/19.
//
#include "Objects/Ray.h"
#include "Objects/Camera.h"
#include "Objects/Image.h"
#include "Objects/Lights.h"
#include "constants.h"
#include "screen.h"
#include "field.h"
#include "march.h"
#include "shade.h"
#include <omp.h>
int main(int argc, char* argv[]) {
/* IMAGE PLANE */
unsigned width = (argc != 3) ? DEFAULT_WIDTH :
(unsigned) strtol(argv[1], nullptr,0);
unsigned height = (argc != 3) ? DEFAULT_HEIGHT :
(unsigned) strtol(argv[2], nullptr,0);
Image image(width, height);
/* CAMERA */
Camera camera(
1.0, // focal distance
1.0, // frame width
width/(double)height, // frame height
R3(0,1,5), // eye position
R3(0,-0.1,-1), // view direction
R3(0,1,0)); // up direction
/* LIGHTS */
Lights lights;
lights.add_directional(
R3(-1,-1,-1),
Color(0.8,0.8,0.8),
true);
/*
lights.add_directional(
R3(0,-1,0),
Color(0.4,0.4,0.4),
false);
*/
lights.add_directional(
R3(-0, 1, 0),
Color(0.0,0.3,0.8),
false);
lights.add_point(
R3(0, 0, 0),
Color(0.0,0.0,4.0),
true);
/*
* for each pixel (i,j) in the image plane,
* take a ray from the camera through that pixel,
* and march along that ray, returning a depth and
* a number of steps and a hit id.
* color the pixel based on those values.
*
*/
#pragma omp parallel num_threads(NUM_THREADS)
#pragma omp for schedule(dynamic,1)
for (unsigned i = 0; i < image.height; ++i) {
for (unsigned j = 0; j < image.width; ++j) {
Ray ray = screen_to_world(camera, image, i, j);
unsigned hit, steps;
R depth = march(ray, field, steps, hit);
Color c = shade(ray, field, lights, depth, steps, hit);
image.set_pixel(i, j, c);
}
}
image.to_file(FILENAME);
}