forked from Maxon-Computer/Redshift-OSL-Shaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TooledSteel.osl
105 lines (97 loc) · 2.6 KB
/
TooledSteel.osl
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
//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 Layer
vector 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));
}