author | Radek Brich <radek.brich@devl.cz> |
Tue, 29 Apr 2008 23:31:08 +0200 | |
branch | pyrit |
changeset 90 | f6a72eb99631 |
parent 86 | ce6abe0aeeae |
child 91 | 9d66d323c354 |
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.cc: Raytracer class |
3 |
* |
|
4 |
* This file is part of Pyrit Ray Tracer. |
|
5 |
* |
|
47
320d5d466864
move Sampler classes to sampler.cc
Radek Brich <radek.brich@devl.cz>
parents:
46
diff
changeset
|
6 |
* 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
|
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 |
|
4
c73bc405ee7a
multi-threaded rendering via pthreads
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
27 |
#include <pthread.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
|
28 |
#include <stdio.h> |
67
249553e1d4fe
new option to choose single or double precision floats
Radek Brich <radek.brich@devl.cz>
parents:
56
diff
changeset
|
29 |
#include <stdlib.h> |
82
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
30 |
#include <assert.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
|
31 |
#include "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
|
32 |
|
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
33 |
int pyrit_verbosity = 2; |
30
33f95441790e
pyrit_verbosity: new variable for controlling amount of output, see common.h
Radek Brich <radek.brich@devl.cz>
parents:
25
diff
changeset
|
34 |
|
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
|
35 |
// Hammersley spherical point distribution |
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 |
// http://www.cse.cuhk.edu.hk/~ttwong/papers/udpoint/udpoints.html |
22 | 37 |
Vector3 Raytracer::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
|
38 |
{ |
22 | 39 |
Float p, t, st, phi, phirad; |
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
|
40 |
int kk; |
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 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
42 |
t = 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
|
43 |
for (p=0.5, kk=i; kk; p*=0.5, kk>>=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
|
44 |
if (kk & 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
|
45 |
t += p; |
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 |
t = 1.0 + (t - 1.0)*extent; |
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 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
48 |
phi = (i + 0.5) / n; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
49 |
phirad = phi * 2.0 * M_PI; |
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 |
|
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 |
st = sqrt(1.0 - t*t); |
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 |
|
22 | 53 |
Float x, y, z, xx, yy, zz, q; |
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
|
54 |
x = st * cos(phirad); |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
55 |
y = st * sin(phirad); |
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 |
z = t; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
57 |
|
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 |
// rotate against Y axis |
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 |
q = acos(normal.z); |
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 |
zz = z*cos(q) - x*sin(q); |
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 |
xx = z*sin(q) + x*cos(q); |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
62 |
yy = y; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
63 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
64 |
// rotate against Z axis |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
65 |
q = atan2f(normal.y, normal.x); |
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 |
x = xx*cos(q) - yy*sin(q); |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
67 |
y = xx*sin(q) + yy*cos(q); |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
68 |
z = zz; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
69 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
70 |
return Vector3(x, y, z); |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
71 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
72 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
73 |
// ---- tyto dve funkce budou v budouci verzi metody objektu PhongShader |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
74 |
|
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 |
// calculate shader function |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
76 |
// P is point of intersection, N normal in this point |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
77 |
Colour PhongShader_ambient(const Material &mat, const Vector3 &P) |
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 |
{ |
42 | 79 |
Colour col; |
80 |
if (mat.texture) |
|
81 |
col = mat.texture->evaluate(P); |
|
82 |
else |
|
83 |
col = mat.colour; |
|
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
|
84 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
85 |
// ambient |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
86 |
return mat.ambient * col; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
87 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
88 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
89 |
/* |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
90 |
P is point of intersection, |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
91 |
N normal in this point, |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
92 |
R direction of reflected ray, |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
93 |
V direction to the viewer |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
94 |
*/ |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
95 |
Colour PhongShader_calculate(const Material &mat, |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
96 |
const Vector3 &P, const Vector3 &N, const Vector3 &R, const Vector3 &V, |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
97 |
const Light &light) |
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
|
98 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
99 |
Colour I = 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
|
100 |
Vector3 L = light.pos - P; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
101 |
L.normalize(); |
22 | 102 |
Float L_dot_N = dot(L, N); |
103 |
Float R_dot_V = dot(R, V); |
|
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
|
104 |
|
42 | 105 |
Colour col; |
106 |
if (mat.texture) |
|
107 |
col = mat.texture->evaluate(P); |
|
108 |
else |
|
109 |
col = mat.colour; |
|
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
|
110 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
111 |
// diffuse |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
112 |
I = mat.diffuse * col * light.colour * L_dot_N; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
113 |
|
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
114 |
// specular |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
115 |
if (R_dot_V > 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
|
116 |
I += mat.specular * light.colour * powf(R_dot_V, mat.shininess); |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
117 |
return I; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
118 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
119 |
|
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
120 |
Colour Raytracer::shader_evalulate(const Ray &ray, int depth, Shape *origin_shape, |
82
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
121 |
Float nearest_distance, Shape *nearest_shape) |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
122 |
{ |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
123 |
Colour col = Colour(); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
124 |
Vector3 P = ray.o + ray.dir * nearest_distance; // point of intersection |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
125 |
Vector3 normal = nearest_shape->normal(P); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
126 |
bool from_inside = false; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
127 |
|
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
128 |
// make shapes double sided |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
129 |
if (dot(normal, ray.dir) > 0.0) |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
130 |
{ |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
131 |
normal = - normal; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
132 |
from_inside = true; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
133 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
134 |
|
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
135 |
col = PhongShader_ambient(*nearest_shape->material, P); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
136 |
|
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
137 |
vector<Light*>::iterator light; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
138 |
for (light = lights.begin(); light != lights.end(); light++) { |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
139 |
Vector3 jo, L = (*light)->pos - P; // direction vector to light |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
140 |
L.normalize(); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
141 |
Float L_dot_N = dot(L, normal); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
142 |
if (L_dot_N > 0) { |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
143 |
// test if this light is occluded (sharp shadows) |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
144 |
if ((*light)->cast_shadows) { |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
145 |
Ray shadow_ray = Ray(P, L); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
146 |
Float dist = FLT_MAX; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
147 |
if (top->nearest_intersection(nearest_shape, shadow_ray, dist)) |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
148 |
continue; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
149 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
150 |
|
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
151 |
// shading function |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
152 |
Vector3 R = L - 2.0 * L_dot_N * normal; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
153 |
col += PhongShader_calculate(*nearest_shape->material, |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
154 |
P, normal, R, ray.dir, **light); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
155 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
156 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
157 |
|
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
158 |
if (depth < max_depth) |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
159 |
{ |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
160 |
Colour trans_col, refl_col; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
161 |
Float trans = nearest_shape->material->transmissivity; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
162 |
Float refl = nearest_shape->material->reflectivity; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
163 |
const Float cos_i = - dot(normal, ray.dir); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
164 |
|
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
165 |
// reflection |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
166 |
if (refl > 0.01) |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
167 |
{ |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
168 |
Vector3 newdir = ray.dir + 2.0 * cos_i * normal; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
169 |
Ray newray = Ray(P, newdir); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
170 |
refl_col = raytrace(newray, depth + 1, nearest_shape); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
171 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
172 |
|
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
173 |
// refraction |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
174 |
if (trans > 0.01) |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
175 |
{ |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
176 |
Float n, n1, n2; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
177 |
if (from_inside) |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
178 |
{ |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
179 |
n1 = nearest_shape->material->refract_index; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
180 |
n2 = 1.0; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
181 |
n = n1; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
182 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
183 |
else |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
184 |
{ |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
185 |
n1 = 1.0; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
186 |
n2 = nearest_shape->material->refract_index; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
187 |
n = 1.0 / n2; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
188 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
189 |
const Float sin2_t = n*n * (1 - cos_i*cos_i); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
190 |
if (sin2_t >= 1.0) |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
191 |
{ |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
192 |
// totally reflected |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
193 |
refl += trans; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
194 |
trans = 0; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
195 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
196 |
else |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
197 |
{ |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
198 |
const Float cos_t = sqrtf(1 - sin2_t); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
199 |
const Float Rdiv = 1.0/(n1*cos_i + n2*cos_t); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
200 |
const Float Rper = (n1*cos_i - n2*cos_t)*Rdiv; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
201 |
const Float Rpar = (n2*cos_i - n1*cos_t)*Rdiv; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
202 |
const Float R = (Rper*Rper + Rpar*Rpar)/2; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
203 |
refl += R*trans; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
204 |
trans = (1-R)*trans; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
205 |
Vector3 newdir = n * ray.dir + (n*cos_i - cos_t) * normal; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
206 |
Ray newray = Ray(P + 0.001*newdir, newdir); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
207 |
trans_col = raytrace(newray, depth + 1, NULL); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
208 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
209 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
210 |
col = (1-refl-trans)*col + refl*refl_col + trans*trans_col; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
211 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
212 |
|
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
213 |
// ambient occlusion |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
214 |
if (!from_inside && ao_samples) |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
215 |
{ |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
216 |
Float miss = 0; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
217 |
for (int i = 0; i < ao_samples; i++) { |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
218 |
Vector3 dir = SphereDistribute(i, ao_samples, ao_angle, normal); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
219 |
Ray ao_ray = Ray(P, dir); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
220 |
Float dist = ao_distance; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
221 |
Shape *shape_in_way = top->nearest_intersection(nearest_shape, ao_ray, dist); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
222 |
if (shape_in_way == NULL) |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
223 |
miss += 1.0; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
224 |
else |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
225 |
miss += dist / ao_distance; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
226 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
227 |
Float ao_intensity = miss / ao_samples; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
228 |
col = col * ao_intensity; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
229 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
230 |
|
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
231 |
return col; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
232 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
233 |
|
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
|
234 |
Colour Raytracer::raytrace(Ray &ray, int depth, Shape *origin_shape) |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
235 |
{ |
22 | 236 |
Float nearest_distance = Inf; |
11
4d192e13ee84
move nearest_intersection() to Container, add dummy KdTree.load(), plus small fixes
Radek Brich <radek.brich@devl.cz>
parents:
10
diff
changeset
|
237 |
Shape *nearest_shape = top->nearest_intersection(origin_shape, ray, nearest_distance); |
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
|
238 |
|
82
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
239 |
if (nearest_shape == NULL) |
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
|
240 |
return bg_colour; |
82
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
241 |
else |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
242 |
return shader_evalulate(ray, depth, origin_shape, nearest_distance, nearest_shape); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
243 |
} |
31 | 244 |
|
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
245 |
void Raytracer::raytracePacket(RayPacket &rays, Colour *results) |
82
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
246 |
{ |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
247 |
Float nearest_distances[4] = {Inf,Inf,Inf,Inf}; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
248 |
Shape *nearest_shapes[4]; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
249 |
static const Shape *origin_shapes[4] = {NULL, NULL, NULL, NULL}; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
250 |
top->packet_intersection(origin_shapes, rays, nearest_distances, nearest_shapes); |
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
|
251 |
|
82
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
252 |
for (int i = 0; i < 4; i++) |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
253 |
if (nearest_shapes[i] == NULL) |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
254 |
results[i] = bg_colour; |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
255 |
else |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
256 |
results[i] = shader_evalulate(rays[i], 0, NULL, |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
257 |
nearest_distances[i], nearest_shapes[i]); |
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
|
258 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
259 |
|
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
260 |
void *Raytracer::raytrace_worker(void *d) |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
261 |
{ |
55 | 262 |
static const int my_queue_size = 256; |
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
263 |
Raytracer *rt = (Raytracer*)d; |
54
dbe3c7a4e0f0
more raytrace_worker optimization and cleaning
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
264 |
Sample my_queue[my_queue_size]; |
dbe3c7a4e0f0
more raytrace_worker optimization and cleaning
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
265 |
Colour my_colours[my_queue_size]; |
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
266 |
int my_count; |
84
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
267 |
Ray ray; |
6f7fe14782c2
prepare kd-tree traversal for packet tracing (4 rays at once)
Radek Brich <radek.brich@devl.cz>
parents:
83
diff
changeset
|
268 |
RayPacket rays; |
82
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
269 |
const bool can_use_packets = (rt->use_packets && rt->sampler->packetableSamples()); |
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
270 |
for (;;) |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
271 |
{ |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
272 |
pthread_mutex_lock(&rt->sample_queue_mutex); |
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
273 |
while (rt->sample_queue_count == 0) |
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
274 |
{ |
54
dbe3c7a4e0f0
more raytrace_worker optimization and cleaning
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
275 |
if (rt->end_of_samples) |
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
276 |
{ |
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
277 |
dbgmsg(4, "T thread [%d] exiting\n", pthread_self()); |
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
278 |
pthread_mutex_unlock(&rt->sample_queue_mutex); |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
279 |
pthread_exit(NULL); |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
280 |
} |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
281 |
pthread_cond_wait(&rt->sample_queue_cond, &rt->sample_queue_mutex); |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
282 |
} |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
283 |
|
54
dbe3c7a4e0f0
more raytrace_worker optimization and cleaning
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
284 |
if (rt->sample_queue_count >= my_queue_size) |
dbe3c7a4e0f0
more raytrace_worker optimization and cleaning
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
285 |
my_count = my_queue_size; |
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
286 |
else |
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
287 |
my_count = rt->sample_queue_count; |
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
288 |
rt->sample_queue_count -= my_count; |
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
289 |
|
54
dbe3c7a4e0f0
more raytrace_worker optimization and cleaning
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
290 |
// copy samples to local queue |
55 | 291 |
if (rt->sample_queue_pos + my_count >= rt->sample_queue_size) |
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
292 |
{ |
55 | 293 |
register int c = rt->sample_queue_size - rt->sample_queue_pos; |
294 |
memcpy(my_queue, rt->sample_queue + rt->sample_queue_pos, c*sizeof(Sample)); |
|
295 |
memcpy(my_queue + c, rt->sample_queue, (my_count - c)*sizeof(Sample)); |
|
296 |
rt->sample_queue_pos = my_count - c; |
|
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
297 |
} |
55 | 298 |
else |
299 |
{ |
|
300 |
memcpy(my_queue, rt->sample_queue + rt->sample_queue_pos, |
|
301 |
my_count*sizeof(Sample)); |
|
302 |
rt->sample_queue_pos += my_count; |
|
303 |
} |
|
304 |
if (rt->sample_queue_count <= my_queue_size*2) |
|
305 |
pthread_cond_signal(&rt->worker_ready_cond); |
|
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
306 |
pthread_mutex_unlock(&rt->sample_queue_mutex); |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
307 |
|
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
308 |
// do the work |
82
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
309 |
if (can_use_packets) |
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
310 |
{ |
82
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
311 |
// packet ray tracing |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
312 |
assert((my_count % 4) == 0); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
313 |
for (int i = 0; i < my_count; i+=4) |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
314 |
{ |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
315 |
rt->camera->makeRayPacket(my_queue + i, rays); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
316 |
rt->raytracePacket(rays, my_colours + i); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
317 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
318 |
} |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
319 |
else |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
320 |
{ |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
321 |
// single ray tracing |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
322 |
for (int i = 0; i < my_count; i++) |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
323 |
{ |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
324 |
ray = rt->camera->makeRay(my_queue[i]); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
325 |
my_colours[i] = rt->raytrace(ray, 0, NULL); |
930a2d3ecaed
prepare structures for packet tracing
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
326 |
} |
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
327 |
} |
51
89fec8668768
remove debug messages - algorithm seems stable, but it's slow
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
328 |
|
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
329 |
// save the results |
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
330 |
pthread_mutex_lock(&rt->sampler_mutex); |
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
331 |
for (int i = 0; i < my_count; i++) |
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
332 |
rt->sampler->saveSample(my_queue[i], my_colours[i]); |
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
333 |
pthread_mutex_unlock(&rt->sampler_mutex); |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
334 |
} |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
335 |
} |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
336 |
|
46 | 337 |
void Raytracer::render() |
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
|
338 |
{ |
46 | 339 |
if (!sampler || !camera || !top) |
20
f22952603f29
new C++ demo: realtime.cc (real-time scene viewer using SDL)
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
340 |
return; |
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
|
341 |
|
55 | 342 |
static const int my_count_max = 256; |
343 |
sample_queue_size = my_count_max*2*num_threads; |
|
344 |
sample_queue = new Sample [sample_queue_size]; |
|
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
345 |
sample_queue_count = 0; |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
346 |
int my_count, my_pos; |
54
dbe3c7a4e0f0
more raytrace_worker optimization and cleaning
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
347 |
int sampnum = 0, sampdone; |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
348 |
int phase = 1; |
54
dbe3c7a4e0f0
more raytrace_worker optimization and cleaning
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
349 |
bool more_samples; |
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
350 |
|
55 | 351 |
sampler->init(); |
352 |
||
46 | 353 |
// create workers |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
354 |
dbgmsg(1, "* using %d threads\n", num_threads); |
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
355 |
pthread_t threads[num_threads]; |
46 | 356 |
|
51
89fec8668768
remove debug messages - algorithm seems stable, but it's slow
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
357 |
dbgmsg(1, "* raytracing...\n"); |
89fec8668768
remove debug messages - algorithm seems stable, but it's slow
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
358 |
|
46 | 359 |
while ( (sampnum = sampler->initSampleSet()) > 0 ) |
360 |
{ |
|
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
361 |
my_pos = 0; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
362 |
sample_queue_pos = 0; |
51
89fec8668768
remove debug messages - algorithm seems stable, but it's slow
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
363 |
sampdone = 0; |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
364 |
end_of_samples = false; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
365 |
|
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
366 |
for (int t = 0; t < num_threads; t++) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
367 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
368 |
int rc = pthread_create(&threads[t], NULL, raytrace_worker, (void*)this); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
369 |
if (rc) { |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
370 |
dbgmsg(0, "\nE pthread_create unsuccessful, return code was %d\n", rc); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
371 |
exit(1); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
372 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
373 |
} |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
374 |
|
90
f6a72eb99631
rename Python module from 'raytracer' to 'pyrit'
Radek Brich <radek.brich@devl.cz>
parents:
86
diff
changeset
|
375 |
dbgmsg(2, "- phase %d: 0%% done", phase); |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
376 |
|
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
377 |
pthread_mutex_lock(&sampler_mutex); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
378 |
|
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
379 |
for (;;) |
46 | 380 |
{ |
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
381 |
my_count = 0; |
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
382 |
while ( more_samples = sampler->nextSample(&sample_queue[my_pos++]) ) |
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
383 |
{ |
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
384 |
my_count++; |
55 | 385 |
if (my_pos >= sample_queue_size) |
386 |
my_pos = 0; |
|
54
dbe3c7a4e0f0
more raytrace_worker optimization and cleaning
Radek Brich <radek.brich@devl.cz>
parents:
53
diff
changeset
|
387 |
if (my_count >= my_count_max) |
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
388 |
break; |
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
389 |
} |
55 | 390 |
if (!more_samples && !my_count) |
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
391 |
break; |
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
392 |
|
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
393 |
pthread_mutex_unlock(&sampler_mutex); |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
394 |
pthread_mutex_lock(&sample_queue_mutex); |
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
395 |
sample_queue_count += my_count; |
46 | 396 |
|
51
89fec8668768
remove debug messages - algorithm seems stable, but it's slow
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
397 |
// wait for workers if there is enough samples ready on queue |
55 | 398 |
while (sample_queue_count > (2*num_threads-1)*my_count_max) |
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
399 |
pthread_cond_wait(&worker_ready_cond, &sample_queue_mutex); |
55 | 400 |
|
401 |
pthread_cond_signal(&sample_queue_cond); |
|
402 |
pthread_mutex_unlock(&sample_queue_mutex); |
|
46 | 403 |
|
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
404 |
sampdone += my_count; |
83
e3a2a5b26abb
vectorize makeRayPacket() using SSE intrinsics
Radek Brich <radek.brich@devl.cz>
parents:
82
diff
changeset
|
405 |
dbgmsg(2, "\b\b\b\b\b\b\b\b%2d%% done", ((long)sampdone - sample_queue_count)*100/sampnum); |
51
89fec8668768
remove debug messages - algorithm seems stable, but it's slow
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
406 |
|
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
407 |
pthread_mutex_lock(&sampler_mutex); |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
408 |
|
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
409 |
if (!more_samples) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
410 |
break; |
46 | 411 |
} |
51
89fec8668768
remove debug messages - algorithm seems stable, but it's slow
Radek Brich <radek.brich@devl.cz>
parents:
50
diff
changeset
|
412 |
dbgmsg(2, "\b\b\b\b\b\b\b\b100%% done\n"); |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
413 |
|
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
414 |
pthread_mutex_unlock(&sampler_mutex); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
415 |
|
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
416 |
// wait for workers |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
417 |
dbgmsg(2, "- waiting for threads to finish\n"); |
46 | 418 |
|
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
419 |
pthread_mutex_lock(&sample_queue_mutex); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
420 |
end_of_samples = true; |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
421 |
while (sample_queue_count) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
422 |
{ |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
423 |
pthread_cond_broadcast(&sample_queue_cond); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
424 |
pthread_mutex_unlock(&sample_queue_mutex); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
425 |
pthread_mutex_lock(&sample_queue_mutex); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
426 |
} |
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
427 |
pthread_cond_broadcast(&sample_queue_cond); |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
428 |
pthread_mutex_unlock(&sample_queue_mutex); |
77
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
429 |
|
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
430 |
for (int t = 0; t < num_threads; t++) |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
431 |
pthread_join(threads[t], NULL); |
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
432 |
|
dbe8438d5dca
rewrite subsampling from old code to DefaultSampler
Radek Brich <radek.brich@devl.cz>
parents:
75
diff
changeset
|
433 |
phase ++; |
50
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
434 |
} |
14a727b70d07
rewritten threads with heavy debug information
Radek Brich <radek.brich@devl.cz>
parents:
49
diff
changeset
|
435 |
|
52
a6413a3d741d
new implementation of sample_queue
Radek Brich <radek.brich@devl.cz>
parents:
51
diff
changeset
|
436 |
delete[] sample_queue; |
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
|
437 |
} |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
438 |
|
75
20dee9819b17
unify capitalization of method names in C++ and Python
Radek Brich <radek.brich@devl.cz>
parents:
72
diff
changeset
|
439 |
void Raytracer::ambientOcclusion(int samples, Float distance, Float angle) |
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
|
440 |
{ |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
441 |
ao_samples = samples; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
442 |
ao_distance = distance; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
443 |
ao_angle = angle; |
3547b885df7e
initial commit, raytracer source as written year ago and unchanged since 2007-03-25
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
444 |
if (ao_distance == 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
|
445 |
/* 0 ==> Inf */ |
53
228cb8bfdd54
slighly optimized raytrace_worker
Radek Brich <radek.brich@devl.cz>
parents:
52
diff
changeset
|
446 |
ao_distance = Inf; |
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
|
447 |
} |