Jump to content

ShadowGenerator usePercentageCloserFiltering breaks Android


Jörg Wasmeier
 Share

Recommended Posts

https://playground.babylonjs.com/indexStable.html#MK6IZ7#1

Hi there,

if you use usePercentageCloserFiltering (Shadowgenerator) it will break Android and only Android (iOS, Safari, Chrome desktop works fine).

BJS - [10:25:40]: Unable to compile effect:

BJS - [10:25:40]: Uniforms:  world, view, viewProjection, vEyePosition, vLightsType, vAmbientColor, vDiffuseColor, vSpecularColor, vEmissiveColor, vFogInfos, vFogColor, pointSize, vDiffuseInfos, vAmbientInfos, vOpacityInfos, vReflectionInfos, vEmissiveInfos, vSpecularInfos, vBumpInfos, vLightmapInfos, vRefractionInfos, mBones, vClipPlane, diffuseMatrix, ambientMatrix, opacityMatrix, reflectionMatrix, emissiveMatrix, specularMatrix, bumpMatrix, normalMatrix, lightmapMatrix, refractionMatrix, diffuseLeftColor, diffuseRightColor, opacityParts, reflectionLeftColor, reflectionRightColor, emissiveLeftColor, emissiveRightColor, refractionLeftColor, refractionRightColor, vReflectionPosition, vReflectionSize, logarithmicDepthConstant, vTangentSpaceParams, alphaCutOff, vLightData0, vLightDiffuse0, vLightSpecular0, vLightDirection0, vLightGround0, lightMatrix0, shadowsInfo0, depthValues0, diffuseSampler, ambientSampler, opacitySampler, reflectionCubeSampler, reflection2DSampler, emissiveSampler, specularSampler, bumpSampler, lightmapSampler, refractionCubeSampler, refraction2DSampler, shadowSampler0, depthSampler0
t._ErrorEnabled @ babylon.js:4


BJS - [10:25:40]: Attributes:  position, normal

BJS - [10:25:40]: Vertex shader: default
1    #version 300 es
2    #define WEBGL2 
3    #define DIFFUSEDIRECTUV 0
4    #define AMBIENTDIRECTUV 0
5    #define OPACITYDIRECTUV 0
6    #define EMISSIVEDIRECTUV 0
7    #define SPECULARDIRECTUV 0
8    #define BUMPDIRECTUV 0
9    #define SPECULARTERM
10    #define NORMAL
11    #define NUM_BONE_INFLUENCERS 0
12    #define BonesPerMesh 0
13    #define LIGHTMAPDIRECTUV 0
14    #define SHADOWFLOAT
15    #define NUM_MORPH_INFLUENCERS 0
16    #define VIGNETTEBLENDMODEMULTIPLY
17    #define SAMPLER3DGREENDEPTH
18    #define SAMPLER3DBGRMAP
19    #define LIGHT0
20    #define DIRLIGHT0
21    #define SHADOW0
22    #define SHADOWPCF0
23    #define SHADOWS
24    
25    #define SHADER_NAME vertex:default
26    precision highp float;
27    layout(std140,column_major) uniform;
28    uniform Material
29    {
30    vec4 diffuseLeftColor;
31    vec4 diffuseRightColor;
32    vec4 opacityParts;
33    vec4 reflectionLeftColor;
34    vec4 reflectionRightColor;
35    vec4 refractionLeftColor;
36    vec4 refractionRightColor;
37    vec4 emissiveLeftColor; 
38    vec4 emissiveRightColor;
39    vec2 vDiffuseInfos;
40    vec2 vAmbientInfos;
41    vec2 vOpacityInfos;
42    vec2 vReflectionInfos;
43    vec3 vReflectionPosition;
44    vec3 vReflectionSize;
45    vec2 vEmissiveInfos;
46    vec2 vLightmapInfos;
47    vec2 vSpecularInfos;
48    vec3 vBumpInfos;
49    mat4 diffuseMatrix;
50    mat4 ambientMatrix;
51    mat4 opacityMatrix;
52    mat4 reflectionMatrix;
53    mat4 emissiveMatrix;
54    mat4 lightmapMatrix;
55    mat4 specularMatrix;
56    mat4 bumpMatrix; 
57    vec4 vTangentSpaceParams;
58    mat4 refractionMatrix;
59    vec4 vRefractionInfos;
60    vec4 vSpecularColor;
61    vec3 vEmissiveColor;
62    vec4 vDiffuseColor;
63    float pointSize; 
64    };
65    uniform Scene {
66    mat4 viewProjection;
67    mat4 view;
68    };
69    
70    #define CUSTOM_VERTEX_BEGIN
71    in vec3 position;
72    #ifdef NORMAL
73    in vec3 normal;
74    #endif
75    #ifdef TANGENT
76    in vec4 tangent;
77    #endif
78    #ifdef UV1
79    in vec2 uv;
80    #endif
81    #ifdef UV2
82    in vec2 uv2;
83    #endif
84    #ifdef VERTEXCOLOR
85    in vec4 color;
86    #endif
87    const float PI=3.1415926535897932384626433832795;
88    const float LinearEncodePowerApprox=2.2;
89    const float GammaEncodePowerApprox=1.0/LinearEncodePowerApprox;
90    const vec3 LuminanceEncodeApprox=vec3(0.2126,0.7152,0.0722);
91    mat3 transposeMat3(mat3 inMatrix) {
92    vec3 i0=inMatrix[0];
93    vec3 i1=inMatrix[1];
94    vec3 i2=inMatrix[2];
95    mat3 outMatrix=mat3(
96    vec3(i0.x,i1.x,i2.x),
97    vec3(i0.y,i1.y,i2.y),
98    vec3(i0.z,i1.z,i2.z)
99    );
100    return outMatrix;
101    }
102    
103    mat3 inverseMat3(mat3 inMatrix) {
104    float a00=inMatrix[0][0],a01=inMatrix[0][1],a02=inMatrix[0][2];
105    float a10=inMatrix[1][0],a11=inMatrix[1][1],a12=inMatrix[1][2];
106    float a20=inMatrix[2][0],a21=inMatrix[2][1],a22=inMatrix[2][2];
107    float b01=a22*a11-a12*a21;
108    float b11=-a22*a10+a12*a20;
109    float b21=a21*a10-a11*a20;
110    float det=a00*b01+a01*b11+a02*b21;
111    return mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),
112    b11,(a22*a00-a02*a20),(-a12*a00+a02*a10),
113    b21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;
114    }
115    float computeFallOff(float value,vec2 clipSpace,float frustumEdgeFalloff)
116    {
117    float mask=smoothstep(1.0-frustumEdgeFalloff,1.0,clamp(dot(clipSpace,clipSpace),0.,1.));
118    return mix(value,1.0,mask);
119    }
120    vec3 applyEaseInOut(vec3 x){
121    return x*x*(3.0-2.0*x);
122    }
123    vec3 toLinearSpace(vec3 color)
124    {
125    return pow(color,vec3(LinearEncodePowerApprox));
126    }
127    vec3 toGammaSpace(vec3 color)
128    {
129    return pow(color,vec3(GammaEncodePowerApprox));
130    }
131    float square(float value)
132    {
133    return value*value;
134    }
135    float getLuminance(vec3 color)
136    {
137    return clamp(dot(color,LuminanceEncodeApprox),0.,1.);
138    }
139    
140    float getRand(vec2 seed) {
141    return fract(sin(dot(seed.xy ,vec2(12.9898,78.233)))*43758.5453);
142    }
143    float dither(vec2 seed,float varianceAmount) {
144    float rand=getRand(seed);
145    float dither=mix(-varianceAmount/255.0,varianceAmount/255.0,rand);
146    return dither;
147    }
148    #if NUM_BONE_INFLUENCERS>0
149    uniform mat4 mBones[BonesPerMesh];
150    in vec4 matricesIndices;
151    in vec4 matricesWeights;
152    #if NUM_BONE_INFLUENCERS>4
153    in vec4 matricesIndicesExtra;
154    in vec4 matricesWeightsExtra;
155    #endif
156    #endif
157    
158    #ifdef INSTANCES
159    in vec4 world0;
160    in vec4 world1;
161    in vec4 world2;
162    in vec4 world3;
163    #else
164    uniform mat4 world;
165    #endif
166    #ifdef MAINUV1
167    out vec2 vMainUV1;
168    #endif
169    #ifdef MAINUV2
170    out vec2 vMainUV2;
171    #endif
172    #if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0
173    out vec2 vDiffuseUV;
174    #endif
175    #if defined(AMBIENT) && AMBIENTDIRECTUV == 0
176    out vec2 vAmbientUV;
177    #endif
178    #if defined(OPACITY) && OPACITYDIRECTUV == 0
179    out vec2 vOpacityUV;
180    #endif
181    #if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0
182    out vec2 vEmissiveUV;
183    #endif
184    #if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0
185    out vec2 vLightmapUV;
186    #endif
187    #if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0
188    out vec2 vSpecularUV;
189    #endif
190    #if defined(BUMP) && BUMPDIRECTUV == 0
191    out vec2 vBumpUV;
192    #endif
193    
194    out vec3 vPositionW;
195    #ifdef NORMAL
196    out vec3 vNormalW;
197    #endif
198    #ifdef VERTEXCOLOR
199    out vec4 vColor;
200    #endif
201    #if defined(BUMP) || defined(PARALLAX)
202    #if defined(TANGENT) && defined(NORMAL) 
203    out mat3 vTBN;
204    #endif
205    #endif
206    
207    #ifdef CLIPPLANE
208    uniform vec4 vClipPlane;
209    out float fClipDistance;
210    #endif
211    #ifdef FOG
212    out vec3 vFogDistance;
213    #endif
214    #ifdef LIGHT0
215    uniform Light0
216    {
217    vec4 vLightData;
218    vec4 vLightDiffuse;
219    vec3 vLightSpecular;
220    #ifdef SPOTLIGHT0
221    vec4 vLightDirection;
222    #endif
223    #ifdef HEMILIGHT0
224    vec3 vLightGround;
225    #endif
226    vec4 shadowsInfo;
227    vec2 depthValues;
228    } light0;
229    #ifdef PROJECTEDLIGHTTEXTURE0
230    uniform mat4 textureProjectionMatrix0;
231    uniform sampler2D projectionLightSampler0;
232    #endif
233    #ifdef SHADOW0
234    #if defined(SHADOWCUBE0)
235    uniform samplerCube shadowSampler0; 
236    #else
237    out vec4 vPositionFromLight0;
238    out float vDepthMetric0;
239    #if defined(SHADOWPCSS0)
240    uniform highp sampler2DShadow shadowSampler0;
241    uniform highp sampler2D depthSampler0;
242    #elif defined(SHADOWPCF0)
243    uniform highp sampler2DShadow shadowSampler0;
244    #else
245    uniform sampler2D shadowSampler0;
246    #endif
247    uniform mat4 lightMatrix0;
248    #endif
249    #endif
250    #endif
251    #ifdef LIGHT1
252    uniform Light1
253    {
254    vec4 vLightData;
255    vec4 vLightDiffuse;
256    vec3 vLightSpecular;
257    #ifdef SPOTLIGHT1
258    vec4 vLightDirection;
259    #endif
260    #ifdef HEMILIGHT1
261    vec3 vLightGround;
262    #endif
263    vec4 shadowsInfo;
264    vec2 depthValues;
265    } light1;
266    #ifdef PROJECTEDLIGHTTEXTURE1
267    uniform mat4 textureProjectionMatrix1;
268    uniform sampler2D projectionLightSampler1;
269    #endif
270    #ifdef SHADOW1
271    #if defined(SHADOWCUBE1)
272    uniform samplerCube shadowSampler1; 
273    #else
274    out vec4 vPositionFromLight1;
275    out float vDepthMetric1;
276    #if defined(SHADOWPCSS1)
277    uniform highp sampler2DShadow shadowSampler1;
278    uniform highp sampler2D depthSampler1;
279    #elif defined(SHADOWPCF1)
280    uniform highp sampler2DShadow shadowSampler1;
281    #else
282    uniform sampler2D shadowSampler1;
283    #endif
284    uniform mat4 lightMatrix1;
285    #endif
286    #endif
287    #endif
288    #ifdef LIGHT2
289    uniform Light2
290    {
291    vec4 vLightData;
292    vec4 vLightDiffuse;
293    vec3 vLightSpecular;
294    #ifdef SPOTLIGHT2
295    vec4 vLightDirection;
296    #endif
297    #ifdef HEMILIGHT2
298    vec3 vLightGround;
299    #endif
300    vec4 shadowsInfo;
301    vec2 depthValues;
302    } light2;
303    #ifdef PROJECTEDLIGHTTEXTURE2
304    uniform mat4 textureProjectionMatrix2;
305    uniform sampler2D projectionLightSampler2;
306    #endif
307    #ifdef SHADOW2
308    #if defined(SHADOWCUBE2)
309    uniform samplerCube shadowSampler2; 
310    #else
311    out vec4 vPositionFromLight2;
312    out float vDepthMetric2;
313    #if defined(SHADOWPCSS2)
314    uniform highp sampler2DShadow shadowSampler2;
315    uniform highp sampler2D depthSampler2;
316    #elif defined(SHADOWPCF2)
317    uniform highp sampler2DShadow shadowSampler2;
318    #else
319    uniform sampler2D shadowSampler2;
320    #endif
321    uniform mat4 lightMatrix2;
322    #endif
323    #endif
324    #endif
325    #ifdef LIGHT3
326    uniform Light3
327    {
328    vec4 vLightData;
329    vec4 vLightDiffuse;
330    vec3 vLightSpecular;
331    #ifdef SPOTLIGHT3
332    vec4 vLightDirection;
333    #endif
334    #ifdef HEMILIGHT3
335    vec3 vLightGround;
336    #endif
337    vec4 shadowsInfo;
338    vec2 depthValues;
339    } light3;
340    #ifdef PROJECTEDLIGHTTEXTURE3
341    uniform mat4 textureProjectionMatrix3;
342    uniform sampler2D projectionLightSampler3;
343    #endif
344    #ifdef SHADOW3
345    #if defined(SHADOWCUBE3)
346    uniform samplerCube shadowSampler3; 
347    #else
348    out vec4 vPositionFromLight3;
349    out float vDepthMetric3;
350    #if defined(SHADOWPCSS3)
351    uniform highp sampler2DShadow shadowSampler3;
352    uniform highp sampler2D depthSampler3;
353    #elif defined(SHADOWPCF3)
354    uniform highp sampler2DShadow shadowSampler3;
355    #else
356    uniform sampler2D shadowSampler3;
357    #endif
358    uniform mat4 lightMatrix3;
359    #endif
360    #endif
361    #endif
362    
363    #ifdef MORPHTARGETS
364    uniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];
365    #endif
366    
367    #ifdef REFLECTIONMAP_SKYBOX
368    out vec3 vPositionUVW;
369    #endif
370    #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
371    out vec3 vDirectionW;
372    #endif
373    #ifdef LOGARITHMICDEPTH
374    uniform float logarithmicDepthConstant;
375    out float vFragmentDepth;
376    #endif
377    #define CUSTOM_VERTEX_DEFINITIONS
378    void main(void) {
379    #define CUSTOM_VERTEX_MAIN_BEGIN
380    vec3 positionUpdated=position;
381    #ifdef NORMAL 
382    vec3 normalUpdated=normal;
383    #endif
384    #ifdef TANGENT
385    vec4 tangentUpdated=tangent;
386    #endif
387    
388    #ifdef REFLECTIONMAP_SKYBOX
389    vPositionUVW=positionUpdated;
390    #endif 
391    #define CUSTOM_VERTEX_UPDATE_POSITION
392    #define CUSTOM_VERTEX_UPDATE_NORMAL
393    #ifdef INSTANCES
394    mat4 finalWorld=mat4(world0,world1,world2,world3);
395    #else
396    mat4 finalWorld=world;
397    #endif
398    #if NUM_BONE_INFLUENCERS>0
399    mat4 influence;
400    influence=mBones[int(matricesIndices[0])]*matricesWeights[0];
401    #if NUM_BONE_INFLUENCERS>1
402    influence+=mBones[int(matricesIndices[1])]*matricesWeights[1];
403    #endif 
404    #if NUM_BONE_INFLUENCERS>2
405    influence+=mBones[int(matricesIndices[2])]*matricesWeights[2];
406    #endif 
407    #if NUM_BONE_INFLUENCERS>3
408    influence+=mBones[int(matricesIndices[3])]*matricesWeights[3];
409    #endif 
410    #if NUM_BONE_INFLUENCERS>4
411    influence+=mBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];
412    #endif 
413    #if NUM_BONE_INFLUENCERS>5
414    influence+=mBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];
415    #endif 
416    #if NUM_BONE_INFLUENCERS>6
417    influence+=mBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];
418    #endif 
419    #if NUM_BONE_INFLUENCERS>7
420    influence+=mBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];
421    #endif 
422    finalWorld=finalWorld*influence;
423    #endif
424    gl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);
425    vec4 worldPos=finalWorld*vec4(positionUpdated,1.0);
426    vPositionW=vec3(worldPos);
427    #ifdef NORMAL
428    mat3 normalWorld=mat3(finalWorld);
429    #ifdef NONUNIFORMSCALING
430    normalWorld=transposeMat3(inverseMat3(normalWorld));
431    #endif
432    vNormalW=normalize(normalWorld*normalUpdated);
433    #endif
434    #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
435    vDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));
436    #endif
437    
438    #ifndef UV1
439    vec2 uv=vec2(0.,0.);
440    #endif
441    #ifndef UV2
442    vec2 uv2=vec2(0.,0.);
443    #endif
444    #ifdef MAINUV1
445    vMainUV1=uv;
446    #endif
447    #ifdef MAINUV2
448    vMainUV2=uv2;
449    #endif
450    #if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0
451    if (vDiffuseInfos.x == 0.)
452    {
453    vDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));
454    }
455    else
456    {
457    vDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));
458    }
459    #endif
460    #if defined(AMBIENT) && AMBIENTDIRECTUV == 0
461    if (vAmbientInfos.x == 0.)
462    {
463    vAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));
464    }
465    else
466    {
467    vAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));
468    }
469    #endif
470    #if defined(OPACITY) && OPACITYDIRECTUV == 0
471    if (vOpacityInfos.x == 0.)
472    {
473    vOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));
474    }
475    else
476    {
477    vOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));
478    }
479    #endif
480    #if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0
481    if (vEmissiveInfos.x == 0.)
482    {
483    vEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));
484    }
485    else
486    {
487    vEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));
488    }
489    #endif
490    #if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0
491    if (vLightmapInfos.x == 0.)
492    {
493    vLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));
494    }
495    else
496    {
497    vLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));
498    }
499    #endif
500    #if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0
501    if (vSpecularInfos.x == 0.)
502    {
503    vSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));
504    }
505    else
506    {
507    vSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));
508    }
509    #endif
510    #if defined(BUMP) && BUMPDIRECTUV == 0
511    if (vBumpInfos.x == 0.)
512    {
513    vBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));
514    }
515    else
516    {
517    vBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));
518    }
519    #endif
520    #if defined(BUMP) || defined(PARALLAX)
521    #if defined(TANGENT) && defined(NORMAL)
522    vec3 tbnNormal=normalize(normalUpdated);
523    vec3 tbnTangent=normalize(tangentUpdated.xyz);
524    vec3 tbnBitangent=cross(tbnNormal,tbnTangent)*tangentUpdated.w;
525    vTBN=mat3(finalWorld)*mat3(tbnTangent,tbnBitangent,tbnNormal);
526    #endif
527    #endif
528    #ifdef CLIPPLANE
529    fClipDistance=dot(worldPos,vClipPlane);
530    #endif
531    #ifdef FOG
532    vFogDistance=(view*worldPos).xyz;
533    #endif
534    #ifdef SHADOWS
535    #if defined(SHADOW0) && !defined(SHADOWCUBE0)
536    vPositionFromLight0=lightMatrix0*worldPos;
537    vDepthMetric0=((vPositionFromLight0.z+light0.depthValues.x)/(light0.depthValues.y));
538    #endif
539    #endif
540    #ifdef SHADOWS
541    #if defined(SHADOW1) && !defined(SHADOWCUBE1)
542    vPositionFromLight1=lightMatrix1*worldPos;
543    vDepthMetric1=((vPositionFromLight1.z+light1.depthValues.x)/(light1.depthValues.y));
544    #endif
545    #endif
546    #ifdef SHADOWS
547    #if defined(SHADOW2) && !defined(SHADOWCUBE2)
548    vPositionFromLight2=lightMatrix2*worldPos;
549    vDepthMetric2=((vPositionFromLight2.z+light2.depthValues.x)/(light2.depthValues.y));
550    #endif
551    #endif
552    #ifdef SHADOWS
553    #if defined(SHADOW3) && !defined(SHADOWCUBE3)
554    vPositionFromLight3=lightMatrix3*worldPos;
555    vDepthMetric3=((vPositionFromLight3.z+light3.depthValues.x)/(light3.depthValues.y));
556    #endif
557    #endif
558    
559    #ifdef VERTEXCOLOR
560    
561    vColor=color;
562    #endif
563    #ifdef POINTSIZE
564    gl_PointSize=pointSize;
565    #endif
566    #ifdef LOGARITHMICDEPTH
567    vFragmentDepth=1.0+gl_Position.w;
568    gl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;
569    #endif
570    #define CUSTOM_VERTEX_MAIN_END
571    }
572    

kind reagards

Link to comment
Share on other sites

Hello a part of the error is missing (the end)

But I guess this is because too much uniforms are used. Just waiting to confirm with the full error log

Link to comment
Share on other sites

Hi, did you see that i provide an example there is only one cube here is the full error report: I hope it helps :)

 

babylon.js:4 BJS - [21:02:28]: Unable to compile effect:
  t._ErrorEnabled @ babylon.js:4
  t._prepareEffect @ babylon.js:1

 

babylon.js:4 BJS - [21:02:28]: Uniforms:  world, view, viewProjection, vEyePosition, vLightsType, vAmbientColor, vDiffuseColor, vSpecularColor, vEmissiveColor, vFogInfos, vFogColor, pointSize, vDiffuseInfos, vAmbientInfos, vOpacityInfos, vReflectionInfos, vEmissiveInfos, vSpecularInfos, vBumpInfos, vLightmapInfos, vRefractionInfos, mBones, vClipPlane, diffuseMatrix, ambientMatrix, opacityMatrix, reflectionMatrix, emissiveMatrix, specularMatrix, bumpMatrix, normalMatrix, lightmapMatrix, refractionMatrix, diffuseLeftColor, diffuseRightColor, opacityParts, reflectionLeftColor, reflectionRightColor, emissiveLeftColor, emissiveRightColor, refractionLeftColor, refractionRightColor, vReflectionPosition, vReflectionSize, logarithmicDepthConstant, vTangentSpaceParams, alphaCutOff, vLightData0, vLightDiffuse0, vLightSpecular0, vLightDirection0, vLightGround0, lightMatrix0, shadowsInfo0, depthValues0, diffuseSampler, ambientSampler, opacitySampler, reflectionCubeSampler, reflection2DSampler, emissiveSampler, specularSampler, bumpSampler, lightmapSampler, refractionCubeSampler, refraction2DSampler, shadowSampler0, depthSampler0

 

babylon.js:4 BJS - [21:02:28]: Attributes: position, normal
  t._ErrorEnabled @

babylon.js:4

 

BJS - [21:02:28]: Vertex shader: default
1    #version 300 es
2    #define WEBGL2 
3    #define DIFFUSEDIRECTUV 0
4    #define AMBIENTDIRECTUV 0
5    #define OPACITYDIRECTUV 0
6    #define EMISSIVEDIRECTUV 0
7    #define SPECULARDIRECTUV 0
8    #define BUMPDIRECTUV 0
9    #define SPECULARTERM
10    #define NORMAL
11    #define NUM_BONE_INFLUENCERS 0
12    #define BonesPerMesh 0
13    #define LIGHTMAPDIRECTUV 0
14    #define SHADOWFLOAT
15    #define NUM_MORPH_INFLUENCERS 0
16    #define VIGNETTEBLENDMODEMULTIPLY
17    #define SAMPLER3DGREENDEPTH
18    #define SAMPLER3DBGRMAP
19    #define LIGHT0
20    #define DIRLIGHT0
21    #define SHADOW0
22    #define SHADOWPCF0
23    #define SHADOWS
24    
25    #define SHADER_NAME vertex:default
26    precision highp float;
27    layout(std140,column_major) uniform;
28    uniform Material
29    {
30    vec4 diffuseLeftColor;
31    vec4 diffuseRightColor;
32    vec4 opacityParts;
33    vec4 reflectionLeftColor;
34    vec4 reflectionRightColor;
35    vec4 refractionLeftColor;
36    vec4 refractionRightColor;
37    vec4 emissiveLeftColor; 
38    vec4 emissiveRightColor;
39    vec2 vDiffuseInfos;
40    vec2 vAmbientInfos;
41    vec2 vOpacityInfos;
42    vec2 vReflectionInfos;
43    vec3 vReflectionPosition;
44    vec3 vReflectionSize;
45    vec2 vEmissiveInfos;
46    vec2 vLightmapInfos;
47    vec2 vSpecularInfos;
48    vec3 vBumpInfos;
49    mat4 diffuseMatrix;
50    mat4 ambientMatrix;
51    mat4 opacityMatrix;
52    mat4 reflectionMatrix;
53    mat4 emissiveMatrix;
54    mat4 lightmapMatrix;
55    mat4 specularMatrix;
56    mat4 bumpMatrix; 
57    vec4 vTangentSpaceParams;
58    mat4 refractionMatrix;
59    vec4 vRefractionInfos;
60    vec4 vSpecularColor;
61    vec3 vEmissiveColor;
62    vec4 vDiffuseColor;
63    float pointSize; 
64    };
65    uniform Scene {
66    mat4 viewProjection;
67    mat4 view;
68    };
69    
70    #define CUSTOM_VERTEX_BEGIN
71    in vec3 position;
72    #ifdef NORMAL
73    in vec3 normal;
74    #endif
75    #ifdef TANGENT
76    in vec4 tangent;
77    #endif
78    #ifdef UV1
79    in vec2 uv;
80    #endif
81    #ifdef UV2
82    in vec2 uv2;
83    #endif
84    #ifdef VERTEXCOLOR
85    in vec4 color;
86    #endif
87    const float PI=3.1415926535897932384626433832795;
88    const float LinearEncodePowerApprox=2.2;
89    const float GammaEncodePowerApprox=1.0/LinearEncodePowerApprox;
90    const vec3 LuminanceEncodeApprox=vec3(0.2126,0.7152,0.0722);
91    mat3 transposeMat3(mat3 inMatrix) {
92    vec3 i0=inMatrix[0];
93    vec3 i1=inMatrix[1];
94    vec3 i2=inMatrix[2];
95    mat3 outMatrix=mat3(
96    vec3(i0.x,i1.x,i2.x),
97    vec3(i0.y,i1.y,i2.y),
98    vec3(i0.z,i1.z,i2.z)
99    );
100    return outMatrix;
101    }
102    
103    mat3 inverseMat3(mat3 inMatrix) {
104    float a00=inMatrix[0][0],a01=inMatrix[0][1],a02=inMatrix[0][2];
105    float a10=inMatrix[1][0],a11=inMatrix[1][1],a12=inMatrix[1][2];
106    float a20=inMatrix[2][0],a21=inMatrix[2][1],a22=inMatrix[2][2];
107    float b01=a22*a11-a12*a21;
108    float b11=-a22*a10+a12*a20;
109    float b21=a21*a10-a11*a20;
110    float det=a00*b01+a01*b11+a02*b21;
111    return mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),
112    b11,(a22*a00-a02*a20),(-a12*a00+a02*a10),
113    b21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;
114    }
115    float computeFallOff(float value,vec2 clipSpace,float frustumEdgeFalloff)
116    {
117    float mask=smoothstep(1.0-frustumEdgeFalloff,1.0,clamp(dot(clipSpace,clipSpace),0.,1.));
118    return mix(value,1.0,mask);
119    }
120    vec3 applyEaseInOut(vec3 x){
121    return x*x*(3.0-2.0*x);
122    }
123    vec3 toLinearSpace(vec3 color)
124    {
125    return pow(color,vec3(LinearEncodePowerApprox));
126    }
127    vec3 toGammaSpace(vec3 color)
128    {
129    return pow(color,vec3(GammaEncodePowerApprox));
130    }
131    float square(float value)
132    {
133    return value*value;
134    }
135    float getLuminance(vec3 color)
136    {
137    return clamp(dot(color,LuminanceEncodeApprox),0.,1.);
138    }
139    
140    float getRand(vec2 seed) {
141    return fract(sin(dot(seed.xy ,vec2(12.9898,78.233)))*43758.5453);
142    }
143    float dither(vec2 seed,float varianceAmount) {
144    float rand=getRand(seed);
145    float dither=mix(-varianceAmount/255.0,varianceAmount/255.0,rand);
146    return dither;
147    }
148    #if NUM_BONE_INFLUENCERS>0
149    uniform mat4 mBones[BonesPerMesh];
150    in vec4 matricesIndices;
151    in vec4 matricesWeights;
152    #if NUM_BONE_INFLUENCERS>4
153    in vec4 matricesIndicesExtra;
154    in vec4 matricesWeightsExtra;
155    #endif
156    #endif
157    
158    #ifdef INSTANCES
159    in vec4 world0;
160    in vec4 world1;
161    in vec4 world2;
162    in vec4 world3;
163    #else
164    uniform mat4 world;
165    #endif
166    #ifdef MAINUV1
167    out vec2 vMainUV1;
168    #endif
169    #ifdef MAINUV2
170    out vec2 vMainUV2;
171    #endif
172    #if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0
173    out vec2 vDiffuseUV;
174    #endif
175    #if defined(AMBIENT) && AMBIENTDIRECTUV == 0
176    out vec2 vAmbientUV;
177    #endif
178    #if defined(OPACITY) && OPACITYDIRECTUV == 0
179    out vec2 vOpacityUV;
180    #endif
181    #if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0
182    out vec2 vEmissiveUV;
183    #endif
184    #if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0
185    out vec2 vLightmapUV;
186    #endif
187    #if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0
188    out vec2 vSpecularUV;
189    #endif
190    #if defined(BUMP) && BUMPDIRECTUV == 0
191    out vec2 vBumpUV;
192    #endif
193    
194    out vec3 vPositionW;
195    #ifdef NORMAL
196    out vec3 vNormalW;
197    #endif
198    #ifdef VERTEXCOLOR
199    out vec4 vColor;
200    #endif
201    #if defined(BUMP) || defined(PARALLAX)
202    #if defined(TANGENT) && defined(NORMAL) 
203    out mat3 vTBN;
204    #endif
205    #endif
206    
207    #ifdef CLIPPLANE
208    uniform vec4 vClipPlane;
209    out float fClipDistance;
210    #endif
211    #ifdef FOG
212    out vec3 vFogDistance;
213    #endif
214    #ifdef LIGHT0
215    uniform Light0
216    {
217    vec4 vLightData;
218    vec4 vLightDiffuse;
219    vec3 vLightSpecular;
220    #ifdef SPOTLIGHT0
221    vec4 vLightDirection;
222    #endif
223    #ifdef HEMILIGHT0
224    vec3 vLightGround;
225    #endif
226    vec4 shadowsInfo;
227    vec2 depthValues;
228    } light0;
229    #ifdef PROJECTEDLIGHTTEXTURE0
230    uniform mat4 textureProjectionMatrix0;
231    uniform sampler2D projectionLightSampler0;
232    #endif
233    #ifdef SHADOW0
234    #if defined(SHADOWCUBE0)
235    uniform samplerCube shadowSampler0; 
236    #else
237    out vec4 vPositionFromLight0;
238    out float vDepthMetric0;
239    #if defined(SHADOWPCSS0)
240    uniform highp sampler2DShadow shadowSampler0;
241    uniform highp sampler2D depthSampler0;
242    #elif defined(SHADOWPCF0)
243    uniform highp sampler2DShadow shadowSampler0;
244    #else
245    uniform sampler2D shadowSampler0;
246    #endif
247    uniform mat4 lightMatrix0;
248    #endif
249    #endif
250    #endif
251    #ifdef LIGHT1
252    uniform Light1
253    {
254    vec4 vLightData;
255    vec4 vLightDiffuse;
256    vec3 vLightSpecular;
257    #ifdef SPOTLIGHT1
258    vec4 vLightDirection;
259    #endif
260    #ifdef HEMILIGHT1
261    vec3 vLightGround;
262    #endif
263    vec4 shadowsInfo;
264    vec2 depthValues;
265    } light1;
266    #ifdef PROJECTEDLIGHTTEXTURE1
267    uniform mat4 textureProjectionMatrix1;
268    uniform sampler2D projectionLightSampler1;
269    #endif
270    #ifdef SHADOW1
271    #if defined(SHADOWCUBE1)
272    uniform samplerCube shadowSampler1; 
273    #else
274    out vec4 vPositionFromLight1;
275    out float vDepthMetric1;
276    #if defined(SHADOWPCSS1)
277    uniform highp sampler2DShadow shadowSampler1;
278    uniform highp sampler2D depthSampler1;
279    #elif defined(SHADOWPCF1)
280    uniform highp sampler2DShadow shadowSampler1;
281    #else
282    uniform sampler2D shadowSampler1;
283    #endif
284    uniform mat4 lightMatrix1;
285    #endif
286    #endif
287    #endif
288    #ifdef LIGHT2
289    uniform Light2
290    {
291    vec4 vLightData;
292    vec4 vLightDiffuse;
293    vec3 vLightSpecular;
294    #ifdef SPOTLIGHT2
295    vec4 vLightDirection;
296    #endif
297    #ifdef HEMILIGHT2
298    vec3 vLightGround;
299    #endif
300    vec4 shadowsInfo;
301    vec2 depthValues;
302    } light2;
303    #ifdef PROJECTEDLIGHTTEXTURE2
304    uniform mat4 textureProjectionMatrix2;
305    uniform sampler2D projectionLightSampler2;
306    #endif
307    #ifdef SHADOW2
308    #if defined(SHADOWCUBE2)
309    uniform samplerCube shadowSampler2; 
310    #else
311    out vec4 vPositionFromLight2;
312    out float vDepthMetric2;
313    #if defined(SHADOWPCSS2)
314    uniform highp sampler2DShadow shadowSampler2;
315    uniform highp sampler2D depthSampler2;
316    #elif defined(SHADOWPCF2)
317    uniform highp sampler2DShadow shadowSampler2;
318    #else
319    uniform sampler2D shadowSampler2;
320    #endif
321    uniform mat4 lightMatrix2;
322    #endif
323    #endif
324    #endif
325    #ifdef LIGHT3
326    uniform Light3
327    {
328    vec4 vLightData;
329    vec4 vLightDiffuse;
330    vec3 vLightSpecular;
331    #ifdef SPOTLIGHT3
332    vec4 vLightDirection;
333    #endif
334    #ifdef HEMILIGHT3
335    vec3 vLightGround;
336    #endif
337    vec4 shadowsInfo;
338    vec2 depthValues;
339    } light3;
340    #ifdef PROJECTEDLIGHTTEXTURE3
341    uniform mat4 textureProjectionMatrix3;
342    uniform sampler2D projectionLightSampler3;
343    #endif
344    #ifdef SHADOW3
345    #if defined(SHADOWCUBE3)
346    uniform samplerCube shadowSampler3; 
347    #else
348    out vec4 vPositionFromLight3;
349    out float vDepthMetric3;
350    #if defined(SHADOWPCSS3)
351    uniform highp sampler2DShadow shadowSampler3;
352    uniform highp sampler2D depthSampler3;
353    #elif defined(SHADOWPCF3)
354    uniform highp sampler2DShadow shadowSampler3;
355    #else
356    uniform sampler2D shadowSampler3;
357    #endif
358    uniform mat4 lightMatrix3;
359    #endif
360    #endif
361    #endif
362    
363    #ifdef MORPHTARGETS
364    uniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];
365    #endif
366    
367    #ifdef REFLECTIONMAP_SKYBOX
368    out vec3 vPositionUVW;
369    #endif
370    #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
371    out vec3 vDirectionW;
372    #endif
373    #ifdef LOGARITHMICDEPTH
374    uniform float logarithmicDepthConstant;
375    out float vFragmentDepth;
376    #endif
377    #define CUSTOM_VERTEX_DEFINITIONS
378    void main(void) {
379    #define CUSTOM_VERTEX_MAIN_BEGIN
380    vec3 positionUpdated=position;
381    #ifdef NORMAL 
382    vec3 normalUpdated=normal;
383    #endif
384    #ifdef TANGENT
385    vec4 tangentUpdated=tangent;
386    #endif
387    
388    #ifdef REFLECTIONMAP_SKYBOX
389    vPositionUVW=positionUpdated;
390    #endif 
391    #define CUSTOM_VERTEX_UPDATE_POSITION
392    #define CUSTOM_VERTEX_UPDATE_NORMAL
393    #ifdef INSTANCES
394    mat4 finalWorld=mat4(world0,world1,world2,world3);
395    #else
396    mat4 finalWorld=world;
397    #endif
398    #if NUM_BONE_INFLUENCERS>0
399    mat4 influence;
400    influence=mBones[int(matricesIndices[0])]*matricesWeights[0];
401    #if NUM_BONE_INFLUENCERS>1
402    influence+=mBones[int(matricesIndices[1])]*matricesWeights[1];
403    #endif 
404    #if NUM_BONE_INFLUENCERS>2
405    influence+=mBones[int(matricesIndices[2])]*matricesWeights[2];
406    #endif 
407    #if NUM_BONE_INFLUENCERS>3
408    influence+=mBones[int(matricesIndices[3])]*matricesWeights[3];
409    #endif 
410    #if NUM_BONE_INFLUENCERS>4
411    influence+=mBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];
412    #endif 
413    #if NUM_BONE_INFLUENCERS>5
414    influence+=mBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];
415    #endif 
416    #if NUM_BONE_INFLUENCERS>6
417    influence+=mBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];
418    #endif 
419    #if NUM_BONE_INFLUENCERS>7
420    influence+=mBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];
421    #endif 
422    finalWorld=finalWorld*influence;
423    #endif
424    gl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);
425    vec4 worldPos=finalWorld*vec4(positionUpdated,1.0);
426    vPositionW=vec3(worldPos);
427    #ifdef NORMAL
428    mat3 normalWorld=mat3(finalWorld);
429    #ifdef NONUNIFORMSCALING
430    normalWorld=transposeMat3(inverseMat3(normalWorld));
431    #endif
432    vNormalW=normalize(normalWorld*normalUpdated);
433    #endif
434    #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
435    vDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));
436    #endif
437    
438    #ifndef UV1
439    vec2 uv=vec2(0.,0.);
440    #endif
441    #ifndef UV2
442    vec2 uv2=vec2(0.,0.);
443    #endif
444    #ifdef MAINUV1
445    vMainUV1=uv;
446    #endif
447    #ifdef MAINUV2
448    vMainUV2=uv2;
449    #endif
450    #if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0
451    if (vDiffuseInfos.x == 0.)
452    {
453    vDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));
454    }
455    else
456    {
457    vDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));
458    }
459    #endif
460    #if defined(AMBIENT) && AMBIENTDIRECTUV == 0
461    if (vAmbientInfos.x == 0.)
462    {
463    vAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));
464    }
465    else
466    {
467    vAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));
468    }
469    #endif
470    #if defined(OPACITY) && OPACITYDIRECTUV == 0
471    if (vOpacityInfos.x == 0.)
472    {
473    vOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));
474    }
475    else
476    {
477    vOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));
478    }
479    #endif
480    #if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0
481    if (vEmissiveInfos.x == 0.)
482    {
483    vEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));
484    }
485    else
486    {
487    vEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));
488    }
489    #endif
490    #if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0
491    if (vLightmapInfos.x == 0.)
492    {
493    vLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));
494    }
495    else
496    {
497    vLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));
498    }
499    #endif
500    #if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0
501    if (vSpecularInfos.x == 0.)
502    {
503    vSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));
504    }
505    else
506    {
507    vSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));
508    }
509    #endif
510    #if defined(BUMP) && BUMPDIRECTUV == 0
511    if (vBumpInfos.x == 0.)
512    {
513    vBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));
514    }
515    else
516    {
517    vBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));
518    }
519    #endif
520    #if defined(BUMP) || defined(PARALLAX)
521    #if defined(TANGENT) && defined(NORMAL)
522    vec3 tbnNormal=normalize(normalUpdated);
523    vec3 tbnTangent=normalize(tangentUpdated.xyz);
524    vec3 tbnBitangent=cross(tbnNormal,tbnTangent)*tangentUpdated.w;
525    vTBN=mat3(finalWorld)*mat3(tbnTangent,tbnBitangent,tbnNormal);
526    #endif
527    #endif
528    #ifdef CLIPPLANE
529    fClipDistance=dot(worldPos,vClipPlane);
530    #endif
531    #ifdef FOG
532    vFogDistance=(view*worldPos).xyz;
533    #endif
534    #ifdef SHADOWS
535    #if defined(SHADOW0) && !defined(SHADOWCUBE0)
536    vPositionFromLight0=lightMatrix0*worldPos;
537    vDepthMetric0=((vPositionFromLight0.z+light0.depthValues.x)/(light0.depthValues.y));
538    #endif
539    #endif
540    #ifdef SHADOWS
541    #if defined(SHADOW1) && !defined(SHADOWCUBE1)
542    vPositionFromLight1=lightMatrix1*worldPos;
543    vDepthMetric1=((vPositionFromLight1.z+light1.depthValues.x)/(light1.depthValues.y));
544    #endif
545    #endif
546    #ifdef SHADOWS
547    #if defined(SHADOW2) && !defined(SHADOWCUBE2)
548    vPositionFromLight2=lightMatrix2*worldPos;
549    vDepthMetric2=((vPositionFromLight2.z+light2.depthValues.x)/(light2.depthValues.y));
550    #endif
551    #endif
552    #ifdef SHADOWS
553    #if defined(SHADOW3) && !defined(SHADOWCUBE3)
554    vPositionFromLight3=lightMatrix3*worldPos;
555    vDepthMetric3=((vPositionFromLight3.z+light3.depthValues.x)/(light3.depthValues.y));
556    #endif
557    #endif
558    
559    #ifdef VERTEXCOLOR
560    
561    vColor=color;
562    #endif
563    #ifdef POINTSIZE
564    gl_PointSize=pointSize;
565    #endif
566    #ifdef LOGARITHMICDEPTH
567    vFragmentDepth=1.0+gl_Position.w;
568    gl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;
569    #endif
570    #define CUSTOM_VERTEX_MAIN_END
571    }
572    

 

BJS - [21:02:28]: Fragment shader: default
1    #version 300 es
2    #define WEBGL2 
3    #define DIFFUSEDIRECTUV 0
4    #define AMBIENTDIRECTUV 0
5    #define OPACITYDIRECTUV 0
6    #define EMISSIVEDIRECTUV 0
7    #define SPECULARDIRECTUV 0
8    #define BUMPDIRECTUV 0
9    #define SPECULARTERM
10    #define NORMAL
11    #define NUM_BONE_INFLUENCERS 0
12    #define BonesPerMesh 0
13    #define LIGHTMAPDIRECTUV 0
14    #define SHADOWFLOAT
15    #define NUM_MORPH_INFLUENCERS 0
16    #define VIGNETTEBLENDMODEMULTIPLY
17    #define SAMPLER3DGREENDEPTH
18    #define SAMPLER3DBGRMAP
19    #define LIGHT0
20    #define DIRLIGHT0
21    #define SHADOW0
22    #define SHADOWPCF0
23    #define SHADOWS
24    
25    #define SHADER_NAME fragment:default
26    precision highp float;
27    layout(std140,column_major) uniform;
28    uniform Material
29    {
30    vec4 diffuseLeftColor;
31    vec4 diffuseRightColor;
32    vec4 opacityParts;
33    vec4 reflectionLeftColor;
34    vec4 reflectionRightColor;
35    vec4 refractionLeftColor;
36    vec4 refractionRightColor;
37    vec4 emissiveLeftColor; 
38    vec4 emissiveRightColor;
39    vec2 vDiffuseInfos;
40    vec2 vAmbientInfos;
41    vec2 vOpacityInfos;
42    vec2 vReflectionInfos;
43    vec3 vReflectionPosition;
44    vec3 vReflectionSize;
45    vec2 vEmissiveInfos;
46    vec2 vLightmapInfos;
47    vec2 vSpecularInfos;
48    vec3 vBumpInfos;
49    mat4 diffuseMatrix;
50    mat4 ambientMatrix;
51    mat4 opacityMatrix;
52    mat4 reflectionMatrix;
53    mat4 emissiveMatrix;
54    mat4 lightmapMatrix;
55    mat4 specularMatrix;
56    mat4 bumpMatrix; 
57    vec4 vTangentSpaceParams;
58    mat4 refractionMatrix;
59    vec4 vRefractionInfos;
60    vec4 vSpecularColor;
61    vec3 vEmissiveColor;
62    vec4 vDiffuseColor;
63    float pointSize; 
64    };
65    uniform Scene {
66    mat4 viewProjection;
67    mat4 view;
68    };
69    #if defined(BUMP) || !defined(NORMAL)
70    
71    #endif
72    #define CUSTOM_FRAGMENT_BEGIN
73    #ifdef LOGARITHMICDEPTH
74    
75    #endif
76    
77    #define RECIPROCAL_PI2 0.15915494
78    uniform vec3 vEyePosition;
79    uniform vec3 vAmbientColor;
80    
81    in vec3 vPositionW;
82    #ifdef NORMAL
83    in vec3 vNormalW;
84    #endif
85    #ifdef VERTEXCOLOR
86    in vec4 vColor;
87    #endif
88    #ifdef MAINUV1
89    in vec2 vMainUV1;
90    #endif
91    #ifdef MAINUV2
92    in vec2 vMainUV2;
93    #endif
94    
95    const float PI=3.1415926535897932384626433832795;
96    const float LinearEncodePowerApprox=2.2;
97    const float GammaEncodePowerApprox=1.0/LinearEncodePowerApprox;
98    const vec3 LuminanceEncodeApprox=vec3(0.2126,0.7152,0.0722);
99    mat3 transposeMat3(mat3 inMatrix) {
100    vec3 i0=inMatrix[0];
101    vec3 i1=inMatrix[1];
102    vec3 i2=inMatrix[2];
103    mat3 outMatrix=mat3(
104    vec3(i0.x,i1.x,i2.x),
105    vec3(i0.y,i1.y,i2.y),
106    vec3(i0.z,i1.z,i2.z)
107    );
108    return outMatrix;
109    }
110    
111    mat3 inverseMat3(mat3 inMatrix) {
112    float a00=inMatrix[0][0],a01=inMatrix[0][1],a02=inMatrix[0][2];
113    float a10=inMatrix[1][0],a11=inMatrix[1][1],a12=inMatrix[1][2];
114    float a20=inMatrix[2][0],a21=inMatrix[2][1],a22=inMatrix[2][2];
115    float b01=a22*a11-a12*a21;
116    float b11=-a22*a10+a12*a20;
117    float b21=a21*a10-a11*a20;
118    float det=a00*b01+a01*b11+a02*b21;
119    return mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),
120    b11,(a22*a00-a02*a20),(-a12*a00+a02*a10),
121    b21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;
122    }
123    float computeFallOff(float value,vec2 clipSpace,float frustumEdgeFalloff)
124    {
125    float mask=smoothstep(1.0-frustumEdgeFalloff,1.0,clamp(dot(clipSpace,clipSpace),0.,1.));
126    return mix(value,1.0,mask);
127    }
128    vec3 applyEaseInOut(vec3 x){
129    return x*x*(3.0-2.0*x);
130    }
131    vec3 toLinearSpace(vec3 color)
132    {
133    return pow(color,vec3(LinearEncodePowerApprox));
134    }
135    vec3 toGammaSpace(vec3 color)
136    {
137    return pow(color,vec3(GammaEncodePowerApprox));
138    }
139    float square(float value)
140    {
141    return value*value;
142    }
143    float getLuminance(vec3 color)
144    {
145    return clamp(dot(color,LuminanceEncodeApprox),0.,1.);
146    }
147    
148    float getRand(vec2 seed) {
149    return fract(sin(dot(seed.xy ,vec2(12.9898,78.233)))*43758.5453);
150    }
151    float dither(vec2 seed,float varianceAmount) {
152    float rand=getRand(seed);
153    float dither=mix(-varianceAmount/255.0,varianceAmount/255.0,rand);
154    return dither;
155    }
156    
157    #ifdef LIGHT0
158    uniform Light0
159    {
160    vec4 vLightData;
161    vec4 vLightDiffuse;
162    vec3 vLightSpecular;
163    #ifdef SPOTLIGHT0
164    vec4 vLightDirection;
165    #endif
166    #ifdef HEMILIGHT0
167    vec3 vLightGround;
168    #endif
169    vec4 shadowsInfo;
170    vec2 depthValues;
171    } light0;
172    #ifdef PROJECTEDLIGHTTEXTURE0
173    uniform mat4 textureProjectionMatrix0;
174    uniform sampler2D projectionLightSampler0;
175    #endif
176    #ifdef SHADOW0
177    #if defined(SHADOWCUBE0)
178    uniform samplerCube shadowSampler0; 
179    #else
180    in vec4 vPositionFromLight0;
181    in float vDepthMetric0;
182    #if defined(SHADOWPCSS0)
183    uniform highp sampler2DShadow shadowSampler0;
184    uniform highp sampler2D depthSampler0;
185    #elif defined(SHADOWPCF0)
186    uniform highp sampler2DShadow shadowSampler0;
187    #else
188    uniform sampler2D shadowSampler0;
189    #endif
190    uniform mat4 lightMatrix0;
191    #endif
192    #endif
193    #endif
194    #ifdef LIGHT1
195    uniform Light1
196    {
197    vec4 vLightData;
198    vec4 vLightDiffuse;
199    vec3 vLightSpecular;
200    #ifdef SPOTLIGHT1
201    vec4 vLightDirection;
202    #endif
203    #ifdef HEMILIGHT1
204    vec3 vLightGround;
205    #endif
206    vec4 shadowsInfo;
207    vec2 depthValues;
208    } light1;
209    #ifdef PROJECTEDLIGHTTEXTURE1
210    uniform mat4 textureProjectionMatrix1;
211    uniform sampler2D projectionLightSampler1;
212    #endif
213    #ifdef SHADOW1
214    #if defined(SHADOWCUBE1)
215    uniform samplerCube shadowSampler1; 
216    #else
217    in vec4 vPositionFromLight1;
218    in float vDepthMetric1;
219    #if defined(SHADOWPCSS1)
220    uniform highp sampler2DShadow shadowSampler1;
221    uniform highp sampler2D depthSampler1;
222    #elif defined(SHADOWPCF1)
223    uniform highp sampler2DShadow shadowSampler1;
224    #else
225    uniform sampler2D shadowSampler1;
226    #endif
227    uniform mat4 lightMatrix1;
228    #endif
229    #endif
230    #endif
231    #ifdef LIGHT2
232    uniform Light2
233    {
234    vec4 vLightData;
235    vec4 vLightDiffuse;
236    vec3 vLightSpecular;
237    #ifdef SPOTLIGHT2
238    vec4 vLightDirection;
239    #endif
240    #ifdef HEMILIGHT2
241    vec3 vLightGround;
242    #endif
243    vec4 shadowsInfo;
244    vec2 depthValues;
245    } light2;
246    #ifdef PROJECTEDLIGHTTEXTURE2
247    uniform mat4 textureProjectionMatrix2;
248    uniform sampler2D projectionLightSampler2;
249    #endif
250    #ifdef SHADOW2
251    #if defined(SHADOWCUBE2)
252    uniform samplerCube shadowSampler2; 
253    #else
254    in vec4 vPositionFromLight2;
255    in float vDepthMetric2;
256    #if defined(SHADOWPCSS2)
257    uniform highp sampler2DShadow shadowSampler2;
258    uniform highp sampler2D depthSampler2;
259    #elif defined(SHADOWPCF2)
260    uniform highp sampler2DShadow shadowSampler2;
261    #else
262    uniform sampler2D shadowSampler2;
263    #endif
264    uniform mat4 lightMatrix2;
265    #endif
266    #endif
267    #endif
268    #ifdef LIGHT3
269    uniform Light3
270    {
271    vec4 vLightData;
272    vec4 vLightDiffuse;
273    vec3 vLightSpecular;
274    #ifdef SPOTLIGHT3
275    vec4 vLightDirection;
276    #endif
277    #ifdef HEMILIGHT3
278    vec3 vLightGround;
279    #endif
280    vec4 shadowsInfo;
281    vec2 depthValues;
282    } light3;
283    #ifdef PROJECTEDLIGHTTEXTURE3
284    uniform mat4 textureProjectionMatrix3;
285    uniform sampler2D projectionLightSampler3;
286    #endif
287    #ifdef SHADOW3
288    #if defined(SHADOWCUBE3)
289    uniform samplerCube shadowSampler3; 
290    #else
291    in vec4 vPositionFromLight3;
292    in float vDepthMetric3;
293    #if defined(SHADOWPCSS3)
294    uniform highp sampler2DShadow shadowSampler3;
295    uniform highp sampler2D depthSampler3;
296    #elif defined(SHADOWPCF3)
297    uniform highp sampler2DShadow shadowSampler3;
298    #else
299    uniform sampler2D shadowSampler3;
300    #endif
301    uniform mat4 lightMatrix3;
302    #endif
303    #endif
304    #endif
305    
306    
307    struct lightingInfo
308    {
309    vec3 diffuse;
310    #ifdef SPECULARTERM
311    vec3 specular;
312    #endif
313    #ifdef NDOTL
314    float ndl;
315    #endif
316    };
317    lightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {
318    lightingInfo result;
319    vec3 lightVectorW;
320    float attenuation=1.0;
321    if (lightData.w == 0.)
322    {
323    vec3 direction=lightData.xyz-vPositionW;
324    attenuation=max(0.,1.0-length(direction)/range);
325    lightVectorW=normalize(direction);
326    }
327    else
328    {
329    lightVectorW=normalize(-lightData.xyz);
330    }
331    
332    float ndl=max(0.,dot(vNormal,lightVectorW));
333    #ifdef NDOTL
334    result.ndl=ndl;
335    #endif
336    result.diffuse=ndl*diffuseColor*attenuation;
337    #ifdef SPECULARTERM
338    
339    vec3 angleW=normalize(viewDirectionW+lightVectorW);
340    float specComp=max(0.,dot(vNormal,angleW));
341    specComp=pow(specComp,max(1.,glossiness));
342    result.specular=specComp*specularColor*attenuation;
343    #endif
344    return result;
345    }
346    lightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {
347    lightingInfo result;
348    vec3 direction=lightData.xyz-vPositionW;
349    vec3 lightVectorW=normalize(direction);
350    float attenuation=max(0.,1.0-length(direction)/range);
351    
352    float cosAngle=max(0.,dot(lightDirection.xyz,-lightVectorW));
353    if (cosAngle>=lightDirection.w)
354    {
355    cosAngle=max(0.,pow(cosAngle,lightData.w));
356    attenuation*=cosAngle;
357    
358    float ndl=max(0.,dot(vNormal,lightVectorW));
359    #ifdef NDOTL
360    result.ndl=ndl;
361    #endif
362    result.diffuse=ndl*diffuseColor*attenuation;
363    #ifdef SPECULARTERM
364    
365    vec3 angleW=normalize(viewDirectionW+lightVectorW);
366    float specComp=max(0.,dot(vNormal,angleW));
367    specComp=pow(specComp,max(1.,glossiness));
368    result.specular=specComp*specularColor*attenuation;
369    #endif
370    return result;
371    }
372    result.diffuse=vec3(0.);
373    #ifdef SPECULARTERM
374    result.specular=vec3(0.);
375    #endif
376    #ifdef NDOTL
377    result.ndl=0.;
378    #endif
379    return result;
380    }
381    lightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float glossiness) {
382    lightingInfo result;
383    
384    float ndl=dot(vNormal,lightData.xyz)*0.5+0.5;
385    #ifdef NDOTL
386    result.ndl=ndl;
387    #endif
388    result.diffuse=mix(groundColor,diffuseColor,ndl);
389    #ifdef SPECULARTERM
390    
391    vec3 angleW=normalize(viewDirectionW+lightData.xyz);
392    float specComp=max(0.,dot(vNormal,angleW));
393    specComp=pow(specComp,max(1.,glossiness));
394    result.specular=specComp*specularColor;
395    #endif
396    return result;
397    }
398    vec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler,mat4 textureProjectionMatrix){
399    vec4 strq=textureProjectionMatrix*vec4(vPositionW,1.0);
400    strq/=strq.w;
401    vec3 textureColor=texture(projectionLightSampler,strq.xy).rgb;
402    return textureColor;
403    }
404    #ifdef SHADOWS
405    #ifndef SHADOWFLOAT
406    float unpack(vec4 color)
407    {
408    const vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);
409    return dot(color,bit_shift);
410    }
411    #endif
412    float computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,vec2 depthValues)
413    {
414    vec3 directionToLight=vPositionW-lightPosition;
415    float depth=length(directionToLight);
416    depth=(depth+depthValues.x)/(depthValues.y);
417    depth=clamp(depth,0.,1.0);
418    directionToLight=normalize(directionToLight);
419    directionToLight.y=-directionToLight.y;
420    #ifndef SHADOWFLOAT
421    float shadow=unpack(texture(shadowSampler,directionToLight));
422    #else
423    float shadow=texture(shadowSampler,directionToLight).x;
424    #endif
425    if (depth>shadow)
426    {
427    return darkness;
428    }
429    return 1.0;
430    }
431    float computeShadowWithPoissonSamplingCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float darkness,vec2 depthValues)
432    {
433    vec3 directionToLight=vPositionW-lightPosition;
434    float depth=length(directionToLight);
435    depth=(depth+depthValues.x)/(depthValues.y);
436    depth=clamp(depth,0.,1.0);
437    directionToLight=normalize(directionToLight);
438    directionToLight.y=-directionToLight.y;
439    float visibility=1.;
440    vec3 poissonDisk[4];
441    poissonDisk[0]=vec3(-1.0,1.0,-1.0);
442    poissonDisk[1]=vec3(1.0,-1.0,-1.0);
443    poissonDisk[2]=vec3(-1.0,-1.0,-1.0);
444    poissonDisk[3]=vec3(1.0,-1.0,1.0);
445    
446    #ifndef SHADOWFLOAT
447    if (unpack(texture(shadowSampler,directionToLight+poissonDisk[0]*mapSize))<depth) visibility-=0.25;
448    if (unpack(texture(shadowSampler,directionToLight+poissonDisk[1]*mapSize))<depth) visibility-=0.25;
449    if (unpack(texture(shadowSampler,directionToLight+poissonDisk[2]*mapSize))<depth) visibility-=0.25;
450    if (unpack(texture(shadowSampler,directionToLight+poissonDisk[3]*mapSize))<depth) visibility-=0.25;
451    #else
452    if (texture(shadowSampler,directionToLight+poissonDisk[0]*mapSize).x<depth) visibility-=0.25;
453    if (texture(shadowSampler,directionToLight+poissonDisk[1]*mapSize).x<depth) visibility-=0.25;
454    if (texture(shadowSampler,directionToLight+poissonDisk[2]*mapSize).x<depth) visibility-=0.25;
455    if (texture(shadowSampler,directionToLight+poissonDisk[3]*mapSize).x<depth) visibility-=0.25;
456    #endif
457    return min(1.0,visibility+darkness);
458    }
459    float computeShadowWithESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)
460    {
461    vec3 directionToLight=vPositionW-lightPosition;
462    float depth=length(directionToLight);
463    depth=(depth+depthValues.x)/(depthValues.y);
464    float shadowPixelDepth=clamp(depth,0.,1.0);
465    directionToLight=normalize(directionToLight);
466    directionToLight.y=-directionToLight.y;
467    #ifndef SHADOWFLOAT
468    float shadowMapSample=unpack(texture(shadowSampler,directionToLight));
469    #else
470    float shadowMapSample=texture(shadowSampler,directionToLight).x;
471    #endif
472    float esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness); 
473    return esm;
474    }
475    float computeShadowWithCloseESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)
476    {
477    vec3 directionToLight=vPositionW-lightPosition;
478    float depth=length(directionToLight);
479    depth=(depth+depthValues.x)/(depthValues.y);
480    float shadowPixelDepth=clamp(depth,0.,1.0);
481    directionToLight=normalize(directionToLight);
482    directionToLight.y=-directionToLight.y;
483    #ifndef SHADOWFLOAT
484    float shadowMapSample=unpack(texture(shadowSampler,directionToLight));
485    #else
486    float shadowMapSample=texture(shadowSampler,directionToLight).x;
487    #endif
488    float esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);
489    return esm;
490    }
491    float computeShadow(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float frustumEdgeFalloff)
492    {
493    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
494    vec2 uv=0.5*clipSpace.xy+vec2(0.5);
495    if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)
496    {
497    return 1.0;
498    }
499    float shadowPixelDepth=clamp(depthMetric,0.,1.0);
500    #ifndef SHADOWFLOAT
501    float shadow=unpack(texture(shadowSampler,uv));
502    #else
503    float shadow=texture(shadowSampler,uv).x;
504    #endif
505    if (shadowPixelDepth>shadow)
506    {
507    return computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff);
508    }
509    return 1.;
510    }
511    float computeShadowWithPoissonSampling(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float mapSize,float darkness,float frustumEdgeFalloff)
512    {
513    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
514    vec2 uv=0.5*clipSpace.xy+vec2(0.5);
515    if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)
516    {
517    return 1.0;
518    }
519    float shadowPixelDepth=clamp(depthMetric,0.,1.0);
520    float visibility=1.;
521    vec2 poissonDisk[4];
522    poissonDisk[0]=vec2(-0.94201624,-0.39906216);
523    poissonDisk[1]=vec2(0.94558609,-0.76890725);
524    poissonDisk[2]=vec2(-0.094184101,-0.92938870);
525    poissonDisk[3]=vec2(0.34495938,0.29387760);
526    
527    #ifndef SHADOWFLOAT
528    if (unpack(texture(shadowSampler,uv+poissonDisk[0]*mapSize))<shadowPixelDepth) visibility-=0.25;
529    if (unpack(texture(shadowSampler,uv+poissonDisk[1]*mapSize))<shadowPixelDepth) visibility-=0.25;
530    if (unpack(texture(shadowSampler,uv+poissonDisk[2]*mapSize))<shadowPixelDepth) visibility-=0.25;
531    if (unpack(texture(shadowSampler,uv+poissonDisk[3]*mapSize))<shadowPixelDepth) visibility-=0.25;
532    #else
533    if (texture(shadowSampler,uv+poissonDisk[0]*mapSize).x<shadowPixelDepth) visibility-=0.25;
534    if (texture(shadowSampler,uv+poissonDisk[1]*mapSize).x<shadowPixelDepth) visibility-=0.25;
535    if (texture(shadowSampler,uv+poissonDisk[2]*mapSize).x<shadowPixelDepth) visibility-=0.25;
536    if (texture(shadowSampler,uv+poissonDisk[3]*mapSize).x<shadowPixelDepth) visibility-=0.25;
537    #endif
538    return computeFallOff(min(1.0,visibility+darkness),clipSpace.xy,frustumEdgeFalloff);
539    }
540    float computeShadowWithESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)
541    {
542    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
543    vec2 uv=0.5*clipSpace.xy+vec2(0.5);
544    if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)
545    {
546    return 1.0;
547    }
548    float shadowPixelDepth=clamp(depthMetric,0.,1.0);
549    #ifndef SHADOWFLOAT
550    float shadowMapSample=unpack(texture(shadowSampler,uv));
551    #else
552    float shadowMapSample=texture(shadowSampler,uv).x;
553    #endif
554    float esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);
555    return computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);
556    }
557    float computeShadowWithCloseESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)
558    {
559    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
560    vec2 uv=0.5*clipSpace.xy+vec2(0.5);
561    if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)
562    {
563    return 1.0;
564    }
565    float shadowPixelDepth=clamp(depthMetric,0.,1.0); 
566    #ifndef SHADOWFLOAT
567    float shadowMapSample=unpack(texture(shadowSampler,uv));
568    #else
569    float shadowMapSample=texture(shadowSampler,uv).x;
570    #endif
571    float esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);
572    return computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);
573    }
574    #ifdef WEBGL2
575    
576    float computeShadowWithPCF1(vec4 vPositionFromLight,float depthMetric,sampler2DShadow shadowSampler,float darkness,float frustumEdgeFalloff)
577    {
578    if (depthMetric>1.0 || depthMetric<0.0) {
579    return 1.0;
580    }
581    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
582    vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));
583    float shadow=texture(shadowSampler,uvDepth);
584    shadow=mix(darkness,1.,shadow);
585    return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);
586    }
587    
588    
589    
590    float computeShadowWithPCF3(vec4 vPositionFromLight,float depthMetric,sampler2DShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)
591    {
592    if (depthMetric>1.0 || depthMetric<0.0) {
593    return 1.0;
594    }
595    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
596    vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));
597    vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; 
598    uv+=0.5; 
599    vec2 st=fract(uv); 
600    vec2 base_uv=floor(uv)-0.5; 
601    base_uv*=shadowMapSizeAndInverse.y; 
602    
603    
604    
605    
606    vec2 uvw0=3.-2.*st;
607    vec2 uvw1=1.+2.*st;
608    vec2 u=vec2((2.-st.x)/uvw0.x-1.,st.x/uvw1.x+1.)*shadowMapSizeAndInverse.y;
609    vec2 v=vec2((2.-st.y)/uvw0.y-1.,st.y/uvw1.y+1.)*shadowMapSizeAndInverse.y;
610    float shadow=0.;
611    shadow+=uvw0.x*uvw0.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[0]),uvDepth.z));
612    shadow+=uvw1.x*uvw0.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[0]),uvDepth.z));
613    shadow+=uvw0.x*uvw1.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[1]),uvDepth.z));
614    shadow+=uvw1.x*uvw1.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[1]),uvDepth.z));
615    shadow=shadow/16.;
616    shadow=mix(darkness,1.,shadow);
617    return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);
618    }
619    
620    
621    
622    float computeShadowWithPCF5(vec4 vPositionFromLight,float depthMetric,sampler2DShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)
623    {
624    if (depthMetric>1.0 || depthMetric<0.0) {
625    return 1.0;
626    }
627    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
628    vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));
629    vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; 
630    uv+=0.5; 
631    vec2 st=fract(uv); 
632    vec2 base_uv=floor(uv)-0.5; 
633    base_uv*=shadowMapSizeAndInverse.y; 
634    
635    
636    vec2 uvw0=4.-3.*st;
637    vec2 uvw1=vec2(7.);
638    vec2 uvw2=1.+3.*st;
639    vec3 u=vec3((3.-2.*st.x)/uvw0.x-2.,(3.+st.x)/uvw1.x,st.x/uvw2.x+2.)*shadowMapSizeAndInverse.y;
640    vec3 v=vec3((3.-2.*st.y)/uvw0.y-2.,(3.+st.y)/uvw1.y,st.y/uvw2.y+2.)*shadowMapSizeAndInverse.y;
641    float shadow=0.;
642    shadow+=uvw0.x*uvw0.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[0]),uvDepth.z));
643    shadow+=uvw1.x*uvw0.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[0]),uvDepth.z));
644    shadow+=uvw2.x*uvw0.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[0]),uvDepth.z));
645    shadow+=uvw0.x*uvw1.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[1]),uvDepth.z));
646    shadow+=uvw1.x*uvw1.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[1]),uvDepth.z));
647    shadow+=uvw2.x*uvw1.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[1]),uvDepth.z));
648    shadow+=uvw0.x*uvw2.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[2]),uvDepth.z));
649    shadow+=uvw1.x*uvw2.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[2]),uvDepth.z));
650    shadow+=uvw2.x*uvw2.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[2]),uvDepth.z));
651    shadow=shadow/144.;
652    shadow=mix(darkness,1.,shadow);
653    return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);
654    }
655    const vec3 PoissonSamplers32[64]=vec3[64](
656    vec3(0.06407013,0.05409927,0.),
657    vec3(0.7366577,0.5789394,0.),
658    vec3(-0.6270542,-0.5320278,0.),
659    vec3(-0.4096107,0.8411095,0.),
660    vec3(0.6849564,-0.4990818,0.),
661    vec3(-0.874181,-0.04579735,0.),
662    vec3(0.9989998,0.0009880066,0.),
663    vec3(-0.004920578,-0.9151649,0.),
664    vec3(0.1805763,0.9747483,0.),
665    vec3(-0.2138451,0.2635818,0.),
666    vec3(0.109845,0.3884785,0.),
667    vec3(0.06876755,-0.3581074,0.),
668    vec3(0.374073,-0.7661266,0.),
669    vec3(0.3079132,-0.1216763,0.),
670    vec3(-0.3794335,-0.8271583,0.),
671    vec3(-0.203878,-0.07715034,0.),
672    vec3(0.5912697,0.1469799,0.),
673    vec3(-0.88069,0.3031784,0.),
674    vec3(0.5040108,0.8283722,0.),
675    vec3(-0.5844124,0.5494877,0.),
676    vec3(0.6017799,-0.1726654,0.),
677    vec3(-0.5554981,0.1559997,0.),
678    vec3(-0.3016369,-0.3900928,0.),
679    vec3(-0.5550632,-0.1723762,0.),
680    vec3(0.925029,0.2995041,0.),
681    vec3(-0.2473137,0.5538505,0.),
682    vec3(0.9183037,-0.2862392,0.),
683    vec3(0.2469421,0.6718712,0.),
684    vec3(0.3916397,-0.4328209,0.),
685    vec3(-0.03576927,-0.6220032,0.),
686    vec3(-0.04661255,0.7995201,0.),
687    vec3(0.4402924,0.3640312,0.),
688    vec3(0.,0.,0.),
689    vec3(0.,0.,0.),
690    vec3(0.,0.,0.),
691    vec3(0.,0.,0.),
692    vec3(0.,0.,0.),
693    vec3(0.,0.,0.),
694    vec3(0.,0.,0.),
695    vec3(0.,0.,0.),
696    vec3(0.,0.,0.),
697    vec3(0.,0.,0.),
698    vec3(0.,0.,0.),
699    vec3(0.,0.,0.),
700    vec3(0.,0.,0.),
701    vec3(0.,0.,0.),
702    vec3(0.,0.,0.),
703    vec3(0.,0.,0.),
704    vec3(0.,0.,0.),
705    vec3(0.,0.,0.),
706    vec3(0.,0.,0.),
707    vec3(0.,0.,0.),
708    vec3(0.,0.,0.),
709    vec3(0.,0.,0.),
710    vec3(0.,0.,0.),
711    vec3(0.,0.,0.),
712    vec3(0.,0.,0.),
713    vec3(0.,0.,0.),
714    vec3(0.,0.,0.),
715    vec3(0.,0.,0.),
716    vec3(0.,0.,0.),
717    vec3(0.,0.,0.),
718    vec3(0.,0.,0.),
719    vec3(0.,0.,0.)
720    );
721    const vec3 PoissonSamplers64[64]=vec3[64](
722    vec3(-0.613392,0.617481,0.),
723    vec3(0.170019,-0.040254,0.),
724    vec3(-0.299417,0.791925,0.),
725    vec3(0.645680,0.493210,0.),
726    vec3(-0.651784,0.717887,0.),
727    vec3(0.421003,0.027070,0.),
728    vec3(-0.817194,-0.271096,0.),
729    vec3(-0.705374,-0.668203,0.),
730    vec3(0.977050,-0.108615,0.),
731    vec3(0.063326,0.142369,0.),
732    vec3(0.203528,0.214331,0.),
733    vec3(-0.667531,0.326090,0.),
734    vec3(-0.098422,-0.295755,0.),
735    vec3(-0.885922,0.215369,0.),
736    vec3(0.566637,0.605213,0.),
737    vec3(0.039766,-0.396100,0.),
738    vec3(0.751946,0.453352,0.),
739    vec3(0.078707,-0.715323,0.),
740    vec3(-0.075838,-0.529344,0.),
741    vec3(0.724479,-0.580798,0.),
742    vec3(0.222999,-0.215125,0.),
743    vec3(-0.467574,-0.405438,0.),
744    vec3(-0.248268,-0.814753,0.),
745    vec3(0.354411,-0.887570,0.),
746    vec3(0.175817,0.382366,0.),
747    vec3(0.487472,-0.063082,0.),
748    vec3(-0.084078,0.898312,0.),
749    vec3(0.488876,-0.783441,0.),
750    vec3(0.470016,0.217933,0.),
751    vec3(-0.696890,-0.549791,0.),
752    vec3(-0.149693,0.605762,0.),
753    vec3(0.034211,0.979980,0.),
754    vec3(0.503098,-0.308878,0.),
755    vec3(-0.016205,-0.872921,0.),
756    vec3(0.385784,-0.393902,0.),
757    vec3(-0.146886,-0.859249,0.),
758    vec3(0.643361,0.164098,0.),
759    vec3(0.634388,-0.049471,0.),
760    vec3(-0.688894,0.007843,0.),
761    vec3(0.464034,-0.188818,0.),
762    vec3(-0.440840,0.137486,0.),
763    vec3(0.364483,0.511704,0.),
764    vec3(0.034028,0.325968,0.),
765    vec3(0.099094,-0.308023,0.),
766    vec3(0.693960,-0.366253,0.),
767    vec3(0.678884,-0.204688,0.),
768    vec3(0.001801,0.780328,0.),
769    vec3(0.145177,-0.898984,0.),
770    vec3(0.062655,-0.611866,0.),
771    vec3(0.315226,-0.604297,0.),
772    vec3(-0.780145,0.486251,0.),
773    vec3(-0.371868,0.882138,0.),
774    vec3(0.200476,0.494430,0.),
775    vec3(-0.494552,-0.711051,0.),
776    vec3(0.612476,0.705252,0.),
777    vec3(-0.578845,-0.768792,0.),
778    vec3(-0.772454,-0.090976,0.),
779    vec3(0.504440,0.372295,0.),
780    vec3(0.155736,0.065157,0.),
781    vec3(0.391522,0.849605,0.),
782    vec3(-0.620106,-0.328104,0.),
783    vec3(0.789239,-0.419965,0.),
784    vec3(-0.545396,0.538133,0.),
785    vec3(-0.178564,-0.596057,0.)
786    );
787    
788    
789    
790    
791    
792    float computeShadowWithPCSS(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff,int searchTapCount,int pcfTapCount,vec3[64] poissonSamplers)
793    {
794    if (depthMetric>1.0 || depthMetric<0.0) {
795    return 1.0;
796    }
797    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
798    vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));
799    float blockerDepth=0.0;
800    float sumBlockerDepth=0.0;
801    float numBlocker=0.0;
802    for (int i=0; i<searchTapCount; i ++) {
803    blockerDepth=texture(depthSampler,uvDepth.xy+(lightSizeUV*shadowMapSizeInverse*PoissonSamplers32.xy)).r;
804    if (blockerDepth<depthMetric) {
805    sumBlockerDepth+=blockerDepth;
806    numBlocker++;
807    }
808    }
809    if (numBlocker<1.0) {
810    return 1.0;
811    }
812    float avgBlockerDepth=sumBlockerDepth/numBlocker;
813    
814    float AAOffset=shadowMapSizeInverse*10.;
815    
816    
817    float penumbraRatio=((depthMetric-avgBlockerDepth)+AAOffset);
818    float filterRadius=penumbraRatio*lightSizeUV*shadowMapSizeInverse;
819    float random=getRand(vPositionFromLight.xy);
820    float rotationAngle=random*3.1415926;
821    vec2 rotationVector=vec2(cos(rotationAngle),sin(rotationAngle));
822    float shadow=0.;
823    for (int i=0; i<pcfTapCount; i++) {
824    vec3 offset=poissonSamplers;
825    
826    offset=vec3(offset.x*rotationVector.x-offset.y*rotationVector.y,offset.y*rotationVector.x+offset.x*rotationVector.y,0.);
827    shadow+=texture(shadowSampler,uvDepth+offset*filterRadius);
828    }
829    shadow/=float(pcfTapCount);
830    
831    shadow=mix(shadow,1.,depthMetric-avgBlockerDepth);
832    
833    shadow=mix(darkness,1.,shadow);
834    
835    return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);
836    }
837    float computeShadowWithPCSS16(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff)
838    {
839    return computeShadowWithPCSS(vPositionFromLight,depthMetric,depthSampler,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,16,PoissonSamplers32);
840    }
841    float computeShadowWithPCSS32(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff)
842    {
843    return computeShadowWithPCSS(vPositionFromLight,depthMetric,depthSampler,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,32,PoissonSamplers32);
844    }
845    float computeShadowWithPCSS64(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff)
846    {
847    return computeShadowWithPCSS(vPositionFromLight,depthMetric,depthSampler,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,32,64,PoissonSamplers64);
848    }
849    #endif
850    #endif
851    
852    
853    #ifdef DIFFUSE
854    #if DIFFUSEDIRECTUV == 1
855    #define vDiffuseUV vMainUV1
856    #elif DIFFUSEDIRECTUV == 2
857    #define vDiffuseUV vMainUV2
858    #else
859    in vec2 vDiffuseUV;
860    #endif
861    uniform sampler2D diffuseSampler;
862    #endif
863    #ifdef AMBIENT
864    #if AMBIENTDIRECTUV == 1
865    #define vAmbientUV vMainUV1
866    #elif AMBIENTDIRECTUV == 2
867    #define vAmbientUV vMainUV2
868    #else
869    in vec2 vAmbientUV;
870    #endif
871    uniform sampler2D ambientSampler;
872    #endif
873    #ifdef OPACITY 
874    #if OPACITYDIRECTUV == 1
875    #define vOpacityUV vMainUV1
876    #elif OPACITYDIRECTUV == 2
877    #define vOpacityUV vMainUV2
878    #else
879    in vec2 vOpacityUV;
880    #endif
881    uniform sampler2D opacitySampler;
882    #endif
883    #ifdef EMISSIVE
884    #if EMISSIVEDIRECTUV == 1
885    #define vEmissiveUV vMainUV1
886    #elif EMISSIVEDIRECTUV == 2
887    #define vEmissiveUV vMainUV2
888    #else
889    in vec2 vEmissiveUV;
890    #endif
891    uniform sampler2D emissiveSampler;
892    #endif
893    #ifdef LIGHTMAP
894    #if LIGHTMAPDIRECTUV == 1
895    #define vLightmapUV vMainUV1
896    #elif LIGHTMAPDIRECTUV == 2
897    #define vLightmapUV vMainUV2
898    #else
899    in vec2 vLightmapUV;
900    #endif
901    uniform sampler2D lightmapSampler;
902    #endif
903    #ifdef REFRACTION
904    #ifdef REFRACTIONMAP_3D
905    uniform samplerCube refractionCubeSampler;
906    #else
907    uniform sampler2D refraction2DSampler;
908    #endif
909    #endif
910    #if defined(SPECULAR) && defined(SPECULARTERM)
911    #if SPECULARDIRECTUV == 1
912    #define vSpecularUV vMainUV1
913    #elif SPECULARDIRECTUV == 2
914    #define vSpecularUV vMainUV2
915    #else
916    in vec2 vSpecularUV;
917    #endif
918    uniform sampler2D specularSampler;
919    #endif
920    #ifdef ALPHATEST
921    uniform float alphaCutOff;
922    #endif
923    
924    #ifdef FRESNEL
925    float computeFresnelTerm(vec3 viewDirection,vec3 worldNormal,float bias,float power)
926    {
927    float fresnelTerm=pow(bias+abs(dot(viewDirection,worldNormal)),power);
928    return clamp(fresnelTerm,0.,1.);
929    }
930    #endif
931    
932    #ifdef REFLECTION
933    #ifdef REFLECTIONMAP_3D
934    uniform samplerCube reflectionCubeSampler;
935    #else
936    uniform sampler2D reflection2DSampler;
937    #endif
938    #ifdef REFLECTIONMAP_SKYBOX
939    in vec3 vPositionUVW;
940    #else
941    #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
942    in vec3 vDirectionW;
943    #endif
944    #endif
945    #ifdef USE_LOCAL_REFLECTIONMAP_CUBIC
946    vec3 parallaxCorrectNormal( vec3 vertexPos,vec3 origVec,vec3 cubeSize,vec3 cubePos ) {
947    
948    vec3 invOrigVec=vec3(1.0,1.0,1.0)/origVec;
949    vec3 halfSize=cubeSize*0.5;
950    vec3 intersecAtMaxPlane=(cubePos+halfSize-vertexPos)*invOrigVec;
951    vec3 intersecAtMinPlane=(cubePos-halfSize-vertexPos)*invOrigVec;
952    
953    vec3 largestIntersec=max(intersecAtMaxPlane,intersecAtMinPlane);
954    
955    float distance=min(min(largestIntersec.x,largestIntersec.y),largestIntersec.z);
956    
957    vec3 intersectPositionWS=vertexPos+origVec*distance;
958    
959    return intersectPositionWS-cubePos;
960    }
961    #endif
962    vec3 computeReflectionCoords(vec4 worldPos,vec3 worldNormal)
963    {
964    #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
965    vec3 direction=vDirectionW;
966    float t=clamp(direction.y*-0.5+0.5,0.,1.0);
967    float s=atan(direction.z,direction.x)*RECIPROCAL_PI2+0.5;
968    #ifdef REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED
969    return vec3(1.0-s,t,0);
970    #else
971    return vec3(s,t,0);
972    #endif
973    #endif
974    #ifdef REFLECTIONMAP_EQUIRECTANGULAR
975    vec3 cameraToVertex=normalize(worldPos.xyz-vEyePosition.xyz);
976    vec3 r=reflect(cameraToVertex,worldNormal);
977    float t=clamp(r.y*-0.5+0.5,0.,1.0);
978    float s=atan(r.z,r.x)*RECIPROCAL_PI2+0.5;
979    return vec3(s,t,0);
980    #endif
981    #ifdef REFLECTIONMAP_SPHERICAL
982    vec3 viewDir=normalize(vec3(view*worldPos));
983    vec3 viewNormal=normalize(vec3(view*vec4(worldNormal,0.0)));
984    vec3 r=reflect(viewDir,viewNormal);
985    r.z=r.z-1.0;
986    float m=2.0*length(r);
987    return vec3(r.x/m+0.5,1.0-r.y/m-0.5,0);
988    #endif
989    #ifdef REFLECTIONMAP_PLANAR
990    vec3 viewDir=worldPos.xyz-vEyePosition.xyz;
991    vec3 coords=normalize(reflect(viewDir,worldNormal));
992    return vec3(reflectionMatrix*vec4(coords,1));
993    #endif
994    #ifdef REFLECTIONMAP_CUBIC
995    vec3 viewDir=normalize(worldPos.xyz-vEyePosition.xyz);
996    
997    vec3 coords=reflect(viewDir,worldNormal);
998    #ifdef USE_LOCAL_REFLECTIONMAP_CUBIC
999    coords=parallaxCorrectNormal(worldPos.xyz,coords,vReflectionSize,vReflectionPosition);
1000    #endif
1001    coords=vec3(reflectionMatrix*vec4(coords,0));
1002    #ifdef INVERTCUBICMAP
1003    coords.y*=-1.0;
1004    #endif
1005    return coords;
1006    #endif
1007    #ifdef REFLECTIONMAP_PROJECTION
1008    return vec3(reflectionMatrix*(view*worldPos));
1009    #endif
1010    #ifdef REFLECTIONMAP_SKYBOX
1011    return vPositionUVW;
1012    #endif
1013    #ifdef REFLECTIONMAP_EXPLICIT
1014    return vec3(0,0,0);
1015    #endif
1016    }
1017    #endif
1018    #ifdef EXPOSURE
1019    uniform float exposureLinear;
1020    #endif
1021    #ifdef CONTRAST
1022    uniform float contrast;
1023    #endif
1024    #ifdef VIGNETTE
1025    uniform vec2 vInverseScreenSize;
1026    uniform vec4 vignetteSettings1;
1027    uniform vec4 vignetteSettings2;
1028    #endif
1029    #ifdef COLORCURVES
1030    uniform vec4 vCameraColorCurveNegative;
1031    uniform vec4 vCameraColorCurveNeutral;
1032    uniform vec4 vCameraColorCurvePositive;
1033    #endif
1034    #ifdef COLORGRADING
1035    #ifdef COLORGRADING3D
1036    uniform highp sampler3D txColorTransform;
1037    #else
1038    uniform sampler2D txColorTransform;
1039    #endif
1040    uniform vec4 colorTransformSettings;
1041    #endif
1042    #if defined(COLORGRADING) && !defined(COLORGRADING3D)
1043    
1044    vec3 sampleTexture3D(sampler2D colorTransform,vec3 color,vec2 sampler3dSetting)
1045    {
1046    float sliceSize=2.0*sampler3dSetting.x; 
1047    #ifdef SAMPLER3DGREENDEPTH
1048    float sliceContinuous=(color.g-sampler3dSetting.x)*sampler3dSetting.y;
1049    #else
1050    float sliceContinuous=(color.b-sampler3dSetting.x)*sampler3dSetting.y;
1051    #endif
1052    float sliceInteger=floor(sliceContinuous);
1053    
1054    
1055    float sliceFraction=sliceContinuous-sliceInteger;
1056    #ifdef SAMPLER3DGREENDEPTH
1057    vec2 sliceUV=color.rb;
1058    #else
1059    vec2 sliceUV=color.rg;
1060    #endif
1061    sliceUV.x*=sliceSize;
1062    sliceUV.x+=sliceInteger*sliceSize;
1063    sliceUV=clamp(sliceUV,0.,1.);
1064    vec4 slice0Color=texture(colorTransform,sliceUV);
1065    sliceUV.x+=sliceSize;
1066    sliceUV=clamp(sliceUV,0.,1.);
1067    vec4 slice1Color=texture(colorTransform,sliceUV);
1068    vec3 result=mix(slice0Color.rgb,slice1Color.rgb,sliceFraction);
1069    #ifdef SAMPLER3DBGRMAP
1070    color.rgb=result.rgb;
1071    #else
1072    color.rgb=result.bgr;
1073    #endif
1074    return color;
1075    }
1076    #endif
1077    vec4 applyImageProcessing(vec4 result) {
1078    #ifdef EXPOSURE
1079    result.rgb*=exposureLinear;
1080    #endif
1081    #ifdef VIGNETTE
1082    
1083    vec2 viewportXY=gl_FragCoord.xy*vInverseScreenSize;
1084    viewportXY=viewportXY*2.0-1.0;
1085    vec3 vignetteXY1=vec3(viewportXY*vignetteSettings1.xy+vignetteSettings1.zw,1.0);
1086    float vignetteTerm=dot(vignetteXY1,vignetteXY1);
1087    float vignette=pow(vignetteTerm,vignetteSettings2.w);
1088    
1089    vec3 vignetteColor=vignetteSettings2.rgb;
1090    #ifdef VIGNETTEBLENDMODEMULTIPLY
1091    vec3 vignetteColorMultiplier=mix(vignetteColor,vec3(1,1,1),vignette);
1092    result.rgb*=vignetteColorMultiplier;
1093    #endif
1094    #ifdef VIGNETTEBLENDMODEOPAQUE
1095    result.rgb=mix(vignetteColor,result.rgb,vignette);
1096    #endif
1097    #endif
1098    #ifdef TONEMAPPING
1099    const float tonemappingCalibration=1.590579;
1100    result.rgb=1.0-exp2(-tonemappingCalibration*result.rgb);
1101    #endif
1102    
1103    result.rgb=toGammaSpace(result.rgb);
1104    result.rgb=clamp(result.rgb,0.0,1.0);
1105    #ifdef CONTRAST
1106    
1107    vec3 resultHighContrast=applyEaseInOut(result.rgb);
1108    if (contrast<1.0) {
1109    
1110    result.rgb=mix(vec3(0.5,0.5,0.5),result.rgb,contrast);
1111    } else {
1112    
1113    result.rgb=mix(result.rgb,resultHighContrast,contrast-1.0);
1114    }
1115    #endif
1116    
1117    #ifdef COLORGRADING
1118    vec3 colorTransformInput=result.rgb*colorTransformSettings.xxx+colorTransformSettings.yyy;
1119    #ifdef COLORGRADING3D
1120    vec3 colorTransformOutput=texture(txColorTransform,colorTransformInput).rgb;
1121    #else
1122    vec3 colorTransformOutput=sampleTexture3D(txColorTransform,colorTransformInput,colorTransformSettings.yz).rgb;
1123    #endif
1124    result.rgb=mix(result.rgb,colorTransformOutput,colorTransformSettings.www);
1125    #endif
1126    #ifdef COLORCURVES
1127    
1128    float luma=getLuminance(result.rgb);
1129    vec2 curveMix=clamp(vec2(luma*3.0-1.5,luma*-3.0+1.5),vec2(0.0),vec2(1.0));
1130    vec4 colorCurve=vCameraColorCurveNeutral+curveMix.x*vCameraColorCurvePositive-curveMix.y*vCameraColorCurveNegative;
1131    result.rgb*=colorCurve.rgb;
1132    result.rgb=mix(vec3(luma),result.rgb,colorCurve.a);
1133    #endif
1134    return result;
1135    }
1136    #ifdef BUMP
1137    #if BUMPDIRECTUV == 1
1138    #define vBumpUV vMainUV1
1139    #elif BUMPDIRECTUV == 2
1140    #define vBumpUV vMainUV2
1141    #else
1142    in vec2 vBumpUV;
1143    #endif
1144    uniform sampler2D bumpSampler;
1145    #if defined(TANGENT) && defined(NORMAL) 
1146    in mat3 vTBN;
1147    #endif
1148    #ifdef OBJECTSPACE_NORMALMAP
1149    uniform mat4 normalMatrix;
1150    #endif
1151    
1152    mat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv)
1153    {
1154    
1155    uv=gl_FrontFacing ? uv : -uv;
1156    
1157    vec3 dp1=dFdx(p);
1158    vec3 dp2=dFdy(p);
1159    vec2 duv1=dFdx(uv);
1160    vec2 duv2=dFdy(uv);
1161    
1162    vec3 dp2perp=cross(dp2,normal);
1163    vec3 dp1perp=cross(normal,dp1);
1164    vec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;
1165    vec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;
1166    
1167    tangent*=vTangentSpaceParams.x;
1168    bitangent*=vTangentSpaceParams.y;
1169    
1170    float invmax=inversesqrt(max(dot(tangent,tangent),dot(bitangent,bitangent)));
1171    return mat3(tangent*invmax,bitangent*invmax,normal);
1172    }
1173    vec3 perturbNormal(mat3 cotangentFrame,vec2 uv)
1174    {
1175    vec3 map=texture(bumpSampler,uv).xyz;
1176    map=map*2.0-1.0;
1177    #ifdef NORMALXYSCALE
1178    map=normalize(map*vec3(vBumpInfos.y,vBumpInfos.y,1.0));
1179    #endif
1180    return normalize(cotangentFrame*map);
1181    }
1182    #ifdef PARALLAX
1183    const float minSamples=4.;
1184    const float maxSamples=15.;
1185    const int iMaxSamples=15;
1186    
1187    vec2 parallaxOcclusion(vec3 vViewDirCoT,vec3 vNormalCoT,vec2 texCoord,float parallaxScale) {
1188    float parallaxLimit=length(vViewDirCoT.xy)/vViewDirCoT.z;
1189    parallaxLimit*=parallaxScale;
1190    vec2 vOffsetDir=normalize(vViewDirCoT.xy);
1191    vec2 vMaxOffset=vOffsetDir*parallaxLimit;
1192    float numSamples=maxSamples+(dot(vViewDirCoT,vNormalCoT)*(minSamples-maxSamples));
1193    float stepSize=1.0/numSamples;
1194    
1195    float currRayHeight=1.0;
1196    vec2 vCurrOffset=vec2(0,0);
1197    vec2 vLastOffset=vec2(0,0);
1198    float lastSampledHeight=1.0;
1199    float currSampledHeight=1.0;
1200    for (int i=0; i<iMaxSamples; i++)
1201    {
1202    currSampledHeight=texture(bumpSampler,vBumpUV+vCurrOffset).w;
1203    
1204    if (currSampledHeight>currRayHeight)
1205    {
1206    float delta1=currSampledHeight-currRayHeight;
1207    float delta2=(currRayHeight+stepSize)-lastSampledHeight;
1208    float ratio=delta1/(delta1+delta2);
1209    vCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;
1210    
1211    break;
1212    }
1213    else
1214    {
1215    currRayHeight-=stepSize;
1216    vLastOffset=vCurrOffset;
1217    vCurrOffset+=stepSize*vMaxOffset;
1218    lastSampledHeight=currSampledHeight;
1219    }
1220    }
1221    return vCurrOffset;
1222    }
1223    vec2 parallaxOffset(vec3 viewDir,float heightScale)
1224    {
1225    
1226    float height=texture(bumpSampler,vBumpUV).w;
1227    vec2 texCoordOffset=heightScale*viewDir.xy*height;
1228    return -texCoordOffset;
1229    }
1230    #endif
1231    #endif
1232    #ifdef CLIPPLANE
1233    in float fClipDistance;
1234    #endif
1235    #ifdef LOGARITHMICDEPTH
1236    uniform float logarithmicDepthConstant;
1237    in float vFragmentDepth;
1238    #endif
1239    #ifdef FOG
1240    #define FOGMODE_NONE 0.
1241    #define FOGMODE_EXP 1.
1242    #define FOGMODE_EXP2 2.
1243    #define FOGMODE_LINEAR 3.
1244    #define E 2.71828
1245    uniform vec4 vFogInfos;
1246    uniform vec3 vFogColor;
1247    in vec3 vFogDistance;
1248    float CalcFogFactor()
1249    {
1250    float fogCoeff=1.0;
1251    float fogStart=vFogInfos.y;
1252    float fogEnd=vFogInfos.z;
1253    float fogDensity=vFogInfos.w;
1254    float fogDistance=length(vFogDistance);
1255    if (FOGMODE_LINEAR == vFogInfos.x)
1256    {
1257    fogCoeff=(fogEnd-fogDistance)/(fogEnd-fogStart);
1258    }
1259    else if (FOGMODE_EXP == vFogInfos.x)
1260    {
1261    fogCoeff=1.0/pow(E,fogDistance*fogDensity);
1262    }
1263    else if (FOGMODE_EXP2 == vFogInfos.x)
1264    {
1265    fogCoeff=1.0/pow(E,fogDistance*fogDistance*fogDensity*fogDensity);
1266    }
1267    return clamp(fogCoeff,0.0,1.0);
1268    }
1269    #endif
1270    #define CUSTOM_FRAGMENT_DEFINITIONS
1271    out vec4 glFragColor;
1272    void main(void) {
1273    #define CUSTOM_FRAGMENT_MAIN_BEGIN
1274    #ifdef CLIPPLANE
1275    if (fClipDistance>0.0)
1276    {
1277    discard;
1278    }
1279    #endif
1280    vec3 viewDirectionW=normalize(vEyePosition-vPositionW);
1281    
1282    vec4 baseColor=vec4(1.,1.,1.,1.);
1283    vec3 diffuseColor=vDiffuseColor.rgb;
1284    
1285    float alpha=vDiffuseColor.a;
1286    
1287    #ifdef NORMAL
1288    vec3 normalW=normalize(vNormalW);
1289    #else
1290    vec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));
1291    #endif
1292    vec2 uvOffset=vec2(0.0,0.0);
1293    #if defined(BUMP) || defined(PARALLAX)
1294    #ifdef NORMALXYSCALE
1295    float normalScale=1.0;
1296    #else 
1297    float normalScale=vBumpInfos.y;
1298    #endif
1299    #if defined(TANGENT) && defined(NORMAL)
1300    mat3 TBN=vTBN;
1301    #else
1302    mat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,vBumpUV);
1303    #endif
1304    #endif
1305    #ifdef PARALLAX
1306    mat3 invTBN=transposeMat3(TBN);
1307    #ifdef PARALLAXOCCLUSION
1308    uvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);
1309    #else
1310    uvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);
1311    #endif
1312    #endif
1313    #ifdef BUMP
1314    #ifdef OBJECTSPACE_NORMALMAP
1315    normalW=normalize(texture(bumpSampler,vBumpUV).xyz*2.0-1.0);
1316    normalW=normalize(mat3(normalMatrix)*normalW); 
1317    #else
1318    normalW=perturbNormal(TBN,vBumpUV+uvOffset);
1319    #endif
1320    #endif
1321    #ifdef TWOSIDEDLIGHTING
1322    normalW=gl_FrontFacing ? normalW : -normalW;
1323    #endif
1324    #ifdef DIFFUSE
1325    baseColor=texture(diffuseSampler,vDiffuseUV+uvOffset);
1326    #ifdef ALPHATEST
1327    if (baseColor.a<alphaCutOff)
1328    discard;
1329    #endif
1330    #ifdef ALPHAFROMDIFFUSE
1331    alpha*=baseColor.a;
1332    #endif
1333    #define CUSTOM_FRAGMENT_UPDATE_ALPHA
1334    baseColor.rgb*=vDiffuseInfos.y;
1335    #endif
1336    #ifdef DEPTHPREPASS
1337    glFragColor=vec4(0.,0.,0.,1.0);
1338    return;
1339    #endif
1340    #ifdef VERTEXCOLOR
1341    baseColor.rgb*=vColor.rgb;
1342    #endif
1343    #define CUSTOM_FRAGMENT_UPDATE_DIFFUSE
1344    
1345    vec3 baseAmbientColor=vec3(1.,1.,1.);
1346    #ifdef AMBIENT
1347    baseAmbientColor=texture(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;
1348    #endif
1349    #define CUSTOM_FRAGMENT_BEFORE_LIGHTS
1350    
1351    #ifdef SPECULARTERM
1352    float glossiness=vSpecularColor.a;
1353    vec3 specularColor=vSpecularColor.rgb;
1354    #ifdef SPECULAR
1355    vec4 specularMapColor=texture(specularSampler,vSpecularUV+uvOffset);
1356    specularColor=specularMapColor.rgb;
1357    #ifdef GLOSSINESS
1358    glossiness=glossiness*specularMapColor.a;
1359    #endif
1360    #endif
1361    #else
1362    float glossiness=0.;
1363    #endif
1364    
1365    vec3 diffuseBase=vec3(0.,0.,0.);
1366    lightingInfo info;
1367    #ifdef SPECULARTERM
1368    vec3 specularBase=vec3(0.,0.,0.);
1369    #endif
1370    float shadow=1.;
1371    #ifdef LIGHTMAP
1372    vec3 lightmapColor=texture(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;
1373    #endif
1374    #ifdef LIGHT0
1375    #if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED0) && defined(LIGHTMAPNOSPECULAR0))
1376    
1377    #else
1378    #ifdef PBR
1379    #ifdef SPOTLIGHT0
1380    info=computeSpotLighting(viewDirectionW,normalW,light0.vLightData,light0.vLightDirection,light0.vLightDiffuse.rgb,light0.vLightSpecular,light0.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1381    #endif
1382    #ifdef HEMILIGHT0
1383    info=computeHemisphericLighting(viewDirectionW,normalW,light0.vLightData,light0.vLightDiffuse.rgb,light0.vLightSpecular,light0.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1384    #endif
1385    #if defined(POINTLIGHT0) || defined(DIRLIGHT0)
1386    info=computeLighting(viewDirectionW,normalW,light0.vLightData,light0.vLightDiffuse.rgb,light0.vLightSpecular,light0.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1387    #endif
1388    #else
1389    #ifdef SPOTLIGHT0
1390    info=computeSpotLighting(viewDirectionW,normalW,light0.vLightData,light0.vLightDirection,light0.vLightDiffuse.rgb,light0.vLightSpecular,light0.vLightDiffuse.a,glossiness);
1391    #endif
1392    #ifdef HEMILIGHT0
1393    info=computeHemisphericLighting(viewDirectionW,normalW,light0.vLightData,light0.vLightDiffuse.rgb,light0.vLightSpecular,light0.vLightGround,glossiness);
1394    #endif
1395    #if defined(POINTLIGHT0) || defined(DIRLIGHT0)
1396    info=computeLighting(viewDirectionW,normalW,light0.vLightData,light0.vLightDiffuse.rgb,light0.vLightSpecular,light0.vLightDiffuse.a,glossiness);
1397    #endif
1398    #endif
1399    #ifdef PROJECTEDLIGHTTEXTURE0
1400    info.diffuse*=computeProjectionTextureDiffuseLighting(projectionLightSampler0,textureProjectionMatrix0);
1401    #endif
1402    #endif
1403    #ifdef SHADOW0
1404    #ifdef SHADOWCLOSEESM0
1405    #if defined(SHADOWCUBE0)
1406    shadow=computeShadowWithCloseESMCube(light0.vLightData.xyz,shadowSampler0,light0.shadowsInfo.x,light0.shadowsInfo.z,light0.depthValues);
1407    #else
1408    shadow=computeShadowWithCloseESM(vPositionFromLight0,vDepthMetric0,shadowSampler0,light0.shadowsInfo.x,light0.shadowsInfo.z,light0.shadowsInfo.w);
1409    #endif
1410    #elif defined(SHADOWESM0)
1411    #if defined(SHADOWCUBE0)
1412    shadow=computeShadowWithESMCube(light0.vLightData.xyz,shadowSampler0,light0.shadowsInfo.x,light0.shadowsInfo.z,light0.depthValues);
1413    #else
1414    shadow=computeShadowWithESM(vPositionFromLight0,vDepthMetric0,shadowSampler0,light0.shadowsInfo.x,light0.shadowsInfo.z,light0.shadowsInfo.w);
1415    #endif
1416    #elif defined(SHADOWPOISSON0)
1417    #if defined(SHADOWCUBE0)
1418    shadow=computeShadowWithPoissonSamplingCube(light0.vLightData.xyz,shadowSampler0,light0.shadowsInfo.y,light0.shadowsInfo.x,light0.depthValues);
1419    #else
1420    shadow=computeShadowWithPoissonSampling(vPositionFromLight0,vDepthMetric0,shadowSampler0,light0.shadowsInfo.y,light0.shadowsInfo.x,light0.shadowsInfo.w);
1421    #endif
1422    #elif defined(SHADOWPCF0)
1423    #if defined(SHADOWLOWQUALITY0)
1424    shadow=computeShadowWithPCF1(vPositionFromLight0,vDepthMetric0,shadowSampler0,light0.shadowsInfo.x,light0.shadowsInfo.w);
1425    #elif defined(SHADOWMEDIUMQUALITY0)
1426    shadow=computeShadowWithPCF3(vPositionFromLight0,vDepthMetric0,shadowSampler0,light0.shadowsInfo.yz,light0.shadowsInfo.x,light0.shadowsInfo.w);
1427    #else
1428    shadow=computeShadowWithPCF5(vPositionFromLight0,vDepthMetric0,shadowSampler0,light0.shadowsInfo.yz,light0.shadowsInfo.x,light0.shadowsInfo.w);
1429    #endif
1430    #elif defined(SHADOWPCSS0)
1431    #if defined(SHADOWLOWQUALITY0)
1432    shadow=computeShadowWithPCSS16(vPositionFromLight0,vDepthMetric0,depthSampler0,shadowSampler0,light0.shadowsInfo.y,light0.shadowsInfo.z,light0.shadowsInfo.x,light0.shadowsInfo.w);
1433    #elif defined(SHADOWMEDIUMQUALITY0)
1434    shadow=computeShadowWithPCSS32(vPositionFromLight0,vDepthMetric0,depthSampler0,shadowSampler0,light0.shadowsInfo.y,light0.shadowsInfo.z,light0.shadowsInfo.x,light0.shadowsInfo.w);
1435    #else
1436    shadow=computeShadowWithPCSS64(vPositionFromLight0,vDepthMetric0,depthSampler0,shadowSampler0,light0.shadowsInfo.y,light0.shadowsInfo.z,light0.shadowsInfo.x,light0.shadowsInfo.w);
1437    #endif
1438    #else
1439    #if defined(SHADOWCUBE0)
1440    shadow=computeShadowCube(light0.vLightData.xyz,shadowSampler0,light0.shadowsInfo.x,light0.depthValues);
1441    #else
1442    shadow=computeShadow(vPositionFromLight0,vDepthMetric0,shadowSampler0,light0.shadowsInfo.x,light0.shadowsInfo.w);
1443    #endif
1444    #endif
1445    #ifdef SHADOWONLY
1446    #ifndef SHADOWINUSE
1447    #define SHADOWINUSE
1448    #endif
1449    globalShadow+=shadow;
1450    shadowLightCount+=1.0;
1451    #endif
1452    #else
1453    shadow=1.;
1454    #endif
1455    #ifndef SHADOWONLY
1456    #ifdef CUSTOMUSERLIGHTING
1457    diffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);
1458    #ifdef SPECULARTERM
1459    specularBase+=computeCustomSpecularLighting(info,specularBase,shadow);
1460    #endif
1461    #elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED0)
1462    diffuseBase+=lightmapColor*shadow;
1463    #ifdef SPECULARTERM
1464    #ifndef LIGHTMAPNOSPECULAR0
1465    specularBase+=info.specular*shadow*lightmapColor;
1466    #endif
1467    #endif
1468    #else
1469    diffuseBase+=info.diffuse*shadow;
1470    #ifdef SPECULARTERM
1471    specularBase+=info.specular*shadow;
1472    #endif
1473    #endif
1474    #endif
1475    #endif
1476    #ifdef LIGHT1
1477    #if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED1) && defined(LIGHTMAPNOSPECULAR1))
1478    
1479    #else
1480    #ifdef PBR
1481    #ifdef SPOTLIGHT1
1482    info=computeSpotLighting(viewDirectionW,normalW,light1.vLightData,light1.vLightDirection,light1.vLightDiffuse.rgb,light1.vLightSpecular,light1.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1483    #endif
1484    #ifdef HEMILIGHT1
1485    info=computeHemisphericLighting(viewDirectionW,normalW,light1.vLightData,light1.vLightDiffuse.rgb,light1.vLightSpecular,light1.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1486    #endif
1487    #if defined(POINTLIGHT1) || defined(DIRLIGHT1)
1488    info=computeLighting(viewDirectionW,normalW,light1.vLightData,light1.vLightDiffuse.rgb,light1.vLightSpecular,light1.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1489    #endif
1490    #else
1491    #ifdef SPOTLIGHT1
1492    info=computeSpotLighting(viewDirectionW,normalW,light1.vLightData,light1.vLightDirection,light1.vLightDiffuse.rgb,light1.vLightSpecular,light1.vLightDiffuse.a,glossiness);
1493    #endif
1494    #ifdef HEMILIGHT1
1495    info=computeHemisphericLighting(viewDirectionW,normalW,light1.vLightData,light1.vLightDiffuse.rgb,light1.vLightSpecular,light1.vLightGround,glossiness);
1496    #endif
1497    #if defined(POINTLIGHT1) || defined(DIRLIGHT1)
1498    info=computeLighting(viewDirectionW,normalW,light1.vLightData,light1.vLightDiffuse.rgb,light1.vLightSpecular,light1.vLightDiffuse.a,glossiness);
1499    #endif
1500    #endif
1501    #ifdef PROJECTEDLIGHTTEXTURE1
1502    info.diffuse*=computeProjectionTextureDiffuseLighting(projectionLightSampler1,textureProjectionMatrix1);
1503    #endif
1504    #endif
1505    #ifdef SHADOW1
1506    #ifdef SHADOWCLOSEESM1
1507    #if defined(SHADOWCUBE1)
1508    shadow=computeShadowWithCloseESMCube(light1.vLightData.xyz,shadowSampler1,light1.shadowsInfo.x,light1.shadowsInfo.z,light1.depthValues);
1509    #else
1510    shadow=computeShadowWithCloseESM(vPositionFromLight1,vDepthMetric1,shadowSampler1,light1.shadowsInfo.x,light1.shadowsInfo.z,light1.shadowsInfo.w);
1511    #endif
1512    #elif defined(SHADOWESM1)
1513    #if defined(SHADOWCUBE1)
1514    shadow=computeShadowWithESMCube(light1.vLightData.xyz,shadowSampler1,light1.shadowsInfo.x,light1.shadowsInfo.z,light1.depthValues);
1515    #else
1516    shadow=computeShadowWithESM(vPositionFromLight1,vDepthMetric1,shadowSampler1,light1.shadowsInfo.x,light1.shadowsInfo.z,light1.shadowsInfo.w);
1517    #endif
1518    #elif defined(SHADOWPOISSON1)
1519    #if defined(SHADOWCUBE1)
1520    shadow=computeShadowWithPoissonSamplingCube(light1.vLightData.xyz,shadowSampler1,light1.shadowsInfo.y,light1.shadowsInfo.x,light1.depthValues);
1521    #else
1522    shadow=computeShadowWithPoissonSampling(vPositionFromLight1,vDepthMetric1,shadowSampler1,light1.shadowsInfo.y,light1.shadowsInfo.x,light1.shadowsInfo.w);
1523    #endif
1524    #elif defined(SHADOWPCF1)
1525    #if defined(SHADOWLOWQUALITY1)
1526    shadow=computeShadowWithPCF1(vPositionFromLight1,vDepthMetric1,shadowSampler1,light1.shadowsInfo.x,light1.shadowsInfo.w);
1527    #elif defined(SHADOWMEDIUMQUALITY1)
1528    shadow=computeShadowWithPCF3(vPositionFromLight1,vDepthMetric1,shadowSampler1,light1.shadowsInfo.yz,light1.shadowsInfo.x,light1.shadowsInfo.w);
1529    #else
1530    shadow=computeShadowWithPCF5(vPositionFromLight1,vDepthMetric1,shadowSampler1,light1.shadowsInfo.yz,light1.shadowsInfo.x,light1.shadowsInfo.w);
1531    #endif
1532    #elif defined(SHADOWPCSS1)
1533    #if defined(SHADOWLOWQUALITY1)
1534    shadow=computeShadowWithPCSS16(vPositionFromLight1,vDepthMetric1,depthSampler1,shadowSampler1,light1.shadowsInfo.y,light1.shadowsInfo.z,light1.shadowsInfo.x,light1.shadowsInfo.w);
1535    #elif defined(SHADOWMEDIUMQUALITY1)
1536    shadow=computeShadowWithPCSS32(vPositionFromLight1,vDepthMetric1,depthSampler1,shadowSampler1,light1.shadowsInfo.y,light1.shadowsInfo.z,light1.shadowsInfo.x,light1.shadowsInfo.w);
1537    #else
1538    shadow=computeShadowWithPCSS64(vPositionFromLight1,vDepthMetric1,depthSampler1,shadowSampler1,light1.shadowsInfo.y,light1.shadowsInfo.z,light1.shadowsInfo.x,light1.shadowsInfo.w);
1539    #endif
1540    #else
1541    #if defined(SHADOWCUBE1)
1542    shadow=computeShadowCube(light1.vLightData.xyz,shadowSampler1,light1.shadowsInfo.x,light1.depthValues);
1543    #else
1544    shadow=computeShadow(vPositionFromLight1,vDepthMetric1,shadowSampler1,light1.shadowsInfo.x,light1.shadowsInfo.w);
1545    #endif
1546    #endif
1547    #ifdef SHADOWONLY
1548    #ifndef SHADOWINUSE
1549    #define SHADOWINUSE
1550    #endif
1551    globalShadow+=shadow;
1552    shadowLightCount+=1.0;
1553    #endif
1554    #else
1555    shadow=1.;
1556    #endif
1557    #ifndef SHADOWONLY
1558    #ifdef CUSTOMUSERLIGHTING
1559    diffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);
1560    #ifdef SPECULARTERM
1561    specularBase+=computeCustomSpecularLighting(info,specularBase,shadow);
1562    #endif
1563    #elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED1)
1564    diffuseBase+=lightmapColor*shadow;
1565    #ifdef SPECULARTERM
1566    #ifndef LIGHTMAPNOSPECULAR1
1567    specularBase+=info.specular*shadow*lightmapColor;
1568    #endif
1569    #endif
1570    #else
1571    diffuseBase+=info.diffuse*shadow;
1572    #ifdef SPECULARTERM
1573    specularBase+=info.specular*shadow;
1574    #endif
1575    #endif
1576    #endif
1577    #endif
1578    #ifdef LIGHT2
1579    #if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED2) && defined(LIGHTMAPNOSPECULAR2))
1580    
1581    #else
1582    #ifdef PBR
1583    #ifdef SPOTLIGHT2
1584    info=computeSpotLighting(viewDirectionW,normalW,light2.vLightData,light2.vLightDirection,light2.vLightDiffuse.rgb,light2.vLightSpecular,light2.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1585    #endif
1586    #ifdef HEMILIGHT2
1587    info=computeHemisphericLighting(viewDirectionW,normalW,light2.vLightData,light2.vLightDiffuse.rgb,light2.vLightSpecular,light2.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1588    #endif
1589    #if defined(POINTLIGHT2) || defined(DIRLIGHT2)
1590    info=computeLighting(viewDirectionW,normalW,light2.vLightData,light2.vLightDiffuse.rgb,light2.vLightSpecular,light2.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1591    #endif
1592    #else
1593    #ifdef SPOTLIGHT2
1594    info=computeSpotLighting(viewDirectionW,normalW,light2.vLightData,light2.vLightDirection,light2.vLightDiffuse.rgb,light2.vLightSpecular,light2.vLightDiffuse.a,glossiness);
1595    #endif
1596    #ifdef HEMILIGHT2
1597    info=computeHemisphericLighting(viewDirectionW,normalW,light2.vLightData,light2.vLightDiffuse.rgb,light2.vLightSpecular,light2.vLightGround,glossiness);
1598    #endif
1599    #if defined(POINTLIGHT2) || defined(DIRLIGHT2)
1600    info=computeLighting(viewDirectionW,normalW,light2.vLightData,light2.vLightDiffuse.rgb,light2.vLightSpecular,light2.vLightDiffuse.a,glossiness);
1601    #endif
1602    #endif
1603    #ifdef PROJECTEDLIGHTTEXTURE2
1604    info.diffuse*=computeProjectionTextureDiffuseLighting(projectionLightSampler2,textureProjectionMatrix2);
1605    #endif
1606    #endif
1607    #ifdef SHADOW2
1608    #ifdef SHADOWCLOSEESM2
1609    #if defined(SHADOWCUBE2)
1610    shadow=computeShadowWithCloseESMCube(light2.vLightData.xyz,shadowSampler2,light2.shadowsInfo.x,light2.shadowsInfo.z,light2.depthValues);
1611    #else
1612    shadow=computeShadowWithCloseESM(vPositionFromLight2,vDepthMetric2,shadowSampler2,light2.shadowsInfo.x,light2.shadowsInfo.z,light2.shadowsInfo.w);
1613    #endif
1614    #elif defined(SHADOWESM2)
1615    #if defined(SHADOWCUBE2)
1616    shadow=computeShadowWithESMCube(light2.vLightData.xyz,shadowSampler2,light2.shadowsInfo.x,light2.shadowsInfo.z,light2.depthValues);
1617    #else
1618    shadow=computeShadowWithESM(vPositionFromLight2,vDepthMetric2,shadowSampler2,light2.shadowsInfo.x,light2.shadowsInfo.z,light2.shadowsInfo.w);
1619    #endif
1620    #elif defined(SHADOWPOISSON2)
1621    #if defined(SHADOWCUBE2)
1622    shadow=computeShadowWithPoissonSamplingCube(light2.vLightData.xyz,shadowSampler2,light2.shadowsInfo.y,light2.shadowsInfo.x,light2.depthValues);
1623    #else
1624    shadow=computeShadowWithPoissonSampling(vPositionFromLight2,vDepthMetric2,shadowSampler2,light2.shadowsInfo.y,light2.shadowsInfo.x,light2.shadowsInfo.w);
1625    #endif
1626    #elif defined(SHADOWPCF2)
1627    #if defined(SHADOWLOWQUALITY2)
1628    shadow=computeShadowWithPCF1(vPositionFromLight2,vDepthMetric2,shadowSampler2,light2.shadowsInfo.x,light2.shadowsInfo.w);
1629    #elif defined(SHADOWMEDIUMQUALITY2)
1630    shadow=computeShadowWithPCF3(vPositionFromLight2,vDepthMetric2,shadowSampler2,light2.shadowsInfo.yz,light2.shadowsInfo.x,light2.shadowsInfo.w);
1631    #else
1632    shadow=computeShadowWithPCF5(vPositionFromLight2,vDepthMetric2,shadowSampler2,light2.shadowsInfo.yz,light2.shadowsInfo.x,light2.shadowsInfo.w);
1633    #endif
1634    #elif defined(SHADOWPCSS2)
1635    #if defined(SHADOWLOWQUALITY2)
1636    shadow=computeShadowWithPCSS16(vPositionFromLight2,vDepthMetric2,depthSampler2,shadowSampler2,light2.shadowsInfo.y,light2.shadowsInfo.z,light2.shadowsInfo.x,light2.shadowsInfo.w);
1637    #elif defined(SHADOWMEDIUMQUALITY2)
1638    shadow=computeShadowWithPCSS32(vPositionFromLight2,vDepthMetric2,depthSampler2,shadowSampler2,light2.shadowsInfo.y,light2.shadowsInfo.z,light2.shadowsInfo.x,light2.shadowsInfo.w);
1639    #else
1640    shadow=computeShadowWithPCSS64(vPositionFromLight2,vDepthMetric2,depthSampler2,shadowSampler2,light2.shadowsInfo.y,light2.shadowsInfo.z,light2.shadowsInfo.x,light2.shadowsInfo.w);
1641    #endif
1642    #else
1643    #if defined(SHADOWCUBE2)
1644    shadow=computeShadowCube(light2.vLightData.xyz,shadowSampler2,light2.shadowsInfo.x,light2.depthValues);
1645    #else
1646    shadow=computeShadow(vPositionFromLight2,vDepthMetric2,shadowSampler2,light2.shadowsInfo.x,light2.shadowsInfo.w);
1647    #endif
1648    #endif
1649    #ifdef SHADOWONLY
1650    #ifndef SHADOWINUSE
1651    #define SHADOWINUSE
1652    #endif
1653    globalShadow+=shadow;
1654    shadowLightCount+=1.0;
1655    #endif
1656    #else
1657    shadow=1.;
1658    #endif
1659    #ifndef SHADOWONLY
1660    #ifdef CUSTOMUSERLIGHTING
1661    diffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);
1662    #ifdef SPECULARTERM
1663    specularBase+=computeCustomSpecularLighting(info,specularBase,shadow);
1664    #endif
1665    #elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED2)
1666    diffuseBase+=lightmapColor*shadow;
1667    #ifdef SPECULARTERM
1668    #ifndef LIGHTMAPNOSPECULAR2
1669    specularBase+=info.specular*shadow*lightmapColor;
1670    #endif
1671    #endif
1672    #else
1673    diffuseBase+=info.diffuse*shadow;
1674    #ifdef SPECULARTERM
1675    specularBase+=info.specular*shadow;
1676    #endif
1677    #endif
1678    #endif
1679    #endif
1680    #ifdef LIGHT3
1681    #if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED3) && defined(LIGHTMAPNOSPECULAR3))
1682    
1683    #else
1684    #ifdef PBR
1685    #ifdef SPOTLIGHT3
1686    info=computeSpotLighting(viewDirectionW,normalW,light3.vLightData,light3.vLightDirection,light3.vLightDiffuse.rgb,light3.vLightSpecular,light3.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1687    #endif
1688    #ifdef HEMILIGHT3
1689    info=computeHemisphericLighting(viewDirectionW,normalW,light3.vLightData,light3.vLightDiffuse.rgb,light3.vLightSpecular,light3.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1690    #endif
1691    #if defined(POINTLIGHT3) || defined(DIRLIGHT3)
1692    info=computeLighting(viewDirectionW,normalW,light3.vLightData,light3.vLightDiffuse.rgb,light3.vLightSpecular,light3.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1693    #endif
1694    #else
1695    #ifdef SPOTLIGHT3
1696    info=computeSpotLighting(viewDirectionW,normalW,light3.vLightData,light3.vLightDirection,light3.vLightDiffuse.rgb,light3.vLightSpecular,light3.vLightDiffuse.a,glossiness);
1697    #endif
1698    #ifdef HEMILIGHT3
1699    info=computeHemisphericLighting(viewDirectionW,normalW,light3.vLightData,light3.vLightDiffuse.rgb,light3.vLightSpecular,light3.vLightGround,glossiness);
1700    #endif
1701    #if defined(POINTLIGHT3) || defined(DIRLIGHT3)
1702    info=computeLighting(viewDirectionW,normalW,light3.vLightData,light3.vLightDiffuse.rgb,light3.vLightSpecular,light3.vLightDiffuse.a,glossiness);
1703    #endif
1704    #endif
1705    #ifdef PROJECTEDLIGHTTEXTURE3
1706    info.diffuse*=computeProjectionTextureDiffuseLighting(projectionLightSampler3,textureProjectionMatrix3);
1707    #endif
1708    #endif
1709    #ifdef SHADOW3
1710    #ifdef SHADOWCLOSEESM3
1711    #if defined(SHADOWCUBE3)
1712    shadow=computeShadowWithCloseESMCube(light3.vLightData.xyz,shadowSampler3,light3.shadowsInfo.x,light3.shadowsInfo.z,light3.depthValues);
1713    #else
1714    shadow=computeShadowWithCloseESM(vPositionFromLight3,vDepthMetric3,shadowSampler3,light3.shadowsInfo.x,light3.shadowsInfo.z,light3.shadowsInfo.w);
1715    #endif
1716    #elif defined(SHADOWESM3)
1717    #if defined(SHADOWCUBE3)
1718    shadow=computeShadowWithESMCube(light3.vLightData.xyz,shadowSampler3,light3.shadowsInfo.x,light3.shadowsInfo.z,light3.depthValues);
1719    #else
1720    shadow=computeShadowWithESM(vPositionFromLight3,vDepthMetric3,shadowSampler3,light3.shadowsInfo.x,light3.shadowsInfo.z,light3.shadowsInfo.w);
1721    #endif
1722    #elif defined(SHADOWPOISSON3)
1723    #if defined(SHADOWCUBE3)
1724    shadow=computeShadowWithPoissonSamplingCube(light3.vLightData.xyz,shadowSampler3,light3.shadowsInfo.y,light3.shadowsInfo.x,light3.depthValues);
1725    #else
1726    shadow=computeShadowWithPoissonSampling(vPositionFromLight3,vDepthMetric3,shadowSampler3,light3.shadowsInfo.y,light3.shadowsInfo.x,light3.shadowsInfo.w);
1727    #endif
1728    #elif defined(SHADOWPCF3)
1729    #if defined(SHADOWLOWQUALITY3)
1730    shadow=computeShadowWithPCF1(vPositionFromLight3,vDepthMetric3,shadowSampler3,light3.shadowsInfo.x,light3.shadowsInfo.w);
1731    #elif defined(SHADOWMEDIUMQUALITY3)
1732    shadow=computeShadowWithPCF3(vPositionFromLight3,vDepthMetric3,shadowSampler3,light3.shadowsInfo.yz,light3.shadowsInfo.x,light3.shadowsInfo.w);
1733    #else
1734    shadow=computeShadowWithPCF5(vPositionFromLight3,vDepthMetric3,shadowSampler3,light3.shadowsInfo.yz,light3.shadowsInfo.x,light3.shadowsInfo.w);
1735    #endif
1736    #elif defined(SHADOWPCSS3)
1737    #if defined(SHADOWLOWQUALITY3)
1738    shadow=computeShadowWithPCSS16(vPositionFromLight3,vDepthMetric3,depthSampler3,shadowSampler3,light3.shadowsInfo.y,light3.shadowsInfo.z,light3.shadowsInfo.x,light3.shadowsInfo.w);
1739    #elif defined(SHADOWMEDIUMQUALITY3)
1740    shadow=computeShadowWithPCSS32(vPositionFromLight3,vDepthMetric3,depthSampler3,shadowSampler3,light3.shadowsInfo.y,light3.shadowsInfo.z,light3.shadowsInfo.x,light3.shadowsInfo.w);
1741    #else
1742    shadow=computeShadowWithPCSS64(vPositionFromLight3,vDepthMetric3,depthSampler3,shadowSampler3,light3.shadowsInfo.y,light3.shadowsInfo.z,light3.shadowsInfo.x,light3.shadowsInfo.w);
1743    #endif
1744    #else
1745    #if defined(SHADOWCUBE3)
1746    shadow=computeShadowCube(light3.vLightData.xyz,shadowSampler3,light3.shadowsInfo.x,light3.depthValues);
1747    #else
1748    shadow=computeShadow(vPositionFromLight3,vDepthMetric3,shadowSampler3,light3.shadowsInfo.x,light3.shadowsInfo.w);
1749    #endif
1750    #endif
1751    #ifdef SHADOWONLY
1752    #ifndef SHADOWINUSE
1753    #define SHADOWINUSE
1754    #endif
1755    globalShadow+=shadow;
1756    shadowLightCount+=1.0;
1757    #endif
1758    #else
1759    shadow=1.;
1760    #endif
1761    #ifndef SHADOWONLY
1762    #ifdef CUSTOMUSERLIGHTING
1763    diffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);
1764    #ifdef SPECULARTERM
1765    specularBase+=computeCustomSpecularLighting(info,specularBase,shadow);
1766    #endif
1767    #elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED3)
1768    diffuseBase+=lightmapColor*shadow;
1769    #ifdef SPECULARTERM
1770    #ifndef LIGHTMAPNOSPECULAR3
1771    specularBase+=info.specular*shadow*lightmapColor;
1772    #endif
1773    #endif
1774    #else
1775    diffuseBase+=info.diffuse*shadow;
1776    #ifdef SPECULARTERM
1777    specularBase+=info.specular*shadow;
1778    #endif
1779    #endif
1780    #endif
1781    #endif
1782    
1783    
1784    vec3 refractionColor=vec3(0.,0.,0.);
1785    #ifdef REFRACTION
1786    vec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));
1787    #ifdef REFRACTIONMAP_3D
1788    refractionVector.y=refractionVector.y*vRefractionInfos.w;
1789    if (dot(refractionVector,viewDirectionW)<1.0) {
1790    refractionColor=texture(refractionCubeSampler,refractionVector).rgb;
1791    }
1792    #else
1793    vec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));
1794    vec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;
1795    refractionCoords.y=1.0-refractionCoords.y;
1796    refractionColor=texture(refraction2DSampler,refractionCoords).rgb;
1797    #endif
1798    #ifdef IS_REFRACTION_LINEAR
1799    refractionColor=toGammaSpace(refractionColor);
1800    #endif
1801    refractionColor*=vRefractionInfos.x;
1802    #endif
1803    
1804    vec3 reflectionColor=vec3(0.,0.,0.);
1805    #ifdef REFLECTION
1806    vec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);
1807    #ifdef REFLECTIONMAP_3D
1808    #ifdef ROUGHNESS
1809    float bias=vReflectionInfos.y;
1810    #ifdef SPECULARTERM
1811    #ifdef SPECULAR
1812    #ifdef GLOSSINESS
1813    bias*=(1.0-specularMapColor.a);
1814    #endif
1815    #endif
1816    #endif
1817    reflectionColor=texture(reflectionCubeSampler,vReflectionUVW,bias).rgb;
1818    #else
1819    reflectionColor=texture(reflectionCubeSampler,vReflectionUVW).rgb;
1820    #endif
1821    #else
1822    vec2 coords=vReflectionUVW.xy;
1823    #ifdef REFLECTIONMAP_PROJECTION
1824    coords/=vReflectionUVW.z;
1825    #endif
1826    coords.y=1.0-coords.y;
1827    reflectionColor=texture(reflection2DSampler,coords).rgb;
1828    #endif
1829    #ifdef IS_REFLECTION_LINEAR
1830    reflectionColor=toGammaSpace(reflectionColor);
1831    #endif
1832    reflectionColor*=vReflectionInfos.x;
1833    #ifdef REFLECTIONFRESNEL
1834    float reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);
1835    #ifdef REFLECTIONFRESNELFROMSPECULAR
1836    #ifdef SPECULARTERM
1837    reflectionColor*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;
1838    #else
1839    reflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;
1840    #endif
1841    #else
1842    reflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;
1843    #endif
1844    #endif
1845    #endif
1846    #ifdef REFRACTIONFRESNEL
1847    float refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);
1848    refractionColor*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;
1849    #endif
1850    #ifdef OPACITY
1851    vec4 opacityMap=texture(opacitySampler,vOpacityUV+uvOffset);
1852    #ifdef OPACITYRGB
1853    opacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);
1854    alpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;
1855    #else
1856    alpha*=opacityMap.a*vOpacityInfos.y;
1857    #endif
1858    #endif
1859    #ifdef VERTEXALPHA
1860    alpha*=vColor.a;
1861    #endif
1862    #ifdef OPACITYFRESNEL
1863    float opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);
1864    alpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;
1865    #endif
1866    
1867    vec3 emissiveColor=vEmissiveColor;
1868    #ifdef EMISSIVE
1869    emissiveColor+=texture(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;
1870    #endif
1871    #ifdef EMISSIVEFRESNEL
1872    float emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);
1873    emissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;
1874    #endif
1875    
1876    #ifdef DIFFUSEFRESNEL
1877    float diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);
1878    diffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;
1879    #endif
1880    
1881    #ifdef EMISSIVEASILLUMINATION
1882    vec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;
1883    #else
1884    #ifdef LINKEMISSIVEWITHDIFFUSE
1885    vec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;
1886    #else
1887    vec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;
1888    #endif
1889    #endif
1890    #ifdef SPECULARTERM
1891    vec3 finalSpecular=specularBase*specularColor;
1892    #ifdef SPECULAROVERALPHA
1893    alpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);
1894    #endif
1895    #else
1896    vec3 finalSpecular=vec3(0.0);
1897    #endif
1898    #ifdef REFLECTIONOVERALPHA
1899    alpha=clamp(alpha+dot(reflectionColor,vec3(0.3,0.59,0.11)),0.,1.);
1900    #endif
1901    
1902    #ifdef EMISSIVEASILLUMINATION
1903    vec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+emissiveColor+refractionColor,0.0,1.0),alpha);
1904    #else
1905    vec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+refractionColor,alpha);
1906    #endif
1907    
1908    #ifdef LIGHTMAP
1909    #ifndef LIGHTMAPEXCLUDED
1910    #ifdef USELIGHTMAPASSHADOWMAP
1911    color.rgb*=lightmapColor;
1912    #else
1913    color.rgb+=lightmapColor;
1914    #endif
1915    #endif
1916    #endif
1917    #define CUSTOM_FRAGMENT_BEFORE_FOG
1918    color.rgb=max(color.rgb,0.);
1919    #ifdef LOGARITHMICDEPTH
1920    gl_FragDepth=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;
1921    #endif
1922    #ifdef FOG
1923    float fog=CalcFogFactor();
1924    color.rgb=fog*color.rgb+(1.0-fog)*vFogColor;
1925    #endif
1926    
1927    
1928    #ifdef IMAGEPROCESSINGPOSTPROCESS
1929    color.rgb=toLinearSpace(color.rgb);
1930    #else
1931    #ifdef IMAGEPROCESSING
1932    color.rgb=toLinearSpace(color.rgb);
1933    color=applyImageProcessing(color);
1934    #endif
1935    #endif
1936    #ifdef PREMULTIPLYALPHA
1937    
1938    color.rgb*=color.a;
1939    #endif
1940    #define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR
1941    glFragColor=color;
1942    }
1943    

 

BJS - [21:02:28]: Error: 0:87: S0032: no default precision defined for parameter 'webgl_4aeb46af4241331f'
  t._ErrorEnabled @

babylon.js:

BJS - [21:02:28]: Trying next fallback.

BJS - [21:02:28]: Unable to compile effect:

BJS - [21:02:28]: Uniforms:  world, view, viewProjection, vEyePosition, vLightsType, vAmbientColor, vDiffuseColor, vSpecularColor, vEmissiveColor, vFogInfos, vFogColor, pointSize, vDiffuseInfos, vAmbientInfos, vOpacityInfos, vReflectionInfos, vEmissiveInfos, vSpecularInfos, vBumpInfos, vLightmapInfos, vRefractionInfos, mBones, vClipPlane, diffuseMatrix, ambientMatrix, opacityMatrix, reflectionMatrix, emissiveMatrix, specularMatrix, bumpMatrix, normalMatrix, lightmapMatrix, refractionMatrix, diffuseLeftColor, diffuseRightColor, opacityParts, reflectionLeftColor, reflectionRightColor, emissiveLeftColor, emissiveRightColor, refractionLeftColor, refractionRightColor, vReflectionPosition, vReflectionSize, logarithmicDepthConstant, vTangentSpaceParams, alphaCutOff, vLightData0, vLightDiffuse0, vLightSpecular0, vLightDirection0, vLightGround0, lightMatrix0, shadowsInfo0, depthValues0, diffuseSampler, ambientSampler, opacitySampler, reflectionCubeSampler, reflection2DSampler, emissiveSampler, specularSampler, bumpSampler, lightmapSampler, refractionCubeSampler, refraction2DSampler, shadowSampler0, depthSampler0

BJS - [21:02:28]: Attributes:  position, normal

BJS - [21:02:28]: Vertex shader: default
1    #version 300 es
2    #define WEBGL2 
3    #define DIFFUSEDIRECTUV 0
4    #define AMBIENTDIRECTUV 0
5    #define OPACITYDIRECTUV 0
6    #define EMISSIVEDIRECTUV 0
7    #define SPECULARDIRECTUV 0
8    #define BUMPDIRECTUV 0
9    
10    #define NORMAL
11    #define NUM_BONE_INFLUENCERS 0
12    #define BonesPerMesh 0
13    #define LIGHTMAPDIRECTUV 0
14    #define SHADOWFLOAT
15    #define NUM_MORPH_INFLUENCERS 0
16    #define VIGNETTEBLENDMODEMULTIPLY
17    #define SAMPLER3DGREENDEPTH
18    #define SAMPLER3DBGRMAP
19    #define LIGHT0
20    #define DIRLIGHT0
21    #define SHADOW0
22    #define SHADOWPCF0
23    #define SHADOWS
24    
25    #define SHADER_NAME vertex:default
26    precision highp float;
27    layout(std140,column_major) uniform;
28    uniform Material
29    {
30    vec4 diffuseLeftColor;
31    vec4 diffuseRightColor;
32    vec4 opacityParts;
33    vec4 reflectionLeftColor;
34    vec4 reflectionRightColor;
35    vec4 refractionLeftColor;
36    vec4 refractionRightColor;
37    vec4 emissiveLeftColor; 
38    vec4 emissiveRightColor;
39    vec2 vDiffuseInfos;
40    vec2 vAmbientInfos;
41    vec2 vOpacityInfos;
42    vec2 vReflectionInfos;
43    vec3 vReflectionPosition;
44    vec3 vReflectionSize;
45    vec2 vEmissiveInfos;
46    vec2 vLightmapInfos;
47    vec2 vSpecularInfos;
48    vec3 vBumpInfos;
49    mat4 diffuseMatrix;
50    mat4 ambientMatrix;
51    mat4 opacityMatrix;
52    mat4 reflectionMatrix;
53    mat4 emissiveMatrix;
54    mat4 lightmapMatrix;
55    mat4 specularMatrix;
56    mat4 bumpMatrix; 
57    vec4 vTangentSpaceParams;
58    mat4 refractionMatrix;
59    vec4 vRefractionInfos;
60    vec4 vSpecularColor;
61    vec3 vEmissiveColor;
62    vec4 vDiffuseColor;
63    float pointSize; 
64    };
65    uniform Scene {
66    mat4 viewProjection;
67    mat4 view;
68    };
69    
70    #define CUSTOM_VERTEX_BEGIN
71    in vec3 position;
72    #ifdef NORMAL
73    in vec3 normal;
74    #endif
75    #ifdef TANGENT
76    in vec4 tangent;
77    #endif
78    #ifdef UV1
79    in vec2 uv;
80    #endif
81    #ifdef UV2
82    in vec2 uv2;
83    #endif
84    #ifdef VERTEXCOLOR
85    in vec4 color;
86    #endif
87    const float PI=3.1415926535897932384626433832795;
88    const float LinearEncodePowerApprox=2.2;
89    const float GammaEncodePowerApprox=1.0/LinearEncodePowerApprox;
90    const vec3 LuminanceEncodeApprox=vec3(0.2126,0.7152,0.0722);
91    mat3 transposeMat3(mat3 inMatrix) {
92    vec3 i0=inMatrix[0];
93    vec3 i1=inMatrix[1];
94    vec3 i2=inMatrix[2];
95    mat3 outMatrix=mat3(
96    vec3(i0.x,i1.x,i2.x),
97    vec3(i0.y,i1.y,i2.y),
98    vec3(i0.z,i1.z,i2.z)
99    );
100    return outMatrix;
101    }
102    
103    mat3 inverseMat3(mat3 inMatrix) {
104    float a00=inMatrix[0][0],a01=inMatrix[0][1],a02=inMatrix[0][2];
105    float a10=inMatrix[1][0],a11=inMatrix[1][1],a12=inMatrix[1][2];
106    float a20=inMatrix[2][0],a21=inMatrix[2][1],a22=inMatrix[2][2];
107    float b01=a22*a11-a12*a21;
108    float b11=-a22*a10+a12*a20;
109    float b21=a21*a10-a11*a20;
110    float det=a00*b01+a01*b11+a02*b21;
111    return mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),
112    b11,(a22*a00-a02*a20),(-a12*a00+a02*a10),
113    b21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;
114    }
115    float computeFallOff(float value,vec2 clipSpace,float frustumEdgeFalloff)
116    {
117    float mask=smoothstep(1.0-frustumEdgeFalloff,1.0,clamp(dot(clipSpace,clipSpace),0.,1.));
118    return mix(value,1.0,mask);
119    }
120    vec3 applyEaseInOut(vec3 x){
121    return x*x*(3.0-2.0*x);
122    }
123    vec3 toLinearSpace(vec3 color)
124    {
125    return pow(color,vec3(LinearEncodePowerApprox));
126    }
127    vec3 toGammaSpace(vec3 color)
128    {
129    return pow(color,vec3(GammaEncodePowerApprox));
130    }
131    float square(float value)
132    {
133    return value*value;
134    }
135    float getLuminance(vec3 color)
136    {
137    return clamp(dot(color,LuminanceEncodeApprox),0.,1.);
138    }
139    
140    float getRand(vec2 seed) {
141    return fract(sin(dot(seed.xy ,vec2(12.9898,78.233)))*43758.5453);
142    }
143    float dither(vec2 seed,float varianceAmount) {
144    float rand=getRand(seed);
145    float dither=mix(-varianceAmount/255.0,varianceAmount/255.0,rand);
146    return dither;
147    }
148    #if NUM_BONE_INFLUENCERS>0
149    uniform mat4 mBones[BonesPerMesh];
150    in vec4 matricesIndices;
151    in vec4 matricesWeights;
152    #if NUM_BONE_INFLUENCERS>4
153    in vec4 matricesIndicesExtra;
154    in vec4 matricesWeightsExtra;
155    #endif
156    #endif
157    
158    #ifdef INSTANCES
159    in vec4 world0;
160    in vec4 world1;
161    in vec4 world2;
162    in vec4 world3;
163    #else
164    uniform mat4 world;
165    #endif
166    #ifdef MAINUV1
167    out vec2 vMainUV1;
168    #endif
169    #ifdef MAINUV2
170    out vec2 vMainUV2;
171    #endif
172    #if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0
173    out vec2 vDiffuseUV;
174    #endif
175    #if defined(AMBIENT) && AMBIENTDIRECTUV == 0
176    out vec2 vAmbientUV;
177    #endif
178    #if defined(OPACITY) && OPACITYDIRECTUV == 0
179    out vec2 vOpacityUV;
180    #endif
181    #if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0
182    out vec2 vEmissiveUV;
183    #endif
184    #if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0
185    out vec2 vLightmapUV;
186    #endif
187    #if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0
188    out vec2 vSpecularUV;
189    #endif
190    #if defined(BUMP) && BUMPDIRECTUV == 0
191    out vec2 vBumpUV;
192    #endif
193    
194    out vec3 vPositionW;
195    #ifdef NORMAL
196    out vec3 vNormalW;
197    #endif
198    #ifdef VERTEXCOLOR
199    out vec4 vColor;
200    #endif
201    #if defined(BUMP) || defined(PARALLAX)
202    #if defined(TANGENT) && defined(NORMAL) 
203    out mat3 vTBN;
204    #endif
205    #endif
206    
207    #ifdef CLIPPLANE
208    uniform vec4 vClipPlane;
209    out float fClipDistance;
210    #endif
211    #ifdef FOG
212    out vec3 vFogDistance;
213    #endif
214    #ifdef LIGHT0
215    uniform Light0
216    {
217    vec4 vLightData;
218    vec4 vLightDiffuse;
219    vec3 vLightSpecular;
220    #ifdef SPOTLIGHT0
221    vec4 vLightDirection;
222    #endif
223    #ifdef HEMILIGHT0
224    vec3 vLightGround;
225    #endif
226    vec4 shadowsInfo;
227    vec2 depthValues;
228    } light0;
229    #ifdef PROJECTEDLIGHTTEXTURE0
230    uniform mat4 textureProjectionMatrix0;
231    uniform sampler2D projectionLightSampler0;
232    #endif
233    #ifdef SHADOW0
234    #if defined(SHADOWCUBE0)
235    uniform samplerCube shadowSampler0; 
236    #else
237    out vec4 vPositionFromLight0;
238    out float vDepthMetric0;
239    #if defined(SHADOWPCSS0)
240    uniform highp sampler2DShadow shadowSampler0;
241    uniform highp sampler2D depthSampler0;
242    #elif defined(SHADOWPCF0)
243    uniform highp sampler2DShadow shadowSampler0;
244    #else
245    uniform sampler2D shadowSampler0;
246    #endif
247    uniform mat4 lightMatrix0;
248    #endif
249    #endif
250    #endif
251    #ifdef LIGHT1
252    uniform Light1
253    {
254    vec4 vLightData;
255    vec4 vLightDiffuse;
256    vec3 vLightSpecular;
257    #ifdef SPOTLIGHT1
258    vec4 vLightDirection;
259    #endif
260    #ifdef HEMILIGHT1
261    vec3 vLightGround;
262    #endif
263    vec4 shadowsInfo;
264    vec2 depthValues;
265    } light1;
266    #ifdef PROJECTEDLIGHTTEXTURE1
267    uniform mat4 textureProjectionMatrix1;
268    uniform sampler2D projectionLightSampler1;
269    #endif
270    #ifdef SHADOW1
271    #if defined(SHADOWCUBE1)
272    uniform samplerCube shadowSampler1; 
273    #else
274    out vec4 vPositionFromLight1;
275    out float vDepthMetric1;
276    #if defined(SHADOWPCSS1)
277    uniform highp sampler2DShadow shadowSampler1;
278    uniform highp sampler2D depthSampler1;
279    #elif defined(SHADOWPCF1)
280    uniform highp sampler2DShadow shadowSampler1;
281    #else
282    uniform sampler2D shadowSampler1;
283    #endif
284    uniform mat4 lightMatrix1;
285    #endif
286    #endif
287    #endif
288    #ifdef LIGHT2
289    uniform Light2
290    {
291    vec4 vLightData;
292    vec4 vLightDiffuse;
293    vec3 vLightSpecular;
294    #ifdef SPOTLIGHT2
295    vec4 vLightDirection;
296    #endif
297    #ifdef HEMILIGHT2
298    vec3 vLightGround;
299    #endif
300    vec4 shadowsInfo;
301    vec2 depthValues;
302    } light2;
303    #ifdef PROJECTEDLIGHTTEXTURE2
304    uniform mat4 textureProjectionMatrix2;
305    uniform sampler2D projectionLightSampler2;
306    #endif
307    #ifdef SHADOW2
308    #if defined(SHADOWCUBE2)
309    uniform samplerCube shadowSampler2; 
310    #else
311    out vec4 vPositionFromLight2;
312    out float vDepthMetric2;
313    #if defined(SHADOWPCSS2)
314    uniform highp sampler2DShadow shadowSampler2;
315    uniform highp sampler2D depthSampler2;
316    #elif defined(SHADOWPCF2)
317    uniform highp sampler2DShadow shadowSampler2;
318    #else
319    uniform sampler2D shadowSampler2;
320    #endif
321    uniform mat4 lightMatrix2;
322    #endif
323    #endif
324    #endif
325    #ifdef LIGHT3
326    uniform Light3
327    {
328    vec4 vLightData;
329    vec4 vLightDiffuse;
330    vec3 vLightSpecular;
331    #ifdef SPOTLIGHT3
332    vec4 vLightDirection;
333    #endif
334    #ifdef HEMILIGHT3
335    vec3 vLightGround;
336    #endif
337    vec4 shadowsInfo;
338    vec2 depthValues;
339    } light3;
340    #ifdef PROJECTEDLIGHTTEXTURE3
341    uniform mat4 textureProjectionMatrix3;
342    uniform sampler2D projectionLightSampler3;
343    #endif
344    #ifdef SHADOW3
345    #if defined(SHADOWCUBE3)
346    uniform samplerCube shadowSampler3; 
347    #else
348    out vec4 vPositionFromLight3;
349    out float vDepthMetric3;
350    #if defined(SHADOWPCSS3)
351    uniform highp sampler2DShadow shadowSampler3;
352    uniform highp sampler2D depthSampler3;
353    #elif defined(SHADOWPCF3)
354    uniform highp sampler2DShadow shadowSampler3;
355    #else
356    uniform sampler2D shadowSampler3;
357    #endif
358    uniform mat4 lightMatrix3;
359    #endif
360    #endif
361    #endif
362    
363    #ifdef MORPHTARGETS
364    uniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];
365    #endif
366    
367    #ifdef REFLECTIONMAP_SKYBOX
368    out vec3 vPositionUVW;
369    #endif
370    #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
371    out vec3 vDirectionW;
372    #endif
373    #ifdef LOGARITHMICDEPTH
374    uniform float logarithmicDepthConstant;
375    out float vFragmentDepth;
376    #endif
377    #define CUSTOM_VERTEX_DEFINITIONS
378    void main(void) {
379    #define CUSTOM_VERTEX_MAIN_BEGIN
380    vec3 positionUpdated=position;
381    #ifdef NORMAL 
382    vec3 normalUpdated=normal;
383    #endif
384    #ifdef TANGENT
385    vec4 tangentUpdated=tangent;
386    #endif
387    
388    #ifdef REFLECTIONMAP_SKYBOX
389    vPositionUVW=positionUpdated;
390    #endif 
391    #define CUSTOM_VERTEX_UPDATE_POSITION
392    #define CUSTOM_VERTEX_UPDATE_NORMAL
393    #ifdef INSTANCES
394    mat4 finalWorld=mat4(world0,world1,world2,world3);
395    #else
396    mat4 finalWorld=world;
397    #endif
398    #if NUM_BONE_INFLUENCERS>0
399    mat4 influence;
400    influence=mBones[int(matricesIndices[0])]*matricesWeights[0];
401    #if NUM_BONE_INFLUENCERS>1
402    influence+=mBones[int(matricesIndices[1])]*matricesWeights[1];
403    #endif 
404    #if NUM_BONE_INFLUENCERS>2
405    influence+=mBones[int(matricesIndices[2])]*matricesWeights[2];
406    #endif 
407    #if NUM_BONE_INFLUENCERS>3
408    influence+=mBones[int(matricesIndices[3])]*matricesWeights[3];
409    #endif 
410    #if NUM_BONE_INFLUENCERS>4
411    influence+=mBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];
412    #endif 
413    #if NUM_BONE_INFLUENCERS>5
414    influence+=mBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];
415    #endif 
416    #if NUM_BONE_INFLUENCERS>6
417    influence+=mBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];
418    #endif 
419    #if NUM_BONE_INFLUENCERS>7
420    influence+=mBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];
421    #endif 
422    finalWorld=finalWorld*influence;
423    #endif
424    gl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);
425    vec4 worldPos=finalWorld*vec4(positionUpdated,1.0);
426    vPositionW=vec3(worldPos);
427    #ifdef NORMAL
428    mat3 normalWorld=mat3(finalWorld);
429    #ifdef NONUNIFORMSCALING
430    normalWorld=transposeMat3(inverseMat3(normalWorld));
431    #endif
432    vNormalW=normalize(normalWorld*normalUpdated);
433    #endif
434    #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
435    vDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));
436    #endif
437    
438    #ifndef UV1
439    vec2 uv=vec2(0.,0.);
440    #endif
441    #ifndef UV2
442    vec2 uv2=vec2(0.,0.);
443    #endif
444    #ifdef MAINUV1
445    vMainUV1=uv;
446    #endif
447    #ifdef MAINUV2
448    vMainUV2=uv2;
449    #endif
450    #if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0
451    if (vDiffuseInfos.x == 0.)
452    {
453    vDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));
454    }
455    else
456    {
457    vDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));
458    }
459    #endif
460    #if defined(AMBIENT) && AMBIENTDIRECTUV == 0
461    if (vAmbientInfos.x == 0.)
462    {
463    vAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));
464    }
465    else
466    {
467    vAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));
468    }
469    #endif
470    #if defined(OPACITY) && OPACITYDIRECTUV == 0
471    if (vOpacityInfos.x == 0.)
472    {
473    vOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));
474    }
475    else
476    {
477    vOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));
478    }
479    #endif
480    #if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0
481    if (vEmissiveInfos.x == 0.)
482    {
483    vEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));
484    }
485    else
486    {
487    vEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));
488    }
489    #endif
490    #if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0
491    if (vLightmapInfos.x == 0.)
492    {
493    vLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));
494    }
495    else
496    {
497    vLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));
498    }
499    #endif
500    #if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0
501    if (vSpecularInfos.x == 0.)
502    {
503    vSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));
504    }
505    else
506    {
507    vSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));
508    }
509    #endif
510    #if defined(BUMP) && BUMPDIRECTUV == 0
511    if (vBumpInfos.x == 0.)
512    {
513    vBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));
514    }
515    else
516    {
517    vBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));
518    }
519    #endif
520    #if defined(BUMP) || defined(PARALLAX)
521    #if defined(TANGENT) && defined(NORMAL)
522    vec3 tbnNormal=normalize(normalUpdated);
523    vec3 tbnTangent=normalize(tangentUpdated.xyz);
524    vec3 tbnBitangent=cross(tbnNormal,tbnTangent)*tangentUpdated.w;
525    vTBN=mat3(finalWorld)*mat3(tbnTangent,tbnBitangent,tbnNormal);
526    #endif
527    #endif
528    #ifdef CLIPPLANE
529    fClipDistance=dot(worldPos,vClipPlane);
530    #endif
531    #ifdef FOG
532    vFogDistance=(view*worldPos).xyz;
533    #endif
534    #ifdef SHADOWS
535    #if defined(SHADOW0) && !defined(SHADOWCUBE0)
536    vPositionFromLight0=lightMatrix0*worldPos;
537    vDepthMetric0=((vPositionFromLight0.z+light0.depthValues.x)/(light0.depthValues.y));
538    #endif
539    #endif
540    #ifdef SHADOWS
541    #if defined(SHADOW1) && !defined(SHADOWCUBE1)
542    vPositionFromLight1=lightMatrix1*worldPos;
543    vDepthMetric1=((vPositionFromLight1.z+light1.depthValues.x)/(light1.depthValues.y));
544    #endif
545    #endif
546    #ifdef SHADOWS
547    #if defined(SHADOW2) && !defined(SHADOWCUBE2)
548    vPositionFromLight2=lightMatrix2*worldPos;
549    vDepthMetric2=((vPositionFromLight2.z+light2.depthValues.x)/(light2.depthValues.y));
550    #endif
551    #endif
552    #ifdef SHADOWS
553    #if defined(SHADOW3) && !defined(SHADOWCUBE3)
554    vPositionFromLight3=lightMatrix3*worldPos;
555    vDepthMetric3=((vPositionFromLight3.z+light3.depthValues.x)/(light3.depthValues.y));
556    #endif
557    #endif
558    
559    #ifdef VERTEXCOLOR
560    
561    vColor=color;
562    #endif
563    #ifdef POINTSIZE
564    gl_PointSize=pointSize;
565    #endif
566    #ifdef LOGARITHMICDEPTH
567    vFragmentDepth=1.0+gl_Position.w;
568    gl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;
569    #endif
570    #define CUSTOM_VERTEX_MAIN_END
571    }
572    

 

BJS - [21:02:28]: Fragment shader: default
1    #version 300 es
2    #define WEBGL2 
3    #define DIFFUSEDIRECTUV 0
4    #define AMBIENTDIRECTUV 0
5    #define OPACITYDIRECTUV 0
6    #define EMISSIVEDIRECTUV 0
7    #define SPECULARDIRECTUV 0
8    #define BUMPDIRECTUV 0
9    
10    #define NORMAL
11    #define NUM_BONE_INFLUENCERS 0
12    #define BonesPerMesh 0
13    #define LIGHTMAPDIRECTUV 0
14    #define SHADOWFLOAT
15    #define NUM_MORPH_INFLUENCERS 0
16    #define VIGNETTEBLENDMODEMULTIPLY
17    #define SAMPLER3DGREENDEPTH
18    #define SAMPLER3DBGRMAP
19    #define LIGHT0
20    #define DIRLIGHT0
21    #define SHADOW0
22    #define SHADOWPCF0
23    #define SHADOWS
24    
25    #define SHADER_NAME fragment:default
26    precision highp float;
27    layout(std140,column_major) uniform;
28    uniform Material
29    {
30    vec4 diffuseLeftColor;
31    vec4 diffuseRightColor;
32    vec4 opacityParts;
33    vec4 reflectionLeftColor;
34    vec4 reflectionRightColor;
35    vec4 refractionLeftColor;
36    vec4 refractionRightColor;
37    vec4 emissiveLeftColor; 
38    vec4 emissiveRightColor;
39    vec2 vDiffuseInfos;
40    vec2 vAmbientInfos;
41    vec2 vOpacityInfos;
42    vec2 vReflectionInfos;
43    vec3 vReflectionPosition;
44    vec3 vReflectionSize;
45    vec2 vEmissiveInfos;
46    vec2 vLightmapInfos;
47    vec2 vSpecularInfos;
48    vec3 vBumpInfos;
49    mat4 diffuseMatrix;
50    mat4 ambientMatrix;
51    mat4 opacityMatrix;
52    mat4 reflectionMatrix;
53    mat4 emissiveMatrix;
54    mat4 lightmapMatrix;
55    mat4 specularMatrix;
56    mat4 bumpMatrix; 
57    vec4 vTangentSpaceParams;
58    mat4 refractionMatrix;
59    vec4 vRefractionInfos;
60    vec4 vSpecularColor;
61    vec3 vEmissiveColor;
62    vec4 vDiffuseColor;
63    float pointSize; 
64    };
65    uniform Scene {
66    mat4 viewProjection;
67    mat4 view;
68    };
69    #if defined(BUMP) || !defined(NORMAL)
70    
71    #endif
72    #define CUSTOM_FRAGMENT_BEGIN
73    #ifdef LOGARITHMICDEPTH
74    
75    #endif
76    
77    #define RECIPROCAL_PI2 0.15915494
78    uniform vec3 vEyePosition;
79    uniform vec3 vAmbientColor;
80    
81    in vec3 vPositionW;
82    #ifdef NORMAL
83    in vec3 vNormalW;
84    #endif
85    #ifdef VERTEXCOLOR
86    in vec4 vColor;
87    #endif
88    #ifdef MAINUV1
89    in vec2 vMainUV1;
90    #endif
91    #ifdef MAINUV2
92    in vec2 vMainUV2;
93    #endif
94    
95    const float PI=3.1415926535897932384626433832795;
96    const float LinearEncodePowerApprox=2.2;
97    const float GammaEncodePowerApprox=1.0/LinearEncodePowerApprox;
98    const vec3 LuminanceEncodeApprox=vec3(0.2126,0.7152,0.0722);
99    mat3 transposeMat3(mat3 inMatrix) {
100    vec3 i0=inMatrix[0];
101    vec3 i1=inMatrix[1];
102    vec3 i2=inMatrix[2];
103    mat3 outMatrix=mat3(
104    vec3(i0.x,i1.x,i2.x),
105    vec3(i0.y,i1.y,i2.y),
106    vec3(i0.z,i1.z,i2.z)
107    );
108    return outMatrix;
109    }
110    
111    mat3 inverseMat3(mat3 inMatrix) {
112    float a00=inMatrix[0][0],a01=inMatrix[0][1],a02=inMatrix[0][2];
113    float a10=inMatrix[1][0],a11=inMatrix[1][1],a12=inMatrix[1][2];
114    float a20=inMatrix[2][0],a21=inMatrix[2][1],a22=inMatrix[2][2];
115    float b01=a22*a11-a12*a21;
116    float b11=-a22*a10+a12*a20;
117    float b21=a21*a10-a11*a20;
118    float det=a00*b01+a01*b11+a02*b21;
119    return mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),
120    b11,(a22*a00-a02*a20),(-a12*a00+a02*a10),
121    b21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;
122    }
123    float computeFallOff(float value,vec2 clipSpace,float frustumEdgeFalloff)
124    {
125    float mask=smoothstep(1.0-frustumEdgeFalloff,1.0,clamp(dot(clipSpace,clipSpace),0.,1.));
126    return mix(value,1.0,mask);
127    }
128    vec3 applyEaseInOut(vec3 x){
129    return x*x*(3.0-2.0*x);
130    }
131    vec3 toLinearSpace(vec3 color)
132    {
133    return pow(color,vec3(LinearEncodePowerApprox));
134    }
135    vec3 toGammaSpace(vec3 color)
136    {
137    return pow(color,vec3(GammaEncodePowerApprox));
138    }
139    float square(float value)
140    {
141    return value*value;
142    }
143    float getLuminance(vec3 color)
144    {
145    return clamp(dot(color,LuminanceEncodeApprox),0.,1.);
146    }
147    
148    float getRand(vec2 seed) {
149    return fract(sin(dot(seed.xy ,vec2(12.9898,78.233)))*43758.5453);
150    }
151    float dither(vec2 seed,float varianceAmount) {
152    float rand=getRand(seed);
153    float dither=mix(-varianceAmount/255.0,varianceAmount/255.0,rand);
154    return dither;
155    }
156    
157    #ifdef LIGHT0
158    uniform Light0
159    {
160    vec4 vLightData;
161    vec4 vLightDiffuse;
162    vec3 vLightSpecular;
163    #ifdef SPOTLIGHT0
164    vec4 vLightDirection;
165    #endif
166    #ifdef HEMILIGHT0
167    vec3 vLightGround;
168    #endif
169    vec4 shadowsInfo;
170    vec2 depthValues;
171    } light0;
172    #ifdef PROJECTEDLIGHTTEXTURE0
173    uniform mat4 textureProjectionMatrix0;
174    uniform sampler2D projectionLightSampler0;
175    #endif
176    #ifdef SHADOW0
177    #if defined(SHADOWCUBE0)
178    uniform samplerCube shadowSampler0; 
179    #else
180    in vec4 vPositionFromLight0;
181    in float vDepthMetric0;
182    #if defined(SHADOWPCSS0)
183    uniform highp sampler2DShadow shadowSampler0;
184    uniform highp sampler2D depthSampler0;
185    #elif defined(SHADOWPCF0)
186    uniform highp sampler2DShadow shadowSampler0;
187    #else
188    uniform sampler2D shadowSampler0;
189    #endif
190    uniform mat4 lightMatrix0;
191    #endif
192    #endif
193    #endif
194    #ifdef LIGHT1
195    uniform Light1
196    {
197    vec4 vLightData;
198    vec4 vLightDiffuse;
199    vec3 vLightSpecular;
200    #ifdef SPOTLIGHT1
201    vec4 vLightDirection;
202    #endif
203    #ifdef HEMILIGHT1
204    vec3 vLightGround;
205    #endif
206    vec4 shadowsInfo;
207    vec2 depthValues;
208    } light1;
209    #ifdef PROJECTEDLIGHTTEXTURE1
210    uniform mat4 textureProjectionMatrix1;
211    uniform sampler2D projectionLightSampler1;
212    #endif
213    #ifdef SHADOW1
214    #if defined(SHADOWCUBE1)
215    uniform samplerCube shadowSampler1; 
216    #else
217    in vec4 vPositionFromLight1;
218    in float vDepthMetric1;
219    #if defined(SHADOWPCSS1)
220    uniform highp sampler2DShadow shadowSampler1;
221    uniform highp sampler2D depthSampler1;
222    #elif defined(SHADOWPCF1)
223    uniform highp sampler2DShadow shadowSampler1;
224    #else
225    uniform sampler2D shadowSampler1;
226    #endif
227    uniform mat4 lightMatrix1;
228    #endif
229    #endif
230    #endif
231    #ifdef LIGHT2
232    uniform Light2
233    {
234    vec4 vLightData;
235    vec4 vLightDiffuse;
236    vec3 vLightSpecular;
237    #ifdef SPOTLIGHT2
238    vec4 vLightDirection;
239    #endif
240    #ifdef HEMILIGHT2
241    vec3 vLightGround;
242    #endif
243    vec4 shadowsInfo;
244    vec2 depthValues;
245    } light2;
246    #ifdef PROJECTEDLIGHTTEXTURE2
247    uniform mat4 textureProjectionMatrix2;
248    uniform sampler2D projectionLightSampler2;
249    #endif
250    #ifdef SHADOW2
251    #if defined(SHADOWCUBE2)
252    uniform samplerCube shadowSampler2; 
253    #else
254    in vec4 vPositionFromLight2;
255    in float vDepthMetric2;
256    #if defined(SHADOWPCSS2)
257    uniform highp sampler2DShadow shadowSampler2;
258    uniform highp sampler2D depthSampler2;
259    #elif defined(SHADOWPCF2)
260    uniform highp sampler2DShadow shadowSampler2;
261    #else
262    uniform sampler2D shadowSampler2;
263    #endif
264    uniform mat4 lightMatrix2;
265    #endif
266    #endif
267    #endif
268    #ifdef LIGHT3
269    uniform Light3
270    {
271    vec4 vLightData;
272    vec4 vLightDiffuse;
273    vec3 vLightSpecular;
274    #ifdef SPOTLIGHT3
275    vec4 vLightDirection;
276    #endif
277    #ifdef HEMILIGHT3
278    vec3 vLightGround;
279    #endif
280    vec4 shadowsInfo;
281    vec2 depthValues;
282    } light3;
283    #ifdef PROJECTEDLIGHTTEXTURE3
284    uniform mat4 textureProjectionMatrix3;
285    uniform sampler2D projectionLightSampler3;
286    #endif
287    #ifdef SHADOW3
288    #if defined(SHADOWCUBE3)
289    uniform samplerCube shadowSampler3; 
290    #else
291    in vec4 vPositionFromLight3;
292    in float vDepthMetric3;
293    #if defined(SHADOWPCSS3)
294    uniform highp sampler2DShadow shadowSampler3;
295    uniform highp sampler2D depthSampler3;
296    #elif defined(SHADOWPCF3)
297    uniform highp sampler2DShadow shadowSampler3;
298    #else
299    uniform sampler2D shadowSampler3;
300    #endif
301    uniform mat4 lightMatrix3;
302    #endif
303    #endif
304    #endif
305    
306    
307    struct lightingInfo
308    {
309    vec3 diffuse;
310    #ifdef SPECULARTERM
311    vec3 specular;
312    #endif
313    #ifdef NDOTL
314    float ndl;
315    #endif
316    };
317    lightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {
318    lightingInfo result;
319    vec3 lightVectorW;
320    float attenuation=1.0;
321    if (lightData.w == 0.)
322    {
323    vec3 direction=lightData.xyz-vPositionW;
324    attenuation=max(0.,1.0-length(direction)/range);
325    lightVectorW=normalize(direction);
326    }
327    else
328    {
329    lightVectorW=normalize(-lightData.xyz);
330    }
331    
332    float ndl=max(0.,dot(vNormal,lightVectorW));
333    #ifdef NDOTL
334    result.ndl=ndl;
335    #endif
336    result.diffuse=ndl*diffuseColor*attenuation;
337    #ifdef SPECULARTERM
338    
339    vec3 angleW=normalize(viewDirectionW+lightVectorW);
340    float specComp=max(0.,dot(vNormal,angleW));
341    specComp=pow(specComp,max(1.,glossiness));
342    result.specular=specComp*specularColor*attenuation;
343    #endif
344    return result;
345    }
346    lightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {
347    lightingInfo result;
348    vec3 direction=lightData.xyz-vPositionW;
349    vec3 lightVectorW=normalize(direction);
350    float attenuation=max(0.,1.0-length(direction)/range);
351    
352    float cosAngle=max(0.,dot(lightDirection.xyz,-lightVectorW));
353    if (cosAngle>=lightDirection.w)
354    {
355    cosAngle=max(0.,pow(cosAngle,lightData.w));
356    attenuation*=cosAngle;
357    
358    float ndl=max(0.,dot(vNormal,lightVectorW));
359    #ifdef NDOTL
360    result.ndl=ndl;
361    #endif
362    result.diffuse=ndl*diffuseColor*attenuation;
363    #ifdef SPECULARTERM
364    
365    vec3 angleW=normalize(viewDirectionW+lightVectorW);
366    float specComp=max(0.,dot(vNormal,angleW));
367    specComp=pow(specComp,max(1.,glossiness));
368    result.specular=specComp*specularColor*attenuation;
369    #endif
370    return result;
371    }
372    result.diffuse=vec3(0.);
373    #ifdef SPECULARTERM
374    result.specular=vec3(0.);
375    #endif
376    #ifdef NDOTL
377    result.ndl=0.;
378    #endif
379    return result;
380    }
381    lightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float glossiness) {
382    lightingInfo result;
383    
384    float ndl=dot(vNormal,lightData.xyz)*0.5+0.5;
385    #ifdef NDOTL
386    result.ndl=ndl;
387    #endif
388    result.diffuse=mix(groundColor,diffuseColor,ndl);
389    #ifdef SPECULARTERM
390    
391    vec3 angleW=normalize(viewDirectionW+lightData.xyz);
392    float specComp=max(0.,dot(vNormal,angleW));
393    specComp=pow(specComp,max(1.,glossiness));
394    result.specular=specComp*specularColor;
395    #endif
396    return result;
397    }
398    vec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler,mat4 textureProjectionMatrix){
399    vec4 strq=textureProjectionMatrix*vec4(vPositionW,1.0);
400    strq/=strq.w;
401    vec3 textureColor=texture(projectionLightSampler,strq.xy).rgb;
402    return textureColor;
403    }
404    #ifdef SHADOWS
405    #ifndef SHADOWFLOAT
406    float unpack(vec4 color)
407    {
408    const vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);
409    return dot(color,bit_shift);
410    }
411    #endif
412    float computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,vec2 depthValues)
413    {
414    vec3 directionToLight=vPositionW-lightPosition;
415    float depth=length(directionToLight);
416    depth=(depth+depthValues.x)/(depthValues.y);
417    depth=clamp(depth,0.,1.0);
418    directionToLight=normalize(directionToLight);
419    directionToLight.y=-directionToLight.y;
420    #ifndef SHADOWFLOAT
421    float shadow=unpack(texture(shadowSampler,directionToLight));
422    #else
423    float shadow=texture(shadowSampler,directionToLight).x;
424    #endif
425    if (depth>shadow)
426    {
427    return darkness;
428    }
429    return 1.0;
430    }
431    float computeShadowWithPoissonSamplingCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float darkness,vec2 depthValues)
432    {
433    vec3 directionToLight=vPositionW-lightPosition;
434    float depth=length(directionToLight);
435    depth=(depth+depthValues.x)/(depthValues.y);
436    depth=clamp(depth,0.,1.0);
437    directionToLight=normalize(directionToLight);
438    directionToLight.y=-directionToLight.y;
439    float visibility=1.;
440    vec3 poissonDisk[4];
441    poissonDisk[0]=vec3(-1.0,1.0,-1.0);
442    poissonDisk[1]=vec3(1.0,-1.0,-1.0);
443    poissonDisk[2]=vec3(-1.0,-1.0,-1.0);
444    poissonDisk[3]=vec3(1.0,-1.0,1.0);
445    
446    #ifndef SHADOWFLOAT
447    if (unpack(texture(shadowSampler,directionToLight+poissonDisk[0]*mapSize))<depth) visibility-=0.25;
448    if (unpack(texture(shadowSampler,directionToLight+poissonDisk[1]*mapSize))<depth) visibility-=0.25;
449    if (unpack(texture(shadowSampler,directionToLight+poissonDisk[2]*mapSize))<depth) visibility-=0.25;
450    if (unpack(texture(shadowSampler,directionToLight+poissonDisk[3]*mapSize))<depth) visibility-=0.25;
451    #else
452    if (texture(shadowSampler,directionToLight+poissonDisk[0]*mapSize).x<depth) visibility-=0.25;
453    if (texture(shadowSampler,directionToLight+poissonDisk[1]*mapSize).x<depth) visibility-=0.25;
454    if (texture(shadowSampler,directionToLight+poissonDisk[2]*mapSize).x<depth) visibility-=0.25;
455    if (texture(shadowSampler,directionToLight+poissonDisk[3]*mapSize).x<depth) visibility-=0.25;
456    #endif
457    return min(1.0,visibility+darkness);
458    }
459    float computeShadowWithESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)
460    {
461    vec3 directionToLight=vPositionW-lightPosition;
462    float depth=length(directionToLight);
463    depth=(depth+depthValues.x)/(depthValues.y);
464    float shadowPixelDepth=clamp(depth,0.,1.0);
465    directionToLight=normalize(directionToLight);
466    directionToLight.y=-directionToLight.y;
467    #ifndef SHADOWFLOAT
468    float shadowMapSample=unpack(texture(shadowSampler,directionToLight));
469    #else
470    float shadowMapSample=texture(shadowSampler,directionToLight).x;
471    #endif
472    float esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness); 
473    return esm;
474    }
475    float computeShadowWithCloseESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)
476    {
477    vec3 directionToLight=vPositionW-lightPosition;
478    float depth=length(directionToLight);
479    depth=(depth+depthValues.x)/(depthValues.y);
480    float shadowPixelDepth=clamp(depth,0.,1.0);
481    directionToLight=normalize(directionToLight);
482    directionToLight.y=-directionToLight.y;
483    #ifndef SHADOWFLOAT
484    float shadowMapSample=unpack(texture(shadowSampler,directionToLight));
485    #else
486    float shadowMapSample=texture(shadowSampler,directionToLight).x;
487    #endif
488    float esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);
489    return esm;
490    }
491    float computeShadow(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float frustumEdgeFalloff)
492    {
493    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
494    vec2 uv=0.5*clipSpace.xy+vec2(0.5);
495    if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)
496    {
497    return 1.0;
498    }
499    float shadowPixelDepth=clamp(depthMetric,0.,1.0);
500    #ifndef SHADOWFLOAT
501    float shadow=unpack(texture(shadowSampler,uv));
502    #else
503    float shadow=texture(shadowSampler,uv).x;
504    #endif
505    if (shadowPixelDepth>shadow)
506    {
507    return computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff);
508    }
509    return 1.;
510    }
511    float computeShadowWithPoissonSampling(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float mapSize,float darkness,float frustumEdgeFalloff)
512    {
513    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
514    vec2 uv=0.5*clipSpace.xy+vec2(0.5);
515    if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)
516    {
517    return 1.0;
518    }
519    float shadowPixelDepth=clamp(depthMetric,0.,1.0);
520    float visibility=1.;
521    vec2 poissonDisk[4];
522    poissonDisk[0]=vec2(-0.94201624,-0.39906216);
523    poissonDisk[1]=vec2(0.94558609,-0.76890725);
524    poissonDisk[2]=vec2(-0.094184101,-0.92938870);
525    poissonDisk[3]=vec2(0.34495938,0.29387760);
526    
527    #ifndef SHADOWFLOAT
528    if (unpack(texture(shadowSampler,uv+poissonDisk[0]*mapSize))<shadowPixelDepth) visibility-=0.25;
529    if (unpack(texture(shadowSampler,uv+poissonDisk[1]*mapSize))<shadowPixelDepth) visibility-=0.25;
530    if (unpack(texture(shadowSampler,uv+poissonDisk[2]*mapSize))<shadowPixelDepth) visibility-=0.25;
531    if (unpack(texture(shadowSampler,uv+poissonDisk[3]*mapSize))<shadowPixelDepth) visibility-=0.25;
532    #else
533    if (texture(shadowSampler,uv+poissonDisk[0]*mapSize).x<shadowPixelDepth) visibility-=0.25;
534    if (texture(shadowSampler,uv+poissonDisk[1]*mapSize).x<shadowPixelDepth) visibility-=0.25;
535    if (texture(shadowSampler,uv+poissonDisk[2]*mapSize).x<shadowPixelDepth) visibility-=0.25;
536    if (texture(shadowSampler,uv+poissonDisk[3]*mapSize).x<shadowPixelDepth) visibility-=0.25;
537    #endif
538    return computeFallOff(min(1.0,visibility+darkness),clipSpace.xy,frustumEdgeFalloff);
539    }
540    float computeShadowWithESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)
541    {
542    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
543    vec2 uv=0.5*clipSpace.xy+vec2(0.5);
544    if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)
545    {
546    return 1.0;
547    }
548    float shadowPixelDepth=clamp(depthMetric,0.,1.0);
549    #ifndef SHADOWFLOAT
550    float shadowMapSample=unpack(texture(shadowSampler,uv));
551    #else
552    float shadowMapSample=texture(shadowSampler,uv).x;
553    #endif
554    float esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);
555    return computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);
556    }
557    float computeShadowWithCloseESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)
558    {
559    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
560    vec2 uv=0.5*clipSpace.xy+vec2(0.5);
561    if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)
562    {
563    return 1.0;
564    }
565    float shadowPixelDepth=clamp(depthMetric,0.,1.0); 
566    #ifndef SHADOWFLOAT
567    float shadowMapSample=unpack(texture(shadowSampler,uv));
568    #else
569    float shadowMapSample=texture(shadowSampler,uv).x;
570    #endif
571    float esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);
572    return computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);
573    }
574    #ifdef WEBGL2
575    
576    float computeShadowWithPCF1(vec4 vPositionFromLight,float depthMetric,sampler2DShadow shadowSampler,float darkness,float frustumEdgeFalloff)
577    {
578    if (depthMetric>1.0 || depthMetric<0.0) {
579    return 1.0;
580    }
581    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
582    vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));
583    float shadow=texture(shadowSampler,uvDepth);
584    shadow=mix(darkness,1.,shadow);
585    return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);
586    }
587    
588    
589    
590    float computeShadowWithPCF3(vec4 vPositionFromLight,float depthMetric,sampler2DShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)
591    {
592    if (depthMetric>1.0 || depthMetric<0.0) {
593    return 1.0;
594    }
595    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
596    vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));
597    vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; 
598    uv+=0.5; 
599    vec2 st=fract(uv); 
600    vec2 base_uv=floor(uv)-0.5; 
601    base_uv*=shadowMapSizeAndInverse.y; 
602    
603    
604    
605    
606    vec2 uvw0=3.-2.*st;
607    vec2 uvw1=1.+2.*st;
608    vec2 u=vec2((2.-st.x)/uvw0.x-1.,st.x/uvw1.x+1.)*shadowMapSizeAndInverse.y;
609    vec2 v=vec2((2.-st.y)/uvw0.y-1.,st.y/uvw1.y+1.)*shadowMapSizeAndInverse.y;
610    float shadow=0.;
611    shadow+=uvw0.x*uvw0.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[0]),uvDepth.z));
612    shadow+=uvw1.x*uvw0.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[0]),uvDepth.z));
613    shadow+=uvw0.x*uvw1.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[1]),uvDepth.z));
614    shadow+=uvw1.x*uvw1.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[1]),uvDepth.z));
615    shadow=shadow/16.;
616    shadow=mix(darkness,1.,shadow);
617    return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);
618    }
619    
620    
621    
622    float computeShadowWithPCF5(vec4 vPositionFromLight,float depthMetric,sampler2DShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)
623    {
624    if (depthMetric>1.0 || depthMetric<0.0) {
625    return 1.0;
626    }
627    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
628    vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));
629    vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x; 
630    uv+=0.5; 
631    vec2 st=fract(uv); 
632    vec2 base_uv=floor(uv)-0.5; 
633    base_uv*=shadowMapSizeAndInverse.y; 
634    
635    
636    vec2 uvw0=4.-3.*st;
637    vec2 uvw1=vec2(7.);
638    vec2 uvw2=1.+3.*st;
639    vec3 u=vec3((3.-2.*st.x)/uvw0.x-2.,(3.+st.x)/uvw1.x,st.x/uvw2.x+2.)*shadowMapSizeAndInverse.y;
640    vec3 v=vec3((3.-2.*st.y)/uvw0.y-2.,(3.+st.y)/uvw1.y,st.y/uvw2.y+2.)*shadowMapSizeAndInverse.y;
641    float shadow=0.;
642    shadow+=uvw0.x*uvw0.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[0]),uvDepth.z));
643    shadow+=uvw1.x*uvw0.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[0]),uvDepth.z));
644    shadow+=uvw2.x*uvw0.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[0]),uvDepth.z));
645    shadow+=uvw0.x*uvw1.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[1]),uvDepth.z));
646    shadow+=uvw1.x*uvw1.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[1]),uvDepth.z));
647    shadow+=uvw2.x*uvw1.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[1]),uvDepth.z));
648    shadow+=uvw0.x*uvw2.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[2]),uvDepth.z));
649    shadow+=uvw1.x*uvw2.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[2]),uvDepth.z));
650    shadow+=uvw2.x*uvw2.y*texture(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[2]),uvDepth.z));
651    shadow=shadow/144.;
652    shadow=mix(darkness,1.,shadow);
653    return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);
654    }
655    const vec3 PoissonSamplers32[64]=vec3[64](
656    vec3(0.06407013,0.05409927,0.),
657    vec3(0.7366577,0.5789394,0.),
658    vec3(-0.6270542,-0.5320278,0.),
659    vec3(-0.4096107,0.8411095,0.),
660    vec3(0.6849564,-0.4990818,0.),
661    vec3(-0.874181,-0.04579735,0.),
662    vec3(0.9989998,0.0009880066,0.),
663    vec3(-0.004920578,-0.9151649,0.),
664    vec3(0.1805763,0.9747483,0.),
665    vec3(-0.2138451,0.2635818,0.),
666    vec3(0.109845,0.3884785,0.),
667    vec3(0.06876755,-0.3581074,0.),
668    vec3(0.374073,-0.7661266,0.),
669    vec3(0.3079132,-0.1216763,0.),
670    vec3(-0.3794335,-0.8271583,0.),
671    vec3(-0.203878,-0.07715034,0.),
672    vec3(0.5912697,0.1469799,0.),
673    vec3(-0.88069,0.3031784,0.),
674    vec3(0.5040108,0.8283722,0.),
675    vec3(-0.5844124,0.5494877,0.),
676    vec3(0.6017799,-0.1726654,0.),
677    vec3(-0.5554981,0.1559997,0.),
678    vec3(-0.3016369,-0.3900928,0.),
679    vec3(-0.5550632,-0.1723762,0.),
680    vec3(0.925029,0.2995041,0.),
681    vec3(-0.2473137,0.5538505,0.),
682    vec3(0.9183037,-0.2862392,0.),
683    vec3(0.2469421,0.6718712,0.),
684    vec3(0.3916397,-0.4328209,0.),
685    vec3(-0.03576927,-0.6220032,0.),
686    vec3(-0.04661255,0.7995201,0.),
687    vec3(0.4402924,0.3640312,0.),
688    vec3(0.,0.,0.),
689    vec3(0.,0.,0.),
690    vec3(0.,0.,0.),
691    vec3(0.,0.,0.),
692    vec3(0.,0.,0.),
693    vec3(0.,0.,0.),
694    vec3(0.,0.,0.),
695    vec3(0.,0.,0.),
696    vec3(0.,0.,0.),
697    vec3(0.,0.,0.),
698    vec3(0.,0.,0.),
699    vec3(0.,0.,0.),
700    vec3(0.,0.,0.),
701    vec3(0.,0.,0.),
702    vec3(0.,0.,0.),
703    vec3(0.,0.,0.),
704    vec3(0.,0.,0.),
705    vec3(0.,0.,0.),
706    vec3(0.,0.,0.),
707    vec3(0.,0.,0.),
708    vec3(0.,0.,0.),
709    vec3(0.,0.,0.),
710    vec3(0.,0.,0.),
711    vec3(0.,0.,0.),
712    vec3(0.,0.,0.),
713    vec3(0.,0.,0.),
714    vec3(0.,0.,0.),
715    vec3(0.,0.,0.),
716    vec3(0.,0.,0.),
717    vec3(0.,0.,0.),
718    vec3(0.,0.,0.),
719    vec3(0.,0.,0.)
720    );
721    const vec3 PoissonSamplers64[64]=vec3[64](
722    vec3(-0.613392,0.617481,0.),
723    vec3(0.170019,-0.040254,0.),
724    vec3(-0.299417,0.791925,0.),
725    vec3(0.645680,0.493210,0.),
726    vec3(-0.651784,0.717887,0.),
727    vec3(0.421003,0.027070,0.),
728    vec3(-0.817194,-0.271096,0.),
729    vec3(-0.705374,-0.668203,0.),
730    vec3(0.977050,-0.108615,0.),
731    vec3(0.063326,0.142369,0.),
732    vec3(0.203528,0.214331,0.),
733    vec3(-0.667531,0.326090,0.),
734    vec3(-0.098422,-0.295755,0.),
735    vec3(-0.885922,0.215369,0.),
736    vec3(0.566637,0.605213,0.),
737    vec3(0.039766,-0.396100,0.),
738    vec3(0.751946,0.453352,0.),
739    vec3(0.078707,-0.715323,0.),
740    vec3(-0.075838,-0.529344,0.),
741    vec3(0.724479,-0.580798,0.),
742    vec3(0.222999,-0.215125,0.),
743    vec3(-0.467574,-0.405438,0.),
744    vec3(-0.248268,-0.814753,0.),
745    vec3(0.354411,-0.887570,0.),
746    vec3(0.175817,0.382366,0.),
747    vec3(0.487472,-0.063082,0.),
748    vec3(-0.084078,0.898312,0.),
749    vec3(0.488876,-0.783441,0.),
750    vec3(0.470016,0.217933,0.),
751    vec3(-0.696890,-0.549791,0.),
752    vec3(-0.149693,0.605762,0.),
753    vec3(0.034211,0.979980,0.),
754    vec3(0.503098,-0.308878,0.),
755    vec3(-0.016205,-0.872921,0.),
756    vec3(0.385784,-0.393902,0.),
757    vec3(-0.146886,-0.859249,0.),
758    vec3(0.643361,0.164098,0.),
759    vec3(0.634388,-0.049471,0.),
760    vec3(-0.688894,0.007843,0.),
761    vec3(0.464034,-0.188818,0.),
762    vec3(-0.440840,0.137486,0.),
763    vec3(0.364483,0.511704,0.),
764    vec3(0.034028,0.325968,0.),
765    vec3(0.099094,-0.308023,0.),
766    vec3(0.693960,-0.366253,0.),
767    vec3(0.678884,-0.204688,0.),
768    vec3(0.001801,0.780328,0.),
769    vec3(0.145177,-0.898984,0.),
770    vec3(0.062655,-0.611866,0.),
771    vec3(0.315226,-0.604297,0.),
772    vec3(-0.780145,0.486251,0.),
773    vec3(-0.371868,0.882138,0.),
774    vec3(0.200476,0.494430,0.),
775    vec3(-0.494552,-0.711051,0.),
776    vec3(0.612476,0.705252,0.),
777    vec3(-0.578845,-0.768792,0.),
778    vec3(-0.772454,-0.090976,0.),
779    vec3(0.504440,0.372295,0.),
780    vec3(0.155736,0.065157,0.),
781    vec3(0.391522,0.849605,0.),
782    vec3(-0.620106,-0.328104,0.),
783    vec3(0.789239,-0.419965,0.),
784    vec3(-0.545396,0.538133,0.),
785    vec3(-0.178564,-0.596057,0.)
786    );
787    
788    
789    
790    
791    
792    float computeShadowWithPCSS(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff,int searchTapCount,int pcfTapCount,vec3[64] poissonSamplers)
793    {
794    if (depthMetric>1.0 || depthMetric<0.0) {
795    return 1.0;
796    }
797    vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;
798    vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));
799    float blockerDepth=0.0;
800    float sumBlockerDepth=0.0;
801    float numBlocker=0.0;
802    for (int i=0; i<searchTapCount; i ++) {
803    blockerDepth=texture(depthSampler,uvDepth.xy+(lightSizeUV*shadowMapSizeInverse*PoissonSamplers32.xy)).r;
804    if (blockerDepth<depthMetric) {
805    sumBlockerDepth+=blockerDepth;
806    numBlocker++;
807    }
808    }
809    if (numBlocker<1.0) {
810    return 1.0;
811    }
812    float avgBlockerDepth=sumBlockerDepth/numBlocker;
813    
814    float AAOffset=shadowMapSizeInverse*10.;
815    
816    
817    float penumbraRatio=((depthMetric-avgBlockerDepth)+AAOffset);
818    float filterRadius=penumbraRatio*lightSizeUV*shadowMapSizeInverse;
819    float random=getRand(vPositionFromLight.xy);
820    float rotationAngle=random*3.1415926;
821    vec2 rotationVector=vec2(cos(rotationAngle),sin(rotationAngle));
822    float shadow=0.;
823    for (int i=0; i<pcfTapCount; i++) {
824    vec3 offset=poissonSamplers;
825    
826    offset=vec3(offset.x*rotationVector.x-offset.y*rotationVector.y,offset.y*rotationVector.x+offset.x*rotationVector.y,0.);
827    shadow+=texture(shadowSampler,uvDepth+offset*filterRadius);
828    }
829    shadow/=float(pcfTapCount);
830    
831    shadow=mix(shadow,1.,depthMetric-avgBlockerDepth);
832    
833    shadow=mix(darkness,1.,shadow);
834    
835    return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);
836    }
837    float computeShadowWithPCSS16(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff)
838    {
839    return computeShadowWithPCSS(vPositionFromLight,depthMetric,depthSampler,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,16,PoissonSamplers32);
840    }
841    float computeShadowWithPCSS32(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff)
842    {
843    return computeShadowWithPCSS(vPositionFromLight,depthMetric,depthSampler,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,32,PoissonSamplers32);
844    }
845    float computeShadowWithPCSS64(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff)
846    {
847    return computeShadowWithPCSS(vPositionFromLight,depthMetric,depthSampler,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,32,64,PoissonSamplers64);
848    }
849    #endif
850    #endif
851    
852    
853    #ifdef DIFFUSE
854    #if DIFFUSEDIRECTUV == 1
855    #define vDiffuseUV vMainUV1
856    #elif DIFFUSEDIRECTUV == 2
857    #define vDiffuseUV vMainUV2
858    #else
859    in vec2 vDiffuseUV;
860    #endif
861    uniform sampler2D diffuseSampler;
862    #endif
863    #ifdef AMBIENT
864    #if AMBIENTDIRECTUV == 1
865    #define vAmbientUV vMainUV1
866    #elif AMBIENTDIRECTUV == 2
867    #define vAmbientUV vMainUV2
868    #else
869    in vec2 vAmbientUV;
870    #endif
871    uniform sampler2D ambientSampler;
872    #endif
873    #ifdef OPACITY 
874    #if OPACITYDIRECTUV == 1
875    #define vOpacityUV vMainUV1
876    #elif OPACITYDIRECTUV == 2
877    #define vOpacityUV vMainUV2
878    #else
879    in vec2 vOpacityUV;
880    #endif
881    uniform sampler2D opacitySampler;
882    #endif
883    #ifdef EMISSIVE
884    #if EMISSIVEDIRECTUV == 1
885    #define vEmissiveUV vMainUV1
886    #elif EMISSIVEDIRECTUV == 2
887    #define vEmissiveUV vMainUV2
888    #else
889    in vec2 vEmissiveUV;
890    #endif
891    uniform sampler2D emissiveSampler;
892    #endif
893    #ifdef LIGHTMAP
894    #if LIGHTMAPDIRECTUV == 1
895    #define vLightmapUV vMainUV1
896    #elif LIGHTMAPDIRECTUV == 2
897    #define vLightmapUV vMainUV2
898    #else
899    in vec2 vLightmapUV;
900    #endif
901    uniform sampler2D lightmapSampler;
902    #endif
903    #ifdef REFRACTION
904    #ifdef REFRACTIONMAP_3D
905    uniform samplerCube refractionCubeSampler;
906    #else
907    uniform sampler2D refraction2DSampler;
908    #endif
909    #endif
910    #if defined(SPECULAR) && defined(SPECULARTERM)
911    #if SPECULARDIRECTUV == 1
912    #define vSpecularUV vMainUV1
913    #elif SPECULARDIRECTUV == 2
914    #define vSpecularUV vMainUV2
915    #else
916    in vec2 vSpecularUV;
917    #endif
918    uniform sampler2D specularSampler;
919    #endif
920    #ifdef ALPHATEST
921    uniform float alphaCutOff;
922    #endif
923    
924    #ifdef FRESNEL
925    float computeFresnelTerm(vec3 viewDirection,vec3 worldNormal,float bias,float power)
926    {
927    float fresnelTerm=pow(bias+abs(dot(viewDirection,worldNormal)),power);
928    return clamp(fresnelTerm,0.,1.);
929    }
930    #endif
931    
932    #ifdef REFLECTION
933    #ifdef REFLECTIONMAP_3D
934    uniform samplerCube reflectionCubeSampler;
935    #else
936    uniform sampler2D reflection2DSampler;
937    #endif
938    #ifdef REFLECTIONMAP_SKYBOX
939    in vec3 vPositionUVW;
940    #else
941    #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
942    in vec3 vDirectionW;
943    #endif
944    #endif
945    #ifdef USE_LOCAL_REFLECTIONMAP_CUBIC
946    vec3 parallaxCorrectNormal( vec3 vertexPos,vec3 origVec,vec3 cubeSize,vec3 cubePos ) {
947    
948    vec3 invOrigVec=vec3(1.0,1.0,1.0)/origVec;
949    vec3 halfSize=cubeSize*0.5;
950    vec3 intersecAtMaxPlane=(cubePos+halfSize-vertexPos)*invOrigVec;
951    vec3 intersecAtMinPlane=(cubePos-halfSize-vertexPos)*invOrigVec;
952    
953    vec3 largestIntersec=max(intersecAtMaxPlane,intersecAtMinPlane);
954    
955    float distance=min(min(largestIntersec.x,largestIntersec.y),largestIntersec.z);
956    
957    vec3 intersectPositionWS=vertexPos+origVec*distance;
958    
959    return intersectPositionWS-cubePos;
960    }
961    #endif
962    vec3 computeReflectionCoords(vec4 worldPos,vec3 worldNormal)
963    {
964    #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
965    vec3 direction=vDirectionW;
966    float t=clamp(direction.y*-0.5+0.5,0.,1.0);
967    float s=atan(direction.z,direction.x)*RECIPROCAL_PI2+0.5;
968    #ifdef REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED
969    return vec3(1.0-s,t,0);
970    #else
971    return vec3(s,t,0);
972    #endif
973    #endif
974    #ifdef REFLECTIONMAP_EQUIRECTANGULAR
975    vec3 cameraToVertex=normalize(worldPos.xyz-vEyePosition.xyz);
976    vec3 r=reflect(cameraToVertex,worldNormal);
977    float t=clamp(r.y*-0.5+0.5,0.,1.0);
978    float s=atan(r.z,r.x)*RECIPROCAL_PI2+0.5;
979    return vec3(s,t,0);
980    #endif
981    #ifdef REFLECTIONMAP_SPHERICAL
982    vec3 viewDir=normalize(vec3(view*worldPos));
983    vec3 viewNormal=normalize(vec3(view*vec4(worldNormal,0.0)));
984    vec3 r=reflect(viewDir,viewNormal);
985    r.z=r.z-1.0;
986    float m=2.0*length(r);
987    return vec3(r.x/m+0.5,1.0-r.y/m-0.5,0);
988    #endif
989    #ifdef REFLECTIONMAP_PLANAR
990    vec3 viewDir=worldPos.xyz-vEyePosition.xyz;
991    vec3 coords=normalize(reflect(viewDir,worldNormal));
992    return vec3(reflectionMatrix*vec4(coords,1));
993    #endif
994    #ifdef REFLECTIONMAP_CUBIC
995    vec3 viewDir=normalize(worldPos.xyz-vEyePosition.xyz);
996    
997    vec3 coords=reflect(viewDir,worldNormal);
998    #ifdef USE_LOCAL_REFLECTIONMAP_CUBIC
999    coords=parallaxCorrectNormal(worldPos.xyz,coords,vReflectionSize,vReflectionPosition);
1000    #endif
1001    coords=vec3(reflectionMatrix*vec4(coords,0));
1002    #ifdef INVERTCUBICMAP
1003    coords.y*=-1.0;
1004    #endif
1005    return coords;
1006    #endif
1007    #ifdef REFLECTIONMAP_PROJECTION
1008    return vec3(reflectionMatrix*(view*worldPos));
1009    #endif
1010    #ifdef REFLECTIONMAP_SKYBOX
1011    return vPositionUVW;
1012    #endif
1013    #ifdef REFLECTIONMAP_EXPLICIT
1014    return vec3(0,0,0);
1015    #endif
1016    }
1017    #endif
1018    #ifdef EXPOSURE
1019    uniform float exposureLinear;
1020    #endif
1021    #ifdef CONTRAST
1022    uniform float contrast;
1023    #endif
1024    #ifdef VIGNETTE
1025    uniform vec2 vInverseScreenSize;
1026    uniform vec4 vignetteSettings1;
1027    uniform vec4 vignetteSettings2;
1028    #endif
1029    #ifdef COLORCURVES
1030    uniform vec4 vCameraColorCurveNegative;
1031    uniform vec4 vCameraColorCurveNeutral;
1032    uniform vec4 vCameraColorCurvePositive;
1033    #endif
1034    #ifdef COLORGRADING
1035    #ifdef COLORGRADING3D
1036    uniform highp sampler3D txColorTransform;
1037    #else
1038    uniform sampler2D txColorTransform;
1039    #endif
1040    uniform vec4 colorTransformSettings;
1041    #endif
1042    #if defined(COLORGRADING) && !defined(COLORGRADING3D)
1043    
1044    vec3 sampleTexture3D(sampler2D colorTransform,vec3 color,vec2 sampler3dSetting)
1045    {
1046    float sliceSize=2.0*sampler3dSetting.x; 
1047    #ifdef SAMPLER3DGREENDEPTH
1048    float sliceContinuous=(color.g-sampler3dSetting.x)*sampler3dSetting.y;
1049    #else
1050    float sliceContinuous=(color.b-sampler3dSetting.x)*sampler3dSetting.y;
1051    #endif
1052    float sliceInteger=floor(sliceContinuous);
1053    
1054    
1055    float sliceFraction=sliceContinuous-sliceInteger;
1056    #ifdef SAMPLER3DGREENDEPTH
1057    vec2 sliceUV=color.rb;
1058    #else
1059    vec2 sliceUV=color.rg;
1060    #endif
1061    sliceUV.x*=sliceSize;
1062    sliceUV.x+=sliceInteger*sliceSize;
1063    sliceUV=clamp(sliceUV,0.,1.);
1064    vec4 slice0Color=texture(colorTransform,sliceUV);
1065    sliceUV.x+=sliceSize;
1066    sliceUV=clamp(sliceUV,0.,1.);
1067    vec4 slice1Color=texture(colorTransform,sliceUV);
1068    vec3 result=mix(slice0Color.rgb,slice1Color.rgb,sliceFraction);
1069    #ifdef SAMPLER3DBGRMAP
1070    color.rgb=result.rgb;
1071    #else
1072    color.rgb=result.bgr;
1073    #endif
1074    return color;
1075    }
1076    #endif
1077    vec4 applyImageProcessing(vec4 result) {
1078    #ifdef EXPOSURE
1079    result.rgb*=exposureLinear;
1080    #endif
1081    #ifdef VIGNETTE
1082    
1083    vec2 viewportXY=gl_FragCoord.xy*vInverseScreenSize;
1084    viewportXY=viewportXY*2.0-1.0;
1085    vec3 vignetteXY1=vec3(viewportXY*vignetteSettings1.xy+vignetteSettings1.zw,1.0);
1086    float vignetteTerm=dot(vignetteXY1,vignetteXY1);
1087    float vignette=pow(vignetteTerm,vignetteSettings2.w);
1088    
1089    vec3 vignetteColor=vignetteSettings2.rgb;
1090    #ifdef VIGNETTEBLENDMODEMULTIPLY
1091    vec3 vignetteColorMultiplier=mix(vignetteColor,vec3(1,1,1),vignette);
1092    result.rgb*=vignetteColorMultiplier;
1093    #endif
1094    #ifdef VIGNETTEBLENDMODEOPAQUE
1095    result.rgb=mix(vignetteColor,result.rgb,vignette);
1096    #endif
1097    #endif
1098    #ifdef TONEMAPPING
1099    const float tonemappingCalibration=1.590579;
1100    result.rgb=1.0-exp2(-tonemappingCalibration*result.rgb);
1101    #endif
1102    
1103    result.rgb=toGammaSpace(result.rgb);
1104    result.rgb=clamp(result.rgb,0.0,1.0);
1105    #ifdef CONTRAST
1106    
1107    vec3 resultHighContrast=applyEaseInOut(result.rgb);
1108    if (contrast<1.0) {
1109    
1110    result.rgb=mix(vec3(0.5,0.5,0.5),result.rgb,contrast);
1111    } else {
1112    
1113    result.rgb=mix(result.rgb,resultHighContrast,contrast-1.0);
1114    }
1115    #endif
1116    
1117    #ifdef COLORGRADING
1118    vec3 colorTransformInput=result.rgb*colorTransformSettings.xxx+colorTransformSettings.yyy;
1119    #ifdef COLORGRADING3D
1120    vec3 colorTransformOutput=texture(txColorTransform,colorTransformInput).rgb;
1121    #else
1122    vec3 colorTransformOutput=sampleTexture3D(txColorTransform,colorTransformInput,colorTransformSettings.yz).rgb;
1123    #endif
1124    result.rgb=mix(result.rgb,colorTransformOutput,colorTransformSettings.www);
1125    #endif
1126    #ifdef COLORCURVES
1127    
1128    float luma=getLuminance(result.rgb);
1129    vec2 curveMix=clamp(vec2(luma*3.0-1.5,luma*-3.0+1.5),vec2(0.0),vec2(1.0));
1130    vec4 colorCurve=vCameraColorCurveNeutral+curveMix.x*vCameraColorCurvePositive-curveMix.y*vCameraColorCurveNegative;
1131    result.rgb*=colorCurve.rgb;
1132    result.rgb=mix(vec3(luma),result.rgb,colorCurve.a);
1133    #endif
1134    return result;
1135    }
1136    #ifdef BUMP
1137    #if BUMPDIRECTUV == 1
1138    #define vBumpUV vMainUV1
1139    #elif BUMPDIRECTUV == 2
1140    #define vBumpUV vMainUV2
1141    #else
1142    in vec2 vBumpUV;
1143    #endif
1144    uniform sampler2D bumpSampler;
1145    #if defined(TANGENT) && defined(NORMAL) 
1146    in mat3 vTBN;
1147    #endif
1148    #ifdef OBJECTSPACE_NORMALMAP
1149    uniform mat4 normalMatrix;
1150    #endif
1151    
1152    mat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv)
1153    {
1154    
1155    uv=gl_FrontFacing ? uv : -uv;
1156    
1157    vec3 dp1=dFdx(p);
1158    vec3 dp2=dFdy(p);
1159    vec2 duv1=dFdx(uv);
1160    vec2 duv2=dFdy(uv);
1161    
1162    vec3 dp2perp=cross(dp2,normal);
1163    vec3 dp1perp=cross(normal,dp1);
1164    vec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;
1165    vec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;
1166    
1167    tangent*=vTangentSpaceParams.x;
1168    bitangent*=vTangentSpaceParams.y;
1169    
1170    float invmax=inversesqrt(max(dot(tangent,tangent),dot(bitangent,bitangent)));
1171    return mat3(tangent*invmax,bitangent*invmax,normal);
1172    }
1173    vec3 perturbNormal(mat3 cotangentFrame,vec2 uv)
1174    {
1175    vec3 map=texture(bumpSampler,uv).xyz;
1176    map=map*2.0-1.0;
1177    #ifdef NORMALXYSCALE
1178    map=normalize(map*vec3(vBumpInfos.y,vBumpInfos.y,1.0));
1179    #endif
1180    return normalize(cotangentFrame*map);
1181    }
1182    #ifdef PARALLAX
1183    const float minSamples=4.;
1184    const float maxSamples=15.;
1185    const int iMaxSamples=15;
1186    
1187    vec2 parallaxOcclusion(vec3 vViewDirCoT,vec3 vNormalCoT,vec2 texCoord,float parallaxScale) {
1188    float parallaxLimit=length(vViewDirCoT.xy)/vViewDirCoT.z;
1189    parallaxLimit*=parallaxScale;
1190    vec2 vOffsetDir=normalize(vViewDirCoT.xy);
1191    vec2 vMaxOffset=vOffsetDir*parallaxLimit;
1192    float numSamples=maxSamples+(dot(vViewDirCoT,vNormalCoT)*(minSamples-maxSamples));
1193    float stepSize=1.0/numSamples;
1194    
1195    float currRayHeight=1.0;
1196    vec2 vCurrOffset=vec2(0,0);
1197    vec2 vLastOffset=vec2(0,0);
1198    float lastSampledHeight=1.0;
1199    float currSampledHeight=1.0;
1200    for (int i=0; i<iMaxSamples; i++)
1201    {
1202    currSampledHeight=texture(bumpSampler,vBumpUV+vCurrOffset).w;
1203    
1204    if (currSampledHeight>currRayHeight)
1205    {
1206    float delta1=currSampledHeight-currRayHeight;
1207    float delta2=(currRayHeight+stepSize)-lastSampledHeight;
1208    float ratio=delta1/(delta1+delta2);
1209    vCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;
1210    
1211    break;
1212    }
1213    else
1214    {
1215    currRayHeight-=stepSize;
1216    vLastOffset=vCurrOffset;
1217    vCurrOffset+=stepSize*vMaxOffset;
1218    lastSampledHeight=currSampledHeight;
1219    }
1220    }
1221    return vCurrOffset;
1222    }
1223    vec2 parallaxOffset(vec3 viewDir,float heightScale)
1224    {
1225    
1226    float height=texture(bumpSampler,vBumpUV).w;
1227    vec2 texCoordOffset=heightScale*viewDir.xy*height;
1228    return -texCoordOffset;
1229    }
1230    #endif
1231    #endif
1232    #ifdef CLIPPLANE
1233    in float fClipDistance;
1234    #endif
1235    #ifdef LOGARITHMICDEPTH
1236    uniform float logarithmicDepthConstant;
1237    in float vFragmentDepth;
1238    #endif
1239    #ifdef FOG
1240    #define FOGMODE_NONE 0.
1241    #define FOGMODE_EXP 1.
1242    #define FOGMODE_EXP2 2.
1243    #define FOGMODE_LINEAR 3.
1244    #define E 2.71828
1245    uniform vec4 vFogInfos;
1246    uniform vec3 vFogColor;
1247    in vec3 vFogDistance;
1248    float CalcFogFactor()
1249    {
1250    float fogCoeff=1.0;
1251    float fogStart=vFogInfos.y;
1252    float fogEnd=vFogInfos.z;
1253    float fogDensity=vFogInfos.w;
1254    float fogDistance=length(vFogDistance);
1255    if (FOGMODE_LINEAR == vFogInfos.x)
1256    {
1257    fogCoeff=(fogEnd-fogDistance)/(fogEnd-fogStart);
1258    }
1259    else if (FOGMODE_EXP == vFogInfos.x)
1260    {
1261    fogCoeff=1.0/pow(E,fogDistance*fogDensity);
1262    }
1263    else if (FOGMODE_EXP2 == vFogInfos.x)
1264    {
1265    fogCoeff=1.0/pow(E,fogDistance*fogDistance*fogDensity*fogDensity);
1266    }
1267    return clamp(fogCoeff,0.0,1.0);
1268    }
1269    #endif
1270    #define CUSTOM_FRAGMENT_DEFINITIONS
1271    out vec4 glFragColor;
1272    void main(void) {
1273    #define CUSTOM_FRAGMENT_MAIN_BEGIN
1274    #ifdef CLIPPLANE
1275    if (fClipDistance>0.0)
1276    {
1277    discard;
1278    }
1279    #endif
1280    vec3 viewDirectionW=normalize(vEyePosition-vPositionW);
1281    
1282    vec4 baseColor=vec4(1.,1.,1.,1.);
1283    vec3 diffuseColor=vDiffuseColor.rgb;
1284    
1285    float alpha=vDiffuseColor.a;
1286    
1287    #ifdef NORMAL
1288    vec3 normalW=normalize(vNormalW);
1289    #else
1290    vec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));
1291    #endif
1292    vec2 uvOffset=vec2(0.0,0.0);
1293    #if defined(BUMP) || defined(PARALLAX)
1294    #ifdef NORMALXYSCALE
1295    float normalScale=1.0;
1296    #else 
1297    float normalScale=vBumpInfos.y;
1298    #endif
1299    #if defined(TANGENT) && defined(NORMAL)
1300    mat3 TBN=vTBN;
1301    #else
1302    mat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,vBumpUV);
1303    #endif
1304    #endif
1305    #ifdef PARALLAX
1306    mat3 invTBN=transposeMat3(TBN);
1307    #ifdef PARALLAXOCCLUSION
1308    uvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);
1309    #else
1310    uvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);
1311    #endif
1312    #endif
1313    #ifdef BUMP
1314    #ifdef OBJECTSPACE_NORMALMAP
1315    normalW=normalize(texture(bumpSampler,vBumpUV).xyz*2.0-1.0);
1316    normalW=normalize(mat3(normalMatrix)*normalW); 
1317    #else
1318    normalW=perturbNormal(TBN,vBumpUV+uvOffset);
1319    #endif
1320    #endif
1321    #ifdef TWOSIDEDLIGHTING
1322    normalW=gl_FrontFacing ? normalW : -normalW;
1323    #endif
1324    #ifdef DIFFUSE
1325    baseColor=texture(diffuseSampler,vDiffuseUV+uvOffset);
1326    #ifdef ALPHATEST
1327    if (baseColor.a<alphaCutOff)
1328    discard;
1329    #endif
1330    #ifdef ALPHAFROMDIFFUSE
1331    alpha*=baseColor.a;
1332    #endif
1333    #define CUSTOM_FRAGMENT_UPDATE_ALPHA
1334    baseColor.rgb*=vDiffuseInfos.y;
1335    #endif
1336    #ifdef DEPTHPREPASS
1337    glFragColor=vec4(0.,0.,0.,1.0);
1338    return;
1339    #endif
1340    #ifdef VERTEXCOLOR
1341    baseColor.rgb*=vColor.rgb;
1342    #endif
1343    #define CUSTOM_FRAGMENT_UPDATE_DIFFUSE
1344    
1345    vec3 baseAmbientColor=vec3(1.,1.,1.);
1346    #ifdef AMBIENT
1347    baseAmbientColor=texture(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;
1348    #endif
1349    #define CUSTOM_FRAGMENT_BEFORE_LIGHTS
1350    
1351    #ifdef SPECULARTERM
1352    float glossiness=vSpecularColor.a;
1353    vec3 specularColor=vSpecularColor.rgb;
1354    #ifdef SPECULAR
1355    vec4 specularMapColor=texture(specularSampler,vSpecularUV+uvOffset);
1356    specularColor=specularMapColor.rgb;
1357    #ifdef GLOSSINESS
1358    glossiness=glossiness*specularMapColor.a;
1359    #endif
1360    #endif
1361    #else
1362    float glossiness=0.;
1363    #endif
1364    
1365    vec3 diffuseBase=vec3(0.,0.,0.);
1366    lightingInfo info;
1367    #ifdef SPECULARTERM
1368    vec3 specularBase=vec3(0.,0.,0.);
1369    #endif
1370    float shadow=1.;
1371    #ifdef LIGHTMAP
1372    vec3 lightmapColor=texture(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;
1373    #endif
1374    #ifdef LIGHT0
1375    #if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED0) && defined(LIGHTMAPNOSPECULAR0))
1376    
1377    #else
1378    #ifdef PBR
1379    #ifdef SPOTLIGHT0
1380    info=computeSpotLighting(viewDirectionW,normalW,light0.vLightData,light0.vLightDirection,light0.vLightDiffuse.rgb,light0.vLightSpecular,light0.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1381    #endif
1382    #ifdef HEMILIGHT0
1383    info=computeHemisphericLighting(viewDirectionW,normalW,light0.vLightData,light0.vLightDiffuse.rgb,light0.vLightSpecular,light0.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1384    #endif
1385    #if defined(POINTLIGHT0) || defined(DIRLIGHT0)
1386    info=computeLighting(viewDirectionW,normalW,light0.vLightData,light0.vLightDiffuse.rgb,light0.vLightSpecular,light0.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1387    #endif
1388    #else
1389    #ifdef SPOTLIGHT0
1390    info=computeSpotLighting(viewDirectionW,normalW,light0.vLightData,light0.vLightDirection,light0.vLightDiffuse.rgb,light0.vLightSpecular,light0.vLightDiffuse.a,glossiness);
1391    #endif
1392    #ifdef HEMILIGHT0
1393    info=computeHemisphericLighting(viewDirectionW,normalW,light0.vLightData,light0.vLightDiffuse.rgb,light0.vLightSpecular,light0.vLightGround,glossiness);
1394    #endif
1395    #if defined(POINTLIGHT0) || defined(DIRLIGHT0)
1396    info=computeLighting(viewDirectionW,normalW,light0.vLightData,light0.vLightDiffuse.rgb,light0.vLightSpecular,light0.vLightDiffuse.a,glossiness);
1397    #endif
1398    #endif
1399    #ifdef PROJECTEDLIGHTTEXTURE0
1400    info.diffuse*=computeProjectionTextureDiffuseLighting(projectionLightSampler0,textureProjectionMatrix0);
1401    #endif
1402    #endif
1403    #ifdef SHADOW0
1404    #ifdef SHADOWCLOSEESM0
1405    #if defined(SHADOWCUBE0)
1406    shadow=computeShadowWithCloseESMCube(light0.vLightData.xyz,shadowSampler0,light0.shadowsInfo.x,light0.shadowsInfo.z,light0.depthValues);
1407    #else
1408    shadow=computeShadowWithCloseESM(vPositionFromLight0,vDepthMetric0,shadowSampler0,light0.shadowsInfo.x,light0.shadowsInfo.z,light0.shadowsInfo.w);
1409    #endif
1410    #elif defined(SHADOWESM0)
1411    #if defined(SHADOWCUBE0)
1412    shadow=computeShadowWithESMCube(light0.vLightData.xyz,shadowSampler0,light0.shadowsInfo.x,light0.shadowsInfo.z,light0.depthValues);
1413    #else
1414    shadow=computeShadowWithESM(vPositionFromLight0,vDepthMetric0,shadowSampler0,light0.shadowsInfo.x,light0.shadowsInfo.z,light0.shadowsInfo.w);
1415    #endif
1416    #elif defined(SHADOWPOISSON0)
1417    #if defined(SHADOWCUBE0)
1418    shadow=computeShadowWithPoissonSamplingCube(light0.vLightData.xyz,shadowSampler0,light0.shadowsInfo.y,light0.shadowsInfo.x,light0.depthValues);
1419    #else
1420    shadow=computeShadowWithPoissonSampling(vPositionFromLight0,vDepthMetric0,shadowSampler0,light0.shadowsInfo.y,light0.shadowsInfo.x,light0.shadowsInfo.w);
1421    #endif
1422    #elif defined(SHADOWPCF0)
1423    #if defined(SHADOWLOWQUALITY0)
1424    shadow=computeShadowWithPCF1(vPositionFromLight0,vDepthMetric0,shadowSampler0,light0.shadowsInfo.x,light0.shadowsInfo.w);
1425    #elif defined(SHADOWMEDIUMQUALITY0)
1426    shadow=computeShadowWithPCF3(vPositionFromLight0,vDepthMetric0,shadowSampler0,light0.shadowsInfo.yz,light0.shadowsInfo.x,light0.shadowsInfo.w);
1427    #else
1428    shadow=computeShadowWithPCF5(vPositionFromLight0,vDepthMetric0,shadowSampler0,light0.shadowsInfo.yz,light0.shadowsInfo.x,light0.shadowsInfo.w);
1429    #endif
1430    #elif defined(SHADOWPCSS0)
1431    #if defined(SHADOWLOWQUALITY0)
1432    shadow=computeShadowWithPCSS16(vPositionFromLight0,vDepthMetric0,depthSampler0,shadowSampler0,light0.shadowsInfo.y,light0.shadowsInfo.z,light0.shadowsInfo.x,light0.shadowsInfo.w);
1433    #elif defined(SHADOWMEDIUMQUALITY0)
1434    shadow=computeShadowWithPCSS32(vPositionFromLight0,vDepthMetric0,depthSampler0,shadowSampler0,light0.shadowsInfo.y,light0.shadowsInfo.z,light0.shadowsInfo.x,light0.shadowsInfo.w);
1435    #else
1436    shadow=computeShadowWithPCSS64(vPositionFromLight0,vDepthMetric0,depthSampler0,shadowSampler0,light0.shadowsInfo.y,light0.shadowsInfo.z,light0.shadowsInfo.x,light0.shadowsInfo.w);
1437    #endif
1438    #else
1439    #if defined(SHADOWCUBE0)
1440    shadow=computeShadowCube(light0.vLightData.xyz,shadowSampler0,light0.shadowsInfo.x,light0.depthValues);
1441    #else
1442    shadow=computeShadow(vPositionFromLight0,vDepthMetric0,shadowSampler0,light0.shadowsInfo.x,light0.shadowsInfo.w);
1443    #endif
1444    #endif
1445    #ifdef SHADOWONLY
1446    #ifndef SHADOWINUSE
1447    #define SHADOWINUSE
1448    #endif
1449    globalShadow+=shadow;
1450    shadowLightCount+=1.0;
1451    #endif
1452    #else
1453    shadow=1.;
1454    #endif
1455    #ifndef SHADOWONLY
1456    #ifdef CUSTOMUSERLIGHTING
1457    diffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);
1458    #ifdef SPECULARTERM
1459    specularBase+=computeCustomSpecularLighting(info,specularBase,shadow);
1460    #endif
1461    #elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED0)
1462    diffuseBase+=lightmapColor*shadow;
1463    #ifdef SPECULARTERM
1464    #ifndef LIGHTMAPNOSPECULAR0
1465    specularBase+=info.specular*shadow*lightmapColor;
1466    #endif
1467    #endif
1468    #else
1469    diffuseBase+=info.diffuse*shadow;
1470    #ifdef SPECULARTERM
1471    specularBase+=info.specular*shadow;
1472    #endif
1473    #endif
1474    #endif
1475    #endif
1476    #ifdef LIGHT1
1477    #if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED1) && defined(LIGHTMAPNOSPECULAR1))
1478    
1479    #else
1480    #ifdef PBR
1481    #ifdef SPOTLIGHT1
1482    info=computeSpotLighting(viewDirectionW,normalW,light1.vLightData,light1.vLightDirection,light1.vLightDiffuse.rgb,light1.vLightSpecular,light1.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1483    #endif
1484    #ifdef HEMILIGHT1
1485    info=computeHemisphericLighting(viewDirectionW,normalW,light1.vLightData,light1.vLightDiffuse.rgb,light1.vLightSpecular,light1.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1486    #endif
1487    #if defined(POINTLIGHT1) || defined(DIRLIGHT1)
1488    info=computeLighting(viewDirectionW,normalW,light1.vLightData,light1.vLightDiffuse.rgb,light1.vLightSpecular,light1.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1489    #endif
1490    #else
1491    #ifdef SPOTLIGHT1
1492    info=computeSpotLighting(viewDirectionW,normalW,light1.vLightData,light1.vLightDirection,light1.vLightDiffuse.rgb,light1.vLightSpecular,light1.vLightDiffuse.a,glossiness);
1493    #endif
1494    #ifdef HEMILIGHT1
1495    info=computeHemisphericLighting(viewDirectionW,normalW,light1.vLightData,light1.vLightDiffuse.rgb,light1.vLightSpecular,light1.vLightGround,glossiness);
1496    #endif
1497    #if defined(POINTLIGHT1) || defined(DIRLIGHT1)
1498    info=computeLighting(viewDirectionW,normalW,light1.vLightData,light1.vLightDiffuse.rgb,light1.vLightSpecular,light1.vLightDiffuse.a,glossiness);
1499    #endif
1500    #endif
1501    #ifdef PROJECTEDLIGHTTEXTURE1
1502    info.diffuse*=computeProjectionTextureDiffuseLighting(projectionLightSampler1,textureProjectionMatrix1);
1503    #endif
1504    #endif
1505    #ifdef SHADOW1
1506    #ifdef SHADOWCLOSEESM1
1507    #if defined(SHADOWCUBE1)
1508    shadow=computeShadowWithCloseESMCube(light1.vLightData.xyz,shadowSampler1,light1.shadowsInfo.x,light1.shadowsInfo.z,light1.depthValues);
1509    #else
1510    shadow=computeShadowWithCloseESM(vPositionFromLight1,vDepthMetric1,shadowSampler1,light1.shadowsInfo.x,light1.shadowsInfo.z,light1.shadowsInfo.w);
1511    #endif
1512    #elif defined(SHADOWESM1)
1513    #if defined(SHADOWCUBE1)
1514    shadow=computeShadowWithESMCube(light1.vLightData.xyz,shadowSampler1,light1.shadowsInfo.x,light1.shadowsInfo.z,light1.depthValues);
1515    #else
1516    shadow=computeShadowWithESM(vPositionFromLight1,vDepthMetric1,shadowSampler1,light1.shadowsInfo.x,light1.shadowsInfo.z,light1.shadowsInfo.w);
1517    #endif
1518    #elif defined(SHADOWPOISSON1)
1519    #if defined(SHADOWCUBE1)
1520    shadow=computeShadowWithPoissonSamplingCube(light1.vLightData.xyz,shadowSampler1,light1.shadowsInfo.y,light1.shadowsInfo.x,light1.depthValues);
1521    #else
1522    shadow=computeShadowWithPoissonSampling(vPositionFromLight1,vDepthMetric1,shadowSampler1,light1.shadowsInfo.y,light1.shadowsInfo.x,light1.shadowsInfo.w);
1523    #endif
1524    #elif defined(SHADOWPCF1)
1525    #if defined(SHADOWLOWQUALITY1)
1526    shadow=computeShadowWithPCF1(vPositionFromLight1,vDepthMetric1,shadowSampler1,light1.shadowsInfo.x,light1.shadowsInfo.w);
1527    #elif defined(SHADOWMEDIUMQUALITY1)
1528    shadow=computeShadowWithPCF3(vPositionFromLight1,vDepthMetric1,shadowSampler1,light1.shadowsInfo.yz,light1.shadowsInfo.x,light1.shadowsInfo.w);
1529    #else
1530    shadow=computeShadowWithPCF5(vPositionFromLight1,vDepthMetric1,shadowSampler1,light1.shadowsInfo.yz,light1.shadowsInfo.x,light1.shadowsInfo.w);
1531    #endif
1532    #elif defined(SHADOWPCSS1)
1533    #if defined(SHADOWLOWQUALITY1)
1534    shadow=computeShadowWithPCSS16(vPositionFromLight1,vDepthMetric1,depthSampler1,shadowSampler1,light1.shadowsInfo.y,light1.shadowsInfo.z,light1.shadowsInfo.x,light1.shadowsInfo.w);
1535    #elif defined(SHADOWMEDIUMQUALITY1)
1536    shadow=computeShadowWithPCSS32(vPositionFromLight1,vDepthMetric1,depthSampler1,shadowSampler1,light1.shadowsInfo.y,light1.shadowsInfo.z,light1.shadowsInfo.x,light1.shadowsInfo.w);
1537    #else
1538    shadow=computeShadowWithPCSS64(vPositionFromLight1,vDepthMetric1,depthSampler1,shadowSampler1,light1.shadowsInfo.y,light1.shadowsInfo.z,light1.shadowsInfo.x,light1.shadowsInfo.w);
1539    #endif
1540    #else
1541    #if defined(SHADOWCUBE1)
1542    shadow=computeShadowCube(light1.vLightData.xyz,shadowSampler1,light1.shadowsInfo.x,light1.depthValues);
1543    #else
1544    shadow=computeShadow(vPositionFromLight1,vDepthMetric1,shadowSampler1,light1.shadowsInfo.x,light1.shadowsInfo.w);
1545    #endif
1546    #endif
1547    #ifdef SHADOWONLY
1548    #ifndef SHADOWINUSE
1549    #define SHADOWINUSE
1550    #endif
1551    globalShadow+=shadow;
1552    shadowLightCount+=1.0;
1553    #endif
1554    #else
1555    shadow=1.;
1556    #endif
1557    #ifndef SHADOWONLY
1558    #ifdef CUSTOMUSERLIGHTING
1559    diffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);
1560    #ifdef SPECULARTERM
1561    specularBase+=computeCustomSpecularLighting(info,specularBase,shadow);
1562    #endif
1563    #elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED1)
1564    diffuseBase+=lightmapColor*shadow;
1565    #ifdef SPECULARTERM
1566    #ifndef LIGHTMAPNOSPECULAR1
1567    specularBase+=info.specular*shadow*lightmapColor;
1568    #endif
1569    #endif
1570    #else
1571    diffuseBase+=info.diffuse*shadow;
1572    #ifdef SPECULARTERM
1573    specularBase+=info.specular*shadow;
1574    #endif
1575    #endif
1576    #endif
1577    #endif
1578    #ifdef LIGHT2
1579    #if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED2) && defined(LIGHTMAPNOSPECULAR2))
1580    
1581    #else
1582    #ifdef PBR
1583    #ifdef SPOTLIGHT2
1584    info=computeSpotLighting(viewDirectionW,normalW,light2.vLightData,light2.vLightDirection,light2.vLightDiffuse.rgb,light2.vLightSpecular,light2.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1585    #endif
1586    #ifdef HEMILIGHT2
1587    info=computeHemisphericLighting(viewDirectionW,normalW,light2.vLightData,light2.vLightDiffuse.rgb,light2.vLightSpecular,light2.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1588    #endif
1589    #if defined(POINTLIGHT2) || defined(DIRLIGHT2)
1590    info=computeLighting(viewDirectionW,normalW,light2.vLightData,light2.vLightDiffuse.rgb,light2.vLightSpecular,light2.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1591    #endif
1592    #else
1593    #ifdef SPOTLIGHT2
1594    info=computeSpotLighting(viewDirectionW,normalW,light2.vLightData,light2.vLightDirection,light2.vLightDiffuse.rgb,light2.vLightSpecular,light2.vLightDiffuse.a,glossiness);
1595    #endif
1596    #ifdef HEMILIGHT2
1597    info=computeHemisphericLighting(viewDirectionW,normalW,light2.vLightData,light2.vLightDiffuse.rgb,light2.vLightSpecular,light2.vLightGround,glossiness);
1598    #endif
1599    #if defined(POINTLIGHT2) || defined(DIRLIGHT2)
1600    info=computeLighting(viewDirectionW,normalW,light2.vLightData,light2.vLightDiffuse.rgb,light2.vLightSpecular,light2.vLightDiffuse.a,glossiness);
1601    #endif
1602    #endif
1603    #ifdef PROJECTEDLIGHTTEXTURE2
1604    info.diffuse*=computeProjectionTextureDiffuseLighting(projectionLightSampler2,textureProjectionMatrix2);
1605    #endif
1606    #endif
1607    #ifdef SHADOW2
1608    #ifdef SHADOWCLOSEESM2
1609    #if defined(SHADOWCUBE2)
1610    shadow=computeShadowWithCloseESMCube(light2.vLightData.xyz,shadowSampler2,light2.shadowsInfo.x,light2.shadowsInfo.z,light2.depthValues);
1611    #else
1612    shadow=computeShadowWithCloseESM(vPositionFromLight2,vDepthMetric2,shadowSampler2,light2.shadowsInfo.x,light2.shadowsInfo.z,light2.shadowsInfo.w);
1613    #endif
1614    #elif defined(SHADOWESM2)
1615    #if defined(SHADOWCUBE2)
1616    shadow=computeShadowWithESMCube(light2.vLightData.xyz,shadowSampler2,light2.shadowsInfo.x,light2.shadowsInfo.z,light2.depthValues);
1617    #else
1618    shadow=computeShadowWithESM(vPositionFromLight2,vDepthMetric2,shadowSampler2,light2.shadowsInfo.x,light2.shadowsInfo.z,light2.shadowsInfo.w);
1619    #endif
1620    #elif defined(SHADOWPOISSON2)
1621    #if defined(SHADOWCUBE2)
1622    shadow=computeShadowWithPoissonSamplingCube(light2.vLightData.xyz,shadowSampler2,light2.shadowsInfo.y,light2.shadowsInfo.x,light2.depthValues);
1623    #else
1624    shadow=computeShadowWithPoissonSampling(vPositionFromLight2,vDepthMetric2,shadowSampler2,light2.shadowsInfo.y,light2.shadowsInfo.x,light2.shadowsInfo.w);
1625    #endif
1626    #elif defined(SHADOWPCF2)
1627    #if defined(SHADOWLOWQUALITY2)
1628    shadow=computeShadowWithPCF1(vPositionFromLight2,vDepthMetric2,shadowSampler2,light2.shadowsInfo.x,light2.shadowsInfo.w);
1629    #elif defined(SHADOWMEDIUMQUALITY2)
1630    shadow=computeShadowWithPCF3(vPositionFromLight2,vDepthMetric2,shadowSampler2,light2.shadowsInfo.yz,light2.shadowsInfo.x,light2.shadowsInfo.w);
1631    #else
1632    shadow=computeShadowWithPCF5(vPositionFromLight2,vDepthMetric2,shadowSampler2,light2.shadowsInfo.yz,light2.shadowsInfo.x,light2.shadowsInfo.w);
1633    #endif
1634    #elif defined(SHADOWPCSS2)
1635    #if defined(SHADOWLOWQUALITY2)
1636    shadow=computeShadowWithPCSS16(vPositionFromLight2,vDepthMetric2,depthSampler2,shadowSampler2,light2.shadowsInfo.y,light2.shadowsInfo.z,light2.shadowsInfo.x,light2.shadowsInfo.w);
1637    #elif defined(SHADOWMEDIUMQUALITY2)
1638    shadow=computeShadowWithPCSS32(vPositionFromLight2,vDepthMetric2,depthSampler2,shadowSampler2,light2.shadowsInfo.y,light2.shadowsInfo.z,light2.shadowsInfo.x,light2.shadowsInfo.w);
1639    #else
1640    shadow=computeShadowWithPCSS64(vPositionFromLight2,vDepthMetric2,depthSampler2,shadowSampler2,light2.shadowsInfo.y,light2.shadowsInfo.z,light2.shadowsInfo.x,light2.shadowsInfo.w);
1641    #endif
1642    #else
1643    #if defined(SHADOWCUBE2)
1644    shadow=computeShadowCube(light2.vLightData.xyz,shadowSampler2,light2.shadowsInfo.x,light2.depthValues);
1645    #else
1646    shadow=computeShadow(vPositionFromLight2,vDepthMetric2,shadowSampler2,light2.shadowsInfo.x,light2.shadowsInfo.w);
1647    #endif
1648    #endif
1649    #ifdef SHADOWONLY
1650    #ifndef SHADOWINUSE
1651    #define SHADOWINUSE
1652    #endif
1653    globalShadow+=shadow;
1654    shadowLightCount+=1.0;
1655    #endif
1656    #else
1657    shadow=1.;
1658    #endif
1659    #ifndef SHADOWONLY
1660    #ifdef CUSTOMUSERLIGHTING
1661    diffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);
1662    #ifdef SPECULARTERM
1663    specularBase+=computeCustomSpecularLighting(info,specularBase,shadow);
1664    #endif
1665    #elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED2)
1666    diffuseBase+=lightmapColor*shadow;
1667    #ifdef SPECULARTERM
1668    #ifndef LIGHTMAPNOSPECULAR2
1669    specularBase+=info.specular*shadow*lightmapColor;
1670    #endif
1671    #endif
1672    #else
1673    diffuseBase+=info.diffuse*shadow;
1674    #ifdef SPECULARTERM
1675    specularBase+=info.specular*shadow;
1676    #endif
1677    #endif
1678    #endif
1679    #endif
1680    #ifdef LIGHT3
1681    #if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED3) && defined(LIGHTMAPNOSPECULAR3))
1682    
1683    #else
1684    #ifdef PBR
1685    #ifdef SPOTLIGHT3
1686    info=computeSpotLighting(viewDirectionW,normalW,light3.vLightData,light3.vLightDirection,light3.vLightDiffuse.rgb,light3.vLightSpecular,light3.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1687    #endif
1688    #ifdef HEMILIGHT3
1689    info=computeHemisphericLighting(viewDirectionW,normalW,light3.vLightData,light3.vLightDiffuse.rgb,light3.vLightSpecular,light3.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1690    #endif
1691    #if defined(POINTLIGHT3) || defined(DIRLIGHT3)
1692    info=computeLighting(viewDirectionW,normalW,light3.vLightData,light3.vLightDiffuse.rgb,light3.vLightSpecular,light3.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,geometricRoughnessFactor,NdotL);
1693    #endif
1694    #else
1695    #ifdef SPOTLIGHT3
1696    info=computeSpotLighting(viewDirectionW,normalW,light3.vLightData,light3.vLightDirection,light3.vLightDiffuse.rgb,light3.vLightSpecular,light3.vLightDiffuse.a,glossiness);
1697    #endif
1698    #ifdef HEMILIGHT3
1699    info=computeHemisphericLighting(viewDirectionW,normalW,light3.vLightData,light3.vLightDiffuse.rgb,light3.vLightSpecular,light3.vLightGround,glossiness);
1700    #endif
1701    #if defined(POINTLIGHT3) || defined(DIRLIGHT3)
1702    info=computeLighting(viewDirectionW,normalW,light3.vLightData,light3.vLightDiffuse.rgb,light3.vLightSpecular,light3.vLightDiffuse.a,glossiness);
1703    #endif
1704    #endif
1705    #ifdef PROJECTEDLIGHTTEXTURE3
1706    info.diffuse*=computeProjectionTextureDiffuseLighting(projectionLightSampler3,textureProjectionMatrix3);
1707    #endif
1708    #endif
1709    #ifdef SHADOW3
1710    #ifdef SHADOWCLOSEESM3
1711    #if defined(SHADOWCUBE3)
1712    shadow=computeShadowWithCloseESMCube(light3.vLightData.xyz,shadowSampler3,light3.shadowsInfo.x,light3.shadowsInfo.z,light3.depthValues);
1713    #else
1714    shadow=computeShadowWithCloseESM(vPositionFromLight3,vDepthMetric3,shadowSampler3,light3.shadowsInfo.x,light3.shadowsInfo.z,light3.shadowsInfo.w);
1715    #endif
1716    #elif defined(SHADOWESM3)
1717    #if defined(SHADOWCUBE3)
1718    shadow=computeShadowWithESMCube(light3.vLightData.xyz,shadowSampler3,light3.shadowsInfo.x,light3.shadowsInfo.z,light3.depthValues);
1719    #else
1720    shadow=computeShadowWithESM(vPositionFromLight3,vDepthMetric3,shadowSampler3,light3.shadowsInfo.x,light3.shadowsInfo.z,light3.shadowsInfo.w);
1721    #endif
1722    #elif defined(SHADOWPOISSON3)
1723    #if defined(SHADOWCUBE3)
1724    shadow=computeShadowWithPoissonSamplingCube(light3.vLightData.xyz,shadowSampler3,light3.shadowsInfo.y,light3.shadowsInfo.x,light3.depthValues);
1725    #else
1726    shadow=computeShadowWithPoissonSampling(vPositionFromLight3,vDepthMetric3,shadowSampler3,light3.shadowsInfo.y,light3.shadowsInfo.x,light3.shadowsInfo.w);
1727    #endif
1728    #elif defined(SHADOWPCF3)
1729    #if defined(SHADOWLOWQUALITY3)
1730    shadow=computeShadowWithPCF1(vPositionFromLight3,vDepthMetric3,shadowSampler3,light3.shadowsInfo.x,light3.shadowsInfo.w);
1731    #elif defined(SHADOWMEDIUMQUALITY3)
1732    shadow=computeShadowWithPCF3(vPositionFromLight3,vDepthMetric3,shadowSampler3,light3.shadowsInfo.yz,light3.shadowsInfo.x,light3.shadowsInfo.w);
1733    #else
1734    shadow=computeShadowWithPCF5(vPositionFromLight3,vDepthMetric3,shadowSampler3,light3.shadowsInfo.yz,light3.shadowsInfo.x,light3.shadowsInfo.w);
1735    #endif
1736    #elif defined(SHADOWPCSS3)
1737    #if defined(SHADOWLOWQUALITY3)
1738    shadow=computeShadowWithPCSS16(vPositionFromLight3,vDepthMetric3,depthSampler3,shadowSampler3,light3.shadowsInfo.y,light3.shadowsInfo.z,light3.shadowsInfo.x,light3.shadowsInfo.w);
1739    #elif defined(SHADOWMEDIUMQUALITY3)
1740    shadow=computeShadowWithPCSS32(vPositionFromLight3,vDepthMetric3,depthSampler3,shadowSampler3,light3.shadowsInfo.y,light3.shadowsInfo.z,light3.shadowsInfo.x,light3.shadowsInfo.w);
1741    #else
1742    shadow=computeShadowWithPCSS64(vPositionFromLight3,vDepthMetric3,depthSampler3,shadowSampler3,light3.shadowsInfo.y,light3.shadowsInfo.z,light3.shadowsInfo.x,light3.shadowsInfo.w);
1743    #endif
1744    #else
1745    #if defined(SHADOWCUBE3)
1746    shadow=computeShadowCube(light3.vLightData.xyz,shadowSampler3,light3.shadowsInfo.x,light3.depthValues);
1747    #else
1748    shadow=computeShadow(vPositionFromLight3,vDepthMetric3,shadowSampler3,light3.shadowsInfo.x,light3.shadowsInfo.w);
1749    #endif
1750    #endif
1751    #ifdef SHADOWONLY
1752    #ifndef SHADOWINUSE
1753    #define SHADOWINUSE
1754    #endif
1755    globalShadow+=shadow;
1756    shadowLightCount+=1.0;
1757    #endif
1758    #else
1759    shadow=1.;
1760    #endif
1761    #ifndef SHADOWONLY
1762    #ifdef CUSTOMUSERLIGHTING
1763    diffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);
1764    #ifdef SPECULARTERM
1765    specularBase+=computeCustomSpecularLighting(info,specularBase,shadow);
1766    #endif
1767    #elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED3)
1768    diffuseBase+=lightmapColor*shadow;
1769    #ifdef SPECULARTERM
1770    #ifndef LIGHTMAPNOSPECULAR3
1771    specularBase+=info.specular*shadow*lightmapColor;
1772    #endif
1773    #endif
1774    #else
1775    diffuseBase+=info.diffuse*shadow;
1776    #ifdef SPECULARTERM
1777    specularBase+=info.specular*shadow;
1778    #endif
1779    #endif
1780    #endif
1781    #endif
1782    
1783    
1784    vec3 refractionColor=vec3(0.,0.,0.);
1785    #ifdef REFRACTION
1786    vec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));
1787    #ifdef REFRACTIONMAP_3D
1788    refractionVector.y=refractionVector.y*vRefractionInfos.w;
1789    if (dot(refractionVector,viewDirectionW)<1.0) {
1790    refractionColor=texture(refractionCubeSampler,refractionVector).rgb;
1791    }
1792    #else
1793    vec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));
1794    vec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;
1795    refractionCoords.y=1.0-refractionCoords.y;
1796    refractionColor=texture(refraction2DSampler,refractionCoords).rgb;
1797    #endif
1798    #ifdef IS_REFRACTION_LINEAR
1799    refractionColor=toGammaSpace(refractionColor);
1800    #endif
1801    refractionColor*=vRefractionInfos.x;
1802    #endif
1803    
1804    vec3 reflectionColor=vec3(0.,0.,0.);
1805    #ifdef REFLECTION
1806    vec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);
1807    #ifdef REFLECTIONMAP_3D
1808    #ifdef ROUGHNESS
1809    float bias=vReflectionInfos.y;
1810    #ifdef SPECULARTERM
1811    #ifdef SPECULAR
1812    #ifdef GLOSSINESS
1813    bias*=(1.0-specularMapColor.a);
1814    #endif
1815    #endif
1816    #endif
1817    reflectionColor=texture(reflectionCubeSampler,vReflectionUVW,bias).rgb;
1818    #else
1819    reflectionColor=texture(reflectionCubeSampler,vReflectionUVW).rgb;
1820    #endif
1821    #else
1822    vec2 coords=vReflectionUVW.xy;
1823    #ifdef REFLECTIONMAP_PROJECTION
1824    coords/=vReflectionUVW.z;
1825    #endif
1826    coords.y=1.0-coords.y;
1827    reflectionColor=texture(reflection2DSampler,coords).rgb;
1828    #endif
1829    #ifdef IS_REFLECTION_LINEAR
1830    reflectionColor=toGammaSpace(reflectionColor);
1831    #endif
1832    reflectionColor*=vReflectionInfos.x;
1833    #ifdef REFLECTIONFRESNEL
1834    float reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);
1835    #ifdef REFLECTIONFRESNELFROMSPECULAR
1836    #ifdef SPECULARTERM
1837    reflectionColor*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;
1838    #else
1839    reflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;
1840    #endif
1841    #else
1842    reflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;
1843    #endif
1844    #endif
1845    #endif
1846    #ifdef REFRACTIONFRESNEL
1847    float refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);
1848    refractionColor*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;
1849    #endif
1850    #ifdef OPACITY
1851    vec4 opacityMap=texture(opacitySampler,vOpacityUV+uvOffset);
1852    #ifdef OPACITYRGB
1853    opacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);
1854    alpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;
1855    #else
1856    alpha*=opacityMap.a*vOpacityInfos.y;
1857    #endif
1858    #endif
1859    #ifdef VERTEXALPHA
1860    alpha*=vColor.a;
1861    #endif
1862    #ifdef OPACITYFRESNEL
1863    float opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);
1864    alpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;
1865    #endif
1866    
1867    vec3 emissiveColor=vEmissiveColor;
1868    #ifdef EMISSIVE
1869    emissiveColor+=texture(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;
1870    #endif
1871    #ifdef EMISSIVEFRESNEL
1872    float emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);
1873    emissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;
1874    #endif
1875    
1876    #ifdef DIFFUSEFRESNEL
1877    float diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);
1878    diffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;
1879    #endif
1880    
1881    #ifdef EMISSIVEASILLUMINATION
1882    vec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;
1883    #else
1884    #ifdef LINKEMISSIVEWITHDIFFUSE
1885    vec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;
1886    #else
1887    vec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;
1888    #endif
1889    #endif
1890    #ifdef SPECULARTERM
1891    vec3 finalSpecular=specularBase*specularColor;
1892    #ifdef SPECULAROVERALPHA
1893    alpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);
1894    #endif
1895    #else
1896    vec3 finalSpecular=vec3(0.0);
1897    #endif
1898    #ifdef REFLECTIONOVERALPHA
1899    alpha=clamp(alpha+dot(reflectionColor,vec3(0.3,0.59,0.11)),0.,1.);
1900    #endif
1901    
1902    #ifdef EMISSIVEASILLUMINATION
1903    vec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+emissiveColor+refractionColor,0.0,1.0),alpha);
1904    #else
1905    vec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+refractionColor,alpha);
1906    #endif
1907    
1908    #ifdef LIGHTMAP
1909    #ifndef LIGHTMAPEXCLUDED
1910    #ifdef USELIGHTMAPASSHADOWMAP
1911    color.rgb*=lightmapColor;
1912    #else
1913    color.rgb+=lightmapColor;
1914    #endif
1915    #endif
1916    #endif
1917    #define CUSTOM_FRAGMENT_BEFORE_FOG
1918    color.rgb=max(color.rgb,0.);
1919    #ifdef LOGARITHMICDEPTH
1920    gl_FragDepth=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;
1921    #endif
1922    #ifdef FOG
1923    float fog=CalcFogFactor();
1924    color.rgb=fog*color.rgb+(1.0-fog)*vFogColor;
1925    #endif
1926    
1927    
1928    #ifdef IMAGEPROCESSINGPOSTPROCESS
1929    color.rgb=toLinearSpace(color.rgb);
1930    #else
1931    #ifdef IMAGEPROCESSING
1932    color.rgb=toLinearSpace(color.rgb);
1933    color=applyImageProcessing(color);
1934    #endif
1935    #endif
1936    #ifdef PREMULTIPLYALPHA
1937    
1938    color.rgb*=color.a;
1939    #endif
1940    #define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR
1941    glFragColor=color;
1942    }
1943    

 

BJS - [21:02:28]: Error: 0:82: S0032: no default precision defined for parameter 'webgl_4aeb46af4241331f'

Link to comment
Share on other sites

Hmm well its a normal Samsung Galaxy S7 with Chrome browser, its more the question if this is happen with all android phones or with all Galaxy S7 / 8 / 9. For my case its fine to just disable "usePercentageCloserFiltering" but in the future i am perhaps not the only one that jump in this problem. So there should perhaps some switch to webgl1 or some Information in the error message how to prevent this error. 

Link to comment
Share on other sites

Unfortunately we have no control on that. This is at driver / browser level. The browser declares it support webgl2 so we turn it on but they have bugs so for now on the mobile space it could be safer to turn off webgl2 until they stabilize it 

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...

Hi, this post is a bit dated but saved me lots of time. Thanks for posting!

It's 2020 and I'm still having issues with some versions of Android (tested on some models, not all, of Samsung and Huawei phones). Chrome version doesn't seem to change anything.

Luckily there is a solution other than disabling PCF. Babylon 4.1 (released yesterday) comes with cascaded shadow maps (see https://doc.babylonjs.com/babylon101/shadows_csm) which is almost drop in API compatible with the normal shadow map generator and doesn't suffer the same issue even with PC ?.

I'm guessing the underlying calls to webgl are a bit different and we happen to be lucky. Tip: if no shadow appears with CSM, remember to set your camera's maxZ value.

Hope this can help others :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...