Skip to content

THREE.WebGLShader: gl.getShaderInfoLog() vertex WARNING: 0:1: extension 'GL_ARB_gpu_shader5' is not supported #10316

Closed
@therocketforever

Description

While following this tutorial errors in firefox console; still seems to render fine. error only appears in firefox. chrome & safari on desktop, mobile(6s) works fine no error.

Firefox Developer Edition - 52.0a2 (2016-12-08) (64-bit)
MacBook (Retina, 12-inch, Early 2015) macOS Sierra 10.12.1

THREE.WebGLShader: gl.getShaderInfoLog() vertex WARNING: 0:1: extension 'GL_ARB_gpu_shader5' is not supported
 1: precision highp float;
2: precision highp int;
3: #define SHADER_NAME MeshLambertMaterial
4: #define VERTEX_TEXTURES
5: #define GAMMA_FACTOR 2
6: #define MAX_BONES 251
7: #define NUM_CLIPPING_PLANES 0
8: uniform mat4 modelMatrix;
9: uniform mat4 modelViewMatrix;
10: uniform mat4 projectionMatrix;
11: uniform mat4 viewMatrix;
12: uniform mat3 normalMatrix;
13: uniform vec3 cameraPosition;
14: attribute vec3 position;
15: attribute vec3 normal;
16: attribute vec2 uv;
17: #ifdef USE_COLOR
18: 	attribute vec3 color;
19: #endif
20: #ifdef USE_MORPHTARGETS
21: 	attribute vec3 morphTarget0;
22: 	attribute vec3 morphTarget1;
23: 	attribute vec3 morphTarget2;
24: 	attribute vec3 morphTarget3;
25: 	#ifdef USE_MORPHNORMALS
26: 		attribute vec3 morphNormal0;
27: 		attribute vec3 morphNormal1;
28: 		attribute vec3 morphNormal2;
29: 		attribute vec3 morphNormal3;
30: 	#else
31: 		attribute vec3 morphTarget4;
32: 		attribute vec3 morphTarget5;
33: 		attribute vec3 morphTarget6;
34: 		attribute vec3 morphTarget7;
35: 	#endif
36: #endif
37: #ifdef USE_SKINNING
38: 	attribute vec4 skinIndex;
39: 	attribute vec4 skinWeight;
40: #endif
41: 
42: #define LAMBERT
43: varying vec3 vLightFront;
44: #ifdef DOUBLE_SIDED
45: 	varying vec3 vLightBack;
46: #endif
47: #define PI 3.14159265359
48: #define PI2 6.28318530718
49: #define RECIPROCAL_PI 0.31830988618
50: #define RECIPROCAL_PI2 0.15915494
51: #define LOG2 1.442695
52: #define EPSILON 1e-6
53: #define saturate(a) clamp( a, 0.0, 1.0 )
54: #define whiteCompliment(a) ( 1.0 - saturate( a ) )
55: float pow2( const in float x ) { return x*x; }
56: float pow3( const in float x ) { return x*x*x; }
57: float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
58: float average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }
59: highp float rand( const in vec2 uv ) {
60: 	const highp float a = 12.9898, b = 78.233, c = 43758.5453;
61: 	highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
62: 	return fract(sin(sn) * c);
63: }
64: struct IncidentLight {
65: 	vec3 color;
66: 	vec3 direction;
67: 	bool visible;
68: };
69: struct ReflectedLight {
70: 	vec3 directDiffuse;
71: 	vec3 directSpecular;
72: 	vec3 indirectDiffuse;
73: 	vec3 indirectSpecular;
74: };
75: struct GeometricContext {
76: 	vec3 position;
77: 	vec3 normal;
78: 	vec3 viewDir;
79: };
80: vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
81: 	return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
82: }
83: vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
84: 	return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );
85: }
86: vec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
87: 	float distance = dot( planeNormal, point - pointOnPlane );
88: 	return - distance * planeNormal + point;
89: }
90: float sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
91: 	return sign( dot( point - pointOnPlane, planeNormal ) );
92: }
93: vec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {
94: 	return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;
95: }
96: 
97: #if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )
98: 	varying vec2 vUv;
99: 	uniform vec4 offsetRepeat;
100: #endif
101: 
102: #if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )
103: 	attribute vec2 uv2;
104: 	varying vec2 vUv2;
105: #endif
106: #ifdef USE_ENVMAP
107: 	#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )
108: 		varying vec3 vWorldPosition;
109: 	#else
110: 		varying vec3 vReflect;
111: 		uniform float refractionRatio;
112: 	#endif
113: #endif
114: 
115: bool testLightInRange( const in float lightDistance, const in float cutoffDistance ) {
116: 	return any( bvec2( cutoffDistance == 0.0, lightDistance < cutoffDistance ) );
117: }
118: float punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
119: 		if( decayExponent > 0.0 ) {
120: #if defined ( PHYSICALLY_CORRECT_LIGHTS )
121: 			float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
122: 			float maxDistanceCutoffFactor = pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
123: 			return distanceFalloff * maxDistanceCutoffFactor;
124: #else
125: 			return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );
126: #endif
127: 		}
128: 		return 1.0;
129: }
130: vec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {
131: 	return RECIPROCAL_PI * diffuseColor;
132: }
133: vec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {
134: 	float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );
135: 	return ( 1.0 - specularColor ) * fresnel + specularColor;
136: }
137: float G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {
138: 	float a2 = pow2( alpha );
139: 	float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
140: 	float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
141: 	return 1.0 / ( gl * gv );
142: }
143: float G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
144: 	float a2 = pow2( alpha );
145: 	float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
146: 	float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
147: 	return 0.5 / max( gv + gl, EPSILON );
148: }
149: float D_GGX( const in float alpha, const in float dotNH ) {
150: 	float a2 = pow2( alpha );
151: 	float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;
152: 	return RECIPROCAL_PI * a2 / pow2( denom );
153: }
154: vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
155: 	float alpha = pow2( roughness );
156: 	vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
157: 	float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );
158: 	float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
159: 	float dotNH = saturate( dot( geometry.normal, halfDir ) );
160: 	float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
161: 	vec3 F = F_Schlick( specularColor, dotLH );
162: 	float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );
163: 	float D = D_GGX( alpha, dotNH );
164: 	return F * ( G * D );
165: }
166: vec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
167: 	float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
168: 	const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );
169: 	const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );
170: 	vec4 r = roughness * c0 + c1;
171: 	float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;
172: 	vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;
173: 	return specularColor * AB.x + AB.y;
174: }
175: float G_BlinnPhong_Implicit( ) {
176: 	return 0.25;
177: }
178: float D_BlinnPhong( const in float shininess, const in float dotNH ) {
179: 	return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
180: }
181: vec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {
182: 	vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
183: 	float dotNH = saturate( dot( geometry.normal, halfDir ) );
184: 	float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
185: 	vec3 F = F_Schlick( specularColor, dotLH );
186: 	float G = G_BlinnPhong_Implicit( );
187: 	float D = D_BlinnPhong( shininess, dotNH );
188: 	return F * ( G * D );
189: }
190: float GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {
191: 	return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );
192: }
193: float BlinnExponentToGGXRoughness( const in float blinnExponent ) {
194: 	return sqrt( 2.0 / ( blinnExponent + 2.0 ) );
195: }
196: 
197: uniform vec3 ambientLightColor;
198: vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
199: 	vec3 irradiance = ambientLightColor;
200: 	#ifndef PHYSICALLY_CORRECT_LIGHTS
201: 		irradiance *= PI;
202: 	#endif
203: 	return irradiance;
204: }
205: #if 0 > 0
206: 	struct DirectionalLight {
207: 		vec3 direction;
208: 		vec3 color;
209: 		int shadow;
210: 		float shadowBias;
211: 		float shadowRadius;
212: 		vec2 shadowMapSize;
213: 	};
214: 	uniform DirectionalLight directionalLights[ 0 ];
215: 	void getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {
216: 		directLight.color = directionalLight.color;
217: 		directLight.direction = directionalLight.direction;
218: 		directLight.visible = true;
219: 	}
220: #endif
221: #if 1 > 0
222: 	struct PointLight {
223: 		vec3 position;
224: 		vec3 color;
225: 		float distance;
226: 		float decay;
227: 		int shadow;
228: 		float shadowBias;
229: 		float shadowRadius;
230: 		vec2 shadowMapSize;
231: 	};
232: 	uniform PointLight pointLights[ 1 ];
233: 	void getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {
234: 		vec3 lVector = pointLight.position - geometry.position;
235: 		directLight.direction = normalize( lVector );
236: 		float lightDistance = length( lVector );
237: 		if ( testLightInRange( lightDistance, pointLight.distance ) ) {
238: 			directLight.color = pointLight.color;
239: 			directLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );
240: 			directLight.visible = true;
241: 		} else {
242: 			directLight.color = vec3( 0.0 );
243: 			directLight.visible = false;
244: 		}
245: 	}
246: #endif
247: #if 0 > 0
248: 	struct SpotLight {
249: 		vec3 position;
250: 		vec3 direction;
251: 		vec3 color;
252: 		float distance;
253: 		float decay;
254: 		float coneCos;
255: 		float penumbraCos;
256: 		int shadow;
257: 		float shadowBias;
258: 		float shadowRadius;
259: 		vec2 shadowMapSize;
260: 	};
261: 	uniform SpotLight spotLights[ 0 ];
262: 	void getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight  ) {
263: 		vec3 lVector = spotLight.position - geometry.position;
264: 		directLight.direction = normalize( lVector );
265: 		float lightDistance = length( lVector );
266: 		float angleCos = dot( directLight.direction, spotLight.direction );
267: 		if ( all( bvec2( angleCos > spotLight.coneCos, testLightInRange( lightDistance, spotLight.distance ) ) ) ) {
268: 			float spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );
269: 			directLight.color = spotLight.color;
270: 			directLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );
271: 			directLight.visible = true;
272: 		} else {
273: 			directLight.color = vec3( 0.0 );
274: 			directLight.visible = false;
275: 		}
276: 	}
277: #endif
278: #if 0 > 0
279: 	struct HemisphereLight {
280: 		vec3 direction;
281: 		vec3 skyColor;
282: 		vec3 groundColor;
283: 	};
284: 	uniform HemisphereLight hemisphereLights[ 0 ];
285: 	vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {
286: 		float dotNL = dot( geometry.normal, hemiLight.direction );
287: 		float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
288: 		vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
289: 		#ifndef PHYSICALLY_CORRECT_LIGHTS
290: 			irradiance *= PI;
291: 		#endif
292: 		return irradiance;
293: 	}
294: #endif
295: #if defined( USE_ENVMAP ) && defined( PHYSICAL )
296: 	vec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {
297: 		#ifdef DOUBLE_SIDED
298: 	float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );
299: #else
300: 	float flipNormal = 1.0;
301: #endif
302: 
303: 		vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );
304: 		#ifdef ENVMAP_TYPE_CUBE
305: 			vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );
306: 			#ifdef TEXTURE_LOD_EXT
307: 				vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );
308: 			#else
309: 				vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );
310: 			#endif
311: 			envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
312: 		#elif defined( ENVMAP_TYPE_CUBE_UV )
313: 			vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );
314: 			vec4 envMapColor = textureCubeUV( queryVec, 1.0 );
315: 		#else
316: 			vec4 envMapColor = vec4( 0.0 );
317: 		#endif
318: 		return PI * envMapColor.rgb * envMapIntensity;
319: 	}
320: 	float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {
321: 		float maxMIPLevelScalar = float( maxMIPLevel );
322: 		float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );
323: 		return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );
324: 	}
325: 	vec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {
326: 		#ifdef ENVMAP_MODE_REFLECTION
327: 			vec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );
328: 		#else
329: 			vec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );
330: 		#endif
331: 		#ifdef DOUBLE_SIDED
332: 	float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );
333: #else
334: 	float flipNormal = 1.0;
335: #endif
336: 
337: 		reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
338: 		float specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );
339: 		#ifdef ENVMAP_TYPE_CUBE
340: 			vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );
341: 			#ifdef TEXTURE_LOD_EXT
342: 				vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );
343: 			#else
344: 				vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );
345: 			#endif
346: 			envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
347: 		#elif defined( ENVMAP_TYPE_CUBE_UV )
348: 			vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );
349: 			vec4 envMapColor = textureCubeUV(queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent));
350: 		#elif defined( ENVMAP_TYPE_EQUIREC )
351: 			vec2 sampleUV;
352: 			sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );
353: 			sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;
354: 			#ifdef TEXTURE_LOD_EXT
355: 				vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );
356: 			#else
357: 				vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );
358: 			#endif
359: 			envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
360: 		#elif defined( ENVMAP_TYPE_SPHERE )
361: 			vec3 reflectView = flipNormal * normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );
362: 			#ifdef TEXTURE_LOD_EXT
363: 				vec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );
364: 			#else
365: 				vec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );
366: 			#endif
367: 			envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
368: 		#endif
369: 		return envMapColor.rgb * envMapIntensity;
370: 	}
371: #endif
372: 
373: #ifdef USE_COLOR
374: 	varying vec3 vColor;
375: #endif
376: #ifdef USE_MORPHTARGETS
377: 	#ifndef USE_MORPHNORMALS
378: 	uniform float morphTargetInfluences[ 8 ];
379: 	#else
380: 	uniform float morphTargetInfluences[ 4 ];
381: 	#endif
382: #endif
383: #ifdef USE_SKINNING
384: 	uniform mat4 bindMatrix;
385: 	uniform mat4 bindMatrixInverse;
386: 	#ifdef BONE_TEXTURE
387: 		uniform sampler2D boneTexture;
388: 		uniform int boneTextureWidth;
389: 		uniform int boneTextureHeight;
390: 		mat4 getBoneMatrix( const in float i ) {
391: 			float j = i * 4.0;
392: 			float x = mod( j, float( boneTextureWidth ) );
393: 			float y = floor( j / float( boneTextureWidth ) );
394: 			float dx = 1.0 / float( boneTextureWidth );
395: 			float dy = 1.0 / float( boneTextureHeight );
396: 			y = dy * ( y + 0.5 );
397: 			vec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );
398: 			vec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );
399: 			vec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );
400: 			vec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );
401: 			mat4 bone = mat4( v1, v2, v3, v4 );
402: 			return bone;
403: 		}
404: 	#else
405: 		uniform mat4 boneMatrices[ MAX_BONES ];
406: 		mat4 getBoneMatrix( const in float i ) {
407: 			mat4 bone = boneMatrices[ int(i) ];
408: 			return bone;
409: 		}
410: 	#endif
411: #endif
412: 
413: #ifdef USE_SHADOWMAP
414: 	#if 0 > 0
415: 		uniform mat4 directionalShadowMatrix[ 0 ];
416: 		varying vec4 vDirectionalShadowCoord[ 0 ];
417: 	#endif
418: 	#if 0 > 0
419: 		uniform mat4 spotShadowMatrix[ 0 ];
420: 		varying vec4 vSpotShadowCoord[ 0 ];
421: 	#endif
422: 	#if 1 > 0
423: 		uniform mat4 pointShadowMatrix[ 1 ];
424: 		varying vec4 vPointShadowCoord[ 1 ];
425: 	#endif
426: #endif
427: 
428: #ifdef USE_LOGDEPTHBUF
429: 	#ifdef USE_LOGDEPTHBUF_EXT
430: 		varying float vFragDepth;
431: 	#endif
432: 	uniform float logDepthBufFC;
433: #endif
434: #if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )
435: 	varying vec3 vViewPosition;
436: #endif
437: 
438: void main() {
439: 	#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )
440: 	vUv = uv * offsetRepeat.zw + offsetRepeat.xy;
441: #endif
442: 	#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )
443: 	vUv2 = uv2;
444: #endif
445: 	#ifdef USE_COLOR
446: 	vColor.xyz = color.xyz;
447: #endif
448: 	
449: vec3 objectNormal = vec3( normal );
450: 
451: 	#ifdef USE_MORPHNORMALS
452: 	objectNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];
453: 	objectNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];
454: 	objectNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];
455: 	objectNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];
456: #endif
457: 
458: 	#ifdef USE_SKINNING
459: 	mat4 boneMatX = getBoneMatrix( skinIndex.x );
460: 	mat4 boneMatY = getBoneMatrix( skinIndex.y );
461: 	mat4 boneMatZ = getBoneMatrix( skinIndex.z );
462: 	mat4 boneMatW = getBoneMatrix( skinIndex.w );
463: #endif
464: 	#ifdef USE_SKINNING
465: 	mat4 skinMatrix = mat4( 0.0 );
466: 	skinMatrix += skinWeight.x * boneMatX;
467: 	skinMatrix += skinWeight.y * boneMatY;
468: 	skinMatrix += skinWeight.z * boneMatZ;
469: 	skinMatrix += skinWeight.w * boneMatW;
470: 	skinMatrix  = bindMatrixInverse * skinMatrix * bindMatrix;
471: 	objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;
472: #endif
473: 
474: 	#ifdef FLIP_SIDED
475: 	objectNormal = -objectNormal;
476: #endif
477: vec3 transformedNormal = normalMatrix * objectNormal;
478: 
479: 	
480: vec3 transformed = vec3( position );
481: 
482: 	#ifdef USE_MORPHTARGETS
483: 	transformed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];
484: 	transformed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];
485: 	transformed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];
486: 	transformed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];
487: 	#ifndef USE_MORPHNORMALS
488: 	transformed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];
489: 	transformed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];
490: 	transformed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];
491: 	transformed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];
492: 	#endif
493: #endif
494: 
495: 	#ifdef USE_SKINNING
496: 	vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );
497: 	vec4 skinned = vec4( 0.0 );
498: 	skinned += boneMatX * skinVertex * skinWeight.x;
499: 	skinned += boneMatY * skinVertex * skinWeight.y;
500: 	skinned += boneMatZ * skinVertex * skinWeight.z;
501: 	skinned += boneMatW * skinVertex * skinWeight.w;
502: 	skinned  = bindMatrixInverse * skinned;
503: #endif
504: 
505: 	#ifdef USE_SKINNING
506: 	vec4 mvPosition = modelViewMatrix * skinned;
507: #else
508: 	vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );
509: #endif
510: gl_Position = projectionMatrix * mvPosition;
511: 
512: 	#ifdef USE_LOGDEPTHBUF
513: 	gl_Position.z = log2(max( EPSILON, gl_Position.w + 1.0 )) * logDepthBufFC;
514: 	#ifdef USE_LOGDEPTHBUF_EXT
515: 		vFragDepth = 1.0 + gl_Position.w;
516: 	#else
517: 		gl_Position.z = (gl_Position.z - 1.0) * gl_Position.w;
518: 	#endif
519: #endif
520: 
521: 	#if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG )
522: 	vViewPosition = - mvPosition.xyz;
523: #endif
524: 
525: 	#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( PHYSICAL ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )
526: 	#ifdef USE_SKINNING
527: 		vec4 worldPosition = modelMatrix * skinned;
528: 	#else
529: 		vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );
530: 	#endif
531: #endif
532: 
533: 	#ifdef USE_ENVMAP
534: 	#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )
535: 		vWorldPosition = worldPosition.xyz;
536: 	#else
537: 		vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );
538: 		vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
539: 		#ifdef ENVMAP_MODE_REFLECTION
540: 			vReflect = reflect( cameraToVertex, worldNormal );
541: 		#else
542: 			vReflect = refract( cameraToVertex, worldNormal, refractionRatio );
543: 		#endif
544: 	#endif
545: #endif
546: 
547: 	vec3 diffuse = vec3( 1.0 );
548: GeometricContext geometry;
549: geometry.position = mvPosition.xyz;
550: geometry.normal = normalize( transformedNormal );
551: geometry.viewDir = normalize( -mvPosition.xyz );
552: GeometricContext backGeometry;
553: backGeometry.position = geometry.position;
554: backGeometry.normal = -geometry.normal;
555: backGeometry.viewDir = geometry.viewDir;
556: vLightFront = vec3( 0.0 );
557: #ifdef DOUBLE_SIDED
558: 	vLightBack = vec3( 0.0 );
559: #endif
560: IncidentLight directLight;
561: float dotNL;
562: vec3 directLightColor_Diffuse;
563: #if 1 > 0
564: 	
565: 		getPointDirectLightIrradiance( pointLights[ 0 ], geometry, directLight );
566: 		dotNL = dot( geometry.normal, directLight.direction );
567: 		directLightColor_Diffuse = PI * directLight.color;
568: 		vLightFront += saturate( dotNL ) * directLightColor_Diffuse;
569: 		#ifdef DOUBLE_SIDED
570: 			vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;
571: 		#endif
572: 	
573: #endif
574: #if 0 > 0
575: 	
576: #endif
577: #if 0 > 0
578: 	
579: #endif
580: #if 0 > 0
581: 	
582: #endif
583: 
584: 	#ifdef USE_SHADOWMAP
585: 	#if 0 > 0
586: 	
587: 	#endif
588: 	#if 0 > 0
589: 	
590: 	#endif
591: 	#if 1 > 0
592: 	
593: 		vPointShadowCoord[ 0 ] = pointShadowMatrix[ 0 ] * worldPosition;
594: 	
595: 	#endif
596: #endif
597: 
598: }
599:   1:84838:4
THREE.WebGLShader: gl.getShaderInfoLog() fragment WARNING: 0:1: extension 'GL_ARB_gpu_shader5' is not supported
 1: precision highp float;
2: precision highp int;
3: #define SHADER_NAME MeshLambertMaterial
4: #define GAMMA_FACTOR 2
5: #define NUM_CLIPPING_PLANES 0
6: #define UNION_CLIPPING_PLANES 0
7: uniform mat4 viewMatrix;
8: uniform vec3 cameraPosition;
9: #define TONE_MAPPING
10: #define saturate(a) clamp( a, 0.0, 1.0 )
11: uniform float toneMappingExposure;
12: uniform float toneMappingWhitePoint;
13: vec3 LinearToneMapping( vec3 color ) {
14:   return toneMappingExposure * color;
15: }
16: vec3 ReinhardToneMapping( vec3 color ) {
17:   color *= toneMappingExposure;
18:   return saturate( color / ( vec3( 1.0 ) + color ) );
19: }
20: #define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )
21: vec3 Uncharted2ToneMapping( vec3 color ) {
22:   color *= toneMappingExposure;
23:   return saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );
24: }
25: vec3 OptimizedCineonToneMapping( vec3 color ) {
26:   color *= toneMappingExposure;
27:   color = max( vec3( 0.0 ), color - 0.004 );
28:   return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );
29: }
30: 
31: vec3 toneMapping( vec3 color ) { return LinearToneMapping( color ); }
32: 
33: vec4 LinearToLinear( in vec4 value ) {
34:   return value;
35: }
36: vec4 GammaToLinear( in vec4 value, in float gammaFactor ) {
37:   return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );
38: }
39: vec4 LinearToGamma( in vec4 value, in float gammaFactor ) {
40:   return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );
41: }
42: vec4 sRGBToLinear( in vec4 value ) {
43:   return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );
44: }
45: vec4 LinearTosRGB( in vec4 value ) {
46:   return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.w );
47: }
48: vec4 RGBEToLinear( in vec4 value ) {
49:   return vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );
50: }
51: vec4 LinearToRGBE( in vec4 value ) {
52:   float maxComponent = max( max( value.r, value.g ), value.b );
53:   float fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );
54:   return vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );
55: }
56: vec4 RGBMToLinear( in vec4 value, in float maxRange ) {
57:   return vec4( value.xyz * value.w * maxRange, 1.0 );
58: }
59: vec4 LinearToRGBM( in vec4 value, in float maxRange ) {
60:   float maxRGB = max( value.x, max( value.g, value.b ) );
61:   float M      = clamp( maxRGB / maxRange, 0.0, 1.0 );
62:   M            = ceil( M * 255.0 ) / 255.0;
63:   return vec4( value.rgb / ( M * maxRange ), M );
64: }
65: vec4 RGBDToLinear( in vec4 value, in float maxRange ) {
66:     return vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );
67: }
68: vec4 LinearToRGBD( in vec4 value, in float maxRange ) {
69:     float maxRGB = max( value.x, max( value.g, value.b ) );
70:     float D      = max( maxRange / maxRGB, 1.0 );
71:     D            = min( floor( D ) / 255.0, 1.0 );
72:     return vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );
73: }
74: const mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );
75: vec4 LinearToLogLuv( in vec4 value )  {
76:   vec3 Xp_Y_XYZp = value.rgb * cLogLuvM;
77:   Xp_Y_XYZp = max(Xp_Y_XYZp, vec3(1e-6, 1e-6, 1e-6));
78:   vec4 vResult;
79:   vResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;
80:   float Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;
81:   vResult.w = fract(Le);
82:   vResult.z = (Le - (floor(vResult.w*255.0))/255.0)/255.0;
83:   return vResult;
84: }
85: const mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );
86: vec4 LogLuvToLinear( in vec4 value ) {
87:   float Le = value.z * 255.0 + value.w;
88:   vec3 Xp_Y_XYZp;
89:   Xp_Y_XYZp.y = exp2((Le - 127.0) / 2.0);
90:   Xp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;
91:   Xp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;
92:   vec3 vRGB = Xp_Y_XYZp.rgb * cLogLuvInverseM;
93:   return vec4( max(vRGB, 0.0), 1.0 );
94: }
95: 
96: vec4 mapTexelToLinear( vec4 value ) { return LinearToLinear( value ); }
97: vec4 envMapTexelToLinear( vec4 value ) { return LinearToLinear( value ); }
98: vec4 emissiveMapTexelToLinear( vec4 value ) { return LinearToLinear( value ); }
99: vec4 linearToOutputTexel( vec4 value ) { return LinearToLinear( value ); }
100: 
101: uniform vec3 diffuse;
102: uniform vec3 emissive;
103: uniform float opacity;
104: varying vec3 vLightFront;
105: #ifdef DOUBLE_SIDED
106: 	varying vec3 vLightBack;
107: #endif
108: #define PI 3.14159265359
109: #define PI2 6.28318530718
110: #define RECIPROCAL_PI 0.31830988618
111: #define RECIPROCAL_PI2 0.15915494
112: #define LOG2 1.442695
113: #define EPSILON 1e-6
114: #define saturate(a) clamp( a, 0.0, 1.0 )
115: #define whiteCompliment(a) ( 1.0 - saturate( a ) )
116: float pow2( const in float x ) { return x*x; }
117: float pow3( const in float x ) { return x*x*x; }
118: float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
119: float average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }
120: highp float rand( const in vec2 uv ) {
121: 	const highp float a = 12.9898, b = 78.233, c = 43758.5453;
122: 	highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
123: 	return fract(sin(sn) * c);
124: }
125: struct IncidentLight {
126: 	vec3 color;
127: 	vec3 direction;
128: 	bool visible;
129: };
130: struct ReflectedLight {
131: 	vec3 directDiffuse;
132: 	vec3 directSpecular;
133: 	vec3 indirectDiffuse;
134: 	vec3 indirectSpecular;
135: };
136: struct GeometricContext {
137: 	vec3 position;
138: 	vec3 normal;
139: 	vec3 viewDir;
140: };
141: vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
142: 	return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
143: }
144: vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
145: 	return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );
146: }
147: vec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
148: 	float distance = dot( planeNormal, point - pointOnPlane );
149: 	return - distance * planeNormal + point;
150: }
151: float sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
152: 	return sign( dot( point - pointOnPlane, planeNormal ) );
153: }
154: vec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {
155: 	return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;
156: }
157: 
158: vec3 packNormalToRGB( const in vec3 normal ) {
159:   return normalize( normal ) * 0.5 + 0.5;
160: }
161: vec3 unpackRGBToNormal( const in vec3 rgb ) {
162:   return 1.0 - 2.0 * rgb.xyz;
163: }
164: const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;
165: const vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256.,  256. );
166: const vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );
167: const float ShiftRight8 = 1. / 256.;
168: vec4 packDepthToRGBA( const in float v ) {
169: 	vec4 r = vec4( fract( v * PackFactors ), v );
170: 	r.yzw -= r.xyz * ShiftRight8;	return r * PackUpscale;
171: }
172: float unpackRGBAToDepth( const in vec4 v ) {
173: 	return dot( v, UnpackFactors );
174: }
175: float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {
176:   return ( viewZ + near ) / ( near - far );
177: }
178: float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {
179:   return linearClipZ * ( near - far ) - near;
180: }
181: float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
182:   return (( near + viewZ ) * far ) / (( far - near ) * viewZ );
183: }
184: float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {
185:   return ( near * far ) / ( ( far - near ) * invClipZ - far );
186: }
187: 
188: #ifdef USE_COLOR
189: 	varying vec3 vColor;
190: #endif
191: 
192: #if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )
193: 	varying vec2 vUv;
194: #endif
195: #if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )
196: 	varying vec2 vUv2;
197: #endif
198: #ifdef USE_MAP
199: 	uniform sampler2D map;
200: #endif
201: 
202: #ifdef USE_ALPHAMAP
203: 	uniform sampler2D alphaMap;
204: #endif
205: 
206: #ifdef USE_AOMAP
207: 	uniform sampler2D aoMap;
208: 	uniform float aoMapIntensity;
209: #endif
210: #ifdef USE_LIGHTMAP
211: 	uniform sampler2D lightMap;
212: 	uniform float lightMapIntensity;
213: #endif
214: #ifdef USE_EMISSIVEMAP
215: 	uniform sampler2D emissiveMap;
216: #endif
217: 
218: #if defined( USE_ENVMAP ) || defined( PHYSICAL )
219: 	uniform float reflectivity;
220: 	uniform float envMapIntenstiy;
221: #endif
222: #ifdef USE_ENVMAP
223: 	#if ! defined( PHYSICAL ) && ( defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) )
224: 		varying vec3 vWorldPosition;
225: 	#endif
226: 	#ifdef ENVMAP_TYPE_CUBE
227: 		uniform samplerCube envMap;
228: 	#else
229: 		uniform sampler2D envMap;
230: 	#endif
231: 	uniform float flipEnvMap;
232: 	#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL )
233: 		uniform float refractionRatio;
234: 	#else
235: 		varying vec3 vReflect;
236: 	#endif
237: #endif
238: 
239: bool testLightInRange( const in float lightDistance, const in float cutoffDistance ) {
240: 	return any( bvec2( cutoffDistance == 0.0, lightDistance < cutoffDistance ) );
241: }
242: float punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
243: 		if( decayExponent > 0.0 ) {
244: #if defined ( PHYSICALLY_CORRECT_LIGHTS )
245: 			float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
246: 			float maxDistanceCutoffFactor = pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
247: 			return distanceFalloff * maxDistanceCutoffFactor;
248: #else
249: 			return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );
250: #endif
251: 		}
252: 		return 1.0;
253: }
254: vec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {
255: 	return RECIPROCAL_PI * diffuseColor;
256: }
257: vec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {
258: 	float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );
259: 	return ( 1.0 - specularColor ) * fresnel + specularColor;
260: }
261: float G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {
262: 	float a2 = pow2( alpha );
263: 	float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
264: 	float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
265: 	return 1.0 / ( gl * gv );
266: }
267: float G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
268: 	float a2 = pow2( alpha );
269: 	float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
270: 	float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
271: 	return 0.5 / max( gv + gl, EPSILON );
272: }
273: float D_GGX( const in float alpha, const in float dotNH ) {
274: 	float a2 = pow2( alpha );
275: 	float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;
276: 	return RECIPROCAL_PI * a2 / pow2( denom );
277: }
278: vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
279: 	float alpha = pow2( roughness );
280: 	vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
281: 	float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );
282: 	float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
283: 	float dotNH = saturate( dot( geometry.normal, halfDir ) );
284: 	float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
285: 	vec3 F = F_Schlick( specularColor, dotLH );
286: 	float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );
287: 	float D = D_GGX( alpha, dotNH );
288: 	return F * ( G * D );
289: }
290: vec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
291: 	float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
292: 	const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );
293: 	const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );
294: 	vec4 r = roughness * c0 + c1;
295: 	float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;
296: 	vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;
297: 	return specularColor * AB.x + AB.y;
298: }
299: float G_BlinnPhong_Implicit( ) {
300: 	return 0.25;
301: }
302: float D_BlinnPhong( const in float shininess, const in float dotNH ) {
303: 	return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
304: }
305: vec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {
306: 	vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
307: 	float dotNH = saturate( dot( geometry.normal, halfDir ) );
308: 	float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
309: 	vec3 F = F_Schlick( specularColor, dotLH );
310: 	float G = G_BlinnPhong_Implicit( );
311: 	float D = D_BlinnPhong( shininess, dotNH );
312: 	return F * ( G * D );
313: }
314: float GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {
315: 	return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );
316: }
317: float BlinnExponentToGGXRoughness( const in float blinnExponent ) {
318: 	return sqrt( 2.0 / ( blinnExponent + 2.0 ) );
319: }
320: 
321: uniform vec3 ambientLightColor;
322: vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
323: 	vec3 irradiance = ambientLightColor;
324: 	#ifndef PHYSICALLY_CORRECT_LIGHTS
325: 		irradiance *= PI;
326: 	#endif
327: 	return irradiance;
328: }
329: #if 0 > 0
330: 	struct DirectionalLight {
331: 		vec3 direction;
332: 		vec3 color;
333: 		int shadow;
334: 		float shadowBias;
335: 		float shadowRadius;
336: 		vec2 shadowMapSize;
337: 	};
338: 	uniform DirectionalLight directionalLights[ 0 ];
339: 	void getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {
340: 		directLight.color = directionalLight.color;
341: 		directLight.direction = directionalLight.direction;
342: 		directLight.visible = true;
343: 	}
344: #endif
345: #if 1 > 0
346: 	struct PointLight {
347: 		vec3 position;
348: 		vec3 color;
349: 		float distance;
350: 		float decay;
351: 		int shadow;
352: 		float shadowBias;
353: 		float shadowRadius;
354: 		vec2 shadowMapSize;
355: 	};
356: 	uniform PointLight pointLights[ 1 ];
357: 	void getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {
358: 		vec3 lVector = pointLight.position - geometry.position;
359: 		directLight.direction = normalize( lVector );
360: 		float lightDistance = length( lVector );
361: 		if ( testLightInRange( lightDistance, pointLight.distance ) ) {
362: 			directLight.color = pointLight.color;
363: 			directLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );
364: 			directLight.visible = true;
365: 		} else {
366: 			directLight.color = vec3( 0.0 );
367: 			directLight.visible = false;
368: 		}
369: 	}
370: #endif
371: #if 0 > 0
372: 	struct SpotLight {
373: 		vec3 position;
374: 		vec3 direction;
375: 		vec3 color;
376: 		float distance;
377: 		float decay;
378: 		float coneCos;
379: 		float penumbraCos;
380: 		int shadow;
381: 		float shadowBias;
382: 		float shadowRadius;
383: 		vec2 shadowMapSize;
384: 	};
385: 	uniform SpotLight spotLights[ 0 ];
386: 	void getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight  ) {
387: 		vec3 lVector = spotLight.position - geometry.position;
388: 		directLight.direction = normalize( lVector );
389: 		float lightDistance = length( lVector );
390: 		float angleCos = dot( directLight.direction, spotLight.direction );
391: 		if ( all( bvec2( angleCos > spotLight.coneCos, testLightInRange( lightDistance, spotLight.distance ) ) ) ) {
392: 			float spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );
393: 			directLight.color = spotLight.color;
394: 			directLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );
395: 			directLight.visible = true;
396: 		} else {
397: 			directLight.color = vec3( 0.0 );
398: 			directLight.visible = false;
399: 		}
400: 	}
401: #endif
402: #if 0 > 0
403: 	struct HemisphereLight {
404: 		vec3 direction;
405: 		vec3 skyColor;
406: 		vec3 groundColor;
407: 	};
408: 	uniform HemisphereLight hemisphereLights[ 0 ];
409: 	vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {
410: 		float dotNL = dot( geometry.normal, hemiLight.direction );
411: 		float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
412: 		vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
413: 		#ifndef PHYSICALLY_CORRECT_LIGHTS
414: 			irradiance *= PI;
415: 		#endif
416: 		return irradiance;
417: 	}
418: #endif
419: #if defined( USE_ENVMAP ) && defined( PHYSICAL )
420: 	vec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {
421: 		#ifdef DOUBLE_SIDED
422: 	float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );
423: #else
424: 	float flipNormal = 1.0;
425: #endif
426: 
427: 		vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );
428: 		#ifdef ENVMAP_TYPE_CUBE
429: 			vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );
430: 			#ifdef TEXTURE_LOD_EXT
431: 				vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );
432: 			#else
433: 				vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );
434: 			#endif
435: 			envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
436: 		#elif defined( ENVMAP_TYPE_CUBE_UV )
437: 			vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );
438: 			vec4 envMapColor = textureCubeUV( queryVec, 1.0 );
439: 		#else
440: 			vec4 envMapColor = vec4( 0.0 );
441: 		#endif
442: 		return PI * envMapColor.rgb * envMapIntensity;
443: 	}
444: 	float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {
445: 		float maxMIPLevelScalar = float( maxMIPLevel );
446: 		float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( pow2( blinnShininessExponent ) + 1.0 );
447: 		return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );
448: 	}
449: 	vec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {
450: 		#ifdef ENVMAP_MODE_REFLECTION
451: 			vec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );
452: 		#else
453: 			vec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );
454: 		#endif
455: 		#ifdef DOUBLE_SIDED
456: 	float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );
457: #else
458: 	float flipNormal = 1.0;
459: #endif
460: 
461: 		reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
462: 		float specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );
463: 		#ifdef ENVMAP_TYPE_CUBE
464: 			vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );
465: 			#ifdef TEXTURE_LOD_EXT
466: 				vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );
467: 			#else
468: 				vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );
469: 			#endif
470: 			envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
471: 		#elif defined( ENVMAP_TYPE_CUBE_UV )
472: 			vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );
473: 			vec4 envMapColor = textureCubeUV(queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent));
474: 		#elif defined( ENVMAP_TYPE_EQUIREC )
475: 			vec2 sampleUV;
476: 			sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );
477: 			sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;
478: 			#ifdef TEXTURE_LOD_EXT
479: 				vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );
480: 			#else
481: 				vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );
482: 			#endif
483: 			envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
484: 		#elif defined( ENVMAP_TYPE_SPHERE )
485: 			vec3 reflectView = flipNormal * normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );
486: 			#ifdef TEXTURE_LOD_EXT
487: 				vec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );
488: 			#else
489: 				vec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );
490: 			#endif
491: 			envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
492: 		#endif
493: 		return envMapColor.rgb * envMapIntensity;
494: 	}
495: #endif
496: 
497: #ifdef USE_FOG
498: 	uniform vec3 fogColor;
499: 	#ifdef FOG_EXP2
500: 		uniform float fogDensity;
501: 	#else
502: 		uniform float fogNear;
503: 		uniform float fogFar;
504: 	#endif
505: #endif
506: #ifdef USE_SHADOWMAP
507: 	#if 0 > 0
508: 		uniform sampler2D directionalShadowMap[ 0 ];
509: 		varying vec4 vDirectionalShadowCoord[ 0 ];
510: 	#endif
511: 	#if 0 > 0
512: 		uniform sampler2D spotShadowMap[ 0 ];
513: 		varying vec4 vSpotShadowCoord[ 0 ];
514: 	#endif
515: 	#if 1 > 0
516: 		uniform sampler2D pointShadowMap[ 1 ];
517: 		varying vec4 vPointShadowCoord[ 1 ];
518: 	#endif
519: 	float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {
520: 		return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );
521: 	}
522: 	float texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {
523: 		const vec2 offset = vec2( 0.0, 1.0 );
524: 		vec2 texelSize = vec2( 1.0 ) / size;
525: 		vec2 centroidUV = floor( uv * size + 0.5 ) / size;
526: 		float lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );
527: 		float lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );
528: 		float rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );
529: 		float rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );
530: 		vec2 f = fract( uv * size + 0.5 );
531: 		float a = mix( lb, lt, f.y );
532: 		float b = mix( rb, rt, f.y );
533: 		float c = mix( a, b, f.x );
534: 		return c;
535: 	}
536: 	float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
537: 		shadowCoord.xyz /= shadowCoord.w;
538: 		shadowCoord.z += shadowBias;
539: 		bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );
540: 		bool inFrustum = all( inFrustumVec );
541: 		bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );
542: 		bool frustumTest = all( frustumTestVec );
543: 		if ( frustumTest ) {
544: 		#if defined( SHADOWMAP_TYPE_PCF )
545: 			vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
546: 			float dx0 = - texelSize.x * shadowRadius;
547: 			float dy0 = - texelSize.y * shadowRadius;
548: 			float dx1 = + texelSize.x * shadowRadius;
549: 			float dy1 = + texelSize.y * shadowRadius;
550: 			return (
551: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +
552: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +
553: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +
554: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +
555: 				texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +
556: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +
557: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +
558: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +
559: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )
560: 			) * ( 1.0 / 9.0 );
561: 		#elif defined( SHADOWMAP_TYPE_PCF_SOFT )
562: 			vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
563: 			float dx0 = - texelSize.x * shadowRadius;
564: 			float dy0 = - texelSize.y * shadowRadius;
565: 			float dx1 = + texelSize.x * shadowRadius;
566: 			float dy1 = + texelSize.y * shadowRadius;
567: 			return (
568: 				texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +
569: 				texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +
570: 				texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +
571: 				texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +
572: 				texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +
573: 				texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +
574: 				texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +
575: 				texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +
576: 				texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )
577: 			) * ( 1.0 / 9.0 );
578: 		#else
579: 			return texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );
580: 		#endif
581: 		}
582: 		return 1.0;
583: 	}
584: 	vec2 cubeToUV( vec3 v, float texelSizeY ) {
585: 		vec3 absV = abs( v );
586: 		float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );
587: 		absV *= scaleToCube;
588: 		v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );
589: 		vec2 planar = v.xy;
590: 		float almostATexel = 1.5 * texelSizeY;
591: 		float almostOne = 1.0 - almostATexel;
592: 		if ( absV.z >= almostOne ) {
593: 			if ( v.z > 0.0 )
594: 				planar.x = 4.0 - v.x;
595: 		} else if ( absV.x >= almostOne ) {
596: 			float signX = sign( v.x );
597: 			planar.x = v.z * signX + 2.0 * signX;
598: 		} else if ( absV.y >= almostOne ) {
599: 			float signY = sign( v.y );
600: 			planar.x = v.x + 2.0 * signY + 2.0;
601: 			planar.y = v.z * signY - 2.0;
602: 		}
603: 		return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );
604: 	}
605: 	float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
606: 		vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );
607: 		vec3 lightToPosition = shadowCoord.xyz;
608: 		vec3 bd3D = normalize( lightToPosition );
609: 		float dp = ( length( lightToPosition ) - shadowBias ) / 1000.0;
610: 		#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )
611: 			vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;
612: 			return (
613: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +
614: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +
615: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +
616: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +
617: 				texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +
618: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +
619: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +
620: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +
621: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )
622: 			) * ( 1.0 / 9.0 );
623: 		#else
624: 			return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );
625: 		#endif
626: 	}
627: #endif
628: 
629: float getShadowMask() {
630: 	float shadow = 1.0;
631: 	#ifdef USE_SHADOWMAP
632: 	#if 0 > 0
633: 	DirectionalLight directionalLight;
634: 	
635: 	#endif
636: 	#if 0 > 0
637: 	SpotLight spotLight;
638: 	
639: 	#endif
640: 	#if 1 > 0
641: 	PointLight pointLight;
642: 	
643: 		pointLight = pointLights[ 0 ];
644: 		shadow *= bool( pointLight.shadow ) ? getPointShadow( pointShadowMap[ 0 ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ 0 ] ) : 1.0;
645: 	
646: 	#endif
647: 	#endif
648: 	return shadow;
649: }
650: 
651: #ifdef USE_SPECULARMAP
652: 	uniform sampler2D specularMap;
653: #endif
654: #ifdef USE_LOGDEPTHBUF
655: 	uniform float logDepthBufFC;
656: 	#ifdef USE_LOGDEPTHBUF_EXT
657: 		varying float vFragDepth;
658: 	#endif
659: #endif
660: 
661: #if NUM_CLIPPING_PLANES > 0
662: 	#if ! defined( PHYSICAL ) && ! defined( PHONG )
663: 		varying vec3 vViewPosition;
664: 	#endif
665: 	uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];
666: #endif
667: 
668: void main() {
669: 	#if NUM_CLIPPING_PLANES > 0
670: 	for ( int i = 0; i < UNION_CLIPPING_PLANES; ++ i ) {
671: 		vec4 plane = clippingPlanes[ i ];
672: 		if ( dot( vViewPosition, plane.xyz ) > plane.w ) discard;
673: 	}
674: 		
675: 	#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
676: 		bool clipped = true;
677: 		for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; ++ i ) {
678: 			vec4 plane = clippingPlanes[ i ];
679: 			clipped = ( dot( vViewPosition, plane.xyz ) > plane.w ) && clipped;
680: 		}
681: 		if ( clipped ) discard;
682: 	
683: 	#endif
684: #endif
685: 
686: 	vec4 diffuseColor = vec4( diffuse, opacity );
687: 	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
688: 	vec3 totalEmissiveRadiance = emissive;
689: 	#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)
690: 	gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;
691: #endif
692: 	#ifdef USE_MAP
693: 	vec4 texelColor = texture2D( map, vUv );
694: 	texelColor = mapTexelToLinear( texelColor );
695: 	diffuseColor *= texelColor;
696: #endif
697: 
698: 	#ifdef USE_COLOR
699: 	diffuseColor.rgb *= vColor;
700: #endif
701: 	#ifdef USE_ALPHAMAP
702: 	diffuseColor.a *= texture2D( alphaMap, vUv ).g;
703: #endif
704: 
705: 	#ifdef ALPHATEST
706: 	if ( diffuseColor.a < ALPHATEST ) discard;
707: #endif
708: 
709: 	float specularStrength;
710: #ifdef USE_SPECULARMAP
711: 	vec4 texelSpecular = texture2D( specularMap, vUv );
712: 	specularStrength = texelSpecular.r;
713: #else
714: 	specularStrength = 1.0;
715: #endif
716: 	#ifdef USE_EMISSIVEMAP
717: 	vec4 emissiveColor = texture2D( emissiveMap, vUv );
718: 	emissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;
719: 	totalEmissiveRadiance *= emissiveColor.rgb;
720: #endif
721: 
722: 	reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );
723: 	#ifdef USE_LIGHTMAP
724: 	reflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;
725: #endif
726: 
727: 	reflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );
728: 	#ifdef DOUBLE_SIDED
729: 		reflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;
730: 	#else
731: 		reflectedLight.directDiffuse = vLightFront;
732: 	#endif
733: 	reflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();
734: 	#ifdef USE_AOMAP
735: 	float ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;
736: 	reflectedLight.indirectDiffuse *= ambientOcclusion;
737: 	#if defined( USE_ENVMAP ) && defined( PHYSICAL )
738: 		float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
739: 		reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );
740: 	#endif
741: #endif
742: 
743: 	vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
744: 	#ifdef DOUBLE_SIDED
745: 	float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );
746: #else
747: 	float flipNormal = 1.0;
748: #endif
749: 
750: 	#ifdef USE_ENVMAP
751: 	#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )
752: 		vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );
753: 		vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
754: 		#ifdef ENVMAP_MODE_REFLECTION
755: 			vec3 reflectVec = reflect( cameraToVertex, worldNormal );
756: 		#else
757: 			vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );
758: 		#endif
759: 	#else
760: 		vec3 reflectVec = vReflect;
761: 	#endif
762: 	#ifdef ENVMAP_TYPE_CUBE
763: 		vec4 envColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );
764: 	#elif defined( ENVMAP_TYPE_EQUIREC )
765: 		vec2 sampleUV;
766: 		sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );
767: 		sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;
768: 		vec4 envColor = texture2D( envMap, sampleUV );
769: 	#elif defined( ENVMAP_TYPE_SPHERE )
770: 		vec3 reflectView = flipNormal * normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) );
771: 		vec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );
772: 	#else
773: 		vec4 envColor = vec4( 0.0 );
774: 	#endif
775: 	envColor = envMapTexelToLinear( envColor );
776: 	#ifdef ENVMAP_BLENDING_MULTIPLY
777: 		outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );
778: 	#elif defined( ENVMAP_BLENDING_MIX )
779: 		outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );
780: 	#elif defined( ENVMAP_BLENDING_ADD )
781: 		outgoingLight += envColor.xyz * specularStrength * reflectivity;
782: 	#endif
783: #endif
784: 
785: 	gl_FragColor = vec4( outgoingLight, diffuseColor.a );
786: 	#ifdef PREMULTIPLIED_ALPHA
787: 	gl_FragColor.rgb *= gl_FragColor.a;
788: #endif
789: 
790: 	#if defined( TONE_MAPPING )
791:   gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
792: #endif
793: 
794: 	  gl_FragColor = linearToOutputTexel( gl_FragColor );
795: 
796: 	#ifdef USE_FOG
797: 	#ifdef USE_LOGDEPTHBUF_EXT
798: 		float depth = gl_FragDepthEXT / gl_FragCoord.w;
799: 	#else
800: 		float depth = gl_FragCoord.z / gl_FragCoord.w;
801: 	#endif
802: 	#ifdef FOG_EXP2
803: 		float fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * depth * depth * LOG2 ) );
804: 	#else
805: 		float fogFactor = smoothstep( fogNear, fogFar, depth );
806: 	#endif
807: 	gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );
808: #endif
809: 
810: }
811:

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions