aboutsummaryrefslogtreecommitdiff
path: root/assets/shaders/ub_vshader.glsl
blob: ff0c09b49babdef80848bdb44069542d090aaf1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* <copyright>
This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
(c) Copyright 2011 Motorola Mobility, Inc.  All Rights Reserved.
</copyright> */

// attributes
attribute vec3 a_pos;
attribute vec3 a_normal;
attribute vec2 a_texcoord;

// uniforms
uniform mat4 u_worldMatrix;
uniform mat4 u_viewMatrix;
uniform mat4 u_projMatrix;
uniform mat4 u_mvMatrix;
uniform mat4 u_normalMatrix;
uniform mat4 u_uvMatrix;
uniform vec3 u_eye;

// attributes
#if defined( MATERIAL )
	uniform vec4		u_ambientColor;
	uniform vec4		u_diffuseColor;
	uniform vec4		u_specularColor;
	uniform float		u_specularPower;
#endif

#if defined( LIGHTING )
	varying vec3 v_normal;
	#if defined( LIGHT_0 )
		uniform int		u_light0Type;
		uniform vec3	u_light0Pos;
		uniform vec3	u_light0Dir;
		uniform vec3	u_light0Atten;
		uniform vec2	u_light0Spot;
		uniform vec4	u_light0Color;
		uniform vec4	u_light0Specular;		
		varying vec3	v_light0Dir;
		varying vec3	v_light0SpotDir;		
	#endif

	#if defined( LIGHT_1 )
		uniform int		u_light1Type;
		uniform vec3	u_light1Pos;
		uniform vec3	u_light1Dir;
		uniform vec3	u_light1Atten;
		uniform vec2	u_light1Spot;
		uniform vec3	u_light1Color;
		uniform vec4	u_light1Specular;		
		varying vec3	v_light1Dir;
		varying vec3	v_light1SpotDir;		
	#endif

	#if defined( LIGHT_2 )
		uniform int		u_light2Type;	// 0 - dir, 1 - point, 2 - spot
		uniform vec3	u_light2Pos;
		uniform vec3	u_light2Dir;
		uniform vec3	u_light2Atten;
		uniform vec2	u_light2Spot;	// 0 - spot light cutoff angle, 1 - spot light exponent
		uniform vec3	u_light2Color;
		uniform vec4	u_light2Specular;				
		varying vec3	v_light2Dir;
		varying vec3	v_light2SpotDir;		
	#endif

	#if defined( LIGHT_3 )
		uniform int		u_light3Type;
		uniform vec3	u_light3Pos;
		uniform vec3	u_light3Dir;
		uniform vec3	u_light3Atten;
		uniform vec2	u_light3Spot;
		uniform vec3	u_light3Color;
		uniform vec4	u_light3Specular;				
		varying vec3	v_light3Dir;
		varying vec3	v_light3SpotDir;		
	#endif
#endif

#if defined( ENVIRONMENT_MAP )
	uniform float u_envReflection;
#endif

varying vec3 v_mvPos;
varying vec3 v_eyeDir;
varying vec2 v_texcoord;

#if defined( PC )
void main() {
	//	position normals and vert
	v_mvPos = ( u_mvMatrix * vec4( a_pos, 1.0 ) ).xyz;

	v_texcoord = (u_uvMatrix * vec4(a_texcoord, 0, 1.0)).xy;
#if ( defined( LIGHTING ) || defined( ENVIRONMENT_MAP ) )
	v_normal = ( u_normalMatrix * vec4( a_normal, 0.0 ) ).xyz;
#endif

#if defined( LIGHTING )
	v_eyeDir = vec3(-u_viewMatrix[3][0], -u_viewMatrix[3][1], -u_viewMatrix[3][2]);
	#if defined( LIGHT_0 )
		{
			vec3	lpos = ( u_viewMatrix * vec4( u_light0Pos, 1.0 ) ).xyz;		
			
			#if ( LIGHT_0 == 0 )
				v_light0Dir = ( u_viewMatrix * vec4( -u_light0Dir, 0.0 ) ).xyz;
			#else
				v_light0Dir = lpos - v_mvPos;
				#if ( LIGHT_0 == 2 )
					v_light0SpotDir = (u_viewMatrix * vec4( -u_light0Dir, 0.0 )).xyz;			
				#endif // ( LIGHT_0 == 2 )
			#endif // ( LIGHT_0 == 0 )
		}
	#endif // defined( LIGHT_0 )	
	#if defined( LIGHT_1 )
		{
			vec3	lpos = ( u_viewMatrix * vec4( u_light1Pos, 1.0 ) ).xyz;		
			
			#if ( LIGHT_1 == 0 )
				v_light1Dir = ( u_viewMatrix * vec4( -u_light1Dir, 0.0 ) ).xyz;
			#else
				v_light1Dir = lpos - v_mvPos;
				#if ( LIGHT_1 == 2 )
					v_light1SpotDir = (u_viewMatrix * vec4( -u_light1Dir, 0.0 )).xyz;			
				#endif // ( LIGHT_1 == 2 )
			#endif // ( LIGHT_1 == 0 )
		}
	#endif // defined( LIGHT_1 )
	#if defined( LIGHT_2 )
		{
			vec3	lpos = ( u_viewMatrix * vec4( u_light2Pos, 1.0 ) ).xyz;		
			
			#if ( LIGHT_2 == 0 )
				v_light2Dir = ( u_viewMatrix * vec4( -u_light2Dir, 0.0 ) ).xyz;
			#else
				v_light2Dir = lpos - v_mvPos;
				#if ( LIGHT_2 == 2 )
					v_light2SpotDir = (u_viewMatrix * vec4( -u_light2Dir, 0.0 )).xyz;			
				#endif // ( LIGHT_2 == 2 )
			#endif // ( LIGHT_2 == 0 )
		}
	#endif // defined( LIGHT_2 )
	#if defined( LIGHT_3 )
		{
			vec3	lpos = ( u_viewMatrix * vec4( u_light3Pos, 1.0 ) ).xyz;		
			
			#if ( LIGHT_3 == 0 )
				v_light3Dir = ( u_viewMatrix * vec4( -u_light3Dir, 0.0 ) ).xyz;
			#else
				v_light3Dir = lpos - v_mvPos;
				#if ( LIGHT_3 == 2 )
					v_light3SpotDir = (u_viewMatrix * vec4( -u_light3Dir, 0.0 )).xyz;			
				#endif // ( LIGHT_3 == 2 )
			#endif // ( LIGHT_3 == 0 )
		}
	#endif // defined( LIGHT_3 )		
#endif // defined( LIGHTING )

	//	pass along the geo
	gl_Position	= u_projMatrix * vec4(v_mvPos, 1.0);
}
#endif