TooledSteel - 图1

    1. //Tooled Steel by Ivan DeWolf
    2. // Modified 4/27/21 by Saul Espinosa for Redshift3d
    3. // Added ACES output, min/max and page meta data and Coating Microfacet GGX Closure Layer
    4. vector nearPtLine(
    5. point testLoc,
    6. point lineStart,
    7. point lineEnd)
    8. {
    9. float lineMag = distance(lineStart, lineEnd);
    10. float U = dot(testLoc-lineStart, lineEnd - lineStart) / (lineMag * lineMag);
    11. return lineStart + U * (lineEnd - lineStart);
    12. }
    13. shader tooldSteel
    14. [[ string help = "Machine Tooled Material Shader",
    15. string label = "Machine Tooled Steel" ]]
    16. (
    17. color metal_color = color(0.9,0.8,0.7)
    18. [[
    19. string page = "0 : Metal",
    20. string label = "Metal Color"
    21. ]],
    22. float xalph = 1
    23. [[
    24. string page = "0 : Metal",
    25. string label = "Anisotropy Roughness x",
    26. float min = 0,
    27. float max = 1
    28. ]],
    29. float yalph = .1
    30. [[
    31. string page = "0 : Metal",
    32. string label = "Anisotropy Roughness y",
    33. float min = 0,
    34. float max = 1
    35. ]],
    36. float IOR = 15
    37. [[
    38. string page = "0 : Metal",
    39. float min = 1,
    40. float max = 25
    41. ]],
    42. float cellmult = 10
    43. [[
    44. string page = "0 : Metal",
    45. string label = "Scale",
    46. float min = 0,
    47. float max = 100
    48. ]],
    49. color coat_color = color(1.0)
    50. [[string label = "Coat Color",
    51. string page = "1 : Coat",
    52. ]],
    53. float coat_weight = 0.0
    54. [[string label = "Coat Weight" ,
    55. string page = "1 : Coat",
    56. float min = 0, float max = 1
    57. ]],
    58. float coat_roughness = 0.0
    59. [[string label = "Coat Roughness" ,
    60. string page = "1 : Coat",
    61. float min = 0, float max = 1
    62. ]],
    63. float coat_IOR = 1.52
    64. [[string label = "Coat IOR" ,
    65. string page = "1 : Coat",
    66. float min = 0, float max = 25
    67. ]],
    68. int aces = 0
    69. [[
    70. string page = "2 : Extra",
    71. string widget = "checkBox",
    72. int connectable = 0,
    73. string label = "ACES"
    74. ]],
    75. output closure color outColor = 0.0)
    76. {
    77. // ACES sRGB Transform
    78. matrix aces_tm = matrix(
    79. 0.6131, 0.0701, 0.0206, 0,
    80. 0.3395, 0.9164, 0.1096, 0,
    81. 0.0474, 0.0135, 0.8698, 0,
    82. 0, 0, 0, 1);
    83. color Out = metal_color;
    84. float r = Out[0], g = Out[1], b = Out[2];
    85. if (aces == 0)
    86. color attenColor = Out;
    87. else
    88. {
    89. attenColor = transform(aces_tm, vector(r,g,b));
    90. }
    91. vector Normal = N;
    92. point Ploc = P;
    93. vector centerLoc = round(Ploc * cellmult)/cellmult;
    94. vector spinCenter = nearPtLine(Ploc, centerLoc+Normal, centerLoc -Normal);
    95. vector anisoDir = normalize(spinCenter-Ploc);
    96. outColor = attenColor * microfacet("ggx", Normal, anisoDir, xalph, yalph, IOR, 0) + (coat_color * coat_weight * microfacet("ggx",Normal,coat_roughness,coat_IOR,0));
    97. }