
//Tooled Steel by Ivan DeWolf// Modified 4/27/21 by Saul Espinosa for Redshift3d// Added ACES output, min/max and page meta data and Coating Microfacet GGX Closure Layervector nearPtLine( point testLoc, point lineStart, point lineEnd){ float lineMag = distance(lineStart, lineEnd); float U = dot(testLoc-lineStart, lineEnd - lineStart) / (lineMag * lineMag); return lineStart + U * (lineEnd - lineStart);}shader tooldSteel[[ string help = "Machine Tooled Material Shader", string label = "Machine Tooled Steel" ]]( color metal_color = color(0.9,0.8,0.7) [[ string page = "0 : Metal", string label = "Metal Color" ]], float xalph = 1 [[ string page = "0 : Metal", string label = "Anisotropy Roughness x", float min = 0, float max = 1 ]], float yalph = .1 [[ string page = "0 : Metal", string label = "Anisotropy Roughness y", float min = 0, float max = 1 ]], float IOR = 15 [[ string page = "0 : Metal", float min = 1, float max = 25 ]], float cellmult = 10 [[ string page = "0 : Metal", string label = "Scale", float min = 0, float max = 100 ]], color coat_color = color(1.0) [[string label = "Coat Color", string page = "1 : Coat", ]], float coat_weight = 0.0 [[string label = "Coat Weight" , string page = "1 : Coat", float min = 0, float max = 1 ]], float coat_roughness = 0.0 [[string label = "Coat Roughness" , string page = "1 : Coat", float min = 0, float max = 1 ]], float coat_IOR = 1.52 [[string label = "Coat IOR" , string page = "1 : Coat", float min = 0, float max = 25 ]], int aces = 0 [[ string page = "2 : Extra", string widget = "checkBox", int connectable = 0, string label = "ACES" ]], output closure color outColor = 0.0){ // ACES sRGB Transform matrix aces_tm = matrix( 0.6131, 0.0701, 0.0206, 0, 0.3395, 0.9164, 0.1096, 0, 0.0474, 0.0135, 0.8698, 0, 0, 0, 0, 1); color Out = metal_color; float r = Out[0], g = Out[1], b = Out[2]; if (aces == 0) color attenColor = Out; else { attenColor = transform(aces_tm, vector(r,g,b)); } vector Normal = N; point Ploc = P; vector centerLoc = round(Ploc * cellmult)/cellmult; vector spinCenter = nearPtLine(Ploc, centerLoc+Normal, centerLoc -Normal); vector anisoDir = normalize(spinCenter-Ploc); outColor = attenColor * microfacet("ggx", Normal, anisoDir, xalph, yalph, IOR, 0) + (coat_color * coat_weight * microfacet("ggx",Normal,coat_roughness,coat_IOR,0));}