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