What is this error?

Hi I’m wondering if anyone can help me understand what this error is?

Sorry it’s so long!

THREE.WebGLShader: gl.getShaderInfoLog() fragment
1: #extension GL_OES_standard_derivatives : enable
2: #extension GL_EXT_shader_texture_lod : enable
3: precision highp float;
4: precision highp int;
5: #define HIGH_PRECISION
6: #define SHADER_NAME MeshStandardMaterial
7: #define STANDARD 
8: #define GAMMA_FACTOR 2
9: #define USE_FOG
10: #define FOG_EXP2
11: #define USE_ENVMAP
12: #define ENVMAP_TYPE_CUBE_UV
13: #define ENVMAP_MODE_REFLECTION
14: #define ENVMAP_BLENDING_NONE
15: #define DOUBLE_SIDED
16: #define TEXTURE_LOD_EXT
17: uniform mat4 viewMatrix;
18: uniform vec3 cameraPosition;
19: uniform bool isOrthographic;
20: #define TONE_MAPPING
21: #ifndef saturate
22: #define saturate(a) clamp( a, 0.0, 1.0 )
23: #endif
24: uniform float toneMappingExposure;
25: uniform float toneMappingWhitePoint;
26: vec3 LinearToneMapping( vec3 color ) {
27: 	return toneMappingExposure * color;
28: }
29: vec3 ReinhardToneMapping( vec3 color ) {
30: 	color *= toneMappingExposure;
31: 	return saturate( color / ( vec3( 1.0 ) + color ) );
32: }
33: #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 ) )
34: vec3 Uncharted2ToneMapping( vec3 color ) {
35: 	color *= toneMappingExposure;
36: 	return saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );
37: }
38: vec3 OptimizedCineonToneMapping( vec3 color ) {
39: 	color *= toneMappingExposure;
40: 	color = max( vec3( 0.0 ), color - 0.004 );
41: 	return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );
42: }
43: vec3 ACESFilmicToneMapping( vec3 color ) {
44: 	color *= toneMappingExposure;
45: 	return saturate( ( color * ( 2.51 * color + 0.03 ) ) / ( color * ( 2.43 * color + 0.59 ) + 0.14 ) );
46: }
47: vec3 toneMapping( vec3 color ) { return ACESFilmicToneMapping( color ); }
48: 
49: vec4 LinearToLinear( in vec4 value ) {
50: 	return value;
51: }
52: vec4 GammaToLinear( in vec4 value, in float gammaFactor ) {
53: 	return vec4( pow( value.rgb, vec3( gammaFactor ) ), value.a );
54: }
55: vec4 LinearToGamma( in vec4 value, in float gammaFactor ) {
56: 	return vec4( pow( value.rgb, vec3( 1.0 / gammaFactor ) ), value.a );
57: }
58: vec4 sRGBToLinear( in vec4 value ) {
59: 	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.a );
60: }
61: vec4 LinearTosRGB( in vec4 value ) {
62: 	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.a );
63: }
64: vec4 RGBEToLinear( in vec4 value ) {
65: 	return vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );
66: }
67: vec4 LinearToRGBE( in vec4 value ) {
68: 	float maxComponent = max( max( value.r, value.g ), value.b );
69: 	float fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );
70: 	return vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );
71: }
72: vec4 RGBMToLinear( in vec4 value, in float maxRange ) {
73: 	return vec4( value.rgb * value.a * maxRange, 1.0 );
74: }
75: vec4 LinearToRGBM( in vec4 value, in float maxRange ) {
76: 	float maxRGB = max( value.r, max( value.g, value.b ) );
77: 	float M = clamp( maxRGB / maxRange, 0.0, 1.0 );
78: 	M = ceil( M * 255.0 ) / 255.0;
79: 	return vec4( value.rgb / ( M * maxRange ), M );
80: }
81: vec4 RGBDToLinear( in vec4 value, in float maxRange ) {
82: 	return vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );
83: }
84: vec4 LinearToRGBD( in vec4 value, in float maxRange ) {
85: 	float maxRGB = max( value.r, max( value.g, value.b ) );
86: 	float D = max( maxRange / maxRGB, 1.0 );
87: 	D = clamp( floor( D ) / 255.0, 0.0, 1.0 );
88: 	return vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );
89: }
90: const mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );
91: vec4 LinearToLogLuv( in vec4 value )  {
92: 	vec3 Xp_Y_XYZp = cLogLuvM * value.rgb;
93: 	Xp_Y_XYZp = max( Xp_Y_XYZp, vec3( 1e-6, 1e-6, 1e-6 ) );
94: 	vec4 vResult;
95: 	vResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;
96: 	float Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;
97: 	vResult.w = fract( Le );
98: 	vResult.z = ( Le - ( floor( vResult.w * 255.0 ) ) / 255.0 ) / 255.0;
99: 	return vResult;
100: }
101: const mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );
102: vec4 LogLuvToLinear( in vec4 value ) {
103: 	float Le = value.z * 255.0 + value.w;
104: 	vec3 Xp_Y_XYZp;
105: 	Xp_Y_XYZp.y = exp2( ( Le - 127.0 ) / 2.0 );
106: 	Xp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;
107: 	Xp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;
108: 	vec3 vRGB = cLogLuvInverseM * Xp_Y_XYZp.rgb;
109: 	return vec4( max( vRGB, 0.0 ), 1.0 );
110: }
111: vec4 mapTexelToLinear( vec4 value ) { return LinearToLinear( value ); }
112: vec4 matcapTexelToLinear( vec4 value ) { return LinearToLinear( value ); }
113: vec4 envMapTexelToLinear( vec4 value ) { return RGBEToLinear( value ); }
114: vec4 emissiveMapTexelToLinear( vec4 value ) { return LinearToLinear( value ); }
115: vec4 lightMapTexelToLinear( vec4 value ) { return LinearToLinear( value ); }
116: vec4 linearToOutputTexel( vec4 value ) { return LinearTosRGB( value ); }
117: 
118: #define STANDARD
119: #ifdef PHYSICAL
120: 	#define REFLECTIVITY
121: 	#define CLEARCOAT
122: 	#define TRANSPARENCY
123: #endif
124: uniform vec3 diffuse;
125: uniform vec3 emissive;
126: uniform float roughness;
127: uniform float metalness;
128: uniform float opacity;
129: #ifdef TRANSPARENCY
130: 	uniform float transparency;
131: #endif
132: #ifdef REFLECTIVITY
133: 	uniform float reflectivity;
134: #endif
135: #ifdef CLEARCOAT
136: 	uniform float clearcoat;
137: 	uniform float clearcoatRoughness;
138: #endif
139: #ifdef USE_SHEEN
140: 	uniform vec3 sheen;
141: #endif
142: varying vec3 vViewPosition;
143: #ifndef FLAT_SHADED
144: 	varying vec3 vNormal;
145: 	#ifdef USE_TANGENT
146: 		varying vec3 vTangent;
147: 		varying vec3 vBitangent;
148: 	#endif
149: #endif
150: #define PI 3.14159265359
151: #define PI2 6.28318530718
152: #define PI_HALF 1.5707963267949
153: #define RECIPROCAL_PI 0.31830988618
154: #define RECIPROCAL_PI2 0.15915494
155: #define LOG2 1.442695
156: #define EPSILON 1e-6
157: #ifndef saturate
158: #define saturate(a) clamp( a, 0.0, 1.0 )
159: #endif
160: #define whiteComplement(a) ( 1.0 - saturate( a ) )
161: float pow2( const in float x ) { return x*x; }
162: float pow3( const in float x ) { return x*x*x; }
163: float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
164: float average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }
165: highp float rand( const in vec2 uv ) {
166: 	const highp float a = 12.9898, b = 78.233, c = 43758.5453;
167: 	highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
168: 	return fract(sin(sn) * c);
169: }
170: #ifdef HIGH_PRECISION
171: 	float precisionSafeLength( vec3 v ) { return length( v ); }
172: #else
173: 	float max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }
174: 	float precisionSafeLength( vec3 v ) {
175: 		float maxComponent = max3( abs( v ) );
176: 		return length( v / maxComponent ) * maxComponent;
177: 	}
178: #endif
179: struct IncidentLight {
180: 	vec3 color;
181: 	vec3 direction;
182: 	bool visible;
183: };
184: struct ReflectedLight {
185: 	vec3 directDiffuse;
186: 	vec3 directSpecular;
187: 	vec3 indirectDiffuse;
188: 	vec3 indirectSpecular;
189: };
190: struct GeometricContext {
191: 	vec3 position;
192: 	vec3 normal;
193: 	vec3 viewDir;
194: #ifdef CLEARCOAT
195: 	vec3 clearcoatNormal;
196: #endif
197: };
198: vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
199: 	return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
200: }
201: vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
202: 	return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );
203: }
204: vec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
205: 	float distance = dot( planeNormal, point - pointOnPlane );
206: 	return - distance * planeNormal + point;
207: }
208: float sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {
209: 	return sign( dot( point - pointOnPlane, planeNormal ) );
210: }
211: vec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {
212: 	return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;
213: }
214: mat3 transposeMat3( const in mat3 m ) {
215: 	mat3 tmp;
216: 	tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );
217: 	tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );
218: 	tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );
219: 	return tmp;
220: }
221: float linearToRelativeLuminance( const in vec3 color ) {
222: 	vec3 weights = vec3( 0.2126, 0.7152, 0.0722 );
223: 	return dot( weights, color.rgb );
224: }
225: bool isPerspectiveMatrix( mat4 m ) {
226:   return m[ 2 ][ 3 ] == - 1.0;
227: }
228: vec3 packNormalToRGB( const in vec3 normal ) {
229: 	return normalize( normal ) * 0.5 + 0.5;
230: }
231: vec3 unpackRGBToNormal( const in vec3 rgb ) {
232: 	return 2.0 * rgb.xyz - 1.0;
233: }
234: const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;
235: const vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256.,  256. );
236: const vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );
237: const float ShiftRight8 = 1. / 256.;
238: vec4 packDepthToRGBA( const in float v ) {
239: 	vec4 r = vec4( fract( v * PackFactors ), v );
240: 	r.yzw -= r.xyz * ShiftRight8;	return r * PackUpscale;
241: }
242: float unpackRGBAToDepth( const in vec4 v ) {
243: 	return dot( v, UnpackFactors );
244: }
245: vec4 pack2HalfToRGBA( vec2 v ) {
246: 	vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ));
247: 	return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w);
248: }
249: vec2 unpackRGBATo2Half( vec4 v ) {
250: 	return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
251: }
252: float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {
253: 	return ( viewZ + near ) / ( near - far );
254: }
255: float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {
256: 	return linearClipZ * ( near - far ) - near;
257: }
258: float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
259: 	return (( near + viewZ ) * far ) / (( far - near ) * viewZ );
260: }
261: float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {
262: 	return ( near * far ) / ( ( far - near ) * invClipZ - far );
263: }
264: #ifdef DITHERING
265: 	vec3 dithering( vec3 color ) {
266: 		float grid_position = rand( gl_FragCoord.xy );
267: 		vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );
268: 		dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );
269: 		return color + dither_shift_RGB;
270: 	}
271: #endif
272: #ifdef USE_COLOR
273: 	varying vec3 vColor;
274: #endif
275: #if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )
276: 	varying vec2 vUv;
277: #endif
278: #if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )
279: 	varying vec2 vUv2;
280: #endif
281: #ifdef USE_MAP
282: 	uniform sampler2D map;
283: #endif
284: #ifdef USE_ALPHAMAP
285: 	uniform sampler2D alphaMap;
286: #endif
287: #ifdef USE_AOMAP
288: 	uniform sampler2D aoMap;
289: 	uniform float aoMapIntensity;
290: #endif
291: #ifdef USE_LIGHTMAP
292: 	uniform sampler2D lightMap;
293: 	uniform float lightMapIntensity;
294: #endif
295: #ifdef USE_EMISSIVEMAP
296: 	uniform sampler2D emissiveMap;
297: #endif
298: vec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {
299: 	const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );
300: 	const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );
301: 	vec4 r = roughness * c0 + c1;
302: 	float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;
303: 	return vec2( -1.04, 1.04 ) * a004 + r.zw;
304: }
305: float punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
306: #if defined ( PHYSICALLY_CORRECT_LIGHTS )
307: 	float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
308: 	if( cutoffDistance > 0.0 ) {
309: 		distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
310: 	}
311: 	return distanceFalloff;
312: #else
313: 	if( cutoffDistance > 0.0 && decayExponent > 0.0 ) {
314: 		return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );
315: 	}
316: 	return 1.0;
317: #endif
318: }
319: vec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {
320: 	return RECIPROCAL_PI * diffuseColor;
321: }
322: vec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {
323: 	float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );
324: 	return ( 1.0 - specularColor ) * fresnel + specularColor;
325: }
326: vec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {
327: 	float fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );
328: 	vec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;
329: 	return Fr * fresnel + F0;
330: }
331: float G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {
332: 	float a2 = pow2( alpha );
333: 	float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
334: 	float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
335: 	return 1.0 / ( gl * gv );
336: }
337: float G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
338: 	float a2 = pow2( alpha );
339: 	float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
340: 	float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
341: 	return 0.5 / max( gv + gl, EPSILON );
342: }
343: float D_GGX( const in float alpha, const in float dotNH ) {
344: 	float a2 = pow2( alpha );
345: 	float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;
346: 	return RECIPROCAL_PI * a2 / pow2( denom );
347: }
348: vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {
349: 	float alpha = pow2( roughness );
350: 	vec3 halfDir = normalize( incidentLight.direction + viewDir );
351: 	float dotNL = saturate( dot( normal, incidentLight.direction ) );
352: 	float dotNV = saturate( dot( normal, viewDir ) );
353: 	float dotNH = saturate( dot( normal, halfDir ) );
354: 	float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
355: 	vec3 F = F_Schlick( specularColor, dotLH );
356: 	float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );
357: 	float D = D_GGX( alpha, dotNH );
358: 	return F * ( G * D );
359: }
360: vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {
361: 	const float LUT_SIZE  = 64.0;
362: 	const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;
363: 	const float LUT_BIAS  = 0.5 / LUT_SIZE;
364: 	float dotNV = saturate( dot( N, V ) );
365: 	vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );
366: 	uv = uv * LUT_SCALE + LUT_BIAS;
367: 	return uv;
368: }
369: float LTC_ClippedSphereFormFactor( const in vec3 f ) {
370: 	float l = length( f );
371: 	return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );
372: }
373: vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {
374: 	float x = dot( v1, v2 );
375: 	float y = abs( x );
376: 	float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;
377: 	float b = 3.4175940 + ( 4.1616724 + y ) * y;
378: 	float v = a / b;
379: 	float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;
380: 	return cross( v1, v2 ) * theta_sintheta;
381: }
382: vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {
383: 	vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];
384: 	vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];
385: 	vec3 lightNormal = cross( v1, v2 );
386: 	if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );
387: 	vec3 T1, T2;
388: 	T1 = normalize( V - N * dot( V, N ) );
389: 	T2 = - cross( N, T1 );
390: 	mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );
391: 	vec3 coords[ 4 ];
392: 	coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );
393: 	coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );
394: 	coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );
395: 	coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );
396: 	coords[ 0 ] = normalize( coords[ 0 ] );
397: 	coords[ 1 ] = normalize( coords[ 1 ] );
398: 	coords[ 2 ] = normalize( coords[ 2 ] );
399: 	coords[ 3 ] = normalize( coords[ 3 ] );
400: 	vec3 vectorFormFactor = vec3( 0.0 );
401: 	vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );
402: 	vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );
403: 	vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );
404: 	vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );
405: 	float result = LTC_ClippedSphereFormFactor( vectorFormFactor );
406: 	return vec3( result );
407: }
408: vec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {
409: 	float dotNV = saturate( dot( normal, viewDir ) );
410: 	vec2 brdf = integrateSpecularBRDF( dotNV, roughness );
411: 	return specularColor * brdf.x + brdf.y;
412: }
413: void BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {
414: 	float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
415: 	vec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );
416: 	vec2 brdf = integrateSpecularBRDF( dotNV, roughness );
417: 	vec3 FssEss = F * brdf.x + brdf.y;
418: 	float Ess = brdf.x + brdf.y;
419: 	float Ems = 1.0 - Ess;
420: 	vec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;	vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );
421: 	singleScatter += FssEss;
422: 	multiScatter += Fms * Ems;
423: }
424: float G_BlinnPhong_Implicit( ) {
425: 	return 0.25;
426: }
427: float D_BlinnPhong( const in float shininess, const in float dotNH ) {
428: 	return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
429: }
430: vec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {
431: 	vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
432: 	float dotNH = saturate( dot( geometry.normal, halfDir ) );
433: 	float dotLH = saturate( dot( incidentLight.direction, halfDir ) );
434: 	vec3 F = F_Schlick( specularColor, dotLH );
435: 	float G = G_BlinnPhong_Implicit( );
436: 	float D = D_BlinnPhong( shininess, dotNH );
437: 	return F * ( G * D );
438: }
439: float GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {
440: 	return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );
441: }
442: float BlinnExponentToGGXRoughness( const in float blinnExponent ) {
443: 	return sqrt( 2.0 / ( blinnExponent + 2.0 ) );
444: }
445: #if defined( USE_SHEEN )
446: float D_Charlie(float roughness, float NoH) {
447: 	float invAlpha  = 1.0 / roughness;
448: 	float cos2h = NoH * NoH;
449: 	float sin2h = max(1.0 - cos2h, 0.0078125);	return (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);
450: }
451: float V_Neubelt(float NoV, float NoL) {
452: 	return saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));
453: }
454: vec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {
455: 	vec3 N = geometry.normal;
456: 	vec3 V = geometry.viewDir;
457: 	vec3 H = normalize( V + L );
458: 	float dotNH = saturate( dot( N, H ) );
459: 	return specularColor * D_Charlie( roughness, dotNH ) * V_Neubelt( dot(N, V), dot(N, L) );
460: }
461: #endif
462: #ifdef ENVMAP_TYPE_CUBE_UV
463: #define cubeUV_maxMipLevel 8.0
464: #define cubeUV_minMipLevel 4.0
465: #define cubeUV_maxTileSize 256.0
466: #define cubeUV_minTileSize 16.0
467: float getFace(vec3 direction) {
468:     vec3 absDirection = abs(direction);
469:     float face = -1.0;
470:     if (absDirection.x > absDirection.z) {
471:       if (absDirection.x > absDirection.y)
472:         face = direction.x > 0.0 ? 0.0 : 3.0;
473:       else
474:         face = direction.y > 0.0 ? 1.0 : 4.0;
475:     } else {
476:       if (absDirection.z > absDirection.y)
477:         face = direction.z > 0.0 ? 2.0 : 5.0;
478:       else
479:         face = direction.y > 0.0 ? 1.0 : 4.0;
480:     }
481:     return face;
482: }
483: vec2 getUV(vec3 direction, float face) {
484:     vec2 uv;
485:     if (face == 0.0) {
486:       uv = vec2(-direction.z, direction.y) / abs(direction.x);
487:     } else if (face == 1.0) {
488:       uv = vec2(direction.x, -direction.z) / abs(direction.y);
489:     } else if (face == 2.0) {
490:       uv = direction.xy / abs(direction.z);
491:     } else if (face == 3.0) {
492:       uv = vec2(direction.z, direction.y) / abs(direction.x);
493:     } else if (face == 4.0) {
494:       uv = direction.xz / abs(direction.y);
495:     } else {
496:       uv = vec2(-direction.x, direction.y) / abs(direction.z);
497:     }
498:     return 0.5 * (uv + 1.0);
499: }
500: vec3 bilinearCubeUV(sampler2D envMap, vec3 direction, float mipInt) {
501:   float face = getFace(direction);
502:   float filterInt = max(cubeUV_minMipLevel - mipInt, 0.0);
503:   mipInt = max(mipInt, cubeUV_minMipLevel);
504:   float faceSize = exp2(mipInt);
505:   float texelSize = 1.0 / (3.0 * cubeUV_maxTileSize);
506:   vec2 uv = getUV(direction, face) * (faceSize - 1.0);
507:   vec2 f = fract(uv);
508:   uv += 0.5 - f;
509:   if (face > 2.0) {
510:     uv.y += faceSize;
511:     face -= 3.0;
512:   }
513:   uv.x += face * faceSize;
514:   if(mipInt < cubeUV_maxMipLevel){
515:     uv.y += 2.0 * cubeUV_maxTileSize;
516:   }
517:   uv.y += filterInt * 2.0 * cubeUV_minTileSize;
518:   uv.x += 3.0 * max(0.0, cubeUV_maxTileSize - 2.0 * faceSize);
519:   uv *= texelSize;
520:   vec3 tl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
521:   uv.x += texelSize;
522:   vec3 tr = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
523:   uv.y += texelSize;
524:   vec3 br = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
525:   uv.x -= texelSize;
526:   vec3 bl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;
527:   vec3 tm = mix(tl, tr, f.x);
528:   vec3 bm = mix(bl, br, f.x);
529:   return mix(tm, bm, f.y);
530: }
531: #define r0 1.0
532: #define v0 0.339
533: #define m0 -2.0
534: #define r1 0.8
535: #define v1 0.276
536: #define m1 -1.0
537: #define r4 0.4
538: #define v4 0.046
539: #define m4 2.0
540: #define r5 0.305
541: #define v5 0.016
542: #define m5 3.0
543: #define r6 0.21
544: #define v6 0.0038
545: #define m6 4.0
546: float roughnessToMip(float roughness) {
547:   float mip = 0.0;
548:   if (roughness >= r1) {
549:     mip = (r0 - roughness) * (m1 - m0) / (r0 - r1) + m0;
550:   } else if (roughness >= r4) {
551:     mip = (r1 - roughness) * (m4 - m1) / (r1 - r4) + m1;
552:   } else if (roughness >= r5) {
553:     mip = (r4 - roughness) * (m5 - m4) / (r4 - r5) + m4;
554:   } else if (roughness >= r6) {
555:     mip = (r5 - roughness) * (m6 - m5) / (r5 - r6) + m5;
556:   } else {
557:     mip = -2.0 * log2(1.16 * roughness);  }
558:   return mip;
559: }
560: vec4 textureCubeUV(sampler2D envMap, vec3 sampleDir, float roughness) {
561:   float mip = clamp(roughnessToMip(roughness), m0, cubeUV_maxMipLevel);
562:   float mipF = fract(mip);
563:   float mipInt = floor(mip);
564:   vec3 color0 = bilinearCubeUV(envMap, sampleDir, mipInt);
565:   if (mipF == 0.0) {
566:     return vec4(color0, 1.0);
567:   } else {
568:     vec3 color1 = bilinearCubeUV(envMap, sampleDir, mipInt + 1.0);
569:     return vec4(mix(color0, color1, mipF), 1.0);
570:   }
571: }
572: #endif
573: #ifdef USE_ENVMAP
574: 	uniform float envMapIntensity;
575: 	uniform float flipEnvMap;
576: 	uniform int maxMipLevel;
577: 	#ifdef ENVMAP_TYPE_CUBE
578: 		uniform samplerCube envMap;
579: 	#else
580: 		uniform sampler2D envMap;
581: 	#endif
582: 	
583: #endif
584: #if defined( USE_ENVMAP )
585: 	#ifdef ENVMAP_MODE_REFRACTION
586: 		uniform float refractionRatio;
587: 	#endif
588: 	vec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {
589: 		vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );
590: 		#ifdef ENVMAP_TYPE_CUBE
591: 			vec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );
592: 			#ifdef TEXTURE_LOD_EXT
593: 				vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );
594: 			#else
595: 				vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );
596: 			#endif
597: 			envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
598: 		#elif defined( ENVMAP_TYPE_CUBE_UV )
599: 			vec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );
600: 		#else
601: 			vec4 envMapColor = vec4( 0.0 );
602: 		#endif
603: 		return PI * envMapColor.rgb * envMapIntensity;
604: 	}
605: 	float getSpecularMIPLevel( const in float roughness, const in int maxMIPLevel ) {
606: 		float maxMIPLevelScalar = float( maxMIPLevel );
607: 		float sigma = PI * roughness * roughness / ( 1.0 + roughness );
608: 		float desiredMIPLevel = maxMIPLevelScalar + log2( sigma );
609: 		return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );
610: 	}
611: 	vec3 getLightProbeIndirectRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in int maxMIPLevel ) {
612: 		#ifdef ENVMAP_MODE_REFLECTION
613: 		  vec3 reflectVec = reflect( -viewDir, normal );
614: 		  reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );
615: 		#else
616: 		  vec3 reflectVec = refract( -viewDir, normal, refractionRatio );
617: 		#endif
618: 		reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
619: 		float specularMIPLevel = getSpecularMIPLevel( roughness, maxMIPLevel );
620: 		#ifdef ENVMAP_TYPE_CUBE
621: 			vec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );
622: 			#ifdef TEXTURE_LOD_EXT
623: 				vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );
624: 			#else
625: 				vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );
626: 			#endif
627: 			envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
628: 		#elif defined( ENVMAP_TYPE_CUBE_UV )
629: 			vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );
630: 		#elif defined( ENVMAP_TYPE_EQUIREC )
631: 			vec2 sampleUV;
632: 			sampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
633: 			sampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;
634: 			#ifdef TEXTURE_LOD_EXT
635: 				vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );
636: 			#else
637: 				vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );
638: 			#endif
639: 			envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
640: 		#elif defined( ENVMAP_TYPE_SPHERE )
641: 			vec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );
642: 			#ifdef TEXTURE_LOD_EXT
643: 				vec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );
644: 			#else
645: 				vec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );
646: 			#endif
647: 			envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;
648: 		#endif
649: 		return envMapColor.rgb * envMapIntensity;
650: 	}
651: #endif
652: #ifdef USE_FOG
653: 	uniform vec3 fogColor;
654: 	varying float fogDepth;
655: 	#ifdef FOG_EXP2
656: 		uniform float fogDensity;
657: 	#else
658: 		uniform float fogNear;
659: 		uniform float fogFar;
660: 	#endif
661: #endif
662: uniform bool receiveShadow;
663: uniform vec3 ambientLightColor;
664: uniform vec3 lightProbe[ 9 ];
665: vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {
666: 	float x = normal.x, y = normal.y, z = normal.z;
667: 	vec3 result = shCoefficients[ 0 ] * 0.886227;
668: 	result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;
669: 	result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;
670: 	result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;
671: 	result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;
672: 	result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;
673: 	result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );
674: 	result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;
675: 	result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );
676: 	return result;
677: }
678: vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in GeometricContext geometry ) {
679: 	vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );
680: 	vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );
681: 	return irradiance;
682: }
683: vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
684: 	vec3 irradiance = ambientLightColor;
685: 	#ifndef PHYSICALLY_CORRECT_LIGHTS
686: 		irradiance *= PI;
687: 	#endif
688: 	return irradiance;
689: }
690: #if 0 > 0
691: 	struct DirectionalLight {
692: 		vec3 direction;
693: 		vec3 color;
694: 	};
695: 	uniform DirectionalLight directionalLights[ 0 ];
696: 	#if defined( USE_SHADOWMAP ) && 0 > 0
697: 		struct DirectionalLightShadow {
698: 			float shadowBias;
699: 			float shadowRadius;
700: 			vec2 shadowMapSize;
701: 		};
702: 		uniform DirectionalLightShadow directionalLightShadows[ 0 ];
703: 	#endif
704: 	void getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {
705: 		directLight.color = directionalLight.color;
706: 		directLight.direction = directionalLight.direction;
707: 		directLight.visible = true;
708: 	}
709: #endif
710: #if 0 > 0
711: 	struct PointLight {
712: 		vec3 position;
713: 		vec3 color;
714: 		float distance;
715: 		float decay;
716: 	};
717: 	uniform PointLight pointLights[ 0 ];
718: 	#if defined( USE_SHADOWMAP ) && 0 > 0
719: 		struct PointLightShadow {
720: 			float shadowBias;
721: 			float shadowRadius;
722: 			vec2 shadowMapSize;
723: 			float shadowCameraNear;
724: 			float shadowCameraFar;
725: 		};
726: 		uniform PointLightShadow pointLightShadows[ 0 ];
727: 	#endif
728: 	void getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {
729: 		vec3 lVector = pointLight.position - geometry.position;
730: 		directLight.direction = normalize( lVector );
731: 		float lightDistance = length( lVector );
732: 		directLight.color = pointLight.color;
733: 		directLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );
734: 		directLight.visible = ( directLight.color != vec3( 0.0 ) );
735: 	}
736: #endif
737: #if 0 > 0
738: 	struct SpotLight {
739: 		vec3 position;
740: 		vec3 direction;
741: 		vec3 color;
742: 		float distance;
743: 		float decay;
744: 		float coneCos;
745: 		float penumbraCos;
746: 	};
747: 	uniform SpotLight spotLights[ 0 ];
748: 	#if defined( USE_SHADOWMAP ) && 0 > 0
749: 		struct SpotLightShadow {
750: 			float shadowBias;
751: 			float shadowRadius;
752: 			vec2 shadowMapSize;
753: 		};
754: 		uniform SpotLightShadow spotLightShadows[ 0 ];
755: 	#endif
756: 	void getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight  ) {
757: 		vec3 lVector = spotLight.position - geometry.position;
758: 		directLight.direction = normalize( lVector );
759: 		float lightDistance = length( lVector );
760: 		float angleCos = dot( directLight.direction, spotLight.direction );
761: 		if ( angleCos > spotLight.coneCos ) {
762: 			float spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );
763: 			directLight.color = spotLight.color;
764: 			directLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );
765: 			directLight.visible = true;
766: 		} else {
767: 			directLight.color = vec3( 0.0 );
768: 			directLight.visible = false;
769: 		}
770: 	}
771: #endif
772: #if 0 > 0
773: 	struct RectAreaLight {
774: 		vec3 color;
775: 		vec3 position;
776: 		vec3 halfWidth;
777: 		vec3 halfHeight;
778: 	};
779: 	uniform sampler2D ltc_1;	uniform sampler2D ltc_2;
780: 	uniform RectAreaLight rectAreaLights[ 0 ];
781: #endif
782: #if 0 > 0
783: 	struct HemisphereLight {
784: 		vec3 direction;
785: 		vec3 skyColor;
786: 		vec3 groundColor;
787: 	};
788: 	uniform HemisphereLight hemisphereLights[ 0 ];
789: 	vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {
790: 		float dotNL = dot( geometry.normal, hemiLight.direction );
791: 		float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
792: 		vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
793: 		#ifndef PHYSICALLY_CORRECT_LIGHTS
794: 			irradiance *= PI;
795: 		#endif
796: 		return irradiance;
797: 	}
798: #endif
799: struct PhysicalMaterial {
800: 	vec3	diffuseColor;
801: 	float	specularRoughness;
802: 	vec3	specularColor;
803: #ifdef CLEARCOAT
804: 	float clearcoat;
805: 	float clearcoatRoughness;
806: #endif
807: #ifdef USE_SHEEN
808: 	vec3 sheenColor;
809: #endif
810: };
811: #define MAXIMUM_SPECULAR_COEFFICIENT 0.16
812: #define DEFAULT_SPECULAR_COEFFICIENT 0.04
813: float clearcoatDHRApprox( const in float roughness, const in float dotNL ) {
814: 	return DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );
815: }
816: #if 0 > 0
817: 	void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
818: 		vec3 normal = geometry.normal;
819: 		vec3 viewDir = geometry.viewDir;
820: 		vec3 position = geometry.position;
821: 		vec3 lightPos = rectAreaLight.position;
822: 		vec3 halfWidth = rectAreaLight.halfWidth;
823: 		vec3 halfHeight = rectAreaLight.halfHeight;
824: 		vec3 lightColor = rectAreaLight.color;
825: 		float roughness = material.specularRoughness;
826: 		vec3 rectCoords[ 4 ];
827: 		rectCoords[ 0 ] = lightPos + halfWidth - halfHeight;		rectCoords[ 1 ] = lightPos - halfWidth - halfHeight;
828: 		rectCoords[ 2 ] = lightPos - halfWidth + halfHeight;
829: 		rectCoords[ 3 ] = lightPos + halfWidth + halfHeight;
830: 		vec2 uv = LTC_Uv( normal, viewDir, roughness );
831: 		vec4 t1 = texture2D( ltc_1, uv );
832: 		vec4 t2 = texture2D( ltc_2, uv );
833: 		mat3 mInv = mat3(
834: 			vec3( t1.x, 0, t1.y ),
835: 			vec3(    0, 1,    0 ),
836: 			vec3( t1.z, 0, t1.w )
837: 		);
838: 		vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );
839: 		reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );
840: 		reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );
841: 	}
842: #endif
843: void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
844: 	float dotNL = saturate( dot( geometry.normal, directLight.direction ) );
845: 	vec3 irradiance = dotNL * directLight.color;
846: 	#ifndef PHYSICALLY_CORRECT_LIGHTS
847: 		irradiance *= PI;
848: 	#endif
849: 	#ifdef CLEARCOAT
850: 		float ccDotNL = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );
851: 		vec3 ccIrradiance = ccDotNL * directLight.color;
852: 		#ifndef PHYSICALLY_CORRECT_LIGHTS
853: 			ccIrradiance *= PI;
854: 		#endif
855: 		float clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );
856: 		reflectedLight.directSpecular += ccIrradiance * material.clearcoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );
857: 	#else
858: 		float clearcoatDHR = 0.0;
859: 	#endif
860: 	#ifdef USE_SHEEN
861: 		reflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_Sheen(
862: 			material.specularRoughness,
863: 			directLight.direction,
864: 			geometry,
865: 			material.sheenColor
866: 		);
867: 	#else
868: 		reflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, material.specularColor, material.specularRoughness);
869: 	#endif
870: 	reflectedLight.directDiffuse += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
871: }
872: void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
873: 	reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );
874: }
875: void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {
876: 	#ifdef CLEARCOAT
877: 		float ccDotNV = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );
878: 		reflectedLight.indirectSpecular += clearcoatRadiance * material.clearcoat * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );
879: 		float ccDotNL = ccDotNV;
880: 		float clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );
881: 	#else
882: 		float clearcoatDHR = 0.0;
883: 	#endif
884: 	float clearcoatInv = 1.0 - clearcoatDHR;
885: 	vec3 singleScattering = vec3( 0.0 );
886: 	vec3 multiScattering = vec3( 0.0 );
887: 	vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;
888: 	BRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );
889: 	vec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );
890: 	reflectedLight.indirectSpecular += clearcoatInv * radiance * singleScattering;
891: 	reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;
892: 	reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;
893: }
894: #define RE_Direct				RE_Direct_Physical
895: #define RE_Direct_RectArea		RE_Direct_RectArea_Physical
896: #define RE_IndirectDiffuse		RE_IndirectDiffuse_Physical
897: #define RE_IndirectSpecular		RE_IndirectSpecular_Physical
898: float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {
899: 	return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );
900: }
901: #ifdef USE_SHADOWMAP
902: 	#if 0 > 0
903: 		uniform sampler2D directionalShadowMap[ 0 ];
904: 		varying vec4 vDirectionalShadowCoord[ 0 ];
905: 	#endif
906: 	#if 0 > 0
907: 		uniform sampler2D spotShadowMap[ 0 ];
908: 		varying vec4 vSpotShadowCoord[ 0 ];
909: 	#endif
910: 	#if 0 > 0
911: 		uniform sampler2D pointShadowMap[ 0 ];
912: 		varying vec4 vPointShadowCoord[ 0 ];
913: 	#endif
914: 	float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {
915: 		return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );
916: 	}
917: 	vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {
918: 		return unpackRGBATo2Half( texture2D( shadow, uv ) );
919: 	}
920: 	float VSMShadow (sampler2D shadow, vec2 uv, float compare ){
921: 		float occlusion = 1.0;
922: 		vec2 distribution = texture2DDistribution( shadow, uv );
923: 		float hard_shadow = step( compare , distribution.x );
924: 		if (hard_shadow != 1.0 ) {
925: 			float distance = compare - distribution.x ;
926: 			float variance = max( 0.00000, distribution.y * distribution.y );
927: 			float softness_probability = variance / (variance + distance * distance );			softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );			occlusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );
928: 		}
929: 		return occlusion;
930: 	}
931: 	float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
932: 		float shadow = 1.0;
933: 		shadowCoord.xyz /= shadowCoord.w;
934: 		shadowCoord.z += shadowBias;
935: 		bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );
936: 		bool inFrustum = all( inFrustumVec );
937: 		bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );
938: 		bool frustumTest = all( frustumTestVec );
939: 		if ( frustumTest ) {
940: 		#if defined( SHADOWMAP_TYPE_PCF )
941: 			vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
942: 			float dx0 = - texelSize.x * shadowRadius;
943: 			float dy0 = - texelSize.y * shadowRadius;
944: 			float dx1 = + texelSize.x * shadowRadius;
945: 			float dy1 = + texelSize.y * shadowRadius;
946: 			float dx2 = dx0 / 2.0;
947: 			float dy2 = dy0 / 2.0;
948: 			float dx3 = dx1 / 2.0;
949: 			float dy3 = dy1 / 2.0;
950: 			shadow = (
951: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +
952: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +
953: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +
954: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +
955: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +
956: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +
957: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +
958: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +
959: 				texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +
960: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +
961: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +
962: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +
963: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +
964: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +
965: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +
966: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +
967: 				texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )
968: 			) * ( 1.0 / 17.0 );
969: 		#elif defined( SHADOWMAP_TYPE_PCF_SOFT )
970: 			vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
971: 			float dx = texelSize.x;
972: 			float dy = texelSize.y;
973: 			vec2 uv = shadowCoord.xy;
974: 			vec2 f = fract( uv * shadowMapSize + 0.5 );
975: 			uv -= f * texelSize;
976: 			shadow = (
977: 				texture2DCompare( shadowMap, uv, shadowCoord.z ) +
978: 				texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +
979: 				texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +
980: 				texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +
981: 				mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), 
982: 					 texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),
983: 					 f.x ) +
984: 				mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), 
985: 					 texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),
986: 					 f.x ) +
987: 				mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), 
988: 					 texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),
989: 					 f.y ) +
990: 				mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), 
991: 					 texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),
992: 					 f.y ) +
993: 				mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), 
994: 						  texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),
995: 						  f.x ),
996: 					 mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), 
997: 						  texture2DCompare( shadowMap, uv + + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),
998: 						  f.x ),
999: 					 f.y )
1000: 			) * ( 1.0 / 9.0 );
1001: 		#elif defined( SHADOWMAP_TYPE_VSM )
1002: 			shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );
1003: 		#else
1004: 			shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );
1005: 		#endif
1006: 		}
1007: 		return shadow;
1008: 	}
1009: 	vec2 cubeToUV( vec3 v, float texelSizeY ) {
1010: 		vec3 absV = abs( v );
1011: 		float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );
1012: 		absV *= scaleToCube;
1013: 		v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );
1014: 		vec2 planar = v.xy;
1015: 		float almostATexel = 1.5 * texelSizeY;
1016: 		float almostOne = 1.0 - almostATexel;
1017: 		if ( absV.z >= almostOne ) {
1018: 			if ( v.z > 0.0 )
1019: 				planar.x = 4.0 - v.x;
1020: 		} else if ( absV.x >= almostOne ) {
1021: 			float signX = sign( v.x );
1022: 			planar.x = v.z * signX + 2.0 * signX;
1023: 		} else if ( absV.y >= almostOne ) {
1024: 			float signY = sign( v.y );
1025: 			planar.x = v.x + 2.0 * signY + 2.0;
1026: 			planar.y = v.z * signY - 2.0;
1027: 		}
1028: 		return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );
1029: 	}
1030: 	float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
1031: 		vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );
1032: 		vec3 lightToPosition = shadowCoord.xyz;
1033: 		float dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );		dp += shadowBias;
1034: 		vec3 bd3D = normalize( lightToPosition );
1035: 		#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )
1036: 			vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;
1037: 			return (
1038: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +
1039: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +
1040: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +
1041: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +
1042: 				texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +
1043: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +
1044: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +
1045: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +
1046: 				texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )
1047: 			) * ( 1.0 / 9.0 );
1048: 		#else
1049: 			return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );
1050: 		#endif
1051: 	}
1052: #endif
1053: #ifdef USE_BUMPMAP
1054: 	uniform sampler2D bumpMap;
1055: 	uniform float bumpScale;
1056: 	vec2 dHdxy_fwd() {
1057: 		vec2 dSTdx = dFdx( vUv );
1058: 		vec2 dSTdy = dFdy( vUv );
1059: 		float Hll = bumpScale * texture2D( bumpMap, vUv ).x;
1060: 		float dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;
1061: 		float dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;
1062: 		return vec2( dBx, dBy );
1063: 	}
1064: 	vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {
1065: 		vec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );
1066: 		vec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );
1067: 		vec3 vN = surf_norm;
1068: 		vec3 R1 = cross( vSigmaY, vN );
1069: 		vec3 R2 = cross( vN, vSigmaX );
1070: 		float fDet = dot( vSigmaX, R1 );
1071: 		fDet *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
1072: 		vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
1073: 		return normalize( abs( fDet ) * surf_norm - vGrad );
1074: 	}
1075: #endif
1076: #ifdef USE_NORMALMAP
1077: 	uniform sampler2D normalMap;
1078: 	uniform vec2 normalScale;
1079: #endif
1080: #ifdef OBJECTSPACE_NORMALMAP
1081: 	uniform mat3 normalMatrix;
1082: #endif
1083: #if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )
1084: 	vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN ) {
1085: 		vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );
1086: 		vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );
1087: 		vec2 st0 = dFdx( vUv.st );
1088: 		vec2 st1 = dFdy( vUv.st );
1089: 		float scale = sign( st1.t * st0.s - st0.t * st1.s );
1090: 		vec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );
1091: 		vec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );
1092: 		vec3 N = normalize( surf_norm );
1093: 		mat3 tsn = mat3( S, T, N );
1094: 		mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
1095: 		return normalize( tsn * mapN );
1096: 	}
1097: #endif
1098: #ifdef USE_CLEARCOAT_NORMALMAP
1099: 	uniform sampler2D clearcoatNormalMap;
1100: 	uniform vec2 clearcoatNormalScale;
1101: #endif
1102: #ifdef USE_ROUGHNESSMAP
1103: 	uniform sampler2D roughnessMap;
1104: #endif
1105: #ifdef USE_METALNESSMAP
1106: 	uniform sampler2D metalnessMap;
1107: #endif
1108: #if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )
1109: 	uniform float logDepthBufFC;
1110: 	varying float vFragDepth;
1111: 	varying float vIsPerspective;
1112: #endif
1113: #if 0 > 0
1114: 	#if ! defined( STANDARD ) && ! defined( PHONG ) && ! defined( MATCAP ) && ! defined( TOON )
1115: 		varying vec3 vViewPosition;
1116: 	#endif
1117: 	uniform vec4 clippingPlanes[ 0 ];
1118: #endif
1119: void main() {
1120: #if 0 > 0
1121: 	vec4 plane;
1122: 	
1123: 	#if 0 < 0
1124: 		bool clipped = true;
1125: 		
1126: 		if ( clipped ) discard;
1127: 	#endif
1128: #endif
1129: 	vec4 diffuseColor = vec4( diffuse, opacity );
1130: 	ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
1131: 	vec3 totalEmissiveRadiance = emissive;
1132: #if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )
1133: 	gl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;
1134: #endif
1135: #ifdef USE_MAP
1136: 	vec4 texelColor = texture2D( map, vUv );
1137: 	texelColor = mapTexelToLinear( texelColor );
1138: 	diffuseColor *= texelColor;
1139: #endif
1140: #ifdef USE_COLOR
1141: 	diffuseColor.rgb *= vColor;
1142: #endif
1143: #ifdef USE_ALPHAMAP
1144: 	diffuseColor.a *= texture2D( alphaMap, vUv ).g;
1145: #endif
1146: #ifdef ALPHATEST
1147: 	if ( diffuseColor.a < ALPHATEST ) discard;
1148: #endif
1149: float roughnessFactor = roughness;
1150: #ifdef USE_ROUGHNESSMAP
1151: 	vec4 texelRoughness = texture2D( roughnessMap, vUv );
1152: 	roughnessFactor *= texelRoughness.g;
1153: #endif
1154: float metalnessFactor = metalness;
1155: #ifdef USE_METALNESSMAP
1156: 	vec4 texelMetalness = texture2D( metalnessMap, vUv );
1157: 	metalnessFactor *= texelMetalness.b;
1158: #endif
1159: #ifdef FLAT_SHADED
1160: 	vec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );
1161: 	vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );
1162: 	vec3 normal = normalize( cross( fdx, fdy ) );
1163: #else
1164: 	vec3 normal = normalize( vNormal );
1165: 	#ifdef DOUBLE_SIDED
1166: 		normal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
1167: 	#endif
1168: 	#ifdef USE_TANGENT
1169: 		vec3 tangent = normalize( vTangent );
1170: 		vec3 bitangent = normalize( vBitangent );
1171: 		#ifdef DOUBLE_SIDED
1172: 			tangent = tangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
1173: 			bitangent = bitangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
1174: 		#endif
1175: 		#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )
1176: 			mat3 vTBN = mat3( tangent, bitangent, normal );
1177: 		#endif
1178: 	#endif
1179: #endif
1180: vec3 geometryNormal = normal;
1181: #ifdef OBJECTSPACE_NORMALMAP
1182: 	normal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
1183: 	#ifdef FLIP_SIDED
1184: 		normal = - normal;
1185: 	#endif
1186: 	#ifdef DOUBLE_SIDED
1187: 		normal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
1188: 	#endif
1189: 	normal = normalize( normalMatrix * normal );
1190: #elif defined( TANGENTSPACE_NORMALMAP )
1191: 	vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;
1192: 	mapN.xy *= normalScale;
1193: 	#ifdef USE_TANGENT
1194: 		normal = normalize( vTBN * mapN );
1195: 	#else
1196: 		normal = perturbNormal2Arb( -vViewPosition, normal, mapN );
1197: 	#endif
1198: #elif defined( USE_BUMPMAP )
1199: 	normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );
1200: #endif
1201: #ifdef CLEARCOAT
1202: 	vec3 clearcoatNormal = geometryNormal;
1203: #endif
1204: #ifdef USE_CLEARCOAT_NORMALMAP
1205: 	vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;
1206: 	clearcoatMapN.xy *= clearcoatNormalScale;
1207: 	#ifdef USE_TANGENT
1208: 		clearcoatNormal = normalize( vTBN * clearcoatMapN );
1209: 	#else
1210: 		clearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN );
1211: 	#endif
1212: #endif
1213: #ifdef USE_EMISSIVEMAP
1214: 	vec4 emissiveColor = texture2D( emissiveMap, vUv );
1215: 	emissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;
1216: 	totalEmissiveRadiance *= emissiveColor.rgb;
1217: #endif
1218: PhysicalMaterial material;
1219: material.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );
1220: vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );
1221: float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
1222: material.specularRoughness = max( roughnessFactor, 0.0525 );material.specularRoughness += geometryRoughness;
1223: material.specularRoughness = min( material.specularRoughness, 1.0 );
1224: #ifdef REFLECTIVITY
1225: 	material.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );
1226: #else
1227: 	material.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );
1228: #endif
1229: #ifdef CLEARCOAT
1230: 	material.clearcoat = saturate( clearcoat );	material.clearcoatRoughness = max( clearcoatRoughness, 0.0525 );
1231: 	material.clearcoatRoughness += geometryRoughness;
1232: 	material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );
1233: #endif
1234: #ifdef USE_SHEEN
1235: 	material.sheenColor = sheen;
1236: #endif
1237: 
1238: GeometricContext geometry;
1239: geometry.position = - vViewPosition;
1240: geometry.normal = normal;
1241: geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
1242: #ifdef CLEARCOAT
1243: 	geometry.clearcoatNormal = clearcoatNormal;
1244: #endif
1245: IncidentLight directLight;
1246: #if ( 0 > 0 ) && defined( RE_Direct )
1247: 	PointLight pointLight;
1248: 	#if defined( USE_SHADOWMAP ) && 0 > 0
1249: 	PointLightShadow pointLightShadow;
1250: 	#endif
1251: 	
1252: #endif
1253: #if ( 0 > 0 ) && defined( RE_Direct )
1254: 	SpotLight spotLight;
1255: 	#if defined( USE_SHADOWMAP ) && 0 > 0
1256: 	SpotLightShadow spotLightShadow;
1257: 	#endif
1258: 	
1259: #endif
1260: #if ( 0 > 0 ) && defined( RE_Direct )
1261: 	DirectionalLight directionalLight;
1262: 	#if defined( USE_SHADOWMAP ) && 0 > 0
1263: 	DirectionalLightShadow directionalLightShadow;
1264: 	#endif
1265: 	
1266: #endif
1267: #if ( 0 > 0 ) && defined( RE_Direct_RectArea )
1268: 	RectAreaLight rectAreaLight;
1269: 	
1270: #endif
1271: #if defined( RE_IndirectDiffuse )
1272: 	vec3 iblIrradiance = vec3( 0.0 );
1273: 	vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
1274: 	irradiance += getLightProbeIrradiance( lightProbe, geometry );
1275: 	#if ( 0 > 0 )
1276: 		
1277: 	#endif
1278: #endif
1279: #if defined( RE_IndirectSpecular )
1280: 	vec3 radiance = vec3( 0.0 );
1281: 	vec3 clearcoatRadiance = vec3( 0.0 );
1282: #endif
1283: #if defined( RE_IndirectDiffuse )
1284: 	#ifdef USE_LIGHTMAP
1285: 		vec4 lightMapTexel= texture2D( lightMap, vUv2 );
1286: 		vec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;
1287: 		#ifndef PHYSICALLY_CORRECT_LIGHTS
1288: 			lightMapIrradiance *= PI;
1289: 		#endif
1290: 		irradiance += lightMapIrradiance;
1291: 	#endif
1292: 	#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )
1293: 		iblIrradiance += getLightProbeIndirectIrradiance( geometry, maxMipLevel );
1294: 	#endif
1295: #endif
1296: #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
1297: 	radiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.normal, material.specularRoughness, maxMipLevel );
1298: 	#ifdef CLEARCOAT
1299: 		clearcoatRadiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness, maxMipLevel );
1300: 	#endif
1301: #endif
1302: #if defined( RE_IndirectDiffuse )
1303: 	RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );
1304: #endif
1305: #if defined( RE_IndirectSpecular )
1306: 	RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );
1307: #endif
1308: #ifdef USE_AOMAP
1309: 	float ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;
1310: 	reflectedLight.indirectDiffuse *= ambientOcclusion;
1311: 	#if defined( USE_ENVMAP ) && defined( STANDARD )
1312: 		float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
1313: 		reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );
1314: 	#endif
1315: #endif
1316: 	vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;
1317: 	#ifdef TRANSPARENCY
1318: 		diffuseColor.a *= saturate( 1. - transparency + linearToRelativeLuminance( reflectedLight.directSpecular + reflectedLight.indirectSpecular ) );
1319: 	#endif
1320: 	gl_FragColor = vec4( outgoingLight, diffuseColor.a );
1321: #if defined( TONE_MAPPING )
1322: 	gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
1323: #endif
1324: gl_FragColor = linearToOutputTexel( gl_FragColor );
1325: #ifdef USE_FOG
1326: 	#ifdef FOG_EXP2
1327: 		float fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth );
1328: 	#else
1329: 		float fogFactor = smoothstep( fogNear, fogFar, fogDepth );
1330: 	#endif
1331: 	gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );
1332: #endif
1333: #ifdef PREMULTIPLIED_ALPHA
1334: 	gl_FragColor.rgb *= gl_FragColor.a;
1335: #endif
1336: #ifdef DITHERING
1337: 	gl_FragColor.rgb = dithering( gl_FragColor.rgb );
1338: #endif
1339: }

Thanks in advance

On what error are you referring? It seems you have just shared the code of a fragment shader.

The above shows in the console as an error:

I can’t reproduce the error with this URL: https://ui-unicorn.co.uk/game-lesson-1/new-index-2021

Can you please check if it works on different devices?

Unfortunately, the error message lacks of detail for some reasons so it’s not clear what causes the issue.

Can you share the code that you are using to pass {vertexShader} to the ShaderMaterial?