-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
152 lines (121 loc) · 4.32 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Copyright (c) 2007 Alexander Strange <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "raytrace.h"
#include "tests.h"
#if 0
static primitive **lots_of_spheres(int *pi)
{
primitive **prims = new primitive*[500];
prims[0] = new plane_prim(vector3(0,1,0), 4.4);
prims[1] = new sphere(point3(2, .8, 3), 2.5);
prims[2] = new sphere(point3(-5.5, -.5, 7), 2);
prims[3] = new sphere(point3(0,5,5), .1);
prims[4] = new sphere(point3(-3, 5, 1), .1);
prims[5] = new sphere(point3(-1.5, -3.8, 1), 1.5);
prims[6] = new plane_prim(vector3(.4,0,-1), 12);
prims[7] = new plane_prim(vector3(0,-1,0), 7.4);
prims[0]->mat.c = color(.4,.3,.3);
prims[0]->mat.diffuse = 1;
prims[1]->mat.c = color(.7,.7,1);
prims[1]->mat.diffuse = .2;
prims[1]->mat.reflect = 0;
prims[1]->mat.transmittance = .8;
prims[1]->mat.dielectric = true;
prims[1]->mat.refractive_index = 1.31;
prims[2]->mat.c = color(.7,.7,1.);
prims[2]->mat.reflect = .5;
prims[2]->mat.clear_reflect = false;
prims[2]->mat.diffuse = .1;
prims[3]->mat.c = color(.4,.4,.4);
prims[3]->light = true;
prims[4]->mat.c = color(.6,.6,.6);
prims[4]->light = true;
prims[5]->mat.c = color(1,.4,.4);
prims[5]->mat.diffuse = .2;
prims[6]->mat.c = color(.5,.3,.5);
prims[6]->mat.diffuse = .6;
prims[7]->mat.c = color(.4,.7,.7);
prims[7]->mat.diffuse = .5;
int primi = 8;
for (int x = 0; x < 8; x++)
for (int y = 0; y < 7; y++) {
prims[primi] = new sphere(vector3(-4.5 + x * 1.5, -4.3 + y * 1.5, 10), .3);
prims[primi]->mat.diffuse = .6;
prims[primi]->mat.c = color(.3,1,.4);
primi++;
}
*pi = primi;
return prims;
}
#endif
static void set_color(primitive *p, color4 c)
{
p->mat.textures[0].tex = new flat_texture(c);
p->mat.texcount = 1;
}
static primitive **checkerboard_scene(int *pi)
{
primitive **prims = new primitive*[6];
prims[0] = new plane_prim(vector3(0,1,0), 2);
prims[1] = new plane_prim(vector3(0,0,-1), 15);
prims[2] = new sphere(vector3(-2.4, 1.8, 3), 2);
prims[3] = new sphere(vector3(2.4, 1.8, 3), 2);
prims[4] = new sphere(vector3(0, 10, -1), .2);
prims[5] = new sphere(vector3(0, -.2, 7), 2);
set_color(prims[0], color4(.7,.7,.7));
prims[0]->mat.diffuse = 1;
prims[1]->mat.textures[prims[1]->mat.texcount++].tex = new checkerboard_texture(color4(1,.1,.1),color4(.1,.15,1));
prims[1]->mat.textures[prims[1]->mat.texcount++].tex = new image_texture("caro.png", true);
prims[1]->mat.textures[1].uScale = prims[1]->mat.textures[1].vScale = 50.;
prims[1]->mat.textures[1].vShift = 12*50;
prims[1]->mat.textures[1].uShift = 12*50;
prims[1]->mat.diffuse = .7;
set_color(prims[2], color4(.7,.9,.7));
prims[2]->mat.reflect = 0;
prims[2]->med.transmittance = .8;
prims[2]->mat.diffuse = .1;
set_color(prims[3], color4(.7,.7,.7));
prims[3]->mat.reflect = 0;
prims[3]->med.transmittance = 1;
prims[3]->mat.diffuse = .1;
prims[3]->med.refractive_index = 1.1;
prims[3]->mat.dielectric = true;
set_color(prims[4], color4(5,5,5));
prims[4]->light = true;
set_color(prims[5], color4(.75,.75,.4));
//prims[5]->mat.textures[0].tex = new checkerboard_texture(color(1,.1,.1),color(.1,.15,1));
//prims[5]->mat.texcount++;
prims[5]->mat.diffuse =.1;
prims[5]->mat.reflect =.5;
prims[5]->mat.clear_reflect = false;
*pi = 6;
return prims;
}
int main (int argc, char * const argv[]) {
size_t w = 1280, h = 960;
camera cam;
int primi;
//primitive **prims = lots_of_spheres(&primi);
primitive **prims = checkerboard_scene(&primi);
raytracer tr(prims,primi);
cam.origin = point3(0,0,-5);
cam.screen.origin = point3(0,0,0);
cam.screen.w = 8;
cam.screen.h = 6;
//run_tests();
tr.render(w,h,cam)->write_to_bmp("scene.bmp");
return 0;
}