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
|
/* An arbitrary value determined by Blender. */
#define BLENDER_ZMAX 10000.0
void node_composite_map_range(float value,
float from_min,
float from_max,
float to_min,
float to_max,
const float should_clamp,
out float result)
{
if (abs(from_max - from_min) < 1e-6) {
result = 0.0;
}
else {
if (value >= -BLENDER_ZMAX && value <= BLENDER_ZMAX) {
result = (value - from_min) / (from_max - from_min);
result = to_min + result * (to_max - to_min);
}
else if (value > BLENDER_ZMAX) {
result = to_max;
}
else {
result = to_min;
}
if (should_clamp != 0.0) {
if (to_max > to_min) {
result = clamp(result, to_min, to_max);
}
else {
result = clamp(result, to_max, to_min);
}
}
}
}
void node_composite_map_value(float value,
float offset,
float size,
const float use_min,
float min,
const float use_max,
float max,
out float result)
{
result = (value + offset) * size;
if (use_min != 0.0 && result < min) {
result = min;
}
if (use_max != 0.0 && result > max) {
result = max;
}
}
|