1 /**
  2  * @author alteredq / http://alteredqualia.com/
  3  * @author mrdoob / http://mrdoob.com/
  4  *
  5  * ShaderUtils currently contains:
  6  *
  7  *	fresnel
  8  *	normal
  9  * 	cube
 10  *
 11  */
 12 
 13 /**@namespace*/
 14 THREE.ShaderUtils = {
 15 
 16 	lib: {
 17 
 18 		/* -------------------------------------------------------------------------
 19 		//	Fresnel shader
 20 		//	- based on Nvidia Cg tutorial
 21 		 ------------------------------------------------------------------------- */
 22 
 23 		'fresnel': {
 24 
 25 			uniforms: {
 26 
 27 				"mRefractionRatio": { type: "f", value: 1.02 },
 28 				"mFresnelBias": { type: "f", value: 0.1 },
 29 				"mFresnelPower": { type: "f", value: 2.0 },
 30 				"mFresnelScale": { type: "f", value: 1.0 },
 31 				"tCube": { type: "t", value: null }
 32 
 33 			},
 34 
 35 			fragmentShader: [
 36 
 37 				"uniform samplerCube tCube;",
 38 
 39 				"varying vec3 vReflect;",
 40 				"varying vec3 vRefract[3];",
 41 				"varying float vReflectionFactor;",
 42 
 43 				"void main() {",
 44 
 45 					"vec4 reflectedColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );",
 46 					"vec4 refractedColor = vec4( 1.0 );",
 47 
 48 					"refractedColor.r = textureCube( tCube, vec3( -vRefract[0].x, vRefract[0].yz ) ).r;",
 49 					"refractedColor.g = textureCube( tCube, vec3( -vRefract[1].x, vRefract[1].yz ) ).g;",
 50 					"refractedColor.b = textureCube( tCube, vec3( -vRefract[2].x, vRefract[2].yz ) ).b;",
 51 
 52 					"gl_FragColor = mix( refractedColor, reflectedColor, clamp( vReflectionFactor, 0.0, 1.0 ) );",
 53 
 54 				"}"
 55 
 56 			].join("\n"),
 57 
 58 			vertexShader: [
 59 
 60 				"uniform float mRefractionRatio;",
 61 				"uniform float mFresnelBias;",
 62 				"uniform float mFresnelScale;",
 63 				"uniform float mFresnelPower;",
 64 
 65 				"varying vec3 vReflect;",
 66 				"varying vec3 vRefract[3];",
 67 				"varying float vReflectionFactor;",
 68 
 69 				"void main() {",
 70 
 71 					"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
 72 					"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
 73 
 74 					"vec3 worldNormal = normalize( mat3( modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz ) * normal );",
 75 
 76 					"vec3 I = worldPosition.xyz - cameraPosition;",
 77 
 78 					"vReflect = reflect( I, worldNormal );",
 79 					"vRefract[0] = refract( normalize( I ), worldNormal, mRefractionRatio );",
 80 					"vRefract[1] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.99 );",
 81 					"vRefract[2] = refract( normalize( I ), worldNormal, mRefractionRatio * 0.98 );",
 82 					"vReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), worldNormal ), mFresnelPower );",
 83 
 84 					"gl_Position = projectionMatrix * mvPosition;",
 85 
 86 				"}"
 87 
 88 			].join("\n")
 89 
 90 		},
 91 
 92 		/* -------------------------------------------------------------------------
 93 		//	Normal map shader
 94 		//		- Blinn-Phong
 95 		//		- normal + diffuse + specular + AO + displacement + reflection + shadow maps
 96 		//		- point and directional lights (use with "lights: true" material option)
 97 		 ------------------------------------------------------------------------- */
 98 
 99 		'normal' : {
100 
101 			uniforms: THREE.UniformsUtils.merge( [
102 
103 				THREE.UniformsLib[ "fog" ],
104 				THREE.UniformsLib[ "lights" ],
105 				THREE.UniformsLib[ "shadowmap" ],
106 
107 				{
108 
109 				"enableAO"		  : { type: "i", value: 0 },
110 				"enableDiffuse"	  : { type: "i", value: 0 },
111 				"enableSpecular"  : { type: "i", value: 0 },
112 				"enableReflection": { type: "i", value: 0 },
113 				"enableDisplacement": { type: "i", value: 0 },
114 
115 				"tDisplacement": { type: "t", value: null }, // must go first as this is vertex texture
116 				"tDiffuse"	   : { type: "t", value: null },
117 				"tCube"		   : { type: "t", value: null },
118 				"tNormal"	   : { type: "t", value: null },
119 				"tSpecular"	   : { type: "t", value: null },
120 				"tAO"		   : { type: "t", value: null },
121 
122 				"uNormalScale": { type: "v2", value: new THREE.Vector2( 1, 1 ) },
123 
124 				"uDisplacementBias": { type: "f", value: 0.0 },
125 				"uDisplacementScale": { type: "f", value: 1.0 },
126 
127 				"uDiffuseColor": { type: "c", value: new THREE.Color( 0xffffff ) },
128 				"uSpecularColor": { type: "c", value: new THREE.Color( 0x111111 ) },
129 				"uAmbientColor": { type: "c", value: new THREE.Color( 0xffffff ) },
130 				"uShininess": { type: "f", value: 30 },
131 				"uOpacity": { type: "f", value: 1 },
132 
133 				"useRefract": { type: "i", value: 0 },
134 				"uRefractionRatio": { type: "f", value: 0.98 },
135 				"uReflectivity": { type: "f", value: 0.5 },
136 
137 				"uOffset" : { type: "v2", value: new THREE.Vector2( 0, 0 ) },
138 				"uRepeat" : { type: "v2", value: new THREE.Vector2( 1, 1 ) },
139 
140 				"wrapRGB"  : { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
141 
142 				}
143 
144 			] ),
145 
146 			fragmentShader: [
147 
148 				"uniform vec3 uAmbientColor;",
149 				"uniform vec3 uDiffuseColor;",
150 				"uniform vec3 uSpecularColor;",
151 				"uniform float uShininess;",
152 				"uniform float uOpacity;",
153 
154 				"uniform bool enableDiffuse;",
155 				"uniform bool enableSpecular;",
156 				"uniform bool enableAO;",
157 				"uniform bool enableReflection;",
158 
159 				"uniform sampler2D tDiffuse;",
160 				"uniform sampler2D tNormal;",
161 				"uniform sampler2D tSpecular;",
162 				"uniform sampler2D tAO;",
163 
164 				"uniform samplerCube tCube;",
165 
166 				"uniform vec2 uNormalScale;",
167 
168 				"uniform bool useRefract;",
169 				"uniform float uRefractionRatio;",
170 				"uniform float uReflectivity;",
171 
172 				"varying vec3 vTangent;",
173 				"varying vec3 vBinormal;",
174 				"varying vec3 vNormal;",
175 				"varying vec2 vUv;",
176 
177 				"uniform vec3 ambientLightColor;",
178 
179 				"#if MAX_DIR_LIGHTS > 0",
180 
181 					"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];",
182 					"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",
183 
184 				"#endif",
185 
186 				"#if MAX_HEMI_LIGHTS > 0",
187 
188 					"uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];",
189 					"uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];",
190 					"uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];",
191 
192 				"#endif",
193 
194 				"#if MAX_POINT_LIGHTS > 0",
195 
196 					"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
197 					"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
198 					"uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
199 
200 				"#endif",
201 
202 				"#if MAX_SPOT_LIGHTS > 0",
203 
204 					"uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];",
205 					"uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];",
206 					"uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];",
207 					"uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];",
208 					"uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];",
209 					"uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];",
210 
211 				"#endif",
212 
213 				"#ifdef WRAP_AROUND",
214 
215 					"uniform vec3 wrapRGB;",
216 
217 				"#endif",
218 
219 				"varying vec3 vWorldPosition;",
220 				"varying vec3 vViewPosition;",
221 
222 				THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
223 				THREE.ShaderChunk[ "fog_pars_fragment" ],
224 
225 				"void main() {",
226 
227 					"gl_FragColor = vec4( vec3( 1.0 ), uOpacity );",
228 
229 					"vec3 specularTex = vec3( 1.0 );",
230 
231 					"vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;",
232 					"normalTex.xy *= uNormalScale;",
233 					"normalTex = normalize( normalTex );",
234 
235 					"if( enableDiffuse ) {",
236 
237 						"#ifdef GAMMA_INPUT",
238 
239 							"vec4 texelColor = texture2D( tDiffuse, vUv );",
240 							"texelColor.xyz *= texelColor.xyz;",
241 
242 							"gl_FragColor = gl_FragColor * texelColor;",
243 
244 						"#else",
245 
246 							"gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );",
247 
248 						"#endif",
249 
250 					"}",
251 
252 					"if( enableAO ) {",
253 
254 						"#ifdef GAMMA_INPUT",
255 
256 							"vec4 aoColor = texture2D( tAO, vUv );",
257 							"aoColor.xyz *= aoColor.xyz;",
258 
259 							"gl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;",
260 
261 						"#else",
262 
263 							"gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;",
264 
265 						"#endif",
266 
267 					"}",
268 
269 					"if( enableSpecular )",
270 						"specularTex = texture2D( tSpecular, vUv ).xyz;",
271 
272 					"mat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );",
273 					"vec3 finalNormal = tsb * normalTex;",
274 
275 					"#ifdef FLIP_SIDED",
276 
277 						"finalNormal = -finalNormal;",
278 
279 					"#endif",
280 
281 					"vec3 normal = normalize( finalNormal );",
282 					"vec3 viewPosition = normalize( vViewPosition );",
283 
284 					// point lights
285 
286 					"#if MAX_POINT_LIGHTS > 0",
287 
288 						"vec3 pointDiffuse = vec3( 0.0 );",
289 						"vec3 pointSpecular = vec3( 0.0 );",
290 
291 						"for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
292 
293 							"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
294 							"vec3 pointVector = lPosition.xyz + vViewPosition.xyz;",
295 
296 							"float pointDistance = 1.0;",
297 							"if ( pointLightDistance[ i ] > 0.0 )",
298 								"pointDistance = 1.0 - min( ( length( pointVector ) / pointLightDistance[ i ] ), 1.0 );",
299 
300 							"pointVector = normalize( pointVector );",
301 
302 							// diffuse
303 
304 							"#ifdef WRAP_AROUND",
305 
306 								"float pointDiffuseWeightFull = max( dot( normal, pointVector ), 0.0 );",
307 								"float pointDiffuseWeightHalf = max( 0.5 * dot( normal, pointVector ) + 0.5, 0.0 );",
308 
309 								"vec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );",
310 
311 							"#else",
312 
313 								"float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );",
314 
315 							"#endif",
316 
317 							"pointDiffuse += pointDistance * pointLightColor[ i ] * uDiffuseColor * pointDiffuseWeight;",
318 
319 							// specular
320 
321 							"vec3 pointHalfVector = normalize( pointVector + viewPosition );",
322 							"float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
323 							"float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, uShininess ), 0.0 );",
324 
325 							"#ifdef PHYSICALLY_BASED_SHADING",
326 
327 								// 2.0 => 2.0001 is hack to work around ANGLE bug
328 
329 								"float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
330 
331 								"vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( pointVector, pointHalfVector ), 5.0 );",
332 								"pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * pointDistance * specularNormalization;",
333 
334 							"#else",
335 
336 								"pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;",
337 
338 							"#endif",
339 
340 						"}",
341 
342 					"#endif",
343 
344 					// spot lights
345 
346 					"#if MAX_SPOT_LIGHTS > 0",
347 
348 						"vec3 spotDiffuse = vec3( 0.0 );",
349 						"vec3 spotSpecular = vec3( 0.0 );",
350 
351 						"for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {",
352 
353 							"vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );",
354 							"vec3 spotVector = lPosition.xyz + vViewPosition.xyz;",
355 
356 							"float spotDistance = 1.0;",
357 							"if ( spotLightDistance[ i ] > 0.0 )",
358 								"spotDistance = 1.0 - min( ( length( spotVector ) / spotLightDistance[ i ] ), 1.0 );",
359 
360 							"spotVector = normalize( spotVector );",
361 
362 							"float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );",
363 
364 							"if ( spotEffect > spotLightAngleCos[ i ] ) {",
365 
366 								"spotEffect = max( pow( spotEffect, spotLightExponent[ i ] ), 0.0 );",
367 
368 								// diffuse
369 
370 								"#ifdef WRAP_AROUND",
371 
372 									"float spotDiffuseWeightFull = max( dot( normal, spotVector ), 0.0 );",
373 									"float spotDiffuseWeightHalf = max( 0.5 * dot( normal, spotVector ) + 0.5, 0.0 );",
374 
375 									"vec3 spotDiffuseWeight = mix( vec3 ( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );",
376 
377 								"#else",
378 
379 									"float spotDiffuseWeight = max( dot( normal, spotVector ), 0.0 );",
380 
381 								"#endif",
382 
383 								"spotDiffuse += spotDistance * spotLightColor[ i ] * uDiffuseColor * spotDiffuseWeight * spotEffect;",
384 
385 								// specular
386 
387 								"vec3 spotHalfVector = normalize( spotVector + viewPosition );",
388 								"float spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );",
389 								"float spotSpecularWeight = specularTex.r * max( pow( spotDotNormalHalf, uShininess ), 0.0 );",
390 
391 								"#ifdef PHYSICALLY_BASED_SHADING",
392 
393 									// 2.0 => 2.0001 is hack to work around ANGLE bug
394 
395 									"float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
396 
397 									"vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( spotVector, spotHalfVector ), 5.0 );",
398 									"spotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * spotDistance * specularNormalization * spotEffect;",
399 
400 								"#else",
401 
402 									"spotSpecular += spotDistance * spotLightColor[ i ] * uSpecularColor * spotSpecularWeight * spotDiffuseWeight * spotEffect;",
403 
404 								"#endif",
405 
406 							"}",
407 
408 						"}",
409 
410 					"#endif",
411 
412 					// directional lights
413 
414 					"#if MAX_DIR_LIGHTS > 0",
415 
416 						"vec3 dirDiffuse = vec3( 0.0 );",
417 						"vec3 dirSpecular = vec3( 0.0 );",
418 
419 						"for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {",
420 
421 							"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
422 							"vec3 dirVector = normalize( lDirection.xyz );",
423 
424 							// diffuse
425 
426 							"#ifdef WRAP_AROUND",
427 
428 								"float directionalLightWeightingFull = max( dot( normal, dirVector ), 0.0 );",
429 								"float directionalLightWeightingHalf = max( 0.5 * dot( normal, dirVector ) + 0.5, 0.0 );",
430 
431 								"vec3 dirDiffuseWeight = mix( vec3( directionalLightWeightingFull ), vec3( directionalLightWeightingHalf ), wrapRGB );",
432 
433 							"#else",
434 
435 								"float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
436 
437 							"#endif",
438 
439 							"dirDiffuse += directionalLightColor[ i ] * uDiffuseColor * dirDiffuseWeight;",
440 
441 							// specular
442 
443 							"vec3 dirHalfVector = normalize( dirVector + viewPosition );",
444 							"float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
445 							"float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, uShininess ), 0.0 );",
446 
447 							"#ifdef PHYSICALLY_BASED_SHADING",
448 
449 								// 2.0 => 2.0001 is hack to work around ANGLE bug
450 
451 								"float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
452 
453 								"vec3 schlick = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( dirVector, dirHalfVector ), 5.0 );",
454 								"dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;",
455 
456 							"#else",
457 
458 								"dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;",
459 
460 							"#endif",
461 
462 						"}",
463 
464 					"#endif",
465 
466 					// hemisphere lights
467 
468 					"#if MAX_HEMI_LIGHTS > 0",
469 
470 						"vec3 hemiDiffuse  = vec3( 0.0 );",
471 						"vec3 hemiSpecular = vec3( 0.0 );" ,
472 
473 						"for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {",
474 
475 							"vec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );",
476 							"vec3 lVector = normalize( lDirection.xyz );",
477 
478 							// diffuse
479 
480 							"float dotProduct = dot( normal, lVector );",
481 							"float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
482 
483 							"vec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
484 
485 							"hemiDiffuse += uDiffuseColor * hemiColor;",
486 
487 							// specular (sky light)
488 
489 
490 							"vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );",
491 							"float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;",
492 							"float hemiSpecularWeightSky = specularTex.r * max( pow( hemiDotNormalHalfSky, uShininess ), 0.0 );",
493 
494 							// specular (ground light)
495 
496 							"vec3 lVectorGround = -lVector;",
497 
498 							"vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );",
499 							"float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
500 							"float hemiSpecularWeightGround = specularTex.r * max( pow( hemiDotNormalHalfGround, uShininess ), 0.0 );",
501 
502 							"#ifdef PHYSICALLY_BASED_SHADING",
503 
504 								"float dotProductGround = dot( normal, lVectorGround );",
505 
506 								// 2.0 => 2.0001 is hack to work around ANGLE bug
507 
508 								"float specularNormalization = ( uShininess + 2.0001 ) / 8.0;",
509 
510 								"vec3 schlickSky = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( lVector, hemiHalfVectorSky ), 5.0 );",
511 								"vec3 schlickGround = uSpecularColor + vec3( 1.0 - uSpecularColor ) * pow( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 5.0 );",
512 								"hemiSpecular += hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );",
513 
514 							"#else",
515 
516 								"hemiSpecular += uSpecularColor * hemiColor * ( hemiSpecularWeightSky + hemiSpecularWeightGround ) * hemiDiffuseWeight;",
517 
518 							"#endif",
519 
520 						"}",
521 
522 					"#endif",
523 
524 					// all lights contribution summation
525 
526 					"vec3 totalDiffuse = vec3( 0.0 );",
527 					"vec3 totalSpecular = vec3( 0.0 );",
528 
529 					"#if MAX_DIR_LIGHTS > 0",
530 
531 						"totalDiffuse += dirDiffuse;",
532 						"totalSpecular += dirSpecular;",
533 
534 					"#endif",
535 
536 					"#if MAX_HEMI_LIGHTS > 0",
537 
538 						"totalDiffuse += hemiDiffuse;",
539 						"totalSpecular += hemiSpecular;",
540 
541 					"#endif",
542 
543 					"#if MAX_POINT_LIGHTS > 0",
544 
545 						"totalDiffuse += pointDiffuse;",
546 						"totalSpecular += pointSpecular;",
547 
548 					"#endif",
549 
550 					"#if MAX_SPOT_LIGHTS > 0",
551 
552 						"totalDiffuse += spotDiffuse;",
553 						"totalSpecular += spotSpecular;",
554 
555 					"#endif",
556 
557 					"#ifdef METAL",
558 
559 						"gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor + totalSpecular );",
560 
561 					"#else",
562 
563 						"gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor ) + totalSpecular;",
564 
565 					"#endif",
566 
567 					"if ( enableReflection ) {",
568 
569 						"vec3 vReflect;",
570 						"vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );",
571 
572 						"if ( useRefract ) {",
573 
574 							"vReflect = refract( cameraToVertex, normal, uRefractionRatio );",
575 
576 						"} else {",
577 
578 							"vReflect = reflect( cameraToVertex, normal );",
579 
580 						"}",
581 
582 						"vec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );",
583 
584 						"#ifdef GAMMA_INPUT",
585 
586 							"cubeColor.xyz *= cubeColor.xyz;",
587 
588 						"#endif",
589 
590 						"gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * uReflectivity );",
591 
592 					"}",
593 
594 					THREE.ShaderChunk[ "shadowmap_fragment" ],
595 					THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
596 					THREE.ShaderChunk[ "fog_fragment" ],
597 
598 				"}"
599 
600 			].join("\n"),
601 
602 			vertexShader: [
603 
604 				"attribute vec4 tangent;",
605 
606 				"uniform vec2 uOffset;",
607 				"uniform vec2 uRepeat;",
608 
609 				"uniform bool enableDisplacement;",
610 
611 				"#ifdef VERTEX_TEXTURES",
612 
613 					"uniform sampler2D tDisplacement;",
614 					"uniform float uDisplacementScale;",
615 					"uniform float uDisplacementBias;",
616 
617 				"#endif",
618 
619 				"varying vec3 vTangent;",
620 				"varying vec3 vBinormal;",
621 				"varying vec3 vNormal;",
622 				"varying vec2 vUv;",
623 
624 				"varying vec3 vWorldPosition;",
625 				"varying vec3 vViewPosition;",
626 
627 				THREE.ShaderChunk[ "skinning_pars_vertex" ],
628 				THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
629 
630 				"void main() {",
631 
632 					THREE.ShaderChunk[ "skinbase_vertex" ],
633 					THREE.ShaderChunk[ "skinnormal_vertex" ],
634 
635 					// normal, tangent and binormal vectors
636 
637 					"#ifdef USE_SKINNING",
638 
639 						"vNormal = normalize( normalMatrix * skinnedNormal.xyz );",
640 
641 						"vec4 skinnedTangent = skinMatrix * vec4( tangent.xyz, 0.0 );",
642 						"vTangent = normalize( normalMatrix * skinnedTangent.xyz );",
643 
644 					"#else",
645 
646 						"vNormal = normalize( normalMatrix * normal );",
647 						"vTangent = normalize( normalMatrix * tangent.xyz );",
648 
649 					"#endif",
650 
651 					"vBinormal = normalize( cross( vNormal, vTangent ) * tangent.w );",
652 
653 					"vUv = uv * uRepeat + uOffset;",
654 
655 					// displacement mapping
656 
657 					"vec3 displacedPosition;",
658 
659 					"#ifdef VERTEX_TEXTURES",
660 
661 						"if ( enableDisplacement ) {",
662 
663 							"vec3 dv = texture2D( tDisplacement, uv ).xyz;",
664 							"float df = uDisplacementScale * dv.x + uDisplacementBias;",
665 							"displacedPosition = position + normalize( normal ) * df;",
666 
667 						"} else {",
668 
669 							"#ifdef USE_SKINNING",
670 
671 								"vec4 skinVertex = vec4( position, 1.0 );",
672 
673 								"vec4 skinned  = boneMatX * skinVertex * skinWeight.x;",
674 								"skinned 	  += boneMatY * skinVertex * skinWeight.y;",
675 
676 								"displacedPosition  = skinned.xyz;",
677 
678 							"#else",
679 
680 								"displacedPosition = position;",
681 
682 							"#endif",
683 
684 						"}",
685 
686 					"#else",
687 
688 						"#ifdef USE_SKINNING",
689 
690 							"vec4 skinVertex = vec4( position, 1.0 );",
691 
692 							"vec4 skinned  = boneMatX * skinVertex * skinWeight.x;",
693 							"skinned 	  += boneMatY * skinVertex * skinWeight.y;",
694 
695 							"displacedPosition  = skinned.xyz;",
696 
697 						"#else",
698 
699 							"displacedPosition = position;",
700 
701 						"#endif",
702 
703 					"#endif",
704 
705 					//
706 
707 					"vec4 mvPosition = modelViewMatrix * vec4( displacedPosition, 1.0 );",
708 					"vec4 worldPosition = modelMatrix * vec4( displacedPosition, 1.0 );",
709 
710 					"gl_Position = projectionMatrix * mvPosition;",
711 
712 					//
713 
714 					"vWorldPosition = worldPosition.xyz;",
715 					"vViewPosition = -mvPosition.xyz;",
716 
717 					// shadows
718 
719 					"#ifdef USE_SHADOWMAP",
720 
721 						"for( int i = 0; i < MAX_SHADOWS; i ++ ) {",
722 
723 							"vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;",
724 
725 						"}",
726 
727 					"#endif",
728 
729 				"}"
730 
731 			].join("\n")
732 
733 		},
734 
735 		/* -------------------------------------------------------------------------
736 		//	Cube map shader
737 		 ------------------------------------------------------------------------- */
738 
739 		'cube': {
740 
741 			uniforms: { "tCube": { type: "t", value: null },
742 						"tFlip": { type: "f", value: -1 } },
743 
744 			vertexShader: [
745 
746 				"varying vec3 vWorldPosition;",
747 
748 				"void main() {",
749 
750 					"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
751 					"vWorldPosition = worldPosition.xyz;",
752 
753 					"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
754 
755 				"}"
756 
757 			].join("\n"),
758 
759 			fragmentShader: [
760 
761 				"uniform samplerCube tCube;",
762 				"uniform float tFlip;",
763 
764 				"varying vec3 vWorldPosition;",
765 
766 				"void main() {",
767 
768 					"gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
769 
770 				"}"
771 
772 			].join("\n")
773 
774 		}
775 
776 	}
777 
778 };
779 

nike free rn new balance hombre baratas cinturones gucci ugg rebajas cinturon gucci ray ban baratas nike cortez peuterey mujer christian louboutin madrid mbt zapatos gafas ray ban baratas mbt ofertas air max blancas mbt barcelona nike air max 90 woolrich barcelona nike mujer botas ugg gafas de sol carrera aratas air max 2016 baratas oakley baratas nike air max 2016

mbt skor nike sverige louboutin skor hollister sverige polo ralph lauren skjorta woolrich jacka dam canada goose jacka woolrich jacka ray ban rea canada goose rea michael kors rea new balance skor ralph lauren skjorta new balance rea uggs sverige lacoste rea christian louboutin skor moncler jacka nike shox barbour jacka uggs rea