Cleanup: Cycles: remove SHARP distribution internally
this option was already unselectable in the UI, and is treated as GGX
with zero roughness. Upon building the shader graph, we only convert a
closure to `SHARP` when option Filter Glossy is not used and the
roughness is below certain threshold. The benefit is that we can avoid
calling `bsdf_eval()` or return earlier in some cases, but the thresholds
vary across files.
This patch removes `SHARP` closures altogether, and checks if the
roughness value is below a global threshold `BSDF_ROUGHNESS_THRESH`
after blurring, in which case the flag `SD_BSDF_HAS_EVAL` is not set.
The global threshold is set to be `5e-7f` because threshold smaller than
that seems to have caused problem in the past (c6aa0217ac). Also removes
a bunch of functions, variables and arguments that were only there
because we converted closures under certain conditions.
Pull Request: https://projects.blender.org/blender/blender/pulls/109902
This commit is contained in:
committed by
Weizhen Huang
parent
84c8c331b4
commit
0b3efc9d8c
@@ -157,12 +157,6 @@ ccl_device_inline int bsdf_sample(KernelGlobals kg,
|
||||
*sampled_roughness = zero_float2();
|
||||
*eta = 1.0f;
|
||||
break;
|
||||
case CLOSURE_BSDF_REFLECTION_ID:
|
||||
case CLOSURE_BSDF_REFRACTION_ID:
|
||||
case CLOSURE_BSDF_SHARP_GLASS_ID:
|
||||
label = bsdf_microfacet_sharp_sample(
|
||||
sc, path_flag, Ng, sd->wi, rand, eval, wo, pdf, sampled_roughness, eta);
|
||||
break;
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
||||
@@ -296,9 +290,6 @@ ccl_device_inline void bsdf_roughness_eta(const KernelGlobals kg,
|
||||
*roughness = zero_float2();
|
||||
*eta = 1.0f;
|
||||
break;
|
||||
case CLOSURE_BSDF_REFLECTION_ID:
|
||||
case CLOSURE_BSDF_REFRACTION_ID:
|
||||
case CLOSURE_BSDF_SHARP_GLASS_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
||||
@@ -398,9 +389,6 @@ ccl_device_inline int bsdf_label(const KernelGlobals kg,
|
||||
case CLOSURE_BSDF_TRANSPARENT_ID:
|
||||
label = LABEL_TRANSMIT | LABEL_TRANSPARENT;
|
||||
break;
|
||||
case CLOSURE_BSDF_REFLECTION_ID:
|
||||
case CLOSURE_BSDF_REFRACTION_ID:
|
||||
case CLOSURE_BSDF_SHARP_GLASS_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
||||
@@ -410,7 +398,7 @@ ccl_device_inline int bsdf_label(const KernelGlobals kg,
|
||||
case CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID: {
|
||||
ccl_private const MicrofacetBsdf *bsdf = (ccl_private const MicrofacetBsdf *)sc;
|
||||
label = ((bsdf_is_transmission(sc, wo)) ? LABEL_TRANSMIT : LABEL_REFLECT) |
|
||||
((bsdf->alpha_x * bsdf->alpha_y <= 1e-7f) ? LABEL_SINGULAR : LABEL_GLOSSY);
|
||||
((bsdf_microfacet_eval_flag(bsdf)) ? LABEL_GLOSSY : LABEL_SINGULAR);
|
||||
break;
|
||||
}
|
||||
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
|
||||
@@ -499,11 +487,6 @@ ccl_device_inline
|
||||
case CLOSURE_BSDF_TRANSPARENT_ID:
|
||||
eval = bsdf_transparent_eval(sc, sd->wi, wo, pdf);
|
||||
break;
|
||||
case CLOSURE_BSDF_REFLECTION_ID:
|
||||
case CLOSURE_BSDF_REFRACTION_ID:
|
||||
case CLOSURE_BSDF_SHARP_GLASS_ID:
|
||||
eval = bsdf_microfacet_sharp_eval(sc, sd->N, sd->wi, wo, pdf);
|
||||
break;
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
||||
@@ -579,13 +562,11 @@ ccl_device void bsdf_blur(KernelGlobals kg, ccl_private ShaderClosure *sc, float
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID:
|
||||
/* TODO: Recompute energy preservation after blur? */
|
||||
bsdf_microfacet_ggx_blur(sc, roughness);
|
||||
break;
|
||||
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID:
|
||||
bsdf_microfacet_beckmann_blur(sc, roughness);
|
||||
/* TODO: Recompute energy preservation after blur? */
|
||||
bsdf_microfacet_blur(sc, roughness);
|
||||
break;
|
||||
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
|
||||
bsdf_ashikhmin_shirley_blur(sc, roughness);
|
||||
|
||||
@@ -18,7 +18,6 @@ CCL_NAMESPACE_BEGIN
|
||||
enum MicrofacetType {
|
||||
BECKMANN,
|
||||
GGX,
|
||||
SHARP,
|
||||
};
|
||||
|
||||
enum MicrofacetFresnel {
|
||||
@@ -444,6 +443,12 @@ ccl_device_inline float bsdf_aniso_D(float alpha_x, float alpha_y, float3 H)
|
||||
}
|
||||
}
|
||||
|
||||
/* Do not set `SD_BSDF_HAS_EVAL` flag if the squared roughness is below a certain threshold. */
|
||||
ccl_device_forceinline int bsdf_microfacet_eval_flag(const ccl_private MicrofacetBsdf *bsdf)
|
||||
{
|
||||
return (bsdf->alpha_x * bsdf->alpha_y > BSDF_ROUGHNESS_SQ_THRESH) ? SD_BSDF_HAS_EVAL : 0;
|
||||
}
|
||||
|
||||
template<MicrofacetType m_type>
|
||||
ccl_device Spectrum bsdf_microfacet_eval(ccl_private const ShaderClosure *sc,
|
||||
const float3 Ng,
|
||||
@@ -451,11 +456,6 @@ ccl_device Spectrum bsdf_microfacet_eval(ccl_private const ShaderClosure *sc,
|
||||
const float3 wo,
|
||||
ccl_private float *pdf)
|
||||
{
|
||||
if (m_type == MicrofacetType::SHARP) {
|
||||
*pdf = 0.0f;
|
||||
return zero_spectrum();
|
||||
}
|
||||
|
||||
ccl_private const MicrofacetBsdf *bsdf = (ccl_private const MicrofacetBsdf *)sc;
|
||||
/* Refraction: Only consider BTDF
|
||||
* Glass: Consider both BRDF and BTDF, mix based on Fresnel
|
||||
@@ -481,7 +481,7 @@ ccl_device Spectrum bsdf_microfacet_eval(ccl_private const ShaderClosure *sc,
|
||||
* - Purely reflective closures can't have refraction.
|
||||
* - Purely refractive closures can't have reflection.
|
||||
*/
|
||||
if ((cos_NI <= 0) || (alpha_x * alpha_y <= 5e-7f) || ((cos_NgO < 0.0f) != is_transmission) ||
|
||||
if ((cos_NI <= 0) || !bsdf_microfacet_eval_flag(bsdf) || ((cos_NgO < 0.0f) != is_transmission) ||
|
||||
(is_transmission && m_reflection) || (!is_transmission && m_refraction))
|
||||
{
|
||||
*pdf = 0.0f;
|
||||
@@ -565,7 +565,7 @@ ccl_device int bsdf_microfacet_sample(ccl_private const ShaderClosure *sc,
|
||||
const bool m_reflection = !(m_refraction || m_glass);
|
||||
const float alpha_x = bsdf->alpha_x;
|
||||
const float alpha_y = bsdf->alpha_y;
|
||||
bool m_singular = (m_type == MicrofacetType::SHARP) || (alpha_x * alpha_y <= 5e-7f);
|
||||
bool m_singular = !bsdf_microfacet_eval_flag(bsdf);
|
||||
|
||||
const float3 N = bsdf->N;
|
||||
const float cos_NI = dot(N, wi);
|
||||
@@ -848,7 +848,7 @@ ccl_device int bsdf_microfacet_ggx_setup(ccl_private MicrofacetBsdf *bsdf)
|
||||
bsdf->energy_scale = 1.0f;
|
||||
bsdf->type = CLOSURE_BSDF_MICROFACET_GGX_ID;
|
||||
|
||||
return SD_BSDF | SD_BSDF_HAS_EVAL;
|
||||
return SD_BSDF | bsdf_microfacet_eval_flag(bsdf);
|
||||
}
|
||||
|
||||
ccl_device int bsdf_microfacet_ggx_clearcoat_setup(ccl_private MicrofacetBsdf *bsdf,
|
||||
@@ -862,7 +862,7 @@ ccl_device int bsdf_microfacet_ggx_clearcoat_setup(ccl_private MicrofacetBsdf *b
|
||||
bsdf->type = CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID;
|
||||
bsdf->sample_weight *= average(bsdf_microfacet_estimate_fresnel(sd, bsdf, true, true));
|
||||
|
||||
return SD_BSDF | SD_BSDF_HAS_EVAL;
|
||||
return SD_BSDF | bsdf_microfacet_eval_flag(bsdf);
|
||||
}
|
||||
|
||||
ccl_device int bsdf_microfacet_ggx_refraction_setup(ccl_private MicrofacetBsdf *bsdf)
|
||||
@@ -874,7 +874,7 @@ ccl_device int bsdf_microfacet_ggx_refraction_setup(ccl_private MicrofacetBsdf *
|
||||
bsdf->energy_scale = 1.0f;
|
||||
bsdf->type = CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID;
|
||||
|
||||
return SD_BSDF | SD_BSDF_HAS_EVAL | SD_BSDF_HAS_TRANSMISSION;
|
||||
return SD_BSDF | SD_BSDF_HAS_TRANSMISSION | bsdf_microfacet_eval_flag(bsdf);
|
||||
}
|
||||
|
||||
ccl_device int bsdf_microfacet_ggx_glass_setup(ccl_private MicrofacetBsdf *bsdf)
|
||||
@@ -886,10 +886,10 @@ ccl_device int bsdf_microfacet_ggx_glass_setup(ccl_private MicrofacetBsdf *bsdf)
|
||||
bsdf->energy_scale = 1.0f;
|
||||
bsdf->type = CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID;
|
||||
|
||||
return SD_BSDF | SD_BSDF_HAS_EVAL | SD_BSDF_HAS_TRANSMISSION;
|
||||
return SD_BSDF | SD_BSDF_HAS_TRANSMISSION | bsdf_microfacet_eval_flag(bsdf);
|
||||
}
|
||||
|
||||
ccl_device void bsdf_microfacet_ggx_blur(ccl_private ShaderClosure *sc, float roughness)
|
||||
ccl_device void bsdf_microfacet_blur(ccl_private ShaderClosure *sc, float roughness)
|
||||
{
|
||||
ccl_private MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)sc;
|
||||
|
||||
@@ -937,7 +937,8 @@ ccl_device int bsdf_microfacet_beckmann_setup(ccl_private MicrofacetBsdf *bsdf)
|
||||
|
||||
bsdf->fresnel_type = MicrofacetFresnel::NONE;
|
||||
bsdf->type = CLOSURE_BSDF_MICROFACET_BECKMANN_ID;
|
||||
return SD_BSDF | SD_BSDF_HAS_EVAL;
|
||||
|
||||
return SD_BSDF | bsdf_microfacet_eval_flag(bsdf);
|
||||
}
|
||||
|
||||
ccl_device int bsdf_microfacet_beckmann_refraction_setup(ccl_private MicrofacetBsdf *bsdf)
|
||||
@@ -947,7 +948,8 @@ ccl_device int bsdf_microfacet_beckmann_refraction_setup(ccl_private MicrofacetB
|
||||
|
||||
bsdf->fresnel_type = MicrofacetFresnel::NONE;
|
||||
bsdf->type = CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID;
|
||||
return SD_BSDF | SD_BSDF_HAS_EVAL | SD_BSDF_HAS_TRANSMISSION;
|
||||
|
||||
return SD_BSDF | SD_BSDF_HAS_TRANSMISSION | bsdf_microfacet_eval_flag(bsdf);
|
||||
}
|
||||
|
||||
ccl_device int bsdf_microfacet_beckmann_glass_setup(ccl_private MicrofacetBsdf *bsdf)
|
||||
@@ -957,15 +959,8 @@ ccl_device int bsdf_microfacet_beckmann_glass_setup(ccl_private MicrofacetBsdf *
|
||||
|
||||
bsdf->fresnel_type = MicrofacetFresnel::DIELECTRIC;
|
||||
bsdf->type = CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID;
|
||||
return SD_BSDF | SD_BSDF_HAS_EVAL | SD_BSDF_HAS_TRANSMISSION;
|
||||
}
|
||||
|
||||
ccl_device void bsdf_microfacet_beckmann_blur(ccl_private ShaderClosure *sc, float roughness)
|
||||
{
|
||||
ccl_private MicrofacetBsdf *bsdf = (ccl_private MicrofacetBsdf *)sc;
|
||||
|
||||
bsdf->alpha_x = fmaxf(roughness, bsdf->alpha_x);
|
||||
bsdf->alpha_y = fmaxf(roughness, bsdf->alpha_y);
|
||||
return SD_BSDF | SD_BSDF_HAS_TRANSMISSION | bsdf_microfacet_eval_flag(bsdf);
|
||||
}
|
||||
|
||||
ccl_device Spectrum bsdf_microfacet_beckmann_eval(ccl_private const ShaderClosure *sc,
|
||||
@@ -992,58 +987,4 @@ ccl_device int bsdf_microfacet_beckmann_sample(ccl_private const ShaderClosure *
|
||||
sc, path_flag, Ng, wi, rand, eval, wo, pdf, sampled_roughness, eta);
|
||||
}
|
||||
|
||||
/* Specular interface, not really a microfacet model but close enough that sharing code makes
|
||||
* sense. */
|
||||
|
||||
ccl_device int bsdf_reflection_setup(ccl_private MicrofacetBsdf *bsdf)
|
||||
{
|
||||
bsdf->fresnel_type = MicrofacetFresnel::NONE;
|
||||
bsdf->type = CLOSURE_BSDF_REFLECTION_ID;
|
||||
bsdf->alpha_x = 0.0f;
|
||||
bsdf->alpha_y = 0.0f;
|
||||
return SD_BSDF;
|
||||
}
|
||||
|
||||
ccl_device int bsdf_refraction_setup(ccl_private MicrofacetBsdf *bsdf)
|
||||
{
|
||||
bsdf->fresnel_type = MicrofacetFresnel::NONE;
|
||||
bsdf->type = CLOSURE_BSDF_REFRACTION_ID;
|
||||
bsdf->alpha_x = 0.0f;
|
||||
bsdf->alpha_y = 0.0f;
|
||||
return SD_BSDF | SD_BSDF_HAS_TRANSMISSION;
|
||||
}
|
||||
|
||||
ccl_device int bsdf_sharp_glass_setup(ccl_private MicrofacetBsdf *bsdf)
|
||||
{
|
||||
bsdf->fresnel_type = MicrofacetFresnel::DIELECTRIC;
|
||||
bsdf->type = CLOSURE_BSDF_SHARP_GLASS_ID;
|
||||
bsdf->alpha_x = 0.0f;
|
||||
bsdf->alpha_y = 0.0f;
|
||||
return SD_BSDF | SD_BSDF_HAS_TRANSMISSION;
|
||||
}
|
||||
|
||||
ccl_device Spectrum bsdf_microfacet_sharp_eval(ccl_private const ShaderClosure *sc,
|
||||
const float3 Ng,
|
||||
const float3 wi,
|
||||
const float3 wo,
|
||||
ccl_private float *pdf)
|
||||
{
|
||||
return bsdf_microfacet_eval<MicrofacetType::SHARP>(sc, Ng, wi, wo, pdf);
|
||||
}
|
||||
|
||||
ccl_device int bsdf_microfacet_sharp_sample(ccl_private const ShaderClosure *sc,
|
||||
const int path_flag,
|
||||
float3 Ng,
|
||||
float3 wi,
|
||||
const float3 rand,
|
||||
ccl_private Spectrum *eval,
|
||||
ccl_private float3 *wo,
|
||||
ccl_private float *pdf,
|
||||
ccl_private float2 *sampled_roughness,
|
||||
ccl_private float *eta)
|
||||
{
|
||||
return bsdf_microfacet_sample<MicrofacetType::SHARP>(
|
||||
sc, path_flag, Ng, wi, rand, eval, wo, pdf, sampled_roughness, eta);
|
||||
}
|
||||
|
||||
CCL_NAMESPACE_END
|
||||
|
||||
@@ -224,6 +224,12 @@ ccl_device_inline void surface_shader_prepare_closures(KernelGlobals kg,
|
||||
bsdf_blur(kg, sc, blur_roughness);
|
||||
}
|
||||
}
|
||||
|
||||
/* NOTE: this is a sufficient condition. If `blur_roughness < THRESH < original_roughness`
|
||||
* then the flag was already set. */
|
||||
if (sqr(blur_roughness) > BSDF_ROUGHNESS_SQ_THRESH) {
|
||||
sd->flag |= SD_BSDF_HAS_EVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,8 +142,9 @@ ccl_device void osl_closure_reflection_setup(KernelGlobals kg,
|
||||
}
|
||||
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->alpha_x = bsdf->alpha_y = 0.0f;
|
||||
|
||||
sd->flag |= bsdf_reflection_setup(bsdf);
|
||||
sd->flag |= bsdf_microfacet_ggx_setup(bsdf);
|
||||
}
|
||||
|
||||
ccl_device void osl_closure_refraction_setup(KernelGlobals kg,
|
||||
@@ -164,8 +165,9 @@ ccl_device void osl_closure_refraction_setup(KernelGlobals kg,
|
||||
|
||||
bsdf->N = ensure_valid_specular_reflection(sd->Ng, sd->wi, closure->N);
|
||||
bsdf->ior = closure->ior;
|
||||
bsdf->alpha_x = bsdf->alpha_y = 0.0f;
|
||||
|
||||
sd->flag |= bsdf_refraction_setup(bsdf);
|
||||
sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
|
||||
}
|
||||
|
||||
ccl_device void osl_closure_transparent_setup(KernelGlobals kg,
|
||||
@@ -397,18 +399,6 @@ ccl_device void osl_closure_microfacet_setup(KernelGlobals kg,
|
||||
sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
|
||||
}
|
||||
}
|
||||
/* Sharp */
|
||||
else if (closure->distribution == make_string("sharp", 1870681295563127462ull)) {
|
||||
if (closure->refract == 1) {
|
||||
sd->flag |= bsdf_refraction_setup(bsdf);
|
||||
}
|
||||
else if (closure->refract == 2) {
|
||||
sd->flag |= bsdf_sharp_glass_setup(bsdf);
|
||||
}
|
||||
else {
|
||||
sd->flag |= bsdf_reflection_setup(bsdf);
|
||||
}
|
||||
}
|
||||
/* Ashikhmin-Shirley */
|
||||
else if (closure->distribution == make_string("ashikhmin_shirley", 11318482998918370922ull)) {
|
||||
sd->flag |= bsdf_ashikhmin_shirley_setup(bsdf);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "stdcycles.h"
|
||||
|
||||
shader node_glass_bsdf(color Color = 0.8,
|
||||
string distribution = "sharp",
|
||||
string distribution = "ggx",
|
||||
float Roughness = 0.2,
|
||||
float IOR = 1.45,
|
||||
normal Normal = N,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "stdcycles.h"
|
||||
|
||||
shader node_refraction_bsdf(color Color = 0.8,
|
||||
string distribution = "sharp",
|
||||
string distribution = "ggx",
|
||||
float Roughness = 0.2,
|
||||
float IOR = 1.45,
|
||||
normal Normal = N,
|
||||
|
||||
@@ -472,7 +472,6 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
||||
bsdf_transparent_setup(sd, weight, path_flag);
|
||||
break;
|
||||
}
|
||||
case CLOSURE_BSDF_REFLECTION_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_BECKMANN_ID:
|
||||
case CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID:
|
||||
@@ -521,10 +520,9 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
||||
}
|
||||
|
||||
/* setup bsdf */
|
||||
if (type == CLOSURE_BSDF_REFLECTION_ID)
|
||||
sd->flag |= bsdf_reflection_setup(bsdf);
|
||||
else if (type == CLOSURE_BSDF_MICROFACET_BECKMANN_ID)
|
||||
if (type == CLOSURE_BSDF_MICROFACET_BECKMANN_ID) {
|
||||
sd->flag |= bsdf_microfacet_beckmann_setup(bsdf);
|
||||
}
|
||||
else if (type == CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID) {
|
||||
sd->flag |= bsdf_ashikhmin_shirley_setup(bsdf);
|
||||
}
|
||||
@@ -539,7 +537,6 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
||||
|
||||
break;
|
||||
}
|
||||
case CLOSURE_BSDF_REFRACTION_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID: {
|
||||
#ifdef __CAUSTICS_TRICKS__
|
||||
@@ -558,29 +555,21 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
||||
eta = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
|
||||
|
||||
/* setup bsdf */
|
||||
if (type == CLOSURE_BSDF_REFRACTION_ID) {
|
||||
bsdf->alpha_x = 0.0f;
|
||||
bsdf->alpha_y = 0.0f;
|
||||
bsdf->ior = eta;
|
||||
float roughness = sqr(param1);
|
||||
bsdf->alpha_x = roughness;
|
||||
bsdf->alpha_y = roughness;
|
||||
bsdf->ior = eta;
|
||||
|
||||
sd->flag |= bsdf_refraction_setup(bsdf);
|
||||
if (type == CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID) {
|
||||
sd->flag |= bsdf_microfacet_beckmann_refraction_setup(bsdf);
|
||||
}
|
||||
else {
|
||||
float roughness = sqr(param1);
|
||||
bsdf->alpha_x = roughness;
|
||||
bsdf->alpha_y = roughness;
|
||||
bsdf->ior = eta;
|
||||
|
||||
if (type == CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID)
|
||||
sd->flag |= bsdf_microfacet_beckmann_refraction_setup(bsdf);
|
||||
else
|
||||
sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
|
||||
sd->flag |= bsdf_microfacet_ggx_refraction_setup(bsdf);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case CLOSURE_BSDF_SHARP_GLASS_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID:
|
||||
case CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID: {
|
||||
@@ -602,28 +591,20 @@ ccl_device_noinline int svm_node_closure_bsdf(KernelGlobals kg,
|
||||
eta = (sd->flag & SD_BACKFACING) ? 1.0f / eta : eta;
|
||||
|
||||
/* setup bsdf */
|
||||
if (type == CLOSURE_BSDF_SHARP_GLASS_ID) {
|
||||
bsdf->alpha_x = 0.0f;
|
||||
bsdf->alpha_y = 0.0f;
|
||||
bsdf->ior = eta;
|
||||
float roughness = sqr(param1);
|
||||
bsdf->alpha_x = roughness;
|
||||
bsdf->alpha_y = roughness;
|
||||
bsdf->ior = eta;
|
||||
|
||||
sd->flag |= bsdf_sharp_glass_setup(bsdf);
|
||||
if (type == CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID) {
|
||||
sd->flag |= bsdf_microfacet_beckmann_glass_setup(bsdf);
|
||||
}
|
||||
else {
|
||||
float roughness = sqr(param1);
|
||||
bsdf->alpha_x = roughness;
|
||||
bsdf->alpha_y = roughness;
|
||||
bsdf->ior = eta;
|
||||
|
||||
if (type == CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID)
|
||||
sd->flag |= bsdf_microfacet_beckmann_glass_setup(bsdf);
|
||||
else {
|
||||
sd->flag |= bsdf_microfacet_ggx_glass_setup(bsdf);
|
||||
if (type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID) {
|
||||
kernel_assert(stack_valid(data_node.z));
|
||||
const Spectrum color = rgb_to_spectrum(stack_load_float3(stack, data_node.z));
|
||||
bsdf_microfacet_setup_fresnel_constant(kg, bsdf, sd, color);
|
||||
}
|
||||
sd->flag |= bsdf_microfacet_ggx_glass_setup(bsdf);
|
||||
if (type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID) {
|
||||
kernel_assert(stack_valid(data_node.z));
|
||||
const Spectrum color = rgb_to_spectrum(stack_load_float3(stack, data_node.z));
|
||||
bsdf_microfacet_setup_fresnel_constant(kg, bsdf, sd, color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,7 +420,6 @@ typedef enum ClosureType {
|
||||
CLOSURE_BSDF_TRANSLUCENT_ID,
|
||||
|
||||
/* Glossy */
|
||||
CLOSURE_BSDF_REFLECTION_ID,
|
||||
CLOSURE_BSDF_MICROFACET_GGX_ID,
|
||||
CLOSURE_BSDF_MICROFACET_GGX_CLEARCOAT_ID,
|
||||
CLOSURE_BSDF_MICROFACET_BECKMANN_ID,
|
||||
@@ -432,14 +431,12 @@ typedef enum ClosureType {
|
||||
CLOSURE_BSDF_HAIR_REFLECTION_ID,
|
||||
|
||||
/* Transmission */
|
||||
CLOSURE_BSDF_REFRACTION_ID,
|
||||
CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID,
|
||||
CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID,
|
||||
CLOSURE_BSDF_HAIR_PRINCIPLED_ID,
|
||||
CLOSURE_BSDF_HAIR_TRANSMISSION_ID,
|
||||
|
||||
/* Glass */
|
||||
CLOSURE_BSDF_SHARP_GLASS_ID,
|
||||
CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID,
|
||||
CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID,
|
||||
CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID, /* virtual closure */
|
||||
@@ -470,21 +467,22 @@ typedef enum ClosureType {
|
||||
#define CLOSURE_IS_BSDF_DIFFUSE(type) \
|
||||
(type >= CLOSURE_BSDF_DIFFUSE_ID && type <= CLOSURE_BSDF_TRANSLUCENT_ID)
|
||||
#define CLOSURE_IS_BSDF_GLOSSY(type) \
|
||||
((type >= CLOSURE_BSDF_REFLECTION_ID && type <= CLOSURE_BSDF_HAIR_REFLECTION_ID) || \
|
||||
((type >= CLOSURE_BSDF_MICROFACET_GGX_ID && type <= CLOSURE_BSDF_HAIR_REFLECTION_ID) || \
|
||||
(type == CLOSURE_BSDF_HAIR_PRINCIPLED_ID))
|
||||
#define CLOSURE_IS_BSDF_TRANSMISSION(type) \
|
||||
(type >= CLOSURE_BSDF_REFRACTION_ID && type <= CLOSURE_BSDF_HAIR_TRANSMISSION_ID)
|
||||
#define CLOSURE_IS_BSDF_SINGULAR(type) \
|
||||
(type == CLOSURE_BSDF_REFLECTION_ID || type == CLOSURE_BSDF_REFRACTION_ID || \
|
||||
type == CLOSURE_BSDF_TRANSPARENT_ID || type == CLOSURE_BSDF_SHARP_GLASS_ID)
|
||||
(type >= CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID && \
|
||||
type <= CLOSURE_BSDF_HAIR_TRANSMISSION_ID)
|
||||
#define CLOSURE_IS_BSDF_SINGULAR(type) (type == CLOSURE_BSDF_TRANSPARENT_ID)
|
||||
#define CLOSURE_IS_BSDF_TRANSPARENT(type) (type == CLOSURE_BSDF_TRANSPARENT_ID)
|
||||
#define CLOSURE_IS_BSDF_MULTISCATTER(type) \
|
||||
(type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID || \
|
||||
type == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID)
|
||||
#define CLOSURE_IS_BSDF_MICROFACET(type) \
|
||||
((type >= CLOSURE_BSDF_REFLECTION_ID && type <= CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID) || \
|
||||
(type >= CLOSURE_BSDF_REFRACTION_ID && type <= CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID) || \
|
||||
(type >= CLOSURE_BSDF_SHARP_GLASS_ID && type <= CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID))
|
||||
((type >= CLOSURE_BSDF_MICROFACET_GGX_ID && type <= CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID) || \
|
||||
(type >= CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID && \
|
||||
type <= CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID) || \
|
||||
(type >= CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID && \
|
||||
type <= CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID))
|
||||
#define CLOSURE_IS_BSDF_OR_BSSRDF(type) (type <= CLOSURE_BSSRDF_RANDOM_WALK_FIXED_RADIUS_ID)
|
||||
#define CLOSURE_IS_BSSRDF(type) \
|
||||
(type >= CLOSURE_BSSRDF_BURLEY_ID && type <= CLOSURE_BSSRDF_RANDOM_WALK_FIXED_RADIUS_ID)
|
||||
@@ -495,11 +493,15 @@ typedef enum ClosureType {
|
||||
#define CLOSURE_IS_HOLDOUT(type) (type == CLOSURE_HOLDOUT_ID)
|
||||
#define CLOSURE_IS_PHASE(type) (type == CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID)
|
||||
#define CLOSURE_IS_REFRACTION(type) \
|
||||
(type >= CLOSURE_BSDF_REFRACTION_ID && type <= CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID)
|
||||
(type >= CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID && \
|
||||
type <= CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID)
|
||||
#define CLOSURE_IS_GLASS(type) \
|
||||
(type >= CLOSURE_BSDF_SHARP_GLASS_ID && type <= CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID)
|
||||
(type >= CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID && \
|
||||
type <= CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID)
|
||||
#define CLOSURE_IS_PRINCIPLED(type) (type == CLOSURE_BSDF_PRINCIPLED_ID)
|
||||
|
||||
#define CLOSURE_WEIGHT_CUTOFF 1e-5f
|
||||
/* Treat closure as singular if the squared roughness is below this threshold. */
|
||||
#define BSDF_ROUGHNESS_SQ_THRESH 5e-7f
|
||||
|
||||
CCL_NAMESPACE_END
|
||||
|
||||
@@ -324,15 +324,6 @@ void Integrator::tag_update(Scene *scene, uint32_t flag)
|
||||
tag_ao_bounces_modified();
|
||||
}
|
||||
|
||||
if (filter_glossy_is_modified()) {
|
||||
foreach (Shader *shader, scene->shaders) {
|
||||
if (shader->has_integrator_dependency) {
|
||||
scene->shader_manager->tag_update(scene, ShaderManager::INTEGRATOR_MODIFIED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (motion_blur_is_modified()) {
|
||||
scene->object_manager->tag_update(scene, ObjectManager::MOTION_BLUR_MODIFIED);
|
||||
scene->camera->tag_modified();
|
||||
|
||||
@@ -895,10 +895,6 @@ void OSLCompiler::add(ShaderNode *node, const char *name, bool isfilepath)
|
||||
if (node->has_attribute_dependency())
|
||||
current_shader->has_volume_attribute_dependency = true;
|
||||
}
|
||||
|
||||
if (node->has_integrator_dependency()) {
|
||||
current_shader->has_integrator_dependency = true;
|
||||
}
|
||||
}
|
||||
|
||||
static TypeDesc array_typedesc(TypeDesc typedesc, int arraylength)
|
||||
@@ -1259,10 +1255,7 @@ void OSLCompiler::compile(OSLGlobals *og, Shader *shader)
|
||||
output->input("Surface")->link && output->input("Displacement")->link;
|
||||
|
||||
/* finalize */
|
||||
shader->graph->finalize(scene,
|
||||
has_bump,
|
||||
shader->has_integrator_dependency,
|
||||
shader->get_displacement_method() == DISPLACE_BOTH);
|
||||
shader->graph->finalize(scene, has_bump, shader->get_displacement_method() == DISPLACE_BOTH);
|
||||
|
||||
current_shader = shader;
|
||||
|
||||
@@ -1277,7 +1270,6 @@ void OSLCompiler::compile(OSLGlobals *og, Shader *shader)
|
||||
shader->has_surface_spatial_varying = false;
|
||||
shader->has_volume_spatial_varying = false;
|
||||
shader->has_volume_attribute_dependency = false;
|
||||
shader->has_integrator_dependency = false;
|
||||
|
||||
/* generate surface shader */
|
||||
if (shader->reference_count() && graph && output->input("Surface")->link) {
|
||||
|
||||
@@ -103,7 +103,6 @@ Shader::Shader() : Node(get_node_type())
|
||||
has_surface_spatial_varying = false;
|
||||
has_volume_spatial_varying = false;
|
||||
has_volume_attribute_dependency = false;
|
||||
has_integrator_dependency = false;
|
||||
has_volume_connected = false;
|
||||
prev_volume_step_rate = 0.0f;
|
||||
|
||||
|
||||
@@ -113,7 +113,6 @@ class Shader : public Node {
|
||||
bool has_surface_spatial_varying;
|
||||
bool has_volume_spatial_varying;
|
||||
bool has_volume_attribute_dependency;
|
||||
bool has_integrator_dependency;
|
||||
|
||||
float3 emission_estimate;
|
||||
EmissionSampling emission_sampling;
|
||||
@@ -168,7 +167,6 @@ class ShaderManager {
|
||||
enum : uint32_t {
|
||||
SHADER_ADDED = (1 << 0),
|
||||
SHADER_MODIFIED = (1 << 2),
|
||||
INTEGRATOR_MODIFIED = (1 << 3),
|
||||
|
||||
/* tag everything in the manager for an update */
|
||||
UPDATE_ALL = ~0u,
|
||||
|
||||
@@ -359,7 +359,7 @@ void ShaderGraph::simplify(Scene *scene)
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderGraph::finalize(Scene *scene, bool do_bump, bool do_simplify, bool bump_in_object_space)
|
||||
void ShaderGraph::finalize(Scene *scene, bool do_bump, bool bump_in_object_space)
|
||||
{
|
||||
/* before compiling, the shader graph may undergo a number of modifications.
|
||||
* currently we set default geometry shader inputs, and create automatic bump
|
||||
@@ -384,9 +384,6 @@ void ShaderGraph::finalize(Scene *scene, bool do_bump, bool do_simplify, bool bu
|
||||
|
||||
finalized = true;
|
||||
}
|
||||
else if (do_simplify) {
|
||||
simplify_settings(scene);
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderGraph::find_dependencies(ShaderNodeSet &dependencies, ShaderInput *input)
|
||||
|
||||
@@ -200,10 +200,6 @@ class ShaderNode : public Node {
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool has_integrator_dependency()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
virtual bool has_volume_support()
|
||||
{
|
||||
return false;
|
||||
@@ -315,10 +311,7 @@ class ShaderGraph : public NodeOwner {
|
||||
void remove_proxy_nodes();
|
||||
void compute_displacement_hash();
|
||||
void simplify(Scene *scene);
|
||||
void finalize(Scene *scene,
|
||||
bool do_bump = false,
|
||||
bool do_simplify = false,
|
||||
bool bump_in_object_space = false);
|
||||
void finalize(Scene *scene, bool do_bump = false, bool bump_in_object_space = false);
|
||||
|
||||
int get_num_closures();
|
||||
|
||||
|
||||
@@ -2361,7 +2361,6 @@ NODE_DEFINE(GlossyBsdfNode)
|
||||
SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
|
||||
|
||||
static NodeEnum distribution_enum;
|
||||
distribution_enum.insert("sharp", CLOSURE_BSDF_REFLECTION_ID);
|
||||
distribution_enum.insert("beckmann", CLOSURE_BSDF_MICROFACET_BECKMANN_ID);
|
||||
distribution_enum.insert("ggx", CLOSURE_BSDF_MICROFACET_GGX_ID);
|
||||
distribution_enum.insert("ashikhmin_shirley", CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID);
|
||||
@@ -2382,7 +2381,6 @@ NODE_DEFINE(GlossyBsdfNode)
|
||||
GlossyBsdfNode::GlossyBsdfNode() : BsdfNode(get_node_type())
|
||||
{
|
||||
closure = CLOSURE_BSDF_MICROFACET_GGX_ID;
|
||||
distribution_orig = NBUILTIN_CLOSURES;
|
||||
}
|
||||
|
||||
bool GlossyBsdfNode::is_isotropic()
|
||||
@@ -2403,68 +2401,27 @@ void GlossyBsdfNode::attributes(Shader *shader, AttributeRequestSet *attributes)
|
||||
ShaderNode::attributes(shader, attributes);
|
||||
}
|
||||
|
||||
void GlossyBsdfNode::simplify_settings(Scene *scene)
|
||||
void GlossyBsdfNode::simplify_settings(Scene * /* scene */)
|
||||
{
|
||||
/* If the anisotropy is close enough to zero, fall back to the isotropic case. */
|
||||
ShaderInput *tangent_input = input("Tangent");
|
||||
if (tangent_input->link && is_isotropic()) {
|
||||
tangent_input->disconnect();
|
||||
}
|
||||
|
||||
if (distribution_orig == NBUILTIN_CLOSURES) {
|
||||
roughness_orig = roughness;
|
||||
distribution_orig = distribution;
|
||||
}
|
||||
else {
|
||||
/* By default we use original values, so we don't worry about restoring
|
||||
* defaults later one and can only do override when needed.
|
||||
*/
|
||||
roughness = roughness_orig;
|
||||
distribution = distribution_orig;
|
||||
}
|
||||
Integrator *integrator = scene->integrator;
|
||||
ShaderInput *roughness_input = input("Roughness");
|
||||
if (integrator->get_filter_glossy() == 0.0f) {
|
||||
/* Fallback to Sharp closure for Roughness close to 0.
|
||||
* NOTE: Keep the epsilon in sync with kernel!
|
||||
*/
|
||||
if (!roughness_input->link && roughness <= 1e-4f) {
|
||||
VLOG_DEBUG << "Using sharp glossy BSDF.";
|
||||
distribution = CLOSURE_BSDF_REFLECTION_ID;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* If filter glossy is used we replace Sharp glossy with GGX so we can
|
||||
* benefit from closure blur to remove unwanted noise.
|
||||
*/
|
||||
if (roughness_input->link == NULL && distribution == CLOSURE_BSDF_REFLECTION_ID) {
|
||||
VLOG_DEBUG << "Using GGX glossy with filter glossy.";
|
||||
distribution = CLOSURE_BSDF_MICROFACET_GGX_ID;
|
||||
roughness = 0.0f;
|
||||
}
|
||||
}
|
||||
closure = distribution;
|
||||
}
|
||||
|
||||
bool GlossyBsdfNode::has_integrator_dependency()
|
||||
{
|
||||
ShaderInput *roughness_input = input("Roughness");
|
||||
return !roughness_input->link &&
|
||||
(distribution == CLOSURE_BSDF_REFLECTION_ID || roughness <= 1e-4f);
|
||||
}
|
||||
|
||||
void GlossyBsdfNode::compile(SVMCompiler &compiler)
|
||||
{
|
||||
closure = distribution;
|
||||
|
||||
if (closure == CLOSURE_BSDF_REFLECTION_ID)
|
||||
BsdfNode::compile(compiler, NULL, NULL);
|
||||
/* TODO: Just use weight for legacy MultiGGX? Would also simplify OSL. */
|
||||
else if (closure == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID)
|
||||
if (closure == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID) {
|
||||
BsdfNode::compile(
|
||||
compiler, input("Roughness"), input("Anisotropy"), input("Rotation"), input("Color"));
|
||||
else
|
||||
}
|
||||
else {
|
||||
BsdfNode::compile(compiler, input("Roughness"), input("Anisotropy"), input("Rotation"));
|
||||
}
|
||||
}
|
||||
|
||||
void GlossyBsdfNode::compile(OSLCompiler &compiler)
|
||||
@@ -2484,7 +2441,6 @@ NODE_DEFINE(GlassBsdfNode)
|
||||
SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
|
||||
|
||||
static NodeEnum distribution_enum;
|
||||
distribution_enum.insert("sharp", CLOSURE_BSDF_SHARP_GLASS_ID);
|
||||
distribution_enum.insert("beckmann", CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID);
|
||||
distribution_enum.insert("ggx", CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID);
|
||||
distribution_enum.insert("multi_ggx", CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
|
||||
@@ -2500,64 +2456,19 @@ NODE_DEFINE(GlassBsdfNode)
|
||||
|
||||
GlassBsdfNode::GlassBsdfNode() : BsdfNode(get_node_type())
|
||||
{
|
||||
closure = CLOSURE_BSDF_SHARP_GLASS_ID;
|
||||
distribution_orig = NBUILTIN_CLOSURES;
|
||||
}
|
||||
|
||||
void GlassBsdfNode::simplify_settings(Scene *scene)
|
||||
{
|
||||
if (distribution_orig == NBUILTIN_CLOSURES) {
|
||||
roughness_orig = roughness;
|
||||
distribution_orig = distribution;
|
||||
}
|
||||
else {
|
||||
/* By default we use original values, so we don't worry about restoring
|
||||
* defaults later one and can only do override when needed.
|
||||
*/
|
||||
roughness = roughness_orig;
|
||||
distribution = distribution_orig;
|
||||
}
|
||||
Integrator *integrator = scene->integrator;
|
||||
ShaderInput *roughness_input = input("Roughness");
|
||||
if (integrator->get_filter_glossy() == 0.0f) {
|
||||
/* Fallback to Sharp closure for Roughness close to 0.
|
||||
* NOTE: Keep the epsilon in sync with kernel!
|
||||
*/
|
||||
if (!roughness_input->link && roughness <= 1e-4f) {
|
||||
VLOG_DEBUG << "Using sharp glass BSDF.";
|
||||
distribution = CLOSURE_BSDF_SHARP_GLASS_ID;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* If filter glossy is used we replace Sharp glossy with GGX so we can
|
||||
* benefit from closure blur to remove unwanted noise.
|
||||
*/
|
||||
if (roughness_input->link == NULL && distribution == CLOSURE_BSDF_SHARP_GLASS_ID) {
|
||||
VLOG_DEBUG << "Using GGX glass with filter glossy.";
|
||||
distribution = CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID;
|
||||
roughness = 0.0f;
|
||||
}
|
||||
}
|
||||
closure = distribution;
|
||||
}
|
||||
|
||||
bool GlassBsdfNode::has_integrator_dependency()
|
||||
{
|
||||
ShaderInput *roughness_input = input("Roughness");
|
||||
return !roughness_input->link &&
|
||||
(distribution == CLOSURE_BSDF_SHARP_GLASS_ID || roughness <= 1e-4f);
|
||||
closure = CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID;
|
||||
}
|
||||
|
||||
void GlassBsdfNode::compile(SVMCompiler &compiler)
|
||||
{
|
||||
closure = distribution;
|
||||
|
||||
if (closure == CLOSURE_BSDF_SHARP_GLASS_ID)
|
||||
BsdfNode::compile(compiler, NULL, input("IOR"));
|
||||
else if (closure == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID)
|
||||
if (closure == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID) {
|
||||
BsdfNode::compile(compiler, input("Roughness"), input("IOR"), input("Color"));
|
||||
else
|
||||
}
|
||||
else {
|
||||
BsdfNode::compile(compiler, input("Roughness"), input("IOR"));
|
||||
}
|
||||
}
|
||||
|
||||
void GlassBsdfNode::compile(OSLCompiler &compiler)
|
||||
@@ -2577,7 +2488,6 @@ NODE_DEFINE(RefractionBsdfNode)
|
||||
SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
|
||||
|
||||
static NodeEnum distribution_enum;
|
||||
distribution_enum.insert("sharp", CLOSURE_BSDF_REFRACTION_ID);
|
||||
distribution_enum.insert("beckmann", CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID);
|
||||
distribution_enum.insert("ggx", CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID);
|
||||
SOCKET_ENUM(
|
||||
@@ -2593,62 +2503,14 @@ NODE_DEFINE(RefractionBsdfNode)
|
||||
|
||||
RefractionBsdfNode::RefractionBsdfNode() : BsdfNode(get_node_type())
|
||||
{
|
||||
closure = CLOSURE_BSDF_REFRACTION_ID;
|
||||
distribution_orig = NBUILTIN_CLOSURES;
|
||||
}
|
||||
|
||||
void RefractionBsdfNode::simplify_settings(Scene *scene)
|
||||
{
|
||||
if (distribution_orig == NBUILTIN_CLOSURES) {
|
||||
roughness_orig = roughness;
|
||||
distribution_orig = distribution;
|
||||
}
|
||||
else {
|
||||
/* By default we use original values, so we don't worry about restoring
|
||||
* defaults later one and can only do override when needed.
|
||||
*/
|
||||
roughness = roughness_orig;
|
||||
distribution = distribution_orig;
|
||||
}
|
||||
Integrator *integrator = scene->integrator;
|
||||
ShaderInput *roughness_input = input("Roughness");
|
||||
if (integrator->get_filter_glossy() == 0.0f) {
|
||||
/* Fallback to Sharp closure for Roughness close to 0.
|
||||
* NOTE: Keep the epsilon in sync with kernel!
|
||||
*/
|
||||
if (!roughness_input->link && roughness <= 1e-4f) {
|
||||
VLOG_DEBUG << "Using sharp refraction BSDF.";
|
||||
distribution = CLOSURE_BSDF_REFRACTION_ID;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* If filter glossy is used we replace Sharp glossy with GGX so we can
|
||||
* benefit from closure blur to remove unwanted noise.
|
||||
*/
|
||||
if (roughness_input->link == NULL && distribution == CLOSURE_BSDF_REFRACTION_ID) {
|
||||
VLOG_DEBUG << "Using GGX refraction with filter glossy.";
|
||||
distribution = CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID;
|
||||
roughness = 0.0f;
|
||||
}
|
||||
}
|
||||
closure = distribution;
|
||||
}
|
||||
|
||||
bool RefractionBsdfNode::has_integrator_dependency()
|
||||
{
|
||||
ShaderInput *roughness_input = input("Roughness");
|
||||
return !roughness_input->link &&
|
||||
(distribution == CLOSURE_BSDF_REFRACTION_ID || roughness <= 1e-4f);
|
||||
closure = CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID;
|
||||
}
|
||||
|
||||
void RefractionBsdfNode::compile(SVMCompiler &compiler)
|
||||
{
|
||||
closure = distribution;
|
||||
|
||||
if (closure == CLOSURE_BSDF_REFRACTION_ID)
|
||||
BsdfNode::compile(compiler, NULL, input("IOR"));
|
||||
else
|
||||
BsdfNode::compile(compiler, input("Roughness"), input("IOR"));
|
||||
BsdfNode::compile(compiler, input("Roughness"), input("IOR"));
|
||||
}
|
||||
|
||||
void RefractionBsdfNode::compile(OSLCompiler &compiler)
|
||||
@@ -2816,7 +2678,6 @@ PrincipledBsdfNode::PrincipledBsdfNode() : BsdfBaseNode(get_node_type())
|
||||
{
|
||||
closure = CLOSURE_BSDF_PRINCIPLED_ID;
|
||||
distribution = CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID;
|
||||
distribution_orig = NBUILTIN_CLOSURES;
|
||||
}
|
||||
|
||||
void PrincipledBsdfNode::expand(ShaderGraph *graph)
|
||||
@@ -2987,12 +2848,6 @@ void PrincipledBsdfNode::compile(SVMCompiler &compiler,
|
||||
__float_as_int(ss_default.z));
|
||||
}
|
||||
|
||||
bool PrincipledBsdfNode::has_integrator_dependency()
|
||||
{
|
||||
ShaderInput *roughness_input = input("Roughness");
|
||||
return !roughness_input->link && roughness <= 1e-4f;
|
||||
}
|
||||
|
||||
void PrincipledBsdfNode::compile(SVMCompiler &compiler)
|
||||
{
|
||||
compile(compiler,
|
||||
|
||||
@@ -563,11 +563,7 @@ class PrincipledBsdfNode : public BsdfBaseNode {
|
||||
NODE_SOCKET_API(float, emission_strength)
|
||||
NODE_SOCKET_API(float, alpha)
|
||||
|
||||
private:
|
||||
ClosureType distribution_orig;
|
||||
|
||||
public:
|
||||
bool has_integrator_dependency();
|
||||
void attributes(Shader *shader, AttributeRequestSet *attributes);
|
||||
bool has_attribute_dependency()
|
||||
{
|
||||
@@ -602,7 +598,6 @@ class GlossyBsdfNode : public BsdfNode {
|
||||
SHADER_NODE_CLASS(GlossyBsdfNode)
|
||||
|
||||
void simplify_settings(Scene *scene);
|
||||
bool has_integrator_dependency();
|
||||
ClosureType get_closure_type()
|
||||
{
|
||||
return distribution;
|
||||
@@ -620,10 +615,6 @@ class GlossyBsdfNode : public BsdfNode {
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
float roughness_orig;
|
||||
ClosureType distribution_orig;
|
||||
|
||||
bool is_isotropic();
|
||||
};
|
||||
|
||||
@@ -631,8 +622,6 @@ class GlassBsdfNode : public BsdfNode {
|
||||
public:
|
||||
SHADER_NODE_CLASS(GlassBsdfNode)
|
||||
|
||||
void simplify_settings(Scene *scene);
|
||||
bool has_integrator_dependency();
|
||||
ClosureType get_closure_type()
|
||||
{
|
||||
return distribution;
|
||||
@@ -641,18 +630,12 @@ class GlassBsdfNode : public BsdfNode {
|
||||
NODE_SOCKET_API(float, roughness)
|
||||
NODE_SOCKET_API(float, IOR)
|
||||
NODE_SOCKET_API(ClosureType, distribution)
|
||||
|
||||
private:
|
||||
float roughness_orig;
|
||||
ClosureType distribution_orig;
|
||||
};
|
||||
|
||||
class RefractionBsdfNode : public BsdfNode {
|
||||
public:
|
||||
SHADER_NODE_CLASS(RefractionBsdfNode)
|
||||
|
||||
void simplify_settings(Scene *scene);
|
||||
bool has_integrator_dependency();
|
||||
ClosureType get_closure_type()
|
||||
{
|
||||
return distribution;
|
||||
@@ -661,10 +644,6 @@ class RefractionBsdfNode : public BsdfNode {
|
||||
NODE_SOCKET_API(float, roughness)
|
||||
NODE_SOCKET_API(float, IOR)
|
||||
NODE_SOCKET_API(ClosureType, distribution)
|
||||
|
||||
private:
|
||||
float roughness_orig;
|
||||
ClosureType distribution_orig;
|
||||
};
|
||||
|
||||
class ToonBsdfNode : public BsdfNode {
|
||||
|
||||
@@ -442,10 +442,6 @@ void SVMCompiler::generate_node(ShaderNode *node, ShaderNodeSet &done)
|
||||
if (node->has_attribute_dependency())
|
||||
current_shader->has_volume_attribute_dependency = true;
|
||||
}
|
||||
|
||||
if (node->has_integrator_dependency()) {
|
||||
current_shader->has_integrator_dependency = true;
|
||||
}
|
||||
}
|
||||
|
||||
void SVMCompiler::generate_svm_nodes(const ShaderNodeSet &nodes, CompilerState *state)
|
||||
@@ -858,10 +854,7 @@ void SVMCompiler::compile(Shader *shader, array<int4> &svm_nodes, int index, Sum
|
||||
/* finalize */
|
||||
{
|
||||
scoped_timer timer((summary != NULL) ? &summary->time_finalize : NULL);
|
||||
shader->graph->finalize(scene,
|
||||
has_bump,
|
||||
shader->has_integrator_dependency,
|
||||
shader->get_displacement_method() == DISPLACE_BOTH);
|
||||
shader->graph->finalize(scene, has_bump, shader->get_displacement_method() == DISPLACE_BOTH);
|
||||
}
|
||||
|
||||
current_shader = shader;
|
||||
@@ -877,7 +870,6 @@ void SVMCompiler::compile(Shader *shader, array<int4> &svm_nodes, int index, Sum
|
||||
shader->has_surface_spatial_varying = false;
|
||||
shader->has_volume_spatial_varying = false;
|
||||
shader->has_volume_attribute_dependency = false;
|
||||
shader->has_integrator_dependency = false;
|
||||
|
||||
/* generate bump shader */
|
||||
if (has_bump) {
|
||||
|
||||
Reference in New Issue
Block a user