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