From 7613ffc944ebc133f1f906ea737ab55718434cc4 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sat, 10 Mar 2018 16:09:22 +0100 Subject: Cycles: switch to squared roughness convention for all nodes. This was already done for the Principled BSDF to be compatible with typical baked roughness maps in PBR workflows. --- .../cycles/kernel/shaders/node_anisotropic_bsdf.osl | 19 ++++++++++--------- intern/cycles/kernel/shaders/node_glass_bsdf.osl | 11 ++++++----- intern/cycles/kernel/shaders/node_glossy_bsdf.osl | 10 ++++++---- .../cycles/kernel/shaders/node_refraction_bsdf.osl | 5 +++-- intern/cycles/kernel/svm/svm_closure.h | 20 ++++++++++++-------- 5 files changed, 37 insertions(+), 28 deletions(-) (limited to 'intern/cycles/kernel') diff --git a/intern/cycles/kernel/shaders/node_anisotropic_bsdf.osl b/intern/cycles/kernel/shaders/node_anisotropic_bsdf.osl index bef6d7e8809..21e28ece65d 100644 --- a/intern/cycles/kernel/shaders/node_anisotropic_bsdf.osl +++ b/intern/cycles/kernel/shaders/node_anisotropic_bsdf.osl @@ -33,27 +33,28 @@ shader node_anisotropic_bsdf( T = rotate(T, Rotation * M_2PI, point(0.0, 0.0, 0.0), Normal); /* compute roughness */ - float RoughnessU, RoughnessV; + float roughness = Roughness * Roughness; + float roughness_u, roughness_v; float aniso = clamp(Anisotropy, -0.99, 0.99); if (aniso < 0.0) { - RoughnessU = Roughness / (1.0 + aniso); - RoughnessV = Roughness * (1.0 + aniso); + roughness_u = roughness / (1.0 + aniso); + roughness_v = roughness * (1.0 + aniso); } else { - RoughnessU = Roughness * (1.0 - aniso); - RoughnessV = Roughness / (1.0 - aniso); + roughness_u = roughness * (1.0 - aniso); + roughness_v = roughness / (1.0 - aniso); } if (distribution == "sharp") BSDF = Color * reflection(Normal); else if (distribution == "beckmann") - BSDF = Color * microfacet_beckmann_aniso(Normal, T, RoughnessU, RoughnessV); + BSDF = Color * microfacet_beckmann_aniso(Normal, T, roughness_u, roughness_v); else if (distribution == "GGX") - BSDF = Color * microfacet_ggx_aniso(Normal, T, RoughnessU, RoughnessV); + BSDF = Color * microfacet_ggx_aniso(Normal, T, roughness_u, roughness_v); else if (distribution == "Multiscatter GGX") - BSDF = Color * microfacet_multi_ggx_aniso(Normal, T, RoughnessU, RoughnessV, Color); + BSDF = Color * microfacet_multi_ggx_aniso(Normal, T, roughness_u, roughness_v, Color); else - BSDF = Color * ashikhmin_shirley(Normal, T, RoughnessU, RoughnessV); + BSDF = Color * ashikhmin_shirley(Normal, T, roughness_u, roughness_v); } diff --git a/intern/cycles/kernel/shaders/node_glass_bsdf.osl b/intern/cycles/kernel/shaders/node_glass_bsdf.osl index a9723a8300a..2e713861c58 100644 --- a/intern/cycles/kernel/shaders/node_glass_bsdf.osl +++ b/intern/cycles/kernel/shaders/node_glass_bsdf.osl @@ -29,16 +29,17 @@ shader node_glass_bsdf( float eta = backfacing() ? 1.0 / f : f; float cosi = dot(I, Normal); float Fr = fresnel_dielectric_cos(cosi, eta); + float roughness = Roughness * Roughness; if (distribution == "sharp") BSDF = Color * (Fr * reflection(Normal) + (1.0 - Fr) * refraction(Normal, eta)); else if (distribution == "beckmann") - BSDF = Color * (Fr * microfacet_beckmann(Normal, Roughness) + - (1.0 - Fr) * microfacet_beckmann_refraction(Normal, Roughness, eta)); + BSDF = Color * (Fr * microfacet_beckmann(Normal, roughness) + + (1.0 - Fr) * microfacet_beckmann_refraction(Normal, roughness, eta)); else if (distribution == "Multiscatter GGX") - BSDF = Color * microfacet_multi_ggx_glass(Normal, Roughness, eta, Color); + BSDF = Color * microfacet_multi_ggx_glass(Normal, roughness, eta, Color); else if (distribution == "GGX") - BSDF = Color * (Fr * microfacet_ggx(Normal, Roughness) + - (1.0 - Fr) * microfacet_ggx_refraction(Normal, Roughness, eta)); + BSDF = Color * (Fr * microfacet_ggx(Normal, roughness) + + (1.0 - Fr) * microfacet_ggx_refraction(Normal, roughness, eta)); } diff --git a/intern/cycles/kernel/shaders/node_glossy_bsdf.osl b/intern/cycles/kernel/shaders/node_glossy_bsdf.osl index f4ea7e7dc6a..7415211b56d 100644 --- a/intern/cycles/kernel/shaders/node_glossy_bsdf.osl +++ b/intern/cycles/kernel/shaders/node_glossy_bsdf.osl @@ -24,16 +24,18 @@ shader node_glossy_bsdf( normal Normal = N, output closure color BSDF = 0) { + float roughness = Roughness * Roughness; + if (distribution == "sharp") BSDF = Color * reflection(Normal); else if (distribution == "beckmann") - BSDF = Color * microfacet_beckmann(Normal, Roughness); + BSDF = Color * microfacet_beckmann(Normal, roughness); else if (distribution == "GGX") - BSDF = Color * microfacet_ggx(Normal, Roughness); + BSDF = Color * microfacet_ggx(Normal, roughness); else if (distribution == "Multiscatter GGX") - BSDF = Color * microfacet_multi_ggx(Normal, Roughness, Color); + BSDF = Color * microfacet_multi_ggx(Normal, roughness, Color); else - BSDF = Color * ashikhmin_shirley(Normal, vector(0, 0, 0), Roughness, Roughness); + BSDF = Color * ashikhmin_shirley(Normal, vector(0, 0, 0), roughness, roughness); } diff --git a/intern/cycles/kernel/shaders/node_refraction_bsdf.osl b/intern/cycles/kernel/shaders/node_refraction_bsdf.osl index 828becf1818..eaab7282243 100644 --- a/intern/cycles/kernel/shaders/node_refraction_bsdf.osl +++ b/intern/cycles/kernel/shaders/node_refraction_bsdf.osl @@ -26,12 +26,13 @@ shader node_refraction_bsdf( { float f = max(IOR, 1e-5); float eta = backfacing() ? 1.0 / f : f; + float roughness = Roughness * Roughness; if (distribution == "sharp") BSDF = Color * refraction(Normal, eta); else if (distribution == "beckmann") - BSDF = Color * microfacet_beckmann_refraction(Normal, Roughness, eta); + BSDF = Color * microfacet_beckmann_refraction(Normal, roughness, eta); else if (distribution == "GGX") - BSDF = Color * microfacet_ggx_refraction(Normal, Roughness, eta); + BSDF = Color * microfacet_ggx_refraction(Normal, roughness, eta); } diff --git a/intern/cycles/kernel/svm/svm_closure.h b/intern/cycles/kernel/svm/svm_closure.h index a54095ed127..886a1333fa3 100644 --- a/intern/cycles/kernel/svm/svm_closure.h +++ b/intern/cycles/kernel/svm/svm_closure.h @@ -468,10 +468,12 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float * break; } + float roughness = sqr(param1); + bsdf->N = N; bsdf->T = make_float3(0.0f, 0.0f, 0.0f); - bsdf->alpha_x = param1; - bsdf->alpha_y = param1; + bsdf->alpha_x = roughness; + bsdf->alpha_y = roughness; bsdf->ior = 0.0f; bsdf->extra = NULL; @@ -525,8 +527,9 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float * sd->flag |= bsdf_refraction_setup(bsdf); } else { - bsdf->alpha_x = param1; - bsdf->alpha_y = param1; + float roughness = sqr(param1); + bsdf->alpha_x = roughness; + bsdf->alpha_y = roughness; bsdf->ior = eta; if(type == CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID) @@ -557,7 +560,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float * /* fresnel */ float cosNO = dot(N, sd->I); float fresnel = fresnel_dielectric_cos(cosNO, eta); - float roughness = param1; + float roughness = sqr(param1); /* reflection */ #ifdef __CAUSTICS_TRICKS__ @@ -611,8 +614,9 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float * bsdf->extra = extra; bsdf->T = make_float3(0.0f, 0.0f, 0.0f); - bsdf->alpha_x = param1; - bsdf->alpha_y = param1; + float roughness = sqr(param1); + bsdf->alpha_x = roughness; + bsdf->alpha_y = roughness; float eta = fmaxf(param2, 1e-5f); bsdf->ior = (sd->flag & SD_BACKFACING)? 1.0f/eta: eta; @@ -648,7 +652,7 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float * bsdf->T = rotate_around_axis(bsdf->T, bsdf->N, rotation * M_2PI_F); /* compute roughness */ - float roughness = param1; + float roughness = sqr(param1); float anisotropy = clamp(param2, -0.99f, 0.99f); if(anisotropy < 0.0f) { -- cgit v1.2.3