| author | Radek Brich <radek.brich@devl.cz> | 
| Thu, 03 Jan 2008 18:06:34 +0100 | |
| branch | pyrit | 
| changeset 44 | 3763b26244f0 | 
| parent 35 | fb170fccb19f | 
| child 46 | 6493fb65f0b1 | 
| 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 | /* | 
| 44 | 2 | * raytracer.h: Raytracer class | 
| 3 | * | |
| 4 | * This file is part of Pyrit Ray Tracer. | |
| 5 | * | |
| 6 | * Copyright 2006, 2007 Radek Brich | |
| 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 | 7 | * | 
| 44 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy | 
| 9 | * of this software and associated documentation files (the "Software"), to deal | |
| 10 | * in the Software without restriction, including without limitation the rights | |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| 12 | * copies of the Software, and to permit persons to whom the Software is | |
| 13 | * furnished to do so, subject to the following conditions: | |
| 14 | * | |
| 15 | * The above copyright notice and this permission notice shall be included in | |
| 16 | * all copies or substantial portions of the Software. | |
| 17 | * | |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
| 24 | * THE SOFTWARE. | |
| 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 | 25 | */ | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 26 | |
| 
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 | #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 | 28 | #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 | 29 | |
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 30 | #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 | 31 | |
| 20 
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
 Radek Brich <radek.brich@devl.cz> parents: 
19diff
changeset | 32 | #include "common.h" | 
| 35 
fb170fccb19f
new space partitioning structure: octree
 Radek Brich <radek.brich@devl.cz> parents: 
34diff
changeset | 33 | #include "container.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 | 34 | #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 | 35 | |
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 36 | 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 | 37 | |
| 4 
c73bc405ee7a
multi-threaded rendering via pthreads
 Radek Brich <radek.brich@devl.cz> parents: 
0diff
changeset | 38 | class Raytracer; | 
| 
c73bc405ee7a
multi-threaded rendering via pthreads
 Radek Brich <radek.brich@devl.cz> parents: 
0diff
changeset | 39 | struct RenderrowData {
 | 
| 
c73bc405ee7a
multi-threaded rendering via pthreads
 Radek Brich <radek.brich@devl.cz> parents: 
0diff
changeset | 40 | Raytracer *rt; | 
| 
c73bc405ee7a
multi-threaded rendering via pthreads
 Radek Brich <radek.brich@devl.cz> parents: 
0diff
changeset | 41 | int w; | 
| 21 
79b516a3803d
naive color driven sub-sampling
 Radek Brich <radek.brich@devl.cz> parents: 
20diff
changeset | 42 | Vector3 eye, dfix, dx, dy; | 
| 22 | 43 | Float *iter; | 
| 4 
c73bc405ee7a
multi-threaded rendering via pthreads
 Radek Brich <radek.brich@devl.cz> parents: 
0diff
changeset | 44 | }; | 
| 
c73bc405ee7a
multi-threaded rendering via pthreads
 Radek Brich <radek.brich@devl.cz> parents: 
0diff
changeset | 45 | |
| 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 | 46 | 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 | 47 | {
 | 
| 10 
f9fad94cd0cc
kd-tree: build algorithm tested and fixed
 Radek Brich <radek.brich@devl.cz> parents: 
7diff
changeset | 48 | Container *top; | 
| 19 
4e0955fca797
added Camera, currently w/o Python binding
 Radek Brich <radek.brich@devl.cz> parents: 
16diff
changeset | 49 | 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 | 50 | 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 | 51 | 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 | 52 | int ao_samples; | 
| 22 | 53 | Float ao_distance, ao_angle; | 
| 16 
20bceb605f48
add Raytracer::setThreads()
 Radek Brich <radek.brich@devl.cz> parents: 
11diff
changeset | 54 | int num_threads; | 
| 21 
79b516a3803d
naive color driven sub-sampling
 Radek Brich <radek.brich@devl.cz> parents: 
20diff
changeset | 55 | int subsample; | 
| 32 
8af5c17d368b
new Raytracer option: oversampling
 Radek Brich <radek.brich@devl.cz> parents: 
31diff
changeset | 56 | int oversample; // 0 = no, 1 = 5x, 2 = 9x, 3 = 16x | 
| 21 
79b516a3803d
naive color driven sub-sampling
 Radek Brich <radek.brich@devl.cz> parents: 
20diff
changeset | 57 | 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 | 58 | |
| 22 | 59 | 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 | 60 | public: | 
| 20 
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
 Radek Brich <radek.brich@devl.cz> parents: 
19diff
changeset | 61 | 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: 
31diff
changeset | 62 | 		ao_samples(0), num_threads(2), subsample(8), oversample(0), max_depth(3) {};
 | 
| 22 | 63 | void render(int w, int h, Float *buffer); | 
| 4 
c73bc405ee7a
multi-threaded rendering via pthreads
 Radek Brich <radek.brich@devl.cz> parents: 
0diff
changeset | 64 | 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: 
7diff
changeset | 65 | 	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 | 66 | void addlight(Light *light); | 
| 19 
4e0955fca797
added Camera, currently w/o Python binding
 Radek Brich <radek.brich@devl.cz> parents: 
16diff
changeset | 67 | 	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: 
19diff
changeset | 68 | 	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: 
19diff
changeset | 69 | 	Container *getTop() { return top; };
 | 
| 32 
8af5c17d368b
new Raytracer option: oversampling
 Radek Brich <radek.brich@devl.cz> parents: 
31diff
changeset | 70 | 	void setSubsample(int sub) { subsample = sub; };
 | 
| 21 
79b516a3803d
naive color driven sub-sampling
 Radek Brich <radek.brich@devl.cz> parents: 
20diff
changeset | 71 | 	int getSubsample() { return subsample; };
 | 
| 32 
8af5c17d368b
new Raytracer option: oversampling
 Radek Brich <radek.brich@devl.cz> parents: 
31diff
changeset | 72 | 	void setOversample(int osa) { oversample = osa; };
 | 
| 
8af5c17d368b
new Raytracer option: oversampling
 Radek Brich <radek.brich@devl.cz> parents: 
31diff
changeset | 73 | 	int getOversample() { return oversample; };
 | 
| 21 
79b516a3803d
naive color driven sub-sampling
 Radek Brich <radek.brich@devl.cz> parents: 
20diff
changeset | 74 | 	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 | 75 | |
| 22 | 76 | void ambientocclusion(int samples, Float distance, Float angle); | 
| 16 
20bceb605f48
add Raytracer::setThreads()
 Radek Brich <radek.brich@devl.cz> parents: 
11diff
changeset | 77 | 	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 | 78 | }; | 
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 79 | |
| 
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
 Radek Brich <radek.brich@devl.cz> parents: diff
changeset | 80 | #endif |