author | Radek Brich <radek.brich@devl.cz> |
Sun, 09 Dec 2007 15:01:51 +0100 | |
branch | pyrit |
changeset 33 | 83d0200d4c09 |
parent 32 | 8af5c17d368b |
child 34 | 28f6e8b9d5d1 |
permissions | -rw-r--r-- |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
/* |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
* C++ RayTracer |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
3 |
* file: raytracer.h |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
4 |
* |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
5 |
* Radek Brich, 2006 |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
*/ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
7 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
8 |
#ifndef RAYTRACER_H |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
9 |
#define RAYTRACER_H |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
10 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
11 |
#include <vector> |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
12 |
|
20
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
13 |
#include "common.h" |
7
bf17f9f84c91
kd-tree: build algorithm - searching for all posible splits
Radek Brich <radek.brich@devl.cz>
parents:
5
diff
changeset
|
14 |
#include "kdtree.h" |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
15 |
#include "scene.h" |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
16 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
17 |
using namespace std; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
18 |
|
4
c73bc405ee7a
multi-threaded rendering via pthreads
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
19 |
class Raytracer; |
c73bc405ee7a
multi-threaded rendering via pthreads
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
20 |
struct RenderrowData { |
c73bc405ee7a
multi-threaded rendering via pthreads
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
21 |
Raytracer *rt; |
c73bc405ee7a
multi-threaded rendering via pthreads
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
22 |
int w; |
21
79b516a3803d
naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents:
20
diff
changeset
|
23 |
Vector3 eye, dfix, dx, dy; |
22 | 24 |
Float *iter; |
4
c73bc405ee7a
multi-threaded rendering via pthreads
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
25 |
}; |
c73bc405ee7a
multi-threaded rendering via pthreads
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
26 |
|
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
27 |
class Raytracer |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
28 |
{ |
10
f9fad94cd0cc
kd-tree: build algorithm tested and fixed
Radek Brich <radek.brich@devl.cz>
parents:
7
diff
changeset
|
29 |
Container *top; |
19
4e0955fca797
added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
30 |
Camera *camera; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
31 |
vector<Light*> lights; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
32 |
Colour bg_colour; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
33 |
int ao_samples; |
22 | 34 |
Float ao_distance, ao_angle; |
16
20bceb605f48
add Raytracer::setThreads()
Radek Brich <radek.brich@devl.cz>
parents:
11
diff
changeset
|
35 |
int num_threads; |
21
79b516a3803d
naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents:
20
diff
changeset
|
36 |
int subsample; |
32
8af5c17d368b
new Raytracer option: oversampling
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
37 |
int oversample; // 0 = no, 1 = 5x, 2 = 9x, 3 = 16x |
21
79b516a3803d
naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents:
20
diff
changeset
|
38 |
int max_depth; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
39 |
|
22 | 40 |
Vector3 SphereDistribute(int i, int n, Float extent, Vector3 &normal); |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
41 |
public: |
20
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
42 |
Raytracer(): top(NULL), camera(NULL), lights(), bg_colour(0.0, 0.0, 0.0), |
32
8af5c17d368b
new Raytracer option: oversampling
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
43 |
ao_samples(0), num_threads(2), subsample(8), oversample(0), max_depth(3) {}; |
22 | 44 |
void render(int w, int h, Float *buffer); |
4
c73bc405ee7a
multi-threaded rendering via pthreads
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
45 |
Colour raytrace(Ray &ray, int depth, Shape *origin_shape); |
10
f9fad94cd0cc
kd-tree: build algorithm tested and fixed
Radek Brich <radek.brich@devl.cz>
parents:
7
diff
changeset
|
46 |
void addshape(Shape *shape) { top->addShape(shape); }; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
47 |
void addlight(Light *light); |
19
4e0955fca797
added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents:
16
diff
changeset
|
48 |
void setCamera(Camera *cam) { camera = cam; }; |
20
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
49 |
void setTop(Container *atop) { top = atop; }; |
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
50 |
Container *getTop() { return top; }; |
32
8af5c17d368b
new Raytracer option: oversampling
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
51 |
void setSubsample(int sub) { subsample = sub; }; |
21
79b516a3803d
naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents:
20
diff
changeset
|
52 |
int getSubsample() { return subsample; }; |
32
8af5c17d368b
new Raytracer option: oversampling
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
53 |
void setOversample(int osa) { oversample = osa; }; |
8af5c17d368b
new Raytracer option: oversampling
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
54 |
int getOversample() { return oversample; }; |
21
79b516a3803d
naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents:
20
diff
changeset
|
55 |
void setMaxDepth(int newdepth) { max_depth = newdepth; }; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
56 |
|
22 | 57 |
void ambientocclusion(int samples, Float distance, Float angle); |
16
20bceb605f48
add Raytracer::setThreads()
Radek Brich <radek.brich@devl.cz>
parents:
11
diff
changeset
|
58 |
void setThreads(int num) { num_threads = num; }; |
0
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
59 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
60 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
61 |
#endif |