author | Radek Brich <radek.brich@devl.cz> |
Mon, 19 May 2008 22:59:04 +0200 | |
branch | pyrit |
changeset 98 | 64638385798a |
parent 95 | ca7d4c665531 |
permissions | -rw-r--r-- |
94 | 1 |
/** |
2 |
* @file scene.h |
|
3 |
* @brief Classes for objects in scene (other than shapes). |
|
44 | 4 |
* |
5 |
* This file is part of Pyrit Ray Tracer. |
|
6 |
* |
|
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
7 |
* Copyright 2006, 2007, 2008 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
|
8 |
* |
44 | 9 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
10 |
* of this software and associated documentation files (the "Software"), to deal |
|
11 |
* in the Software without restriction, including without limitation the rights |
|
12 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
13 |
* copies of the Software, and to permit persons to whom the Software is |
|
14 |
* furnished to do so, subject to the following conditions: |
|
15 |
* |
|
16 |
* The above copyright notice and this permission notice shall be included in |
|
17 |
* all copies or substantial portions of the Software. |
|
18 |
* |
|
19 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
20 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
21 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
22 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
23 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
24 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
25 |
* 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
|
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 |
|
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 |
#ifndef 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
|
29 |
#define 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
|
30 |
|
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 |
#include <vector> |
28
ffe83ca074f3
smooth triangles (aka Phong shading)
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
32 |
#include <typeinfo> |
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
|
33 |
|
78
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
73
diff
changeset
|
34 |
#include "common.h" |
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
35 |
#include "sampler.h" |
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
36 |
#include "vector.h" |
34
28f6e8b9d5d1
quaternion moved to extra header file
Radek Brich <radek.brich@devl.cz>
parents:
31
diff
changeset
|
37 |
#include "quaternion.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
|
38 |
|
78
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
73
diff
changeset
|
39 |
/** |
94 | 40 |
* A ray |
78
9569e9f35374
move shapes to extra source file
Radek Brich <radek.brich@devl.cz>
parents:
73
diff
changeset
|
41 |
*/ |
12
f4fcabf05785
kd-tree: traversal algorithm (KdTree::nearest_intersection)
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
42 |
class Ray |
f4fcabf05785
kd-tree: traversal algorithm (KdTree::nearest_intersection)
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
43 |
{ |
f4fcabf05785
kd-tree: traversal algorithm (KdTree::nearest_intersection)
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
44 |
public: |
94 | 45 |
Vector o; ///< Origin |
46 |
Vector dir; ///< Normalized direction |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
47 |
|
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
48 |
Ray(): o(), dir() {}; |
91 | 49 |
Ray(const Vector &ao, const Vector &adir): |
15
a0a3e334744f
C++ demos: prepare infrastructure, add spheres_shadow.cc
Radek Brich <radek.brich@devl.cz>
parents:
14
diff
changeset
|
50 |
o(ao), dir(adir) {}; |
12
f4fcabf05785
kd-tree: traversal algorithm (KdTree::nearest_intersection)
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
51 |
}; |
f4fcabf05785
kd-tree: traversal algorithm (KdTree::nearest_intersection)
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
52 |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
53 |
#ifndef NO_SIMD |
46 | 54 |
/** |
94 | 55 |
* Packet of four rays for SIMD accelerated packet tracing. |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
56 |
*/ |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
57 |
class RayPacket |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
58 |
{ |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
59 |
public: |
94 | 60 |
VectorPacket o; ///< Packet of four origins |
61 |
VectorPacket dir; ///< Directions |
|
62 |
VectorPacket invdir; ///< Inverted directions (1/dir) |
|
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
63 |
|
91 | 64 |
RayPacket(): o(), dir() {}; |
65 |
RayPacket(const VectorPacket &ao, const VectorPacket &adir): |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
66 |
o(ao), dir(adir), invdir(mOne/adir) {}; |
91 | 67 |
|
94 | 68 |
/** Index operator: get ray 'i' */ |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
69 |
Ray operator[](int i) const |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
70 |
{ |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
71 |
return Ray( |
91 | 72 |
Vector(o.x[i], o.y[i], o.z[i]), |
73 |
Vector(dir.x[i], dir.y[i], dir.z[i])); |
|
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
74 |
}; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
75 |
}; |
91 | 76 |
#endif |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
77 |
|
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
78 |
/** |
98
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
79 |
* Standard ray tracing camera |
46 | 80 |
*/ |
19
4e0955fca797
added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
81 |
class Camera |
4e0955fca797
added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
82 |
{ |
91 | 83 |
Vector eye, p, u, v; |
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
84 |
Float F; |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
85 |
public: |
93 | 86 |
Camera(): eye(0,0,10), p(0,0,-1), u(-1,0,0), v(0,1,0), F(2*tan(PI/8)) {}; |
98
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
87 |
|
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
88 |
/** Position + p,u,v constructor */ |
91 | 89 |
Camera(const Vector &C, const Vector &ap, const Vector &au, const Vector &av): |
93 | 90 |
eye(C), p(ap), u(au), v(av), F(2*tan(PI/8)) {}; |
98
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
91 |
|
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
92 |
/** Look-at constructor */ |
91 | 93 |
Camera(const Vector &from, const Vector &lookat, const Vector &up): |
93 | 94 |
eye(from), F(2*tan(PI/8)) |
72
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
95 |
{ |
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
96 |
p = lookat - from; u = cross(up, p); |
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
97 |
p.normalize(); u.normalize(); |
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
98 |
v = cross(p, u); |
7c3f38dff082
kd-tree building - check all axes for best split, add additional shape-bbox check
Radek Brich <radek.brich@devl.cz>
parents:
69
diff
changeset
|
99 |
}; |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
100 |
|
95
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
101 |
#ifndef NO_SIMD |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
102 |
void *operator new(size_t size) { return _mm_malloc(size, 16); }; |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
103 |
void operator delete(void *p) { _mm_free(p); }; |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
104 |
#endif |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
105 |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
106 |
const Vector &getEye() const { return eye; }; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
107 |
const Vector &getp() const { return p; }; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
108 |
const Vector &getu() const { return u; }; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
109 |
const Vector &getv() const { return v; }; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
110 |
const Float &getF() const { return F; }; |
98
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
111 |
|
91 | 112 |
void setEye(const Vector &aeye) { eye = aeye; }; |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
113 |
void setp(const Vector &ap) { p = ap; }; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
114 |
void setu(const Vector &au) { u = au; }; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
115 |
void setv(const Vector &av) { v = av; }; |
98
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
116 |
|
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
117 |
/** set "screen plane" size |
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
118 |
* @param[in] F height of the screen plane */ |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
119 |
void setF(const Float &aF) { F = aF; }; |
98
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
120 |
|
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
121 |
/** set camera's angle of view (in radians) */ |
93 | 122 |
void setAngle(const Float angle) { F = 2*tan(angle/2); }; |
98
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
123 |
|
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
124 |
/** rotate camera using a quaternion */ |
20
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
125 |
void rotate(const Quaternion &q); |
98
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
126 |
|
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
127 |
/** translate the camera in its direction |
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
128 |
* @param[in] fw size of forward step |
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
129 |
* @param[in] left size of left step |
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
130 |
* @param[in] up size of up step |
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
131 |
*/ |
22 | 132 |
void move(const Float fw, const Float left, const Float up); |
46 | 133 |
|
98
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
134 |
/** make the ray from screen sample according the camera's parameters */ |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
135 |
const Ray makeRay(const Sample &samp) const |
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
136 |
{ |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
137 |
Vector dir = normalize(p - (u*samp.x + v*samp.y)*F); |
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
138 |
return Ray(eye, dir); |
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
139 |
}; |
82
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
80
diff
changeset
|
140 |
|
98
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
141 |
/** same as makeRay but for ray packet */ |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
142 |
#ifndef NO_SIMD |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
143 |
void makeRayPacket(const Sample *samples, RayPacket &rays) const |
82
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
80
diff
changeset
|
144 |
{ |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
145 |
mfloat4 m1x,m1y,m1z; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
146 |
mfloat4 m2x,m2y,m2z; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
147 |
mfloat4 m; |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
148 |
|
83
e3a2a5b26abb
vectorize makeRayPacket() using SSE intrinsics
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
149 |
// m1(xyz) = u * samples[i].x |
95
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
150 |
m1x = mshuffle(u.mf4, u.mf4, mShuffle0); // u.x |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
151 |
m1y = mshuffle(u.mf4, u.mf4, mShuffle1); // u.y |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
152 |
m1z = mshuffle(u.mf4, u.mf4, mShuffle2); // u.z |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
153 |
m = mset(samples[3].x, samples[2].x, samples[1].x, samples[0].x); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
154 |
m1x = mmul(m1x, m); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
155 |
m1y = mmul(m1y, m); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
156 |
m1z = mmul(m1z, m); |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
157 |
|
83
e3a2a5b26abb
vectorize makeRayPacket() using SSE intrinsics
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
158 |
// m2(xyz) = v * samples[i].y |
95
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
159 |
m2x = mshuffle(v.mf4, v.mf4, mShuffle0); // v.x |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
160 |
m2y = mshuffle(v.mf4, v.mf4, mShuffle1); // v.y |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
161 |
m2z = mshuffle(v.mf4, v.mf4, mShuffle2); // v.z |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
162 |
m = mset(samples[3].y, samples[2].y, samples[1].y, samples[0].y); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
163 |
m2x = mmul(m2x, m); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
164 |
m2y = mmul(m2y, m); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
165 |
m2z = mmul(m2z, m); |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
166 |
|
83
e3a2a5b26abb
vectorize makeRayPacket() using SSE intrinsics
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
167 |
// m1(xyz) = (m1 + m2) = (u*samples[i].x + v*samples[i].y) |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
168 |
m1x = madd(m1x, m2x); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
169 |
m1y = madd(m1y, m2y); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
170 |
m1z = madd(m1z, m2z); |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
171 |
|
83
e3a2a5b26abb
vectorize makeRayPacket() using SSE intrinsics
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
172 |
// m1(xyz) = m1*F = (u*samples[i].x + v*samples[i].y)*F |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
173 |
m = mset1(F); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
174 |
m1x = mmul(m1x, m); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
175 |
m1y = mmul(m1y, m); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
176 |
m1z = mmul(m1z, m); |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
177 |
|
83
e3a2a5b26abb
vectorize makeRayPacket() using SSE intrinsics
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
178 |
// m1(xyz) = p - m1 = p - (u*samples[i].x + v*samples[i].y)*F = dir |
95
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
179 |
m2x = mshuffle(p.mf4, p.mf4, mShuffle0); // p.x |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
180 |
m2y = mshuffle(p.mf4, p.mf4, mShuffle1); // p.y |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
181 |
m2z = mshuffle(p.mf4, p.mf4, mShuffle2); // p.z |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
182 |
rays.dir.mx = msub(m2x, m1x); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
183 |
rays.dir.my = msub(m2y, m1y); |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
184 |
rays.dir.mz = msub(m2z, m1z); |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
185 |
|
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
186 |
// copy origin |
95
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
187 |
rays.o.mx = mshuffle(eye.mf4, eye.mf4, mShuffle0); // eye.x |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
188 |
rays.o.my = mshuffle(eye.mf4, eye.mf4, mShuffle1); // eye.y |
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
189 |
rays.o.mz = mshuffle(eye.mf4, eye.mf4, mShuffle2); // eye.z |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
190 |
|
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
191 |
rays.dir.normalize(); |
95
ca7d4c665531
build script fixes, add ldflags build option
Radek Brich <radek.brich@devl.cz>
parents:
94
diff
changeset
|
192 |
rays.invdir = mOne / rays.dir; |
82
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
80
diff
changeset
|
193 |
}; |
91 | 194 |
#endif |
19
4e0955fca797
added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
195 |
}; |
4e0955fca797
added Camera, currently w/o Python binding
Radek Brich <radek.brich@devl.cz>
parents:
15
diff
changeset
|
196 |
|
46 | 197 |
/** |
198 |
* light object |
|
199 |
*/ |
|
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
|
200 |
class Light |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
201 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
202 |
public: |
91 | 203 |
Vector pos; |
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
|
204 |
Colour colour; |
93 | 205 |
int cast_shadows; |
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
|
206 |
|
40
929aad02c5f2
Makefile: added help and distclean target, plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
38
diff
changeset
|
207 |
Light(): |
91 | 208 |
pos(Vector(0,0,0)), colour(Colour(1,1,1)), cast_shadows(true) {}; |
209 |
Light(const Vector &position, const Colour &acolour): |
|
21
79b516a3803d
naive color driven sub-sampling
Radek Brich <radek.brich@devl.cz>
parents:
20
diff
changeset
|
210 |
pos(position), colour(acolour), cast_shadows(true) {}; |
98
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
211 |
|
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
212 |
/** allow shadows from this light */ |
93 | 213 |
void castShadows(int cast) { cast_shadows = cast; }; |
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
|
214 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
215 |
|
46 | 216 |
/** |
79
062b1c4143f7
material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
217 |
* axis-aligned bounding box |
46 | 218 |
*/ |
79
062b1c4143f7
material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
219 |
class BBox |
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
|
220 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
221 |
public: |
91 | 222 |
Vector L; |
223 |
Vector H; |
|
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
224 |
|
79
062b1c4143f7
material and texture classes moved to material.(cc,h)
Radek Brich <radek.brich@devl.cz>
parents:
78
diff
changeset
|
225 |
BBox(): L(), H() {}; |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
226 |
BBox(const Vector &aL, const Vector &aH): L(aL), H(aH) {}; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
227 |
|
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
228 |
Float w() const { return H.x-L.x; }; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
229 |
Float h() const { return H.y-L.y; }; |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
230 |
Float d() const { return H.z-L.z; }; |
98
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
231 |
|
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
232 |
/** |
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
233 |
* intersect ray with the bounding box |
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
234 |
* @param[in] ray the ray |
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
235 |
* @param[out] a distance of first intersection |
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
236 |
* @param[out] b distance of second intersection |
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
237 |
* @return true if ray intersects bbox |
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
238 |
*/ |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
239 |
bool intersect(const Ray &ray, Float &a, Float &b) const; |
98
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
240 |
|
64638385798a
add sections about demos to README
Radek Brich <radek.brich@devl.cz>
parents:
95
diff
changeset
|
241 |
/** same as intersect() but for ray packets */ |
92
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
242 |
#ifndef NO_SIMD |
9af5c039b678
add MSVC compiler support, make it default for Windows
Radek Brich <radek.brich@devl.cz>
parents:
91
diff
changeset
|
243 |
mfloat4 intersect_packet(const RayPacket &rays, mfloat4 &a, mfloat4 &b) const; |
91 | 244 |
#endif |
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
|
245 |
}; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
246 |
|
25
b8232edee786
tuned ray-triangle intersection, now there are three algorithms to choose from:
Radek Brich <radek.brich@devl.cz>
parents:
24
diff
changeset
|
247 |
#endif |