diff options
author | L. E. Segovia <leonardo.segovia@cs.uns.edu.ar> | 2018-07-24 19:13:17 +0300 |
---|---|---|
committer | L. E. Segovia <leonardo.segovia@cs.uns.edu.ar> | 2018-07-24 19:13:17 +0300 |
commit | 52a0e67fe0050683a888d6643ec2035bd2b3ea1c (patch) | |
tree | 91c57739e4920562c77e2ce912691a920babcc55 | |
parent | ec640510a8c8ef5de8daea907da2351ef1988915 (diff) |
Fix Filter Glossy handling
Previously, Filter Glossy was applied to the logistic distribution's
parameters. This wasn't noticeable unless one traced bsdf_blur.
Now, bsdf->v, s and m0_roughness are only used within the shader; the
corresponding (roughness) parameters are roughness, radial_roughness and
coat.
-rw-r--r-- | intern/cycles/kernel/closure/bsdf_hair_principled.h | 59 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/osl_closures.cpp | 10 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_closure.h | 10 | ||||
m--------- | release/scripts/addons | 0 | ||||
m--------- | release/scripts/addons_contrib | 0 | ||||
m--------- | source/tools | 0 |
6 files changed, 47 insertions, 32 deletions
diff --git a/intern/cycles/kernel/closure/bsdf_hair_principled.h b/intern/cycles/kernel/closure/bsdf_hair_principled.h index 4ee58089384..6907b5e7f08 100644 --- a/intern/cycles/kernel/closure/bsdf_hair_principled.h +++ b/intern/cycles/kernel/closure/bsdf_hair_principled.h @@ -26,6 +26,10 @@ CCL_NAMESPACE_BEGIN typedef ccl_addr_space struct PrincipledHairExtra { + /* Cuticle tilt angle. */ + float alpha; + /* IOR. */ + float eta; /* Geometry data. */ float4 geom; } PrincipledHairExtra; @@ -35,14 +39,18 @@ typedef ccl_addr_space struct PrincipledHairBSDF { /* Absorption coefficient. */ float3 sigma; + + /* Roughness. */ + float roughness; + /* Radial roughness. */ + float radial_roughness; + /* Percentage of the roughness to be applied for the diffuse bounce only. */ + float coat; + /* Variance of the underlying logistic distribution. */ float v; /* Scale factor of the underlying logistic distribution. */ float s; - /* Cuticle tilt angle. */ - float alpha; - /* IOR. */ - float eta; /* Effective variance for the diffuse bounce only. */ float m0_roughness; @@ -194,14 +202,14 @@ ccl_device_inline float4 combine_with_energy(KernelGlobals *kg, float3 c) ccl_device int bsdf_principled_hair_setup(ShaderData *sd, PrincipledHairBSDF *bsdf) { bsdf->type = CLOSURE_BSDF_HAIR_PRINCIPLED_ID; - bsdf->v = clamp(bsdf->v, 0.001f, 1.0f); - bsdf->s = clamp(bsdf->s, 0.001f, 1.0f); + bsdf->roughness = clamp(bsdf->roughness, 0.01f, 1.0f); + bsdf->radial_roughness = clamp(bsdf->radial_roughness, 0.01f, 1.0f); /* Apply Primary Reflection Roughness modifier. */ - bsdf->m0_roughness = clamp(bsdf->m0_roughness*bsdf->v, 0.001f, 1.0f); + bsdf->m0_roughness = clamp(bsdf->coat*bsdf->roughness, 0.01f, 1.0f); /* Map from roughness_u and roughness_v to variance and scale factor. */ - bsdf->v = sqr(0.726f*bsdf->v + 0.812f*sqr(bsdf->v) + 3.700f*pow20(bsdf->v)); - bsdf->s = (0.265f*bsdf->s + 1.194f*sqr(bsdf->s) + 5.372f*pow22(bsdf->s))*M_SQRT_PI_8_F; + bsdf->v = sqr(0.726f*bsdf->roughness + 0.812f*sqr(bsdf->roughness) + 3.700f*pow20(bsdf->roughness)); + bsdf->s = (0.265f*bsdf->radial_roughness + 1.194f*sqr(bsdf->radial_roughness) + 5.372f*pow22(bsdf->radial_roughness))*M_SQRT_PI_8_F; bsdf->m0_roughness = sqr(0.726f*bsdf->m0_roughness + 0.812f*sqr(bsdf->m0_roughness) + 3.700f*pow20(bsdf->m0_roughness)); /* Compute local frame, aligned to curve tangent and ray direction. */ @@ -306,20 +314,20 @@ ccl_device float3 bsdf_principled_hair_eval(KernelGlobals *kg, float cos_theta_o = cos_from_sin(sin_theta_o); float phi_o = atan2f(wo.z, wo.y); - float sin_theta_t = sin_theta_o / bsdf->eta; + float sin_theta_t = sin_theta_o / bsdf->extra->eta; float cos_theta_t = cos_from_sin(sin_theta_t); float sin_gamma_o = bsdf->extra->geom.w; float cos_gamma_o = cos_from_sin(sin_gamma_o); float gamma_o = safe_asinf(sin_gamma_o); - float sin_gamma_t = sin_gamma_o * cos_theta_o / sqrtf(sqr(bsdf->eta) - sqr(sin_theta_o)); + float sin_gamma_t = sin_gamma_o * cos_theta_o / sqrtf(sqr(bsdf->extra->eta) - sqr(sin_theta_o)); float cos_gamma_t = cos_from_sin(sin_gamma_t); float gamma_t = safe_asinf(sin_gamma_t); float3 T = exp3(-bsdf->sigma * (2.0f * cos_gamma_t / cos_theta_t)); float4 Ap[4]; - hair_attenuation(kg, fresnel_dielectric_cos(cos_theta_o * cos_gamma_o, bsdf->eta), T, Ap); + hair_attenuation(kg, fresnel_dielectric_cos(cos_theta_o * cos_gamma_o, bsdf->extra->eta), T, Ap); float sin_theta_i = wi.x; float cos_theta_i = cos_from_sin(sin_theta_i); @@ -328,7 +336,7 @@ ccl_device float3 bsdf_principled_hair_eval(KernelGlobals *kg, float phi = phi_i - phi_o; float angles[6]; - hair_alpha_angles(sin_theta_i, cos_theta_i, bsdf->alpha, angles); + hair_alpha_angles(sin_theta_i, cos_theta_i, bsdf->extra->alpha, angles); float4 F; float Mp, Np; @@ -392,20 +400,20 @@ ccl_device int bsdf_principled_hair_sample(KernelGlobals *kg, float cos_theta_o = cos_from_sin(sin_theta_o); float phi_o = atan2f(wo.z, wo.y); - float sin_theta_t = sin_theta_o / bsdf->eta; + float sin_theta_t = sin_theta_o / bsdf->extra->eta; float cos_theta_t = cos_from_sin(sin_theta_t); float sin_gamma_o = bsdf->extra->geom.w; float cos_gamma_o = cos_from_sin(sin_gamma_o); float gamma_o = safe_asinf(sin_gamma_o); - float sin_gamma_t = sin_gamma_o * cos_theta_o / sqrtf(sqr(bsdf->eta) - sqr(sin_theta_o)); + float sin_gamma_t = sin_gamma_o * cos_theta_o / sqrtf(sqr(bsdf->extra->eta) - sqr(sin_theta_o)); float cos_gamma_t = cos_from_sin(sin_gamma_t); float gamma_t = safe_asinf(sin_gamma_t); float3 T = exp3(-bsdf->sigma * (2.0f * cos_gamma_t / cos_theta_t)); float4 Ap[4]; - hair_attenuation(kg, fresnel_dielectric_cos(cos_theta_o * cos_gamma_o, bsdf->eta), T, Ap); + hair_attenuation(kg, fresnel_dielectric_cos(cos_theta_o * cos_gamma_o, bsdf->extra->eta), T, Ap); int p = 0; for(; p < 3; p++) { @@ -430,7 +438,7 @@ ccl_device int bsdf_principled_hair_sample(KernelGlobals *kg, float angles[6]; if(p < 3) { - hair_alpha_angles(sin_theta_i, cos_theta_i, -bsdf->alpha, angles); + hair_alpha_angles(sin_theta_i, cos_theta_i, -bsdf->extra->alpha, angles); sin_theta_i = angles[2*p]; cos_theta_i = angles[2*p+1]; } @@ -444,7 +452,7 @@ ccl_device int bsdf_principled_hair_sample(KernelGlobals *kg, } float phi_i = phi_o + phi; - hair_alpha_angles(sin_theta_i, cos_theta_i, bsdf->alpha, angles); + hair_alpha_angles(sin_theta_i, cos_theta_i, bsdf->extra->alpha, angles); float4 F; float Mp, Np; @@ -487,14 +495,21 @@ ccl_device int bsdf_principled_hair_sample(KernelGlobals *kg, return LABEL_GLOSSY|((p == 0)? LABEL_REFLECT : LABEL_TRANSMIT); } -/* Implements Filter Glossy by capping the effective roughness. */ +/* Implements Filter Glossy by increasing and then remapping the roughness. */ ccl_device void bsdf_principled_hair_blur(ShaderClosure *sc, float roughness) { PrincipledHairBSDF *bsdf = (PrincipledHairBSDF*)sc; - bsdf->v = fmaxf(roughness, bsdf->v); - bsdf->s = fmaxf(roughness, bsdf->s); - bsdf->m0_roughness = fmaxf(roughness, bsdf->m0_roughness); + bsdf->roughness = fmaxf(roughness, bsdf->roughness); + bsdf->radial_roughness = fmaxf(roughness, bsdf->radial_roughness); + + /* Apply Primary Reflection Roughness modifier. */ + bsdf->m0_roughness = clamp(bsdf->coat*bsdf->roughness, 0.01f, 1.0f); + + /* Map (again) from roughness_u and roughness_v to variance and scale factor. */ + bsdf->v = sqr(0.726f*bsdf->roughness + 0.812f*sqr(bsdf->roughness) + 3.700f*pow20(bsdf->roughness)); + bsdf->s = (0.265f*bsdf->radial_roughness + 1.194f*sqr(bsdf->radial_roughness) + 5.372f*pow22(bsdf->radial_roughness))*M_SQRT_PI_8_F; + bsdf->m0_roughness = sqr(0.726f*bsdf->m0_roughness + 0.812f*sqr(bsdf->m0_roughness) + 3.700f*pow20(bsdf->m0_roughness)); } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/osl/osl_closures.cpp b/intern/cycles/kernel/osl/osl_closures.cpp index 8c7ae30725c..20a4a3ac607 100644 --- a/intern/cycles/kernel/osl/osl_closures.cpp +++ b/intern/cycles/kernel/osl/osl_closures.cpp @@ -218,11 +218,11 @@ static ClosureParam *closure_bsdf_principled_hair_params() static ClosureParam params[] = { CLOSURE_FLOAT3_PARAM(PrincipledHairClosure, params.N), CLOSURE_FLOAT3_PARAM(PrincipledHairClosure, params.sigma), - CLOSURE_FLOAT_PARAM(PrincipledHairClosure, params.v), - CLOSURE_FLOAT_PARAM(PrincipledHairClosure, params.s), - CLOSURE_FLOAT_PARAM(PrincipledHairClosure, params.m0_roughness), - CLOSURE_FLOAT_PARAM(PrincipledHairClosure, params.alpha), - CLOSURE_FLOAT_PARAM(PrincipledHairClosure, params.eta), + CLOSURE_FLOAT_PARAM(PrincipledHairClosure, params.roughness), + CLOSURE_FLOAT_PARAM(PrincipledHairClosure, params.radial_roughness), + CLOSURE_FLOAT_PARAM(PrincipledHairClosure, params.coat), + CLOSURE_FLOAT_PARAM(PrincipledHairClosure, params.extra->alpha), + CLOSURE_FLOAT_PARAM(PrincipledHairClosure, params.extra->eta), CLOSURE_STRING_KEYPARAM(PrincipledHairClosure, label, "label"), CLOSURE_FINISH_PARAM(PrincipledHairClosure) }; diff --git a/intern/cycles/kernel/svm/svm_closure.h b/intern/cycles/kernel/svm/svm_closure.h index aa253223c93..6b2910df67a 100644 --- a/intern/cycles/kernel/svm/svm_closure.h +++ b/intern/cycles/kernel/svm/svm_closure.h @@ -783,12 +783,12 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float * float m0_roughness = 1.0f - clamp(coat, 0.0f, 1.0f); bsdf->N = N; - bsdf->v = roughness; - bsdf->s = radial_roughness; - bsdf->m0_roughness = m0_roughness; - bsdf->alpha = alpha; - bsdf->eta = ior; + bsdf->roughness = roughness; + bsdf->radial_roughness = radial_roughness; + bsdf->coat = m0_roughness; bsdf->extra = extra; + bsdf->extra->alpha = alpha; + bsdf->extra->eta = ior; switch(parametrization) { case NODE_PRINCIPLED_HAIR_DIRECT_ABSORPTION: { diff --git a/release/scripts/addons b/release/scripts/addons -Subproject 9ae033c49c1b16718eac6306bdc271a5e6e6bf3 +Subproject c87ee4d46f16d60a2e1db7514c8d5ab42c5d93d diff --git a/release/scripts/addons_contrib b/release/scripts/addons_contrib -Subproject f178e6c933a25c621a5cc7d92935b66cd2ec2f5 +Subproject 15b25a42783d1e516b5298d70b582fae2559ae1 diff --git a/source/tools b/source/tools -Subproject 87f7038ee8c4b46a5e73a1a9065e2a9b7367f59 +Subproject 8ebcf630fcd0131674d69cbf3ae30101bc3c8b6 |