4588e41573b90ae14d6a1854fca0c4b42fd1a741
[blender.git] / source / blender / gpu / shaders / gpu_shader_2D_edituvs_stretch_vert.glsl
1
2 uniform mat4 ModelViewProjectionMatrix;
3
4 in vec2 pos;
5 in float stretch;
6
7 noperspective out vec4 finalColor;
8
9 vec3 weight_to_rgb(float weight)
10 {
11         vec3 r_rgb;
12         float blend = ((weight / 2.0) + 0.5);
13
14         if (weight <= 0.25) {    /* blue->cyan */
15                 r_rgb[0] = 0.0;
16                 r_rgb[1] = blend * weight * 4.0;
17                 r_rgb[2] = blend;
18         }
19         else if (weight <= 0.50) {  /* cyan->green */
20                 r_rgb[0] = 0.0;
21                 r_rgb[1] = blend;
22                 r_rgb[2] = blend * (1.0 - ((weight - 0.25) * 4.0));
23         }
24         else if (weight <= 0.75) {  /* green->yellow */
25                 r_rgb[0] = blend * ((weight - 0.50) * 4.0);
26                 r_rgb[1] = blend;
27                 r_rgb[2] = 0.0;
28         }
29         else if (weight <= 1.0) {  /* yellow->red */
30                 r_rgb[0] = blend;
31                 r_rgb[1] = blend * (1.0 - ((weight - 0.75) * 4.0));
32                 r_rgb[2] = 0.0;
33         }
34         else {
35                 /* exceptional value, unclamped or nan,
36                  * avoid uninitialized memory use */
37                 r_rgb[0] = 1.0;
38                 r_rgb[1] = 0.0;
39                 r_rgb[2] = 1.0;
40         }
41
42         return r_rgb;
43 }
44
45 void main()
46 {
47         gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
48         finalColor = vec4(weight_to_rgb(stretch), 1.0);
49 }