aboutsummaryrefslogtreecommitdiff
path: root/assets/shaders/Taper.vert.glsl
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-02-22 11:00:20 -0800
committerNivesh Rajbhandari2012-02-22 11:00:20 -0800
commit96a0a8c916533eb5625816192ed38488f639326d (patch)
treea6283ee8c546419c3e79aa71c8e39c61d6dc34ed /assets/shaders/Taper.vert.glsl
parentd2f4d5e5f6742d53b6324d585a700566f73c992a (diff)
downloadninja-96a0a8c916533eb5625816192ed38488f639326d.tar.gz
Integrating canvas-2d drawing and WebGL fixes, including adding back WebGL materials.
Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'assets/shaders/Taper.vert.glsl')
-rw-r--r--assets/shaders/Taper.vert.glsl122
1 files changed, 122 insertions, 0 deletions
diff --git a/assets/shaders/Taper.vert.glsl b/assets/shaders/Taper.vert.glsl
new file mode 100644
index 00000000..30b73456
--- /dev/null
+++ b/assets/shaders/Taper.vert.glsl
@@ -0,0 +1,122 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7
8#ifdef GL_ES
9precision highp float;
10#endif
11
12
13// attributes
14attribute vec3 vert;
15attribute vec3 normal;
16attribute vec2 texcoord;
17
18// scalar uniforms
19uniform float u_limit1;
20uniform float u_limit2;
21uniform float u_limit3;
22uniform float u_taperAmount;
23uniform float u_minVal;
24uniform float u_maxVal;
25uniform float u_center;
26
27uniform vec4 color;
28
29
30// matrix uniforms
31uniform mat4 u_mvMatrix;
32uniform mat4 u_projMatrix;
33uniform mat4 u_worldMatrix;
34
35varying vec4 v_color;
36
37
38
39float TaperAmount( float param )
40{
41 // Bezier coordinates of the X coordinate.
42 // Adjust these to get tighter or looser
43 float tightness = 0.8;
44
45 float x0, y0, x1, y1, x2, y2;
46 float t;
47 if (param < 0.5)
48 {
49 t = 2.0*param;
50 x0 = 0.0; y0 = 0.0;
51 x1 = tightness; y1 = 0.0;
52 x2 = 1.0; y2 = 0.5;
53 }
54 else
55 {
56 t = (param - 0.5)*2.0;
57 x0 = 0.0; y0 = 0.5;
58 x1 = 1.0 - tightness; y1 = 1.0;
59 x2 = 1.0; y2 = 1.0;
60 }
61
62 float a = x0 - 2.0*x1 + x2;
63 float b = 2.0*(x1 - x0);
64 float c = x0 - t;
65
66 float descr = sqrt( b*b - 4.0*a*c );
67 float denom = 2.0*a;
68 float n1 = (-b + descr)/denom;
69 float n2 = (-b - descr)/denom;
70 if ((n1 >= 0.0) || (n1 <= 1.0)) t = n1;
71 else if ((n2 >= 0.0) || (n2 <= 1.0)) t = n2;
72 else
73 t = 0.0;
74
75 float ya = y0 + t*(y1 - y0);
76 float yb = y1 + t*(y2 - y1);
77 float yc = ya + t*(yb - ya);
78
79 return yc;
80}
81
82
83void main(void)
84{
85 vec3 pos = vert;
86 vec2 uv = texcoord;
87
88
89 float limit1 = u_limit1,
90 limit2 = u_limit2,
91 limit3 = u_limit2;
92
93 v_color = vec4(texcoord.x, texcoord.y, 0, 1);
94 if ((uv.x > u_limit1) && (uv.x < u_limit3))
95 {
96 float t;
97 if (uv.x < u_limit2)
98 {
99 t = (uv.x - u_limit1)/(u_limit2 - u_limit1);
100 }
101 else
102 {
103 t = 1.0 - (uv.x - u_limit2)/(u_limit3 - u_limit2);
104 }
105 t = TaperAmount( t );
106
107 float maxVal;
108 if (pos.y > u_center)
109 {
110 maxVal = u_maxVal;
111 }
112 else
113 {
114 maxVal = u_minVal;
115 }
116
117 float yFrac = (pos.y - u_center)/(maxVal-u_center);
118 pos.y = pos.y - yFrac * (maxVal - u_center)*t*u_taperAmount;
119 }
120
121 gl_Position = u_projMatrix * u_mvMatrix * vec4(pos,1.0) ;
122} \ No newline at end of file