Using three.js results in shaders unable to compile (sometimes). It got this bug while using the starter code from https://github.com/expo/expo-three
However, I know that it is not a React Native, or Expo or Expo-Three bug because I was able to get the code to work perfectly on an iPad (Apple A9 GPU -- GLES 3.0). However it did not work on a Xiaomi RedMi 4A (Adreno 308 -- GLES 3.0 -- Android 6) nor did it work on an older Android phone running Android Jellybean.
The error log printed out two long .vert and .frag source codes and I tried to find out which files it was from and I saw that the source files were assembled from chunks, so I didn't know how to find out where it was assembled.
Fragment shader compilation failed.
ERROR: 0:158: 'const' : overloaded functions must have the same parameter qualifiers
ERROR: 1 compilation errors. No code generated.`
Description of the problem
Using
three.js
results in shaders unable to compile (sometimes). It got this bug while using the starter code from https://github.com/expo/expo-threeHowever, I know that it is not a React Native, or Expo or Expo-Three bug because I was able to get the code to work perfectly on an iPad (Apple A9 GPU -- GLES 3.0). However it did not work on a Xiaomi RedMi 4A (Adreno 308 -- GLES 3.0 -- Android 6) nor did it work on an older Android phone running Android Jellybean.
The error log printed out two long .vert and .frag source codes and I tried to find out which files it was from and I saw that the source files were assembled from chunks, so I didn't know how to find out where it was assembled.
You can edit for small-test.
http://jsfiddle.net/akmcv7Lh/ (current revision)
http://jsfiddle.net/hw9rcLL8/ (dev)
Three.js version
Browser
OS
Hardware Requirements (graphics card, VR Device, ...)
This bug was seen on a Xiaomi RedMi 4A using an Adreno 308 GPU (GLES 3.0).
`THREE.WebGLShader: Shader couldn't compile. 4:12:10 PM THREE.WebGLShader: gl.getShaderInfoLog() vertex Vertex shader compilation failed. ERROR: 0:97: 'const' : overloaded functions must have the same parameter qualifiers ERROR: 1 compilation errors. No code generated.
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 0 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 PI_HALF 1.5707963267949 50: #define RECIPROCAL_PI 0.31830988618 51: #define RECIPROCAL_PI2 0.15915494 52: #define LOG2 1.442695 53: #define EPSILON 1e-6 54: #define saturate(a) clamp( a, 0.0, 1.0 ) 55: #define whiteCompliment(a) ( 1.0 - saturate( a ) ) 56: float pow2( const in float x ) { return xx; } 57: float pow3( const in float x ) { return xxx; } 58: float pow4( const in float x ) { float x2 = xx; return x2x2; } 59: float average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); } 60: highp float rand( const in vec2 uv ) { 61: const highp float a = 12.9898, b = 78.233, c = 43758.5453; 62: highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI ); 63: return fract(sin(sn) c); 64: } 65: struct IncidentLight { 66: vec3 color; 67: vec3 direction; 68: bool visible; 69: }; 70: struct ReflectedLight { 71: vec3 directDiffuse; 72: vec3 directSpecular; 73: vec3 indirectDiffuse; 74: vec3 indirectSpecular; 75: }; 76: struct GeometricContext { 77: vec3 position; 78: vec3 normal; 79: vec3 viewDir; 80: }; 81: vec3 transformDirection( in vec3 dir, in mat4 matrix ) { 82: return normalize( ( matrix vec4( dir, 0.0 ) ).xyz ); 83: } 84: vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) { 85: return normalize( ( vec4( dir, 0.0 ) matrix ).xyz ); 86: } 87: vec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) { 88: float distance = dot( planeNormal, point - pointOnPlane ); 89: return - distance planeNormal + point; 90: } 91: float sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) { 92: return sign( dot( point - pointOnPlane, planeNormal ) ); 93: } 94: vec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) { 95: return lineDirection ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine; 96: } 97: mat3 transpose( const in mat3 v ) { 98: mat3 tmp; 99: tmp[0] = vec3(v[0].x, v[1].x, v[2].x); 100: tmp[1] = vec3(v[0].y, v[1].y, v[2].y); 101: tmp[2] = vec3(v[0].z, v[1].z, v[2].z); 102: return tmp; 103: } 104: 105: #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 ) 106: varying vec2 vUv; 107: uniform vec4 offsetRepeat; 108: #endif 109: 110: #if defined( USE_LIGHTMAP ) || defined( USE_AOMAP ) 111: attribute vec2 uv2; 112: varying vec2 vUv2; 113: #endif 114: #ifdef USE_ENVMAP 115: #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) 116: varying vec3 vWorldPosition; 117: #else 118: varying vec3 vReflect; 119: uniform float refractionRatio; 120: #endif 121: #endif 122: 123: float punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) { 124: if( decayExponent > 0.0 ) { 125: #if defined ( PHYSICALLY_CORRECT_LIGHTS ) 126: float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 ); 127: float maxDistanceCutoffFactor = pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) ); 128: return distanceFalloff maxDistanceCutoffFactor; 129: #else 130: return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent ); 131: #endif 132: } 133: return 1.0; 134: } 135: vec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) { 136: return RECIPROCAL_PI diffuseColor; 137: } 138: vec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) { 139: float fresnel = exp2( ( -5.55473 dotLH - 6.98316 ) dotLH ); 140: return ( 1.0 - specularColor ) fresnel + specularColor; 141: } 142: float G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) { 143: float a2 = pow2( alpha ); 144: float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) pow2( dotNL ) ); 145: float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) pow2( dotNV ) ); 146: return 1.0 / ( gl gv ); 147: } 148: float G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) { 149: float a2 = pow2( alpha ); 150: float gv = dotNL sqrt( a2 + ( 1.0 - a2 ) pow2( dotNV ) ); 151: float gl = dotNV sqrt( a2 + ( 1.0 - a2 ) pow2( dotNL ) ); 152: return 0.5 / max( gv + gl, EPSILON ); 153: } 154: float D_GGX( const in float alpha, const in float dotNH ) { 155: float a2 = pow2( alpha ); 156: float denom = pow2( dotNH ) ( a2 - 1.0 ) + 1.0; 157: return RECIPROCAL_PI a2 / pow2( denom ); 158: } 159: vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) { 160: float alpha = pow2( roughness ); 161: vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir ); 162: float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) ); 163: float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) ); 164: float dotNH = saturate( dot( geometry.normal, halfDir ) ); 165: float dotLH = saturate( dot( incidentLight.direction, halfDir ) ); 166: vec3 F = F_Schlick( specularColor, dotLH ); 167: float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV ); 168: float D = D_GGX( alpha, dotNH ); 169: return F ( G D ); 170: } 171: vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) { 172: const float LUT_SIZE = 64.0; 173: const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE; 174: const float LUT_BIAS = 0.5 / LUT_SIZE; 175: float theta = acos( dot( N, V ) ); 176: vec2 uv = vec2( 177: sqrt( saturate( roughness ) ), 178: saturate( theta / ( 0.5 PI ) ) ); 179: uv = uv LUT_SCALE + LUT_BIAS; 180: return uv; 181: } 182: float LTC_ClippedSphereFormFactor( const in vec3 f ) { 183: float l = length( f ); 184: return max( ( l l + f.z ) / ( l + 1.0 ), 0.0 ); 185: } 186: vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) { 187: float x = dot( v1, v2 ); 188: float y = abs( x ); 189: float a = 0.86267 + (0.49788 + 0.01436 y ) y; 190: float b = 3.45068 + (4.18814 + y) y; 191: float v = a / b; 192: float theta_sintheta = (x > 0.0) ? v : 0.5 inversesqrt( 1.0 - x x ) - v; 193: return cross( v1, v2 ) theta_sintheta; 194: } 195: vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) { 196: vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ]; 197: vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ]; 198: vec3 lightNormal = cross( v1, v2 ); 199: if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 ); 200: vec3 T1, T2; 201: T1 = normalize( V - N dot( V, N ) ); 202: T2 = - cross( N, T1 ); 203: mat3 mat = mInv transpose( mat3( T1, T2, N ) ); 204: vec3 coords[ 4 ]; 205: coords[ 0 ] = mat ( rectCoords[ 0 ] - P ); 206: coords[ 1 ] = mat ( rectCoords[ 1 ] - P ); 207: coords[ 2 ] = mat ( rectCoords[ 2 ] - P ); 208: coords[ 3 ] = mat ( rectCoords[ 3 ] - P ); 209: coords[ 0 ] = normalize( coords[ 0 ] ); 210: coords[ 1 ] = normalize( coords[ 1 ] ); 211: coords[ 2 ] = normalize( coords[ 2 ] ); 212: coords[ 3 ] = normalize( coords[ 3 ] ); 213: vec3 vectorFormFactor = vec3( 0.0 ); 214: vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] ); 215: vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] ); 216: vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] ); 217: vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] ); 218: vec3 result = vec3( LTC_ClippedSphereFormFactor( vectorFormFactor ) ); 219: return result; 220: } 221: vec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) { 222: float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) ); 223: const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 ); 224: const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 ); 225: vec4 r = roughness c0 + c1; 226: float a004 = min( r.x r.x, exp2( - 9.28 dotNV ) ) r.x + r.y; 227: vec2 AB = vec2( -1.04, 1.04 ) a004 + r.zw; 228: return specularColor AB.x + AB.y; 229: } 230: float G_BlinnPhong_Implicit( ) { 231: return 0.25; 232: } 233: float D_BlinnPhong( const in float shininess, const in float dotNH ) { 234: return RECIPROCAL_PI ( shininess 0.5 + 1.0 ) pow( dotNH, shininess ); 235: } 236: vec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) { 237: vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir ); 238: float dotNH = saturate( dot( geometry.normal, halfDir ) ); 239: float dotLH = saturate( dot( incidentLight.direction, halfDir ) ); 240: vec3 F = F_Schlick( specularColor, dotLH ); 241: float G = G_BlinnPhong_Implicit( ); 242: float D = D_BlinnPhong( shininess, dotNH ); 243: return F ( G D ); 244: } 245: float GGXRoughnessToBlinnExponent( const in float ggxRoughness ) { 246: return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 ); 247: } 248: float BlinnExponentToGGXRoughness( const in float blinnExponent ) { 249: return sqrt( 2.0 / ( blinnExponent + 2.0 ) ); 250: } 251: 252: uniform vec3 ambientLightColor; 253: vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) { 254: vec3 irradiance = ambientLightColor; 255: #ifndef PHYSICALLY_CORRECT_LIGHTS 256: irradiance = PI; 257: #endif 258: return irradiance; 259: } 260: #if 0 > 0 261: struct DirectionalLight { 262: vec3 direction; 263: vec3 color; 264: int shadow; 265: float shadowBias; 266: float shadowRadius; 267: vec2 shadowMapSize; 268: }; 269: uniform DirectionalLight directionalLights[ 0 ]; 270: void getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) { 271: directLight.color = directionalLight.color; 272: directLight.direction = directionalLight.direction; 273: directLight.visible = true; 274: } 275: #endif 276: #if 1 > 0 277: struct PointLight { 278: vec3 position; 279: vec3 color; 280: float distance; 281: float decay; 282: int shadow; 283: float shadowBias; 284: float shadowRadius; 285: vec2 shadowMapSize; 286: }; 287: uniform PointLight pointLights[ 1 ]; 288: void getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) { 289: vec3 lVector = pointLight.position - geometry.position; 290: directLight.direction = normalize( lVector ); 291: float lightDistance = length( lVector ); 292: directLight.color = pointLight.color; 293: directLight.color = punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay ); 294: directLight.visible = ( directLight.color != vec3( 0.0 ) ); 295: } 296: #endif 297: #if 0 > 0 298: struct SpotLight { 299: vec3 position; 300: vec3 direction; 301: vec3 color; 302: float distance; 303: float decay; 304: float coneCos; 305: float penumbraCos; 306: int shadow; 307: float shadowBias; 308: float shadowRadius; 309: vec2 shadowMapSize; 310: }; 311: uniform SpotLight spotLights[ 0 ]; 312: void getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) { 313: vec3 lVector = spotLight.position - geometry.position; 314: directLight.direction = normalize( lVector ); 315: float lightDistance = length( lVector ); 316: float angleCos = dot( directLight.direction, spotLight.direction ); 317: if ( angleCos > spotLight.coneCos ) { 318: float spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos ); 319: directLight.color = spotLight.color; 320: directLight.color = spotEffect punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay ); 321: directLight.visible = true; 322: } else { 323: directLight.color = vec3( 0.0 ); 324: directLight.visible = false; 325: } 326: } 327: #endif 328: #if 0 > 0 329: struct RectAreaLight { 330: vec3 color; 331: vec3 position; 332: vec3 halfWidth; 333: vec3 halfHeight; 334: }; 335: uniform sampler2D ltcMat; uniform sampler2D ltcMag; 336: uniform RectAreaLight rectAreaLights[ 0 ]; 337: #endif 338: #if 0 > 0 339: struct HemisphereLight { 340: vec3 direction; 341: vec3 skyColor; 342: vec3 groundColor; 343: }; 344: uniform HemisphereLight hemisphereLights[ 0 ]; 345: vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) { 346: float dotNL = dot( geometry.normal, hemiLight.direction ); 347: float hemiDiffuseWeight = 0.5 dotNL + 0.5; 348: vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight ); 349: #ifndef PHYSICALLY_CORRECT_LIGHTS 350: irradiance = PI; 351: #endif 352: return irradiance; 353: } 354: #endif 355: #if defined( USE_ENVMAP ) && defined( PHYSICAL ) 356: vec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) { 357: vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix ); 358: #ifdef ENVMAP_TYPE_CUBE 359: vec3 queryVec = vec3( flipEnvMap worldNormal.x, worldNormal.yz ); 360: #ifdef TEXTURE_LOD_EXT 361: vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) ); 362: #else 363: vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) ); 364: #endif 365: envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb; 366: #elif defined( ENVMAP_TYPE_CUBE_UV ) 367: vec3 queryVec = vec3( flipEnvMap worldNormal.x, worldNormal.yz ); 368: vec4 envMapColor = textureCubeUV( queryVec, 1.0 ); 369: #else 370: vec4 envMapColor = vec4( 0.0 ); 371: #endif 372: return PI envMapColor.rgb envMapIntensity; 373: } 374: float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) { 375: float maxMIPLevelScalar = float( maxMIPLevel ); 376: float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 log2( pow2( blinnShininessExponent ) + 1.0 ); 377: return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar ); 378: } 379: vec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) { 380: #ifdef ENVMAP_MODE_REFLECTION 381: vec3 reflectVec = reflect( -geometry.viewDir, geometry.normal ); 382: #else 383: vec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio ); 384: #endif 385: reflectVec = inverseTransformDirection( reflectVec, viewMatrix ); 386: float specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel ); 387: #ifdef ENVMAP_TYPE_CUBE 388: vec3 queryReflectVec = vec3( flipEnvMap reflectVec.x, reflectVec.yz ); 389: #ifdef TEXTURE_LOD_EXT 390: vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel ); 391: #else 392: vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel ); 393: #endif 394: envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb; 395: #elif defined( ENVMAP_TYPE_CUBE_UV ) 396: vec3 queryReflectVec = vec3( flipEnvMap reflectVec.x, reflectVec.yz ); 397: vec4 envMapColor = textureCubeUV(queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent)); 398: #elif defined( ENVMAP_TYPE_EQUIREC ) 399: vec2 sampleUV; 400: sampleUV.y = saturate( reflectVec.y 0.5 + 0.5 ); 401: sampleUV.x = atan( reflectVec.z, reflectVec.x ) RECIPROCAL_PI2 + 0.5; 402: #ifdef TEXTURE_LOD_EXT 403: vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel ); 404: #else 405: vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel ); 406: #endif 407: envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb; 408: #elif defined( ENVMAP_TYPE_SPHERE ) 409: vec3 reflectView = normalize( ( viewMatrix vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) ); 410: #ifdef TEXTURE_LOD_EXT 411: vec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy 0.5 + 0.5, specularMIPLevel ); 412: #else 413: vec4 envMapColor = texture2D( envMap, reflectView.xy 0.5 + 0.5, specularMIPLevel ); 414: #endif 415: envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb; 416: #endif 417: return envMapColor.rgb envMapIntensity; 418: } 419: #endif 420: 421: #ifdef USE_COLOR 422: varying vec3 vColor; 423: #endif 424: #ifdef USE_FOG 425: varying float fogDepth; 426: #endif 427: 428: #ifdef USE_MORPHTARGETS 429: #ifndef USE_MORPHNORMALS 430: uniform float morphTargetInfluences[ 8 ]; 431: #else 432: uniform float morphTargetInfluences[ 4 ]; 433: #endif 434: #endif 435: #ifdef USE_SKINNING 436: uniform mat4 bindMatrix; 437: uniform mat4 bindMatrixInverse; 438: #ifdef BONE_TEXTURE 439: uniform sampler2D boneTexture; 440: uniform int boneTextureSize; 441: mat4 getBoneMatrix( const in float i ) { 442: float j = i 4.0; 443: float x = mod( j, float( boneTextureSize ) ); 444: float y = floor( j / float( boneTextureSize ) ); 445: float dx = 1.0 / float( boneTextureSize ); 446: float dy = 1.0 / float( boneTextureSize ); 447: y = dy ( y + 0.5 ); 448: vec4 v1 = texture2D( boneTexture, vec2( dx ( x + 0.5 ), y ) ); 449: vec4 v2 = texture2D( boneTexture, vec2( dx ( x + 1.5 ), y ) ); 450: vec4 v3 = texture2D( boneTexture, vec2( dx ( x + 2.5 ), y ) ); 451: vec4 v4 = texture2D( boneTexture, vec2( dx ( x + 3.5 ), y ) ); 452: mat4 bone = mat4( v1, v2, v3, v4 ); 453: return bone; 454: } 455: #else 456: uniform mat4 boneMatrices[ MAX_BONES ]; 457: mat4 getBoneMatrix( const in float i ) { 458: mat4 bone = boneMatrices[ int(i) ]; 459: return bone; 460: } 461: #endif 462: #endif 463: 464: #ifdef USE_SHADOWMAP 465: #if 0 > 0 466: uniform mat4 directionalShadowMatrix[ 0 ]; 467: varying vec4 vDirectionalShadowCoord[ 0 ]; 468: #endif 469: #if 0 > 0 470: uniform mat4 spotShadowMatrix[ 0 ]; 471: varying vec4 vSpotShadowCoord[ 0 ]; 472: #endif 473: #if 1 > 0 474: uniform mat4 pointShadowMatrix[ 1 ]; 475: varying vec4 vPointShadowCoord[ 1 ]; 476: #endif 477: #endif 478: 479: #ifdef USE_LOGDEPTHBUF 480: #ifdef USE_LOGDEPTHBUF_EXT 481: varying float vFragDepth; 482: #endif 483: uniform float logDepthBufFC; 484: #endif 485: #if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) 486: varying vec3 vViewPosition; 487: #endif 488: 489: void main() { 490: #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 ) 491: vUv = uv offsetRepeat.zw + offsetRepeat.xy; 492: #endif 493: #if defined( USE_LIGHTMAP ) || defined( USE_AOMAP ) 494: vUv2 = uv2; 495: #endif 496: #ifdef USE_COLOR 497: vColor.xyz = color.xyz; 498: #endif 499: 500: vec3 objectNormal = vec3( normal ); 501: 502: #ifdef USE_MORPHNORMALS 503: objectNormal += ( morphNormal0 - normal ) morphTargetInfluences[ 0 ]; 504: objectNormal += ( morphNormal1 - normal ) morphTargetInfluences[ 1 ]; 505: objectNormal += ( morphNormal2 - normal ) morphTargetInfluences[ 2 ]; 506: objectNormal += ( morphNormal3 - normal ) morphTargetInfluences[ 3 ]; 507: #endif 508: 509: #ifdef USE_SKINNING 510: mat4 boneMatX = getBoneMatrix( skinIndex.x ); 511: mat4 boneMatY = getBoneMatrix( skinIndex.y ); 512: mat4 boneMatZ = getBoneMatrix( skinIndex.z ); 513: mat4 boneMatW = getBoneMatrix( skinIndex.w ); 514: #endif 515: #ifdef USE_SKINNING 516: mat4 skinMatrix = mat4( 0.0 ); 517: skinMatrix += skinWeight.x boneMatX; 518: skinMatrix += skinWeight.y boneMatY; 519: skinMatrix += skinWeight.z boneMatZ; 520: skinMatrix += skinWeight.w boneMatW; 521: skinMatrix = bindMatrixInverse skinMatrix bindMatrix; 522: objectNormal = vec4( skinMatrix vec4( objectNormal, 0.0 ) ).xyz; 523: #endif 524: 525: vec3 transformedNormal = normalMatrix objectNormal; 526: #ifdef FLIP_SIDED 527: transformedNormal = - transformedNormal; 528: #endif 529: 530: 531: vec3 transformed = vec3( position ); 532: 533: #ifdef USE_MORPHTARGETS 534: transformed += ( morphTarget0 - position ) morphTargetInfluences[ 0 ]; 535: transformed += ( morphTarget1 - position ) morphTargetInfluences[ 1 ]; 536: transformed += ( morphTarget2 - position ) morphTargetInfluences[ 2 ]; 537: transformed += ( morphTarget3 - position ) morphTargetInfluences[ 3 ]; 538: #ifndef USE_MORPHNORMALS 539: transformed += ( morphTarget4 - position ) morphTargetInfluences[ 4 ]; 540: transformed += ( morphTarget5 - position ) morphTargetInfluences[ 5 ]; 541: transformed += ( morphTarget6 - position ) morphTargetInfluences[ 6 ]; 542: transformed += ( morphTarget7 - position ) morphTargetInfluences[ 7 ]; 543: #endif 544: #endif 545: 546: #ifdef USE_SKINNING 547: vec4 skinVertex = bindMatrix vec4( transformed, 1.0 ); 548: vec4 skinned = vec4( 0.0 ); 549: skinned += boneMatX skinVertex skinWeight.x; 550: skinned += boneMatY skinVertex skinWeight.y; 551: skinned += boneMatZ skinVertex skinWeight.z; 552: skinned += boneMatW skinVertex skinWeight.w; 553: transformed = ( bindMatrixInverse skinned ).xyz; 554: #endif 555: 556: vec4 mvPosition = modelViewMatrix vec4( transformed, 1.0 ); 557: gl_Position = projectionMatrix mvPosition; 558: 559: #ifdef USE_LOGDEPTHBUF 560: gl_Position.z = log2(max( EPSILON, gl_Position.w + 1.0 )) logDepthBufFC; 561: #ifdef USE_LOGDEPTHBUF_EXT 562: vFragDepth = 1.0 + gl_Position.w; 563: #else 564: gl_Position.z = (gl_Position.z - 1.0) gl_Position.w; 565: #endif 566: #endif 567: 568: #if NUM_CLIPPING_PLANES > 0 && ! defined( PHYSICAL ) && ! defined( PHONG ) 569: vViewPosition = - mvPosition.xyz; 570: #endif 571: 572: #if defined( USE_ENVMAP ) || defined( PHONG ) || defined( PHYSICAL ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP ) 573: vec4 worldPosition = modelMatrix vec4( transformed, 1.0 ); 574: #endif 575: 576: #ifdef USE_ENVMAP 577: #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) 578: vWorldPosition = worldPosition.xyz; 579: #else 580: vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition ); 581: vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix ); 582: #ifdef ENVMAP_MODE_REFLECTION 583: vReflect = reflect( cameraToVertex, worldNormal ); 584: #else 585: vReflect = refract( cameraToVertex, worldNormal, refractionRatio ); 586: #endif 587: #endif 588: #endif 589: 590: vec3 diffuse = vec3( 1.0 ); 591: GeometricContext geometry; 592: geometry.position = mvPosition.xyz; 593: geometry.normal = normalize( transformedNormal ); 594: geometry.viewDir = normalize( -mvPosition.xyz ); 595: GeometricContext backGeometry; 596: backGeometry.position = geometry.position; 597: backGeometry.normal = -geometry.normal; 598: backGeometry.viewDir = geometry.viewDir; 599: vLightFront = vec3( 0.0 ); 600: #ifdef DOUBLE_SIDED 601: vLightBack = vec3( 0.0 ); 602: #endif 603: IncidentLight directLight; 604: float dotNL; 605: vec3 directLightColor_Diffuse; 606: #if 1 > 0 607:
608: getPointDirectLightIrradiance( pointLights[ 0 ], geometry, directLight ); 609: dotNL = dot( geometry.normal, directLight.direction ); 610: directLightColor_Diffuse = PI directLight.color; 611: vLightFront += saturate( dotNL ) directLightColor_Diffuse; 612: #ifdef DOUBLE_SIDED 613: vLightBack += saturate( -dotNL ) directLightColor_Diffuse; 614: #endif 615:
616: #endif 617: #if 0 > 0 618:
619: #endif 620: #if 0 > 0 621:
622: #endif 623: #if 0 > 0 624:
625: #endif 626: 627: #ifdef USE_SHADOWMAP 628: #if 0 > 0 629:
630: #endif 631: #if 0 > 0 632:
633: #endif 634: #if 1 > 0 635:
636: vPointShadowCoord[ 0 ] = pointShadowMatrix[ 0 ] * worldPosition; 637:
638: #endif 639: #endif 640: 641: 642: #ifdef USE_FOG 643: fogDepth = -mvPosition.z; 644: #endif 645: } 646: 4:12:10 PM THREE.WebGLShader: Shader couldn't compile. 4:12:10 PM THREE.WebGLShader: gl.getShaderInfoLog() fragment Fragment shader compilation failed. ERROR: 0:158: 'const' : overloaded functions must have the same parameter qualifiers ERROR: 1 compilation errors. No code generated.
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.w255.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 PI_HALF 1.5707963267949 111: #define RECIPROCAL_PI 0.31830988618 112: #define RECIPROCAL_PI2 0.15915494 113: #define LOG2 1.442695 114: #define EPSILON 1e-6 115: #define saturate(a) clamp( a, 0.0, 1.0 ) 116: #define whiteCompliment(a) ( 1.0 - saturate( a ) ) 117: float pow2( const in float x ) { return xx; } 118: float pow3( const in float x ) { return xxx; } 119: float pow4( const in float x ) { float x2 = xx; return x2x2; } 120: float average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); } 121: highp float rand( const in vec2 uv ) { 122: const highp float a = 12.9898, b = 78.233, c = 43758.5453; 123: highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI ); 124: return fract(sin(sn) c); 125: } 126: struct IncidentLight { 127: vec3 color; 128: vec3 direction; 129: bool visible; 130: }; 131: struct ReflectedLight { 132: vec3 directDiffuse; 133: vec3 directSpecular; 134: vec3 indirectDiffuse; 135: vec3 indirectSpecular; 136: }; 137: struct GeometricContext { 138: vec3 position; 139: vec3 normal; 140: vec3 viewDir; 141: }; 142: vec3 transformDirection( in vec3 dir, in mat4 matrix ) { 143: return normalize( ( matrix vec4( dir, 0.0 ) ).xyz ); 144: } 145: vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) { 146: return normalize( ( vec4( dir, 0.0 ) matrix ).xyz ); 147: } 148: vec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) { 149: float distance = dot( planeNormal, point - pointOnPlane ); 150: return - distance planeNormal + point; 151: } 152: float sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) { 153: return sign( dot( point - pointOnPlane, planeNormal ) ); 154: } 155: vec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) { 156: return lineDirection ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine; 157: } 158: mat3 transpose( const in mat3 v ) { 159: mat3 tmp; 160: tmp[0] = vec3(v[0].x, v[1].x, v[2].x); 161: tmp[1] = vec3(v[0].y, v[1].y, v[2].y); 162: tmp[2] = vec3(v[0].z, v[1].z, v[2].z); 163: return tmp; 164: } 165: 166: vec3 packNormalToRGB( const in vec3 normal ) { 167: return normalize( normal ) 0.5 + 0.5; 168: } 169: vec3 unpackRGBToNormal( const in vec3 rgb ) { 170: return 1.0 - 2.0 rgb.xyz; 171: } 172: const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.; 173: const vec3 PackFactors = vec3( 256. 256. 256., 256. 256., 256. ); 174: const vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. ); 175: const float ShiftRight8 = 1. / 256.; 176: vec4 packDepthToRGBA( const in float v ) { 177: vec4 r = vec4( fract( v PackFactors ), v ); 178: r.yzw -= r.xyz ShiftRight8; return r PackUpscale; 179: } 180: float unpackRGBAToDepth( const in vec4 v ) { 181: return dot( v, UnpackFactors ); 182: } 183: float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) { 184: return ( viewZ + near ) / ( near - far ); 185: } 186: float orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) { 187: return linearClipZ ( near - far ) - near; 188: } 189: float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) { 190: return (( near + viewZ ) far ) / (( far - near ) viewZ ); 191: } 192: float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) { 193: return ( near far ) / ( ( far - near ) invClipZ - far ); 194: } 195: 196: #if defined( DITHERING ) 197: vec3 dithering( vec3 color ) { 198: float grid_position = rand( gl_FragCoord.xy ); 199: vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 ); 200: dither_shift_RGB = mix( 2.0 dither_shift_RGB, -2.0 dither_shift_RGB, grid_position ); 201: return color + dither_shift_RGB; 202: } 203: #endif 204: 205: #ifdef USE_COLOR 206: varying vec3 vColor; 207: #endif 208: 209: #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 ) 210: varying vec2 vUv; 211: #endif 212: #if defined( USE_LIGHTMAP ) || defined( USE_AOMAP ) 213: varying vec2 vUv2; 214: #endif 215: #ifdef USE_MAP 216: uniform sampler2D map; 217: #endif 218: 219: #ifdef USE_ALPHAMAP 220: uniform sampler2D alphaMap; 221: #endif 222: 223: #ifdef USE_AOMAP 224: uniform sampler2D aoMap; 225: uniform float aoMapIntensity; 226: #endif 227: #ifdef USE_LIGHTMAP 228: uniform sampler2D lightMap; 229: uniform float lightMapIntensity; 230: #endif 231: #ifdef USE_EMISSIVEMAP 232: uniform sampler2D emissiveMap; 233: #endif 234: 235: #if defined( USE_ENVMAP ) || defined( PHYSICAL ) 236: uniform float reflectivity; 237: uniform float envMapIntensity; 238: #endif 239: #ifdef USE_ENVMAP 240: #if ! defined( PHYSICAL ) && ( defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) ) 241: varying vec3 vWorldPosition; 242: #endif 243: #ifdef ENVMAP_TYPE_CUBE 244: uniform samplerCube envMap; 245: #else 246: uniform sampler2D envMap; 247: #endif 248: uniform float flipEnvMap; 249: #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( PHYSICAL ) 250: uniform float refractionRatio; 251: #else 252: varying vec3 vReflect; 253: #endif 254: #endif 255: 256: float punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) { 257: if( decayExponent > 0.0 ) { 258: #if defined ( PHYSICALLY_CORRECT_LIGHTS ) 259: float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 ); 260: float maxDistanceCutoffFactor = pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) ); 261: return distanceFalloff maxDistanceCutoffFactor; 262: #else 263: return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent ); 264: #endif 265: } 266: return 1.0; 267: } 268: vec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) { 269: return RECIPROCAL_PI diffuseColor; 270: } 271: vec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) { 272: float fresnel = exp2( ( -5.55473 dotLH - 6.98316 ) dotLH ); 273: return ( 1.0 - specularColor ) fresnel + specularColor; 274: } 275: float G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) { 276: float a2 = pow2( alpha ); 277: float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) pow2( dotNL ) ); 278: float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) pow2( dotNV ) ); 279: return 1.0 / ( gl gv ); 280: } 281: float G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) { 282: float a2 = pow2( alpha ); 283: float gv = dotNL sqrt( a2 + ( 1.0 - a2 ) pow2( dotNV ) ); 284: float gl = dotNV sqrt( a2 + ( 1.0 - a2 ) pow2( dotNL ) ); 285: return 0.5 / max( gv + gl, EPSILON ); 286: } 287: float D_GGX( const in float alpha, const in float dotNH ) { 288: float a2 = pow2( alpha ); 289: float denom = pow2( dotNH ) ( a2 - 1.0 ) + 1.0; 290: return RECIPROCAL_PI a2 / pow2( denom ); 291: } 292: vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) { 293: float alpha = pow2( roughness ); 294: vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir ); 295: float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) ); 296: float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) ); 297: float dotNH = saturate( dot( geometry.normal, halfDir ) ); 298: float dotLH = saturate( dot( incidentLight.direction, halfDir ) ); 299: vec3 F = F_Schlick( specularColor, dotLH ); 300: float G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV ); 301: float D = D_GGX( alpha, dotNH ); 302: return F ( G D ); 303: } 304: vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) { 305: const float LUT_SIZE = 64.0; 306: const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE; 307: const float LUT_BIAS = 0.5 / LUT_SIZE; 308: float theta = acos( dot( N, V ) ); 309: vec2 uv = vec2( 310: sqrt( saturate( roughness ) ), 311: saturate( theta / ( 0.5 PI ) ) ); 312: uv = uv LUT_SCALE + LUT_BIAS; 313: return uv; 314: } 315: float LTC_ClippedSphereFormFactor( const in vec3 f ) { 316: float l = length( f ); 317: return max( ( l l + f.z ) / ( l + 1.0 ), 0.0 ); 318: } 319: vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) { 320: float x = dot( v1, v2 ); 321: float y = abs( x ); 322: float a = 0.86267 + (0.49788 + 0.01436 y ) y; 323: float b = 3.45068 + (4.18814 + y) y; 324: float v = a / b; 325: float theta_sintheta = (x > 0.0) ? v : 0.5 inversesqrt( 1.0 - x x ) - v; 326: return cross( v1, v2 ) theta_sintheta; 327: } 328: vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) { 329: vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ]; 330: vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ]; 331: vec3 lightNormal = cross( v1, v2 ); 332: if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 ); 333: vec3 T1, T2; 334: T1 = normalize( V - N dot( V, N ) ); 335: T2 = - cross( N, T1 ); 336: mat3 mat = mInv transpose( mat3( T1, T2, N ) ); 337: vec3 coords[ 4 ]; 338: coords[ 0 ] = mat ( rectCoords[ 0 ] - P ); 339: coords[ 1 ] = mat ( rectCoords[ 1 ] - P ); 340: coords[ 2 ] = mat ( rectCoords[ 2 ] - P ); 341: coords[ 3 ] = mat ( rectCoords[ 3 ] - P ); 342: coords[ 0 ] = normalize( coords[ 0 ] ); 343: coords[ 1 ] = normalize( coords[ 1 ] ); 344: coords[ 2 ] = normalize( coords[ 2 ] ); 345: coords[ 3 ] = normalize( coords[ 3 ] ); 346: vec3 vectorFormFactor = vec3( 0.0 ); 347: vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] ); 348: vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] ); 349: vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] ); 350: vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] ); 351: vec3 result = vec3( LTC_ClippedSphereFormFactor( vectorFormFactor ) ); 352: return result; 353: } 354: vec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) { 355: float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) ); 356: const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 ); 357: const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 ); 358: vec4 r = roughness c0 + c1; 359: float a004 = min( r.x r.x, exp2( - 9.28 dotNV ) ) r.x + r.y; 360: vec2 AB = vec2( -1.04, 1.04 ) a004 + r.zw; 361: return specularColor AB.x + AB.y; 362: } 363: float G_BlinnPhong_Implicit( ) { 364: return 0.25; 365: } 366: float D_BlinnPhong( const in float shininess, const in float dotNH ) { 367: return RECIPROCAL_PI ( shininess 0.5 + 1.0 ) pow( dotNH, shininess ); 368: } 369: vec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) { 370: vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir ); 371: float dotNH = saturate( dot( geometry.normal, halfDir ) ); 372: float dotLH = saturate( dot( incidentLight.direction, halfDir ) ); 373: vec3 F = F_Schlick( specularColor, dotLH ); 374: float G = G_BlinnPhong_Implicit( ); 375: float D = D_BlinnPhong( shininess, dotNH ); 376: return F ( G D ); 377: } 378: float GGXRoughnessToBlinnExponent( const in float ggxRoughness ) { 379: return ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 ); 380: } 381: float BlinnExponentToGGXRoughness( const in float blinnExponent ) { 382: return sqrt( 2.0 / ( blinnExponent + 2.0 ) ); 383: } 384: 385: uniform vec3 ambientLightColor; 386: vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) { 387: vec3 irradiance = ambientLightColor; 388: #ifndef PHYSICALLY_CORRECT_LIGHTS 389: irradiance = PI; 390: #endif 391: return irradiance; 392: } 393: #if 0 > 0 394: struct DirectionalLight { 395: vec3 direction; 396: vec3 color; 397: int shadow; 398: float shadowBias; 399: float shadowRadius; 400: vec2 shadowMapSize; 401: }; 402: uniform DirectionalLight directionalLights[ 0 ]; 403: void getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) { 404: directLight.color = directionalLight.color; 405: directLight.direction = directionalLight.direction; 406: directLight.visible = true; 407: } 408: #endif 409: #if 1 > 0 410: struct PointLight { 411: vec3 position; 412: vec3 color; 413: float distance; 414: float decay; 415: int shadow; 416: float shadowBias; 417: float shadowRadius; 418: vec2 shadowMapSize; 419: }; 420: uniform PointLight pointLights[ 1 ]; 421: void getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) { 422: vec3 lVector = pointLight.position - geometry.position; 423: directLight.direction = normalize( lVector ); 424: float lightDistance = length( lVector ); 425: directLight.color = pointLight.color; 426: directLight.color = punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay ); 427: directLight.visible = ( directLight.color != vec3( 0.0 ) ); 428: } 429: #endif 430: #if 0 > 0 431: struct SpotLight { 432: vec3 position; 433: vec3 direction; 434: vec3 color; 435: float distance; 436: float decay; 437: float coneCos; 438: float penumbraCos; 439: int shadow; 440: float shadowBias; 441: float shadowRadius; 442: vec2 shadowMapSize; 443: }; 444: uniform SpotLight spotLights[ 0 ]; 445: void getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) { 446: vec3 lVector = spotLight.position - geometry.position; 447: directLight.direction = normalize( lVector ); 448: float lightDistance = length( lVector ); 449: float angleCos = dot( directLight.direction, spotLight.direction ); 450: if ( angleCos > spotLight.coneCos ) { 451: float spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos ); 452: directLight.color = spotLight.color; 453: directLight.color = spotEffect punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay ); 454: directLight.visible = true; 455: } else { 456: directLight.color = vec3( 0.0 ); 457: directLight.visible = false; 458: } 459: } 460: #endif 461: #if 0 > 0 462: struct RectAreaLight { 463: vec3 color; 464: vec3 position; 465: vec3 halfWidth; 466: vec3 halfHeight; 467: }; 468: uniform sampler2D ltcMat; uniform sampler2D ltcMag; 469: uniform RectAreaLight rectAreaLights[ 0 ]; 470: #endif 471: #if 0 > 0 472: struct HemisphereLight { 473: vec3 direction; 474: vec3 skyColor; 475: vec3 groundColor; 476: }; 477: uniform HemisphereLight hemisphereLights[ 0 ]; 478: vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) { 479: float dotNL = dot( geometry.normal, hemiLight.direction ); 480: float hemiDiffuseWeight = 0.5 dotNL + 0.5; 481: vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight ); 482: #ifndef PHYSICALLY_CORRECT_LIGHTS 483: irradiance = PI; 484: #endif 485: return irradiance; 486: } 487: #endif 488: #if defined( USE_ENVMAP ) && defined( PHYSICAL ) 489: vec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) { 490: vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix ); 491: #ifdef ENVMAP_TYPE_CUBE 492: vec3 queryVec = vec3( flipEnvMap worldNormal.x, worldNormal.yz ); 493: #ifdef TEXTURE_LOD_EXT 494: vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) ); 495: #else 496: vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) ); 497: #endif 498: envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb; 499: #elif defined( ENVMAP_TYPE_CUBE_UV ) 500: vec3 queryVec = vec3( flipEnvMap worldNormal.x, worldNormal.yz ); 501: vec4 envMapColor = textureCubeUV( queryVec, 1.0 ); 502: #else 503: vec4 envMapColor = vec4( 0.0 ); 504: #endif 505: return PI envMapColor.rgb envMapIntensity; 506: } 507: float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) { 508: float maxMIPLevelScalar = float( maxMIPLevel ); 509: float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 log2( pow2( blinnShininessExponent ) + 1.0 ); 510: return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar ); 511: } 512: vec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) { 513: #ifdef ENVMAP_MODE_REFLECTION 514: vec3 reflectVec = reflect( -geometry.viewDir, geometry.normal ); 515: #else 516: vec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio ); 517: #endif 518: reflectVec = inverseTransformDirection( reflectVec, viewMatrix ); 519: float specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel ); 520: #ifdef ENVMAP_TYPE_CUBE 521: vec3 queryReflectVec = vec3( flipEnvMap reflectVec.x, reflectVec.yz ); 522: #ifdef TEXTURE_LOD_EXT 523: vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel ); 524: #else 525: vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel ); 526: #endif 527: envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb; 528: #elif defined( ENVMAP_TYPE_CUBE_UV ) 529: vec3 queryReflectVec = vec3( flipEnvMap reflectVec.x, reflectVec.yz ); 530: vec4 envMapColor = textureCubeUV(queryReflectVec, BlinnExponentToGGXRoughness(blinnShininessExponent)); 531: #elif defined( ENVMAP_TYPE_EQUIREC ) 532: vec2 sampleUV; 533: sampleUV.y = saturate( reflectVec.y 0.5 + 0.5 ); 534: sampleUV.x = atan( reflectVec.z, reflectVec.x ) RECIPROCAL_PI2 + 0.5; 535: #ifdef TEXTURE_LOD_EXT 536: vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel ); 537: #else 538: vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel ); 539: #endif 540: envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb; 541: #elif defined( ENVMAP_TYPE_SPHERE ) 542: vec3 reflectView = normalize( ( viewMatrix vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) ); 543: #ifdef TEXTURE_LOD_EXT 544: vec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy 0.5 + 0.5, specularMIPLevel ); 545: #else 546: vec4 envMapColor = texture2D( envMap, reflectView.xy 0.5 + 0.5, specularMIPLevel ); 547: #endif 548: envMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb; 549: #endif 550: return envMapColor.rgb envMapIntensity; 551: } 552: #endif 553: 554: #ifdef USE_FOG 555: uniform vec3 fogColor; 556: varying float fogDepth; 557: #ifdef FOG_EXP2 558: uniform float fogDensity; 559: #else 560: uniform float fogNear; 561: uniform float fogFar; 562: #endif 563: #endif 564: 565: #ifdef USE_SHADOWMAP 566: #if 0 > 0 567: uniform sampler2D directionalShadowMap[ 0 ]; 568: varying vec4 vDirectionalShadowCoord[ 0 ]; 569: #endif 570: #if 0 > 0 571: uniform sampler2D spotShadowMap[ 0 ]; 572: varying vec4 vSpotShadowCoord[ 0 ]; 573: #endif 574: #if 1 > 0 575: uniform sampler2D pointShadowMap[ 1 ]; 576: varying vec4 vPointShadowCoord[ 1 ]; 577: #endif 578: float texture2DCompare( sampler2D depths, vec2 uv, float compare ) { 579: return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) ); 580: } 581: float texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) { 582: const vec2 offset = vec2( 0.0, 1.0 ); 583: vec2 texelSize = vec2( 1.0 ) / size; 584: vec2 centroidUV = floor( uv size + 0.5 ) / size; 585: float lb = texture2DCompare( depths, centroidUV + texelSize offset.xx, compare ); 586: float lt = texture2DCompare( depths, centroidUV + texelSize offset.xy, compare ); 587: float rb = texture2DCompare( depths, centroidUV + texelSize offset.yx, compare ); 588: float rt = texture2DCompare( depths, centroidUV + texelSize offset.yy, compare ); 589: vec2 f = fract( uv size + 0.5 ); 590: float a = mix( lb, lt, f.y ); 591: float b = mix( rb, rt, f.y ); 592: float c = mix( a, b, f.x ); 593: return c; 594: } 595: float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) { 596: float shadow = 1.0; 597: shadowCoord.xyz /= shadowCoord.w; 598: shadowCoord.z += shadowBias; 599: bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 ); 600: bool inFrustum = all( inFrustumVec ); 601: bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 ); 602: bool frustumTest = all( frustumTestVec ); 603: if ( frustumTest ) { 604: #if defined( SHADOWMAP_TYPE_PCF ) 605: vec2 texelSize = vec2( 1.0 ) / shadowMapSize; 606: float dx0 = - texelSize.x shadowRadius; 607: float dy0 = - texelSize.y shadowRadius; 608: float dx1 = + texelSize.x shadowRadius; 609: float dy1 = + texelSize.y shadowRadius; 610: shadow = ( 611: texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) + 612: texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) + 613: texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) + 614: texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) + 615: texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) + 616: texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) + 617: texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) + 618: texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) + 619: texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z ) 620: ) ( 1.0 / 9.0 ); 621: #elif defined( SHADOWMAP_TYPE_PCF_SOFT ) 622: vec2 texelSize = vec2( 1.0 ) / shadowMapSize; 623: float dx0 = - texelSize.x shadowRadius; 624: float dy0 = - texelSize.y shadowRadius; 625: float dx1 = + texelSize.x shadowRadius; 626: float dy1 = + texelSize.y shadowRadius; 627: shadow = ( 628: texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) + 629: texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) + 630: texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) + 631: texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) + 632: texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) + 633: texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) + 634: texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) + 635: texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) + 636: texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z ) 637: ) ( 1.0 / 9.0 ); 638: #else 639: shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ); 640: #endif 641: } 642: return shadow; 643: } 644: vec2 cubeToUV( vec3 v, float texelSizeY ) { 645: vec3 absV = abs( v ); 646: float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) ); 647: absV = scaleToCube; 648: v = scaleToCube ( 1.0 - 2.0 texelSizeY ); 649: vec2 planar = v.xy; 650: float almostATexel = 1.5 texelSizeY; 651: float almostOne = 1.0 - almostATexel; 652: if ( absV.z >= almostOne ) { 653: if ( v.z > 0.0 ) 654: planar.x = 4.0 - v.x; 655: } else if ( absV.x >= almostOne ) { 656: float signX = sign( v.x ); 657: planar.x = v.z signX + 2.0 signX; 658: } else if ( absV.y >= almostOne ) { 659: float signY = sign( v.y ); 660: planar.x = v.x + 2.0 signY + 2.0; 661: planar.y = v.z signY - 2.0; 662: } 663: return vec2( 0.125, 0.25 ) planar + vec2( 0.375, 0.75 ); 664: } 665: float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) { 666: vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize vec2( 4.0, 2.0 ) ); 667: vec3 lightToPosition = shadowCoord.xyz; 668: vec3 bd3D = normalize( lightToPosition ); 669: float dp = ( length( lightToPosition ) - shadowBias ) / 1000.0; 670: #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) 671: vec2 offset = vec2( - 1, 1 ) shadowRadius texelSize.y; 672: return ( 673: texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) + 674: texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) + 675: texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) + 676: texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) + 677: texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) + 678: texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) + 679: texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) + 680: texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) + 681: texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp ) 682: ) ( 1.0 / 9.0 ); 683: #else 684: return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ); 685: #endif 686: } 687: #endif 688: 689: float getShadowMask() { 690: float shadow = 1.0; 691: #ifdef USE_SHADOWMAP 692: #if 0 > 0 693: DirectionalLight directionalLight; 694:
695: #endif 696: #if 0 > 0 697: SpotLight spotLight; 698:
699: #endif 700: #if 1 > 0 701: PointLight pointLight; 702:
703: pointLight = pointLights[ 0 ]; 704: shadow = bool( pointLight.shadow ) ? getPointShadow( pointShadowMap[ 0 ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ 0 ] ) : 1.0; 705:
706: #endif 707: #endif 708: return shadow; 709: } 710: 711: #ifdef USE_SPECULARMAP 712: uniform sampler2D specularMap; 713: #endif 714: #ifdef USE_LOGDEPTHBUF 715: uniform float logDepthBufFC; 716: #ifdef USE_LOGDEPTHBUF_EXT 717: varying float vFragDepth; 718: #endif 719: #endif 720: 721: #if NUM_CLIPPING_PLANES > 0 722: #if ! defined( PHYSICAL ) && ! defined( PHONG ) 723: varying vec3 vViewPosition; 724: #endif 725: uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ]; 726: #endif 727: 728: void main() { 729: #if NUM_CLIPPING_PLANES > 0 730: for ( int i = 0; i < UNION_CLIPPING_PLANES; ++ i ) { 731: vec4 plane = clippingPlanes[ i ]; 732: if ( dot( vViewPosition, plane.xyz ) > plane.w ) discard; 733: } 734:
735: #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES 736: bool clipped = true; 737: for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; ++ i ) { 738: vec4 plane = clippingPlanes[ i ]; 739: clipped = ( dot( vViewPosition, plane.xyz ) > plane.w ) && clipped; 740: } 741: if ( clipped ) discard; 742:
743: #endif 744: #endif 745: 746: vec4 diffuseColor = vec4( diffuse, opacity ); 747: ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) ); 748: vec3 totalEmissiveRadiance = emissive; 749: #if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT) 750: gl_FragDepthEXT = log2(vFragDepth) logDepthBufFC 0.5; 751: #endif 752: #ifdef USE_MAP 753: vec4 texelColor = texture2D( map, vUv ); 754: texelColor = mapTexelToLinear( texelColor ); 755: diffuseColor = texelColor; 756: #endif 757: 758: #ifdef USE_COLOR 759: diffuseColor.rgb = vColor; 760: #endif 761: #ifdef USE_ALPHAMAP 762: diffuseColor.a = texture2D( alphaMap, vUv ).g; 763: #endif 764: 765: #ifdef ALPHATEST 766: if ( diffuseColor.a < ALPHATEST ) discard; 767: #endif 768: 769: float specularStrength; 770: #ifdef USE_SPECULARMAP 771: vec4 texelSpecular = texture2D( specularMap, vUv ); 772: specularStrength = texelSpecular.r; 773: #else 774: specularStrength = 1.0; 775: #endif 776: #ifdef USE_EMISSIVEMAP 777: vec4 emissiveColor = texture2D( emissiveMap, vUv ); 778: emissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb; 779: totalEmissiveRadiance = emissiveColor.rgb; 780: #endif 781: 782: reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor ); 783: #ifdef USE_LIGHTMAP 784: reflectedLight.indirectDiffuse += PI texture2D( lightMap, vUv2 ).xyz lightMapIntensity; 785: #endif 786: 787: reflectedLight.indirectDiffuse = BRDF_Diffuse_Lambert( diffuseColor.rgb ); 788: #ifdef DOUBLE_SIDED 789: reflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack; 790: #else 791: reflectedLight.directDiffuse = vLightFront; 792: #endif 793: reflectedLight.directDiffuse = BRDF_Diffuse_Lambert( diffuseColor.rgb ) getShadowMask(); 794: #ifdef USE_AOMAP 795: float ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) aoMapIntensity + 1.0; 796: reflectedLight.indirectDiffuse = ambientOcclusion; 797: #if defined( USE_ENVMAP ) && defined( PHYSICAL ) 798: float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) ); 799: reflectedLight.indirectSpecular = computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness ); 800: #endif 801: #endif 802: 803: vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance; 804: #ifdef DOUBLE_SIDED 805: float flipNormal = ( float( gl_FrontFacing ) 2.0 - 1.0 ); 806: #else 807: float flipNormal = 1.0; 808: #endif 809: 810: #ifdef USE_ENVMAP 811: #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) 812: vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition ); 813: vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); 814: #ifdef ENVMAP_MODE_REFLECTION 815: vec3 reflectVec = reflect( cameraToVertex, worldNormal ); 816: #else 817: vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio ); 818: #endif 819: #else 820: vec3 reflectVec = vReflect; 821: #endif 822: #ifdef ENVMAP_TYPE_CUBE 823: vec4 envColor = textureCube( envMap, flipNormal vec3( flipEnvMap reflectVec.x, reflectVec.yz ) ); 824: #elif defined( ENVMAP_TYPE_EQUIREC ) 825: vec2 sampleUV; 826: sampleUV.y = asin( flipNormal reflectVec.y ) RECIPROCAL_PI + 0.5; 827: sampleUV.x = atan( flipNormal reflectVec.z, flipNormal reflectVec.x ) RECIPROCAL_PI2 + 0.5; 828: vec4 envColor = texture2D( envMap, sampleUV ); 829: #elif defined( ENVMAP_TYPE_SPHERE ) 830: vec3 reflectView = flipNormal normalize( ( viewMatrix vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) ); 831: vec4 envColor = texture2D( envMap, reflectView.xy 0.5 + 0.5 ); 832: #else 833: vec4 envColor = vec4( 0.0 ); 834: #endif 835: envColor = envMapTexelToLinear( envColor ); 836: #ifdef ENVMAP_BLENDING_MULTIPLY 837: outgoingLight = mix( outgoingLight, outgoingLight envColor.xyz, specularStrength reflectivity ); 838: #elif defined( ENVMAP_BLENDING_MIX ) 839: outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength reflectivity ); 840: #elif defined( ENVMAP_BLENDING_ADD ) 841: outgoingLight += envColor.xyz specularStrength reflectivity; 842: #endif 843: #endif 844: 845: gl_FragColor = vec4( outgoingLight, diffuseColor.a ); 846: #if defined( TONE_MAPPING ) 847: gl_FragColor.rgb = toneMapping( gl_FragColor.rgb ); 848: #endif 849: 850: gl_FragColor = linearToOutputTexel( gl_FragColor ); 851: 852: #ifdef USE_FOG 853: #ifdef FOG_EXP2 854: float fogFactor = whiteCompliment( exp2( - fogDensity fogDensity fogDepth fogDepth LOG2 ) ); 855: #else 856: float fogFactor = smoothstep( fogNear, fogFar, fogDepth ); 857: #endif 858: gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor ); 859: #endif 860: 861: #ifdef PREMULTIPLIED_ALPHA 862: gl_FragColor.rgb = gl_FragColor.a; 863: #endif 864: 865: #if defined( DITHERING ) 866: gl_FragColor.rgb = dithering( gl_FragColor.rgb ); 867: #endif 868: 869: } 870: 4:12:10 PM THREE.WebGLProgram: shader error: 0 gl.VALIDATE_STATUS false gl.getProgramInfoLog Invalid vertex shader. Invalid fragment shader. Link cannot proceed. Vertex shader compilation failed. ERROR: 0:97: 'const' : overloaded functions must have the same parameter qualifiers ERROR: 1 compilation errors. No code generated.
Fragment shader compilation failed. ERROR: 0:158: 'const' : overloaded functions must have the same parameter qualifiers ERROR: 1 compilation errors. No code generated.`