diff options
Diffstat (limited to 'assets/shaders/ub_vshader.glsl')
-rw-r--r-- | assets/shaders/ub_vshader.glsl | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/assets/shaders/ub_vshader.glsl b/assets/shaders/ub_vshader.glsl new file mode 100644 index 00000000..ff0c09b4 --- /dev/null +++ b/assets/shaders/ub_vshader.glsl | |||
@@ -0,0 +1,162 @@ | |||
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 | // attributes | ||
8 | attribute vec3 a_pos; | ||
9 | attribute vec3 a_normal; | ||
10 | attribute vec2 a_texcoord; | ||
11 | |||
12 | // uniforms | ||
13 | uniform mat4 u_worldMatrix; | ||
14 | uniform mat4 u_viewMatrix; | ||
15 | uniform mat4 u_projMatrix; | ||
16 | uniform mat4 u_mvMatrix; | ||
17 | uniform mat4 u_normalMatrix; | ||
18 | uniform mat4 u_uvMatrix; | ||
19 | uniform vec3 u_eye; | ||
20 | |||
21 | // attributes | ||
22 | #if defined( MATERIAL ) | ||
23 | uniform vec4 u_ambientColor; | ||
24 | uniform vec4 u_diffuseColor; | ||
25 | uniform vec4 u_specularColor; | ||
26 | uniform float u_specularPower; | ||
27 | #endif | ||
28 | |||
29 | #if defined( LIGHTING ) | ||
30 | varying vec3 v_normal; | ||
31 | #if defined( LIGHT_0 ) | ||
32 | uniform int u_light0Type; | ||
33 | uniform vec3 u_light0Pos; | ||
34 | uniform vec3 u_light0Dir; | ||
35 | uniform vec3 u_light0Atten; | ||
36 | uniform vec2 u_light0Spot; | ||
37 | uniform vec4 u_light0Color; | ||
38 | uniform vec4 u_light0Specular; | ||
39 | varying vec3 v_light0Dir; | ||
40 | varying vec3 v_light0SpotDir; | ||
41 | #endif | ||
42 | |||
43 | #if defined( LIGHT_1 ) | ||
44 | uniform int u_light1Type; | ||
45 | uniform vec3 u_light1Pos; | ||
46 | uniform vec3 u_light1Dir; | ||
47 | uniform vec3 u_light1Atten; | ||
48 | uniform vec2 u_light1Spot; | ||
49 | uniform vec3 u_light1Color; | ||
50 | uniform vec4 u_light1Specular; | ||
51 | varying vec3 v_light1Dir; | ||
52 | varying vec3 v_light1SpotDir; | ||
53 | #endif | ||
54 | |||
55 | #if defined( LIGHT_2 ) | ||
56 | uniform int u_light2Type; // 0 - dir, 1 - point, 2 - spot | ||
57 | uniform vec3 u_light2Pos; | ||
58 | uniform vec3 u_light2Dir; | ||
59 | uniform vec3 u_light2Atten; | ||
60 | uniform vec2 u_light2Spot; // 0 - spot light cutoff angle, 1 - spot light exponent | ||
61 | uniform vec3 u_light2Color; | ||
62 | uniform vec4 u_light2Specular; | ||
63 | varying vec3 v_light2Dir; | ||
64 | varying vec3 v_light2SpotDir; | ||
65 | #endif | ||
66 | |||
67 | #if defined( LIGHT_3 ) | ||
68 | uniform int u_light3Type; | ||
69 | uniform vec3 u_light3Pos; | ||
70 | uniform vec3 u_light3Dir; | ||
71 | uniform vec3 u_light3Atten; | ||
72 | uniform vec2 u_light3Spot; | ||
73 | uniform vec3 u_light3Color; | ||
74 | uniform vec4 u_light3Specular; | ||
75 | varying vec3 v_light3Dir; | ||
76 | varying vec3 v_light3SpotDir; | ||
77 | #endif | ||
78 | #endif | ||
79 | |||
80 | #if defined( ENVIRONMENT_MAP ) | ||
81 | uniform float u_envReflection; | ||
82 | #endif | ||
83 | |||
84 | varying vec3 v_mvPos; | ||
85 | varying vec3 v_eyeDir; | ||
86 | varying vec2 v_texcoord; | ||
87 | |||
88 | #if defined( PC ) | ||
89 | void main() { | ||
90 | // position normals and vert | ||
91 | v_mvPos = ( u_mvMatrix * vec4( a_pos, 1.0 ) ).xyz; | ||
92 | |||
93 | v_texcoord = (u_uvMatrix * vec4(a_texcoord, 0, 1.0)).xy; | ||
94 | #if ( defined( LIGHTING ) || defined( ENVIRONMENT_MAP ) ) | ||
95 | v_normal = ( u_normalMatrix * vec4( a_normal, 0.0 ) ).xyz; | ||
96 | #endif | ||
97 | |||
98 | #if defined( LIGHTING ) | ||
99 | v_eyeDir = vec3(-u_viewMatrix[3][0], -u_viewMatrix[3][1], -u_viewMatrix[3][2]); | ||
100 | #if defined( LIGHT_0 ) | ||
101 | { | ||
102 | vec3 lpos = ( u_viewMatrix * vec4( u_light0Pos, 1.0 ) ).xyz; | ||
103 | |||
104 | #if ( LIGHT_0 == 0 ) | ||
105 | v_light0Dir = ( u_viewMatrix * vec4( -u_light0Dir, 0.0 ) ).xyz; | ||
106 | #else | ||
107 | v_light0Dir = lpos - v_mvPos; | ||
108 | #if ( LIGHT_0 == 2 ) | ||
109 | v_light0SpotDir = (u_viewMatrix * vec4( -u_light0Dir, 0.0 )).xyz; | ||
110 | #endif // ( LIGHT_0 == 2 ) | ||
111 | #endif // ( LIGHT_0 == 0 ) | ||
112 | } | ||
113 | #endif // defined( LIGHT_0 ) | ||
114 | #if defined( LIGHT_1 ) | ||
115 | { | ||
116 | vec3 lpos = ( u_viewMatrix * vec4( u_light1Pos, 1.0 ) ).xyz; | ||
117 | |||
118 | #if ( LIGHT_1 == 0 ) | ||
119 | v_light1Dir = ( u_viewMatrix * vec4( -u_light1Dir, 0.0 ) ).xyz; | ||
120 | #else | ||
121 | v_light1Dir = lpos - v_mvPos; | ||
122 | #if ( LIGHT_1 == 2 ) | ||
123 | v_light1SpotDir = (u_viewMatrix * vec4( -u_light1Dir, 0.0 )).xyz; | ||
124 | #endif // ( LIGHT_1 == 2 ) | ||
125 | #endif // ( LIGHT_1 == 0 ) | ||
126 | } | ||
127 | #endif // defined( LIGHT_1 ) | ||
128 | #if defined( LIGHT_2 ) | ||
129 | { | ||
130 | vec3 lpos = ( u_viewMatrix * vec4( u_light2Pos, 1.0 ) ).xyz; | ||
131 | |||
132 | #if ( LIGHT_2 == 0 ) | ||
133 | v_light2Dir = ( u_viewMatrix * vec4( -u_light2Dir, 0.0 ) ).xyz; | ||
134 | #else | ||
135 | v_light2Dir = lpos - v_mvPos; | ||
136 | #if ( LIGHT_2 == 2 ) | ||
137 | v_light2SpotDir = (u_viewMatrix * vec4( -u_light2Dir, 0.0 )).xyz; | ||
138 | #endif // ( LIGHT_2 == 2 ) | ||
139 | #endif // ( LIGHT_2 == 0 ) | ||
140 | } | ||
141 | #endif // defined( LIGHT_2 ) | ||
142 | #if defined( LIGHT_3 ) | ||
143 | { | ||
144 | vec3 lpos = ( u_viewMatrix * vec4( u_light3Pos, 1.0 ) ).xyz; | ||
145 | |||
146 | #if ( LIGHT_3 == 0 ) | ||
147 | v_light3Dir = ( u_viewMatrix * vec4( -u_light3Dir, 0.0 ) ).xyz; | ||
148 | #else | ||
149 | v_light3Dir = lpos - v_mvPos; | ||
150 | #if ( LIGHT_3 == 2 ) | ||
151 | v_light3SpotDir = (u_viewMatrix * vec4( -u_light3Dir, 0.0 )).xyz; | ||
152 | #endif // ( LIGHT_3 == 2 ) | ||
153 | #endif // ( LIGHT_3 == 0 ) | ||
154 | } | ||
155 | #endif // defined( LIGHT_3 ) | ||
156 | #endif // defined( LIGHTING ) | ||
157 | |||
158 | // pass along the geo | ||
159 | gl_Position = u_projMatrix * vec4(v_mvPos, 1.0); | ||
160 | } | ||
161 | #endif | ||
162 | |||