a1b39c6ca1e22fdcdb55c8af8d127812cc4cbcf0
[blender.git] / intern / cycles / kernel / svm / svm_bsdf.h
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #include "bsdf_ashikhmin_velvet.h"
20 #include "bsdf_diffuse.h"
21 #include "bsdf_microfacet.h"
22 #include "bsdf_reflection.h"
23 #include "bsdf_refraction.h"
24 #include "bsdf_transparent.h"
25 #ifdef __DPDU__
26 #include "bsdf_ward.h"
27 #endif
28 #include "bsdf_westin.h"
29
30 CCL_NAMESPACE_BEGIN
31
32 __device int svm_bsdf_sample(const ShaderData *sd, const ShaderClosure *sc, float randu, float randv, float3 *eval, float3 *omega_in, differential3 *domega_in, float *pdf)
33 {
34         int label;
35
36         switch(sc->type) {
37                 case CLOSURE_BSDF_DIFFUSE_ID:
38                         label = bsdf_diffuse_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
39                         break;
40 #ifdef __SVM__
41                 case CLOSURE_BSDF_TRANSLUCENT_ID:
42                         label = bsdf_translucent_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
43                         break;
44                 case CLOSURE_BSDF_REFLECTION_ID:
45                         label = bsdf_reflection_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
46                         break;
47                 case CLOSURE_BSDF_REFRACTION_ID:
48                         label = bsdf_refraction_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
49                         break;
50                 case CLOSURE_BSDF_TRANSPARENT_ID:
51                         label = bsdf_transparent_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
52                         break;
53                 case CLOSURE_BSDF_MICROFACET_GGX_ID:
54                 case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
55                         label = bsdf_microfacet_ggx_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
56                         break;
57                 case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
58                 case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
59                         label = bsdf_microfacet_beckmann_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
60                         break;
61 #ifdef __DPDU__
62                 case CLOSURE_BSDF_WARD_ID:
63                         label = bsdf_ward_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
64                         break;
65 #endif
66                 case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
67                         label = bsdf_ashikhmin_velvet_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
68                         break;
69                 case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
70                         label = bsdf_westin_backscatter_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
71                         break;
72                 case CLOSURE_BSDF_WESTIN_SHEEN_ID:
73                         label = bsdf_westin_sheen_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
74                         break;
75 #endif
76                 default:
77                         label = LABEL_NONE;
78                         break;
79         }
80
81         return label;
82 }
83
84 __device float3 svm_bsdf_eval(const ShaderData *sd, const ShaderClosure *sc, const float3 omega_in, float *pdf)
85 {
86         float3 eval;
87
88         if(dot(sd->Ng, omega_in) >= 0.0f) {
89                 switch(sc->type) {
90                         case CLOSURE_BSDF_DIFFUSE_ID:
91                                 eval = bsdf_diffuse_eval_reflect(sd, sc, sd->I, omega_in, pdf);
92                                 break;
93                         case CLOSURE_BSDF_TRANSLUCENT_ID:
94                                 eval = bsdf_translucent_eval_reflect(sd, sc, sd->I, omega_in, pdf);
95                                 break;
96                         case CLOSURE_BSDF_REFLECTION_ID:
97                                 eval = bsdf_reflection_eval_reflect(sd, sc, sd->I, omega_in, pdf);
98                                 break;
99                         case CLOSURE_BSDF_REFRACTION_ID:
100                                 eval = bsdf_refraction_eval_reflect(sd, sc, sd->I, omega_in, pdf);
101                                 break;
102                         case CLOSURE_BSDF_TRANSPARENT_ID:
103                                 eval = bsdf_transparent_eval_reflect(sd, sc, sd->I, omega_in, pdf);
104                                 break;
105                         case CLOSURE_BSDF_MICROFACET_GGX_ID:
106                         case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
107                                 eval = bsdf_microfacet_ggx_eval_reflect(sd, sc, sd->I, omega_in, pdf);
108                                 break;
109                         case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
110                         case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
111                                 eval = bsdf_microfacet_beckmann_eval_reflect(sd, sc, sd->I, omega_in, pdf);
112                                 break;
113 #ifdef __DPDU__
114                         case CLOSURE_BSDF_WARD_ID:
115                                 eval = bsdf_ward_eval_reflect(sd, sc, sd->I, omega_in, pdf);
116                                 break;
117 #endif
118                         case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
119                                 eval = bsdf_ashikhmin_velvet_eval_reflect(sd, sc, sd->I, omega_in, pdf);
120                                 break;
121                         case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
122                                 eval = bsdf_westin_backscatter_eval_reflect(sd, sc, sd->I, omega_in, pdf);
123                                 break;
124                         case CLOSURE_BSDF_WESTIN_SHEEN_ID:
125                                 eval = bsdf_westin_sheen_eval_reflect(sd, sc, sd->I, omega_in, pdf);
126                                 break;
127                         default:
128                                 eval = make_float3(0.0f, 0.0f, 0.0f);
129                                 break;
130                 }
131         }
132         else {
133                 switch(sc->type) {
134                         case CLOSURE_BSDF_DIFFUSE_ID:
135                                 eval = bsdf_diffuse_eval_transmit(sd, sc, sd->I, omega_in, pdf);
136                                 break;
137                         case CLOSURE_BSDF_TRANSLUCENT_ID:
138                                 eval = bsdf_translucent_eval_transmit(sd, sc, sd->I, omega_in, pdf);
139                                 break;
140                         case CLOSURE_BSDF_REFLECTION_ID:
141                                 eval = bsdf_reflection_eval_transmit(sd, sc, sd->I, omega_in, pdf);
142                                 break;
143                         case CLOSURE_BSDF_REFRACTION_ID:
144                                 eval = bsdf_refraction_eval_transmit(sd, sc, sd->I, omega_in, pdf);
145                                 break;
146                         case CLOSURE_BSDF_TRANSPARENT_ID:
147                                 eval = bsdf_transparent_eval_transmit(sd, sc, sd->I, omega_in, pdf);
148                                 break;
149                         case CLOSURE_BSDF_MICROFACET_GGX_ID:
150                         case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
151                                 eval = bsdf_microfacet_ggx_eval_transmit(sd, sc, sd->I, omega_in, pdf);
152                                 break;
153                         case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
154                         case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
155                                 eval = bsdf_microfacet_beckmann_eval_transmit(sd, sc, sd->I, omega_in, pdf);
156                                 break;
157 #ifdef __DPDU__
158                         case CLOSURE_BSDF_WARD_ID:
159                                 eval = bsdf_ward_eval_transmit(sd, sc, sd->I, omega_in, pdf);
160                                 break;
161 #endif
162                         case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
163                                 eval = bsdf_ashikhmin_velvet_eval_transmit(sd, sc, sd->I, omega_in, pdf);
164                                 break;
165                         case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
166                                 eval = bsdf_westin_backscatter_eval_transmit(sd, sc, sd->I, omega_in, pdf);
167                                 break;
168                         case CLOSURE_BSDF_WESTIN_SHEEN_ID:
169                                 eval = bsdf_westin_sheen_eval_transmit(sd, sc, sd->I, omega_in, pdf);
170                                 break;
171                         default:
172                                 eval = make_float3(0.0f, 0.0f, 0.0f);
173                                 break;
174                 }
175         }
176
177         return eval;
178 }
179
180 __device void svm_bsdf_blur(ShaderClosure *sc, float roughness)
181 {
182         switch(sc->type) {
183                 case CLOSURE_BSDF_DIFFUSE_ID:
184                         bsdf_diffuse_blur(sc, roughness);
185                         break;
186                 case CLOSURE_BSDF_TRANSLUCENT_ID:
187                         bsdf_translucent_blur(sc, roughness);
188                         break;
189                 case CLOSURE_BSDF_REFLECTION_ID:
190                         bsdf_reflection_blur(sc, roughness);
191                         break;
192                 case CLOSURE_BSDF_REFRACTION_ID:
193                         bsdf_refraction_blur(sc, roughness);
194                         break;
195                 case CLOSURE_BSDF_TRANSPARENT_ID:
196                         bsdf_transparent_blur(sc, roughness);
197                         break;
198                 case CLOSURE_BSDF_MICROFACET_GGX_ID:
199                 case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
200                         bsdf_microfacet_ggx_blur(sc, roughness);
201                         break;
202                 case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
203                 case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
204                         bsdf_microfacet_beckmann_blur(sc, roughness);
205                         break;
206 #ifdef __DPDU__
207                 case CLOSURE_BSDF_WARD_ID:
208                         bsdf_ward_blur(sc, roughness);
209                         break;
210 #endif
211                 case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
212                         bsdf_ashikhmin_velvet_blur(sc, roughness);
213                         break;
214                 case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
215                         bsdf_westin_backscatter_blur(sc, roughness);
216                         break;
217                 case CLOSURE_BSDF_WESTIN_SHEEN_ID:
218                         bsdf_westin_sheen_blur(sc, roughness);
219                         break;
220                 default:
221                         break;
222         }
223 }
224
225 CCL_NAMESPACE_END
226