aboutsummaryrefslogtreecommitdiff
path: root/assets/shaders/Taper.vert.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'assets/shaders/Taper.vert.glsl')
-rw-r--r--assets/shaders/Taper.vert.glsl175
1 files changed, 88 insertions, 87 deletions
diff --git a/assets/shaders/Taper.vert.glsl b/assets/shaders/Taper.vert.glsl
index 5fe173b2..e804f0e4 100644
--- a/assets/shaders/Taper.vert.glsl
+++ b/assets/shaders/Taper.vert.glsl
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -60,85 +61,85 @@ varying vec4 v_color;
60 61
61float TaperAmount( float param ) 62float TaperAmount( float param )
62{ 63{
63 // Bezier coordinates of the X coordinate. 64 // Bezier coordinates of the X coordinate.
64 // Adjust these to get tighter or looser 65 // Adjust these to get tighter or looser
65 float tightness = 0.8; 66 float tightness = 0.8;
66 67
67 float x0, y0, x1, y1, x2, y2; 68 float x0, y0, x1, y1, x2, y2;
68 float t; 69 float t;
69 if (param < 0.5) 70 if (param < 0.5)
70 { 71 {
71 t = 2.0*param; 72 t = 2.0*param;
72 x0 = 0.0; y0 = 0.0; 73 x0 = 0.0; y0 = 0.0;
73 x1 = tightness; y1 = 0.0; 74 x1 = tightness; y1 = 0.0;
74 x2 = 1.0; y2 = 0.5; 75 x2 = 1.0; y2 = 0.5;
75 } 76 }
76 else 77 else
77 { 78 {
78 t = (param - 0.5)*2.0; 79 t = (param - 0.5)*2.0;
79 x0 = 0.0; y0 = 0.5; 80 x0 = 0.0; y0 = 0.5;
80 x1 = 1.0 - tightness; y1 = 1.0; 81 x1 = 1.0 - tightness; y1 = 1.0;
81 x2 = 1.0; y2 = 1.0; 82 x2 = 1.0; y2 = 1.0;
82 } 83 }
83 84
84 float a = x0 - 2.0*x1 + x2; 85 float a = x0 - 2.0*x1 + x2;
85 float b = 2.0*(x1 - x0); 86 float b = 2.0*(x1 - x0);
86 float c = x0 - t; 87 float c = x0 - t;
87 88
88 float descr = sqrt( b*b - 4.0*a*c ); 89 float descr = sqrt( b*b - 4.0*a*c );
89 float denom = 2.0*a; 90 float denom = 2.0*a;
90 float n1 = (-b + descr)/denom; 91 float n1 = (-b + descr)/denom;
91 float n2 = (-b - descr)/denom; 92 float n2 = (-b - descr)/denom;
92 if ((n1 >= 0.0) || (n1 <= 1.0)) t = n1; 93 if ((n1 >= 0.0) || (n1 <= 1.0)) t = n1;
93 else if ((n2 >= 0.0) || (n2 <= 1.0)) t = n2; 94 else if ((n2 >= 0.0) || (n2 <= 1.0)) t = n2;
94 else 95 else
95 t = 0.0; 96 t = 0.0;
96 97
97 float ya = y0 + t*(y1 - y0); 98 float ya = y0 + t*(y1 - y0);
98 float yb = y1 + t*(y2 - y1); 99 float yb = y1 + t*(y2 - y1);
99 float yc = ya + t*(yb - ya); 100 float yc = ya + t*(yb - ya);
100 101
101 return yc; 102 return yc;
102} 103}
103 104
104 105
105void main(void) 106void main(void)
106{ 107{
107 vec3 pos = vert; 108 vec3 pos = vert;
108 vec2 uv = texcoord; 109 vec2 uv = texcoord;
109 110
110 111
111 float limit1 = u_limit1, 112 float limit1 = u_limit1,
112 limit2 = u_limit2, 113 limit2 = u_limit2,
113 limit3 = u_limit2; 114 limit3 = u_limit2;
114 115
115 v_color = vec4(texcoord.x, texcoord.y, 0, 1); 116 v_color = vec4(texcoord.x, texcoord.y, 0, 1);
116 if ((uv.x > u_limit1) && (uv.x < u_limit3)) 117 if ((uv.x > u_limit1) && (uv.x < u_limit3))
117 { 118 {
118 float t; 119 float t;
119 if (uv.x < u_limit2) 120 if (uv.x < u_limit2)
120 { 121 {
121 t = (uv.x - u_limit1)/(u_limit2 - u_limit1); 122 t = (uv.x - u_limit1)/(u_limit2 - u_limit1);
122 } 123 }
123 else 124 else
124 { 125 {
125 t = 1.0 - (uv.x - u_limit2)/(u_limit3 - u_limit2); 126 t = 1.0 - (uv.x - u_limit2)/(u_limit3 - u_limit2);
126 } 127 }
127 t = TaperAmount( t ); 128 t = TaperAmount( t );
128 129
129 float maxVal; 130 float maxVal;
130 if (pos.y > u_center) 131 if (pos.y > u_center)
131 { 132 {
132 maxVal = u_maxVal; 133 maxVal = u_maxVal;
133 } 134 }
134 else 135 else
135 { 136 {
136 maxVal = u_minVal; 137 maxVal = u_minVal;
137 } 138 }
138 139
139 float yFrac = (pos.y - u_center)/(maxVal-u_center); 140 float yFrac = (pos.y - u_center)/(maxVal-u_center);
140 pos.y = pos.y - yFrac * (maxVal - u_center)*t*u_taperAmount; 141 pos.y = pos.y - yFrac * (maxVal - u_center)*t*u_taperAmount;
141 } 142 }
142 143
143 gl_Position = u_projMatrix * u_mvMatrix * vec4(pos,1.0) ; 144 gl_Position = u_projMatrix * u_mvMatrix * vec4(pos,1.0) ;
144} 145}