Cycles: option to make background visible through glass transparent.
[blender-staging.git] / intern / cycles / kernel / closure / bsdf.h
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "kernel/closure/bsdf_ashikhmin_velvet.h"
18 #include "kernel/closure/bsdf_diffuse.h"
19 #include "kernel/closure/bsdf_oren_nayar.h"
20 #include "kernel/closure/bsdf_phong_ramp.h"
21 #include "kernel/closure/bsdf_diffuse_ramp.h"
22 #include "kernel/closure/bsdf_microfacet.h"
23 #include "kernel/closure/bsdf_microfacet_multi.h"
24 #include "kernel/closure/bsdf_reflection.h"
25 #include "kernel/closure/bsdf_refraction.h"
26 #include "kernel/closure/bsdf_transparent.h"
27 #include "kernel/closure/bsdf_ashikhmin_shirley.h"
28 #include "kernel/closure/bsdf_toon.h"
29 #include "kernel/closure/bsdf_hair.h"
30 #include "kernel/closure/bsdf_principled_diffuse.h"
31 #include "kernel/closure/bsdf_principled_sheen.h"
32 #include "kernel/closure/bssrdf.h"
33 #ifdef __VOLUME__
34 #  include "kernel/closure/volume.h"
35 #endif
36
37 CCL_NAMESPACE_BEGIN
38
39 /* Returns the square of the roughness of the closure if it has roughness,
40  * 0 for singular closures and 1 otherwise. */
41 ccl_device_inline float bsdf_get_roughness_squared(const ShaderClosure *sc)
42 {
43         if(CLOSURE_IS_BSDF_SINGULAR(sc->type)) {
44                 return 0.0f;
45         }
46
47         if(CLOSURE_IS_BSDF_MICROFACET(sc->type)) {
48                 MicrofacetBsdf *bsdf = (MicrofacetBsdf*) sc;
49                 return bsdf->alpha_x*bsdf->alpha_y;
50         }
51
52         return 1.0f;
53 }
54
55 ccl_device_forceinline int bsdf_sample(KernelGlobals *kg,
56                                        ShaderData *sd,
57                                        const ShaderClosure *sc,
58                                        float randu,
59                                        float randv,
60                                        float3 *eval,
61                                        float3 *omega_in,
62                                        differential3 *domega_in,
63                                        float *pdf)
64 {
65         int label;
66
67         switch(sc->type) {
68                 case CLOSURE_BSDF_DIFFUSE_ID:
69                 case CLOSURE_BSDF_BSSRDF_ID:
70                         label = bsdf_diffuse_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
71                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
72                         break;
73 #ifdef __SVM__
74                 case CLOSURE_BSDF_OREN_NAYAR_ID:
75                         label = bsdf_oren_nayar_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
76                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
77                         break;
78 #ifdef __OSL__
79                 case CLOSURE_BSDF_PHONG_RAMP_ID:
80                         label = bsdf_phong_ramp_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
81                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
82                         break;
83                 case CLOSURE_BSDF_DIFFUSE_RAMP_ID:
84                         label = bsdf_diffuse_ramp_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
85                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
86                         break;
87 #endif
88                 case CLOSURE_BSDF_TRANSLUCENT_ID:
89                         label = bsdf_translucent_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
90                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
91                         break;
92                 case CLOSURE_BSDF_REFLECTION_ID:
93                         label = bsdf_reflection_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
94                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
95                         break;
96                 case CLOSURE_BSDF_REFRACTION_ID:
97                         label = bsdf_refraction_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
98                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
99                         break;
100                 case CLOSURE_BSDF_TRANSPARENT_ID:
101                         label = bsdf_transparent_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
102                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
103                         break;
104                 case CLOSURE_BSDF_MICROFACET_GGX_ID:
105                 case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
106                 case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
107                 case CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID:
108                 case CLOSURE_BSDF_MICROFACET_GGX_ANISO_FRESNEL_ID:
109                 case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
110                         label = bsdf_microfacet_ggx_sample(kg, sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
111                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
112                         break;
113                 case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID:
114                 case CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID:
115                         label = bsdf_microfacet_multi_ggx_sample(kg, sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
116                                 eval, omega_in,  &domega_in->dx, &domega_in->dy, pdf, &sd->lcg_state);
117                         break;
118                 case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID:
119                 case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID:
120                         label = bsdf_microfacet_multi_ggx_glass_sample(kg, sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
121                                 eval, omega_in,  &domega_in->dx, &domega_in->dy, pdf, &sd->lcg_state);
122                         break;
123                 case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
124                 case CLOSURE_BSDF_MICROFACET_BECKMANN_ANISO_ID:
125                 case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
126                         label = bsdf_microfacet_beckmann_sample(kg, sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
127                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
128                         break;
129                 case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
130                 case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID:
131                         label = bsdf_ashikhmin_shirley_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
132                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
133                         break;
134                 case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
135                         label = bsdf_ashikhmin_velvet_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
136                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
137                         break;
138                 case CLOSURE_BSDF_DIFFUSE_TOON_ID:
139                         label = bsdf_diffuse_toon_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
140                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
141                         break;
142                 case CLOSURE_BSDF_GLOSSY_TOON_ID:
143                         label = bsdf_glossy_toon_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
144                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
145                         break;
146                 case CLOSURE_BSDF_HAIR_REFLECTION_ID:
147                         label = bsdf_hair_reflection_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
148                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
149                         break;
150                 case CLOSURE_BSDF_HAIR_TRANSMISSION_ID:
151                         label = bsdf_hair_transmission_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
152                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
153                         break;
154 #ifdef __PRINCIPLED__
155                 case CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID:
156                 case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID:
157                         label = bsdf_principled_diffuse_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
158                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
159                         break;
160                 case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID:
161                         label = bsdf_principled_sheen_sample(sc, sd->Ng, sd->I, sd->dI.dx, sd->dI.dy, randu, randv,
162                                 eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
163                         break;
164 #endif  /* __PRINCIPLED__ */
165 #endif
166 #ifdef __VOLUME__
167                 case CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID:
168                         label = volume_henyey_greenstein_sample(sc, sd->I, sd->dI.dx, sd->dI.dy, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
169                         break;
170 #endif
171                 default:
172                         label = LABEL_NONE;
173                         break;
174         }
175
176         /* Test if BSDF sample should be treated as transparent for background. */
177         if(label & LABEL_TRANSMIT) {
178                 float threshold_squared = kernel_data.background.transparent_roughness_squared_threshold;
179
180                 if(threshold_squared >= 0.0f) {
181                         if(bsdf_get_roughness_squared(sc) <= threshold_squared) {
182                                 label |= LABEL_TRANSMIT_TRANSPARENT;
183                         }
184                 }
185         }
186
187         return label;
188 }
189
190 #ifndef __KERNEL_CUDA__
191 ccl_device
192 #else
193 ccl_device_forceinline
194 #endif
195 float3 bsdf_eval(KernelGlobals *kg,
196                  ShaderData *sd,
197                  const ShaderClosure *sc,
198                  const float3 omega_in,
199                  float *pdf)
200 {
201         float3 eval;
202
203         if(dot(sd->Ng, omega_in) >= 0.0f) {
204                 switch(sc->type) {
205                         case CLOSURE_BSDF_DIFFUSE_ID:
206                         case CLOSURE_BSDF_BSSRDF_ID:
207                                 eval = bsdf_diffuse_eval_reflect(sc, sd->I, omega_in, pdf);
208                                 break;
209 #ifdef __SVM__
210                         case CLOSURE_BSDF_OREN_NAYAR_ID:
211                                 eval = bsdf_oren_nayar_eval_reflect(sc, sd->I, omega_in, pdf);
212                                 break;
213 #ifdef __OSL__
214                         case CLOSURE_BSDF_PHONG_RAMP_ID:
215                                 eval = bsdf_phong_ramp_eval_reflect(sc, sd->I, omega_in, pdf);
216                                 break;
217                         case CLOSURE_BSDF_DIFFUSE_RAMP_ID:
218                                 eval = bsdf_diffuse_ramp_eval_reflect(sc, sd->I, omega_in, pdf);
219                                 break;
220 #endif
221                         case CLOSURE_BSDF_TRANSLUCENT_ID:
222                                 eval = bsdf_translucent_eval_reflect(sc, sd->I, omega_in, pdf);
223                                 break;
224                         case CLOSURE_BSDF_REFLECTION_ID:
225                                 eval = bsdf_reflection_eval_reflect(sc, sd->I, omega_in, pdf);
226                                 break;
227                         case CLOSURE_BSDF_REFRACTION_ID:
228                                 eval = bsdf_refraction_eval_reflect(sc, sd->I, omega_in, pdf);
229                                 break;
230                         case CLOSURE_BSDF_TRANSPARENT_ID:
231                                 eval = bsdf_transparent_eval_reflect(sc, sd->I, omega_in, pdf);
232                                 break;
233                         case CLOSURE_BSDF_MICROFACET_GGX_ID:
234                         case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
235                         case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
236                         case CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID:
237                         case CLOSURE_BSDF_MICROFACET_GGX_ANISO_FRESNEL_ID:
238                         case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
239                                 eval = bsdf_microfacet_ggx_eval_reflect(sc, sd->I, omega_in, pdf);
240                                 break;
241                         case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID:
242                         case CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID:
243                                 eval = bsdf_microfacet_multi_ggx_eval_reflect(sc, sd->I, omega_in, pdf, &sd->lcg_state);
244                                 break;
245                         case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID:
246                         case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID:
247                                 eval = bsdf_microfacet_multi_ggx_glass_eval_reflect(sc, sd->I, omega_in, pdf, &sd->lcg_state);
248                                 break;
249                         case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
250                         case CLOSURE_BSDF_MICROFACET_BECKMANN_ANISO_ID:
251                         case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
252                                 eval = bsdf_microfacet_beckmann_eval_reflect(sc, sd->I, omega_in, pdf);
253                                 break;
254                         case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
255                         case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID:
256                                 eval = bsdf_ashikhmin_shirley_eval_reflect(sc, sd->I, omega_in, pdf);
257                                 break;
258                         case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
259                                 eval = bsdf_ashikhmin_velvet_eval_reflect(sc, sd->I, omega_in, pdf);
260                                 break;
261                         case CLOSURE_BSDF_DIFFUSE_TOON_ID:
262                                 eval = bsdf_diffuse_toon_eval_reflect(sc, sd->I, omega_in, pdf);
263                                 break;
264                         case CLOSURE_BSDF_GLOSSY_TOON_ID:
265                                 eval = bsdf_glossy_toon_eval_reflect(sc, sd->I, omega_in, pdf);
266                                 break;
267                         case CLOSURE_BSDF_HAIR_REFLECTION_ID:
268                                 eval = bsdf_hair_reflection_eval_reflect(sc, sd->I, omega_in, pdf);
269                                 break;
270                         case CLOSURE_BSDF_HAIR_TRANSMISSION_ID:
271                                 eval = bsdf_hair_transmission_eval_reflect(sc, sd->I, omega_in, pdf);
272                                 break;
273 #ifdef __PRINCIPLED__
274                         case CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID:
275                         case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID:
276                                 eval = bsdf_principled_diffuse_eval_reflect(sc, sd->I, omega_in, pdf);
277                                 break;
278                         case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID:
279                                 eval = bsdf_principled_sheen_eval_reflect(sc, sd->I, omega_in, pdf);
280                                 break;
281 #endif  /* __PRINCIPLED__ */
282 #endif
283 #ifdef __VOLUME__
284                         case CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID:
285                                 eval = volume_henyey_greenstein_eval_phase(sc, sd->I, omega_in, pdf);
286                                 break;
287 #endif
288                         default:
289                                 eval = make_float3(0.0f, 0.0f, 0.0f);
290                                 break;
291                 }
292         }
293         else {
294                 switch(sc->type) {
295                         case CLOSURE_BSDF_DIFFUSE_ID:
296                         case CLOSURE_BSDF_BSSRDF_ID:
297                                 eval = bsdf_diffuse_eval_transmit(sc, sd->I, omega_in, pdf);
298                                 break;
299 #ifdef __SVM__
300                         case CLOSURE_BSDF_OREN_NAYAR_ID:
301                                 eval = bsdf_oren_nayar_eval_transmit(sc, sd->I, omega_in, pdf);
302                                 break;
303                         case CLOSURE_BSDF_TRANSLUCENT_ID:
304                                 eval = bsdf_translucent_eval_transmit(sc, sd->I, omega_in, pdf);
305                                 break;
306                         case CLOSURE_BSDF_REFLECTION_ID:
307                                 eval = bsdf_reflection_eval_transmit(sc, sd->I, omega_in, pdf);
308                                 break;
309                         case CLOSURE_BSDF_REFRACTION_ID:
310                                 eval = bsdf_refraction_eval_transmit(sc, sd->I, omega_in, pdf);
311                                 break;
312                         case CLOSURE_BSDF_TRANSPARENT_ID:
313                                 eval = bsdf_transparent_eval_transmit(sc, sd->I, omega_in, pdf);
314                                 break;
315                         case CLOSURE_BSDF_MICROFACET_GGX_ID:
316                         case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
317                         case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
318                         case CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID:
319                         case CLOSURE_BSDF_MICROFACET_GGX_ANISO_FRESNEL_ID:
320                         case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
321                                 eval = bsdf_microfacet_ggx_eval_transmit(sc, sd->I, omega_in, pdf);
322                                 break;
323                         case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID:
324                         case CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID:
325                                 eval = bsdf_microfacet_multi_ggx_eval_transmit(sc, sd->I, omega_in, pdf, &sd->lcg_state);
326                                 break;
327                         case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID:
328                         case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID:
329                                 eval = bsdf_microfacet_multi_ggx_glass_eval_transmit(sc, sd->I, omega_in, pdf, &sd->lcg_state);
330                                 break;
331                         case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
332                         case CLOSURE_BSDF_MICROFACET_BECKMANN_ANISO_ID:
333                         case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
334                                 eval = bsdf_microfacet_beckmann_eval_transmit(sc, sd->I, omega_in, pdf);
335                                 break;
336                         case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
337                         case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID:
338                                 eval = bsdf_ashikhmin_shirley_eval_transmit(sc, sd->I, omega_in, pdf);
339                                 break;
340                         case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
341                                 eval = bsdf_ashikhmin_velvet_eval_transmit(sc, sd->I, omega_in, pdf);
342                                 break;
343                         case CLOSURE_BSDF_DIFFUSE_TOON_ID:
344                                 eval = bsdf_diffuse_toon_eval_transmit(sc, sd->I, omega_in, pdf);
345                                 break;
346                         case CLOSURE_BSDF_GLOSSY_TOON_ID:
347                                 eval = bsdf_glossy_toon_eval_transmit(sc, sd->I, omega_in, pdf);
348                                 break;
349                         case CLOSURE_BSDF_HAIR_REFLECTION_ID:
350                                 eval = bsdf_hair_reflection_eval_transmit(sc, sd->I, omega_in, pdf);
351                                 break;
352                         case CLOSURE_BSDF_HAIR_TRANSMISSION_ID:
353                                 eval = bsdf_hair_transmission_eval_transmit(sc, sd->I, omega_in, pdf);
354                                 break;
355 #ifdef __PRINCIPLED__
356                         case CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID:
357                         case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID:
358                                 eval = bsdf_principled_diffuse_eval_transmit(sc, sd->I, omega_in, pdf);
359                                 break;
360                         case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID:
361                                 eval = bsdf_principled_sheen_eval_transmit(sc, sd->I, omega_in, pdf);
362                                 break;
363 #endif  /* __PRINCIPLED__ */
364 #endif
365 #ifdef __VOLUME__
366                         case CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID:
367                                 eval = volume_henyey_greenstein_eval_phase(sc, sd->I, omega_in, pdf);
368                                 break;
369 #endif
370                         default:
371                                 eval = make_float3(0.0f, 0.0f, 0.0f);
372                                 break;
373                 }
374         }
375
376         return eval;
377 }
378
379 ccl_device void bsdf_blur(KernelGlobals *kg, ShaderClosure *sc, float roughness)
380 {
381         /* ToDo: do we want to blur volume closures? */
382 #ifdef __SVM__
383         switch(sc->type) {
384                 case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID:
385                 case CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID:
386                 case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID:
387                 case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID:
388                         bsdf_microfacet_multi_ggx_blur(sc, roughness);
389                         break;
390                 case CLOSURE_BSDF_MICROFACET_GGX_ID:
391                 case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
392                 case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
393                 case CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID:
394                 case CLOSURE_BSDF_MICROFACET_GGX_ANISO_FRESNEL_ID:
395                 case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
396                         bsdf_microfacet_ggx_blur(sc, roughness);
397                         break;
398                 case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
399                 case CLOSURE_BSDF_MICROFACET_BECKMANN_ANISO_ID:
400                 case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
401                         bsdf_microfacet_beckmann_blur(sc, roughness);
402                         break;
403                 case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
404                 case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID:
405                         bsdf_ashikhmin_shirley_blur(sc, roughness);
406                         break;
407                 default:
408                         break;
409         }
410 #endif
411 }
412
413 ccl_device bool bsdf_merge(ShaderClosure *a, ShaderClosure *b)
414 {
415 #ifdef __SVM__
416         switch(a->type) {
417                 case CLOSURE_BSDF_TRANSPARENT_ID:
418                         return true;
419                 case CLOSURE_BSDF_DIFFUSE_ID:
420                 case CLOSURE_BSDF_BSSRDF_ID:
421                 case CLOSURE_BSDF_TRANSLUCENT_ID:
422                         return bsdf_diffuse_merge(a, b);
423                 case CLOSURE_BSDF_OREN_NAYAR_ID:
424                         return bsdf_oren_nayar_merge(a, b);
425                 case CLOSURE_BSDF_REFLECTION_ID:
426                 case CLOSURE_BSDF_REFRACTION_ID:
427                 case CLOSURE_BSDF_MICROFACET_GGX_ID:
428                 case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
429                 case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
430                 case CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID:
431                 case CLOSURE_BSDF_MICROFACET_GGX_ANISO_FRESNEL_ID:
432                 case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
433                 case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID:
434                 case CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID:
435                 case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID:
436                 case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID:
437                 case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
438                 case CLOSURE_BSDF_MICROFACET_BECKMANN_ANISO_ID:
439                 case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
440                 case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
441                 case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID:
442                         return bsdf_microfacet_merge(a, b);
443                 case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
444                         return bsdf_ashikhmin_velvet_merge(a, b);
445                 case CLOSURE_BSDF_DIFFUSE_TOON_ID:
446                 case CLOSURE_BSDF_GLOSSY_TOON_ID:
447                         return bsdf_toon_merge(a, b);
448                 case CLOSURE_BSDF_HAIR_REFLECTION_ID:
449                 case CLOSURE_BSDF_HAIR_TRANSMISSION_ID:
450                         return bsdf_hair_merge(a, b);
451 #ifdef __PRINCIPLED__
452                 case CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID:
453                 case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID:
454                         return bsdf_principled_diffuse_merge(a, b);
455 #endif
456 #ifdef __VOLUME__
457                 case CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID:
458                         return volume_henyey_greenstein_merge(a, b);
459 #endif
460                 default:
461                         return false;
462         }
463 #else
464         return false;
465 #endif
466 }
467
468 CCL_NAMESPACE_END
469