/* * * Wavelength dependent subsurface scattering OSL material by Derek Flood (cc)2016 * Inspired by the hypershade tree by Tony Reynolds, with added double-lobe spec and mappable glossiness. * from http://docs.sharktacos.com/vray/osl.html * */ color getTextureDif(string texture_name, color no_texture_default_color) { int channels = -1; if (gettextureinfo(texture_name, "channels", channels)) { return texture(texture_name, u, v); } return no_texture_default_color; } float fresnelReflectionFactor(normal Nb, float ior) { float c = abs(dot(I, Nb)); float g = ior * ior - 1.0 + c * c; if (g > 0.0) { g = sqrt (g); float A = (g - c) / (g + c); float B = (c * (g + c) - 1.0) / (c * (g - c) + 1.0); return 0.5 * A * A * (1.0 + B * B); } return 1.0; } float blendGloss(float GlossMin, float GlossMax, color Blender) { Blender = luminance(Blender); return GlossMin * (1.0 - Blender[0]) + GlossMax * Blender[0]; } surface DFskinMtl [[ string description = "blended skin material" ]] ( /* Global Section */ string Transparency = "trs.png", float Depth_Scale = 1, float Overall_Brightness = 0.8, color Diffuse_Color = 0.5, float Diffuse_Amount = 0.5, /* SSS Section */ string Subsurface_Color = "color.png", float Subsurface_Amount = 1, string RGB_Scatter_Depth = "RGB.png" [[ string description = "Proportional scatter depth for red, green, and blue wavelengths." ]], float Texture_Gamma = 2.2, /* Spec section */ string Spec_color = "specular.png", string Gloss_Mask = "mask.png" [[ string description = "black and white mask for glossiness min/max values." ]], float Spec_total_amount = 0.5 [[ string description = "Total amount of sharp and soft spec." ]], float Sharp_Amount = 0.3 [[ string description = "For the sharp spec lobe." ]], float Bloom_Amount = 0.7 [[ string description = "For the soft spec lobe." ]], float Gloss_Min = 0.6 [[ string description = "Glossiness value for the black parts of the Gloss Mask map." ]], float Gloss_Max = 0.8 [[ string description = "Glossiness value for the white parts of the Gloss Mask map." ]], float Spec_bloom = 0.3 [[ string description = "For the soft spec lobe (Blinn). Controls tail size of spec." ]], float Reflection_IOR = 1.5, int Reflection_Subdivs = 8, int Trace_Sharp_Reflections = 1 [[ string widget = "checkBox" ]], int Trace_Bloom_Reflections = 1 [[ string widget = "checkBox" ]], int Use_Single_SSS = 0 [[ string widget = "checkBox" ]], output color result = 1 ) { /* Define Bump */ normal Nb = N; /* Declare sss variables and read texture map */ color TrsColor = getTextureDif(Transparency, color(0)); color Opacity = 1-TrsColor; color Depth = getTextureDif(RGB_Scatter_Depth, color(0.8,0.2,0.1)); Depth = clamp(Depth,0.001,1); // Prevent depth values from being zero which breaks the shader RGB mix color SubColor = getTextureDif(Subsurface_Color, color(0.85,0.75,0.65)); SubColor = pow(SubColor, Texture_Gamma); //gamma correct texture SubColor *= Overall_Brightness; color SubR = SubColor * color(1,0,0); color SubG = SubColor * color(0,1,0); color SubB = SubColor * color(0,0,1); /* Define spec */ float IOR = 1.38; float PhaseFunction = 0.8; int Subdivs = 8; color SpecColor = getTextureDif(Spec_color, color(1,1,1)); color GlossMask = getTextureDif(Gloss_Mask, color(1)); float Spec_sharpness = blendGloss(Gloss_Min, Gloss_Max, GlossMask); color Fresnel = SpecColor * fresnelReflectionFactor(Nb, Reflection_IOR); //fresnel for Blinn float SoftGloss = (1-Spec_bloom * 0.6) * Spec_sharpness; //modify spec sharpness with inverted bloom at 60% float Tail = 2.0; float Roughness = 0; float Anisotropy = 0; float Aniso_rotation = 0; /* Closures */ closure color Diff = Diffuse_Color * Diffuse_Amount * Overall_Brightness * diffuse(Nb, "roughness", 0); closure color SSS = vray_subsurface ( IOR, PhaseFunction, Depth * Depth_Scale * 0.5, SubColor * Subsurface_Amount, "subdivs", Subdivs); closure color SkinR = vray_subsurface ( IOR, PhaseFunction, SubR * Depth[0] * Depth_Scale, SubR * Subsurface_Amount, "subdivs", Subdivs); closure color SkinGB = vray_subsurface ( IOR, PhaseFunction, ((SubG * Depth[1]) + (SubB * Depth[2])) * Depth_Scale, (SubG + SubB) * Subsurface_Amount, "subdivs", Subdivs); closure color spcHard = Sharp_Amount * SpecColor * Spec_total_amount * 0.5 * microfacet_ggx (Nb, Roughness, Reflection_IOR, "gtr_gamma", Tail, "subdivs", Reflection_Subdivs, "reflection_glossiness", Spec_sharpness, "highlight_glossiness", Spec_sharpness, "trace_reflections", Trace_Sharp_Reflections ); closure color spcSoft = Bloom_Amount * Fresnel * Spec_total_amount * 2 * vray_blinn (Nb, SoftGloss, Anisotropy, Aniso_rotation, "subdivs", Reflection_Subdivs, "trace_reflections", Trace_Bloom_Reflections); if (Use_Single_SSS) { Ci = Opacity * Diff + SSS + spcHard + spcSoft + (1.0 - Opacity) * transparent(); } else { Ci = Opacity * Diff + SkinR + SkinGB + spcHard + spcSoft + (1.0 - Opacity) * transparent(); } }