-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathbidirectional_8cpp-source.html
234 lines (234 loc) · 41.4 KB
/
bidirectional_8cpp-source.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>pbrt: bidirectional.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<h1>bidirectional.cpp</h1><a href="bidirectional_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
<a name="l00002"></a>00002 <span class="comment">/*</span>
<a name="l00003"></a>00003 <span class="comment"> pbrt source code Copyright(c) 1998-2007 Matt Pharr and Greg Humphreys.</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment"> This file is part of pbrt.</span>
<a name="l00006"></a>00006 <span class="comment"></span>
<a name="l00007"></a>00007 <span class="comment"> pbrt is free software; you can redistribute it and/or modify</span>
<a name="l00008"></a>00008 <span class="comment"> it under the terms of the GNU General Public License as published by</span>
<a name="l00009"></a>00009 <span class="comment"> the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00010"></a>00010 <span class="comment"> (at your option) any later version. Note that the text contents of</span>
<a name="l00011"></a>00011 <span class="comment"> the book "Physically Based Rendering" are *not* licensed under the</span>
<a name="l00012"></a>00012 <span class="comment"> GNU GPL.</span>
<a name="l00013"></a>00013 <span class="comment"></span>
<a name="l00014"></a>00014 <span class="comment"> pbrt is distributed in the hope that it will be useful,</span>
<a name="l00015"></a>00015 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00016"></a>00016 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<a name="l00017"></a>00017 <span class="comment"> GNU General Public License for more details.</span>
<a name="l00018"></a>00018 <span class="comment"></span>
<a name="l00019"></a>00019 <span class="comment"> You should have received a copy of the GNU General Public License</span>
<a name="l00020"></a>00020 <span class="comment"> along with this program. If not, see <http://www.gnu.org/licenses/>.</span>
<a name="l00021"></a>00021 <span class="comment"></span>
<a name="l00022"></a>00022 <span class="comment"> */</span>
<a name="l00023"></a>00023
<a name="l00024"></a>00024 <span class="comment">// bidirectional.cpp*</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="pbrt_8h.html">pbrt.h</a>"</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="transport_8h.html">transport.h</a>"</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include "<a class="code" href="scene_8h.html">scene.h</a>"</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include "<a class="code" href="mc_8h.html">mc.h</a>"</span>
<a name="l00029"></a>00029 <span class="comment">// Bidirectional Local Declarations</span>
<a name="l00030"></a>00030 <span class="keyword">struct </span><a class="code" href="structBidirVertex.html">BidirVertex</a>;
<a name="l00031"></a><a class="code" href="classBidirIntegrator.html">00031</a> <span class="keyword">class </span><a class="code" href="classBidirIntegrator.html">BidirIntegrator</a> : <span class="keyword">public</span> <a class="code" href="classSurfaceIntegrator.html">SurfaceIntegrator</a> {
<a name="l00032"></a>00032 <span class="keyword">public</span>:
<a name="l00033"></a>00033 <span class="comment">// BidirIntegrator Public Methods</span>
<a name="l00034"></a>00034 <a class="code" href="classSpectrum.html">Spectrum</a> <a class="code" href="classBidirIntegrator.html#ea96afae536ff7475ea6afa7682c46e4">Li</a>(<span class="keyword">const</span> <a class="code" href="classScene.html">Scene</a> *scene, <span class="keyword">const</span> <a class="code" href="classRayDifferential.html">RayDifferential</a> &ray, <span class="keyword">const</span> <a class="code" href="structSample.html">Sample</a> *sample, <span class="keywordtype">float</span> *alpha) <span class="keyword">const</span>;
<a name="l00035"></a>00035 <span class="keywordtype">void</span> <a class="code" href="classBidirIntegrator.html#7a5f53d7aa66c97ab10a1803758d38ad">RequestSamples</a>(<a class="code" href="structSample.html">Sample</a> *sample, <span class="keyword">const</span> <a class="code" href="classScene.html">Scene</a> *scene);
<a name="l00036"></a>00036 <span class="keyword">private</span>:
<a name="l00037"></a>00037 <span class="comment">// BidirIntegrator Private Methods</span>
<a name="l00038"></a>00038 <span class="keywordtype">int</span> <a class="code" href="classBidirIntegrator.html#4809b915a817d284a38dfa25e965ed7a">generatePath</a>(<span class="keyword">const</span> <a class="code" href="classScene.html">Scene</a> *scene, <span class="keyword">const</span> <a class="code" href="classRay.html">Ray</a> &r, <span class="keyword">const</span> <a class="code" href="structSample.html">Sample</a> *sample,
<a name="l00039"></a>00039 <span class="keyword">const</span> <span class="keywordtype">int</span> *bsdfOffset, <span class="keyword">const</span> <span class="keywordtype">int</span> *bsdfCompOffset,
<a name="l00040"></a>00040 <a class="code" href="structBidirVertex.html">BidirVertex</a> *vertices, <span class="keywordtype">int</span> maxVerts) <span class="keyword">const</span>;
<a name="l00041"></a>00041 <span class="keywordtype">float</span> <a class="code" href="classBidirIntegrator.html#d1edf6a6df526788f46a2501c34649c5">weightPath</a>(<a class="code" href="structBidirVertex.html">BidirVertex</a> *eye, <span class="keywordtype">int</span> nEye, <a class="code" href="structBidirVertex.html">BidirVertex</a> *light, <span class="keywordtype">int</span> nLight) <span class="keyword">const</span>;
<a name="l00042"></a>00042 <a class="code" href="classSpectrum.html">Spectrum</a> <a class="code" href="classBidirIntegrator.html#bcf89054339d5c0e92d3ba1e174ccdae">evalPath</a>(<span class="keyword">const</span> <a class="code" href="classScene.html">Scene</a> *scene, <a class="code" href="structBidirVertex.html">BidirVertex</a> *eye, <span class="keywordtype">int</span> nEye,
<a name="l00043"></a>00043 <a class="code" href="structBidirVertex.html">BidirVertex</a> *light, <span class="keywordtype">int</span> nLight) <span class="keyword">const</span>;
<a name="l00044"></a>00044 <span class="keyword">static</span> <span class="keywordtype">float</span> <a class="code" href="classBidirIntegrator.html#c74413af0858c6b32e285f714549dc43">G</a>(<span class="keyword">const</span> <a class="code" href="structBidirVertex.html">BidirVertex</a> &v0, <span class="keyword">const</span> <a class="code" href="structBidirVertex.html">BidirVertex</a> &v1);
<a name="l00045"></a>00045 <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classBidirIntegrator.html#3171d808dcf882e2457ca021c1155d6c">visible</a>(<span class="keyword">const</span> <a class="code" href="classScene.html">Scene</a> *scene, <span class="keyword">const</span> <a class="code" href="classPoint.html">Point</a> &P0, <span class="keyword">const</span> <a class="code" href="classPoint.html">Point</a> &P1);
<a name="l00046"></a>00046 <span class="comment">// BidirIntegrator Data</span>
<a name="l00047"></a><a class="code" href="bidirectional_8cpp.html#5c84c1a3c727eb9feb5e7b6ecda33b16">00047</a> <span class="preprocessor"> #define MAX_VERTS 4</span>
<a name="l00048"></a><a class="code" href="classBidirIntegrator.html#8c507afa65c7dc17ab2a8ca789d4d291">00048</a> <span class="preprocessor"></span> <span class="keywordtype">int</span> <a class="code" href="classBidirIntegrator.html#8c507afa65c7dc17ab2a8ca789d4d291">eyeBSDFOffset</a>[<a class="code" href="bidirectional_8cpp.html#5c84c1a3c727eb9feb5e7b6ecda33b16">MAX_VERTS</a>], <a class="code" href="classBidirIntegrator.html#e10b42ae22b956ad067dec9746b17fbd">eyeBSDFCompOffset</a>[<a class="code" href="bidirectional_8cpp.html#5c84c1a3c727eb9feb5e7b6ecda33b16">MAX_VERTS</a>];
<a name="l00049"></a><a class="code" href="classBidirIntegrator.html#ac93903e90463d2a10fa296fa0f9895e">00049</a> <span class="keywordtype">int</span> <a class="code" href="classBidirIntegrator.html#ac93903e90463d2a10fa296fa0f9895e">lightBSDFOffset</a>[<a class="code" href="bidirectional_8cpp.html#5c84c1a3c727eb9feb5e7b6ecda33b16">MAX_VERTS</a>], <a class="code" href="classBidirIntegrator.html#4ad6b3d7ff55ba9c55a6ad0c3f91220e">lightBSDFCompOffset</a>[<a class="code" href="bidirectional_8cpp.html#5c84c1a3c727eb9feb5e7b6ecda33b16">MAX_VERTS</a>];
<a name="l00050"></a><a class="code" href="classBidirIntegrator.html#95f02b3116c4971ea69d6a42d1963285">00050</a> <span class="keywordtype">int</span> <a class="code" href="classBidirIntegrator.html#95f02b3116c4971ea69d6a42d1963285">directLightOffset</a>[<a class="code" href="bidirectional_8cpp.html#5c84c1a3c727eb9feb5e7b6ecda33b16">MAX_VERTS</a>], <a class="code" href="classBidirIntegrator.html#855ce617cd2757f14ec2dd032a7bfc02">directLightNumOffset</a>[<a class="code" href="bidirectional_8cpp.html#5c84c1a3c727eb9feb5e7b6ecda33b16">MAX_VERTS</a>];
<a name="l00051"></a><a class="code" href="classBidirIntegrator.html#05b304172b328e4e9d235b41538c428c">00051</a> <span class="keywordtype">int</span> <a class="code" href="classBidirIntegrator.html#05b304172b328e4e9d235b41538c428c">directBSDFOffset</a>[<a class="code" href="bidirectional_8cpp.html#5c84c1a3c727eb9feb5e7b6ecda33b16">MAX_VERTS</a>], <a class="code" href="classBidirIntegrator.html#3aac236b97991f3e7800278d7ff3edc1">directBSDFCompOffset</a>[<a class="code" href="bidirectional_8cpp.html#5c84c1a3c727eb9feb5e7b6ecda33b16">MAX_VERTS</a>];
<a name="l00052"></a><a class="code" href="classBidirIntegrator.html#f19f4b23a19e39ad674d5819c78e5ee5">00052</a> <span class="keywordtype">int</span> <a class="code" href="classBidirIntegrator.html#c59c244c5a40df32b8a23658ac73d082">lightNumOffset</a>, <a class="code" href="classBidirIntegrator.html#f19f4b23a19e39ad674d5819c78e5ee5">lightPosOffset</a>, <a class="code" href="classBidirIntegrator.html#d40a2a95be37f2e53e11a770bc8851a2">lightDirOffset</a>;
<a name="l00053"></a>00053 };
<a name="l00054"></a><a class="code" href="structBidirVertex.html">00054</a> <span class="keyword">struct </span><a class="code" href="structBidirVertex.html">BidirVertex</a> {
<a name="l00055"></a><a class="code" href="structBidirVertex.html#7f4a4067ffef2a8ed5d860f6251bb5d8">00055</a> <a class="code" href="structBidirVertex.html#7f4a4067ffef2a8ed5d860f6251bb5d8">BidirVertex</a>() { <a class="code" href="structBidirVertex.html#49c9235e9f411a149b27700c55019d9b">bsdfWeight</a> = <a class="code" href="structBidirVertex.html#d1016768794eb76d1d4f6e77942a49b1">dAWeight</a> = 0.; <a class="code" href="structBidirVertex.html#857ed97160e3cf94db12dbabc06c0191">rrWeight</a> = 1.;
<a name="l00056"></a>00056 <a class="code" href="structBidirVertex.html#096b753667c8acf27900b3f09c96df20">flags</a> = <a class="code" href="reflection_8h.html#0ab5fa7d70a51348af4188bf1e669730">BxDFType</a>(0); <a class="code" href="structBidirVertex.html#2d78337f5ec0635c0cce5dd78bda1e0c">bsdf</a> = NULL; }
<a name="l00057"></a><a class="code" href="structBidirVertex.html#2d78337f5ec0635c0cce5dd78bda1e0c">00057</a> <a class="code" href="classBSDF.html">BSDF</a> *<a class="code" href="structBidirVertex.html#2d78337f5ec0635c0cce5dd78bda1e0c">bsdf</a>;
<a name="l00058"></a><a class="code" href="structBidirVertex.html#a100945b9113a983c702c2ba619faddc">00058</a> <a class="code" href="classPoint.html">Point</a> <a class="code" href="structBidirVertex.html#a100945b9113a983c702c2ba619faddc">p</a>;
<a name="l00059"></a><a class="code" href="structBidirVertex.html#16109bc6708caff5e8e471ad902d3f8e">00059</a> <a class="code" href="classNormal.html">Normal</a> <a class="code" href="structBidirVertex.html#ddcb5c57aa24287cbf997ff2ef20f8ae">ng</a>, <a class="code" href="structBidirVertex.html#16109bc6708caff5e8e471ad902d3f8e">ns</a>;
<a name="l00060"></a><a class="code" href="structBidirVertex.html#55114967c70275932d4bce7589b42270">00060</a> <a class="code" href="classVector.html">Vector</a> <a class="code" href="structBidirVertex.html#1c5c0540ebfca79dfdfec130c777524a">wi</a>, <a class="code" href="structBidirVertex.html#55114967c70275932d4bce7589b42270">wo</a>;
<a name="l00061"></a><a class="code" href="structBidirVertex.html#857ed97160e3cf94db12dbabc06c0191">00061</a> <span class="keywordtype">float</span> <a class="code" href="structBidirVertex.html#49c9235e9f411a149b27700c55019d9b">bsdfWeight</a>, <a class="code" href="structBidirVertex.html#d1016768794eb76d1d4f6e77942a49b1">dAWeight</a>, <a class="code" href="structBidirVertex.html#857ed97160e3cf94db12dbabc06c0191">rrWeight</a>;
<a name="l00062"></a><a class="code" href="structBidirVertex.html#096b753667c8acf27900b3f09c96df20">00062</a> <a class="code" href="reflection_8h.html#0ab5fa7d70a51348af4188bf1e669730">BxDFType</a> <a class="code" href="structBidirVertex.html#096b753667c8acf27900b3f09c96df20">flags</a>;
<a name="l00063"></a>00063 };
<a name="l00064"></a>00064 <span class="comment">// Bidirectional Method Definitions</span>
<a name="l00065"></a><a class="code" href="classBidirIntegrator.html#7a5f53d7aa66c97ab10a1803758d38ad">00065</a> <span class="keywordtype">void</span> <a class="code" href="classBidirIntegrator.html#7a5f53d7aa66c97ab10a1803758d38ad">BidirIntegrator::RequestSamples</a>(<a class="code" href="structSample.html">Sample</a> *sample, <span class="keyword">const</span> <a class="code" href="classScene.html">Scene</a> *scene) {
<a name="l00066"></a>00066 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="bidirectional_8cpp.html#5c84c1a3c727eb9feb5e7b6ecda33b16">MAX_VERTS</a>; ++i) {
<a name="l00067"></a>00067 <a class="code" href="classBidirIntegrator.html#8c507afa65c7dc17ab2a8ca789d4d291">eyeBSDFOffset</a>[i] = sample-><a class="code" href="structSample.html#21b7f539ec14f3b5c7bdddf790e1b8a7">Add2D</a>(1);
<a name="l00068"></a>00068 <a class="code" href="classBidirIntegrator.html#e10b42ae22b956ad067dec9746b17fbd">eyeBSDFCompOffset</a>[i] = sample-><a class="code" href="structSample.html#a2b567c5a4160488ba81953b59df59f0">Add1D</a>(1);
<a name="l00069"></a>00069 <a class="code" href="classBidirIntegrator.html#ac93903e90463d2a10fa296fa0f9895e">lightBSDFOffset</a>[i] = sample-><a class="code" href="structSample.html#21b7f539ec14f3b5c7bdddf790e1b8a7">Add2D</a>(1);
<a name="l00070"></a>00070 <a class="code" href="classBidirIntegrator.html#4ad6b3d7ff55ba9c55a6ad0c3f91220e">lightBSDFCompOffset</a>[i] = sample-><a class="code" href="structSample.html#a2b567c5a4160488ba81953b59df59f0">Add1D</a>(1);
<a name="l00071"></a>00071 <a class="code" href="classBidirIntegrator.html#95f02b3116c4971ea69d6a42d1963285">directLightOffset</a>[i] = sample-><a class="code" href="structSample.html#21b7f539ec14f3b5c7bdddf790e1b8a7">Add2D</a>(1);
<a name="l00072"></a>00072 <a class="code" href="classBidirIntegrator.html#855ce617cd2757f14ec2dd032a7bfc02">directLightNumOffset</a>[i] = sample-><a class="code" href="structSample.html#a2b567c5a4160488ba81953b59df59f0">Add1D</a>(1);
<a name="l00073"></a>00073 <a class="code" href="classBidirIntegrator.html#05b304172b328e4e9d235b41538c428c">directBSDFOffset</a>[i] = sample-><a class="code" href="structSample.html#21b7f539ec14f3b5c7bdddf790e1b8a7">Add2D</a>(1);
<a name="l00074"></a>00074 <a class="code" href="classBidirIntegrator.html#3aac236b97991f3e7800278d7ff3edc1">directBSDFCompOffset</a>[i] = sample-><a class="code" href="structSample.html#a2b567c5a4160488ba81953b59df59f0">Add1D</a>(1);
<a name="l00075"></a>00075 }
<a name="l00076"></a>00076 <a class="code" href="classBidirIntegrator.html#c59c244c5a40df32b8a23658ac73d082">lightNumOffset</a> = sample-><a class="code" href="structSample.html#a2b567c5a4160488ba81953b59df59f0">Add1D</a>(1);
<a name="l00077"></a>00077 <a class="code" href="classBidirIntegrator.html#f19f4b23a19e39ad674d5819c78e5ee5">lightPosOffset</a> = sample-><a class="code" href="structSample.html#21b7f539ec14f3b5c7bdddf790e1b8a7">Add2D</a>(1);
<a name="l00078"></a>00078 <a class="code" href="classBidirIntegrator.html#d40a2a95be37f2e53e11a770bc8851a2">lightDirOffset</a> = sample-><a class="code" href="structSample.html#21b7f539ec14f3b5c7bdddf790e1b8a7">Add2D</a>(1);
<a name="l00079"></a>00079 }
<a name="l00080"></a><a class="code" href="classBidirIntegrator.html#ea96afae536ff7475ea6afa7682c46e4">00080</a> <a class="code" href="classSpectrum.html">Spectrum</a> <a class="code" href="classBidirIntegrator.html#ea96afae536ff7475ea6afa7682c46e4">BidirIntegrator::Li</a>(<span class="keyword">const</span> <a class="code" href="classScene.html">Scene</a> *scene,
<a name="l00081"></a>00081 <span class="keyword">const</span> <a class="code" href="classRayDifferential.html">RayDifferential</a> &ray,
<a name="l00082"></a>00082 <span class="keyword">const</span> <a class="code" href="structSample.html">Sample</a> *sample, <span class="keywordtype">float</span> *alpha)<span class="keyword"> const </span>{
<a name="l00083"></a>00083 <a class="code" href="classSpectrum.html">Spectrum</a> L(0.);
<a name="l00084"></a>00084 <span class="comment">// Generate eye and light sub-paths</span>
<a name="l00085"></a>00085 <a class="code" href="structBidirVertex.html">BidirVertex</a> eyePath[<a class="code" href="bidirectional_8cpp.html#5c84c1a3c727eb9feb5e7b6ecda33b16">MAX_VERTS</a>], lightPath[<a class="code" href="bidirectional_8cpp.html#5c84c1a3c727eb9feb5e7b6ecda33b16">MAX_VERTS</a>];
<a name="l00086"></a>00086 <span class="keywordtype">int</span> nEye = <a class="code" href="classBidirIntegrator.html#4809b915a817d284a38dfa25e965ed7a">generatePath</a>(scene, ray, sample, <a class="code" href="classBidirIntegrator.html#8c507afa65c7dc17ab2a8ca789d4d291">eyeBSDFOffset</a>,
<a name="l00087"></a>00087 <a class="code" href="classBidirIntegrator.html#e10b42ae22b956ad067dec9746b17fbd">eyeBSDFCompOffset</a>, eyePath, <a class="code" href="bidirectional_8cpp.html#5c84c1a3c727eb9feb5e7b6ecda33b16">MAX_VERTS</a>);
<a name="l00088"></a>00088 <span class="keywordflow">if</span> (nEye == 0) {
<a name="l00089"></a>00089 *alpha = 0.;
<a name="l00090"></a>00090 <span class="keywordflow">return</span> L;
<a name="l00091"></a>00091 }
<a name="l00092"></a>00092 *alpha = 1;
<a name="l00093"></a>00093 <span class="comment">// Choose light for bidirectional path</span>
<a name="l00094"></a>00094 <span class="keywordtype">int</span> lightNum = <a class="code" href="pbrt_8h.html#02648670ea7bf29f5782902cd9aa87c1">Floor2Int</a>(sample-><a class="code" href="structSample.html#4a1ae5fbae61678e57efaf185a319ceb">oneD</a>[<a class="code" href="classBidirIntegrator.html#c59c244c5a40df32b8a23658ac73d082">lightNumOffset</a>][0] *
<a name="l00095"></a>00095 scene-><a class="code" href="classScene.html#546553c8f864fd2aa709ad95a1d5ecc9">lights</a>.size());
<a name="l00096"></a>00096 lightNum = min(lightNum, (<span class="keywordtype">int</span>)scene-><a class="code" href="classScene.html#546553c8f864fd2aa709ad95a1d5ecc9">lights</a>.size() - 1);
<a name="l00097"></a>00097 <a class="code" href="classLight.html">Light</a> *light = scene-><a class="code" href="classScene.html#546553c8f864fd2aa709ad95a1d5ecc9">lights</a>[lightNum];
<a name="l00098"></a>00098 <span class="keywordtype">float</span> lightWeight = float(scene-><a class="code" href="classScene.html#546553c8f864fd2aa709ad95a1d5ecc9">lights</a>.size());
<a name="l00099"></a>00099 <span class="comment">// Sample ray from light source to start light path</span>
<a name="l00100"></a>00100 <a class="code" href="classRay.html">Ray</a> lightRay;
<a name="l00101"></a>00101 <span class="keywordtype">float</span> lightPdf;
<a name="l00102"></a>00102 <span class="keywordtype">float</span> u[4];
<a name="l00103"></a>00103 u[0] = sample-><a class="code" href="structSample.html#8e0e38f3500cced0e381981d0aec7914">twoD</a>[<a class="code" href="classBidirIntegrator.html#f19f4b23a19e39ad674d5819c78e5ee5">lightPosOffset</a>][0];
<a name="l00104"></a>00104 u[1] = sample-><a class="code" href="structSample.html#8e0e38f3500cced0e381981d0aec7914">twoD</a>[<a class="code" href="classBidirIntegrator.html#f19f4b23a19e39ad674d5819c78e5ee5">lightPosOffset</a>][1];
<a name="l00105"></a>00105 u[2] = sample-><a class="code" href="structSample.html#8e0e38f3500cced0e381981d0aec7914">twoD</a>[<a class="code" href="classBidirIntegrator.html#d40a2a95be37f2e53e11a770bc8851a2">lightDirOffset</a>][0];
<a name="l00106"></a>00106 u[3] = sample-><a class="code" href="structSample.html#8e0e38f3500cced0e381981d0aec7914">twoD</a>[<a class="code" href="classBidirIntegrator.html#d40a2a95be37f2e53e11a770bc8851a2">lightDirOffset</a>][1];
<a name="l00107"></a>00107 <a class="code" href="classSpectrum.html">Spectrum</a> Le = light->Sample_L(scene, u[0], u[1], u[2], u[3],
<a name="l00108"></a>00108 &lightRay, &lightPdf);
<a name="l00109"></a>00109 <span class="keywordflow">if</span> (lightPdf == 0.) <span class="keywordflow">return</span> 0.f;
<a name="l00110"></a>00110 Le = lightWeight / lightPdf;
<a name="l00111"></a>00111 <span class="keywordtype">int</span> nLight = <a class="code" href="classBidirIntegrator.html#4809b915a817d284a38dfa25e965ed7a">generatePath</a>(scene, lightRay, sample, <a class="code" href="classBidirIntegrator.html#ac93903e90463d2a10fa296fa0f9895e">lightBSDFOffset</a>,
<a name="l00112"></a>00112 <a class="code" href="classBidirIntegrator.html#4ad6b3d7ff55ba9c55a6ad0c3f91220e">lightBSDFCompOffset</a>, lightPath, <a class="code" href="bidirectional_8cpp.html#5c84c1a3c727eb9feb5e7b6ecda33b16">MAX_VERTS</a>);
<a name="l00113"></a>00113 <span class="comment">// Connect bidirectional path prefixes and evaluate throughput</span>
<a name="l00114"></a>00114 <a class="code" href="classSpectrum.html">Spectrum</a> directWt(1.0);
<a name="l00115"></a>00115 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i <= nEye; ++i) {
<a name="l00116"></a>00116 <span class="comment">// Handle direct lighting for bidirectional integrator</span>
<a name="l00117"></a>00117 directWt /= eyePath[i-1].<a class="code" href="structBidirVertex.html#857ed97160e3cf94db12dbabc06c0191">rrWeight</a>;
<a name="l00118"></a>00118 L += directWt *
<a name="l00119"></a>00119 <a class="code" href="transport_8cpp.html#0005379f28153d39ff77ae784c38cfdf">UniformSampleOneLight</a>(scene, eyePath[i-1].p, eyePath[i-1].ng, eyePath[i-1].wi,
<a name="l00120"></a>00120 eyePath[i-1].bsdf, sample, <a class="code" href="classBidirIntegrator.html#95f02b3116c4971ea69d6a42d1963285">directLightOffset</a>[i-1], <a class="code" href="classBidirIntegrator.html#855ce617cd2757f14ec2dd032a7bfc02">directLightNumOffset</a>[i-1],
<a name="l00121"></a>00121 <a class="code" href="classBidirIntegrator.html#05b304172b328e4e9d235b41538c428c">directBSDFOffset</a>[i-1], <a class="code" href="classBidirIntegrator.html#3aac236b97991f3e7800278d7ff3edc1">directBSDFCompOffset</a>[i-1]) /
<a name="l00122"></a>00122 <a class="code" href="classBidirIntegrator.html#d1edf6a6df526788f46a2501c34649c5">weightPath</a>(eyePath, i, lightPath, 0);
<a name="l00123"></a>00123 directWt *= eyePath[i-1].<a class="code" href="structBidirVertex.html#2d78337f5ec0635c0cce5dd78bda1e0c">bsdf</a>-><a class="code" href="classBSDF.html#137c0efa679347a2787b366effdeeb50">f</a>(eyePath[i-1].wi, eyePath[i-1].wo) *
<a name="l00124"></a>00124 <a class="code" href="geometry_8h.html#0c07ebf9b1454b90d6646a2f89065bb3">AbsDot</a>(eyePath[i-1].wo, eyePath[i-1].ng) /
<a name="l00125"></a>00125 eyePath[i-1].<a class="code" href="structBidirVertex.html#49c9235e9f411a149b27700c55019d9b">bsdfWeight</a>;
<a name="l00126"></a>00126 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 1; j <= nLight; ++j)
<a name="l00127"></a>00127 L += Le * <a class="code" href="classBidirIntegrator.html#bcf89054339d5c0e92d3ba1e174ccdae">evalPath</a>(scene, eyePath, i, lightPath, j) /
<a name="l00128"></a>00128 <a class="code" href="classBidirIntegrator.html#d1edf6a6df526788f46a2501c34649c5">weightPath</a>(eyePath, i, lightPath, j);
<a name="l00129"></a>00129 }
<a name="l00130"></a>00130 <span class="keywordflow">return</span> L;
<a name="l00131"></a>00131 }
<a name="l00132"></a><a class="code" href="classBidirIntegrator.html#4809b915a817d284a38dfa25e965ed7a">00132</a> <span class="keywordtype">int</span> <a class="code" href="classBidirIntegrator.html#4809b915a817d284a38dfa25e965ed7a">BidirIntegrator::generatePath</a>(<span class="keyword">const</span> <a class="code" href="classScene.html">Scene</a> *scene, <span class="keyword">const</span> <a class="code" href="classRay.html">Ray</a> &r,
<a name="l00133"></a>00133 <span class="keyword">const</span> <a class="code" href="structSample.html">Sample</a> *sample, <span class="keyword">const</span> <span class="keywordtype">int</span> *bsdfOffset,
<a name="l00134"></a>00134 <span class="keyword">const</span> <span class="keywordtype">int</span> *bsdfCompOffset,
<a name="l00135"></a>00135 <a class="code" href="structBidirVertex.html">BidirVertex</a> *vertices, <span class="keywordtype">int</span> maxVerts)<span class="keyword"> const </span>{
<a name="l00136"></a>00136 <span class="keywordtype">int</span> nVerts = 0;
<a name="l00137"></a>00137 <a class="code" href="classRayDifferential.html">RayDifferential</a> ray(r.<a class="code" href="classRay.html#1014d000992e8ac3b92f150ad2a5cffe">o</a>, r.<a class="code" href="classRay.html#5bbfc94e178e0a050b51200acc579069">d</a>);
<a name="l00138"></a>00138 <span class="keywordflow">while</span> (nVerts < maxVerts) {
<a name="l00139"></a>00139 <span class="comment">// Find next vertex in path and initialize _vertices_</span>
<a name="l00140"></a>00140 <a class="code" href="structIntersection.html">Intersection</a> isect;
<a name="l00141"></a>00141 <span class="keywordflow">if</span> (!scene-><a class="code" href="classScene.html#36f27fc416cc5b53fe03575e2d15803a">Intersect</a>(ray, &isect))
<a name="l00142"></a>00142 <span class="keywordflow">break</span>;
<a name="l00143"></a>00143 <a class="code" href="structBidirVertex.html">BidirVertex</a> &v = vertices[nVerts];
<a name="l00144"></a>00144 v.<a class="code" href="structBidirVertex.html#2d78337f5ec0635c0cce5dd78bda1e0c">bsdf</a> = isect.<a class="code" href="structIntersection.html#ff18bb39143b49fa340a3697b9c606b5">GetBSDF</a>(ray); <span class="comment">// do before Ns is set!</span>
<a name="l00145"></a>00145 v.<a class="code" href="structBidirVertex.html#a100945b9113a983c702c2ba619faddc">p</a> = isect.<a class="code" href="structIntersection.html#27a04b9f68291416c4d864f105a7d991">dg</a>.<a class="code" href="structDifferentialGeometry.html#3d5353db1c1a6a93ef6da642d064f46e">p</a>;
<a name="l00146"></a>00146 v.<a class="code" href="structBidirVertex.html#ddcb5c57aa24287cbf997ff2ef20f8ae">ng</a> = isect.<a class="code" href="structIntersection.html#27a04b9f68291416c4d864f105a7d991">dg</a>.<a class="code" href="structDifferentialGeometry.html#1aa044f6c7b053ca460c10b0cf832c14">nn</a>;
<a name="l00147"></a>00147 v.<a class="code" href="structBidirVertex.html#16109bc6708caff5e8e471ad902d3f8e">ns</a> = v.<a class="code" href="structBidirVertex.html#2d78337f5ec0635c0cce5dd78bda1e0c">bsdf</a>-><a class="code" href="classBSDF.html#4fbebe2038bb049c50deba997a497f2d">dgShading</a>.<a class="code" href="structDifferentialGeometry.html#1aa044f6c7b053ca460c10b0cf832c14">nn</a>;
<a name="l00148"></a>00148 v.<a class="code" href="structBidirVertex.html#1c5c0540ebfca79dfdfec130c777524a">wi</a> = -ray.<a class="code" href="classRay.html#5bbfc94e178e0a050b51200acc579069">d</a>;
<a name="l00149"></a>00149 ++nVerts;
<a name="l00150"></a>00150 <span class="comment">// Possibly terminate bidirectional path sampling</span>
<a name="l00151"></a>00151 <span class="keywordflow">if</span> (nVerts > 2) {
<a name="l00152"></a>00152 <span class="keywordtype">float</span> rrProb = .2f;
<a name="l00153"></a>00153 <span class="keywordflow">if</span> (<a class="code" href="pbrt_8h.html#4f11994534b888fcf650c04b5d61d9d4">RandomFloat</a>() > rrProb)
<a name="l00154"></a>00154 <span class="keywordflow">break</span>;
<a name="l00155"></a>00155 v.<a class="code" href="structBidirVertex.html#857ed97160e3cf94db12dbabc06c0191">rrWeight</a> = 1.f / rrProb;
<a name="l00156"></a>00156 }
<a name="l00157"></a>00157 <span class="comment">// Initialize _ray_ for next segment of path</span>
<a name="l00158"></a>00158 <span class="keywordtype">float</span> u1 = sample-><a class="code" href="structSample.html#8e0e38f3500cced0e381981d0aec7914">twoD</a>[bsdfOffset[nVerts-1]][0];
<a name="l00159"></a>00159 <span class="keywordtype">float</span> u2 = sample-><a class="code" href="structSample.html#8e0e38f3500cced0e381981d0aec7914">twoD</a>[bsdfOffset[nVerts-1]][1];
<a name="l00160"></a>00160 <span class="keywordtype">float</span> u3 = sample-><a class="code" href="structSample.html#4a1ae5fbae61678e57efaf185a319ceb">oneD</a>[bsdfCompOffset[nVerts-1]][0];
<a name="l00161"></a>00161 <a class="code" href="classSpectrum.html">Spectrum</a> fr = v.<a class="code" href="structBidirVertex.html#2d78337f5ec0635c0cce5dd78bda1e0c">bsdf</a>-><a class="code" href="classBSDF.html#3498bc3b7484a17abd8429084124a0d4">Sample_f</a>(v.<a class="code" href="structBidirVertex.html#1c5c0540ebfca79dfdfec130c777524a">wi</a>, &v.<a class="code" href="structBidirVertex.html#55114967c70275932d4bce7589b42270">wo</a>, u1, u2, u3,
<a name="l00162"></a>00162 &v.<a class="code" href="structBidirVertex.html#49c9235e9f411a149b27700c55019d9b">bsdfWeight</a>, <a class="code" href="reflection_8h.html#0ab5fa7d70a51348af4188bf1e669730734897d21389ab0737866047d40e7122">BSDF_ALL</a>, &v.<a class="code" href="structBidirVertex.html#096b753667c8acf27900b3f09c96df20">flags</a>);
<a name="l00163"></a>00163 <span class="keywordflow">if</span> (fr.<a class="code" href="classSpectrum.html#a05b9a07476998192a83fcd015b7619f">Black</a>() && v.<a class="code" href="structBidirVertex.html#49c9235e9f411a149b27700c55019d9b">bsdfWeight</a> == 0.f)
<a name="l00164"></a>00164 <span class="keywordflow">break</span>;
<a name="l00165"></a>00165 ray = <a class="code" href="classRayDifferential.html">RayDifferential</a>(v.<a class="code" href="structBidirVertex.html#a100945b9113a983c702c2ba619faddc">p</a>, v.<a class="code" href="structBidirVertex.html#55114967c70275932d4bce7589b42270">wo</a>);
<a name="l00166"></a>00166 }
<a name="l00167"></a>00167 <span class="comment">// Initialize additional values in _vertices_</span>
<a name="l00168"></a>00168 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < nVerts-1; ++i)
<a name="l00169"></a>00169 vertices[i].dAWeight = vertices[i].bsdfWeight *
<a name="l00170"></a>00170 <a class="code" href="geometry_8h.html#0c07ebf9b1454b90d6646a2f89065bb3">AbsDot</a>(-vertices[i].wo, vertices[i+1].ng) /
<a name="l00171"></a>00171 <a class="code" href="geometry_8h.html#7e7a8e6ca4a481e5f0d1c44312a956d0">DistanceSquared</a>(vertices[i].p, vertices[i+1].p);
<a name="l00172"></a>00172 <span class="keywordflow">return</span> nVerts;
<a name="l00173"></a>00173 }
<a name="l00174"></a>00174
<a name="l00175"></a><a class="code" href="classBidirIntegrator.html#d1edf6a6df526788f46a2501c34649c5">00175</a> <span class="keywordtype">float</span> <a class="code" href="classBidirIntegrator.html#d1edf6a6df526788f46a2501c34649c5">BidirIntegrator::weightPath</a>(<a class="code" href="structBidirVertex.html">BidirVertex</a> *eye, <span class="keywordtype">int</span> nEye,
<a name="l00176"></a>00176 <a class="code" href="structBidirVertex.html">BidirVertex</a> *light, <span class="keywordtype">int</span> nLight)<span class="keyword"> const </span>{
<a name="l00177"></a>00177 <span class="keywordflow">return</span> float(nEye + nLight);
<a name="l00178"></a>00178 }
<a name="l00179"></a><a class="code" href="classBidirIntegrator.html#bcf89054339d5c0e92d3ba1e174ccdae">00179</a> <a class="code" href="classSpectrum.html">Spectrum</a> <a class="code" href="classBidirIntegrator.html#bcf89054339d5c0e92d3ba1e174ccdae">BidirIntegrator::evalPath</a>(<span class="keyword">const</span> <a class="code" href="classScene.html">Scene</a> *scene, <a class="code" href="structBidirVertex.html">BidirVertex</a> *eye, <span class="keywordtype">int</span> nEye,
<a name="l00180"></a>00180 <a class="code" href="structBidirVertex.html">BidirVertex</a> *light, <span class="keywordtype">int</span> nLight)<span class="keyword"> const </span>{
<a name="l00181"></a>00181 <a class="code" href="classSpectrum.html">Spectrum</a> L(1.);
<a name="l00182"></a>00182 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < nEye-1; ++i)
<a name="l00183"></a>00183 L *= eye[i].bsdf->f(eye[i].<a class="code" href="structBidirVertex.html#1c5c0540ebfca79dfdfec130c777524a">wi</a>, eye[i].<a class="code" href="structBidirVertex.html#55114967c70275932d4bce7589b42270">wo</a>) *
<a name="l00184"></a>00184 <a class="code" href="geometry_8h.html#0c07ebf9b1454b90d6646a2f89065bb3">AbsDot</a>(eye[i].wo, eye[i].ng) /
<a name="l00185"></a>00185 (eye[i].<a class="code" href="structBidirVertex.html#49c9235e9f411a149b27700c55019d9b">bsdfWeight</a> * eye[i].<a class="code" href="structBidirVertex.html#857ed97160e3cf94db12dbabc06c0191">rrWeight</a>);
<a name="l00186"></a>00186 <a class="code" href="classVector.html">Vector</a> w = light[nLight-1].<a class="code" href="structBidirVertex.html#a100945b9113a983c702c2ba619faddc">p</a> - eye[nEye-1].<a class="code" href="structBidirVertex.html#a100945b9113a983c702c2ba619faddc">p</a>;
<a name="l00187"></a>00187 L *= eye[nEye-1].<a class="code" href="structBidirVertex.html#2d78337f5ec0635c0cce5dd78bda1e0c">bsdf</a>-><a class="code" href="classBSDF.html#137c0efa679347a2787b366effdeeb50">f</a>(eye[nEye-1].wi, w) *
<a name="l00188"></a>00188 <a class="code" href="classBidirIntegrator.html#c74413af0858c6b32e285f714549dc43">G</a>(eye[nEye-1], light[nLight-1]) *
<a name="l00189"></a>00189 light[nLight-1].<a class="code" href="structBidirVertex.html#2d78337f5ec0635c0cce5dd78bda1e0c">bsdf</a>-><a class="code" href="classBSDF.html#137c0efa679347a2787b366effdeeb50">f</a>(-w, light[nLight-1].wi) /
<a name="l00190"></a>00190 (eye[nEye-1].<a class="code" href="structBidirVertex.html#857ed97160e3cf94db12dbabc06c0191">rrWeight</a> * light[nLight-1].<a class="code" href="structBidirVertex.html#857ed97160e3cf94db12dbabc06c0191">rrWeight</a>);
<a name="l00191"></a>00191 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = nLight-2; i >= 0; --i)
<a name="l00192"></a>00192 L *= light[i].bsdf->f(light[i].<a class="code" href="structBidirVertex.html#1c5c0540ebfca79dfdfec130c777524a">wi</a>, light[i].<a class="code" href="structBidirVertex.html#55114967c70275932d4bce7589b42270">wo</a>) *
<a name="l00193"></a>00193 <a class="code" href="geometry_8h.html#0c07ebf9b1454b90d6646a2f89065bb3">AbsDot</a>(light[i].wo, light[i].ng) /
<a name="l00194"></a>00194 (light[i].<a class="code" href="structBidirVertex.html#49c9235e9f411a149b27700c55019d9b">bsdfWeight</a> * light[i].<a class="code" href="structBidirVertex.html#857ed97160e3cf94db12dbabc06c0191">rrWeight</a>);
<a name="l00195"></a>00195 <span class="keywordflow">if</span> (L.<a class="code" href="classSpectrum.html#a05b9a07476998192a83fcd015b7619f">Black</a>())
<a name="l00196"></a>00196 <span class="keywordflow">return</span> L;
<a name="l00197"></a>00197 <span class="keywordflow">if</span> (!<a class="code" href="classBidirIntegrator.html#3171d808dcf882e2457ca021c1155d6c">visible</a>(scene, eye[nEye-1].p, light[nLight-1].p))
<a name="l00198"></a>00198 <span class="keywordflow">return</span> 0.;
<a name="l00199"></a>00199 <span class="keywordflow">return</span> L;
<a name="l00200"></a>00200 }
<a name="l00201"></a><a class="code" href="classBidirIntegrator.html#c74413af0858c6b32e285f714549dc43">00201</a> <span class="keywordtype">float</span> <a class="code" href="classBidirIntegrator.html#c74413af0858c6b32e285f714549dc43">BidirIntegrator::G</a>(<span class="keyword">const</span> <a class="code" href="structBidirVertex.html">BidirVertex</a> &v0, <span class="keyword">const</span> <a class="code" href="structBidirVertex.html">BidirVertex</a> &v1) {
<a name="l00202"></a>00202 <a class="code" href="classVector.html">Vector</a> w = <a class="code" href="geometry_8h.html#46448bfa3df1c2de5e3b763f163866a4">Normalize</a>(v1.<a class="code" href="structBidirVertex.html#a100945b9113a983c702c2ba619faddc">p</a> - v0.<a class="code" href="structBidirVertex.html#a100945b9113a983c702c2ba619faddc">p</a>);
<a name="l00203"></a>00203 <span class="keywordflow">return</span> <a class="code" href="geometry_8h.html#0c07ebf9b1454b90d6646a2f89065bb3">AbsDot</a>(v0.<a class="code" href="structBidirVertex.html#ddcb5c57aa24287cbf997ff2ef20f8ae">ng</a>, w) * <a class="code" href="geometry_8h.html#0c07ebf9b1454b90d6646a2f89065bb3">AbsDot</a>(v1.<a class="code" href="structBidirVertex.html#ddcb5c57aa24287cbf997ff2ef20f8ae">ng</a>, -w) /
<a name="l00204"></a>00204 <a class="code" href="geometry_8h.html#7e7a8e6ca4a481e5f0d1c44312a956d0">DistanceSquared</a>(v0.<a class="code" href="structBidirVertex.html#a100945b9113a983c702c2ba619faddc">p</a>, v1.<a class="code" href="structBidirVertex.html#a100945b9113a983c702c2ba619faddc">p</a>);
<a name="l00205"></a>00205 }
<a name="l00206"></a><a class="code" href="classBidirIntegrator.html#3171d808dcf882e2457ca021c1155d6c">00206</a> <span class="keywordtype">bool</span> <a class="code" href="classBidirIntegrator.html#3171d808dcf882e2457ca021c1155d6c">BidirIntegrator::visible</a>(<span class="keyword">const</span> <a class="code" href="classScene.html">Scene</a> *scene, <span class="keyword">const</span> <a class="code" href="classPoint.html">Point</a> &P0,
<a name="l00207"></a>00207 <span class="keyword">const</span> <a class="code" href="classPoint.html">Point</a> &P1) {
<a name="l00208"></a>00208 <a class="code" href="classRay.html">Ray</a> ray(P0, P1-P0, <a class="code" href="pbrt_8h.html#7507e14449e57d80d946ee4509de1b3b">RAY_EPSILON</a>, 1.f - <a class="code" href="pbrt_8h.html#7507e14449e57d80d946ee4509de1b3b">RAY_EPSILON</a>);
<a name="l00209"></a>00209 <span class="keywordflow">return</span> !scene-><a class="code" href="classScene.html#558b5f74407c7479517ef82b0fe3f913">IntersectP</a>(ray);
<a name="l00210"></a>00210 }
<a name="l00211"></a><a class="code" href="bidirectional_8cpp.html#292dab5329893d80187ce895221b3e6d">00211</a> <span class="keyword">extern</span> <span class="stringliteral">"C"</span> <a class="code" href="pbrt_8h.html#808e08638be3cba36e36759e5b150de0">DLLEXPORT</a> <a class="code" href="classSurfaceIntegrator.html">SurfaceIntegrator</a> *<a class="code" href="bidirectional_8cpp.html#292dab5329893d80187ce895221b3e6d">CreateSurfaceIntegrator</a>(<span class="keyword">const</span> <a class="code" href="classParamSet.html">ParamSet</a> &params) {
<a name="l00212"></a>00212 <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classBidirIntegrator.html">BidirIntegrator</a>;
<a name="l00213"></a>00213 }
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 20 17:31:52 2009 for pbrt by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>