Cycles: Improve handling of Principled BSDF Caustics settings
Improve the handling of Principled BSDF Caustics from Metallic and Transmissive components, improving consistency between SVM and OSL, and offering more predictable results. Pull Request: https://projects.blender.org/blender/blender/pulls/115081
This commit is contained in:
@@ -47,11 +47,23 @@ ccl_device_forceinline bool osl_closure_skip(KernelGlobals kg,
|
||||
uint32_t path_flag,
|
||||
int scattering)
|
||||
{
|
||||
/* caustic options */
|
||||
/* Caustic options */
|
||||
if ((scattering & LABEL_GLOSSY) && (path_flag & PATH_RAY_DIFFUSE)) {
|
||||
if ((!kernel_data.integrator.caustics_reflective && (scattering & LABEL_REFLECT)) ||
|
||||
(!kernel_data.integrator.caustics_refractive && (scattering & LABEL_TRANSMIT)))
|
||||
{
|
||||
const bool has_reflect = (scattering & LABEL_REFLECT);
|
||||
const bool has_transmit = (scattering & LABEL_TRANSMIT);
|
||||
const bool reflect_caustics_disabled = !kernel_data.integrator.caustics_reflective;
|
||||
const bool refract_caustics_disabled = !kernel_data.integrator.caustics_refractive;
|
||||
|
||||
/* Reflective Caustics */
|
||||
if (reflect_caustics_disabled && has_reflect && !has_transmit) {
|
||||
return true;
|
||||
}
|
||||
/* Refractive Caustics*/
|
||||
if (refract_caustics_disabled && has_transmit && !has_reflect) {
|
||||
return true;
|
||||
}
|
||||
/* Glass Caustics */
|
||||
if (reflect_caustics_disabled && refract_caustics_disabled && has_reflect && has_transmit) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -322,7 +334,12 @@ ccl_device void osl_closure_generalized_schlick_bsdf_setup(
|
||||
const bool has_reflection = !is_zero(closure->reflection_tint);
|
||||
const bool has_transmission = !is_zero(closure->transmission_tint);
|
||||
|
||||
if (osl_closure_skip(kg, sd, path_flag, LABEL_GLOSSY | LABEL_REFLECT)) {
|
||||
int label = LABEL_GLOSSY | LABEL_REFLECT;
|
||||
if (has_transmission) {
|
||||
label |= LABEL_TRANSMIT;
|
||||
}
|
||||
|
||||
if (osl_closure_skip(kg, sd, path_flag, label)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -271,64 +271,66 @@ ccl_device
|
||||
}
|
||||
|
||||
/* Metallic component */
|
||||
if (reflective_caustics && metallic > CLOSURE_WEIGHT_CUTOFF) {
|
||||
ccl_private MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)bsdf_alloc(
|
||||
sd, sizeof(MicrofacetBsdf), metallic * weight);
|
||||
ccl_private FresnelF82Tint *fresnel =
|
||||
(bsdf != NULL) ?
|
||||
(ccl_private FresnelF82Tint *)closure_alloc_extra(sd, sizeof(FresnelF82Tint)) :
|
||||
NULL;
|
||||
if (metallic > CLOSURE_WEIGHT_CUTOFF) {
|
||||
if (reflective_caustics) {
|
||||
ccl_private MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)bsdf_alloc(
|
||||
sd, sizeof(MicrofacetBsdf), metallic * weight);
|
||||
ccl_private FresnelF82Tint *fresnel =
|
||||
(bsdf != NULL) ?
|
||||
(ccl_private FresnelF82Tint *)closure_alloc_extra(sd, sizeof(FresnelF82Tint)) :
|
||||
NULL;
|
||||
|
||||
if (bsdf && fresnel) {
|
||||
bsdf->N = valid_reflection_N;
|
||||
bsdf->ior = 1.0f;
|
||||
bsdf->T = T;
|
||||
bsdf->alpha_x = alpha_x;
|
||||
bsdf->alpha_y = alpha_y;
|
||||
if (bsdf && fresnel) {
|
||||
bsdf->N = valid_reflection_N;
|
||||
bsdf->ior = 1.0f;
|
||||
bsdf->T = T;
|
||||
bsdf->alpha_x = alpha_x;
|
||||
bsdf->alpha_y = alpha_y;
|
||||
|
||||
fresnel->f0 = rgb_to_spectrum(clamped_base_color);
|
||||
const Spectrum f82 = min(specular_tint, one_spectrum());
|
||||
fresnel->f0 = rgb_to_spectrum(clamped_base_color);
|
||||
const Spectrum f82 = min(specular_tint, one_spectrum());
|
||||
|
||||
/* setup bsdf */
|
||||
sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
|
||||
const bool is_multiggx = (distribution == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
|
||||
bsdf_microfacet_setup_fresnel_f82_tint(kg, bsdf, sd, fresnel, f82, is_multiggx);
|
||||
|
||||
/* Attenuate other components */
|
||||
weight *= (1.0f - metallic);
|
||||
/* setup bsdf */
|
||||
sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
|
||||
const bool is_multiggx = (distribution == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
|
||||
bsdf_microfacet_setup_fresnel_f82_tint(kg, bsdf, sd, fresnel, f82, is_multiggx);
|
||||
}
|
||||
}
|
||||
/* Attenuate other components */
|
||||
weight *= (1.0f - metallic);
|
||||
}
|
||||
|
||||
/* Transmission component */
|
||||
if (glass_caustics && transmission_weight > CLOSURE_WEIGHT_CUTOFF) {
|
||||
ccl_private MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)bsdf_alloc(
|
||||
sd, sizeof(MicrofacetBsdf), transmission_weight * weight);
|
||||
ccl_private FresnelGeneralizedSchlick *fresnel =
|
||||
(bsdf != NULL) ? (ccl_private FresnelGeneralizedSchlick *)closure_alloc_extra(
|
||||
sd, sizeof(FresnelGeneralizedSchlick)) :
|
||||
NULL;
|
||||
if (transmission_weight > CLOSURE_WEIGHT_CUTOFF) {
|
||||
if (glass_caustics) {
|
||||
ccl_private MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)bsdf_alloc(
|
||||
sd, sizeof(MicrofacetBsdf), transmission_weight * weight);
|
||||
ccl_private FresnelGeneralizedSchlick *fresnel =
|
||||
(bsdf != NULL) ? (ccl_private FresnelGeneralizedSchlick *)closure_alloc_extra(
|
||||
sd, sizeof(FresnelGeneralizedSchlick)) :
|
||||
NULL;
|
||||
|
||||
if (bsdf && fresnel) {
|
||||
bsdf->N = valid_reflection_N;
|
||||
bsdf->T = zero_float3();
|
||||
if (bsdf && fresnel) {
|
||||
bsdf->N = valid_reflection_N;
|
||||
bsdf->T = zero_float3();
|
||||
|
||||
bsdf->alpha_x = bsdf->alpha_y = sqr(roughness);
|
||||
bsdf->ior = (sd->flag & SD_BACKFACING) ? 1.0f / ior : ior;
|
||||
bsdf->alpha_x = bsdf->alpha_y = sqr(roughness);
|
||||
bsdf->ior = (sd->flag & SD_BACKFACING) ? 1.0f / ior : ior;
|
||||
|
||||
fresnel->f0 = make_float3(F0_from_ior(ior)) * specular_tint;
|
||||
fresnel->f90 = one_spectrum();
|
||||
fresnel->exponent = -ior;
|
||||
fresnel->reflection_tint = one_spectrum();
|
||||
fresnel->transmission_tint = sqrt(rgb_to_spectrum(clamped_base_color));
|
||||
fresnel->f0 = make_float3(F0_from_ior(ior)) * specular_tint;
|
||||
fresnel->f90 = one_spectrum();
|
||||
fresnel->exponent = -ior;
|
||||
fresnel->reflection_tint = one_spectrum();
|
||||
fresnel->transmission_tint = sqrt(rgb_to_spectrum(clamped_base_color));
|
||||
|
||||
/* setup bsdf */
|
||||
sd->flag |= bsdf_microfacet_ggx_glass_setup(bsdf);
|
||||
const bool is_multiggx = (distribution == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
|
||||
bsdf_microfacet_setup_fresnel_generalized_schlick(kg, bsdf, sd, fresnel, is_multiggx);
|
||||
|
||||
/* Attenuate other components */
|
||||
weight *= (1.0f - transmission_weight);
|
||||
/* setup bsdf */
|
||||
sd->flag |= bsdf_microfacet_ggx_glass_setup(bsdf);
|
||||
const bool is_multiggx = (distribution == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
|
||||
bsdf_microfacet_setup_fresnel_generalized_schlick(kg, bsdf, sd, fresnel, is_multiggx);
|
||||
}
|
||||
}
|
||||
/* Attenuate other components */
|
||||
weight *= (1.0f - transmission_weight);
|
||||
}
|
||||
|
||||
/* Apply IOR adjustment */
|
||||
|
||||
Reference in New Issue
Block a user