aboutsummaryrefslogtreecommitdiff
path: root/assets/shaders/ub_fshader.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'assets/shaders/ub_fshader.glsl')
-rwxr-xr-xassets/shaders/ub_fshader.glsl102
1 files changed, 51 insertions, 51 deletions
diff --git a/assets/shaders/ub_fshader.glsl b/assets/shaders/ub_fshader.glsl
index 840a97b6..9b37899d 100755
--- a/assets/shaders/ub_fshader.glsl
+++ b/assets/shaders/ub_fshader.glsl
@@ -51,9 +51,9 @@ uniform mat4 u_viewMatrix;
51 uniform vec3 u_light0Atten; 51 uniform vec3 u_light0Atten;
52 uniform vec2 u_light0Spot; 52 uniform vec2 u_light0Spot;
53 uniform vec4 u_light0Color; 53 uniform vec4 u_light0Color;
54 uniform vec4 u_light0Specular; 54 uniform vec4 u_light0Specular;
55 varying vec3 v_light0Dir; 55 varying vec3 v_light0Dir;
56 varying vec3 v_light0SpotDir; 56 varying vec3 v_light0SpotDir;
57 #endif 57 #endif
58 58
59 #if defined( LIGHT_1 ) 59 #if defined( LIGHT_1 )
@@ -63,9 +63,9 @@ uniform mat4 u_viewMatrix;
63 uniform vec3 u_light1Atten; 63 uniform vec3 u_light1Atten;
64 uniform vec2 u_light1Spot; 64 uniform vec2 u_light1Spot;
65 uniform vec4 u_light1Color; 65 uniform vec4 u_light1Color;
66 uniform vec4 u_light1Specular; 66 uniform vec4 u_light1Specular;
67 varying vec3 v_light1Dir; 67 varying vec3 v_light1Dir;
68 varying vec3 v_light1SpotDir; 68 varying vec3 v_light1SpotDir;
69 #endif 69 #endif
70 70
71 #if defined( LIGHT_2 ) 71 #if defined( LIGHT_2 )
@@ -75,9 +75,9 @@ uniform mat4 u_viewMatrix;
75 uniform vec3 u_light2Atten; 75 uniform vec3 u_light2Atten;
76 uniform vec2 u_light2Spot; 76 uniform vec2 u_light2Spot;
77 uniform vec4 u_light2Color; 77 uniform vec4 u_light2Color;
78 uniform vec4 u_light2Specular; 78 uniform vec4 u_light2Specular;
79 varying vec3 v_light2Dir; 79 varying vec3 v_light2Dir;
80 varying vec3 v_light2SpotDir; 80 varying vec3 v_light2SpotDir;
81 #endif 81 #endif
82 82
83 #if defined( LIGHT_3 ) 83 #if defined( LIGHT_3 )
@@ -87,9 +87,9 @@ uniform mat4 u_viewMatrix;
87 uniform vec3 u_light3Atten; 87 uniform vec3 u_light3Atten;
88 uniform vec2 u_light3Spot; 88 uniform vec2 u_light3Spot;
89 uniform vec4 u_light3Color; 89 uniform vec4 u_light3Color;
90 uniform vec4 u_light3Specular; 90 uniform vec4 u_light3Specular;
91 varying vec3 v_light3Dir; 91 varying vec3 v_light3Dir;
92 varying vec3 v_light3SpotDir; 92 varying vec3 v_light3SpotDir;
93 #endif 93 #endif
94#endif 94#endif
95 95
@@ -114,7 +114,7 @@ void main() {
114 vec4 d = vec4(0.0,0.0,0.0,0.0); // diffuse contribution 114 vec4 d = vec4(0.0,0.0,0.0,0.0); // diffuse contribution
115 vec4 s = vec4(0.0,0.0,0.0,0.0); // specular contribution 115 vec4 s = vec4(0.0,0.0,0.0,0.0); // specular contribution
116 vec4 l = vec4(0.0,0.0,0.0,0.0); // lighting contribution 116 vec4 l = vec4(0.0,0.0,0.0,0.0); // lighting contribution
117 117
118#if defined( MATERIAL ) 118#if defined( MATERIAL )
119 a += u_ambientColor; 119 a += u_ambientColor;
120 d += u_diffuseColor; 120 d += u_diffuseColor;
@@ -124,10 +124,10 @@ void main() {
124 d *= texture2D(s_diffuseMap, v_texcoord); 124 d *= texture2D(s_diffuseMap, v_texcoord);
125#endif 125#endif
126 126
127#if ( defined( LIGHTING ) || defined( ENVIRONMENT_MAPPING ) ) 127#if ( defined( LIGHTING ) || defined( ENVIRONMENT_MAPPING ) )
128 vec3 normal = normalize( v_normal ); 128 vec3 normal = normalize( v_normal );
129#endif 129#endif
130 130
131#if defined( LIGHTING ) 131#if defined( LIGHTING )
132 #if defined( NORMAL_MAP ) 132 #if defined( NORMAL_MAP )
133 vec4 normalMap = texture2D(s_normalMap, v_texcoord); 133 vec4 normalMap = texture2D(s_normalMap, v_texcoord);
@@ -136,25 +136,25 @@ void main() {
136 #endif // NORMAL_MAP 136 #endif // NORMAL_MAP
137 137
138 #if defined( LIGHT_0 ) 138 #if defined( LIGHT_0 )
139 { 139 {
140 // diffuse lighting 140 // diffuse lighting
141 float ldist = length( v_light0Dir.xyz ); 141 float ldist = length( v_light0Dir.xyz );
142 vec3 ldir = v_light0Dir.xyz / ldist; 142 vec3 ldir = v_light0Dir.xyz / ldist;
143 143
144 float atten = 1.0; 144 float atten = 1.0;
145 145
146 #if ( LIGHT_0 > 0 ) 146 #if ( LIGHT_0 > 0 )
147 atten = 1.0 / ( u_light0Atten.x + u_light0Atten.y * ldist + u_light0Atten.z * ( ldist * ldist ) ); 147 atten = 1.0 / ( u_light0Atten.x + u_light0Atten.y * ldist + u_light0Atten.z * ( ldist * ldist ) );
148 #if (LIGHT_0 == 2) 148 #if (LIGHT_0 == 2)
149 float spotAngle = dot( ldir, normalize( v_light0SpotDir ) ); 149 float spotAngle = dot( ldir, normalize( v_light0SpotDir ) );
150 float spotAtten = 0.0; 150 float spotAtten = 0.0;
151 if ( spotAngle > u_light0Spot.y ) { 151 if ( spotAngle > u_light0Spot.y ) {
152 spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light0Spot.y ) / ( u_light0Spot.x - u_light0Spot.y ) ) ); 152 spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light0Spot.y ) / ( u_light0Spot.x - u_light0Spot.y ) ) );
153 } 153 }
154 atten *= spotAtten; 154 atten *= spotAtten;
155 #endif 155 #endif
156 #endif 156 #endif
157 157
158 float ndotl = max( 0.0, dot( normal, ldir ) ); 158 float ndotl = max( 0.0, dot( normal, ldir ) );
159 l += ndotl * atten * u_light0Color; 159 l += ndotl * atten * u_light0Color;
160 160
@@ -166,27 +166,27 @@ void main() {
166 #endif 166 #endif
167 } 167 }
168 #endif // LIGHT_0 168 #endif // LIGHT_0
169 169
170 #if defined( LIGHT_1 ) 170 #if defined( LIGHT_1 )
171 { 171 {
172 // diffuse lighting 172 // diffuse lighting
173 float ldist = length( v_light1Dir.xyz ); 173 float ldist = length( v_light1Dir.xyz );
174 vec3 ldir = v_light1Dir.xyz / ldist; 174 vec3 ldir = v_light1Dir.xyz / ldist;
175 175
176 float atten = 1.0; 176 float atten = 1.0;
177 177
178 #if ( LIGHT_1 > 0 ) 178 #if ( LIGHT_1 > 0 )
179 atten = 1.0 / ( u_light1Atten.x + u_light1Atten.y * ldist + u_light1Atten.z * ( ldist * ldist ) ); 179 atten = 1.0 / ( u_light1Atten.x + u_light1Atten.y * ldist + u_light1Atten.z * ( ldist * ldist ) );
180 #if (LIGHT_1 == 2) 180 #if (LIGHT_1 == 2)
181 float spotAngle = dot( ldir, normalize( v_light1SpotDir ) ); 181 float spotAngle = dot( ldir, normalize( v_light1SpotDir ) );
182 float spotAtten = 0.0; 182 float spotAtten = 0.0;
183 if ( spotAngle > u_light1Spot.y ) { 183 if ( spotAngle > u_light1Spot.y ) {
184 spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light1Spot.y ) / ( u_light1Spot.x - u_light1Spot.y ) ) ); 184 spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light1Spot.y ) / ( u_light1Spot.x - u_light1Spot.y ) ) );
185 } 185 }
186 atten *= spotAtten; 186 atten *= spotAtten;
187 #endif 187 #endif
188 #endif 188 #endif
189 189
190 float ndotl = max( 0.0, dot( normal, ldir ) ); 190 float ndotl = max( 0.0, dot( normal, ldir ) );
191 l += ndotl * atten * u_light1Color; 191 l += ndotl * atten * u_light1Color;
192 192
@@ -198,27 +198,27 @@ void main() {
198 #endif 198 #endif
199 } 199 }
200 #endif // LIGHT_1 200 #endif // LIGHT_1
201 201
202 #if defined( LIGHT_2 ) 202 #if defined( LIGHT_2 )
203 { 203 {
204 // diffuse lighting 204 // diffuse lighting
205 float ldist = length( v_light2Dir.xyz ); 205 float ldist = length( v_light2Dir.xyz );
206 vec3 ldir = v_light2Dir.xyz / ldist; 206 vec3 ldir = v_light2Dir.xyz / ldist;
207 207
208 float atten = 1.0; 208 float atten = 1.0;
209 209
210 #if ( LIGHT_2 > 0 ) 210 #if ( LIGHT_2 > 0 )
211 atten = 1.0 / ( u_light2Atten.x + u_light2Atten.y * ldist + u_light2Atten.z * ( ldist * ldist ) ); 211 atten = 1.0 / ( u_light2Atten.x + u_light2Atten.y * ldist + u_light2Atten.z * ( ldist * ldist ) );
212 #if (LIGHT_2 == 2) 212 #if (LIGHT_2 == 2)
213 float spotAngle = dot( ldir, normalize( v_light2SpotDir ) ); 213 float spotAngle = dot( ldir, normalize( v_light2SpotDir ) );
214 float spotAtten = 0.0; 214 float spotAtten = 0.0;
215 if ( spotAngle > u_light2Spot.y ) { 215 if ( spotAngle > u_light2Spot.y ) {
216 spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light2Spot.y ) / ( u_light2Spot.x - u_light2Spot.y ) ) ); 216 spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light2Spot.y ) / ( u_light2Spot.x - u_light2Spot.y ) ) );
217 } 217 }
218 atten *= spotAtten; 218 atten *= spotAtten;
219 #endif 219 #endif
220 #endif 220 #endif
221 221
222 float ndotl = max( 0.0, dot( normal, ldir ) ); 222 float ndotl = max( 0.0, dot( normal, ldir ) );
223 l += ndotl * atten * u_light2Color; 223 l += ndotl * atten * u_light2Color;
224 224
@@ -228,29 +228,29 @@ void main() {
228 float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); 228 float ndoth = max( 0.0, dot( normal, halfAngleVec ) );
229 s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light2Specular); 229 s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light2Specular);
230 #endif 230 #endif
231 } 231 }
232 #endif // LIGHT_2 232 #endif // LIGHT_2
233 233
234 #if defined( LIGHT_3 ) 234 #if defined( LIGHT_3 )
235 { 235 {
236 // diffuse lighting 236 // diffuse lighting
237 float ldist = length( v_light3Dir.xyz ); 237 float ldist = length( v_light3Dir.xyz );
238 vec3 ldir = v_light3Dir.xyz / ldist; 238 vec3 ldir = v_light3Dir.xyz / ldist;
239 239
240 float atten = 1.0; 240 float atten = 1.0;
241 241
242 #if ( LIGHT_3 > 0 ) 242 #if ( LIGHT_3 > 0 )
243 atten = 1.0 / ( u_light3Atten.x + u_light3Atten.y * ldist + u_light3Atten.z * ( ldist * ldist ) ); 243 atten = 1.0 / ( u_light3Atten.x + u_light3Atten.y * ldist + u_light3Atten.z * ( ldist * ldist ) );