1 /**
  2  * @author alteredq / http://alteredqualia.com/
  3  * @author mrdoob / http://mrdoob.com/
  4  * @author mikael emtinger / http://gomo.se/
  5  */
  6 
  7 /**@namespace*/
  8 THREE.ShaderChunk = {
  9 
 10 	// FOG
 11 
 12 	fog_pars_fragment: [
 13 
 14 		"#ifdef USE_FOG",
 15 
 16 			"uniform vec3 fogColor;",
 17 
 18 			"#ifdef FOG_EXP2",
 19 
 20 				"uniform float fogDensity;",
 21 
 22 			"#else",
 23 
 24 				"uniform float fogNear;",
 25 				"uniform float fogFar;",
 26 
 27 			"#endif",
 28 
 29 		"#endif"
 30 
 31 	].join("\n"),
 32 
 33 	fog_fragment: [
 34 
 35 		"#ifdef USE_FOG",
 36 
 37 			"float depth = gl_FragCoord.z / gl_FragCoord.w;",
 38 
 39 			"#ifdef FOG_EXP2",
 40 
 41 				"const float LOG2 = 1.442695;",
 42 				"float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );",
 43 				"fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );",
 44 
 45 			"#else",
 46 
 47 				"float fogFactor = smoothstep( fogNear, fogFar, depth );",
 48 
 49 			"#endif",
 50 
 51 			"gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );",
 52 
 53 		"#endif"
 54 
 55 	].join("\n"),
 56 
 57 	// ENVIRONMENT MAP
 58 
 59 	envmap_pars_fragment: [
 60 
 61 		"#ifdef USE_ENVMAP",
 62 
 63 			"uniform float reflectivity;",
 64 			"uniform samplerCube envMap;",
 65 			"uniform float flipEnvMap;",
 66 			"uniform int combine;",
 67 
 68 			"#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )",
 69 
 70 				"uniform bool useRefract;",
 71 				"uniform float refractionRatio;",
 72 
 73 			"#else",
 74 
 75 				"varying vec3 vReflect;",
 76 
 77 			"#endif",
 78 
 79 		"#endif"
 80 
 81 	].join("\n"),
 82 
 83 	envmap_fragment: [
 84 
 85 		"#ifdef USE_ENVMAP",
 86 
 87 			"vec3 reflectVec;",
 88 
 89 			"#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP )",
 90 
 91 				"vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );",
 92 
 93 				"if ( useRefract ) {",
 94 
 95 					"reflectVec = refract( cameraToVertex, normal, refractionRatio );",
 96 
 97 				"} else { ",
 98 
 99 					"reflectVec = reflect( cameraToVertex, normal );",
100 
101 				"}",
102 
103 			"#else",
104 
105 				"reflectVec = vReflect;",
106 
107 			"#endif",
108 
109 			"#ifdef DOUBLE_SIDED",
110 
111 				"float flipNormal = ( -1.0 + 2.0 * float( gl_FrontFacing ) );",
112 				"vec4 cubeColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );",
113 
114 			"#else",
115 
116 				"vec4 cubeColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );",
117 
118 			"#endif",
119 
120 			"#ifdef GAMMA_INPUT",
121 
122 				"cubeColor.xyz *= cubeColor.xyz;",
123 
124 			"#endif",
125 
126 			"if ( combine == 1 ) {",
127 
128 				"gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularStrength * reflectivity );",
129 
130 			"} else if ( combine == 2 ) {",
131 
132 				"gl_FragColor.xyz += cubeColor.xyz * specularStrength * reflectivity;",
133 
134 			"} else {",
135 
136 				"gl_FragColor.xyz = mix( gl_FragColor.xyz, gl_FragColor.xyz * cubeColor.xyz, specularStrength * reflectivity );",
137 
138 			"}",
139 
140 		"#endif"
141 
142 	].join("\n"),
143 
144 	envmap_pars_vertex: [
145 
146 		"#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP )",
147 
148 			"varying vec3 vReflect;",
149 
150 			"uniform float refractionRatio;",
151 			"uniform bool useRefract;",
152 
153 		"#endif"
154 
155 	].join("\n"),
156 
157 	worldpos_vertex : [
158 
159 		"#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )",
160 
161 			"#ifdef USE_SKINNING",
162 
163 				"vec4 worldPosition = modelMatrix * skinned;",
164 
165 			"#endif",
166 
167 			"#if defined( USE_MORPHTARGETS ) && ! defined( USE_SKINNING )",
168 
169 				"vec4 worldPosition = modelMatrix * vec4( morphed, 1.0 );",
170 
171 			"#endif",
172 
173 			"#if ! defined( USE_MORPHTARGETS ) && ! defined( USE_SKINNING )",
174 
175 				"vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
176 
177 			"#endif",
178 
179 		"#endif"
180 
181 	].join("\n"),
182 
183 	envmap_vertex : [
184 
185 		"#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP )",
186 
187 			"vec3 worldNormal = mat3( modelMatrix[ 0 ].xyz, modelMatrix[ 1 ].xyz, modelMatrix[ 2 ].xyz ) * objectNormal;",
188 			"worldNormal = normalize( worldNormal );",
189 
190 			"vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );",
191 
192 			"if ( useRefract ) {",
193 
194 				"vReflect = refract( cameraToVertex, worldNormal, refractionRatio );",
195 
196 			"} else {",
197 
198 				"vReflect = reflect( cameraToVertex, worldNormal );",
199 
200 			"}",
201 
202 		"#endif"
203 
204 	].join("\n"),
205 
206 	// COLOR MAP (particles)
207 
208 	map_particle_pars_fragment: [
209 
210 		"#ifdef USE_MAP",
211 
212 			"uniform sampler2D map;",
213 
214 		"#endif"
215 
216 	].join("\n"),
217 
218 
219 	map_particle_fragment: [
220 
221 		"#ifdef USE_MAP",
222 
223 			"gl_FragColor = gl_FragColor * texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) );",
224 
225 		"#endif"
226 
227 	].join("\n"),
228 
229 	// COLOR MAP (triangles)
230 
231 	map_pars_vertex: [
232 
233 		"#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP )",
234 
235 			"varying vec2 vUv;",
236 			"uniform vec4 offsetRepeat;",
237 
238 		"#endif"
239 
240 	].join("\n"),
241 
242 	map_pars_fragment: [
243 
244 		"#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP )",
245 
246 			"varying vec2 vUv;",
247 
248 		"#endif",
249 
250 		"#ifdef USE_MAP",
251 
252 			"uniform sampler2D map;",
253 
254 		"#endif",
255 
256 	].join("\n"),
257 
258 	map_vertex: [
259 
260 		"#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP )",
261 
262 			"vUv = uv * offsetRepeat.zw + offsetRepeat.xy;",
263 
264 		"#endif"
265 
266 	].join("\n"),
267 
268 	map_fragment: [
269 
270 		"#ifdef USE_MAP",
271 
272 			"#ifdef GAMMA_INPUT",
273 
274 				"vec4 texelColor = texture2D( map, vUv );",
275 				"texelColor.xyz *= texelColor.xyz;",
276 
277 				"gl_FragColor = gl_FragColor * texelColor;",
278 
279 			"#else",
280 
281 				"gl_FragColor = gl_FragColor * texture2D( map, vUv );",
282 
283 			"#endif",
284 
285 		"#endif"
286 
287 	].join("\n"),
288 
289 	// LIGHT MAP
290 
291 	lightmap_pars_fragment: [
292 
293 		"#ifdef USE_LIGHTMAP",
294 
295 			"varying vec2 vUv2;",
296 			"uniform sampler2D lightMap;",
297 
298 		"#endif"
299 
300 	].join("\n"),
301 
302 	lightmap_pars_vertex: [
303 
304 		"#ifdef USE_LIGHTMAP",
305 
306 			"varying vec2 vUv2;",
307 
308 		"#endif"
309 
310 	].join("\n"),
311 
312 	lightmap_fragment: [
313 
314 		"#ifdef USE_LIGHTMAP",
315 
316 			"gl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );",
317 
318 		"#endif"
319 
320 	].join("\n"),
321 
322 	lightmap_vertex: [
323 
324 		"#ifdef USE_LIGHTMAP",
325 
326 			"vUv2 = uv2;",
327 
328 		"#endif"
329 
330 	].join("\n"),
331 
332 	// BUMP MAP
333 
334 	bumpmap_pars_fragment: [
335 
336 		"#ifdef USE_BUMPMAP",
337 
338 			"uniform sampler2D bumpMap;",
339 			"uniform float bumpScale;",
340 
341 			// Derivative maps - bump mapping unparametrized surfaces by Morten Mikkelsen
342 			//	http://mmikkelsen3d.blogspot.sk/2011/07/derivative-maps.html
343 
344 			// Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)
345 
346 			"vec2 dHdxy_fwd() {",
347 
348 				"vec2 dSTdx = dFdx( vUv );",
349 				"vec2 dSTdy = dFdy( vUv );",
350 
351 				"float Hll = bumpScale * texture2D( bumpMap, vUv ).x;",
352 				"float dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;",
353 				"float dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;",
354 
355 				"return vec2( dBx, dBy );",
356 
357 			"}",
358 
359 			"vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {",
360 
361 				"vec3 vSigmaX = dFdx( surf_pos );",
362 				"vec3 vSigmaY = dFdy( surf_pos );",
363 				"vec3 vN = surf_norm;",		// normalized
364 
365 				"vec3 R1 = cross( vSigmaY, vN );",
366 				"vec3 R2 = cross( vN, vSigmaX );",
367 
368 				"float fDet = dot( vSigmaX, R1 );",
369 
370 				"vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );",
371 				"return normalize( abs( fDet ) * surf_norm - vGrad );",
372 
373 			"}",
374 
375 		"#endif"
376 
377 	].join("\n"),
378 
379 	// NORMAL MAP
380 
381 	normalmap_pars_fragment: [
382 
383 		"#ifdef USE_NORMALMAP",
384 
385 			"uniform sampler2D normalMap;",
386 			"uniform vec2 normalScale;",
387 
388 			// Per-Pixel Tangent Space Normal Mapping
389 			// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html
390 
391 			"vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {",
392 
393 				"vec3 q0 = dFdx( eye_pos.xyz );",
394 				"vec3 q1 = dFdy( eye_pos.xyz );",
395 				"vec2 st0 = dFdx( vUv.st );",
396 				"vec2 st1 = dFdy( vUv.st );",
397 
398 				"vec3 S = normalize(  q0 * st1.t - q1 * st0.t );",
399 				"vec3 T = normalize( -q0 * st1.s + q1 * st0.s );",
400 				"vec3 N = normalize( surf_norm );",
401 
402 				"vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;",
403 				"mapN.xy = normalScale * mapN.xy;",
404 				"mat3 tsn = mat3( S, T, N );",
405 				"return normalize( tsn * mapN );",
406 
407 			"}",
408 
409 		"#endif"
410 
411 	].join("\n"),
412 
413 	// SPECULAR MAP
414 
415 	specularmap_pars_fragment: [
416 
417 		"#ifdef USE_SPECULARMAP",
418 
419 			"uniform sampler2D specularMap;",
420 
421 		"#endif"
422 
423 	].join("\n"),
424 
425 	specularmap_fragment: [
426 
427 		"float specularStrength;",
428 
429 		"#ifdef USE_SPECULARMAP",
430 
431 			"vec4 texelSpecular = texture2D( specularMap, vUv );",
432 			"specularStrength = texelSpecular.r;",
433 
434 		"#else",
435 
436 			"specularStrength = 1.0;",
437 
438 		"#endif"
439 
440 	].join("\n"),
441 
442 	// LIGHTS LAMBERT
443 
444 	lights_lambert_pars_vertex: [
445 
446 		"uniform vec3 ambient;",
447 		"uniform vec3 diffuse;",
448 		"uniform vec3 emissive;",
449 
450 		"uniform vec3 ambientLightColor;",
451 
452 		"#if MAX_DIR_LIGHTS > 0",
453 
454 			"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];",
455 			"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",
456 
457 		"#endif",
458 
459 		"#if MAX_HEMI_LIGHTS > 0",
460 
461 			"uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];",
462 			"uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];",
463 			"uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];",
464 
465 		"#endif",
466 
467 		"#if MAX_POINT_LIGHTS > 0",
468 
469 			"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
470 			"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
471 			"uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
472 
473 		"#endif",
474 
475 		"#if MAX_SPOT_LIGHTS > 0",
476 
477 			"uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];",
478 			"uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];",
479 			"uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];",
480 			"uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];",
481 			"uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];",
482 			"uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];",
483 
484 		"#endif",
485 
486 		"#ifdef WRAP_AROUND",
487 
488 			"uniform vec3 wrapRGB;",
489 
490 		"#endif"
491 
492 	].join("\n"),
493 
494 	lights_lambert_vertex: [
495 
496 		"vLightFront = vec3( 0.0 );",
497 
498 		"#ifdef DOUBLE_SIDED",
499 
500 			"vLightBack = vec3( 0.0 );",
501 
502 		"#endif",
503 
504 		"transformedNormal = normalize( transformedNormal );",
505 
506 		"#if MAX_DIR_LIGHTS > 0",
507 
508 		"for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {",
509 
510 			"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
511 			"vec3 dirVector = normalize( lDirection.xyz );",
512 
513 			"float dotProduct = dot( transformedNormal, dirVector );",
514 			"vec3 directionalLightWeighting = vec3( max( dotProduct, 0.0 ) );",
515 
516 			"#ifdef DOUBLE_SIDED",
517 
518 				"vec3 directionalLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );",
519 
520 				"#ifdef WRAP_AROUND",
521 
522 					"vec3 directionalLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );",
523 
524 				"#endif",
525 
526 			"#endif",
527 
528 			"#ifdef WRAP_AROUND",
529 
530 				"vec3 directionalLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );",
531 				"directionalLightWeighting = mix( directionalLightWeighting, directionalLightWeightingHalf, wrapRGB );",
532 
533 				"#ifdef DOUBLE_SIDED",
534 
535 					"directionalLightWeightingBack = mix( directionalLightWeightingBack, directionalLightWeightingHalfBack, wrapRGB );",
536 
537 				"#endif",
538 
539 			"#endif",
540 
541 			"vLightFront += directionalLightColor[ i ] * directionalLightWeighting;",
542 
543 			"#ifdef DOUBLE_SIDED",
544 
545 				"vLightBack += directionalLightColor[ i ] * directionalLightWeightingBack;",
546 
547 			"#endif",
548 
549 		"}",
550 
551 		"#endif",
552 
553 		"#if MAX_POINT_LIGHTS > 0",
554 
555 			"for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
556 
557 				"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
558 				"vec3 lVector = lPosition.xyz - mvPosition.xyz;",
559 
560 				"float lDistance = 1.0;",
561 				"if ( pointLightDistance[ i ] > 0.0 )",
562 					"lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
563 
564 				"lVector = normalize( lVector );",
565 				"float dotProduct = dot( transformedNormal, lVector );",
566 
567 				"vec3 pointLightWeighting = vec3( max( dotProduct, 0.0 ) );",
568 
569 				"#ifdef DOUBLE_SIDED",
570 
571 					"vec3 pointLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );",
572 
573 					"#ifdef WRAP_AROUND",
574 
575 						"vec3 pointLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );",
576 
577 					"#endif",
578 
579 				"#endif",
580 
581 				"#ifdef WRAP_AROUND",
582 
583 					"vec3 pointLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );",
584 					"pointLightWeighting = mix( pointLightWeighting, pointLightWeightingHalf, wrapRGB );",
585 
586 					"#ifdef DOUBLE_SIDED",
587 
588 						"pointLightWeightingBack = mix( pointLightWeightingBack, pointLightWeightingHalfBack, wrapRGB );",
589 
590 					"#endif",
591 
592 				"#endif",
593 
594 				"vLightFront += pointLightColor[ i ] * pointLightWeighting * lDistance;",
595 
596 				"#ifdef DOUBLE_SIDED",
597 
598 					"vLightBack += pointLightColor[ i ] * pointLightWeightingBack * lDistance;",
599 
600 				"#endif",
601 
602 			"}",
603 
604 		"#endif",
605 
606 		"#if MAX_SPOT_LIGHTS > 0",
607 
608 			"for( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {",
609 
610 				"vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );",
611 				"vec3 lVector = lPosition.xyz - mvPosition.xyz;",
612 
613 				"float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - worldPosition.xyz ) );",
614 
615 				"if ( spotEffect > spotLightAngleCos[ i ] ) {",
616 
617 					"spotEffect = max( pow( spotEffect, spotLightExponent[ i ] ), 0.0 );",
618 
619 					"float lDistance = 1.0;",
620 					"if ( spotLightDistance[ i ] > 0.0 )",
621 						"lDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );",
622 
623 					"lVector = normalize( lVector );",
624 
625 					"float dotProduct = dot( transformedNormal, lVector );",
626 					"vec3 spotLightWeighting = vec3( max( dotProduct, 0.0 ) );",
627 
628 					"#ifdef DOUBLE_SIDED",
629 
630 						"vec3 spotLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );",
631 
632 						"#ifdef WRAP_AROUND",
633 
634 							"vec3 spotLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );",
635 
636 						"#endif",
637 
638 					"#endif",
639 
640 					"#ifdef WRAP_AROUND",
641 
642 						"vec3 spotLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );",
643 						"spotLightWeighting = mix( spotLightWeighting, spotLightWeightingHalf, wrapRGB );",
644 
645 						"#ifdef DOUBLE_SIDED",
646 
647 							"spotLightWeightingBack = mix( spotLightWeightingBack, spotLightWeightingHalfBack, wrapRGB );",
648 
649 						"#endif",
650 
651 					"#endif",
652 
653 					"vLightFront += spotLightColor[ i ] * spotLightWeighting * lDistance * spotEffect;",
654 
655 					"#ifdef DOUBLE_SIDED",
656 
657 						"vLightBack += spotLightColor[ i ] * spotLightWeightingBack * lDistance * spotEffect;",
658 
659 					"#endif",
660 
661 				"}",
662 
663 			"}",
664 
665 		"#endif",
666 
667 		"#if MAX_HEMI_LIGHTS > 0",
668 
669 			"for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {",
670 
671 				"vec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );",
672 				"vec3 lVector = normalize( lDirection.xyz );",
673 
674 				"float dotProduct = dot( transformedNormal, lVector );",
675 
676 				"float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
677 				"float hemiDiffuseWeightBack = -0.5 * dotProduct + 0.5;",
678 
679 				"vLightFront += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
680 
681 				"#ifdef DOUBLE_SIDED",
682 
683 					"vLightBack += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeightBack );",
684 
685 				"#endif",
686 
687 			"}",
688 
689 		"#endif",
690 
691 		"vLightFront = vLightFront * diffuse + ambient * ambientLightColor + emissive;",
692 
693 		"#ifdef DOUBLE_SIDED",
694 
695 			"vLightBack = vLightBack * diffuse + ambient * ambientLightColor + emissive;",
696 
697 		"#endif"
698 
699 	].join("\n"),
700 
701 	// LIGHTS PHONG
702 
703 	lights_phong_pars_vertex: [
704 
705 		"#ifndef PHONG_PER_PIXEL",
706 
707 		"#if MAX_POINT_LIGHTS > 0",
708 
709 			"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
710 			"uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
711 
712 			"varying vec4 vPointLight[ MAX_POINT_LIGHTS ];",
713 
714 		"#endif",
715 
716 		"#if MAX_SPOT_LIGHTS > 0",
717 
718 			"uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];",
719 			"uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];",
720 
721 			"varying vec4 vSpotLight[ MAX_SPOT_LIGHTS ];",
722 
723 		"#endif",
724 
725 		"#endif",
726 
727 		"#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP )",
728 
729 			"varying vec3 vWorldPosition;",
730 
731 		"#endif"
732 
733 	].join("\n"),
734 
735 
736 	lights_phong_vertex: [
737 
738 		"#ifndef PHONG_PER_PIXEL",
739 
740 		"#if MAX_POINT_LIGHTS > 0",
741 
742 			"for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
743 
744 				"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
745 				"vec3 lVector = lPosition.xyz - mvPosition.xyz;",
746 
747 				"float lDistance = 1.0;",
748 				"if ( pointLightDistance[ i ] > 0.0 )",
749 					"lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
750 
751 				"vPointLight[ i ] = vec4( lVector, lDistance );",
752 
753 			"}",
754 
755 		"#endif",
756 
757 		"#if MAX_SPOT_LIGHTS > 0",
758 
759 			"for( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {",
760 
761 				"vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );",
762 				"vec3 lVector = lPosition.xyz - mvPosition.xyz;",
763 
764 				"float lDistance = 1.0;",
765 				"if ( spotLightDistance[ i ] > 0.0 )",
766 					"lDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );",
767 
768 				"vSpotLight[ i ] = vec4( lVector, lDistance );",
769 
770 			"}",
771 
772 		"#endif",
773 
774 		"#endif",
775 
776 		"#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP )",
777 
778 			"vWorldPosition = worldPosition.xyz;",
779 
780 		"#endif"
781 
782 	].join("\n"),
783 
784 	lights_phong_pars_fragment: [
785 
786 		"uniform vec3 ambientLightColor;",
787 
788 		"#if MAX_DIR_LIGHTS > 0",
789 
790 			"uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];",
791 			"uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",
792 
793 		"#endif",
794 
795 		"#if MAX_HEMI_LIGHTS > 0",
796 
797 			"uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];",
798 			"uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];",
799 			"uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];",
800 
801 		"#endif",
802 
803 		"#if MAX_POINT_LIGHTS > 0",
804 
805 			"uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
806 
807 			"#ifdef PHONG_PER_PIXEL",
808 
809 				"uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
810 				"uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
811 
812 			"#else",
813 
814 				"varying vec4 vPointLight[ MAX_POINT_LIGHTS ];",
815 
816 			"#endif",
817 
818 		"#endif",
819 
820 		"#if MAX_SPOT_LIGHTS > 0",
821 
822 			"uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];",
823 			"uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];",
824 			"uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];",
825 			"uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];",
826 			"uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];",
827 
828 			"#ifdef PHONG_PER_PIXEL",
829 
830 				"uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];",
831 
832 			"#else",
833 
834 				"varying vec4 vSpotLight[ MAX_SPOT_LIGHTS ];",
835 
836 			"#endif",
837 
838 		"#endif",
839 
840 		"#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP )",
841 
842 			"varying vec3 vWorldPosition;",
843 
844 		"#endif",
845 
846 		"#ifdef WRAP_AROUND",
847 
848 			"uniform vec3 wrapRGB;",
849 
850 		"#endif",
851 
852 		"varying vec3 vViewPosition;",
853 		"varying vec3 vNormal;"
854 
855 	].join("\n"),
856 
857 	lights_phong_fragment: [
858 
859 		"vec3 normal = normalize( vNormal );",
860 		"vec3 viewPosition = normalize( vViewPosition );",
861 
862 		"#ifdef DOUBLE_SIDED",
863 
864 			"normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );",
865 
866 		"#endif",
867 
868 		"#ifdef USE_NORMALMAP",
869 
870 			"normal = perturbNormal2Arb( -viewPosition, normal );",
871 
872 		"#elif defined( USE_BUMPMAP )",
873 
874 			"normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );",
875 
876 		"#endif",
877 
878 		"#if MAX_POINT_LIGHTS > 0",
879 
880 			"vec3 pointDiffuse  = vec3( 0.0 );",
881 			"vec3 pointSpecular = vec3( 0.0 );",
882 
883 			"for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
884 
885 				"#ifdef PHONG_PER_PIXEL",
886 
887 					"vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
888 					"vec3 lVector = lPosition.xyz + vViewPosition.xyz;",
889 
890 					"float lDistance = 1.0;",
891 					"if ( pointLightDistance[ i ] > 0.0 )",
892 						"lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );",
893 
894 					"lVector = normalize( lVector );",
895 
896 				"#else",
897 
898 					"vec3 lVector = normalize( vPointLight[ i ].xyz );",
899 					"float lDistance = vPointLight[ i ].w;",
900 
901 				"#endif",
902 
903 				// diffuse
904 
905 				"float dotProduct = dot( normal, lVector );",
906 
907 				"#ifdef WRAP_AROUND",
908 
909 					"float pointDiffuseWeightFull = max( dotProduct, 0.0 );",
910 					"float pointDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );",
911 
912 					"vec3 pointDiffuseWeight = mix( vec3 ( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );",
913 
914 				"#else",
915 
916 					"float pointDiffuseWeight = max( dotProduct, 0.0 );",
917 
918 				"#endif",
919 
920 				"pointDiffuse  += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;",
921 
922 				// specular
923 
924 				"vec3 pointHalfVector = normalize( lVector + viewPosition );",
925 				"float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
926 				"float pointSpecularWeight = specularStrength * max( pow( pointDotNormalHalf, shininess ), 0.0 );",
927 
928 				"#ifdef PHYSICALLY_BASED_SHADING",
929 
930 					// 2.0 => 2.0001 is hack to work around ANGLE bug
931 
932 					"float specularNormalization = ( shininess + 2.0001 ) / 8.0;",
933 
934 					"vec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVector, pointHalfVector ), 5.0 );",
935 					"pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance * specularNormalization;",
936 
937 				"#else",
938 
939 					"pointSpecular += specular * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance;",
940 
941 				"#endif",
942 
943 			"}",
944 
945 		"#endif",
946 
947 		"#if MAX_SPOT_LIGHTS > 0",
948 
949 			"vec3 spotDiffuse  = vec3( 0.0 );",
950 			"vec3 spotSpecular = vec3( 0.0 );",
951 
952 			"for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {",
953 
954 				"#ifdef PHONG_PER_PIXEL",
955 
956 					"vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );",
957 					"vec3 lVector = lPosition.xyz + vViewPosition.xyz;",
958 
959 					"float lDistance = 1.0;",
960 					"if ( spotLightDistance[ i ] > 0.0 )",
961 						"lDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );",
962 
963 					"lVector = normalize( lVector );",
964 
965 				"#else",
966 
967 					"vec3 lVector = normalize( vSpotLight[ i ].xyz );",
968 					"float lDistance = vSpotLight[ i ].w;",
969 
970 				"#endif",
971 
972 				"float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );",
973 
974 				"if ( spotEffect > spotLightAngleCos[ i ] ) {",
975 
976 					"spotEffect = max( pow( spotEffect, spotLightExponent[ i ] ), 0.0 );",
977 
978 					// diffuse
979 
980 					"float dotProduct = dot( normal, lVector );",
981 
982 					"#ifdef WRAP_AROUND",
983 
984 						"float spotDiffuseWeightFull = max( dotProduct, 0.0 );",
985 						"float spotDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );",
986 
987 						"vec3 spotDiffuseWeight = mix( vec3 ( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );",
988 
989 					"#else",
990 
991 						"float spotDiffuseWeight = max( dotProduct, 0.0 );",
992 
993 					"#endif",
994 
995 					"spotDiffuse += diffuse * spotLightColor[ i ] * spotDiffuseWeight * lDistance * spotEffect;",
996 
997 					// specular
998 
999 					"vec3 spotHalfVector = normalize( lVector + viewPosition );",
1000 					"float spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );",
1001 					"float spotSpecularWeight = specularStrength * max( pow( spotDotNormalHalf, shininess ), 0.0 );",
1002 
1003 					"#ifdef PHYSICALLY_BASED_SHADING",
1004 
1005 						// 2.0 => 2.0001 is hack to work around ANGLE bug
1006 
1007 						"float specularNormalization = ( shininess + 2.0001 ) / 8.0;",
1008 
1009 						"vec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVector, spotHalfVector ), 5.0 );",
1010 						"spotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * lDistance * specularNormalization * spotEffect;",
1011 
1012 					"#else",
1013 
1014 						"spotSpecular += specular * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * lDistance * spotEffect;",
1015 
1016 					"#endif",
1017 
1018 				"}",
1019 
1020 			"}",
1021 
1022 		"#endif",
1023 
1024 		"#if MAX_DIR_LIGHTS > 0",
1025 
1026 			"vec3 dirDiffuse  = vec3( 0.0 );",
1027 			"vec3 dirSpecular = vec3( 0.0 );" ,
1028 
1029 			"for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {",
1030 
1031 				"vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
1032 				"vec3 dirVector = normalize( lDirection.xyz );",
1033 
1034 				// diffuse
1035 
1036 				"float dotProduct = dot( normal, dirVector );",
1037 
1038 				"#ifdef WRAP_AROUND",
1039 
1040 					"float dirDiffuseWeightFull = max( dotProduct, 0.0 );",
1041 					"float dirDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );",
1042 
1043 					"vec3 dirDiffuseWeight = mix( vec3( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), wrapRGB );",
1044 
1045 				"#else",
1046 
1047 					"float dirDiffuseWeight = max( dotProduct, 0.0 );",
1048 
1049 				"#endif",
1050 
1051 				"dirDiffuse  += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;",
1052 
1053 				// specular
1054 
1055 				"vec3 dirHalfVector = normalize( dirVector + viewPosition );",
1056 				"float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
1057 				"float dirSpecularWeight = specularStrength * max( pow( dirDotNormalHalf, shininess ), 0.0 );",
1058 
1059 				"#ifdef PHYSICALLY_BASED_SHADING",
1060 
1061 					/*
1062 					// fresnel term from skin shader
1063 					"const float F0 = 0.128;",
1064 
1065 					"float base = 1.0 - dot( viewPosition, dirHalfVector );",
1066 					"float exponential = pow( base, 5.0 );",
1067 
1068 					"float fresnel = exponential + F0 * ( 1.0 - exponential );",
1069 					*/
1070 
1071 					/*
1072 					// fresnel term from fresnel shader
1073 					"const float mFresnelBias = 0.08;",
1074 					"const float mFresnelScale = 0.3;",
1075 					"const float mFresnelPower = 5.0;",
1076 
1077 					"float fresnel = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( -viewPosition ), normal ), mFresnelPower );",
1078 					*/
1079 
1080 					// 2.0 => 2.0001 is hack to work around ANGLE bug
1081 
1082 					"float specularNormalization = ( shininess + 2.0001 ) / 8.0;",
1083 
1084 					//"dirSpecular += specular * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization * fresnel;",
1085 
1086 					"vec3 schlick = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( dirVector, dirHalfVector ), 5.0 );",
1087 					"dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;",
1088 
1089 				"#else",
1090 
1091 					"dirSpecular += specular * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight;",
1092 
1093 				"#endif",
1094 
1095 			"}",
1096 
1097 		"#endif",
1098 
1099 		"#if MAX_HEMI_LIGHTS > 0",
1100 
1101 			"vec3 hemiDiffuse  = vec3( 0.0 );",
1102 			"vec3 hemiSpecular = vec3( 0.0 );" ,
1103 
1104 			"for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {",
1105 
1106 				"vec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );",
1107 				"vec3 lVector = normalize( lDirection.xyz );",
1108 
1109 				// diffuse
1110 
1111 				"float dotProduct = dot( normal, lVector );",
1112 				"float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
1113 
1114 				"vec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
1115 
1116 				"hemiDiffuse += diffuse * hemiColor;",
1117 
1118 				// specular (sky light)
1119 
1120 				"vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );",
1121 				"float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;",
1122 				"float hemiSpecularWeightSky = specularStrength * max( pow( hemiDotNormalHalfSky, shininess ), 0.0 );",
1123 
1124 				// specular (ground light)
1125 
1126 				"vec3 lVectorGround = -lVector;",
1127 
1128 				"vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );",
1129 				"float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
1130 				"float hemiSpecularWeightGround = specularStrength * max( pow( hemiDotNormalHalfGround, shininess ), 0.0 );",
1131 
1132 				"#ifdef PHYSICALLY_BASED_SHADING",
1133 
1134 					"float dotProductGround = dot( normal, lVectorGround );",
1135 
1136 					// 2.0 => 2.0001 is hack to work around ANGLE bug
1137 
1138 					"float specularNormalization = ( shininess + 2.0001 ) / 8.0;",
1139 
1140 					"vec3 schlickSky = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVector, hemiHalfVectorSky ), 5.0 );",
1141 					"vec3 schlickGround = specular + vec3( 1.0 - specular ) * pow( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 5.0 );",
1142 					"hemiSpecular += hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );",
1143 
1144 				"#else",
1145 
1146 					"hemiSpecular += specular * hemiColor * ( hemiSpecularWeightSky + hemiSpecularWeightGround ) * hemiDiffuseWeight;",
1147 
1148 				"#endif",
1149 
1150 			"}",
1151 
1152 		"#endif",
1153 
1154 		"vec3 totalDiffuse = vec3( 0.0 );",
1155 		"vec3 totalSpecular = vec3( 0.0 );",
1156 
1157 		"#if MAX_DIR_LIGHTS > 0",
1158 
1159 			"totalDiffuse += dirDiffuse;",
1160 			"totalSpecular += dirSpecular;",
1161 
1162 		"#endif",
1163 
1164 		"#if MAX_HEMI_LIGHTS > 0",
1165 
1166 			"totalDiffuse += hemiDiffuse;",
1167 			"totalSpecular += hemiSpecular;",
1168 
1169 		"#endif",
1170 
1171 		"#if MAX_POINT_LIGHTS > 0",
1172 
1173 			"totalDiffuse += pointDiffuse;",
1174 			"totalSpecular += pointSpecular;",
1175 
1176 		"#endif",
1177 
1178 		"#if MAX_SPOT_LIGHTS > 0",
1179 
1180 			"totalDiffuse += spotDiffuse;",
1181 			"totalSpecular += spotSpecular;",
1182 
1183 		"#endif",
1184 
1185 		"#ifdef METAL",
1186 
1187 			"gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient + totalSpecular );",
1188 
1189 		"#else",
1190 
1191 			"gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient ) + totalSpecular;",
1192 
1193 		"#endif"
1194 
1195 	].join("\n"),
1196 
1197 	// VERTEX COLORS
1198 
1199 	color_pars_fragment: [
1200 
1201 		"#ifdef USE_COLOR",
1202 
1203 			"varying vec3 vColor;",
1204 
1205 		"#endif"
1206 
1207 	].join("\n"),
1208 
1209 
1210 	color_fragment: [
1211 
1212 		"#ifdef USE_COLOR",
1213 
1214 			"gl_FragColor = gl_FragColor * vec4( vColor, opacity );",
1215 
1216 		"#endif"
1217 
1218 	].join("\n"),
1219 
1220 	color_pars_vertex: [
1221 
1222 		"#ifdef USE_COLOR",
1223 
1224 			"varying vec3 vColor;",
1225 
1226 		"#endif"
1227 
1228 	].join("\n"),
1229 
1230 
1231 	color_vertex: [
1232 
1233 		"#ifdef USE_COLOR",
1234 
1235 			"#ifdef GAMMA_INPUT",
1236 
1237 				"vColor = color * color;",
1238 
1239 			"#else",
1240 
1241 				"vColor = color;",
1242 
1243 			"#endif",
1244 
1245 		"#endif"
1246 
1247 	].join("\n"),
1248 
1249 	// SKINNING
1250 
1251 	skinning_pars_vertex: [
1252 
1253 		"#ifdef USE_SKINNING",
1254 
1255 			"#ifdef BONE_TEXTURE",
1256 
1257 				"uniform sampler2D boneTexture;",
1258 
1259 				"mat4 getBoneMatrix( const in float i ) {",
1260 
1261 					"float j = i * 4.0;",
1262 					"float x = mod( j, N_BONE_PIXEL_X );",
1263 					"float y = floor( j / N_BONE_PIXEL_X );",
1264 
1265 					"const float dx = 1.0 / N_BONE_PIXEL_X;",
1266 					"const float dy = 1.0 / N_BONE_PIXEL_Y;",
1267 
1268 					"y = dy * ( y + 0.5 );",
1269 
1270 					"vec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );",
1271 					"vec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );",
1272 					"vec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );",
1273 					"vec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );",
1274 
1275 					"mat4 bone = mat4( v1, v2, v3, v4 );",
1276 
1277 					"return bone;",
1278 
1279 				"}",
1280 
1281 			"#else",
1282 
1283 				"uniform mat4 boneGlobalMatrices[ MAX_BONES ];",
1284 
1285 				"mat4 getBoneMatrix( const in float i ) {",
1286 
1287 					"mat4 bone = boneGlobalMatrices[ int(i) ];",
1288 					"return bone;",
1289 
1290 				"}",
1291 
1292 			"#endif",
1293 
1294 		"#endif"
1295 
1296 	].join("\n"),
1297 
1298 	skinbase_vertex: [
1299 
1300 		"#ifdef USE_SKINNING",
1301 
1302 			"mat4 boneMatX = getBoneMatrix( skinIndex.x );",
1303 			"mat4 boneMatY = getBoneMatrix( skinIndex.y );",
1304 
1305 		"#endif"
1306 
1307 	].join("\n"),
1308 
1309 	skinning_vertex: [
1310 
1311 		"#ifdef USE_SKINNING",
1312 
1313 			"#ifdef USE_MORPHTARGETS",
1314 
1315 			"vec4 skinVertex = vec4( morphed, 1.0 );",
1316 
1317 			"#else",
1318 
1319 			"vec4 skinVertex = vec4( position, 1.0 );",
1320 
1321 			"#endif",
1322 
1323 			"vec4 skinned  = boneMatX * skinVertex * skinWeight.x;",
1324 			"skinned 	  += boneMatY * skinVertex * skinWeight.y;",
1325 
1326 		"#endif"
1327 
1328 	].join("\n"),
1329 
1330 	// MORPHING
1331 
1332 	morphtarget_pars_vertex: [
1333 
1334 		"#ifdef USE_MORPHTARGETS",
1335 
1336 			"#ifndef USE_MORPHNORMALS",
1337 
1338 			"uniform float morphTargetInfluences[ 8 ];",
1339 
1340 			"#else",
1341 
1342 			"uniform float morphTargetInfluences[ 4 ];",
1343 
1344 			"#endif",
1345 
1346 		"#endif"
1347 
1348 	].join("\n"),
1349 
1350 	morphtarget_vertex: [
1351 
1352 		"#ifdef USE_MORPHTARGETS",
1353 
1354 			"vec3 morphed = vec3( 0.0 );",
1355 			"morphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];",
1356 			"morphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];",
1357 			"morphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];",
1358 			"morphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];",
1359 
1360 			"#ifndef USE_MORPHNORMALS",
1361 
1362 			"morphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];",
1363 			"morphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];",
1364 			"morphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];",
1365 			"morphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];",
1366 
1367 			"#endif",
1368 
1369 			"morphed += position;",
1370 
1371 		"#endif"
1372 
1373 	].join("\n"),
1374 
1375 	default_vertex : [
1376 
1377 		"vec4 mvPosition;",
1378 
1379 		"#ifdef USE_SKINNING",
1380 
1381 			"mvPosition = modelViewMatrix * skinned;",
1382 
1383 		"#endif",
1384 
1385 		"#if !defined( USE_SKINNING ) && defined( USE_MORPHTARGETS )",
1386 
1387 			"mvPosition = modelViewMatrix * vec4( morphed, 1.0 );",
1388 
1389 		"#endif",
1390 
1391 		"#if !defined( USE_SKINNING ) && ! defined( USE_MORPHTARGETS )",
1392 
1393 			"mvPosition = modelViewMatrix * vec4( position, 1.0 );",
1394 
1395 		"#endif",
1396 
1397 		"gl_Position = projectionMatrix * mvPosition;",
1398 
1399 	].join("\n"),
1400 
1401 	morphnormal_vertex: [
1402 
1403 		"#ifdef USE_MORPHNORMALS",
1404 
1405 			"vec3 morphedNormal = vec3( 0.0 );",
1406 
1407 			"morphedNormal +=  ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];",
1408 			"morphedNormal +=  ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];",
1409 			"morphedNormal +=  ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];",
1410 			"morphedNormal +=  ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];",
1411 
1412 			"morphedNormal += normal;",
1413 
1414 		"#endif"
1415 
1416 	].join("\n"),
1417 
1418 	skinnormal_vertex: [
1419 
1420 		"#ifdef USE_SKINNING",
1421 
1422 			"mat4 skinMatrix = skinWeight.x * boneMatX;",
1423 			"skinMatrix 	+= skinWeight.y * boneMatY;",
1424 
1425 			"#ifdef USE_MORPHNORMALS",
1426 
1427 			"vec4 skinnedNormal = skinMatrix * vec4( morphedNormal, 0.0 );",
1428 
1429 			"#else",
1430 
1431 			"vec4 skinnedNormal = skinMatrix * vec4( normal, 0.0 );",
1432 
1433 			"#endif",
1434 
1435 		"#endif"
1436 
1437 	].join("\n"),
1438 
1439 	defaultnormal_vertex: [
1440 
1441 		"vec3 objectNormal;",
1442 
1443 		"#ifdef USE_SKINNING",
1444 
1445 			"objectNormal = skinnedNormal.xyz;",
1446 
1447 		"#endif",
1448 
1449 		"#if !defined( USE_SKINNING ) && defined( USE_MORPHNORMALS )",
1450 
1451 			"objectNormal = morphedNormal;",
1452 
1453 		"#endif",
1454 
1455 		"#if !defined( USE_SKINNING ) && ! defined( USE_MORPHNORMALS )",
1456 
1457 			"objectNormal = normal;",
1458 
1459 		"#endif",
1460 
1461 		"#ifdef FLIP_SIDED",
1462 
1463 			"objectNormal = -objectNormal;",
1464 
1465 		"#endif",
1466 
1467 		"vec3 transformedNormal = normalMatrix * objectNormal;",
1468 
1469 	].join("\n"),
1470 
1471 	// SHADOW MAP
1472 
1473 	// based on SpiderGL shadow map and Fabien Sanglard's GLSL shadow mapping examples
1474 	//  http://spidergl.org/example.php?id=6
1475 	// 	http://fabiensanglard.net/shadowmapping
1476 
1477 	shadowmap_pars_fragment: [
1478 
1479 		"#ifdef USE_SHADOWMAP",
1480 
1481 			"uniform sampler2D shadowMap[ MAX_SHADOWS ];",
1482 			"uniform vec2 shadowMapSize[ MAX_SHADOWS ];",
1483 
1484 			"uniform float shadowDarkness[ MAX_SHADOWS ];",
1485 			"uniform float shadowBias[ MAX_SHADOWS ];",
1486 
1487 			"varying vec4 vShadowCoord[ MAX_SHADOWS ];",
1488 
1489 			"float unpackDepth( const in vec4 rgba_depth ) {",
1490 
1491 				"const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
1492 				"float depth = dot( rgba_depth, bit_shift );",
1493 				"return depth;",
1494 
1495 			"}",
1496 
1497 		"#endif"
1498 
1499 	].join("\n"),
1500 
1501 	shadowmap_fragment: [
1502 
1503 		"#ifdef USE_SHADOWMAP",
1504 
1505 			"#ifdef SHADOWMAP_DEBUG",
1506 
1507 				"vec3 frustumColors[3];",
1508 				"frustumColors[0] = vec3( 1.0, 0.5, 0.0 );",
1509 				"frustumColors[1] = vec3( 0.0, 1.0, 0.8 );",
1510 				"frustumColors[2] = vec3( 0.0, 0.5, 1.0 );",
1511 
1512 			"#endif",
1513 
1514 			"#ifdef SHADOWMAP_CASCADE",
1515 
1516 				"int inFrustumCount = 0;",
1517 
1518 			"#endif",
1519 
1520 			"float fDepth;",
1521 			"vec3 shadowColor = vec3( 1.0 );",
1522 
1523 			"for( int i = 0; i < MAX_SHADOWS; i ++ ) {",
1524 
1525 				"vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;",
1526 
1527 				// "if ( something && something )" 		 breaks ATI OpenGL shader compiler
1528 				// "if ( all( something, something ) )"  using this instead
1529 
1530 				"bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );",
1531 				"bool inFrustum = all( inFrustumVec );",
1532 
1533 				// don't shadow pixels outside of light frustum
1534 				// use just first frustum (for cascades)
1535 				// don't shadow pixels behind far plane of light frustum
1536 
1537 				"#ifdef SHADOWMAP_CASCADE",
1538 
1539 					"inFrustumCount += int( inFrustum );",
1540 					"bvec3 frustumTestVec = bvec3( inFrustum, inFrustumCount == 1, shadowCoord.z <= 1.0 );",
1541 
1542 				"#else",
1543 
1544 					"bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );",
1545 
1546 				"#endif",
1547 
1548 				"bool frustumTest = all( frustumTestVec );",
1549 
1550 				"if ( frustumTest ) {",
1551 
1552 					"shadowCoord.z += shadowBias[ i ];",
1553 
1554 					"#ifdef SHADOWMAP_SOFT",
1555 
1556 						// Percentage-close filtering
1557 						// (9 pixel kernel)
1558 						// http://fabiensanglard.net/shadowmappingPCF/
1559 
1560 						"float shadow = 0.0;",
1561 
1562 						/*
1563 						// nested loops breaks shader compiler / validator on some ATI cards when using OpenGL
1564 						// must enroll loop manually
1565 
1566 						"for ( float y = -1.25; y <= 1.25; y += 1.25 )",
1567 							"for ( float x = -1.25; x <= 1.25; x += 1.25 ) {",
1568 
1569 								"vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );",
1570 
1571 								// doesn't seem to produce any noticeable visual difference compared to simple "texture2D" lookup
1572 								//"vec4 rgbaDepth = texture2DProj( shadowMap[ i ], vec4( vShadowCoord[ i ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ i ].w ) );",
1573 
1574 								"float fDepth = unpackDepth( rgbaDepth );",
1575 
1576 								"if ( fDepth < shadowCoord.z )",
1577 									"shadow += 1.0;",
1578 
1579 						"}",
1580 
1581 						"shadow /= 9.0;",
1582 
1583 						*/
1584 
1585 						"const float shadowDelta = 1.0 / 9.0;",
1586 
1587 						"float xPixelOffset = 1.0 / shadowMapSize[ i ].x;",
1588 						"float yPixelOffset = 1.0 / shadowMapSize[ i ].y;",
1589 
1590 						"float dx0 = -1.25 * xPixelOffset;",
1591 						"float dy0 = -1.25 * yPixelOffset;",
1592 						"float dx1 = 1.25 * xPixelOffset;",
1593 						"float dy1 = 1.25 * yPixelOffset;",
1594 
1595 						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );",
1596 						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
1597 
1598 						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );",
1599 						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
1600 
1601 						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );",
1602 						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
1603 
1604 						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );",
1605 						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
1606 
1607 						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );",
1608 						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
1609 
1610 						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );",
1611 						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
1612 
1613 						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );",
1614 						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
1615 
1616 						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );",
1617 						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
1618 
1619 						"fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );",
1620 						"if ( fDepth < shadowCoord.z ) shadow += shadowDelta;",
1621 
1622 						"shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );",
1623 
1624 					"#else",
1625 
1626 						"vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );",
1627 						"float fDepth = unpackDepth( rgbaDepth );",
1628 
1629 						"if ( fDepth < shadowCoord.z )",
1630 
1631 							// spot with multiple shadows is darker
1632 
1633 							"shadowColor = shadowColor * vec3( 1.0 - shadowDarkness[ i ] );",
1634 
1635 							// spot with multiple shadows has the same color as single shadow spot
1636 
1637 							//"shadowColor = min( shadowColor, vec3( shadowDarkness[ i ] ) );",
1638 
1639 					"#endif",
1640 
1641 				"}",
1642 
1643 
1644 				"#ifdef SHADOWMAP_DEBUG",
1645 
1646 					"#ifdef SHADOWMAP_CASCADE",
1647 
1648 						"if ( inFrustum && inFrustumCount == 1 ) gl_FragColor.xyz *= frustumColors[ i ];",
1649 
1650 					"#else",
1651 
1652 						"if ( inFrustum ) gl_FragColor.xyz *= frustumColors[ i ];",
1653 
1654 					"#endif",
1655 
1656 				"#endif",
1657 
1658 			"}",
1659 
1660 			"#ifdef GAMMA_OUTPUT",
1661 
1662 				"shadowColor *= shadowColor;",
1663 
1664 			"#endif",
1665 
1666 			"gl_FragColor.xyz = gl_FragColor.xyz * shadowColor;",
1667 
1668 		"#endif"
1669 
1670 	].join("\n"),
1671 
1672 	shadowmap_pars_vertex: [
1673 
1674 		"#ifdef USE_SHADOWMAP",
1675 
1676 			"varying vec4 vShadowCoord[ MAX_SHADOWS ];",
1677 			"uniform mat4 shadowMatrix[ MAX_SHADOWS ];",
1678 
1679 		"#endif"
1680 
1681 	].join("\n"),
1682 
1683 	shadowmap_vertex: [
1684 
1685 		"#ifdef USE_SHADOWMAP",
1686 
1687 			"for( int i = 0; i < MAX_SHADOWS; i ++ ) {",
1688 
1689 				"vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;",
1690 
1691 			"}",
1692 
1693 		"#endif"
1694 
1695 	].join("\n"),
1696 
1697 	// ALPHATEST
1698 
1699 	alphatest_fragment: [
1700 
1701 		"#ifdef ALPHATEST",
1702 
1703 			"if ( gl_FragColor.a < ALPHATEST ) discard;",
1704 
1705 		"#endif"
1706 
1707 	].join("\n"),
1708 
1709 	// LINEAR SPACE
1710 
1711 	linear_to_gamma_fragment: [
1712 
1713 		"#ifdef GAMMA_OUTPUT",
1714 
1715 			"gl_FragColor.xyz = sqrt( gl_FragColor.xyz );",
1716 
1717 		"#endif"
1718 
1719 	].join("\n"),
1720 
1721 
1722 };
1723 
1724 /**@namespace*/
1725 THREE.UniformsUtils = {
1726 
1727 	merge: function ( uniforms ) {
1728 
1729 		var u, p, tmp, merged = {};
1730 
1731 		for ( u = 0; u < uniforms.length; u ++ ) {
1732 
1733 			tmp = this.clone( uniforms[ u ] );
1734 
1735 			for ( p in tmp ) {
1736 
1737 				merged[ p ] = tmp[ p ];
1738 
1739 			}
1740 
1741 		}
1742 
1743 		return merged;
1744 
1745 	},
1746 
1747 	clone: function ( uniforms_src ) {
1748 
1749 		var u, p, parameter, parameter_src, uniforms_dst = {};
1750 
1751 		for ( u in uniforms_src ) {
1752 
1753 			uniforms_dst[ u ] = {};
1754 
1755 			for ( p in uniforms_src[ u ] ) {
1756 
1757 				parameter_src = uniforms_src[ u ][ p ];
1758 
1759 				if ( parameter_src instanceof THREE.Color ||
1760 					 parameter_src instanceof THREE.Vector2 ||
1761 					 parameter_src instanceof THREE.Vector3 ||
1762 					 parameter_src instanceof THREE.Vector4 ||
1763 					 parameter_src instanceof THREE.Matrix4 ||
1764 					 parameter_src instanceof THREE.Texture ) {
1765 
1766 					uniforms_dst[ u ][ p ] = parameter_src.clone();
1767 
1768 				} else if ( parameter_src instanceof Array ) {
1769 
1770 					uniforms_dst[ u ][ p ] = parameter_src.slice();
1771 
1772 				} else {
1773 
1774 					uniforms_dst[ u ][ p ] = parameter_src;
1775 
1776 				}
1777 
1778 			}
1779 
1780 		}
1781 
1782 		return uniforms_dst;
1783 
1784 	}
1785 
1786 };
1787 
1788 /**@namespace*/
1789 THREE.UniformsLib = {
1790 
1791 	common: {
1792 
1793 		"diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
1794 		"opacity" : { type: "f", value: 1.0 },
1795 
1796 		"map" : { type: "t", value: null },
1797 		"offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
1798 
1799 		"lightMap" : { type: "t", value: null },
1800 		"specularMap" : { type: "t", value: null },
1801 
1802 		"envMap" : { type: "t", value: null },
1803 		"flipEnvMap" : { type: "f", value: -1 },
1804 		"useRefract" : { type: "i", value: 0 },
1805 		"reflectivity" : { type: "f", value: 1.0 },
1806 		"refractionRatio" : { type: "f", value: 0.98 },
1807 		"combine" : { type: "i", value: 0 },
1808 
1809 		"morphTargetInfluences" : { type: "f", value: 0 }
1810 
1811 	},
1812 
1813 	bump: {
1814 
1815 		"bumpMap" : { type: "t", value: null },
1816 		"bumpScale" : { type: "f", value: 1 }
1817 
1818 	},
1819 
1820 	normalmap: {
1821 
1822 		"normalMap" : { type: "t", value: null },
1823 		"normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
1824 	},
1825 
1826 	fog : {
1827 
1828 		"fogDensity" : { type: "f", value: 0.00025 },
1829 		"fogNear" : { type: "f", value: 1 },
1830 		"fogFar" : { type: "f", value: 2000 },
1831 		"fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
1832 
1833 	},
1834 
1835 	lights: {
1836 
1837 		"ambientLightColor" : { type: "fv", value: [] },
1838 
1839 		"directionalLightDirection" : { type: "fv", value: [] },
1840 		"directionalLightColor" : { type: "fv", value: [] },
1841 
1842 		"hemisphereLightDirection" : { type: "fv", value: [] },
1843 		"hemisphereLightSkyColor" : { type: "fv", value: [] },
1844 		"hemisphereLightGroundColor" : { type: "fv", value: [] },
1845 
1846 		"pointLightColor" : { type: "fv", value: [] },
1847 		"pointLightPosition" : { type: "fv", value: [] },
1848 		"pointLightDistance" : { type: "fv1", value: [] },
1849 
1850 		"spotLightColor" : { type: "fv", value: [] },
1851 		"spotLightPosition" : { type: "fv", value: [] },
1852 		"spotLightDirection" : { type: "fv", value: [] },
1853 		"spotLightDistance" : { type: "fv1", value: [] },
1854 		"spotLightAngleCos" : { type: "fv1", value: [] },
1855 		"spotLightExponent" : { type: "fv1", value: [] }
1856 
1857 	},
1858 
1859 	particle: {
1860 
1861 		"psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
1862 		"opacity" : { type: "f", value: 1.0 },
1863 		"size" : { type: "f", value: 1.0 },
1864 		"scale" : { type: "f", value: 1.0 },
1865 		"map" : { type: "t", value: null },
1866 
1867 		"fogDensity" : { type: "f", value: 0.00025 },
1868 		"fogNear" : { type: "f", value: 1 },
1869 		"fogFar" : { type: "f", value: 2000 },
1870 		"fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
1871 
1872 	},
1873 
1874 	shadowmap: {
1875 
1876 		"shadowMap": { type: "tv", value: [] },
1877 		"shadowMapSize": { type: "v2v", value: [] },
1878 
1879 		"shadowBias" : { type: "fv1", value: [] },
1880 		"shadowDarkness": { type: "fv1", value: [] },
1881 
1882 		"shadowMatrix" : { type: "m4v", value: [] },
1883 
1884 	}
1885 
1886 };
1887 
1888 /**@namespace*/
1889 THREE.ShaderLib = {
1890 
1891 	'depth': {
1892 
1893 		uniforms: {
1894 
1895 			"mNear": { type: "f", value: 1.0 },
1896 			"mFar" : { type: "f", value: 2000.0 },
1897 			"opacity" : { type: "f", value: 1.0 }
1898 
1899 		},
1900 
1901 		vertexShader: [
1902 
1903 			"void main() {",
1904 
1905 				"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
1906 
1907 			"}"
1908 
1909 		].join("\n"),
1910 
1911 		fragmentShader: [
1912 
1913 			"uniform float mNear;",
1914 			"uniform float mFar;",
1915 			"uniform float opacity;",
1916 
1917 			"void main() {",
1918 
1919 				"float depth = gl_FragCoord.z / gl_FragCoord.w;",
1920 				"float color = 1.0 - smoothstep( mNear, mFar, depth );",
1921 				"gl_FragColor = vec4( vec3( color ), opacity );",
1922 
1923 			"}"
1924 
1925 		].join("\n")
1926 
1927 	},
1928 
1929 	'normal': {
1930 
1931 		uniforms: {
1932 
1933 			"opacity" : { type: "f", value: 1.0 }
1934 
1935 		},
1936 
1937 		vertexShader: [
1938 
1939 			"varying vec3 vNormal;",
1940 
1941 			"void main() {",
1942 
1943 				"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
1944 				"vNormal = normalize( normalMatrix * normal );",
1945 
1946 				"gl_Position = projectionMatrix * mvPosition;",
1947 
1948 			"}"
1949 
1950 		].join("\n"),
1951 
1952 		fragmentShader: [
1953 
1954 			"uniform float opacity;",
1955 			"varying vec3 vNormal;",
1956 
1957 			"void main() {",
1958 
1959 				"gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
1960 
1961 			"}"
1962 
1963 		].join("\n")
1964 
1965 	},
1966 
1967 	'basic': {
1968 
1969 		uniforms: THREE.UniformsUtils.merge( [
1970 
1971 			THREE.UniformsLib[ "common" ],
1972 			THREE.UniformsLib[ "fog" ],
1973 			THREE.UniformsLib[ "shadowmap" ]
1974 
1975 		] ),
1976 
1977 		vertexShader: [
1978 
1979 			THREE.ShaderChunk[ "map_pars_vertex" ],
1980 			THREE.ShaderChunk[ "lightmap_pars_vertex" ],
1981 			THREE.ShaderChunk[ "envmap_pars_vertex" ],
1982 			THREE.ShaderChunk[ "color_pars_vertex" ],
1983 			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
1984 			THREE.ShaderChunk[ "skinning_pars_vertex" ],
1985 			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
1986 
1987 			"void main() {",
1988 
1989 				THREE.ShaderChunk[ "map_vertex" ],
1990 				THREE.ShaderChunk[ "lightmap_vertex" ],
1991 				THREE.ShaderChunk[ "color_vertex" ],
1992 
1993 				"#ifdef USE_ENVMAP",
1994 
1995 				THREE.ShaderChunk[ "morphnormal_vertex" ],
1996 				THREE.ShaderChunk[ "skinbase_vertex" ],
1997 				THREE.ShaderChunk[ "skinnormal_vertex" ],
1998 				THREE.ShaderChunk[ "defaultnormal_vertex" ],
1999 
2000 				"#endif",
2001 
2002 				THREE.ShaderChunk[ "morphtarget_vertex" ],
2003 				THREE.ShaderChunk[ "skinning_vertex" ],
2004 				THREE.ShaderChunk[ "default_vertex" ],
2005 
2006 				THREE.ShaderChunk[ "worldpos_vertex" ],
2007 				THREE.ShaderChunk[ "envmap_vertex" ],
2008 				THREE.ShaderChunk[ "shadowmap_vertex" ],
2009 
2010 			"}"
2011 
2012 		].join("\n"),
2013 
2014 		fragmentShader: [
2015 
2016 			"uniform vec3 diffuse;",
2017 			"uniform float opacity;",
2018 
2019 			THREE.ShaderChunk[ "color_pars_fragment" ],
2020 			THREE.ShaderChunk[ "map_pars_fragment" ],
2021 			THREE.ShaderChunk[ "lightmap_pars_fragment" ],
2022 			THREE.ShaderChunk[ "envmap_pars_fragment" ],
2023 			THREE.ShaderChunk[ "fog_pars_fragment" ],
2024 			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
2025 			THREE.ShaderChunk[ "specularmap_pars_fragment" ],
2026 
2027 			"void main() {",
2028 
2029 				"gl_FragColor = vec4( diffuse, opacity );",
2030 
2031 				THREE.ShaderChunk[ "map_fragment" ],
2032 				THREE.ShaderChunk[ "alphatest_fragment" ],
2033 				THREE.ShaderChunk[ "specularmap_fragment" ],
2034 				THREE.ShaderChunk[ "lightmap_fragment" ],
2035 				THREE.ShaderChunk[ "color_fragment" ],
2036 				THREE.ShaderChunk[ "envmap_fragment" ],
2037 				THREE.ShaderChunk[ "shadowmap_fragment" ],
2038 
2039 				THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
2040 
2041 				THREE.ShaderChunk[ "fog_fragment" ],
2042 
2043 			"}"
2044 
2045 		].join("\n")
2046 
2047 	},
2048 
2049 	'lambert': {
2050 
2051 		uniforms: THREE.UniformsUtils.merge( [
2052 
2053 			THREE.UniformsLib[ "common" ],
2054 			THREE.UniformsLib[ "fog" ],
2055 			THREE.UniformsLib[ "lights" ],
2056 			THREE.UniformsLib[ "shadowmap" ],
2057 
2058 			{
2059 				"ambient"  : { type: "c", value: new THREE.Color( 0xffffff ) },
2060 				"emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
2061 				"wrapRGB"  : { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
2062 			}
2063 
2064 		] ),
2065 
2066 		vertexShader: [
2067 
2068 			"#define LAMBERT",
2069 
2070 			"varying vec3 vLightFront;",
2071 
2072 			"#ifdef DOUBLE_SIDED",
2073 
2074 				"varying vec3 vLightBack;",
2075 
2076 			"#endif",
2077 
2078 			THREE.ShaderChunk[ "map_pars_vertex" ],
2079 			THREE.ShaderChunk[ "lightmap_pars_vertex" ],
2080 			THREE.ShaderChunk[ "envmap_pars_vertex" ],
2081 			THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
2082 			THREE.ShaderChunk[ "color_pars_vertex" ],
2083 			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
2084 			THREE.ShaderChunk[ "skinning_pars_vertex" ],
2085 			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
2086 
2087 			"void main() {",
2088 
2089 				THREE.ShaderChunk[ "map_vertex" ],
2090 				THREE.ShaderChunk[ "lightmap_vertex" ],
2091 				THREE.ShaderChunk[ "color_vertex" ],
2092 
2093 				THREE.ShaderChunk[ "morphnormal_vertex" ],
2094 				THREE.ShaderChunk[ "skinbase_vertex" ],
2095 				THREE.ShaderChunk[ "skinnormal_vertex" ],
2096 				THREE.ShaderChunk[ "defaultnormal_vertex" ],
2097 
2098 				THREE.ShaderChunk[ "morphtarget_vertex" ],
2099 				THREE.ShaderChunk[ "skinning_vertex" ],
2100 				THREE.ShaderChunk[ "default_vertex" ],
2101 
2102 				THREE.ShaderChunk[ "worldpos_vertex" ],
2103 				THREE.ShaderChunk[ "envmap_vertex" ],
2104 				THREE.ShaderChunk[ "lights_lambert_vertex" ],
2105 				THREE.ShaderChunk[ "shadowmap_vertex" ],
2106 
2107 			"}"
2108 
2109 		].join("\n"),
2110 
2111 		fragmentShader: [
2112 
2113 			"uniform float opacity;",
2114 
2115 			"varying vec3 vLightFront;",
2116 
2117 			"#ifdef DOUBLE_SIDED",
2118 
2119 				"varying vec3 vLightBack;",
2120 
2121 			"#endif",
2122 
2123 			THREE.ShaderChunk[ "color_pars_fragment" ],
2124 			THREE.ShaderChunk[ "map_pars_fragment" ],
2125 			THREE.ShaderChunk[ "lightmap_pars_fragment" ],
2126 			THREE.ShaderChunk[ "envmap_pars_fragment" ],
2127 			THREE.ShaderChunk[ "fog_pars_fragment" ],
2128 			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
2129 			THREE.ShaderChunk[ "specularmap_pars_fragment" ],
2130 
2131 			"void main() {",
2132 
2133 				"gl_FragColor = vec4( vec3 ( 1.0 ), opacity );",
2134 
2135 				THREE.ShaderChunk[ "map_fragment" ],
2136 				THREE.ShaderChunk[ "alphatest_fragment" ],
2137 				THREE.ShaderChunk[ "specularmap_fragment" ],
2138 
2139 				"#ifdef DOUBLE_SIDED",
2140 
2141 					//"float isFront = float( gl_FrontFacing );",
2142 					//"gl_FragColor.xyz *= isFront * vLightFront + ( 1.0 - isFront ) * vLightBack;",
2143 
2144 					"if ( gl_FrontFacing )",
2145 						"gl_FragColor.xyz *= vLightFront;",
2146 					"else",
2147 						"gl_FragColor.xyz *= vLightBack;",
2148 
2149 				"#else",
2150 
2151 					"gl_FragColor.xyz *= vLightFront;",
2152 
2153 				"#endif",
2154 
2155 				THREE.ShaderChunk[ "lightmap_fragment" ],
2156 				THREE.ShaderChunk[ "color_fragment" ],
2157 				THREE.ShaderChunk[ "envmap_fragment" ],
2158 				THREE.ShaderChunk[ "shadowmap_fragment" ],
2159 
2160 				THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
2161 
2162 				THREE.ShaderChunk[ "fog_fragment" ],
2163 
2164 			"}"
2165 
2166 		].join("\n")
2167 
2168 	},
2169 
2170 	'phong': {
2171 
2172 		uniforms: THREE.UniformsUtils.merge( [
2173 
2174 			THREE.UniformsLib[ "common" ],
2175 			THREE.UniformsLib[ "bump" ],
2176 			THREE.UniformsLib[ "normalmap" ],
2177 			THREE.UniformsLib[ "fog" ],
2178 			THREE.UniformsLib[ "lights" ],
2179 			THREE.UniformsLib[ "shadowmap" ],
2180 
2181 			{
2182 				"ambient"  : { type: "c", value: new THREE.Color( 0xffffff ) },
2183 				"emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
2184 				"specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
2185 				"shininess": { type: "f", value: 30 },
2186 				"wrapRGB"  : { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
2187 			}
2188 
2189 		] ),
2190 
2191 		vertexShader: [
2192 
2193 			"#define PHONG",
2194 
2195 			"varying vec3 vViewPosition;",
2196 			"varying vec3 vNormal;",
2197 
2198 			THREE.ShaderChunk[ "map_pars_vertex" ],
2199 			THREE.ShaderChunk[ "lightmap_pars_vertex" ],
2200 			THREE.ShaderChunk[ "envmap_pars_vertex" ],
2201 			THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
2202 			THREE.ShaderChunk[ "color_pars_vertex" ],
2203 			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
2204 			THREE.ShaderChunk[ "skinning_pars_vertex" ],
2205 			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
2206 
2207 			"void main() {",
2208 
2209 				THREE.ShaderChunk[ "map_vertex" ],
2210 				THREE.ShaderChunk[ "lightmap_vertex" ],
2211 				THREE.ShaderChunk[ "color_vertex" ],
2212 
2213 				THREE.ShaderChunk[ "morphnormal_vertex" ],
2214 				THREE.ShaderChunk[ "skinbase_vertex" ],
2215 				THREE.ShaderChunk[ "skinnormal_vertex" ],
2216 				THREE.ShaderChunk[ "defaultnormal_vertex" ],
2217 
2218 				"vNormal = normalize( transformedNormal );",
2219 
2220 				THREE.ShaderChunk[ "morphtarget_vertex" ],
2221 				THREE.ShaderChunk[ "skinning_vertex" ],
2222 				THREE.ShaderChunk[ "default_vertex" ],
2223 
2224 				"vViewPosition = -mvPosition.xyz;",
2225 
2226 				THREE.ShaderChunk[ "worldpos_vertex" ],
2227 				THREE.ShaderChunk[ "envmap_vertex" ],
2228 				THREE.ShaderChunk[ "lights_phong_vertex" ],
2229 				THREE.ShaderChunk[ "shadowmap_vertex" ],
2230 
2231 			"}"
2232 
2233 		].join("\n"),
2234 
2235 		fragmentShader: [
2236 
2237 			"uniform vec3 diffuse;",
2238 			"uniform float opacity;",
2239 
2240 			"uniform vec3 ambient;",
2241 			"uniform vec3 emissive;",
2242 			"uniform vec3 specular;",
2243 			"uniform float shininess;",
2244 
2245 			THREE.ShaderChunk[ "color_pars_fragment" ],
2246 			THREE.ShaderChunk[ "map_pars_fragment" ],
2247 			THREE.ShaderChunk[ "lightmap_pars_fragment" ],
2248 			THREE.ShaderChunk[ "envmap_pars_fragment" ],
2249 			THREE.ShaderChunk[ "fog_pars_fragment" ],
2250 			THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
2251 			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
2252 			THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
2253 			THREE.ShaderChunk[ "normalmap_pars_fragment" ],
2254 			THREE.ShaderChunk[ "specularmap_pars_fragment" ],
2255 
2256 			"void main() {",
2257 
2258 				"gl_FragColor = vec4( vec3 ( 1.0 ), opacity );",
2259 
2260 				THREE.ShaderChunk[ "map_fragment" ],
2261 				THREE.ShaderChunk[ "alphatest_fragment" ],
2262 				THREE.ShaderChunk[ "specularmap_fragment" ],
2263 
2264 				THREE.ShaderChunk[ "lights_phong_fragment" ],
2265 
2266 				THREE.ShaderChunk[ "lightmap_fragment" ],
2267 				THREE.ShaderChunk[ "color_fragment" ],
2268 				THREE.ShaderChunk[ "envmap_fragment" ],
2269 				THREE.ShaderChunk[ "shadowmap_fragment" ],
2270 
2271 				THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
2272 
2273 				THREE.ShaderChunk[ "fog_fragment" ],
2274 
2275 			"}"
2276 
2277 		].join("\n")
2278 
2279 	},
2280 
2281 	'particle_basic': {
2282 
2283 		uniforms:  THREE.UniformsUtils.merge( [
2284 
2285 			THREE.UniformsLib[ "particle" ],
2286 			THREE.UniformsLib[ "shadowmap" ]
2287 
2288 		] ),
2289 
2290 		vertexShader: [
2291 
2292 			"uniform float size;",
2293 			"uniform float scale;",
2294 
2295 			THREE.ShaderChunk[ "color_pars_vertex" ],
2296 			THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
2297 
2298 			"void main() {",
2299 
2300 				THREE.ShaderChunk[ "color_vertex" ],
2301 
2302 				"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
2303 
2304 				"#ifdef USE_SIZEATTENUATION",
2305 					"gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
2306 				"#else",
2307 					"gl_PointSize = size;",
2308 				"#endif",
2309 
2310 				"gl_Position = projectionMatrix * mvPosition;",
2311 
2312 				THREE.ShaderChunk[ "worldpos_vertex" ],
2313 				THREE.ShaderChunk[ "shadowmap_vertex" ],
2314 
2315 			"}"
2316 
2317 		].join("\n"),
2318 
2319 		fragmentShader: [
2320 
2321 			"uniform vec3 psColor;",
2322 			"uniform float opacity;",
2323 
2324 			THREE.ShaderChunk[ "color_pars_fragment" ],
2325 			THREE.ShaderChunk[ "map_particle_pars_fragment" ],
2326 			THREE.ShaderChunk[ "fog_pars_fragment" ],
2327 			THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
2328 
2329 			"void main() {",
2330 
2331 				"gl_FragColor = vec4( psColor, opacity );",
2332 
2333 				THREE.ShaderChunk[ "map_particle_fragment" ],
2334 				THREE.ShaderChunk[ "alphatest_fragment" ],
2335 				THREE.ShaderChunk[ "color_fragment" ],
2336 				THREE.ShaderChunk[ "shadowmap_fragment" ],
2337 				THREE.ShaderChunk[ "fog_fragment" ],
2338 
2339 			"}"
2340 
2341 		].join("\n")
2342 
2343 	},
2344 
2345 	'dashed': {
2346 
2347 		uniforms: THREE.UniformsUtils.merge( [
2348 
2349 			THREE.UniformsLib[ "common" ],
2350 			THREE.UniformsLib[ "fog" ],
2351 
2352 			{
2353 				"scale":     { type: "f", value: 1 },
2354 				"dashSize":  { type: "f", value: 1 },
2355 				"totalSize": { type: "f", value: 2 }
2356 			}
2357 
2358 		] ),
2359 
2360 		vertexShader: [
2361 
2362 			"uniform float scale;",
2363 			"attribute float lineDistance;",
2364 
2365 			"varying float vLineDistance;",
2366 
2367 			THREE.ShaderChunk[ "color_pars_vertex" ],
2368 
2369 			"void main() {",
2370 
2371 				THREE.ShaderChunk[ "color_vertex" ],
2372 
2373 				"vLineDistance = scale * lineDistance;",
2374 
2375 				"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
2376 				"gl_Position = projectionMatrix * mvPosition;",
2377 
2378 			"}"
2379 
2380 		].join("\n"),
2381 
2382 		fragmentShader: [
2383 
2384 			"uniform vec3 diffuse;",
2385 			"uniform float opacity;",
2386 
2387 			"uniform float dashSize;",
2388 			"uniform float totalSize;",
2389 
2390 			"varying float vLineDistance;",
2391 
2392 			THREE.ShaderChunk[ "color_pars_fragment" ],
2393 			THREE.ShaderChunk[ "fog_pars_fragment" ],
2394 
2395 			"void main() {",
2396 
2397 				"if ( mod( vLineDistance, totalSize ) > dashSize ) {",
2398 
2399 					"discard;",
2400 
2401 				"}",
2402 
2403 				"gl_FragColor = vec4( diffuse, opacity );",
2404 
2405 				THREE.ShaderChunk[ "color_fragment" ],
2406 				THREE.ShaderChunk[ "fog_fragment" ],
2407 
2408 			"}"
2409 
2410 		].join("\n")
2411 
2412 	},
2413 
2414 	// Depth encoding into RGBA texture
2415 	// 	based on SpiderGL shadow map example
2416 	// 		http://spidergl.org/example.php?id=6
2417 	// 	originally from
2418 	//		http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
2419 	// 	see also here:
2420 	//		http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
2421 
2422 	'depthRGBA': {
2423 
2424 		uniforms: {},
2425 
2426 		vertexShader: [
2427 
2428 			THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
2429 			THREE.ShaderChunk[ "skinning_pars_vertex" ],
2430 
2431 			"void main() {",
2432 
2433 				THREE.ShaderChunk[ "skinbase_vertex" ],
2434 				THREE.ShaderChunk[ "morphtarget_vertex" ],
2435 				THREE.ShaderChunk[ "skinning_vertex" ],
2436 				THREE.ShaderChunk[ "default_vertex" ],
2437 
2438 			"}"
2439 
2440 		].join("\n"),
2441 
2442 		fragmentShader: [
2443 
2444 			"vec4 pack_depth( const in float depth ) {",
2445 
2446 				"const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
2447 				"const vec4 bit_mask  = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
2448 				"vec4 res = fract( depth * bit_shift );",
2449 				"res -= res.xxyz * bit_mask;",
2450 				"return res;",
2451 
2452 			"}",
2453 
2454 			"void main() {",
2455 
2456 				"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
2457 
2458 				//"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
2459 				//"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
2460 				//"gl_FragData[ 0 ] = pack_depth( z );",
2461 				//"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
2462 
2463 			"}"
2464 
2465 		].join("\n")
2466 
2467 	}
2468 
2469 };
2470 

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