-
Notifications
You must be signed in to change notification settings - Fork 43
/
MelaninColor.osl
44 lines (37 loc) · 1.48 KB
/
MelaninColor.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
// Melanin Color Generator OSL node based on Weta's Melanin research paper.
// This was made for Redshift 3D, by Saul Espinosa v.2.1
// Modified : 3/15/2021 - Added ACEScg Output Support
// outColor should be input into the Transmission, Internal Reflection inputs of the rsHair and Diffuse if used.
// This file is licensed under Apache 2.0 license
shader MelaninColor
[[ string help = "Generates Melanin Output Colors",
string label = "Melanin Color" ]]
(
float melanin = 0.5 [[float min = 0, float max = 1, string label = "Melanin"]],
color dyeColor = 1 [[string label = "Dye Color"]],
float redness = 0 [[float min = 0, float max = 1, string label = "Melanin Redness"]],
float dyeMix = 0 [[float min = 0, float max = 1, string label = "Dye Mix"]],
int convToAces = 0 [[ string widget = "checkBox", string label = "ACES", int connectable = 0 ]],
output color outColor = 0
)
{
// ACES Transform
matrix srgbToAcesAP1 = {
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 };
float w = max( pow(melanin, 2.0) * 33.0, 0.02);
color pheomelanin = exp(w * -vector(0.187, 0.4, 1.05));
color eumelanin = exp(w * -vector(0.419, 0.697, 1.37));
color mel_out = mix(mix(eumelanin, pheomelanin, redness), dyeColor, dyeMix);
float sR = mel_out[0];
float sG = mel_out[1];
float sB = mel_out[2];
if (convToAces == 1){
outColor = transform(srgbToAcesAP1, vector(sR, sG, sB));
}
else {
outColor = mel_out;
}
}