-
Notifications
You must be signed in to change notification settings - Fork 3
/
smallpt.cu
56 lines (50 loc) · 1.68 KB
/
smallpt.cu
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
#include <stdlib.h>
#include <stdio.h>
#include <ctime>
#include <iostream>
#include "gpu.h"
inline double clamp(double x){ return x<0 ? 0 : x>1 ? 1 : x; }
inline int toInt(double x){ return int(pow(clamp(x),1/2.2)*255+.5); }
int main(){
freopen("../scene", "r", stdin);
int w=1024, h=768;
int samps;
std::cin >> samps;
samps /= 4;
Ray cam(Vec(50,52,295.6), Vec(0,-0.042612,-1).norm());
Vec cx=Vec(w*.5135/h), cy=(cx%cam.d).norm()*.5135, r, *c=new Vec[w*h];
clock_t t1, t2;
float mseconds;
t1 = clock();
ParallelBVH *B = new ParallelBVH();
t2 = clock();
mseconds = ((float)(t2 - t1))/ CLOCKS_PER_SEC;
std::cout << "Initialization took " << mseconds << "\n";
t1 = clock();
B->constructRadixTree();
t2 = clock();
mseconds = ((float)(t2 - t1))/ CLOCKS_PER_SEC;
std::cout << "Construct Radix Tree took " << mseconds << "\n";
t1 = clock();
B->constructBVHTree();
t2 = clock();
mseconds = ((float)(t2 - t1))/ CLOCKS_PER_SEC;
std::cout << "Construct BVH Tree took " << mseconds << "\n";
t1 = clock();
B->optimize();
t2 = clock();
mseconds = ((float)(t2 - t1))/ CLOCKS_PER_SEC;
std::cout << "Optimize BVH Tree took " << mseconds << "\n";
B->raytrace(c, w, h, samps, cam, cx, cy);
t1 = clock();
FILE *f = fopen("image.ppm", "w");
fprintf(f, "P3\n%d %d\n%d\n", w, h, 255);
for (int i=(h-1); i>=0; i--) {
for (int j=0; j<w; j++) {
fprintf(f,"%d %d %d ", toInt(c[i*w+j].x), toInt(c[i*w+j].y), toInt(c[i*w+j].z));
}
}
t2 = clock();
mseconds = ((float)(t2 - t1))/ CLOCKS_PER_SEC;
std::cout << "Write to file took " << mseconds << "\n";
}