2012-06-09 17:22:52 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2012-06-09 17:22:52 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2012-06-09 17:22:52 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-06-09 17:22:52 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2012-06-09 17:22:52 +00:00
|
|
|
*/
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "kernel/closure/bsdf_ashikhmin_velvet.h"
|
|
|
|
#include "kernel/closure/bsdf_diffuse.h"
|
|
|
|
#include "kernel/closure/bsdf_oren_nayar.h"
|
|
|
|
#include "kernel/closure/bsdf_phong_ramp.h"
|
|
|
|
#include "kernel/closure/bsdf_diffuse_ramp.h"
|
|
|
|
#include "kernel/closure/bsdf_microfacet.h"
|
|
|
|
#include "kernel/closure/bsdf_microfacet_multi.h"
|
|
|
|
#include "kernel/closure/bsdf_reflection.h"
|
|
|
|
#include "kernel/closure/bsdf_refraction.h"
|
|
|
|
#include "kernel/closure/bsdf_transparent.h"
|
|
|
|
#include "kernel/closure/bsdf_ashikhmin_shirley.h"
|
|
|
|
#include "kernel/closure/bsdf_toon.h"
|
|
|
|
#include "kernel/closure/bsdf_hair.h"
|
2018-07-18 09:14:43 +00:00
|
|
|
#include "kernel/closure/bsdf_hair_principled.h"
|
2017-04-18 09:43:09 +00:00
|
|
|
#include "kernel/closure/bsdf_principled_diffuse.h"
|
|
|
|
#include "kernel/closure/bsdf_principled_sheen.h"
|
2017-08-18 16:37:05 +00:00
|
|
|
#include "kernel/closure/bssrdf.h"
|
2018-01-21 13:04:22 +00:00
|
|
|
#include "kernel/closure/volume.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2017-11-05 20:43:23 +00:00
|
|
|
/* Returns the square of the roughness of the closure if it has roughness,
|
|
|
|
* 0 for singular closures and 1 otherwise. */
|
2018-03-28 21:18:46 +00:00
|
|
|
ccl_device_inline float bsdf_get_specular_roughness_squared(const ShaderClosure *sc)
|
2017-11-05 20:43:23 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
if (CLOSURE_IS_BSDF_SINGULAR(sc->type)) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
2017-11-05 20:43:23 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
if (CLOSURE_IS_BSDF_MICROFACET(sc->type)) {
|
|
|
|
MicrofacetBsdf *bsdf = (MicrofacetBsdf *)sc;
|
|
|
|
return bsdf->alpha_x * bsdf->alpha_y;
|
|
|
|
}
|
2017-11-05 20:43:23 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
return 1.0f;
|
2017-11-05 20:43:23 +00:00
|
|
|
}
|
|
|
|
|
2018-03-28 21:18:46 +00:00
|
|
|
ccl_device_inline float bsdf_get_roughness_squared(const ShaderClosure *sc)
|
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
/* This version includes diffuse, mainly for baking Principled BSDF
|
|
|
|
* where specular and metallic zero otherwise does not bake the
|
|
|
|
* specified roughness parameter. */
|
|
|
|
if (sc->type == CLOSURE_BSDF_OREN_NAYAR_ID) {
|
|
|
|
OrenNayarBsdf *bsdf = (OrenNayarBsdf *)sc;
|
|
|
|
return sqr(sqr(bsdf->roughness));
|
|
|
|
}
|
2018-03-28 21:18:46 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
if (sc->type == CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID) {
|
|
|
|
PrincipledDiffuseBsdf *bsdf = (PrincipledDiffuseBsdf *)sc;
|
|
|
|
return sqr(sqr(bsdf->roughness));
|
|
|
|
}
|
2018-03-28 21:18:46 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
if (CLOSURE_IS_BSDF_DIFFUSE(sc->type)) {
|
|
|
|
return 0.0f;
|
|
|
|
}
|
2018-03-28 21:18:46 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
return bsdf_get_specular_roughness_squared(sc);
|
2018-03-28 21:18:46 +00:00
|
|
|
}
|
|
|
|
|
2018-06-21 09:29:09 +00:00
|
|
|
ccl_device_inline int bsdf_sample(KernelGlobals *kg,
|
|
|
|
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
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
int label;
|
2012-12-15 10:18:42 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
switch (sc->type) {
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_ID:
|
|
|
|
case CLOSURE_BSDF_BSSRDF_ID:
|
|
|
|
label = bsdf_diffuse_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
2012-12-15 10:18:42 +00:00
|
|
|
#ifdef __SVM__
|
2019-04-17 04:17:24 +00:00
|
|
|
case CLOSURE_BSDF_OREN_NAYAR_ID:
|
|
|
|
label = bsdf_oren_nayar_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
# ifdef __OSL__
|
|
|
|
case CLOSURE_BSDF_PHONG_RAMP_ID:
|
|
|
|
label = bsdf_phong_ramp_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_RAMP_ID:
|
|
|
|
label = bsdf_diffuse_ramp_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
# endif
|
|
|
|
case CLOSURE_BSDF_TRANSLUCENT_ID:
|
|
|
|
label = bsdf_translucent_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_REFLECTION_ID:
|
|
|
|
label = bsdf_reflection_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_REFRACTION_ID:
|
|
|
|
label = bsdf_refraction_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_TRANSPARENT_ID:
|
|
|
|
label = bsdf_transparent_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ANISO_FRESNEL_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
|
|
|
label = bsdf_microfacet_ggx_sample(kg,
|
|
|
|
sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID:
|
|
|
|
label = bsdf_microfacet_multi_ggx_sample(kg,
|
|
|
|
sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf,
|
|
|
|
&sd->lcg_state);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID:
|
|
|
|
label = bsdf_microfacet_multi_ggx_glass_sample(kg,
|
|
|
|
sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf,
|
|
|
|
&sd->lcg_state);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ANISO_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
|
|
|
|
label = bsdf_microfacet_beckmann_sample(kg,
|
|
|
|
sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID:
|
|
|
|
label = bsdf_ashikhmin_shirley_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
|
|
|
|
label = bsdf_ashikhmin_velvet_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_TOON_ID:
|
|
|
|
label = bsdf_diffuse_toon_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_GLOSSY_TOON_ID:
|
|
|
|
label = bsdf_glossy_toon_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_HAIR_REFLECTION_ID:
|
|
|
|
label = bsdf_hair_reflection_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_HAIR_TRANSMISSION_ID:
|
|
|
|
label = bsdf_hair_transmission_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_HAIR_PRINCIPLED_ID:
|
|
|
|
label = bsdf_principled_hair_sample(
|
|
|
|
kg, sc, sd, randu, randv, eval, omega_in, &domega_in->dx, &domega_in->dy, pdf);
|
|
|
|
break;
|
|
|
|
# ifdef __PRINCIPLED__
|
|
|
|
case CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID:
|
|
|
|
case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID:
|
|
|
|
label = bsdf_principled_diffuse_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID:
|
|
|
|
label = bsdf_principled_sheen_sample(sc,
|
|
|
|
sd->Ng,
|
|
|
|
sd->I,
|
|
|
|
sd->dI.dx,
|
|
|
|
sd->dI.dy,
|
|
|
|
randu,
|
|
|
|
randv,
|
|
|
|
eval,
|
|
|
|
omega_in,
|
|
|
|
&domega_in->dx,
|
|
|
|
&domega_in->dy,
|
|
|
|
pdf);
|
|
|
|
break;
|
|
|
|
# endif /* __PRINCIPLED__ */
|
2011-04-27 11:58:34 +00:00
|
|
|
#endif
|
2014-01-07 14:48:04 +00:00
|
|
|
#ifdef __VOLUME__
|
2019-04-17 04:17:24 +00:00
|
|
|
case CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID:
|
|
|
|
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);
|
|
|
|
break;
|
2014-01-07 14:48:04 +00:00
|
|
|
#endif
|
2019-04-17 04:17:24 +00:00
|
|
|
default:
|
|
|
|
label = LABEL_NONE;
|
|
|
|
break;
|
|
|
|
}
|
2012-12-15 10:18:42 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
/* Test if BSDF sample should be treated as transparent for background. */
|
|
|
|
if (label & LABEL_TRANSMIT) {
|
|
|
|
float threshold_squared = kernel_data.background.transparent_roughness_squared_threshold;
|
2018-01-11 19:03:31 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
if (threshold_squared >= 0.0f) {
|
|
|
|
if (bsdf_get_specular_roughness_squared(sc) <= threshold_squared) {
|
|
|
|
label |= LABEL_TRANSMIT_TRANSPARENT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-11 19:03:31 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
return label;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-08-05 12:45:54 +00:00
|
|
|
#ifndef __KERNEL_CUDA__
|
2016-08-02 13:04:34 +00:00
|
|
|
ccl_device
|
|
|
|
#else
|
2018-06-21 09:29:09 +00:00
|
|
|
ccl_device_inline
|
2016-08-02 13:04:34 +00:00
|
|
|
#endif
|
2019-04-17 04:17:24 +00:00
|
|
|
float3
|
|
|
|
bsdf_eval(KernelGlobals *kg,
|
|
|
|
ShaderData *sd,
|
|
|
|
const ShaderClosure *sc,
|
|
|
|
const float3 omega_in,
|
|
|
|
float *pdf)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
float3 eval;
|
2012-12-15 10:18:42 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
if (dot(sd->Ng, omega_in) >= 0.0f) {
|
|
|
|
switch (sc->type) {
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_ID:
|
|
|
|
case CLOSURE_BSDF_BSSRDF_ID:
|
|
|
|
eval = bsdf_diffuse_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
2012-12-15 10:18:42 +00:00
|
|
|
#ifdef __SVM__
|
2019-04-17 04:17:24 +00:00
|
|
|
case CLOSURE_BSDF_OREN_NAYAR_ID:
|
|
|
|
eval = bsdf_oren_nayar_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
# ifdef __OSL__
|
|
|
|
case CLOSURE_BSDF_PHONG_RAMP_ID:
|
|
|
|
eval = bsdf_phong_ramp_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_RAMP_ID:
|
|
|
|
eval = bsdf_diffuse_ramp_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
# endif
|
|
|
|
case CLOSURE_BSDF_TRANSLUCENT_ID:
|
|
|
|
eval = bsdf_translucent_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_REFLECTION_ID:
|
|
|
|
eval = bsdf_reflection_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_REFRACTION_ID:
|
|
|
|
eval = bsdf_refraction_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_TRANSPARENT_ID:
|
|
|
|
eval = bsdf_transparent_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ANISO_FRESNEL_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
|
|
|
eval = bsdf_microfacet_ggx_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID:
|
|
|
|
eval = bsdf_microfacet_multi_ggx_eval_reflect(sc, sd->I, omega_in, pdf, &sd->lcg_state);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID:
|
|
|
|
eval = bsdf_microfacet_multi_ggx_glass_eval_reflect(
|
|
|
|
sc, sd->I, omega_in, pdf, &sd->lcg_state);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ANISO_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
|
|
|
|
eval = bsdf_microfacet_beckmann_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID:
|
|
|
|
eval = bsdf_ashikhmin_shirley_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
|
|
|
|
eval = bsdf_ashikhmin_velvet_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_TOON_ID:
|
|
|
|
eval = bsdf_diffuse_toon_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_GLOSSY_TOON_ID:
|
|
|
|
eval = bsdf_glossy_toon_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_HAIR_PRINCIPLED_ID:
|
|
|
|
eval = bsdf_principled_hair_eval(kg, sd, sc, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_HAIR_REFLECTION_ID:
|
|
|
|
eval = bsdf_hair_reflection_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_HAIR_TRANSMISSION_ID:
|
|
|
|
eval = bsdf_hair_transmission_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
# ifdef __PRINCIPLED__
|
|
|
|
case CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID:
|
|
|
|
case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID:
|
|
|
|
eval = bsdf_principled_diffuse_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID:
|
|
|
|
eval = bsdf_principled_sheen_eval_reflect(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
# endif /* __PRINCIPLED__ */
|
2013-12-29 14:40:43 +00:00
|
|
|
#endif
|
|
|
|
#ifdef __VOLUME__
|
2019-04-17 04:17:24 +00:00
|
|
|
case CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID:
|
|
|
|
eval = volume_henyey_greenstein_eval_phase(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
2012-12-15 10:18:42 +00:00
|
|
|
#endif
|
2019-04-17 04:17:24 +00:00
|
|
|
default:
|
|
|
|
eval = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (sc->type) {
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_ID:
|
|
|
|
case CLOSURE_BSDF_BSSRDF_ID:
|
|
|
|
eval = bsdf_diffuse_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
2012-12-15 10:18:42 +00:00
|
|
|
#ifdef __SVM__
|
2019-04-17 04:17:24 +00:00
|
|
|
case CLOSURE_BSDF_OREN_NAYAR_ID:
|
|
|
|
eval = bsdf_oren_nayar_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_TRANSLUCENT_ID:
|
|
|
|
eval = bsdf_translucent_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_REFLECTION_ID:
|
|
|
|
eval = bsdf_reflection_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_REFRACTION_ID:
|
|
|
|
eval = bsdf_refraction_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_TRANSPARENT_ID:
|
|
|
|
eval = bsdf_transparent_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ANISO_FRESNEL_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
|
|
|
eval = bsdf_microfacet_ggx_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID:
|
|
|
|
eval = bsdf_microfacet_multi_ggx_eval_transmit(sc, sd->I, omega_in, pdf, &sd->lcg_state);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID:
|
|
|
|
eval = bsdf_microfacet_multi_ggx_glass_eval_transmit(
|
|
|
|
sc, sd->I, omega_in, pdf, &sd->lcg_state);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ANISO_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
|
|
|
|
eval = bsdf_microfacet_beckmann_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID:
|
|
|
|
eval = bsdf_ashikhmin_shirley_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
|
|
|
|
eval = bsdf_ashikhmin_velvet_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_TOON_ID:
|
|
|
|
eval = bsdf_diffuse_toon_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_GLOSSY_TOON_ID:
|
|
|
|
eval = bsdf_glossy_toon_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_HAIR_PRINCIPLED_ID:
|
|
|
|
eval = bsdf_principled_hair_eval(kg, sd, sc, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_HAIR_REFLECTION_ID:
|
|
|
|
eval = bsdf_hair_reflection_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_HAIR_TRANSMISSION_ID:
|
|
|
|
eval = bsdf_hair_transmission_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
# ifdef __PRINCIPLED__
|
|
|
|
case CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID:
|
|
|
|
case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID:
|
|
|
|
eval = bsdf_principled_diffuse_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID:
|
|
|
|
eval = bsdf_principled_sheen_eval_transmit(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
|
|
|
# endif /* __PRINCIPLED__ */
|
2013-12-29 14:40:43 +00:00
|
|
|
#endif
|
|
|
|
#ifdef __VOLUME__
|
2019-04-17 04:17:24 +00:00
|
|
|
case CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID:
|
|
|
|
eval = volume_henyey_greenstein_eval_phase(sc, sd->I, omega_in, pdf);
|
|
|
|
break;
|
2012-12-15 10:18:42 +00:00
|
|
|
#endif
|
2019-04-17 04:17:24 +00:00
|
|
|
default:
|
|
|
|
eval = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
return eval;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2013-11-15 23:17:10 +00:00
|
|
|
ccl_device void bsdf_blur(KernelGlobals *kg, ShaderClosure *sc, float roughness)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
/* ToDo: do we want to blur volume closures? */
|
2012-12-15 10:18:42 +00:00
|
|
|
#ifdef __SVM__
|
2019-04-17 04:17:24 +00:00
|
|
|
switch (sc->type) {
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID:
|
|
|
|
bsdf_microfacet_multi_ggx_blur(sc, roughness);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ANISO_FRESNEL_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
|
|
|
bsdf_microfacet_ggx_blur(sc, roughness);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ANISO_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
|
|
|
|
bsdf_microfacet_beckmann_blur(sc, roughness);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID:
|
|
|
|
bsdf_ashikhmin_shirley_blur(sc, roughness);
|
|
|
|
break;
|
|
|
|
case CLOSURE_BSDF_HAIR_PRINCIPLED_ID:
|
|
|
|
bsdf_principled_hair_blur(sc, roughness);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-02-17 12:43:12 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-07-25 01:03:23 +00:00
|
|
|
ccl_device bool bsdf_merge(ShaderClosure *a, ShaderClosure *b)
|
|
|
|
{
|
|
|
|
#ifdef __SVM__
|
2019-04-17 04:17:24 +00:00
|
|
|
switch (a->type) {
|
|
|
|
case CLOSURE_BSDF_TRANSPARENT_ID:
|
|
|
|
return true;
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_ID:
|
|
|
|
case CLOSURE_BSDF_BSSRDF_ID:
|
|
|
|
case CLOSURE_BSDF_TRANSLUCENT_ID:
|
|
|
|
return bsdf_diffuse_merge(a, b);
|
|
|
|
case CLOSURE_BSDF_OREN_NAYAR_ID:
|
|
|
|
return bsdf_oren_nayar_merge(a, b);
|
|
|
|
case CLOSURE_BSDF_REFLECTION_ID:
|
|
|
|
case CLOSURE_BSDF_REFRACTION_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_FRESNEL_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_ANISO_FRESNEL_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_FRESNEL_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_FRESNEL_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_ANISO_ID:
|
|
|
|
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID:
|
|
|
|
return bsdf_microfacet_merge(a, b);
|
|
|
|
case CLOSURE_BSDF_ASHIKHMIN_VELVET_ID:
|
|
|
|
return bsdf_ashikhmin_velvet_merge(a, b);
|
|
|
|
case CLOSURE_BSDF_DIFFUSE_TOON_ID:
|
|
|
|
case CLOSURE_BSDF_GLOSSY_TOON_ID:
|
|
|
|
return bsdf_toon_merge(a, b);
|
|
|
|
case CLOSURE_BSDF_HAIR_REFLECTION_ID:
|
|
|
|
case CLOSURE_BSDF_HAIR_TRANSMISSION_ID:
|
|
|
|
return bsdf_hair_merge(a, b);
|
|
|
|
# ifdef __PRINCIPLED__
|
|
|
|
case CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID:
|
|
|
|
case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID:
|
|
|
|
return bsdf_principled_diffuse_merge(a, b);
|
|
|
|
# endif
|
|
|
|
# ifdef __VOLUME__
|
|
|
|
case CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID:
|
|
|
|
return volume_henyey_greenstein_merge(a, b);
|
|
|
|
# endif
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-28 15:03:42 +00:00
|
|
|
#else
|
2019-04-17 04:17:24 +00:00
|
|
|
return false;
|
2016-07-25 01:03:23 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|