Cycles: improve SSS Fresnel and retro-reflection in Principled BSDF
For details see the "Extending the Disney BRDF to a BSDF with Integrated Subsurface Scattering" paper. We split the diffuse BSDF into a lambertian and retro-reflection component. The retro-reflection component is always handled as a BSDF, while the lambertian component can be replaced by a BSSRDF. For the BSSRDF case, we compute Fresnel separately at the entry and exit points, which may have different normals. As the scattering radius decreases this converges to the BSDF case. A downside is that this increases noise for subsurface scattering in the Principled BSDF, due to some samples going to the retro-reflection component. However the previous logic (also in 2.93) was simple wrong, using a non-sensical view direction vector at the exit point. We use an importance sampling weight estimate for the retro-reflection to try to better balance samples between the BSDF and BSSRDF. Differential Revision: https://developer.blender.org/D12801
This commit is contained in:
@@ -128,7 +128,6 @@ ccl_device_inline int bsdf_sample(const KernelGlobals *kg,
|
|||||||
|
|
||||||
switch (sc->type) {
|
switch (sc->type) {
|
||||||
case CLOSURE_BSDF_DIFFUSE_ID:
|
case CLOSURE_BSDF_DIFFUSE_ID:
|
||||||
case CLOSURE_BSDF_BSSRDF_ID:
|
|
||||||
label = bsdf_diffuse_sample(sc,
|
label = bsdf_diffuse_sample(sc,
|
||||||
Ng,
|
Ng,
|
||||||
sd->I,
|
sd->I,
|
||||||
@@ -401,7 +400,6 @@ ccl_device_inline int bsdf_sample(const KernelGlobals *kg,
|
|||||||
break;
|
break;
|
||||||
# ifdef __PRINCIPLED__
|
# ifdef __PRINCIPLED__
|
||||||
case CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID:
|
case CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID:
|
||||||
case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID:
|
|
||||||
label = bsdf_principled_diffuse_sample(sc,
|
label = bsdf_principled_diffuse_sample(sc,
|
||||||
Ng,
|
Ng,
|
||||||
sd->I,
|
sd->I,
|
||||||
@@ -481,7 +479,6 @@ ccl_device_inline
|
|||||||
if (!is_transmission) {
|
if (!is_transmission) {
|
||||||
switch (sc->type) {
|
switch (sc->type) {
|
||||||
case CLOSURE_BSDF_DIFFUSE_ID:
|
case CLOSURE_BSDF_DIFFUSE_ID:
|
||||||
case CLOSURE_BSDF_BSSRDF_ID:
|
|
||||||
eval = bsdf_diffuse_eval_reflect(sc, sd->I, omega_in, pdf);
|
eval = bsdf_diffuse_eval_reflect(sc, sd->I, omega_in, pdf);
|
||||||
break;
|
break;
|
||||||
#ifdef __SVM__
|
#ifdef __SVM__
|
||||||
@@ -550,7 +547,6 @@ ccl_device_inline
|
|||||||
break;
|
break;
|
||||||
# ifdef __PRINCIPLED__
|
# ifdef __PRINCIPLED__
|
||||||
case CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID:
|
case CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID:
|
||||||
case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID:
|
|
||||||
eval = bsdf_principled_diffuse_eval_reflect(sc, sd->I, omega_in, pdf);
|
eval = bsdf_principled_diffuse_eval_reflect(sc, sd->I, omega_in, pdf);
|
||||||
break;
|
break;
|
||||||
case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID:
|
case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID:
|
||||||
@@ -576,7 +572,6 @@ ccl_device_inline
|
|||||||
else {
|
else {
|
||||||
switch (sc->type) {
|
switch (sc->type) {
|
||||||
case CLOSURE_BSDF_DIFFUSE_ID:
|
case CLOSURE_BSDF_DIFFUSE_ID:
|
||||||
case CLOSURE_BSDF_BSSRDF_ID:
|
|
||||||
eval = bsdf_diffuse_eval_transmit(sc, sd->I, omega_in, pdf);
|
eval = bsdf_diffuse_eval_transmit(sc, sd->I, omega_in, pdf);
|
||||||
break;
|
break;
|
||||||
#ifdef __SVM__
|
#ifdef __SVM__
|
||||||
@@ -637,7 +632,6 @@ ccl_device_inline
|
|||||||
break;
|
break;
|
||||||
# ifdef __PRINCIPLED__
|
# ifdef __PRINCIPLED__
|
||||||
case CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID:
|
case CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID:
|
||||||
case CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID:
|
|
||||||
eval = bsdf_principled_diffuse_eval_transmit(sc, sd->I, omega_in, pdf);
|
eval = bsdf_principled_diffuse_eval_transmit(sc, sd->I, omega_in, pdf);
|
||||||
break;
|
break;
|
||||||
case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID:
|
case CLOSURE_BSDF_PRINCIPLED_SHEEN_ID:
|
||||||
|
@@ -19,50 +19,98 @@
|
|||||||
/* DISNEY PRINCIPLED DIFFUSE BRDF
|
/* DISNEY PRINCIPLED DIFFUSE BRDF
|
||||||
*
|
*
|
||||||
* Shading model by Brent Burley (Disney): "Physically Based Shading at Disney" (2012)
|
* Shading model by Brent Burley (Disney): "Physically Based Shading at Disney" (2012)
|
||||||
|
*
|
||||||
|
* "Extending the Disney BRDF to a BSDF with Integrated Subsurface Scattering" (2015)
|
||||||
|
* For the separation of retro-reflection, "2.3 Dielectric BRDF with integrated
|
||||||
|
* subsurface scattering"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "kernel/closure/bsdf_util.h"
|
#include "kernel/closure/bsdf_util.h"
|
||||||
|
|
||||||
CCL_NAMESPACE_BEGIN
|
CCL_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
enum PrincipledDiffuseBsdfComponents {
|
||||||
|
PRINCIPLED_DIFFUSE_FULL = 1,
|
||||||
|
PRINCIPLED_DIFFUSE_LAMBERT = 2,
|
||||||
|
PRINCIPLED_DIFFUSE_LAMBERT_EXIT = 4,
|
||||||
|
PRINCIPLED_DIFFUSE_RETRO_REFLECTION = 8,
|
||||||
|
};
|
||||||
|
|
||||||
typedef ccl_addr_space struct PrincipledDiffuseBsdf {
|
typedef ccl_addr_space struct PrincipledDiffuseBsdf {
|
||||||
SHADER_CLOSURE_BASE;
|
SHADER_CLOSURE_BASE;
|
||||||
|
|
||||||
float roughness;
|
float roughness;
|
||||||
|
int components;
|
||||||
} PrincipledDiffuseBsdf;
|
} PrincipledDiffuseBsdf;
|
||||||
|
|
||||||
static_assert(sizeof(ShaderClosure) >= sizeof(PrincipledDiffuseBsdf),
|
static_assert(sizeof(ShaderClosure) >= sizeof(PrincipledDiffuseBsdf),
|
||||||
"PrincipledDiffuseBsdf is too large!");
|
"PrincipledDiffuseBsdf is too large!");
|
||||||
|
|
||||||
ccl_device float3 calculate_principled_diffuse_brdf(
|
ccl_device int bsdf_principled_diffuse_setup(PrincipledDiffuseBsdf *bsdf)
|
||||||
|
{
|
||||||
|
bsdf->type = CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID;
|
||||||
|
return SD_BSDF | SD_BSDF_HAS_EVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ccl_device float3 bsdf_principled_diffuse_compute_brdf(
|
||||||
const PrincipledDiffuseBsdf *bsdf, float3 N, float3 V, float3 L, float *pdf)
|
const PrincipledDiffuseBsdf *bsdf, float3 N, float3 V, float3 L, float *pdf)
|
||||||
{
|
{
|
||||||
float NdotL = dot(N, L);
|
const float NdotL = dot(N, L);
|
||||||
|
|
||||||
if (NdotL <= 0) {
|
if (NdotL <= 0) {
|
||||||
return make_float3(0.0f, 0.0f, 0.0f);
|
return make_float3(0.0f, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float NdotV = dot(N, V);
|
const float NdotV = dot(N, V);
|
||||||
|
|
||||||
/* H = normalize(L + V); // Bisector of an angle between L and V.
|
const float FV = schlick_fresnel(NdotV);
|
||||||
* LH2 = 2 * dot(L, H)^2 = 2cos(x)^2 = cos(2x) + 1 = dot(L, V) + 1,
|
const float FL = schlick_fresnel(NdotL);
|
||||||
* half-angle x between L and V is at most 90 deg
|
|
||||||
*/
|
|
||||||
float LH2 = dot(L, V) + 1;
|
|
||||||
|
|
||||||
float FL = schlick_fresnel(NdotL), FV = schlick_fresnel(NdotV);
|
float f = 0.0f;
|
||||||
const float Fd90 = 0.5f + LH2 * bsdf->roughness;
|
|
||||||
float Fd = (1.0f - FL + Fd90 * FL) * (1.0f - FV + Fd90 * FV);
|
|
||||||
|
|
||||||
float value = M_1_PI_F * NdotL * Fd;
|
/* Lambertian component. */
|
||||||
|
if (bsdf->components & (PRINCIPLED_DIFFUSE_FULL | PRINCIPLED_DIFFUSE_LAMBERT)) {
|
||||||
|
f += (1.0f - 0.5f * FV) * (1.0f - 0.5f * FL);
|
||||||
|
}
|
||||||
|
else if (bsdf->components & PRINCIPLED_DIFFUSE_LAMBERT_EXIT) {
|
||||||
|
f += (1.0f - 0.5f * FL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Retro-reflection component. */
|
||||||
|
if (bsdf->components & (PRINCIPLED_DIFFUSE_FULL | PRINCIPLED_DIFFUSE_RETRO_REFLECTION)) {
|
||||||
|
/* H = normalize(L + V); // Bisector of an angle between L and V
|
||||||
|
* LH2 = 2 * dot(L, H)^2 = 2cos(x)^2 = cos(2x) + 1 = dot(L, V) + 1,
|
||||||
|
* half-angle x between L and V is at most 90 deg. */
|
||||||
|
const float LH2 = dot(L, V) + 1;
|
||||||
|
const float RR = bsdf->roughness * LH2;
|
||||||
|
f += RR * (FL + FV + FL * FV * (RR - 1.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
float value = M_1_PI_F * NdotL * f;
|
||||||
|
|
||||||
return make_float3(value, value, value);
|
return make_float3(value, value, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
ccl_device int bsdf_principled_diffuse_setup(PrincipledDiffuseBsdf *bsdf)
|
/* Compute Fresnel at entry point, to be compbined with PRINCIPLED_DIFFUSE_LAMBERT_EXIT
|
||||||
|
* at the exit point to get the complete BSDF. */
|
||||||
|
ccl_device_inline float bsdf_principled_diffuse_compute_entry_fresnel(const float NdotV)
|
||||||
|
{
|
||||||
|
const float FV = schlick_fresnel(NdotV);
|
||||||
|
return (1.0f - 0.5f * FV);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ad-hoc weight adjusment to avoid retro-reflection taking away half the
|
||||||
|
* samples from BSSRDF. */
|
||||||
|
ccl_device_inline float bsdf_principled_diffuse_retro_reflection_sample_weight(
|
||||||
|
PrincipledDiffuseBsdf *bsdf, const float3 I)
|
||||||
|
{
|
||||||
|
return bsdf->roughness * schlick_fresnel(dot(bsdf->N, I));
|
||||||
|
}
|
||||||
|
|
||||||
|
ccl_device int bsdf_principled_diffuse_setup(PrincipledDiffuseBsdf *bsdf, int components)
|
||||||
{
|
{
|
||||||
bsdf->type = CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID;
|
bsdf->type = CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID;
|
||||||
|
bsdf->components = components;
|
||||||
return SD_BSDF | SD_BSDF_HAS_EVAL;
|
return SD_BSDF | SD_BSDF_HAS_EVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +127,7 @@ ccl_device float3 bsdf_principled_diffuse_eval_reflect(const ShaderClosure *sc,
|
|||||||
|
|
||||||
if (dot(N, omega_in) > 0.0f) {
|
if (dot(N, omega_in) > 0.0f) {
|
||||||
*pdf = fmaxf(dot(N, omega_in), 0.0f) * M_1_PI_F;
|
*pdf = fmaxf(dot(N, omega_in), 0.0f) * M_1_PI_F;
|
||||||
return calculate_principled_diffuse_brdf(bsdf, N, V, L, pdf);
|
return bsdf_principled_diffuse_compute_brdf(bsdf, N, V, L, pdf);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*pdf = 0.0f;
|
*pdf = 0.0f;
|
||||||
@@ -115,7 +163,7 @@ ccl_device int bsdf_principled_diffuse_sample(const ShaderClosure *sc,
|
|||||||
sample_cos_hemisphere(N, randu, randv, omega_in, pdf);
|
sample_cos_hemisphere(N, randu, randv, omega_in, pdf);
|
||||||
|
|
||||||
if (dot(Ng, *omega_in) > 0) {
|
if (dot(Ng, *omega_in) > 0) {
|
||||||
*eval = calculate_principled_diffuse_brdf(bsdf, N, I, *omega_in, pdf);
|
*eval = bsdf_principled_diffuse_compute_brdf(bsdf, N, I, *omega_in, pdf);
|
||||||
|
|
||||||
#ifdef __RAY_DIFFERENTIALS__
|
#ifdef __RAY_DIFFERENTIALS__
|
||||||
// TODO: find a better approximation for the diffuse bounce
|
// TODO: find a better approximation for the diffuse bounce
|
||||||
|
@@ -277,10 +277,27 @@ ccl_device_inline Bssrdf *bssrdf_alloc(ShaderData *sd, float3 weight)
|
|||||||
ccl_device int bssrdf_setup(ShaderData *sd, Bssrdf *bssrdf, ClosureType type, const float ior)
|
ccl_device int bssrdf_setup(ShaderData *sd, Bssrdf *bssrdf, ClosureType type, const float ior)
|
||||||
{
|
{
|
||||||
int flag = 0;
|
int flag = 0;
|
||||||
|
|
||||||
|
/* Add retro-reflection component as separate diffuse BSDF. */
|
||||||
|
if (bssrdf->roughness != FLT_MAX) {
|
||||||
|
PrincipledDiffuseBsdf *bsdf = (PrincipledDiffuseBsdf *)bsdf_alloc(
|
||||||
|
sd, sizeof(PrincipledDiffuseBsdf), bssrdf->weight);
|
||||||
|
|
||||||
|
if (bsdf) {
|
||||||
|
bsdf->N = bssrdf->N;
|
||||||
|
bsdf->roughness = bssrdf->roughness;
|
||||||
|
flag |= bsdf_principled_diffuse_setup(bsdf, PRINCIPLED_DIFFUSE_RETRO_REFLECTION);
|
||||||
|
|
||||||
|
/* Ad-hoc weight adjusment to avoid retro-reflection taking away half the
|
||||||
|
* samples from BSSRDF. */
|
||||||
|
bsdf->sample_weight *= bsdf_principled_diffuse_retro_reflection_sample_weight(bsdf, sd->I);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Verify if the radii are large enough to sample without precision issues. */
|
||||||
int bssrdf_channels = 3;
|
int bssrdf_channels = 3;
|
||||||
float3 diffuse_weight = make_float3(0.0f, 0.0f, 0.0f);
|
float3 diffuse_weight = make_float3(0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
/* Verify if the radii are large enough to sample without precision issues. */
|
|
||||||
if (bssrdf->radius.x < BSSRDF_MIN_RADIUS) {
|
if (bssrdf->radius.x < BSSRDF_MIN_RADIUS) {
|
||||||
diffuse_weight.x = bssrdf->weight.x;
|
diffuse_weight.x = bssrdf->weight.x;
|
||||||
bssrdf->weight.x = 0.0f;
|
bssrdf->weight.x = 0.0f;
|
||||||
@@ -304,17 +321,13 @@ ccl_device int bssrdf_setup(ShaderData *sd, Bssrdf *bssrdf, ClosureType type, co
|
|||||||
/* Add diffuse BSDF if any radius too small. */
|
/* Add diffuse BSDF if any radius too small. */
|
||||||
#ifdef __PRINCIPLED__
|
#ifdef __PRINCIPLED__
|
||||||
if (bssrdf->roughness != FLT_MAX) {
|
if (bssrdf->roughness != FLT_MAX) {
|
||||||
float roughness = bssrdf->roughness;
|
|
||||||
float3 N = bssrdf->N;
|
|
||||||
|
|
||||||
PrincipledDiffuseBsdf *bsdf = (PrincipledDiffuseBsdf *)bsdf_alloc(
|
PrincipledDiffuseBsdf *bsdf = (PrincipledDiffuseBsdf *)bsdf_alloc(
|
||||||
sd, sizeof(PrincipledDiffuseBsdf), diffuse_weight);
|
sd, sizeof(PrincipledDiffuseBsdf), diffuse_weight);
|
||||||
|
|
||||||
if (bsdf) {
|
if (bsdf) {
|
||||||
bsdf->type = CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID;
|
bsdf->N = bssrdf->N;
|
||||||
bsdf->N = N;
|
bsdf->roughness = bssrdf->roughness;
|
||||||
bsdf->roughness = roughness;
|
flag |= bsdf_principled_diffuse_setup(bsdf, PRINCIPLED_DIFFUSE_LAMBERT);
|
||||||
flag |= bsdf_principled_diffuse_setup(bsdf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -323,7 +336,6 @@ ccl_device int bssrdf_setup(ShaderData *sd, Bssrdf *bssrdf, ClosureType type, co
|
|||||||
DiffuseBsdf *bsdf = (DiffuseBsdf *)bsdf_alloc(sd, sizeof(DiffuseBsdf), diffuse_weight);
|
DiffuseBsdf *bsdf = (DiffuseBsdf *)bsdf_alloc(sd, sizeof(DiffuseBsdf), diffuse_weight);
|
||||||
|
|
||||||
if (bsdf) {
|
if (bsdf) {
|
||||||
bsdf->type = CLOSURE_BSDF_BSSRDF_ID;
|
|
||||||
bsdf->N = bssrdf->N;
|
bsdf->N = bssrdf->N;
|
||||||
flag |= bsdf_diffuse_setup(bsdf);
|
flag |= bsdf_diffuse_setup(bsdf);
|
||||||
}
|
}
|
||||||
|
@@ -378,11 +378,11 @@ ccl_device bool integrate_surface(INTEGRATOR_STATE_ARGS,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __SUBSURFACE__
|
#ifdef __SUBSURFACE__
|
||||||
if (INTEGRATOR_STATE(path, flag) & PATH_RAY_SUBSURFACE) {
|
if (path_flag & PATH_RAY_SUBSURFACE) {
|
||||||
/* When coming from inside subsurface scattering, setup a diffuse
|
/* When coming from inside subsurface scattering, setup a diffuse
|
||||||
* closure to perform lighting at the exit point. */
|
* closure to perform lighting at the exit point. */
|
||||||
|
subsurface_shader_data_setup(INTEGRATOR_STATE_PASS, &sd, path_flag);
|
||||||
INTEGRATOR_STATE_WRITE(path, flag) &= ~PATH_RAY_SUBSURFACE;
|
INTEGRATOR_STATE_WRITE(path, flag) &= ~PATH_RAY_SUBSURFACE;
|
||||||
subsurface_shader_data_setup(INTEGRATOR_STATE_PASS, &sd);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -99,7 +99,6 @@ KERNEL_STRUCT_BEGIN(subsurface)
|
|||||||
KERNEL_STRUCT_MEMBER(subsurface, float3, albedo, KERNEL_FEATURE_SUBSURFACE)
|
KERNEL_STRUCT_MEMBER(subsurface, float3, albedo, KERNEL_FEATURE_SUBSURFACE)
|
||||||
KERNEL_STRUCT_MEMBER(subsurface, float3, radius, KERNEL_FEATURE_SUBSURFACE)
|
KERNEL_STRUCT_MEMBER(subsurface, float3, radius, KERNEL_FEATURE_SUBSURFACE)
|
||||||
KERNEL_STRUCT_MEMBER(subsurface, float, anisotropy, KERNEL_FEATURE_SUBSURFACE)
|
KERNEL_STRUCT_MEMBER(subsurface, float, anisotropy, KERNEL_FEATURE_SUBSURFACE)
|
||||||
KERNEL_STRUCT_MEMBER(subsurface, float, roughness, KERNEL_FEATURE_SUBSURFACE)
|
|
||||||
KERNEL_STRUCT_END(subsurface)
|
KERNEL_STRUCT_END(subsurface)
|
||||||
|
|
||||||
/********************************** Volume Stack ******************************/
|
/********************************** Volume Stack ******************************/
|
||||||
|
@@ -47,7 +47,7 @@ ccl_device int subsurface_bounce(INTEGRATOR_STATE_ARGS, ShaderData *sd, const Sh
|
|||||||
|
|
||||||
/* Setup ray into surface. */
|
/* Setup ray into surface. */
|
||||||
INTEGRATOR_STATE_WRITE(ray, P) = sd->P;
|
INTEGRATOR_STATE_WRITE(ray, P) = sd->P;
|
||||||
INTEGRATOR_STATE_WRITE(ray, D) = sd->N;
|
INTEGRATOR_STATE_WRITE(ray, D) = bssrdf->N;
|
||||||
INTEGRATOR_STATE_WRITE(ray, t) = FLT_MAX;
|
INTEGRATOR_STATE_WRITE(ray, t) = FLT_MAX;
|
||||||
INTEGRATOR_STATE_WRITE(ray, dP) = differential_make_compact(sd->dP);
|
INTEGRATOR_STATE_WRITE(ray, dP) = differential_make_compact(sd->dP);
|
||||||
INTEGRATOR_STATE_WRITE(ray, dD) = differential_zero_compact();
|
INTEGRATOR_STATE_WRITE(ray, dD) = differential_zero_compact();
|
||||||
@@ -56,13 +56,20 @@ ccl_device int subsurface_bounce(INTEGRATOR_STATE_ARGS, ShaderData *sd, const Sh
|
|||||||
INTEGRATOR_STATE_WRITE(isect, Ng) = sd->Ng;
|
INTEGRATOR_STATE_WRITE(isect, Ng) = sd->Ng;
|
||||||
INTEGRATOR_STATE_WRITE(isect, object) = sd->object;
|
INTEGRATOR_STATE_WRITE(isect, object) = sd->object;
|
||||||
|
|
||||||
/* Pass BSSRDF parameters. */
|
uint32_t path_flag = (INTEGRATOR_STATE(path, flag) & ~PATH_RAY_CAMERA) |
|
||||||
const uint32_t path_flag = INTEGRATOR_STATE_WRITE(path, flag);
|
((sc->type == CLOSURE_BSSRDF_BURLEY_ID) ? PATH_RAY_SUBSURFACE_DISK :
|
||||||
INTEGRATOR_STATE_WRITE(path, flag) = (path_flag & ~PATH_RAY_CAMERA) |
|
PATH_RAY_SUBSURFACE_RANDOM_WALK);
|
||||||
((sc->type == CLOSURE_BSSRDF_BURLEY_ID) ?
|
|
||||||
PATH_RAY_SUBSURFACE_DISK :
|
/* Compute weight, optionally including Fresnel from entry point. */
|
||||||
PATH_RAY_SUBSURFACE_RANDOM_WALK);
|
float3 weight = shader_bssrdf_sample_weight(sd, sc);
|
||||||
INTEGRATOR_STATE_WRITE(path, throughput) *= shader_bssrdf_sample_weight(sd, sc);
|
# ifdef __PRINCIPLED__
|
||||||
|
if (bssrdf->roughness != FLT_MAX) {
|
||||||
|
path_flag |= PATH_RAY_SUBSURFACE_USE_FRESNEL;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
INTEGRATOR_STATE_WRITE(path, throughput) *= weight;
|
||||||
|
INTEGRATOR_STATE_WRITE(path, flag) = path_flag;
|
||||||
|
|
||||||
/* Advance random number offset for bounce. */
|
/* Advance random number offset for bounce. */
|
||||||
INTEGRATOR_STATE_WRITE(path, rng_offset) += PRNG_BOUNCE_NUM;
|
INTEGRATOR_STATE_WRITE(path, rng_offset) += PRNG_BOUNCE_NUM;
|
||||||
@@ -73,15 +80,17 @@ ccl_device int subsurface_bounce(INTEGRATOR_STATE_ARGS, ShaderData *sd, const Sh
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Pass BSSRDF parameters. */
|
||||||
INTEGRATOR_STATE_WRITE(subsurface, albedo) = bssrdf->albedo;
|
INTEGRATOR_STATE_WRITE(subsurface, albedo) = bssrdf->albedo;
|
||||||
INTEGRATOR_STATE_WRITE(subsurface, radius) = bssrdf->radius;
|
INTEGRATOR_STATE_WRITE(subsurface, radius) = bssrdf->radius;
|
||||||
INTEGRATOR_STATE_WRITE(subsurface, roughness) = bssrdf->roughness;
|
|
||||||
INTEGRATOR_STATE_WRITE(subsurface, anisotropy) = bssrdf->anisotropy;
|
INTEGRATOR_STATE_WRITE(subsurface, anisotropy) = bssrdf->anisotropy;
|
||||||
|
|
||||||
return LABEL_SUBSURFACE_SCATTER;
|
return LABEL_SUBSURFACE_SCATTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
ccl_device void subsurface_shader_data_setup(INTEGRATOR_STATE_ARGS, ShaderData *sd)
|
ccl_device void subsurface_shader_data_setup(INTEGRATOR_STATE_ARGS,
|
||||||
|
ShaderData *sd,
|
||||||
|
const uint32_t path_flag)
|
||||||
{
|
{
|
||||||
/* Get bump mapped normal from shader evaluation at exit point. */
|
/* Get bump mapped normal from shader evaluation at exit point. */
|
||||||
float3 N = sd->N;
|
float3 N = sd->N;
|
||||||
@@ -95,21 +104,16 @@ ccl_device void subsurface_shader_data_setup(INTEGRATOR_STATE_ARGS, ShaderData *
|
|||||||
sd->num_closure_left = kernel_data.max_closures;
|
sd->num_closure_left = kernel_data.max_closures;
|
||||||
|
|
||||||
const float3 weight = one_float3();
|
const float3 weight = one_float3();
|
||||||
const float roughness = INTEGRATOR_STATE(subsurface, roughness);
|
|
||||||
|
|
||||||
# ifdef __PRINCIPLED__
|
# ifdef __PRINCIPLED__
|
||||||
if (roughness != FLT_MAX) {
|
if (path_flag & PATH_RAY_SUBSURFACE_USE_FRESNEL) {
|
||||||
PrincipledDiffuseBsdf *bsdf = (PrincipledDiffuseBsdf *)bsdf_alloc(
|
PrincipledDiffuseBsdf *bsdf = (PrincipledDiffuseBsdf *)bsdf_alloc(
|
||||||
sd, sizeof(PrincipledDiffuseBsdf), weight);
|
sd, sizeof(PrincipledDiffuseBsdf), weight);
|
||||||
|
|
||||||
if (bsdf) {
|
if (bsdf) {
|
||||||
bsdf->N = N;
|
bsdf->N = N;
|
||||||
bsdf->roughness = roughness;
|
bsdf->roughness = FLT_MAX;
|
||||||
sd->flag |= bsdf_principled_diffuse_setup(bsdf);
|
sd->flag |= bsdf_principled_diffuse_setup(bsdf, PRINCIPLED_DIFFUSE_LAMBERT_EXIT);
|
||||||
|
|
||||||
/* replace CLOSURE_BSDF_PRINCIPLED_DIFFUSE_ID with this special ID so render passes
|
|
||||||
* can recognize it as not being a regular Disney principled diffuse closure */
|
|
||||||
bsdf->type = CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -120,10 +124,6 @@ ccl_device void subsurface_shader_data_setup(INTEGRATOR_STATE_ARGS, ShaderData *
|
|||||||
if (bsdf) {
|
if (bsdf) {
|
||||||
bsdf->N = N;
|
bsdf->N = N;
|
||||||
sd->flag |= bsdf_diffuse_setup(bsdf);
|
sd->flag |= bsdf_diffuse_setup(bsdf);
|
||||||
|
|
||||||
/* replace CLOSURE_BSDF_DIFFUSE_ID with this special ID so render passes
|
|
||||||
* can recognize it as not being a regular diffuse closure */
|
|
||||||
bsdf->type = CLOSURE_BSDF_BSSRDF_ID;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -159,7 +159,7 @@ ccl_device_forceinline bool _shader_bsdf_exclude(ClosureType type, uint light_sh
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (light_shader_flags & SHADER_EXCLUDE_DIFFUSE) {
|
if (light_shader_flags & SHADER_EXCLUDE_DIFFUSE) {
|
||||||
if (CLOSURE_IS_BSDF_DIFFUSE(type) || CLOSURE_IS_BSDF_BSSRDF(type)) {
|
if (CLOSURE_IS_BSDF_DIFFUSE(type)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,8 +201,7 @@ ccl_device_inline float _shader_bsdf_multi_eval(const KernelGlobals *kg,
|
|||||||
float3 eval = bsdf_eval(kg, sd, sc, omega_in, is_transmission, &bsdf_pdf);
|
float3 eval = bsdf_eval(kg, sd, sc, omega_in, is_transmission, &bsdf_pdf);
|
||||||
|
|
||||||
if (bsdf_pdf != 0.0f) {
|
if (bsdf_pdf != 0.0f) {
|
||||||
const bool is_diffuse = (CLOSURE_IS_BSDF_DIFFUSE(sc->type) ||
|
const bool is_diffuse = CLOSURE_IS_BSDF_DIFFUSE(sc->type);
|
||||||
CLOSURE_IS_BSDF_BSSRDF(sc->type));
|
|
||||||
bsdf_eval_accum(result_eval, is_diffuse, eval * sc->weight, 1.0f);
|
bsdf_eval_accum(result_eval, is_diffuse, eval * sc->weight, 1.0f);
|
||||||
sum_pdf += bsdf_pdf * sc->sample_weight;
|
sum_pdf += bsdf_pdf * sc->sample_weight;
|
||||||
}
|
}
|
||||||
@@ -320,8 +319,7 @@ ccl_device int shader_bsdf_sample_closure(const KernelGlobals *kg,
|
|||||||
label = bsdf_sample(kg, sd, sc, randu, randv, &eval, omega_in, domega_in, pdf);
|
label = bsdf_sample(kg, sd, sc, randu, randv, &eval, omega_in, domega_in, pdf);
|
||||||
|
|
||||||
if (*pdf != 0.0f) {
|
if (*pdf != 0.0f) {
|
||||||
const bool is_diffuse = (CLOSURE_IS_BSDF_DIFFUSE(sc->type) ||
|
const bool is_diffuse = CLOSURE_IS_BSDF_DIFFUSE(sc->type);
|
||||||
CLOSURE_IS_BSDF_BSSRDF(sc->type));
|
|
||||||
bsdf_eval_init(bsdf_eval, is_diffuse, eval * sc->weight);
|
bsdf_eval_init(bsdf_eval, is_diffuse, eval * sc->weight);
|
||||||
|
|
||||||
if (sd->num_closure > 1) {
|
if (sd->num_closure > 1) {
|
||||||
@@ -401,8 +399,7 @@ ccl_device float3 shader_bsdf_diffuse(const KernelGlobals *kg, const ShaderData
|
|||||||
for (int i = 0; i < sd->num_closure; i++) {
|
for (int i = 0; i < sd->num_closure; i++) {
|
||||||
const ShaderClosure *sc = &sd->closure[i];
|
const ShaderClosure *sc = &sd->closure[i];
|
||||||
|
|
||||||
if (CLOSURE_IS_BSDF_DIFFUSE(sc->type) || CLOSURE_IS_BSSRDF(sc->type) ||
|
if (CLOSURE_IS_BSDF_DIFFUSE(sc->type) || CLOSURE_IS_BSSRDF(sc->type))
|
||||||
CLOSURE_IS_BSDF_BSSRDF(sc->type))
|
|
||||||
eval += sc->weight;
|
eval += sc->weight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -263,32 +263,34 @@ enum PathRayFlag {
|
|||||||
/* Perform subsurface scattering. */
|
/* Perform subsurface scattering. */
|
||||||
PATH_RAY_SUBSURFACE_RANDOM_WALK = (1 << 20),
|
PATH_RAY_SUBSURFACE_RANDOM_WALK = (1 << 20),
|
||||||
PATH_RAY_SUBSURFACE_DISK = (1 << 21),
|
PATH_RAY_SUBSURFACE_DISK = (1 << 21),
|
||||||
PATH_RAY_SUBSURFACE = (PATH_RAY_SUBSURFACE_RANDOM_WALK | PATH_RAY_SUBSURFACE_DISK),
|
PATH_RAY_SUBSURFACE_USE_FRESNEL = (1 << 22),
|
||||||
|
PATH_RAY_SUBSURFACE = (PATH_RAY_SUBSURFACE_RANDOM_WALK | PATH_RAY_SUBSURFACE_DISK |
|
||||||
|
PATH_RAY_SUBSURFACE_USE_FRESNEL),
|
||||||
|
|
||||||
/* Contribute to denoising features. */
|
/* Contribute to denoising features. */
|
||||||
PATH_RAY_DENOISING_FEATURES = (1 << 22),
|
PATH_RAY_DENOISING_FEATURES = (1 << 23),
|
||||||
|
|
||||||
/* Render pass categories. */
|
/* Render pass categories. */
|
||||||
PATH_RAY_REFLECT_PASS = (1 << 23),
|
PATH_RAY_REFLECT_PASS = (1 << 24),
|
||||||
PATH_RAY_TRANSMISSION_PASS = (1 << 24),
|
PATH_RAY_TRANSMISSION_PASS = (1 << 25),
|
||||||
PATH_RAY_VOLUME_PASS = (1 << 25),
|
PATH_RAY_VOLUME_PASS = (1 << 26),
|
||||||
PATH_RAY_ANY_PASS = (PATH_RAY_REFLECT_PASS | PATH_RAY_TRANSMISSION_PASS | PATH_RAY_VOLUME_PASS),
|
PATH_RAY_ANY_PASS = (PATH_RAY_REFLECT_PASS | PATH_RAY_TRANSMISSION_PASS | PATH_RAY_VOLUME_PASS),
|
||||||
|
|
||||||
/* Shadow ray is for a light or surface. */
|
/* Shadow ray is for a light or surface. */
|
||||||
PATH_RAY_SHADOW_FOR_LIGHT = (1 << 26),
|
PATH_RAY_SHADOW_FOR_LIGHT = (1 << 27),
|
||||||
|
|
||||||
/* A shadow catcher object was hit and the path was split into two. */
|
/* A shadow catcher object was hit and the path was split into two. */
|
||||||
PATH_RAY_SHADOW_CATCHER_HIT = (1 << 27),
|
PATH_RAY_SHADOW_CATCHER_HIT = (1 << 28),
|
||||||
|
|
||||||
/* A shadow catcher object was hit and this path traces only shadow catchers, writing them into
|
/* A shadow catcher object was hit and this path traces only shadow catchers, writing them into
|
||||||
* their dedicated pass for later division.
|
* their dedicated pass for later division.
|
||||||
*
|
*
|
||||||
* NOTE: Is not covered with `PATH_RAY_ANY_PASS` because shadow catcher does special handling
|
* NOTE: Is not covered with `PATH_RAY_ANY_PASS` because shadow catcher does special handling
|
||||||
* which is separate from the light passes. */
|
* which is separate from the light passes. */
|
||||||
PATH_RAY_SHADOW_CATCHER_PASS = (1 << 28),
|
PATH_RAY_SHADOW_CATCHER_PASS = (1 << 29),
|
||||||
|
|
||||||
/* Path is evaluating background for an approximate shadow catcher with non-transparent film. */
|
/* Path is evaluating background for an approximate shadow catcher with non-transparent film. */
|
||||||
PATH_RAY_SHADOW_CATCHER_BACKGROUND = (1 << 29),
|
PATH_RAY_SHADOW_CATCHER_BACKGROUND = (1 << 30),
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Configure ray visibility bits for rays and objects respectively,
|
/* Configure ray visibility bits for rays and objects respectively,
|
||||||
|
@@ -221,7 +221,7 @@ ccl_device_noinline int svm_node_closure_bsdf(
|
|||||||
bsdf->roughness = roughness;
|
bsdf->roughness = roughness;
|
||||||
|
|
||||||
/* setup bsdf */
|
/* setup bsdf */
|
||||||
sd->flag |= bsdf_principled_diffuse_setup(bsdf);
|
sd->flag |= bsdf_principled_diffuse_setup(bsdf, PRINCIPLED_DIFFUSE_FULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (subsurface > CLOSURE_WEIGHT_CUTOFF) {
|
else if (subsurface > CLOSURE_WEIGHT_CUTOFF) {
|
||||||
@@ -255,7 +255,7 @@ ccl_device_noinline int svm_node_closure_bsdf(
|
|||||||
bsdf->roughness = roughness;
|
bsdf->roughness = roughness;
|
||||||
|
|
||||||
/* setup bsdf */
|
/* setup bsdf */
|
||||||
sd->flag |= bsdf_principled_diffuse_setup(bsdf);
|
sd->flag |= bsdf_principled_diffuse_setup(bsdf, PRINCIPLED_DIFFUSE_FULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
@@ -538,8 +538,6 @@ typedef enum ClosureType {
|
|||||||
CLOSURE_BSDF_HAIR_TRANSMISSION_ID,
|
CLOSURE_BSDF_HAIR_TRANSMISSION_ID,
|
||||||
|
|
||||||
/* Special cases */
|
/* Special cases */
|
||||||
CLOSURE_BSDF_BSSRDF_ID,
|
|
||||||
CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID,
|
|
||||||
CLOSURE_BSDF_TRANSPARENT_ID,
|
CLOSURE_BSDF_TRANSPARENT_ID,
|
||||||
|
|
||||||
/* BSSRDF */
|
/* BSSRDF */
|
||||||
@@ -569,8 +567,6 @@ typedef enum ClosureType {
|
|||||||
(type == CLOSURE_BSDF_HAIR_PRINCIPLED_ID))
|
(type == CLOSURE_BSDF_HAIR_PRINCIPLED_ID))
|
||||||
#define CLOSURE_IS_BSDF_TRANSMISSION(type) \
|
#define CLOSURE_IS_BSDF_TRANSMISSION(type) \
|
||||||
(type >= CLOSURE_BSDF_REFRACTION_ID && type <= CLOSURE_BSDF_HAIR_TRANSMISSION_ID)
|
(type >= CLOSURE_BSDF_REFRACTION_ID && type <= CLOSURE_BSDF_HAIR_TRANSMISSION_ID)
|
||||||
#define CLOSURE_IS_BSDF_BSSRDF(type) \
|
|
||||||
(type == CLOSURE_BSDF_BSSRDF_ID || type == CLOSURE_BSDF_BSSRDF_PRINCIPLED_ID)
|
|
||||||
#define CLOSURE_IS_BSDF_SINGULAR(type) \
|
#define CLOSURE_IS_BSDF_SINGULAR(type) \
|
||||||
(type == CLOSURE_BSDF_REFLECTION_ID || type == CLOSURE_BSDF_REFRACTION_ID || \
|
(type == CLOSURE_BSDF_REFLECTION_ID || type == CLOSURE_BSDF_REFRACTION_ID || \
|
||||||
type == CLOSURE_BSDF_TRANSPARENT_ID)
|
type == CLOSURE_BSDF_TRANSPARENT_ID)
|
||||||
|
Reference in New Issue
Block a user