ok I'll try right after lunch and I'll let you know

/* * * Wavelenghth dependant subsurface scattering OSL shader by Derek Flood (c)2016 * based on a shader tree by Tony Reynolds * from http://docs.sharktacos.com/misc.php?action=help&hid=66 * */ 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; } color getTextureBump(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; } normal getBumpedBump(color centerColor, color uColor, color vColor, float inverseBumpAmount) { vector worldTangent = normalize(dPdu); vector worldBitangent = normalize(dPdv); vector worldNormal = normalize(N); vector average = vector(0.3333333); float center = dot (average, vector(centerColor)); float ddu = center - dot(average, vector(uColor)); float ddv = center - dot(average, vector(vColor)); return normalize(ddu * worldTangent + ddv * worldBitangent + inverseBumpAmount * worldNormal); } normal getBumpedNormal(color compressedNormalSample, float Bump_amount) { vector worldTangent = normalize(dPdu); vector worldBitangent = normalize(dPdv); vector worldNormal = normalize(N); color normalSample = 2.0 * compressedNormalSample - 1.0; normalSample *= color(Bump_amount, Bump_amount, 1.0); return normalize(normalSample[0] * worldTangent + normalSample[1] * worldBitangent + normalSample[2] * worldNormal); } surface DFskinMtl [[ string description = "Wavelenghth dependant subsurface scattering material" ]] ( //float Depth_Scale = 1, string Depth_Scale = "depth.png", float Overall_Color_Mult = 1, //string Opacity = "opacity.png", color Diffuse_Color = color(0.6,0.6,0.6), float Diffuse_Amount = 0.8, string Subsurface_Color = "color.png", color RGB_Scatter_Depth = color(1,0.4,0.1), float Subsurface_Amount = 1, float ior = 1.38, float Phase_Function = 0.8, int Subdivs = 8, float Texture_Gamma = 2.2, /* Bump section */ string Bump_Map = "normal.png", float Bump_amount = 1.0, int Normal_Mapping = 0 [[ string widget = "checkBox" ]], output color result = 1 ) { /* Define Bump */ normal bumped_normal = N; if ( Normal_Mapping == 1 ) { //color compressedNormalSample = getTextureBump(Bump_Map, color(0.5,0.5,1)); color compressedNormalSample = texture (Bump_Map, u, v, "missingcolor", color(0.5,0.5,1)); bumped_normal = getBumpedNormal(compressedNormalSample, Bump_amount); } else { float delta = 0.004; color center = texture(Bump_Map, u, v); color uColor = texture(Bump_Map, u + delta, v); color vColor = texture(Bump_Map, u, v + delta); float Bump_amount = Bump_amount * 10; bumped_normal = getBumpedBump(center, uColor, vColor, 1.0 / Bump_amount); } /* declare variables and read texture map */ color Red = color(1,0,0); color Green = color(0,1,0); color Blue = color(0,0,1); color RGB_Depth = RGB_Scatter_Depth; RGB_Depth[0] = clamp(RGB_Scatter_Depth[0],0.001,1); RGB_Depth[1] = clamp(RGB_Scatter_Depth[1],0.001,1); RGB_Depth[2] = clamp(RGB_Scatter_Depth[2],0.001,1); //color Map = getTextureDif(Subsurface_Color, color(0.85,0.75,0.65)); color Map = texture (Subsurface_Color, u, v, "missingcolor", color(0.85,0.75,0.65)); color DepthScale = texture (Depth_Scale, u, v, "missingcolor", color(1,1,1)); Map = pow(Map, Texture_Gamma); color SubsurfaceColor = Map * Subsurface_Amount * Overall_Color_Mult; color DifCol = pow(Diffuse_Color,Texture_Gamma); // color for lambertian diffuse (single scatter) /* Closures */ closure color diffuse_component = Overall_Color_Mult * Diffuse_Amount * DifCol * diffuse(bumped_normal); closure color SkinR = vray_subsurface ( ior, Phase_Function, SubsurfaceColor * Red * RGB_Depth[0] * DepthScale, SubsurfaceColor * Red, "subdivs", Subdivs); closure color SkinG = vray_subsurface ( ior, Phase_Function, SubsurfaceColor * Green * RGB_Depth[1] * DepthScale, SubsurfaceColor * Green, "subdivs", Subdivs); closure color SkinB = vray_subsurface ( ior, Phase_Function, SubsurfaceColor * Blue * RGB_Depth[2] * DepthScale, SubsurfaceColor * Blue, "subdivs", Subdivs); Ci = SkinR + SkinG + SkinB; Ci += diffuse_component; }
float getTextureFloat(string texture_name, float no_texture_default_value, float value_scale, float value_center_offset) { int channels = -1; if (gettextureinfo(texture_name, "channels", channels)) { color texture_sample = texture(texture_name, u, v); float sample_value = dot(vector(texture_sample), vector(0.3333333)); float result = value_scale * sample_value + value_center_offset; return result; } return no_texture_default_value; } color getTextureColor(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 bumped_normal, float ior) { float c = fabs(dot(I, bumped_normal)); 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; } normal getBumpNormal(string normal_map_texture, float bump_amount) { int channels = -1; if (gettextureinfo(normal_map_texture, "channels", channels)) { color texture_sample = texture(normal_map_texture, u, v); texture_sample *= 2.0; texture_sample -= 1.0; texture_sample[0] *= bump_amount; texture_sample[1] *= bump_amount; return normalize(normal("shader", texture_sample[0], texture_sample[1], texture_sample[2])); } return N; } surface cook_torrance_material ( /* Diffuse section */ color diffuse_color = 0.75, string diffuse_color_texture = "diffuse_color_texture.bmp", float roughness = 0.0, string roughness_texture = "roughness_texture.bmp", /* Reflection section */ color reflection_color = 0.16, string reflection_color_texture = "reflection_color_texture.bmp", float reflection_glossiness = 0.7, string reflection_glossiness_texture = "reflection_glossiness_texture.bmp", int lock_highlight_glossiness = 1 [[ string widget = "checkBox" ]], float highlight_glossiness = 0.7, string highlight_glossiness_texture = "highlight_glossiness_texture.bmp", int fresnel_reflections = 0 [[ string widget = "checkBox" ]], float fresnel_ior = 3.0, int subdivs = 8, /* BRDF section */ float anisotropy = 0.0, string anisotropy_texture = "anisotropy_texture.bmp", float aniso_rotation = 0.0, string aniso_rotation_texture = "aniso_rotation_texture.bmp", float soften_edge = 0.0, /* Options section */ int trace_reflections = 0 [[ string widget = "checkBox" ]], /* Maps section */ float bump_amount = 0.0, string bump_texture = "bump_texture.bmp", color opacity_color = 1.0, string opacity_color_texture = "opacity_color_texture.bmp" ) { normal bumped_normal = N; if (bump_amount > 0.0) { bumped_normal = getBumpNormal(bump_texture, bump_amount); } color diffuse_color_result = getTextureColor(diffuse_color_texture, diffuse_color); float roughness_result = getTextureFloat(roughness_texture, roughness, 1.0, 0.0); color reflection_color_result = getTextureColor(reflection_color_texture, reflection_color); if (fresnel_reflections) { reflection_color_result *= fresnelReflectionFactor(bumped_normal, fresnel_ior); } if (trace_reflections) { diffuse_color_result *= (1.0 - reflection_color_result); } Ci = diffuse_color_result * orennayar(bumped_normal, roughness_result); float reflection_glossiness_result = getTextureFloat(reflection_glossiness_texture, reflection_glossiness, 1.0, 0.0); float highlight_glossiness_result = reflection_glossiness_result; if (!lock_highlight_glossiness) { highlight_glossiness_result = getTextureFloat(highlight_glossiness_texture, highlight_glossiness, 1.0, 0.0); } float anisotropy_result = getTextureFloat(anisotropy_texture, anisotropy, 1.0, 0.0); anisotropy_result = clamp(anisotropy_result, 0.0, 0.99); float aniso_rotation_result = getTextureFloat(aniso_rotation_texture, aniso_rotation, 360.0, -180.0); Ci += reflection_color_result * vray_cooktorrance(bumped_normal, highlight_glossiness_result, "anisotropy", anisotropy_result, "aniso_rotation", aniso_rotation_result, "reflection_glossiness", reflection_glossiness_result, "soften_edge", soften_edge, "subdivs", subdivs, "trace_reflections", trace_reflections); color opacity_result = getTextureColor(opacity_color_texture, opacity_color); if (luminance(opacity_result) < 0.99) { Ci *= opacity_result; Ci += (1.0 - opacity_result) * transparent(); } }
surface Lambert ( string diffuse_texture = "diffuse.png", float diffuse_weight = 0.5, ) { color diffuseColor = texture(diffuse_texture, u, v); Ci = diffuse_weight * diffuseColor * diffuse(N) ; }
Comment