2011-04-27 11:58:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011, Blender Foundation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bsdf_ashikhmin_velvet.h"
|
|
|
|
#include "bsdf_diffuse.h"
|
2011-11-14 17:31:47 +00:00
|
|
|
#include "bsdf_oren_nayar.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "bsdf_microfacet.h"
|
|
|
|
#include "bsdf_reflection.h"
|
|
|
|
#include "bsdf_refraction.h"
|
|
|
|
#include "bsdf_transparent.h"
|
|
|
|
#ifdef __DPDU__
|
|
|
|
#include "bsdf_ward.h"
|
|
|
|
#endif
|
|
|
|
#include "bsdf_westin.h"
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2011-09-12 13:13:56 +00:00
|
|
|
__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)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
int label;
|
|
|
|
|
2011-09-12 13:13:56 +00:00
|
|
|
switch(sc->type) {
|
2011-04-27 11:58:34 +00:00
|
|
|
case CLOSURE_BSDF_DIFFUSE_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
label = bsdf_diffuse_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
2011-09-03 10:49:54 +00:00
|
|
|
#ifdef __SVM__
|
2011-11-14 17:31:47 +00:00
|
|
|
case CLOSURE_BSDF_OREN_NAYAR_ID:
|
|
|
|
label = bsdf_oren_nayar_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
|
|
|
|
break;
|
2011-04-27 11:58:34 +00:00
|
|
|
case CLOSURE_BSDF_TRANSLUCENT_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
label = bsdf_translucent_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_REFLECTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
label = bsdf_reflection_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_REFRACTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
label = bsdf_refraction_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_TRANSPARENT_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
label = bsdf_transparent_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
label = bsdf_microfacet_ggx_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
label = bsdf_microfacet_beckmann_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
#ifdef __DPDU__
|
|
|
|
case CLOSURE_BSDF_WARD_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
label = bsdf_ward_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
label = bsdf_ashikhmin_velvet_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
label = bsdf_westin_backscatter_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_WESTIN_SHEEN_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
label = bsdf_westin_sheen_sample(sd, sc, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
2011-09-03 10:49:54 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
default:
|
|
|
|
label = LABEL_NONE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2011-09-12 13:13:56 +00:00
|
|
|
__device float3 svm_bsdf_eval(const ShaderData *sd, const ShaderClosure *sc, const float3 omega_in, float *pdf)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
float3 eval;
|
|
|
|
|
|
|
|
if(dot(sd->Ng, omega_in) >= 0.0f) {
|
2011-09-12 13:13:56 +00:00
|
|
|
switch(sc->type) {
|
2011-04-27 11:58:34 +00:00
|
|
|
case CLOSURE_BSDF_DIFFUSE_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_diffuse_eval_reflect(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
2011-09-27 20:37:24 +00:00
|
|
|
#ifdef __SVM__
|
2011-11-14 17:31:47 +00:00
|
|
|
case CLOSURE_BSDF_OREN_NAYAR_ID:
|
|
|
|
eval = bsdf_oren_nayar_eval_reflect(sd, sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
2011-04-27 11:58:34 +00:00
|
|
|
case CLOSURE_BSDF_TRANSLUCENT_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_translucent_eval_reflect(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_REFLECTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_reflection_eval_reflect(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_REFRACTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_refraction_eval_reflect(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_TRANSPARENT_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_transparent_eval_reflect(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_microfacet_ggx_eval_reflect(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_microfacet_beckmann_eval_reflect(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
#ifdef __DPDU__
|
|
|
|
case CLOSURE_BSDF_WARD_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_ward_eval_reflect(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_ashikhmin_velvet_eval_reflect(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_westin_backscatter_eval_reflect(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_WESTIN_SHEEN_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_westin_sheen_eval_reflect(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
2011-09-27 20:37:24 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
default:
|
|
|
|
eval = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2011-09-12 13:13:56 +00:00
|
|
|
switch(sc->type) {
|
2011-04-27 11:58:34 +00:00
|
|
|
case CLOSURE_BSDF_DIFFUSE_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_diffuse_eval_transmit(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
2011-09-27 20:37:24 +00:00
|
|
|
#ifdef __SVM__
|
2011-11-14 17:31:47 +00:00
|
|
|
case CLOSURE_BSDF_OREN_NAYAR_ID:
|
|
|
|
eval = bsdf_oren_nayar_eval_transmit(sd, sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
2011-04-27 11:58:34 +00:00
|
|
|
case CLOSURE_BSDF_TRANSLUCENT_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_translucent_eval_transmit(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_REFLECTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_reflection_eval_transmit(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_REFRACTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_refraction_eval_transmit(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_TRANSPARENT_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_transparent_eval_transmit(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_microfacet_ggx_eval_transmit(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_microfacet_beckmann_eval_transmit(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
#ifdef __DPDU__
|
|
|
|
case CLOSURE_BSDF_WARD_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_ward_eval_transmit(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_ashikhmin_velvet_eval_transmit(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_westin_backscatter_eval_transmit(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_WESTIN_SHEEN_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
eval = bsdf_westin_sheen_eval_transmit(sd, sc, sd->I, omega_in, pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
2011-09-27 20:37:24 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
default:
|
|
|
|
eval = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return eval;
|
|
|
|
}
|
|
|
|
|
2011-09-12 13:13:56 +00:00
|
|
|
__device void svm_bsdf_blur(ShaderClosure *sc, float roughness)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2011-09-12 13:13:56 +00:00
|
|
|
switch(sc->type) {
|
2011-04-27 11:58:34 +00:00
|
|
|
case CLOSURE_BSDF_DIFFUSE_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
bsdf_diffuse_blur(sc, roughness);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
2011-09-27 20:37:24 +00:00
|
|
|
#ifdef __SVM__
|
2011-11-14 17:31:47 +00:00
|
|
|
case CLOSURE_BSDF_OREN_NAYAR_ID:
|
|
|
|
bsdf_oren_nayar_blur(sc, roughness);
|
|
|
|
break;
|
2011-04-27 11:58:34 +00:00
|
|
|
case CLOSURE_BSDF_TRANSLUCENT_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
bsdf_translucent_blur(sc, roughness);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_REFLECTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
bsdf_reflection_blur(sc, roughness);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_REFRACTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
bsdf_refraction_blur(sc, roughness);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_TRANSPARENT_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
bsdf_transparent_blur(sc, roughness);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
bsdf_microfacet_ggx_blur(sc, roughness);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
bsdf_microfacet_beckmann_blur(sc, roughness);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
#ifdef __DPDU__
|
|
|
|
case CLOSURE_BSDF_WARD_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
bsdf_ward_blur(sc, roughness);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
bsdf_ashikhmin_velvet_blur(sc, roughness);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_WESTIN_BACKSCATTER_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
bsdf_westin_backscatter_blur(sc, roughness);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_WESTIN_SHEEN_ID:
|
2011-09-12 13:13:56 +00:00
|
|
|
bsdf_westin_sheen_blur(sc, roughness);
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
2011-09-27 20:37:24 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|