diff options
Diffstat (limited to 'assets/shaders/ub_fshader.glsl')
-rw-r--r-- | assets/shaders/ub_fshader.glsl | 263 |
1 files changed, 263 insertions, 0 deletions
diff --git a/assets/shaders/ub_fshader.glsl b/assets/shaders/ub_fshader.glsl new file mode 100644 index 00000000..19a35b7d --- /dev/null +++ b/assets/shaders/ub_fshader.glsl | |||
@@ -0,0 +1,263 @@ | |||
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 | // defines | ||
8 | #if defined( GL_ES ) | ||
9 | precision highp float; | ||
10 | #endif | ||
11 | |||
12 | uniform mat4 u_viewMatrix; | ||
13 | |||
14 | #if defined( MATERIAL ) | ||
15 | uniform vec4 u_ambientColor; | ||
16 | uniform vec4 u_diffuseColor; | ||
17 | uniform vec4 u_specularColor; | ||
18 | uniform float u_specularPower; | ||
19 | #endif | ||
20 | |||
21 | #if defined( LIGHTING ) | ||
22 | varying vec3 v_normal; | ||
23 | #if defined( LIGHT_0 ) | ||
24 | // uniform int u_light0Type; | ||
25 | uniform vec3 u_light0Pos; | ||
26 | uniform vec3 u_light0Dir; | ||
27 | uniform vec3 u_light0Atten; | ||
28 | uniform vec2 u_light0Spot; | ||
29 | uniform vec4 u_light0Color; | ||
30 | uniform vec4 u_light0Specular; | ||
31 | varying vec3 v_light0Dir; | ||
32 | varying vec3 v_light0SpotDir; | ||
33 | #endif | ||
34 | |||
35 | #if defined( LIGHT_1 ) | ||
36 | // uniform int u_light1Type; | ||
37 | uniform vec3 u_light1Pos; | ||
38 | uniform vec3 u_light1Dir; | ||
39 | uniform vec3 u_light1Atten; | ||
40 | uniform vec2 u_light1Spot; | ||
41 | uniform vec4 u_light1Color; | ||
42 | uniform vec4 u_light1Specular; | ||
43 | varying vec3 v_light1Dir; | ||
44 | varying vec3 v_light1SpotDir; | ||
45 | #endif | ||
46 | |||
47 | #if defined( LIGHT_2 ) | ||
48 | // uniform int u_light2Type; | ||
49 | uniform vec3 u_light2Pos; | ||
50 | uniform vec3 u_light2Dir; | ||
51 | uniform vec3 u_light2Atten; | ||
52 | uniform vec2 u_light2Spot; | ||
53 | uniform vec4 u_light2Color; | ||
54 | uniform vec4 u_light2Specular; | ||
55 | varying vec3 v_light2Dir; | ||
56 | varying vec3 v_light2SpotDir; | ||
57 | #endif | ||
58 | |||
59 | #if defined( LIGHT_3 ) | ||
60 | // uniform int u_light3Type; | ||
61 | uniform vec3 u_light3Pos; | ||
62 | uniform vec3 u_light3Dir; | ||
63 | uniform vec3 u_light3Atten; | ||
64 | uniform vec2 u_light3Spot; | ||
65 | uniform vec4 u_light3Color; | ||
66 | uniform vec4 u_light3Specular; | ||
67 | varying vec3 v_light3Dir; | ||
68 | varying vec3 v_light3SpotDir; | ||
69 | #endif | ||
70 | #endif | ||
71 | |||
72 | #if defined( ENVIRONMENT_MAP ) | ||
73 | uniform float u_envReflection; | ||
74 | #endif | ||
75 | |||
76 | uniform vec3 u_eye; | ||
77 | |||
78 | uniform sampler2D s_diffuseMap; | ||
79 | uniform sampler2D s_normalMap; | ||
80 | uniform sampler2D s_envMap; | ||
81 | uniform sampler2D s_specMap; | ||
82 | |||
83 | varying vec3 v_mvPos; | ||
84 | varying vec3 v_eyeDir; | ||
85 | varying vec2 v_texcoord; | ||
86 | |||
87 | void main() { | ||
88 | // these are the four principle color elements making up the final fragment equation. | ||
89 | vec4 a = vec4(0.0,0.0,0.0,0.0); // ambient contribution | ||
90 | vec4 d = vec4(0.0,0.0,0.0,0.0); // diffuse contribution | ||
91 | vec4 s = vec4(0.0,0.0,0.0,0.0); // specular contribution | ||
92 | vec4 l = vec4(0.0,0.0,0.0,0.0); // lighting contribution | ||
93 | |||
94 | #if defined( MATERIAL ) | ||
95 | a += u_ambientColor; | ||
96 | d += u_diffuseColor; | ||
97 | #endif | ||
98 | |||
99 | #if defined( DIFFUSE_MAP ) | ||
100 | d *= texture2D(s_diffuseMap, v_texcoord); | ||
101 | #endif | ||
102 | |||
103 | #if ( defined( LIGHTING ) || defined( ENVIRONMENT_MAPPING ) ) | ||
104 | vec3 normal = normalize( v_normal ); | ||
105 | #endif | ||
106 | |||
107 | #if defined( LIGHTING ) | ||
108 | #if defined( NORMAL_MAP ) | ||
109 | vec4 normalMap = texture2D(s_normalMap, v_texcoord); | ||
110 | normalMap = vec4( (normalMap.xyz * 2.0 - 1.0), 0.0 ); | ||
111 | normal = normalize(normalMap.x*vec3(normal.z, 0.0, normal.x) + vec3(0.0, normalMap.y, 0.0) + normalMap.z*normal); | ||
112 | #endif // NORMAL_MAP | ||
113 | |||
114 | #if defined( LIGHT_0 ) | ||
115 | { | ||
116 | // diffuse lighting | ||
117 | float ldist = length( v_light0Dir.xyz ); | ||
118 | vec3 ldir = v_light0Dir.xyz / ldist; | ||
119 | |||
120 | float atten = 1.0; | ||
121 | |||
122 | #if ( LIGHT_0 > 0 ) | ||
123 | atten = 1.0 / ( u_light0Atten.x + u_light0Atten.y * ldist + u_light0Atten.z * ( ldist * ldist ) ); | ||
124 | #if (LIGHT_0 == 2) | ||
125 | float spotAngle = dot( ldir, normalize( v_light0SpotDir ) ); | ||
126 | float spotAtten = 0.0; | ||
127 | if ( spotAngle > u_light0Spot.y ) { | ||
128 | spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light0Spot.y ) / ( u_light0Spot.x - u_light0Spot.y ) ) ); | ||
129 | } | ||
130 | atten *= spotAtten; | ||
131 | #endif | ||
132 | #endif | ||
133 | |||
134 | float ndotl = max( 0.0, dot( normal, ldir ) ); | ||
135 | l += ndotl * atten * u_light0Color; | ||
136 | |||
137 | #if defined( LIGHT_0_SPECULAR ) | ||
138 | // specular contribution | ||
139 | vec3 halfAngleVec = normalize( normalize( v_light0Dir.xyz ) + vec3(0.0,0.0,1.0) ); | ||
140 | float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); | ||
141 | s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light0Specular); | ||
142 | #endif | ||
143 | } | ||
144 | #endif // LIGHT_0 | ||
145 | |||
146 | #if defined( LIGHT_1 ) | ||
147 | { | ||
148 | // diffuse lighting | ||
149 | float ldist = length( v_light1Dir.xyz ); | ||
150 | vec3 ldir = v_light1Dir.xyz / ldist; | ||
151 | |||
152 | float atten = 1.0; | ||
153 | |||
154 | #if ( LIGHT_1 > 0 ) | ||
155 | atten = 1.0 / ( u_light1Atten.x + u_light1Atten.y * ldist + u_light1Atten.z * ( ldist * ldist ) ); | ||
156 | #if (LIGHT_1 == 2) | ||
157 | float spotAngle = dot( ldir, normalize( v_light1SpotDir ) ); | ||
158 | float spotAtten = 0.0; | ||
159 | if ( spotAngle > u_light1Spot.y ) { | ||
160 | spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light1Spot.y ) / ( u_light1Spot.x - u_light1Spot.y ) ) ); | ||
161 | } | ||
162 | atten *= spotAtten; | ||
163 | #endif | ||
164 | #endif | ||
165 | |||
166 | float ndotl = max( 0.0, dot( normal, ldir ) ); | ||
167 | l += ndotl * atten * u_light1Color; | ||
168 | |||
169 | #if defined( LIGHT_1_SPECULAR ) | ||
170 | // specular contribution | ||
171 | vec3 halfAngleVec = normalize( normalize( v_light1Dir.xyz ) + vec3(0.0,0.0,1.0) ); | ||
172 | float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); | ||
173 | s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light1Specular); | ||
174 | #endif | ||
175 | } | ||
176 | #endif // LIGHT_1 | ||
177 | |||
178 | #if defined( LIGHT_2 ) | ||
179 | { | ||
180 | // diffuse lighting | ||
181 | float ldist = length( v_light2Dir.xyz ); | ||
182 | vec3 ldir = v_light2Dir.xyz / ldist; | ||
183 | |||
184 | float atten = 1.0; | ||
185 | |||
186 | #if ( LIGHT_2 > 0 ) | ||
187 | atten = 1.0 / ( u_light2Atten.x + u_light2Atten.y * ldist + u_light2Atten.z * ( ldist * ldist ) ); | ||
188 | #if (LIGHT_2 == 2) | ||
189 | float spotAngle = dot( ldir, normalize( v_light2SpotDir ) ); | ||
190 | float spotAtten = 0.0; | ||
191 | if ( spotAngle > u_light2Spot.y ) { | ||
192 | spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light2Spot.y ) / ( u_light2Spot.x - u_light2Spot.y ) ) ); | ||
193 | } | ||
194 | atten *= spotAtten; | ||
195 | #endif | ||
196 | #endif | ||
197 | |||
198 | float ndotl = max( 0.0, dot( normal, ldir ) ); | ||
199 | l += ndotl * atten * u_light2Color; | ||
200 | |||
201 | #if defined( LIGHT_2_SPECULAR ) | ||
202 | // specular contribution | ||
203 | vec3 halfAngleVec = normalize( normalize( v_light2Dir.xyz ) + vec3(0.0,0.0,1.0) ); | ||
204 | float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); | ||
205 | s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light2Specular); | ||
206 | #endif | ||
207 | } | ||
208 | #endif // LIGHT_2 | ||
209 | |||
210 | #if defined( LIGHT_3 ) | ||
211 | { | ||
212 | // diffuse lighting | ||
213 | float ldist = length( v_light3Dir.xyz ); | ||
214 | vec3 ldir = v_light3Dir.xyz / ldist; | ||
215 | |||
216 | float atten = 1.0; | ||
217 | |||
218 | #if ( LIGHT_3 > 0 ) | ||
219 | atten = 1.0 / ( u_light3Atten.x + u_light3Atten.y * ldist + u_light3Atten.z * ( ldist * ldist ) ); | ||
220 | #if (LIGHT_3 == 2) | ||
221 | float spotAngle = dot( ldir, normalize( v_light3SpotDir ) ); | ||
222 | float spotAtten = 0.0; | ||
223 | if ( spotAngle > u_light3Spot.y ) { | ||
224 | spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light3Spot.y ) / ( u_light3Spot.x - u_light3Spot.y ) ) ); | ||
225 | } | ||
226 | atten *= spotAtten; | ||
227 | #endif | ||
228 | #endif | ||
229 | |||