branch | pyrit |
changeset 88 | f7edb3b90816 |
parent 81 | 9dbb9c8c115b |
child 91 | 9d66d323c354 |
87:1081e3dd3f3e | 88:f7edb3b90816 |
---|---|
1 #include "raytracer.h" |
1 #include "raytracer.h" |
2 #include "octree.h" |
2 #include "octree.h" |
3 |
3 |
4 #include "image.h" |
|
5 #include "common_sdl.h" |
4 #include "common_sdl.h" |
6 |
5 |
7 Camera cam(Vector3(0.,6.,6.), Vector3(0.,2.,-7.), Vector3(0.,0.,-1.)); |
6 Camera cam(Vector3(0.,6.,6.), Vector3(0.,2.,-7.), Vector3(0.,0.,-1.)); |
8 Light light(Vector3(-2.0, 10.0, -2.0), Colour(0.9, 0.9, 0.9)); |
7 Light light(Vector3(-2.0, 10.0, -2.0), Colour(0.9, 0.9, 0.9)); |
9 |
8 |
139 |
138 |
140 /* render image */ |
139 /* render image */ |
141 if (argc == 2 && !strcmp(argv[1], "-r")) |
140 if (argc == 2 && !strcmp(argv[1], "-r")) |
142 { |
141 { |
143 pyrit_verbosity = 2; |
142 pyrit_verbosity = 2; |
144 Float *fdata = (Float *) malloc(w*h*3*sizeof(Float)); |
|
145 rt.ambientOcclusion(300, 5.0, 0.5); |
143 rt.ambientOcclusion(300, 5.0, 0.5); |
146 DefaultSampler sampler(fdata, w, h); |
144 DefaultSampler sampler(w, h); |
147 sampler.setOversample(2); |
145 sampler.setOversample(2); |
148 sampler.setSubsample(1); |
146 sampler.setSubsample(1); |
149 rt.setSampler(&sampler); |
147 rt.setSampler(&sampler); |
150 rt.render(); |
148 rt.render(); |
151 |
149 sampler.getPixmap().writePNG("textures.png"); |
152 struct image *img; |
|
153 new_image(&img, w, h, 3); |
|
154 |
|
155 Float *fd = fdata; |
|
156 for (unsigned char *cd = img->data; cd != img->data + w*h*3; cd++, fd++) { |
|
157 if (*fd > 1.0) |
|
158 *cd = 255; |
|
159 else |
|
160 *cd = (unsigned char)(*fd * 255.0); |
|
161 } |
|
162 free(fdata); |
|
163 save_png("textures.png", img); |
|
164 destroy_image(&img); |
|
165 } |
150 } |
166 } |
151 } |