equal
deleted
inserted
replaced
1 #include "raytracer.h" |
1 #include "raytracer.h" |
2 #include "kdtree.h" |
2 #include "octree.h" |
|
3 |
3 #include "image.h" |
4 #include "image.h" |
|
5 #include "common_sdl.h" |
4 |
6 |
5 int main() |
7 int main(int argc, char **argv) |
6 { |
8 { |
7 Raytracer rt; |
9 Raytracer rt; |
8 rt.setThreads(2); |
|
9 rt.setOversample(0); |
10 rt.setOversample(0); |
10 rt.setSubsample(8); |
11 rt.setSubsample(8); |
11 |
12 |
12 KdTree top; |
13 Octree top; |
13 rt.setTop(&top); |
14 rt.setTop(&top); |
14 |
15 |
15 Light light1(Vector3(0.0, 5.0, -5.0), Colour(0.7, 0.3, 0.6)); |
16 Light light1(Vector3(0.0, 5.0, -5.0), Colour(0.7, 0.3, 0.6)); |
16 rt.addlight(&light1); |
17 rt.addlight(&light1); |
17 |
18 |
39 |
40 |
40 Camera cam; |
41 Camera cam; |
41 cam.setEye(Vector3(0,0,15)); |
42 cam.setEye(Vector3(0,0,15)); |
42 rt.setCamera(&cam); |
43 rt.setCamera(&cam); |
43 |
44 |
44 int w = 800; |
45 w = 800; |
45 int h = 600; |
46 h = 600; |
46 Float *fdata = (Float *) malloc(w*h*3*sizeof(Float)); |
|
47 rt.render(w, h, fdata); |
|
48 |
47 |
49 struct image *img; |
48 if (argc == 2 && !strcmp(argv[1], "-i")) |
50 new_image(&img, w, h, 3); |
49 loop_sdl(rt, cam); |
51 |
50 else |
52 Float *fd = fdata; |
51 { |
53 for (char *cd = img->data; cd != img->data + w*h*3; cd++, fd++) { |
52 Float *fdata = (Float *) malloc(w*h*3*sizeof(Float)); |
54 if (*fd > 1.0) |
53 rt.render(w, h, fdata); |
55 *cd = 255; |
54 |
56 else |
55 struct image *img; |
57 *cd = (unsigned char)(*fd * 255.0); |
56 new_image(&img, w, h, 3); |
|
57 |
|
58 Float *fd = fdata; |
|
59 for (char *cd = img->data; cd != img->data + w*h*3; cd++, fd++) { |
|
60 if (*fd > 1.0) |
|
61 *cd = 255; |
|
62 else |
|
63 *cd = (unsigned char)(*fd * 255.0); |
|
64 } |
|
65 free(fdata); |
|
66 save_png("spheres_shadow.png", img); |
|
67 destroy_image(&img); |
58 } |
68 } |
59 free(fdata); |
|
60 save_png("spheres_shadow.png", img); |
|
61 destroy_image(&img); |
|
62 } |
69 } |