Blender V2.61 - r43446

svm_bsdf.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2011, Blender Foundation.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include "bsdf_ashikhmin_velvet.h"
00020 #include "bsdf_diffuse.h"
00021 #include "bsdf_oren_nayar.h"
00022 #include "bsdf_microfacet.h"
00023 #include "bsdf_reflection.h"
00024 #include "bsdf_refraction.h"
00025 #include "bsdf_transparent.h"
00026 #ifdef __DPDU__
00027 #include "bsdf_ward.h"
00028 #endif
00029 #include "bsdf_westin.h"
00030 
00031 CCL_NAMESPACE_BEGIN
00032 
00033 __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)
00034 {
00035     int label;
00036 
00037     switch(sc->type) {
00038         case CLOSURE_BSDF_DIFFUSE_ID:
00039             label = bsdf_diffuse_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
00040             break;
00041 #ifdef __SVM__
00042         case CLOSURE_BSDF_OREN_NAYAR_ID:
00043             label = bsdf_oren_nayar_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
00044             break;
00045         case CLOSURE_BSDF_TRANSLUCENT_ID:
00046             label = bsdf_translucent_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
00047             break;
00048         case CLOSURE_BSDF_REFLECTION_ID:
00049             label = bsdf_reflection_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
00050             break;
00051         case CLOSURE_BSDF_REFRACTION_ID:
00052             label = bsdf_refraction_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
00053             break;
00054         case CLOSURE_BSDF_TRANSPARENT_ID:
00055             label = bsdf_transparent_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
00056             break;
00057         case CLOSURE_BSDF_MICROFACET_GGX_ID:
00058         case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
00059             label = bsdf_microfacet_ggx_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
00060             break;
00061         case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
00062         case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
00063             label = bsdf_microfacet_beckmann_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
00064             break;
00065 #ifdef __DPDU__
00066         case CLOSURE_BSDF_WARD_ID:
00067             label = bsdf_ward_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
00068             break;
00069 #endif
00070         case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
00071             label = bsdf_ashikhmin_velvet_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
00072             break;
00073         case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
00074             label = bsdf_westin_backscatter_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
00075             break;
00076         case CLOSURE_BSDF_WESTIN_SHEEN_ID:
00077             label = bsdf_westin_sheen_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
00078             break;
00079 #endif
00080         default:
00081             label = LABEL_NONE;
00082             break;
00083     }
00084 
00085     return label;
00086 }
00087 
00088 __device float3 svm_bsdf_eval(const ShaderData *sd, const ShaderClosure *sc, const float3 omega_in, float *pdf)
00089 {
00090     float3 eval;
00091 
00092     if(dot(sd->Ng, omega_in) >= 0.0f) {
00093         switch(sc->type) {
00094             case CLOSURE_BSDF_DIFFUSE_ID:
00095                 eval = bsdf_diffuse_eval_reflect(sd, sc, sd->I, omega_in, pdf);
00096                 break;
00097 #ifdef __SVM__
00098             case CLOSURE_BSDF_OREN_NAYAR_ID:
00099                 eval = bsdf_oren_nayar_eval_reflect(sd, sc, sd->I, omega_in, pdf);
00100                 break;
00101             case CLOSURE_BSDF_TRANSLUCENT_ID:
00102                 eval = bsdf_translucent_eval_reflect(sd, sc, sd->I, omega_in, pdf);
00103                 break;
00104             case CLOSURE_BSDF_REFLECTION_ID:
00105                 eval = bsdf_reflection_eval_reflect(sd, sc, sd->I, omega_in, pdf);
00106                 break;
00107             case CLOSURE_BSDF_REFRACTION_ID:
00108                 eval = bsdf_refraction_eval_reflect(sd, sc, sd->I, omega_in, pdf);
00109                 break;
00110             case CLOSURE_BSDF_TRANSPARENT_ID:
00111                 eval = bsdf_transparent_eval_reflect(sd, sc, sd->I, omega_in, pdf);
00112                 break;
00113             case CLOSURE_BSDF_MICROFACET_GGX_ID:
00114             case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
00115                 eval = bsdf_microfacet_ggx_eval_reflect(sd, sc, sd->I, omega_in, pdf);
00116                 break;
00117             case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
00118             case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
00119                 eval = bsdf_microfacet_beckmann_eval_reflect(sd, sc, sd->I, omega_in, pdf);
00120                 break;
00121 #ifdef __DPDU__
00122             case CLOSURE_BSDF_WARD_ID:
00123                 eval = bsdf_ward_eval_reflect(sd, sc, sd->I, omega_in, pdf);
00124                 break;
00125 #endif
00126             case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
00127                 eval = bsdf_ashikhmin_velvet_eval_reflect(sd, sc, sd->I, omega_in, pdf);
00128                 break;
00129             case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
00130                 eval = bsdf_westin_backscatter_eval_reflect(sd, sc, sd->I, omega_in, pdf);
00131                 break;
00132             case CLOSURE_BSDF_WESTIN_SHEEN_ID:
00133                 eval = bsdf_westin_sheen_eval_reflect(sd, sc, sd->I, omega_in, pdf);
00134                 break;
00135 #endif
00136             default:
00137                 eval = make_float3(0.0f, 0.0f, 0.0f);
00138                 break;
00139         }
00140     }
00141     else {
00142         switch(sc->type) {
00143             case CLOSURE_BSDF_DIFFUSE_ID:
00144                 eval = bsdf_diffuse_eval_transmit(sd, sc, sd->I, omega_in, pdf);
00145                 break;
00146 #ifdef __SVM__
00147             case CLOSURE_BSDF_OREN_NAYAR_ID:
00148                 eval = bsdf_oren_nayar_eval_transmit(sd, sc, sd->I, omega_in, pdf);
00149                 break;
00150             case CLOSURE_BSDF_TRANSLUCENT_ID:
00151                 eval = bsdf_translucent_eval_transmit(sd, sc, sd->I, omega_in, pdf);
00152                 break;
00153             case CLOSURE_BSDF_REFLECTION_ID:
00154                 eval = bsdf_reflection_eval_transmit(sd, sc, sd->I, omega_in, pdf);
00155                 break;
00156             case CLOSURE_BSDF_REFRACTION_ID:
00157                 eval = bsdf_refraction_eval_transmit(sd, sc, sd->I, omega_in, pdf);
00158                 break;
00159             case CLOSURE_BSDF_TRANSPARENT_ID:
00160                 eval = bsdf_transparent_eval_transmit(sd, sc, sd->I, omega_in, pdf);
00161                 break;
00162             case CLOSURE_BSDF_MICROFACET_GGX_ID:
00163             case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
00164                 eval = bsdf_microfacet_ggx_eval_transmit(sd, sc, sd->I, omega_in, pdf);
00165                 break;
00166             case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
00167             case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
00168                 eval = bsdf_microfacet_beckmann_eval_transmit(sd, sc, sd->I, omega_in, pdf);
00169                 break;
00170 #ifdef __DPDU__
00171             case CLOSURE_BSDF_WARD_ID:
00172                 eval = bsdf_ward_eval_transmit(sd, sc, sd->I, omega_in, pdf);
00173                 break;
00174 #endif
00175             case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
00176                 eval = bsdf_ashikhmin_velvet_eval_transmit(sd, sc, sd->I, omega_in, pdf);
00177                 break;
00178             case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
00179                 eval = bsdf_westin_backscatter_eval_transmit(sd, sc, sd->I, omega_in, pdf);
00180                 break;
00181             case CLOSURE_BSDF_WESTIN_SHEEN_ID:
00182                 eval = bsdf_westin_sheen_eval_transmit(sd, sc, sd->I, omega_in, pdf);
00183                 break;
00184 #endif
00185             default:
00186                 eval = make_float3(0.0f, 0.0f, 0.0f);
00187                 break;
00188         }
00189     }
00190 
00191     return eval;
00192 }
00193 
00194 __device void svm_bsdf_blur(ShaderClosure *sc, float roughness)
00195 {
00196     switch(sc->type) {
00197         case CLOSURE_BSDF_DIFFUSE_ID:
00198             bsdf_diffuse_blur(sc, roughness);
00199             break;
00200 #ifdef __SVM__
00201         case CLOSURE_BSDF_OREN_NAYAR_ID:
00202             bsdf_oren_nayar_blur(sc, roughness);
00203             break;
00204         case CLOSURE_BSDF_TRANSLUCENT_ID:
00205             bsdf_translucent_blur(sc, roughness);
00206             break;
00207         case CLOSURE_BSDF_REFLECTION_ID:
00208             bsdf_reflection_blur(sc, roughness);
00209             break;
00210         case CLOSURE_BSDF_REFRACTION_ID:
00211             bsdf_refraction_blur(sc, roughness);
00212             break;
00213         case CLOSURE_BSDF_TRANSPARENT_ID:
00214             bsdf_transparent_blur(sc, roughness);
00215             break;
00216         case CLOSURE_BSDF_MICROFACET_GGX_ID:
00217         case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
00218             bsdf_microfacet_ggx_blur(sc, roughness);
00219             break;
00220         case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
00221         case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
00222             bsdf_microfacet_beckmann_blur(sc, roughness);
00223             break;
00224 #ifdef __DPDU__
00225         case CLOSURE_BSDF_WARD_ID:
00226             bsdf_ward_blur(sc, roughness);
00227             break;
00228 #endif
00229         case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
00230             bsdf_ashikhmin_velvet_blur(sc, roughness);
00231             break;
00232         case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
00233             bsdf_westin_backscatter_blur(sc, roughness);
00234             break;
00235         case CLOSURE_BSDF_WESTIN_SHEEN_ID:
00236             bsdf_westin_sheen_blur(sc, roughness);
00237             break;
00238 #endif
00239         default:
00240             break;
00241     }
00242 }
00243 
00244 CCL_NAMESPACE_END
00245