diff options
Diffstat (limited to 'assets/shaders/Taper.vert.glsl')
-rw-r--r-- | assets/shaders/Taper.vert.glsl | 122 |
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> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No 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 | ||
9 | precision highp float; | ||
10 | #endif | ||
11 | |||
12 | |||
13 | // attributes | ||
14 | attribute vec3 vert; | ||
15 | attribute vec3 normal; | ||
16 | attribute vec2 texcoord; | ||
17 | |||
18 | // scalar uniforms | ||
19 | uniform float u_limit1; | ||
20 | uniform float u_limit2; | ||
21 | uniform float u_limit3; | ||
22 | uniform float u_taperAmount; | ||
23 | uniform float u_minVal; | ||
24 | uniform float u_maxVal; | ||
25 | uniform float u_center; | ||
26 | |||
27 | uniform vec4 color; | ||
28 | |||
29 | |||
30 | // matrix uniforms | ||
31 | uniform mat4 u_mvMatrix; | ||
32 | uniform mat4 u_projMatrix; | ||
33 | uniform mat4 u_worldMatrix; | ||
34 | |||
35 | varying vec4 v_color; | ||
36 | |||
37 | |||
38 | |||
39 | float 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 | |||
83 | void 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 | ||