2
* Copyright 2011, Blender Foundation.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2
* Copyright 2011-2013 Blender Foundation
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License
19
17
CCL_NAMESPACE_BEGIN
33
31
eval->glossy = make_float3(0.0f, 0.0f, 0.0f);
34
32
eval->transmission = make_float3(0.0f, 0.0f, 0.0f);
35
33
eval->transparent = make_float3(0.0f, 0.0f, 0.0f);
34
eval->subsurface = make_float3(0.0f, 0.0f, 0.0f);
37
36
if(type == CLOSURE_BSDF_TRANSPARENT_ID)
38
37
eval->transparent = value;
40
39
eval->diffuse = value;
41
40
else if(CLOSURE_IS_BSDF_GLOSSY(type))
42
41
eval->glossy = value;
42
else if(CLOSURE_IS_BSDF_TRANSMISSION(type))
44
43
eval->transmission = value;
44
else if(CLOSURE_IS_BSDF_BSSRDF(type))
45
eval->subsurface = value;
47
48
eval->diffuse = value;
58
59
eval->diffuse += value;
59
60
else if(CLOSURE_IS_BSDF_GLOSSY(type))
60
61
eval->glossy += value;
62
else if(CLOSURE_IS_BSDF_TRANSMISSION(type))
62
63
eval->transmission += value;
64
else if(CLOSURE_IS_BSDF_BSSRDF(type))
65
eval->subsurface += value;
64
67
/* skipping transparent, this function is used by for eval(), will be zero then */
77
80
return is_zero(eval->diffuse)
78
81
&& is_zero(eval->glossy)
79
82
&& is_zero(eval->transmission)
80
&& is_zero(eval->transparent);
83
&& is_zero(eval->transparent)
84
&& is_zero(eval->subsurface);
83
87
return is_zero(eval->diffuse);
124
129
L->color_diffuse = make_float3(0.0f, 0.0f, 0.0f);
125
130
L->color_glossy = make_float3(0.0f, 0.0f, 0.0f);
126
131
L->color_transmission = make_float3(0.0f, 0.0f, 0.0f);
132
L->color_subsurface = make_float3(0.0f, 0.0f, 0.0f);
128
134
L->direct_diffuse = make_float3(0.0f, 0.0f, 0.0f);
129
135
L->direct_glossy = make_float3(0.0f, 0.0f, 0.0f);
130
136
L->direct_transmission = make_float3(0.0f, 0.0f, 0.0f);
137
L->direct_subsurface = make_float3(0.0f, 0.0f, 0.0f);
132
139
L->indirect_diffuse = make_float3(0.0f, 0.0f, 0.0f);
133
140
L->indirect_glossy = make_float3(0.0f, 0.0f, 0.0f);
134
141
L->indirect_transmission = make_float3(0.0f, 0.0f, 0.0f);
142
L->indirect_subsurface = make_float3(0.0f, 0.0f, 0.0f);
136
144
L->path_diffuse = make_float3(0.0f, 0.0f, 0.0f);
137
145
L->path_glossy = make_float3(0.0f, 0.0f, 0.0f);
138
146
L->path_transmission = make_float3(0.0f, 0.0f, 0.0f);
147
L->path_subsurface = make_float3(0.0f, 0.0f, 0.0f);
140
149
L->emission = make_float3(0.0f, 0.0f, 0.0f);
141
150
L->background = make_float3(0.0f, 0.0f, 0.0f);
164
173
L->path_diffuse = bsdf_eval->diffuse*value;
165
174
L->path_glossy = bsdf_eval->glossy*value;
166
175
L->path_transmission = bsdf_eval->transmission*value;
176
L->path_subsurface = bsdf_eval->subsurface*value;
168
*throughput = L->path_diffuse + L->path_glossy + L->path_transmission;
178
*throughput = L->path_diffuse + L->path_glossy + L->path_transmission + L->path_subsurface;
170
180
L->direct_throughput = *throughput;
173
183
/* transparent bounce before first hit, or indirectly visible through BSDF */
174
float3 sum = (bsdf_eval->diffuse + bsdf_eval->glossy + bsdf_eval->transmission + bsdf_eval->transparent)*inverse_pdf;
184
float3 sum = (bsdf_eval->diffuse + bsdf_eval->glossy + bsdf_eval->transmission + bsdf_eval->transparent + bsdf_eval->subsurface)*inverse_pdf;
175
185
*throughput *= sum;
203
__device_inline void path_radiance_accum_ao(PathRadiance *L, float3 throughput, float3 bsdf, float3 ao, int bounce)
213
__device_inline void path_radiance_accum_ao(PathRadiance *L, float3 throughput, float3 alpha, float3 bsdf, float3 ao, int bounce)
205
215
#ifdef __PASSES__
206
216
if(L->use_light_pass) {
207
217
if(bounce == 0) {
208
218
/* directly visible lighting */
209
219
L->direct_diffuse += throughput*bsdf*ao;
210
L->ao += throughput*ao;
220
L->ao += alpha*throughput*ao;
213
223
/* indirectly visible lighting after BSDF bounce */
230
240
L->direct_diffuse += throughput*bsdf_eval->diffuse*shadow;
231
241
L->direct_glossy += throughput*bsdf_eval->glossy*shadow;
232
242
L->direct_transmission += throughput*bsdf_eval->transmission*shadow;
243
L->direct_subsurface += throughput*bsdf_eval->subsurface*shadow;
235
246
L->shadow.x += shadow.x*shadow_fac;
241
252
/* indirectly visible lighting after BSDF bounce */
242
float3 sum = bsdf_eval->diffuse + bsdf_eval->glossy + bsdf_eval->transmission;
253
float3 sum = bsdf_eval->diffuse + bsdf_eval->glossy + bsdf_eval->transmission + bsdf_eval->subsurface;
243
254
L->indirect += throughput*sum*shadow;
273
284
#ifdef __PASSES__
274
285
/* this division is a bit ugly, but means we only have to keep track of
275
286
* only a single throughput further along the path, here we recover just
276
* the indirect parth that is not influenced by any particular BSDF type */
287
* the indirect path that is not influenced by any particular BSDF type */
277
288
if(L->use_light_pass) {
278
289
L->direct_emission = safe_divide_color(L->direct_emission, L->direct_throughput);
279
290
L->direct_diffuse += L->path_diffuse*L->direct_emission;
280
291
L->direct_glossy += L->path_glossy*L->direct_emission;
281
292
L->direct_transmission += L->path_transmission*L->direct_emission;
293
L->direct_subsurface += L->path_subsurface*L->direct_emission;
283
295
L->indirect = safe_divide_color(L->indirect, L->direct_throughput);
284
296
L->indirect_diffuse += L->path_diffuse*L->indirect;
285
297
L->indirect_glossy += L->path_glossy*L->indirect;
286
298
L->indirect_transmission += L->path_transmission*L->indirect;
299
L->indirect_subsurface += L->path_subsurface*L->indirect;
295
308
L->path_diffuse = make_float3(0.0f, 0.0f, 0.0f);
296
309
L->path_glossy = make_float3(0.0f, 0.0f, 0.0f);
297
310
L->path_transmission = make_float3(0.0f, 0.0f, 0.0f);
311
L->path_subsurface = make_float3(0.0f, 0.0f, 0.0f);
299
313
L->direct_emission = make_float3(0.0f, 0.0f, 0.0f);
300
314
L->indirect = make_float3(0.0f, 0.0f, 0.0f);
309
323
path_radiance_sum_indirect(L);
311
325
float3 L_sum = L->emission
312
+ L->direct_diffuse + L->direct_glossy + L->direct_transmission
313
+ L->indirect_diffuse + L->indirect_glossy + L->indirect_transmission;
326
+ L->direct_diffuse + L->direct_glossy + L->direct_transmission + L->direct_subsurface
327
+ L->indirect_diffuse + L->indirect_glossy + L->indirect_transmission + L->indirect_subsurface;
315
329
if(!kernel_data.background.transparent)
316
330
L_sum += L->background;
337
351
L->direct_diffuse = make_float3(0.0f, 0.0f, 0.0f);
338
352
L->direct_glossy = make_float3(0.0f, 0.0f, 0.0f);
339
353
L->direct_transmission = make_float3(0.0f, 0.0f, 0.0f);
354
L->direct_subsurface = make_float3(0.0f, 0.0f, 0.0f);
341
356
L->indirect_diffuse = make_float3(0.0f, 0.0f, 0.0f);
342
357
L->indirect_glossy = make_float3(0.0f, 0.0f, 0.0f);
343
358
L->indirect_transmission = make_float3(0.0f, 0.0f, 0.0f);
359
L->indirect_subsurface = make_float3(0.0f, 0.0f, 0.0f);
345
361
L->emission = make_float3(0.0f, 0.0f, 0.0f);
357
373
L->direct_diffuse *= scale;
358
374
L->direct_glossy *= scale;
359
375
L->direct_transmission *= scale;
376
L->direct_subsurface *= scale;
361
378
L->indirect_diffuse *= scale;
362
379
L->indirect_glossy *= scale;
363
380
L->indirect_transmission *= scale;
381
L->indirect_subsurface *= scale;
365
383
L->emission *= scale;