File: linear-scale.glsl

package info (click to toggle)
python-vispy 0.15.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,868 kB
  • sloc: python: 59,799; javascript: 6,800; makefile: 69; sh: 6
file content (127 lines) | stat: -rw-r--r-- 3,394 bytes parent folder | download | duplicates (5)
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
// ----------------------------------------------------------------------------
// Copyright (c) 2014, Nicolas P. Rougier. All Rights Reserved.
// Distributed under the (new) BSD License.
// ----------------------------------------------------------------------------
/*
  Linear scales are the most common scale, and a good default choice to map a
  continuous input domain to a continuous output range. The mapping is linear
  in that the output range value y can be expressed as a linear function of the
  input domain value x: y = mx + b. The input domain is typically a dimension
  of the data that you want to visualize, such as the height of students
  (measured in meters) in a sample population. The output range is typically a
  dimension of the desired output visualization, such as the height of bars
  (measured in pixels) in a histogram.
*/
uniform int  linear_scale_clamp;
uniform int  linear_scale_discard;
uniform vec2 linear_scale_range;
uniform vec2 linear_scale_domain;


float forward(float value)
{
    vec2 domain = linear_scale_domain;
    vec2 range = linear_scale_range;
    float t = (value - domain.x) /(domain.y - domain.x);

#ifdef __FRAGMENT_SHADER__
    if (linear_scale_discard > 0)
        if (t != clamp(t, 0.0, 1.0))
            discard;
#endif

    if (linear_scale_clamp > 0)
        t = clamp(t, 0.0, 1.0);

    return range.x + t*(range.y - range.x);
}

vec2 forward(vec2 value)
{
    vec2 domain = linear_scale_domain;
    vec2 range = linear_scale_range;
    vec2 t = (value - domain.x) /(domain.y - domain.x);

#ifdef __FRAGMENT_SHADER__
    if (linear_scale_discard > 0)
        if (t != clamp(t, 0.0, 1.0))
            discard;
#endif

    if (linear_scale_clamp > 0)
        t = clamp(t, 0.0, 1.0);

    return range.x + t*(range.y - range.x);
}

vec3 forward(vec3 value)
{
    vec2 domain = linear_scale_domain;
    vec2 range = linear_scale_range;
    vec3 t = (value - domain.x) /(domain.y - domain.x);

#ifdef __FRAGMENT_SHADER__
    if (linear_scale_discard > 0)
        if (t != clamp(t, 0.0, 1.0))
            discard;
#endif

    if (linear_scale_clamp > 0)
        t = clamp(t, 0.0, 1.0);

    return range.x + t*(range.y - range.x);
}

float inverse(float value)
{
    vec2 domain = linear_scale_domain;
    vec2 range = linear_scale_range;
    float t = (value - range.x) / (range.y - range.x);

#ifdef __FRAGMENT_SHADER__
    if (linear_scale_discard > 0)
        if (t != clamp(t, 0.0, 1.0))
            discard;
#endif

    if (linear_scale_clamp > 0)
        t = clamp(t, 0.0, 1.0);

    return domain.x + t*(domain.y - domain.x);
}

vec2 inverse(vec2 value)
{
    vec2 domain = linear_scale_domain;
    vec2 range = linear_scale_range;
    vec2 t = (value - range.x) / (range.y - range.x);

#ifdef __FRAGMENT_SHADER__
    if (linear_scale_discard > 0)
        if (t != clamp(t, 0.0, 1.0))
            discard;
#endif

    if (linear_scale_clamp > 0)
        t = clamp(t, 0.0, 1.0);

    return domain.x + t*(domain.y - domain.x);
}

vec3 inverse(vec3 value)
{
    vec2 domain = linear_scale_domain;
    vec2 range = linear_scale_range;
    vec3 t = (value - range.x) / (range.y - range.x);

#ifdef __FRAGMENT_SHADER__
    if (linear_scale_discard > 0)
        if (t != clamp(t, 0.0, 1.0))
            discard;
#endif

    if (linear_scale_clamp > 0)
        t = clamp(t, 0.0, 1.0);

    return domain.x + t*(domain.y - domain.x);
}