aboutsummaryrefslogtreecommitdiff
path: root/assets/shaders/TwistVert.vert.glsl
diff options
context:
space:
mode:
authorValerio Virgillito2012-02-23 17:05:43 -0800
committerValerio Virgillito2012-02-23 17:05:43 -0800
commitafc53c6f553c97ab778154154aa2b7a146cb5fef (patch)
tree66b5ec886a49894feda44ccf8b5233ef39a46536 /assets/shaders/TwistVert.vert.glsl
parent8974ecd564563a991ff96f9cb6d47da172174242 (diff)
parentdb2fd02a1b0e909bb536fa63cefd2144f4642ead (diff)
downloadninja-afc53c6f553c97ab778154154aa2b7a146cb5fef.tar.gz
Merge branch 'refs/heads/master' into local-storage-version
Diffstat (limited to 'assets/shaders/TwistVert.vert.glsl')
-rw-r--r--assets/shaders/TwistVert.vert.glsl97
1 files changed, 97 insertions, 0 deletions
diff --git a/assets/shaders/TwistVert.vert.glsl b/assets/shaders/TwistVert.vert.glsl
new file mode 100644
index 00000000..29cb30ea
--- /dev/null
+++ b/assets/shaders/TwistVert.vert.glsl
@@ -0,0 +1,97 @@
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_twistAmount;
22uniform float u_center;
23
24// texture sampler uniforms
25uniform sampler2D u_tex0;
26uniform sampler2D u_tex1;
27
28uniform vec4 color;
29
30
31// matrix uniforms
32uniform mat4 u_mvMatrix;
33uniform mat4 u_projMatrix;
34uniform mat4 u_worldMatrix;
35
36//varying vec4 v_color;
37varying float v_zNormal;
38varying vec2 v_texcoord;
39
40
41float GetAngle( float t )
42{
43 float angle= 0.0;
44 if (t < u_limit2)
45 {
46 if (t < u_limit1)
47 {
48 angle = u_twistAmount;
49 }
50 else
51 {
52 angle = (t - u_limit2)/(u_limit1 - u_limit2)*u_twistAmount;
53 }
54 }
55
56 return angle;
57}
58
59
60void main(void)
61{
62 vec3 pos = vert;
63 vec2 uv = texcoord;
64 v_texcoord = texcoord;
65
66 //v_color = vec4(texcoord.x, texcoord.y, 0, 1);
67
68 v_zNormal = 1.0;
69 if (uv.x < u_limit2)
70 {
71 float angle = GetAngle( uv.x );
72 float cs = cos(angle), sn = sin(angle);
73
74 pos.y -= u_center;
75 vec3 ctrPt = pos;
76 float y = pos.y*cs - pos.z*sn + u_center;
77 pos.z = pos.y*sn + pos.z*cs;
78 pos.y = y;
79
80 // rotate the normal
81 mat3 rotMat = mat3( vec3( 1.0, 0.0, 0.0 ), vec3( 0.0, cs, sn ), vec3( 0.0, -sn, cs ) );
82 vec3 pt0 = ctrPt, pt1 = vec3(ctrPt.x, ctrPt.y+1.0, ctrPt.z), pt2 = vec3( ctrPt.x+1.0, ctrPt.y, ctrPt.z);
83 pt0 = rotMat * pt0; pt1 = rotMat * pt1;
84 angle = GetAngle(1.0);
85 cs = cos(angle); sn = sin(angle);
86 rotMat = mat3( vec3( 1.0, 0.0, 0.0 ), vec3( 0.0, cs, sn ), vec3( 0.0, -sn, cs ) );
87 pt2 = rotMat * pt2;
88 pt0.y += u_center; pt1.y += u_center; pt2.y += u_center;
89 //vec4 nrm = u_projMatrix * u_mvMatrix * vec4( cross(pt1-pt0, pt2-pt0), 1.0 );
90 vec4 nrm = vec4( cross(pt1-pt0, pt2-pt0), 1.0 );
91
92 //v_zNormal = normal.y*sn + normal.z*cs;
93 v_zNormal = -nrm.z;
94 }
95
96 gl_Position = u_projMatrix * u_mvMatrix * vec4(pos,1.0) ;
97} \ No newline at end of file