MarbleShader - 图1

    1. /*
    2. * VeinedMarble.osl by Shane Ambler
    3. * from https://github.com/sambler/osl-shaders
    4. *
    5. * original script from -
    6. * http://www.renderman.org/RMR/RMRShaders.html
    7. *
    8. * veinedmarble.sl -- surface shader for a nice veined marble.
    9. *
    10. * DESCRIPTION:
    11. * Makes solid marble texture with strong veins. The "veincolor" parameter
    12. * controls the color of the veins. The background color is given by the
    13. * surface color (Cs).
    14. *
    15. * PARAMETERS:
    16. * Ka, Kd, Ks, roughness, specularcolor - same as plastic
    17. * veinfreq - controls fhe lowest frequency of the color veins
    18. * veinlevels - how many "levels" of vein tendrills it has
    19. * warpfreq - lowest frequency of the turbulent warping in the marble
    20. * warping - controls how much turbulent warping there will be
    21. * veincolor - the color of the veins
    22. * sharpness - controls how sharp or fuzzy the veins are (higher = sharper)
    23. *
    24. *
    25. * AUTHOR: Larry Gritz, the George Washington University
    26. * email: gritz AT seas DOT gwu DOT edu
    27. * This file is licensed under Apache 2.0 license
    28. * HISTORY:
    29. *
    30. * last modified 29 Jun 1994 by Larry Gritz
    31. * 2012-12-19 converted to blender osl shader by Shane Ambler
    32. * 2020-4-27 converted to a Redshift Shader by Saul Espinosa, added coating Microfact GGX & Oren Nayer closure,
    33. * new defaults, min/max values, label and page metadata.
    34. * 2022-03-08 Added World, Object space controls for the Noise
    35. */
    36. shader VeinedMarble
    37. [[ string help = "Marble Closure Based Material",
    38. string label = "Marble" ]]
    39. (
    40. // Input Paramaters
    41. color diffuse_color = color(0.946,0.788,0.829)
    42. [[
    43. string label = "Diffuse Color",
    44. string page = "Diffuse"
    45. ]],
    46. float diffuse_weight = 0.8
    47. [[
    48. string label = "Diffuse Weight" ,
    49. string page = "Diffuse",
    50. float min = 0, float max = 1
    51. ]],
    52. float diffuse_rough = 0.0
    53. [[
    54. string label = "Diffuse Roughness" ,
    55. string page = "Diffuse",
    56. float min = 0, float max = 1
    57. ]],
    58. color SpecularColor = color(1.0)
    59. [[
    60. string page = "Specular",
    61. string label = "Specular Color"
    62. ]],
    63. float SpecularWeight = 1.0
    64. [[
    65. string label = "Specular Weight" ,
    66. string page = "Specular",
    67. float min = 0, float max = 1
    68. ]],
    69. float Roughness = 0.4
    70. [[
    71. string label = "Roughness" ,
    72. string page = "Specular",
    73. float min = 0, float max = 1
    74. ]],
    75. float IOR = 1.48
    76. [[
    77. string label = "IOR",
    78. string page = "Specular",
    79. float min = 0, float max = 25
    80. ]],
    81. color coat_color = color(1.0)
    82. [[
    83. string label = "Coat Color",
    84. string page = "Coat",
    85. ]],
    86. float coat_weight = 1.0
    87. [[
    88. string label = "Coat Weight" ,
    89. string page = "Coat",
    90. float min = 0, float max = 1
    91. ]],
    92. float coat_roughness = 0.005
    93. [[
    94. string label = "Coat Roughness" ,
    95. string page = "Coat",
    96. float min = 0, float max = 1
    97. ]],
    98. float coat_IOR = 1.52
    99. [[
    100. string label = "Coat IOR" ,
    101. string page = "Coat",
    102. float min = 0, float max = 25
    103. ]],
    104. color VeinColor = color(0.663, 0.319, 0.371)
    105. [[
    106. string label = "Vein Color",
    107. string page = "Marble Vein"
    108. ]],
    109. float VeinFreq = 1.0
    110. [[
    111. string label = "Vein Frequency" ,
    112. string page = "Marble Vein",
    113. float min = 0, float max = 10
    114. ]],
    115. float VeinLevels = 2.0
    116. [[
    117. string label = "Vein Levels" ,
    118. string page = "Marble Vein",
    119. float min = 0, float max = 25
    120. ]],
    121. float WarpFreq = 1.0
    122. [[
    123. string label = "Warp Frequency" ,
    124. string page = "Marble Vein",
    125. float min = 0, float max = 25
    126. ]],
    127. float Warping = 0.5
    128. [[
    129. string label = "Vein Warping" ,
    130. string page = "Marble Vein",
    131. float min = 0, float max = 25
    132. ]],
    133. float Sharpness = 8.0
    134. [[
    135. string label = "Vein Sharpness" ,
    136. string page = "Marble Vein",
    137. float min = 0, float max = 25
    138. ]],
    139. int Space = 1
    140. [[
    141. string page = "Co-ordinates",
    142. string widget = "mapper",
    143. string options = "World:0|Object:1|Fixed:2",
    144. int connectable = 0
    145. ]],
    146. vector Origin = 0
    147. [[
    148. string page = "Co-ordinates"
    149. ]],
    150. // Output Closure
    151. output closure color outColor = diffuse(N) )
    152. {
    153. #define snoise(x) (2*noise(x)-1)
    154. color Ct;
    155. point Nf;
    156. point PP, offset;
    157. float i, turb, freq, j;
    158. float turbsum;
    159. if (Space == 0)
    160. PP = P + Origin;
    161. else if (Space == 1)
    162. PP = transform("object", P) + Origin;
    163. else
    164. PP = Origin;
    165. /* perturb the lookup */
    166. freq = 1;
    167. offset = 0;
    168. for (i = 0; i < 6; i += 1) {
    169. offset += 2 * Warping * ( noise (WarpFreq * freq * PP) - 0.5) / freq;
    170. freq *= 2;
    171. }
    172. PP += offset;
    173. /* Now calculate the veining function for the lookup area */
    174. turbsum = 0; freq = 1;
    175. PP *= VeinFreq;
    176. for (i = 0; i < VeinLevels; i += 1) {
    177. turb = abs (snoise (PP));
    178. turb = pow (smoothstep (0.8, 1, 1 - turb), Sharpness) / freq;
    179. turbsum += (1-turbsum) * turb;
    180. freq *= 3;
    181. PP *= 3;
    182. }
    183. color Out = mix (diffuse_color, VeinColor, turbsum);
    184. Nf = normalize(N);
    185. outColor = Out * diffuse_weight * oren_nayar(Nf, diffuse_rough);
    186. outColor += (SpecularColor * SpecularWeight * microfacet("ggx",Nf,Roughness,IOR,0)) + (coat_color * coat_weight * microfacet("ggx",Nf,coat_roughness,coat_IOR,0));
    187. }