forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cm.mdl
195 lines (172 loc) · 6.65 KB
/
cm.mdl
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
//
// TM & (c) 2020 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
// All rights reserved. See LICENSE.txt for license.
//
// Default color management transforms for MDL
//
mdl 1.6;
using core import *;
import::base::*;
import::anno::*;
import::state::*;
import.::swizzle::*;
import::math::*;
// Threshold utility
float4 aboveThreshold(float4 value, float4 threshold)
{
return float4(value.x > threshold.x ? 1.0 : 0.0,
value.y > threshold.y ? 1.0 : 0.0,
value.z > threshold.z ? 1.0 : 0.0,
value.w > threshold.w ? 1.0 : 0.0 );
}
export float3 mx_acescg_to_linear_color3(float3 mxp_in)
[[
anno::description("ACES CG to linear transform for color3")
]]
{
float4 outColor = float4(mxp_in.x, mxp_in.y, mxp_in.z, 0.0);
float4x4 xform = float4x4(1.705079555511475, -0.1297005265951157, -0.02416634373366833, 0.0,
-0.6242334842681885, 1.138468623161316, -0.1246141716837883, 0.0,
-0.0808461606502533, -0.008768022060394287, 1.148780584335327,
0.0, 0.0, 0.0, 0.0, 1.0);
float3 result = ::swizzle::xyz(xform * outColor);
return result;
}
export color mx_acescg_to_linear_color3(color mxp_in)
{
return color(mx_acescg_to_linear_color3(float3(mxp_in)));
}
export float4 mx_acescg_to_linear_color4(float4 mxp_in)
[[
anno::description("ACES CG to linear transform for color4")
]]
{
float4 outColor = float4(mxp_in.x, mxp_in.y, mxp_in.z, 0.0);
float4x4 xform = float4x4(1.705079555511475, -0.1297005265951157, -0.02416634373366833, 0.0,
-0.6242334842681885, 1.138468623161316, -0.1246141716837883, 0.0,
-0.0808461606502533, -0.008768022060394287, 1.148780584335327,
0.0, 0.0, 0.0, 0.0, 1.0);
float3 result3 = ::swizzle::xyz(xform * outColor);
float4 result = float4(result3.x,result3.y, result3.z, mxp_in.w);
return result;
}
export color4 mx_acescg_to_linear_color4(color4 mxp_in)
{
return mk_color4(mx_acescg_to_linear_color4(mk_float4(mxp_in)));
}
export float3 mx_gamma18_to_linear_color3(float3 mxp_in)
[[
anno::description("Gamma 1.8 to linear transform for color3")
]]
{
float3 gamma = float3(1.8, 1.8, 1.8);
return ::math::pow( ::math::max( float3(0.0, 0.0, 0.0), mxp_in ), gamma );
}
export color mx_gamma18_to_linear_color3(color mxp_in)
{
return color(mx_gamma18_to_linear_color3(float3(mxp_in)));
}
export float4 mx_gamma18_to_linear_color4(float4 mxp_in)
[[
anno::description("Gamma 1.8 to linear transform for color4")
]]
{
float4 gamma = float4(1.8, 1.8, 1.8, 1.0);
return ::math::pow( ::math::max( float4(0.0, 0.0, 0.0, 0.0), mxp_in ), gamma );
}
export color4 mx_gamma18_to_linear_color4(color4 mxp_in)
{
return mk_color4(mx_acescg_to_linear_color4(mk_float4(mxp_in)));
}
export float3 mx_gamma22_to_linear_color3(float3 mxp_in)
[[
anno::description("Gamma 2.2 to linear transform for color3")
]]
{
float3 gamma = float3(2.2, 2.2, 2.2);
return ::math::pow( ::math::max( float3(0.0, 0.0, 0.0), mxp_in ), gamma );
}
export color mx_gamma22_to_linear_color3(color mxp_in)
{
return color(mx_gamma22_to_linear_color3(float3(mxp_in)));
}
export float4 mx_gamma22_to_linear_color4(float4 mxp_in)
[[
anno::description("Gamma 2.2 to linear transform for color4")
]]
{
float4 gamma = float4(2.2, 2.2, 2.2, 1.0);
return ::math::pow( ::math::max( float4(0.0, 0.0, 0.0, 0.0), mxp_in ), gamma );
}
export color4 mx_gamma22_to_linear_color4(color4 mxp_in)
{
return mk_color4(mx_gamma22_to_linear_color4(mk_float4(mxp_in)));
}
export float3 mx_gamma24_to_linear_color3(float3 mxp_in)
[[
anno::description("Gamma 2.4 to linear transform for color3")
]]
{
float3 gamma = float3(2.4, 2.4, 2.4);
return ::math::pow( ::math::max( float3(0.0, 0.0, 0.0), mxp_in ), gamma );
}
export color mx_gamma24_to_linear_color3(color mxp_in)
{
return color(mx_gamma24_to_linear_color3(float3(mxp_in)));
}
export float4 mx_gamma24_to_linear_color4(float4 mxp_in)
[[
anno::description("Gamma 2.4 to linear transform for color4")
]]
{
float4 gamma = float4(2.4, 2.4, 2.4, 1.0);
return ::math::pow( ::math::max( float4(0.0, 0.0, 0.0, 0.0), mxp_in ), gamma );
}
export color4 mx_gamma24_to_linear_color4(color4 mxp_in)
{
return mk_color4(mx_gamma24_to_linear_color4(mk_float4(mxp_in)));
}
export float3 mx_srgb_texture_to_linear_color3(float3 mxp_in)
[[
anno::description("SRGB-texture to linear transform for color3")
]]
{
float4 outColor = float4(mxp_in.x, mxp_in.y, mxp_in.z, 0.0);
float4 breakPnt = float4(0.03928571566939354, 0.03928571566939354, 0.03928571566939354, 1.0);
float4 slope = float4(0.07738015800714493, 0.07738015800714493, 0.07738015800714493, 1.0);
float4 scale = float4(0.9478672742843628, 0.9478672742843628, 0.9478672742843628, 1.0);
float4 offset = float4(0.05213269963860512, 0.05213269963860512, 0.05213269963860512, 0.0);
float4 gamma = float4(2.4, 2.4, 2.4, 1.0);
float4 isAboveBreak = aboveThreshold(outColor, breakPnt);
float4 linSeg = outColor * slope;
float4 powSeg = ::math::pow( ::math::max( float4(0.0, 0.0, 0.0, 0.0), scale * outColor + offset), gamma);
float4 result4 = isAboveBreak * powSeg + float4( float4(1.0, 1.0, 1.0, 1.0) - isAboveBreak ) * linSeg;
float3 result = ::swizzle::xyz(result4);
return result;
}
export color mx_srgb_texture_to_linear_color3(color mxp_in)
{
return color(mx_srgb_texture_to_linear_color3(float3(mxp_in)));
}
export float4 mx_srgb_texture_to_linear_color4(float4 mxp_in)
[[
anno::description("SRGB-texture to linear transform for color4")
]]
{
float4 outColor = float4(mxp_in.x, mxp_in.y, mxp_in.z, 0.0);
float4 breakPnt = float4(0.03928571566939354, 0.03928571566939354, 0.03928571566939354, 1.0);
float4 slope = float4(0.07738015800714493, 0.07738015800714493, 0.07738015800714493, 1.0);
float4 scale = float4(0.9478672742843628, 0.9478672742843628, 0.9478672742843628, 1.0);
float4 offset = float4(0.05213269963860512, 0.05213269963860512, 0.05213269963860512, 0.0);
float4 gamma = float4(2.4, 2.4, 2.4, 1.0);
float4 isAboveBreak = aboveThreshold(outColor, breakPnt);
float4 linSeg = outColor * slope;
float4 powSeg = ::math::pow( ::math::max( float4(0.0, 0.0, 0.0, 0.0), scale * outColor + offset), gamma);
float3 result3 = ::swizzle::xyz(isAboveBreak * powSeg + float4( float4(1.0, 1.0, 1.0, 1.0) - isAboveBreak ) * linSeg);
float4 result = float4(result3.x, result3.y, result3.z, mxp_in.w);
return result;
}
export color4 mx_srgb_texture_to_linear_color4(color4 mxp_in)
{
return mk_color4(mx_srgb_texture_to_linear_color4(mk_float4(mxp_in)));
}