diff options
author | Pascal Schoen <pascal_schoen@gmx.net> | 2016-07-20 12:13:00 +0300 |
---|---|---|
committer | Pascal Schoen <pascal_schoen@gmx.net> | 2016-07-20 12:13:00 +0300 |
commit | dbad91ca6d46f5a4a6f2ba7ed4c811ffa723942f (patch) | |
tree | f676f1f8a635781d480871283a93eb1206831e90 /intern/cycles/kernel/shaders | |
parent | 50ea5e3e34394a727e3cceb6203adb48834a9ab7 (diff) |
Added a roughness parameter for refractions (for scattering of the rays
within an object)
With this, one can create a translucent material with a smooth surface and
with a milky look.
The final refraction roughness has to be calculated using the surface
roughness and the refraction roughness because those two are correlated
for refractions. If a ray hits a rough surface of a translucent material,
it is scattered while entering the surface. Then it is scattered further
within the object. The calculation I'm using is the following:
RefrRoughnessFinal = 1.0 - (1.0 - Roughness) * (1.0 - RefrRoughness)
Diffstat (limited to 'intern/cycles/kernel/shaders')
-rw-r--r-- | intern/cycles/kernel/shaders/node_disney_bsdf.osl | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/intern/cycles/kernel/shaders/node_disney_bsdf.osl b/intern/cycles/kernel/shaders/node_disney_bsdf.osl index b6312c61002..b608b734546 100644 --- a/intern/cycles/kernel/shaders/node_disney_bsdf.osl +++ b/intern/cycles/kernel/shaders/node_disney_bsdf.osl @@ -31,6 +31,7 @@ shader node_disney_bsdf( float ClearcoatGloss = 1.0, float IOR = 1.45, float Transparency = 0.0, + float RefractionRoughness = 0.0, normal Normal = N, normal ClearcoatNormal = N, normal Tangent = normalize(dPdu), @@ -39,23 +40,27 @@ shader node_disney_bsdf( { float f = max(IOR, 1e-5); float eta = backfacing() ? 1.0 / f : f; - float cosi = dot(I, Normal); - float Fr = fresnel_dielectric_cos(cosi, eta); - float trans = clamp(Transparency, 0.0, 1.0); - float metal = clamp(Metallic, 0.0, 1.0); - float specWeight = mix(1.0, Fr, mix(trans, 0.0, metal)); + float cosNO = dot(Normal, I); + float Fr = fresnel_dielectric_cos(cosNO, eta); + float diffuse_weight = (1.0 - clamp(Metallic, 0.0, 1.0)) * (1.0 - clamp(Transparency, 0.0, 1.0)); + float transp = clamp(Transparency, 0.0, 1.0) * (1.0 - clamp(Metallic, 0.0, 1.0)); + float specular_weight = (1.0 - transp); - if (metal < 1.0) { + float refr_roughness = 1.0 - (1.0 - Roughness) * (1.0 - RefractionRoughness); + + if (diffuse_weight > 0.0) { BSDF = (((Subsurface * BaseColor * bssrdf_burley(Normal, vector(1.0, 1.0, 1.0), 0.0, BaseColor)) + disney_diffuse(Normal, BaseColor, Roughness) * (1.0 - Subsurface)) - + disney_sheen(Normal, BaseColor, Sheen, SheenTint)) * (1.0 - metal) * (1.0 - trans); + + disney_sheen(Normal, BaseColor, Sheen, SheenTint)) * diffuse_weight; } if (Specular != 0.0 || Metallic != 0.0) { - BSDF = BSDF + specWeight * disney_specular(Normal, Tangent, BaseColor, Metallic, Specular, + BSDF = BSDF + specular_weight * disney_specular(Normal, Tangent, BaseColor, Metallic, Specular, SpecularTint, Roughness, Anisotropic) - + (1.0 - specWeight) * BaseColor * microfacet_ggx_refraction(Normal, Roughness * Roughness, eta); - } else if (trans > 0.0) { - BSDF = BSDF + trans * microfacet_ggx_refraction(Normal, Roughness * Roughness, eta); + + (1.0 - specular_weight) * (Fr * disney_specular(Normal, Tangent, BaseColor, 0.0, 12.5, + SpecularTint, Roughness, 0.0) + (1.0 - Fr) * BaseColor * microfacet_ggx_refraction(Normal, refr_roughness * refr_roughness, eta)); + } else if (transp > 0.0) { + BSDF = BSDF + transp * (disney_specular(Normal, Tangent, BaseColor, 0.0, 12.5, SpecularTint, Roughness, 0.0) + + BaseColor * microfacet_ggx_refraction(Normal, refr_roughness * refr_roughness, eta)); } if (Clearcoat != 0.0) { |