-
Notifications
You must be signed in to change notification settings - Fork 6
/
Color - Scheme.osl
214 lines (189 loc) · 5.42 KB
/
Color - Scheme.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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
// ColorScheme - Various schemes to convert a float grayscale map to color.
// ColorScheme by Philippe Groarke
// Copyright 2022 Philippe Groarke, All rights reserved. This file is licensed under Apache 2.0 license
// https://github.com/ADN-DevTech/3dsMax-OSL-Shaders/blob/master/LICENSE.txt
#include "C:\Users\groarkp\code\3dsmax-plugins\OSL\FeaOSL\include\fea_color.osl"
#include "C:\Users\groarkp\code\3dsmax-plugins\OSL\FeaOSL\include\fea_widget.osl"
#define degs30 0.0833333333333333
#define degs60 0.1666666666666667
// Given a hue and how many levels to output,
// returns the closest multiple.
float flattenize(int levels, float in_val) {
if (!levels) {
return in_val;
}
float multiple = 1.0 / float(levels);
return ceil(in_val / multiple) * multiple;
}
shader ColorScheme
[[
string help =
"<h3>Color Scheme</h3>"
"Various schemes to convert a float grayscale map to color.\n"
"Expects values between [0, 1], clamps input."
,
string label = "Color - Scheme"
]]
(
float In = 0
[[
string label = "In",
string help = "Input grayscale map, expects float.",
]],
int in_invert = 0
[[
string label = "Invert",
string help = "Flips the input values, 1 becomes 0, 0 becomes 1.",
int connectable = 0,
string widget = "checkBox",
]],
// FEA_SPACER(0),
int in_color_mode = 0
[[
string widget = "mapper",
string label = "Color Mode",
string options =
"Simple Hue:0"
"|Heat Map:1"
"|Bright Burn:2"
"|Complements:3"
"|Analogous:4"
"|Split-Complementary:5"
"|Triad:6"
"|Tetradic:7"
"|Square:8"
,
string help = "The output 'Color' algorithm to use.",
int connectable = 0,
string packName = "Color Mode / Hue",
]],
float in_hue = 0
[[
string label = "Hue",
string help = "Cycles through available hues.",
// float min = 0,
// float max = 1,
string packName = "Color Mode / Hue",
int widgetWidth = FEA_RPACK_W,
]],
FEA_SPACER(1),
int in_step_amount = 6
[[
string label = "Step Amount",
string help = "The number of steps to use for 'Flatten' and for 'Countour' settings.",
int min = 2,
int connectable = 0,
]],
int in_flatten = 0
[[
string label = "Flatten",
string help = "Flatten colors to selected bands.",
int connectable = 0,
string widget = "checkBox",
]],
int in_contours = 0
[[
string label = "Contour",
string help = "Draw contours / edges according to number of levels.",
int connectable = 0,
string widget = "checkBox",
string packName = "Countour / Soft"
]],
int in_smooth_contours = 0
[[
string label = "Soften Contour",
string help = "Soften edges of contour lines.",
int connectable = 0,
string widget = "checkBox",
string packName = "Countour / Soft"
]],
float in_contour_width = 1.0
[[
string label = "Contour Width",
string help = "The contour width.",
int connectable = 0,
float min = 0.0001,
]],
output color Out = 0
)
{
float val = clamp(In, 0.0, 1.0);
val = in_invert ? 1.0 - val : val;
float hue = in_hue;
float hsv_v = 1.0;
if (in_contours && val != 0.0 && val != 1.0) {
float c_multiple = 1.0 / float(in_step_amount);
float c_mod = fmod(val, c_multiple);
float c_width = in_contour_width * 0.01;
if (in_smooth_contours) {
float high_w = c_width * 2.0;
hsv_v = smoothstep(c_width, high_w, c_mod);
hsv_v -= smoothstep(c_multiple - high_w, c_multiple - c_width, c_mod);
} else {
if (c_mod < c_width || c_mod > c_multiple - c_width) {
hsv_v = 0.0;
}
}
}
// Step
if (in_flatten != 0) {
val = flattenize(in_step_amount, val);
}
color out_col;
if (in_color_mode == 0) {
// hsv
// float col = fmod(val + hue, 1);
float col = val + hue;
out_col = color("hsv", col, 1, hsv_v);
} else if (in_color_mode == 1) {
// heat map
float offset = 0.5 + degs60 + hue;
float col = offset + val * 0.5;
out_col = color("hsv", col, 1, hsv_v);
} else if (in_color_mode == 2) {
// bright burn
float g = 0.618033988749895;
float col = val * 0.569 + g + hue;
float s = 1.0 - val;
if (in_flatten) {
s = flattenize(in_step_amount, s);
}
out_col = color("hsv", col, s, hsv_v);
} else if (in_color_mode == 3) {
// complements
color start_col = color("hsv", hue, 1, hsv_v);
color end_col = color("hsv", 0.5 + hue, 1, hsv_v);
out_col = mix(start_col, end_col, val);
} else if (in_color_mode == 4) {
// analogous
float col = fmod(val * degs60 + hue, 1) ;
out_col = color("hsv", col, 1, hsv_v);
} else if (in_color_mode == 5) {
// split complementary
color c1 = color("hsv", hue, 1, hsv_v);
color c2 = color("hsv", 0.5 + degs30 + hue, 1, hsv_v);
color c3 = color("hsv", 0.5 - degs30 + hue, 1, hsv_v);
out_col = fea_mix(c1, c2, c3, val);
} else if (in_color_mode == 6) {
// triad
color c1 = color("hsv", hue, 1, hsv_v);
color c2 = color("hsv", 0.25 + degs30 + hue, 1, hsv_v);
color c3 = color("hsv", 0.75 - degs30 + hue, 1, hsv_v);
out_col = fea_mix(c1, c3, c2, val);
} else if (in_color_mode == 7) {
// tetradic
color c1 = color("hsv", (1 / 12.0) + hue, 1, hsv_v);
color c2 = color("hsv", 0.5 - degs30 + hue, 1, hsv_v);
color c3 = color("hsv", 0.5 + degs30 + hue, 1, hsv_v);
color c4 = color("hsv", 1.0 - degs30 + hue, 1, hsv_v);
out_col = fea_mix(c1, c4, c2, c3, val);
} else if (in_color_mode == 8) {
// square
color c1 = color("hsv", hue, 1, hsv_v);
color c2 = color("hsv", 0.25 + hue, 1, hsv_v);
color c3 = color("hsv", 0.5 + hue, 1, hsv_v);
color c4 = color("hsv", 0.75 + hue, 1, hsv_v);
out_col = fea_mix(c1, c3, c4, c2, val);
}
Out = out_col;
}