Cycles: internal changes that should have no effect on user level yet, added
[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 #ifdef __SVM__
94                         case CLOSURE_BSDF_TRANSLUCENT_ID:
95                                 eval = bsdf_translucent_eval_reflect(sd, sc, sd->I, omega_in, pdf);
96                                 break;
97                         case CLOSURE_BSDF_REFLECTION_ID:
98                                 eval = bsdf_reflection_eval_reflect(sd, sc, sd->I, omega_in, pdf);
99                                 break;
100                         case CLOSURE_BSDF_REFRACTION_ID:
101                                 eval = bsdf_refraction_eval_reflect(sd, sc, sd->I, omega_in, pdf);
102                                 break;
103                         case CLOSURE_BSDF_TRANSPARENT_ID:
104                                 eval = bsdf_transparent_eval_reflect(sd, sc, sd->I, omega_in, pdf);
105                                 break;
106                         case CLOSURE_BSDF_MICROFACET_GGX_ID:
107                         case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
108                                 eval = bsdf_microfacet_ggx_eval_reflect(sd, sc, sd->I, omega_in, pdf);
109                                 break;
110                         case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
111                         case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
112                                 eval = bsdf_microfacet_beckmann_eval_reflect(sd, sc, sd->I, omega_in, pdf);
113                                 break;
114 #ifdef __DPDU__
115                         case CLOSURE_BSDF_WARD_ID:
116                                 eval = bsdf_ward_eval_reflect(sd, sc, sd->I, omega_in, pdf);
117                                 break;
118 #endif
119                         case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
120                                 eval = bsdf_ashikhmin_velvet_eval_reflect(sd, sc, sd->I, omega_in, pdf);
121                                 break;
122                         case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
123                                 eval = bsdf_westin_backscatter_eval_reflect(sd, sc, sd->I, omega_in, pdf);
124                                 break;
125                         case CLOSURE_BSDF_WESTIN_SHEEN_ID:
126                                 eval = bsdf_westin_sheen_eval_reflect(sd, sc, sd->I, omega_in, pdf);
127                                 break;
128 #endif
129                         default:
130                                 eval = make_float3(0.0f, 0.0f, 0.0f);
131                                 break;
132                 }
133         }
134         else {
135                 switch(sc->type) {
136                         case CLOSURE_BSDF_DIFFUSE_ID:
137                                 eval = bsdf_diffuse_eval_transmit(sd, sc, sd->I, omega_in, pdf);
138                                 break;
139 #ifdef __SVM__
140                         case CLOSURE_BSDF_TRANSLUCENT_ID:
141                                 eval = bsdf_translucent_eval_transmit(sd, sc, sd->I, omega_in, pdf);
142                                 break;
143                         case CLOSURE_BSDF_REFLECTION_ID:
144                                 eval = bsdf_reflection_eval_transmit(sd, sc, sd->I, omega_in, pdf);
145                                 break;
146                         case CLOSURE_BSDF_REFRACTION_ID:
147                                 eval = bsdf_refraction_eval_transmit(sd, sc, sd->I, omega_in, pdf);
148                                 break;
149                         case CLOSURE_BSDF_TRANSPARENT_ID:
150                                 eval = bsdf_transparent_eval_transmit(sd, sc, sd->I, omega_in, pdf);
151                                 break;
152                         case CLOSURE_BSDF_MICROFACET_GGX_ID:
153                         case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
154                                 eval = bsdf_microfacet_ggx_eval_transmit(sd, sc, sd->I, omega_in, pdf);
155                                 break;
156                         case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
157                         case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
158                                 eval = bsdf_microfacet_beckmann_eval_transmit(sd, sc, sd->I, omega_in, pdf);
159                                 break;
160 #ifdef __DPDU__
161                         case CLOSURE_BSDF_WARD_ID:
162                                 eval = bsdf_ward_eval_transmit(sd, sc, sd->I, omega_in, pdf);
163                                 break;
164 #endif
165                         case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
166                                 eval = bsdf_ashikhmin_velvet_eval_transmit(sd, sc, sd->I, omega_in, pdf);
167                                 break;
168                         case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
169                                 eval = bsdf_westin_backscatter_eval_transmit(sd, sc, sd->I, omega_in, pdf);
170                                 break;
171                         case CLOSURE_BSDF_WESTIN_SHEEN_ID:
172                                 eval = bsdf_westin_sheen_eval_transmit(sd, sc, sd->I, omega_in, pdf);
173                                 break;
174 #endif
175                         default:
176                                 eval = make_float3(0.0f, 0.0f, 0.0f);
177                                 break;
178                 }
179         }
180
181         return eval;
182 }
183
184 __device void svm_bsdf_blur(ShaderClosure *sc, float roughness)
185 {
186         switch(sc->type) {
187                 case CLOSURE_BSDF_DIFFUSE_ID:
188                         bsdf_diffuse_blur(sc, roughness);
189                         break;
190 #ifdef __SVM__
191                 case CLOSURE_BSDF_TRANSLUCENT_ID:
192                         bsdf_translucent_blur(sc, roughness);
193                         break;
194                 case CLOSURE_BSDF_REFLECTION_ID:
195                         bsdf_reflection_blur(sc, roughness);
196                         break;
197                 case CLOSURE_BSDF_REFRACTION_ID:
198                         bsdf_refraction_blur(sc, roughness);
199                         break;
200                 case CLOSURE_BSDF_TRANSPARENT_ID:
201                         bsdf_transparent_blur(sc, roughness);
202                         break;
203                 case CLOSURE_BSDF_MICROFACET_GGX_ID:
204                 case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
205                         bsdf_microfacet_ggx_blur(sc, roughness);
206                         break;
207                 case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
208                 case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
209                         bsdf_microfacet_beckmann_blur(sc, roughness);
210                         break;
211 #ifdef __DPDU__
212                 case CLOSURE_BSDF_WARD_ID:
213                         bsdf_ward_blur(sc, roughness);
214                         break;
215 #endif
216                 case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
217                         bsdf_ashikhmin_velvet_blur(sc, roughness);
218                         break;
219                 case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
220                         bsdf_westin_backscatter_blur(sc, roughness);
221                         break;
222                 case CLOSURE_BSDF_WESTIN_SHEEN_ID:
223                         bsdf_westin_sheen_blur(sc, roughness);
224                         break;
225 #endif
226                 default:
227                         break;
228         }
229 }
230
231 CCL_NAMESPACE_END
232