/* * Copyright 2011-2013 Blender Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "stdosl.h" #include "node_fresnel.h" shader node_disney_bsdf( color BaseColor = color(0.64555527, 0.41514809, 0.01698805), color SubsurfaceColor = color(0.64555527, 0.41514809, 0.01698805), float Metallic = 0.0, float Subsurface = 0.0, float Specular = 0.5, float Roughness = 0.5, float SpecularTint = 0.0, float Anisotropic = 0.0, float Sheen = 0.0, float SheenTint = 0.5, float Clearcoat = 0.0, 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), //normal AnisotropicRotation = normal(0, 0, 0), output closure color BSDF = 0) { float f = max(IOR, 1e-5); float eta = backfacing() ? 1.0 / f : f; 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); 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)) * diffuse_weight; } if (Specular != 0.0 || Metallic != 0.0) { BSDF = BSDF + specular_weight * disney_specular(Normal, Tangent, BaseColor, Metallic, Specular, SpecularTint, Roughness, Anisotropic) + (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) { BSDF = BSDF + disney_clearcoat(ClearcoatNormal, Clearcoat, ClearcoatGloss); } }