Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gpu_shader_material_map_range.glsl « material « shaders « gpu « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7853aae31a111b026caa1e3b743dcecdebb8780a (plain)
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
float smootherstep(float edge0, float edge1, float x)
{
  x = clamp(safe_divide((x - edge0), (edge1 - edge0)), 0.0, 1.0);
  return x * x * x * (x * (x * 6.0 - 15.0) + 10.0);
}

void map_range_linear(float value,
                      float fromMin,
                      float fromMax,
                      float toMin,
                      float toMax,
                      float steps,
                      out float result)
{
  if (fromMax != fromMin) {
    result = toMin + ((value - fromMin) / (fromMax - fromMin)) * (toMax - toMin);
  }
  else {
    result = 0.0;
  }
}

void map_range_stepped(float value,
                       float fromMin,
                       float fromMax,
                       float toMin,
                       float toMax,
                       float steps,
                       out float result)
{
  if (fromMax != fromMin) {
    float factor = (value - fromMin) / (fromMax - fromMin);
    factor = (steps > 0.0) ? floor(factor * (steps + 1.0)) / steps : 0.0;
    result = toMin + factor * (toMax - toMin);
  }
  else {
    result = 0.0;
  }
}

void map_range_smoothstep(float value,
                          float fromMin,
                          float fromMax,
                          float toMin,
                          float toMax,
                          float steps,
                          out float result)
{
  if (fromMax != fromMin) {
    float factor = (fromMin > fromMax) ? 1.0 - smoothstep(fromMax, fromMin, value) :
                                         smoothstep(fromMin, fromMax, value);
    result = toMin + factor * (toMax - toMin);
  }
  else {
    result = 0.0;
  }
}

void map_range_smootherstep(float value,
                            float fromMin,
                            float fromMax,
                            float toMin,
                            float toMax,
                            float steps,
                            out float result)
{
  if (fromMax != fromMin) {
    float factor = (fromMin > fromMax) ? 1.0 - smootherstep(fromMax, fromMin, value) :
                                         smootherstep(fromMin, fromMax, value);
    result = toMin + factor * (toMax - toMin);
  }
  else {
    result = 0.0;
  }
}