@graphty/graphty-element 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/basisTextureLoader-BqIvxvNl.js +312 -0
- package/dist/basisTextureLoader-BqIvxvNl.js.map +1 -0
- package/dist/custom-elements.json +1 -0
- package/dist/dds-BlAaKjyJ.js +357 -0
- package/dist/dds-BlAaKjyJ.js.map +1 -0
- package/dist/ddsTextureLoader-D7Jh83wc.js +44 -0
- package/dist/ddsTextureLoader-D7Jh83wc.js.map +1 -0
- package/dist/default.fragment-BNc4beoN.js +452 -0
- package/dist/default.fragment-BNc4beoN.js.map +1 -0
- package/dist/default.fragment-CSeCDRwv.js +512 -0
- package/dist/default.fragment-CSeCDRwv.js.map +1 -0
- package/dist/default.vertex-9pBFrn06.js +202 -0
- package/dist/default.vertex-9pBFrn06.js.map +1 -0
- package/dist/default.vertex-DDjK1DRv.js +185 -0
- package/dist/default.vertex-DDjK1DRv.js.map +1 -0
- package/dist/defaultUboDeclaration-CG47IDRY.js +9 -0
- package/dist/defaultUboDeclaration-CG47IDRY.js.map +1 -0
- package/dist/defaultUboDeclaration-Ct5CiQ-w.js +11 -0
- package/dist/defaultUboDeclaration-Ct5CiQ-w.js.map +1 -0
- package/dist/dumpTools-DA1xMSIZ.js +103 -0
- package/dist/dumpTools-DA1xMSIZ.js.map +1 -0
- package/dist/envTextureLoader-DdCLpySN.js +238 -0
- package/dist/envTextureLoader-DdCLpySN.js.map +1 -0
- package/dist/exrTextureLoader-CnJSRQ9w.js +741 -0
- package/dist/exrTextureLoader-CnJSRQ9w.js.map +1 -0
- package/dist/graphty.js +12 -0
- package/dist/graphty.js.map +1 -0
- package/dist/graphty.umd.cjs +12657 -0
- package/dist/graphty.umd.cjs.map +1 -0
- package/dist/greasedLine.fragment-BZnGGe-r.js +30 -0
- package/dist/greasedLine.fragment-BZnGGe-r.js.map +1 -0
- package/dist/greasedLine.fragment-DixuqXus.js +12 -0
- package/dist/greasedLine.fragment-DixuqXus.js.map +1 -0
- package/dist/greasedLine.vertex-BhhwFKPy.js +33 -0
- package/dist/greasedLine.vertex-BhhwFKPy.js.map +1 -0
- package/dist/greasedLine.vertex-DIhgGSOi.js +49 -0
- package/dist/greasedLine.vertex-DIhgGSOi.js.map +1 -0
- package/dist/harmonicsFunctions-B9jTNKTF.js +197 -0
- package/dist/harmonicsFunctions-B9jTNKTF.js.map +1 -0
- package/dist/harmonicsFunctions-D9ZL5yLA.js +194 -0
- package/dist/harmonicsFunctions-D9ZL5yLA.js.map +1 -0
- package/dist/hdrTextureLoader-DreWCvHD.js +112 -0
- package/dist/hdrTextureLoader-DreWCvHD.js.map +1 -0
- package/dist/helperFunctions-Dh1WD8YN.js +106 -0
- package/dist/helperFunctions-Dh1WD8YN.js.map +1 -0
- package/dist/helperFunctions-ZBnqb-in.js +79 -0
- package/dist/helperFunctions-ZBnqb-in.js.map +1 -0
- package/dist/iesTextureLoader-JdfAyRK-.js +94 -0
- package/dist/iesTextureLoader-JdfAyRK-.js.map +1 -0
- package/dist/index-ChGTkj2q.js +62191 -0
- package/dist/index-ChGTkj2q.js.map +1 -0
- package/dist/instancesVertex-BrWNnWxF.js +46 -0
- package/dist/instancesVertex-BrWNnWxF.js.map +1 -0
- package/dist/instancesVertex-evcSIvCA.js +55 -0
- package/dist/instancesVertex-evcSIvCA.js.map +1 -0
- package/dist/ktxTextureLoader-Dg1h0a-4.js +520 -0
- package/dist/ktxTextureLoader-Dg1h0a-4.js.map +1 -0
- package/dist/logDepthDeclaration-BHUUDd5l.js +12 -0
- package/dist/logDepthDeclaration-BHUUDd5l.js.map +1 -0
- package/dist/logDepthDeclaration-Bou5AJOP.js +28 -0
- package/dist/logDepthDeclaration-Bou5AJOP.js.map +1 -0
- package/dist/logDepthVertex-CCFGLExi.js +496 -0
- package/dist/logDepthVertex-CCFGLExi.js.map +1 -0
- package/dist/logDepthVertex-r_niddz9.js +496 -0
- package/dist/logDepthVertex-r_niddz9.js.map +1 -0
- package/dist/mesh.vertexData.functions-Bc9lJlrU.js +75 -0
- package/dist/mesh.vertexData.functions-Bc9lJlrU.js.map +1 -0
- package/dist/meshUboDeclaration-Dg__Mhmj.js +18 -0
- package/dist/meshUboDeclaration-Dg__Mhmj.js.map +1 -0
- package/dist/oitFragment-Bn29Ggvj.js +1191 -0
- package/dist/oitFragment-Bn29Ggvj.js.map +1 -0
- package/dist/oitFragment-D6JBEGk0.js +1328 -0
- package/dist/oitFragment-D6JBEGk0.js.map +1 -0
- package/dist/pass.fragment-C9O4ZLJL.js +11 -0
- package/dist/pass.fragment-C9O4ZLJL.js.map +1 -0
- package/dist/pass.fragment-Cf0ob1Y3.js +11 -0
- package/dist/pass.fragment-Cf0ob1Y3.js.map +1 -0
- package/dist/passCube.fragment-Mg8Qj5T9.js +30 -0
- package/dist/passCube.fragment-Mg8Qj5T9.js.map +1 -0
- package/dist/passCube.fragment-uM4B7TOI.js +30 -0
- package/dist/passCube.fragment-uM4B7TOI.js.map +1 -0
- package/dist/pbr.fragment-C8Lm3cwF.js +3176 -0
- package/dist/pbr.fragment-C8Lm3cwF.js.map +1 -0
- package/dist/pbr.fragment-siOdCYqI.js +3219 -0
- package/dist/pbr.fragment-siOdCYqI.js.map +1 -0
- package/dist/pbr.vertex-Bw_TrGQv.js +229 -0
- package/dist/pbr.vertex-Bw_TrGQv.js.map +1 -0
- package/dist/pbr.vertex-CmEPCcBW.js +365 -0
- package/dist/pbr.vertex-CmEPCcBW.js.map +1 -0
- package/dist/postprocess.vertex-B086G8mM.js +16 -0
- package/dist/postprocess.vertex-B086G8mM.js.map +1 -0
- package/dist/rgbdDecode.fragment-bNaGtQ-x.js +9 -0
- package/dist/rgbdDecode.fragment-bNaGtQ-x.js.map +1 -0
- package/dist/rgbdDecode.fragment-koAcppx0.js +9 -0
- package/dist/rgbdDecode.fragment-koAcppx0.js.map +1 -0
- package/dist/rgbdEncode.fragment-BDHL2P_i.js +9 -0
- package/dist/rgbdEncode.fragment-BDHL2P_i.js.map +1 -0
- package/dist/rgbdEncode.fragment-Dw0FS9aH.js +9 -0
- package/dist/rgbdEncode.fragment-Dw0FS9aH.js.map +1 -0
- package/dist/tgaTextureLoader-DIfkfgQh.js +199 -0
- package/dist/tgaTextureLoader-DIfkfgQh.js.map +1 -0
- package/package.json +124 -0
|
@@ -0,0 +1,1328 @@
|
|
|
1
|
+
import { S as e } from "./index-ChGTkj2q.js";
|
|
2
|
+
const o = "decalFragmentDeclaration", x = `#ifdef DECAL
|
|
3
|
+
uniform vec4 vDecalInfos;
|
|
4
|
+
#endif
|
|
5
|
+
`;
|
|
6
|
+
e.IncludesShadersStore[o] || (e.IncludesShadersStore[o] = x);
|
|
7
|
+
const t = "prePassDeclaration", E = `#ifdef PREPASS
|
|
8
|
+
#extension GL_EXT_draw_buffers : require
|
|
9
|
+
layout(location=0) out highp vec4 glFragData[{X}];highp vec4 gl_FragColor;
|
|
10
|
+
#ifdef PREPASS_LOCAL_POSITION
|
|
11
|
+
varying highp vec3 vPosition;
|
|
12
|
+
#endif
|
|
13
|
+
#ifdef PREPASS_DEPTH
|
|
14
|
+
varying highp vec3 vViewPos;
|
|
15
|
+
#endif
|
|
16
|
+
#ifdef PREPASS_NORMALIZED_VIEW_DEPTH
|
|
17
|
+
varying highp float vNormViewDepth;
|
|
18
|
+
#endif
|
|
19
|
+
#if defined(PREPASS_VELOCITY) || defined(PREPASS_VELOCITY_LINEAR)
|
|
20
|
+
varying highp vec4 vCurrentPosition;varying highp vec4 vPreviousPosition;
|
|
21
|
+
#endif
|
|
22
|
+
#endif
|
|
23
|
+
`;
|
|
24
|
+
e.IncludesShadersStore[t] || (e.IncludesShadersStore[t] = E);
|
|
25
|
+
const i = "oitDeclaration", I = `#ifdef ORDER_INDEPENDENT_TRANSPARENCY
|
|
26
|
+
#extension GL_EXT_draw_buffers : require
|
|
27
|
+
layout(location=0) out vec2 depth;
|
|
28
|
+
layout(location=1) out vec4 frontColor;layout(location=2) out vec4 backColor;
|
|
29
|
+
#define MAX_DEPTH 99999.0
|
|
30
|
+
highp vec4 gl_FragColor;uniform sampler2D oitDepthSampler;uniform sampler2D oitFrontColorSampler;
|
|
31
|
+
#endif
|
|
32
|
+
`;
|
|
33
|
+
e.IncludesShadersStore[i] || (e.IncludesShadersStore[i] = I);
|
|
34
|
+
const a = "lightFragmentDeclaration", T = `#ifdef LIGHT{X}
|
|
35
|
+
uniform vec4 vLightData{X};uniform vec4 vLightDiffuse{X};
|
|
36
|
+
#ifdef SPECULARTERM
|
|
37
|
+
uniform vec4 vLightSpecular{X};
|
|
38
|
+
#else
|
|
39
|
+
vec4 vLightSpecular{X}=vec4(0.);
|
|
40
|
+
#endif
|
|
41
|
+
#ifdef SHADOW{X}
|
|
42
|
+
#ifdef SHADOWCSM{X}
|
|
43
|
+
uniform mat4 lightMatrix{X}[SHADOWCSMNUM_CASCADES{X}];uniform float viewFrustumZ{X}[SHADOWCSMNUM_CASCADES{X}];uniform float frustumLengths{X}[SHADOWCSMNUM_CASCADES{X}];uniform float cascadeBlendFactor{X};varying vec4 vPositionFromLight{X}[SHADOWCSMNUM_CASCADES{X}];varying float vDepthMetric{X}[SHADOWCSMNUM_CASCADES{X}];varying vec4 vPositionFromCamera{X};
|
|
44
|
+
#if defined(SHADOWPCSS{X})
|
|
45
|
+
uniform highp sampler2DArrayShadow shadowTexture{X};uniform highp sampler2DArray depthTexture{X};uniform vec2 lightSizeUVCorrection{X}[SHADOWCSMNUM_CASCADES{X}];uniform float depthCorrection{X}[SHADOWCSMNUM_CASCADES{X}];uniform float penumbraDarkness{X};
|
|
46
|
+
#elif defined(SHADOWPCF{X})
|
|
47
|
+
uniform highp sampler2DArrayShadow shadowTexture{X};
|
|
48
|
+
#else
|
|
49
|
+
uniform highp sampler2DArray shadowTexture{X};
|
|
50
|
+
#endif
|
|
51
|
+
#ifdef SHADOWCSMDEBUG{X}
|
|
52
|
+
const vec3 vCascadeColorsMultiplier{X}[8]=vec3[8]
|
|
53
|
+
(
|
|
54
|
+
vec3 ( 1.5,0.0,0.0 ),
|
|
55
|
+
vec3 ( 0.0,1.5,0.0 ),
|
|
56
|
+
vec3 ( 0.0,0.0,5.5 ),
|
|
57
|
+
vec3 ( 1.5,0.0,5.5 ),
|
|
58
|
+
vec3 ( 1.5,1.5,0.0 ),
|
|
59
|
+
vec3 ( 1.0,1.0,1.0 ),
|
|
60
|
+
vec3 ( 0.0,1.0,5.5 ),
|
|
61
|
+
vec3 ( 0.5,3.5,0.75 )
|
|
62
|
+
);vec3 shadowDebug{X};
|
|
63
|
+
#endif
|
|
64
|
+
#ifdef SHADOWCSMUSESHADOWMAXZ{X}
|
|
65
|
+
int index{X}=-1;
|
|
66
|
+
#else
|
|
67
|
+
int index{X}=SHADOWCSMNUM_CASCADES{X}-1;
|
|
68
|
+
#endif
|
|
69
|
+
float diff{X}=0.;
|
|
70
|
+
#elif defined(SHADOWCUBE{X})
|
|
71
|
+
uniform samplerCube shadowTexture{X};
|
|
72
|
+
#else
|
|
73
|
+
varying vec4 vPositionFromLight{X};varying float vDepthMetric{X};
|
|
74
|
+
#if defined(SHADOWPCSS{X})
|
|
75
|
+
uniform highp sampler2DShadow shadowTexture{X};uniform highp sampler2D depthTexture{X};
|
|
76
|
+
#elif defined(SHADOWPCF{X})
|
|
77
|
+
uniform highp sampler2DShadow shadowTexture{X};
|
|
78
|
+
#else
|
|
79
|
+
uniform sampler2D shadowTexture{X};
|
|
80
|
+
#endif
|
|
81
|
+
uniform mat4 lightMatrix{X};
|
|
82
|
+
#endif
|
|
83
|
+
uniform vec4 shadowsInfo{X};uniform vec2 depthValues{X};
|
|
84
|
+
#endif
|
|
85
|
+
#ifdef SPOTLIGHT{X}
|
|
86
|
+
uniform vec4 vLightDirection{X};uniform vec4 vLightFalloff{X};
|
|
87
|
+
#elif defined(POINTLIGHT{X})
|
|
88
|
+
uniform vec4 vLightFalloff{X};
|
|
89
|
+
#elif defined(HEMILIGHT{X})
|
|
90
|
+
uniform vec3 vLightGround{X};
|
|
91
|
+
#endif
|
|
92
|
+
#ifdef AREALIGHT{X}
|
|
93
|
+
uniform vec4 vLightWidth{X};uniform vec4 vLightHeight{X};
|
|
94
|
+
#endif
|
|
95
|
+
#ifdef IESLIGHTTEXTURE{X}
|
|
96
|
+
uniform sampler2D iesLightTexture{X};
|
|
97
|
+
#endif
|
|
98
|
+
#ifdef PROJECTEDLIGHTTEXTURE{X}
|
|
99
|
+
uniform mat4 textureProjectionMatrix{X};uniform sampler2D projectionLightTexture{X};
|
|
100
|
+
#endif
|
|
101
|
+
#endif
|
|
102
|
+
`;
|
|
103
|
+
e.IncludesShadersStore[a] || (e.IncludesShadersStore[a] = T);
|
|
104
|
+
const r = "lightUboDeclaration", A = `#ifdef LIGHT{X}
|
|
105
|
+
uniform Light{X}
|
|
106
|
+
{vec4 vLightData;vec4 vLightDiffuse;vec4 vLightSpecular;
|
|
107
|
+
#ifdef SPOTLIGHT{X}
|
|
108
|
+
vec4 vLightDirection;vec4 vLightFalloff;
|
|
109
|
+
#elif defined(POINTLIGHT{X})
|
|
110
|
+
vec4 vLightFalloff;
|
|
111
|
+
#elif defined(HEMILIGHT{X})
|
|
112
|
+
vec3 vLightGround;
|
|
113
|
+
#endif
|
|
114
|
+
#if defined(AREALIGHT{X})
|
|
115
|
+
vec4 vLightWidth;vec4 vLightHeight;
|
|
116
|
+
#endif
|
|
117
|
+
vec4 shadowsInfo;vec2 depthValues;} light{X};
|
|
118
|
+
#ifdef IESLIGHTTEXTURE{X}
|
|
119
|
+
uniform sampler2D iesLightTexture{X};
|
|
120
|
+
#endif
|
|
121
|
+
#ifdef PROJECTEDLIGHTTEXTURE{X}
|
|
122
|
+
uniform mat4 textureProjectionMatrix{X};uniform sampler2D projectionLightTexture{X};
|
|
123
|
+
#endif
|
|
124
|
+
#ifdef SHADOW{X}
|
|
125
|
+
#ifdef SHADOWCSM{X}
|
|
126
|
+
uniform mat4 lightMatrix{X}[SHADOWCSMNUM_CASCADES{X}];uniform float viewFrustumZ{X}[SHADOWCSMNUM_CASCADES{X}];uniform float frustumLengths{X}[SHADOWCSMNUM_CASCADES{X}];uniform float cascadeBlendFactor{X};varying vec4 vPositionFromLight{X}[SHADOWCSMNUM_CASCADES{X}];varying float vDepthMetric{X}[SHADOWCSMNUM_CASCADES{X}];varying vec4 vPositionFromCamera{X};
|
|
127
|
+
#if defined(SHADOWPCSS{X})
|
|
128
|
+
uniform highp sampler2DArrayShadow shadowTexture{X};uniform highp sampler2DArray depthTexture{X};uniform vec2 lightSizeUVCorrection{X}[SHADOWCSMNUM_CASCADES{X}];uniform float depthCorrection{X}[SHADOWCSMNUM_CASCADES{X}];uniform float penumbraDarkness{X};
|
|
129
|
+
#elif defined(SHADOWPCF{X})
|
|
130
|
+
uniform highp sampler2DArrayShadow shadowTexture{X};
|
|
131
|
+
#else
|
|
132
|
+
uniform highp sampler2DArray shadowTexture{X};
|
|
133
|
+
#endif
|
|
134
|
+
#ifdef SHADOWCSMDEBUG{X}
|
|
135
|
+
const vec3 vCascadeColorsMultiplier{X}[8]=vec3[8]
|
|
136
|
+
(
|
|
137
|
+
vec3 ( 1.5,0.0,0.0 ),
|
|
138
|
+
vec3 ( 0.0,1.5,0.0 ),
|
|
139
|
+
vec3 ( 0.0,0.0,5.5 ),
|
|
140
|
+
vec3 ( 1.5,0.0,5.5 ),
|
|
141
|
+
vec3 ( 1.5,1.5,0.0 ),
|
|
142
|
+
vec3 ( 1.0,1.0,1.0 ),
|
|
143
|
+
vec3 ( 0.0,1.0,5.5 ),
|
|
144
|
+
vec3 ( 0.5,3.5,0.75 )
|
|
145
|
+
);vec3 shadowDebug{X};
|
|
146
|
+
#endif
|
|
147
|
+
#ifdef SHADOWCSMUSESHADOWMAXZ{X}
|
|
148
|
+
int index{X}=-1;
|
|
149
|
+
#else
|
|
150
|
+
int index{X}=SHADOWCSMNUM_CASCADES{X}-1;
|
|
151
|
+
#endif
|
|
152
|
+
float diff{X}=0.;
|
|
153
|
+
#elif defined(SHADOWCUBE{X})
|
|
154
|
+
uniform samplerCube shadowTexture{X};
|
|
155
|
+
#else
|
|
156
|
+
varying vec4 vPositionFromLight{X};varying float vDepthMetric{X};
|
|
157
|
+
#if defined(SHADOWPCSS{X})
|
|
158
|
+
uniform highp sampler2DShadow shadowTexture{X};uniform highp sampler2D depthTexture{X};
|
|
159
|
+
#elif defined(SHADOWPCF{X})
|
|
160
|
+
uniform highp sampler2DShadow shadowTexture{X};
|
|
161
|
+
#else
|
|
162
|
+
uniform sampler2D shadowTexture{X};
|
|
163
|
+
#endif
|
|
164
|
+
uniform mat4 lightMatrix{X};
|
|
165
|
+
#endif
|
|
166
|
+
#endif
|
|
167
|
+
#endif
|
|
168
|
+
`;
|
|
169
|
+
e.IncludesShadersStore[r] || (e.IncludesShadersStore[r] = A);
|
|
170
|
+
const n = "ltcHelperFunctions", P = `vec2 LTCUv( const in vec3 N,const in vec3 V,const in float roughness ) {const float LUTSIZE=64.0;const float LUTSCALE=( LUTSIZE-1.0 )/LUTSIZE;const float LUTBIAS=0.5/LUTSIZE;float dotNV=saturate( dot( N,V ) );vec2 uv=vec2( roughness,sqrt( 1.0-dotNV ) );uv=uv*LUTSCALE+LUTBIAS;return uv;}
|
|
171
|
+
float LTCClippedSphereFormFactor( const in vec3 f ) {float l=length( f );return max( ( l*l+f.z )/( l+1.0 ),0.0 );}
|
|
172
|
+
vec3 LTCEdgeVectorFormFactor( const in vec3 v1,const in vec3 v2 ) {float x=dot( v1,v2 );float y=abs( x );float a=0.8543985+( 0.4965155+0.0145206*y )*y;float b=3.4175940+( 4.1616724+y )*y;float v=a/b;float thetaSintheta=0.0;if( x>0.0 )
|
|
173
|
+
{thetaSintheta=v;}
|
|
174
|
+
else
|
|
175
|
+
{thetaSintheta=0.5*inversesqrt( max( 1.0-x*x,1e-7 ) )-v;}
|
|
176
|
+
return cross( v1,v2 )*thetaSintheta;}
|
|
177
|
+
vec3 LTCEvaluate( const in vec3 N,const in vec3 V,const in vec3 P,const in mat3 mInv,const in vec3 rectCoords[ 4 ] ) {vec3 v1=rectCoords[ 1 ]-rectCoords[ 0 ];vec3 v2=rectCoords[ 3 ]-rectCoords[ 0 ];vec3 lightNormal=cross( v1,v2 );if( dot( lightNormal,P-rectCoords[ 0 ] )<0.0 ) return vec3( 0.0 );vec3 T1,T2;T1=normalize( V-N*dot( V,N ) );T2=- cross( N,T1 );
|
|
178
|
+
mat3 mat=mInv*transposeMat3( mat3( T1,T2,N ) );vec3 coords[ 4 ];coords[ 0 ]=mat*( rectCoords[ 0 ]-P );coords[ 1 ]=mat*( rectCoords[ 1 ]-P );coords[ 2 ]=mat*( rectCoords[ 2 ]-P );coords[ 3 ]=mat*( rectCoords[ 3 ]-P );coords[ 0 ]=normalize( coords[ 0 ] );coords[ 1 ]=normalize( coords[ 1 ] );coords[ 2 ]=normalize( coords[ 2 ] );coords[ 3 ]=normalize( coords[ 3 ] );vec3 vectorFormFactor=vec3( 0.0 );vectorFormFactor+=LTCEdgeVectorFormFactor( coords[ 0 ],coords[ 1 ] );vectorFormFactor+=LTCEdgeVectorFormFactor( coords[ 1 ],coords[ 2 ] );vectorFormFactor+=LTCEdgeVectorFormFactor( coords[ 2 ],coords[ 3 ] );vectorFormFactor+=LTCEdgeVectorFormFactor( coords[ 3 ],coords[ 0 ] );float result=LTCClippedSphereFormFactor( vectorFormFactor );return vec3( result );}
|
|
179
|
+
struct areaLightData
|
|
180
|
+
{vec3 Diffuse;vec3 Specular;vec4 Fresnel;};
|
|
181
|
+
#define inline
|
|
182
|
+
areaLightData computeAreaLightSpecularDiffuseFresnel(const in sampler2D ltc1,const in sampler2D ltc2,const in vec3 viewDir,const in vec3 normal,const in vec3 position,const in vec3 lightPos,const in vec3 halfWidth,const in vec3 halfHeight,const in float roughness)
|
|
183
|
+
{areaLightData result;vec3 rectCoords[ 4 ];rectCoords[ 0 ]=lightPos+halfWidth-halfHeight;
|
|
184
|
+
rectCoords[ 1 ]=lightPos-halfWidth-halfHeight;rectCoords[ 2 ]=lightPos-halfWidth+halfHeight;rectCoords[ 3 ]=lightPos+halfWidth+halfHeight;
|
|
185
|
+
#ifdef SPECULARTERM
|
|
186
|
+
vec2 uv=LTCUv( normal,viewDir,roughness );vec4 t1=texture2D( ltc1,uv );vec4 t2=texture2D( ltc2,uv );mat3 mInv=mat3(
|
|
187
|
+
vec3( t1.x,0,t1.y ),
|
|
188
|
+
vec3( 0,1, 0 ),
|
|
189
|
+
vec3( t1.z,0,t1.w )
|
|
190
|
+
);result.Specular=LTCEvaluate( normal,viewDir,position,mInv,rectCoords );result.Fresnel=t2;
|
|
191
|
+
#endif
|
|
192
|
+
result.Diffuse=LTCEvaluate( normal,viewDir,position,mat3( 1.0 ),rectCoords );return result;}`;
|
|
193
|
+
e.IncludesShadersStore[n] || (e.IncludesShadersStore[n] = P);
|
|
194
|
+
const s = "shadowsFragmentFunctions", F = `#ifdef SHADOWS
|
|
195
|
+
#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)
|
|
196
|
+
#define TEXTUREFUNC(s,c,l) texture2DLodEXT(s,c,l)
|
|
197
|
+
#else
|
|
198
|
+
#define TEXTUREFUNC(s,c,b) texture2D(s,c,b)
|
|
199
|
+
#endif
|
|
200
|
+
#ifndef SHADOWFLOAT
|
|
201
|
+
float unpack(vec4 color)
|
|
202
|
+
{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);return dot(color,bit_shift);}
|
|
203
|
+
#endif
|
|
204
|
+
float computeFallOff(float value,vec2 clipSpace,float frustumEdgeFalloff)
|
|
205
|
+
{float mask=smoothstep(1.0-frustumEdgeFalloff,1.00000012,clamp(dot(clipSpace,clipSpace),0.,1.));return mix(value,1.0,mask);}
|
|
206
|
+
#define inline
|
|
207
|
+
float computeShadowCube(vec3 worldPos,vec3 lightPosition,samplerCube shadowSampler,float darkness,vec2 depthValues)
|
|
208
|
+
{vec3 directionToLight=worldPos-lightPosition;float depth=length(directionToLight);depth=(depth+depthValues.x)/(depthValues.y);depth=clamp(depth,0.,1.0);directionToLight=normalize(directionToLight);directionToLight.y=-directionToLight.y;
|
|
209
|
+
#ifndef SHADOWFLOAT
|
|
210
|
+
float shadow=unpack(textureCube(shadowSampler,directionToLight));
|
|
211
|
+
#else
|
|
212
|
+
float shadow=textureCube(shadowSampler,directionToLight).x;
|
|
213
|
+
#endif
|
|
214
|
+
return depth>shadow ? darkness : 1.0;}
|
|
215
|
+
#define inline
|
|
216
|
+
float computeShadowWithPoissonSamplingCube(vec3 worldPos,vec3 lightPosition,samplerCube shadowSampler,float mapSize,float darkness,vec2 depthValues)
|
|
217
|
+
{vec3 directionToLight=worldPos-lightPosition;float depth=length(directionToLight);depth=(depth+depthValues.x)/(depthValues.y);depth=clamp(depth,0.,1.0);directionToLight=normalize(directionToLight);directionToLight.y=-directionToLight.y;float visibility=1.;vec3 poissonDisk[4];poissonDisk[0]=vec3(-1.0,1.0,-1.0);poissonDisk[1]=vec3(1.0,-1.0,-1.0);poissonDisk[2]=vec3(-1.0,-1.0,-1.0);poissonDisk[3]=vec3(1.0,-1.0,1.0);
|
|
218
|
+
#ifndef SHADOWFLOAT
|
|
219
|
+
if (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))<depth) visibility-=0.25;if (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize))<depth) visibility-=0.25;if (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize))<depth) visibility-=0.25;if (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize))<depth) visibility-=0.25;
|
|
220
|
+
#else
|
|
221
|
+
if (textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize).x<depth) visibility-=0.25;if (textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize).x<depth) visibility-=0.25;if (textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize).x<depth) visibility-=0.25;if (textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize).x<depth) visibility-=0.25;
|
|
222
|
+
#endif
|
|
223
|
+
return min(1.0,visibility+darkness);}
|
|
224
|
+
#define inline
|
|
225
|
+
float computeShadowWithESMCube(vec3 worldPos,vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)
|
|
226
|
+
{vec3 directionToLight=worldPos-lightPosition;float depth=length(directionToLight);depth=(depth+depthValues.x)/(depthValues.y);float shadowPixelDepth=clamp(depth,0.,1.0);directionToLight=normalize(directionToLight);directionToLight.y=-directionToLight.y;
|
|
227
|
+
#ifndef SHADOWFLOAT
|
|
228
|
+
float shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));
|
|
229
|
+
#else
|
|
230
|
+
float shadowMapSample=textureCube(shadowSampler,directionToLight).x;
|
|
231
|
+
#endif
|
|
232
|
+
float esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);return esm;}
|
|
233
|
+
#define inline
|
|
234
|
+
float computeShadowWithCloseESMCube(vec3 worldPos,vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)
|
|
235
|
+
{vec3 directionToLight=worldPos-lightPosition;float depth=length(directionToLight);depth=(depth+depthValues.x)/(depthValues.y);float shadowPixelDepth=clamp(depth,0.,1.0);directionToLight=normalize(directionToLight);directionToLight.y=-directionToLight.y;
|
|
236
|
+
#ifndef SHADOWFLOAT
|
|
237
|
+
float shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));
|
|
238
|
+
#else
|
|
239
|
+
float shadowMapSample=textureCube(shadowSampler,directionToLight).x;
|
|
240
|
+
#endif
|
|
241
|
+
float esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);return esm;}
|
|
242
|
+
#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)
|
|
243
|
+
#define inline
|
|
244
|
+
float computeShadowCSM(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArray shadowSampler,float darkness,float frustumEdgeFalloff)
|
|
245
|
+
{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec2 uv=0.5*clipSpace.xy+vec2(0.5);vec3 uvLayer=vec3(uv.x,uv.y,layer);float shadowPixelDepth=clamp(depthMetric,0.,1.0);
|
|
246
|
+
#ifndef SHADOWFLOAT
|
|
247
|
+
float shadow=unpack(texture2D(shadowSampler,uvLayer));
|
|
248
|
+
#else
|
|
249
|
+
float shadow=texture2D(shadowSampler,uvLayer).x;
|
|
250
|
+
#endif
|
|
251
|
+
return shadowPixelDepth>shadow ? computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff) : 1.;}
|
|
252
|
+
#endif
|
|
253
|
+
#define inline
|
|
254
|
+
float computeShadow(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float frustumEdgeFalloff)
|
|
255
|
+
{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec2 uv=0.5*clipSpace.xy+vec2(0.5);if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)
|
|
256
|
+
{return 1.0;}
|
|
257
|
+
else
|
|
258
|
+
{float shadowPixelDepth=clamp(depthMetric,0.,1.0);
|
|
259
|
+
#ifndef SHADOWFLOAT
|
|
260
|
+
float shadow=unpack(TEXTUREFUNC(shadowSampler,uv,0.));
|
|
261
|
+
#else
|
|
262
|
+
float shadow=TEXTUREFUNC(shadowSampler,uv,0.).x;
|
|
263
|
+
#endif
|
|
264
|
+
return shadowPixelDepth>shadow ? computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff) : 1.;}}
|
|
265
|
+
#define inline
|
|
266
|
+
float computeShadowWithPoissonSampling(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float mapSize,float darkness,float frustumEdgeFalloff)
|
|
267
|
+
{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec2 uv=0.5*clipSpace.xy+vec2(0.5);if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)
|
|
268
|
+
{return 1.0;}
|
|
269
|
+
else
|
|
270
|
+
{float shadowPixelDepth=clamp(depthMetric,0.,1.0);float visibility=1.;vec2 poissonDisk[4];poissonDisk[0]=vec2(-0.94201624,-0.39906216);poissonDisk[1]=vec2(0.94558609,-0.76890725);poissonDisk[2]=vec2(-0.094184101,-0.92938870);poissonDisk[3]=vec2(0.34495938,0.29387760);
|
|
271
|
+
#ifndef SHADOWFLOAT
|
|
272
|
+
if (unpack(TEXTUREFUNC(shadowSampler,uv+poissonDisk[0]*mapSize,0.))<shadowPixelDepth) visibility-=0.25;if (unpack(TEXTUREFUNC(shadowSampler,uv+poissonDisk[1]*mapSize,0.))<shadowPixelDepth) visibility-=0.25;if (unpack(TEXTUREFUNC(shadowSampler,uv+poissonDisk[2]*mapSize,0.))<shadowPixelDepth) visibility-=0.25;if (unpack(TEXTUREFUNC(shadowSampler,uv+poissonDisk[3]*mapSize,0.))<shadowPixelDepth) visibility-=0.25;
|
|
273
|
+
#else
|
|
274
|
+
if (TEXTUREFUNC(shadowSampler,uv+poissonDisk[0]*mapSize,0.).x<shadowPixelDepth) visibility-=0.25;if (TEXTUREFUNC(shadowSampler,uv+poissonDisk[1]*mapSize,0.).x<shadowPixelDepth) visibility-=0.25;if (TEXTUREFUNC(shadowSampler,uv+poissonDisk[2]*mapSize,0.).x<shadowPixelDepth) visibility-=0.25;if (TEXTUREFUNC(shadowSampler,uv+poissonDisk[3]*mapSize,0.).x<shadowPixelDepth) visibility-=0.25;
|
|
275
|
+
#endif
|
|
276
|
+
return computeFallOff(min(1.0,visibility+darkness),clipSpace.xy,frustumEdgeFalloff);}}
|
|
277
|
+
#define inline
|
|
278
|
+
float computeShadowWithESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)
|
|
279
|
+
{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec2 uv=0.5*clipSpace.xy+vec2(0.5);if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)
|
|
280
|
+
{return 1.0;}
|
|
281
|
+
else
|
|
282
|
+
{float shadowPixelDepth=clamp(depthMetric,0.,1.0);
|
|
283
|
+
#ifndef SHADOWFLOAT
|
|
284
|
+
float shadowMapSample=unpack(TEXTUREFUNC(shadowSampler,uv,0.));
|
|
285
|
+
#else
|
|
286
|
+
float shadowMapSample=TEXTUREFUNC(shadowSampler,uv,0.).x;
|
|
287
|
+
#endif
|
|
288
|
+
float esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);return computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);}}
|
|
289
|
+
#define inline
|
|
290
|
+
float computeShadowWithCloseESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)
|
|
291
|
+
{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec2 uv=0.5*clipSpace.xy+vec2(0.5);if (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)
|
|
292
|
+
{return 1.0;}
|
|
293
|
+
else
|
|
294
|
+
{float shadowPixelDepth=clamp(depthMetric,0.,1.0);
|
|
295
|
+
#ifndef SHADOWFLOAT
|
|
296
|
+
float shadowMapSample=unpack(TEXTUREFUNC(shadowSampler,uv,0.));
|
|
297
|
+
#else
|
|
298
|
+
float shadowMapSample=TEXTUREFUNC(shadowSampler,uv,0.).x;
|
|
299
|
+
#endif
|
|
300
|
+
float esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);return computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);}}
|
|
301
|
+
#ifdef IS_NDC_HALF_ZRANGE
|
|
302
|
+
#define ZINCLIP clipSpace.z
|
|
303
|
+
#else
|
|
304
|
+
#define ZINCLIP uvDepth.z
|
|
305
|
+
#endif
|
|
306
|
+
#if defined(WEBGL2) || defined(WEBGPU) || defined(NATIVE)
|
|
307
|
+
#define GREATEST_LESS_THAN_ONE 0.99999994
|
|
308
|
+
#define DISABLE_UNIFORMITY_ANALYSIS
|
|
309
|
+
#define inline
|
|
310
|
+
float computeShadowWithCSMPCF1(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArrayShadow shadowSampler,float darkness,float frustumEdgeFalloff)
|
|
311
|
+
{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=clamp(ZINCLIP,0.,GREATEST_LESS_THAN_ONE);vec4 uvDepthLayer=vec4(uvDepth.x,uvDepth.y,layer,uvDepth.z);float shadow=texture2D(shadowSampler,uvDepthLayer);shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}
|
|
312
|
+
#define inline
|
|
313
|
+
float computeShadowWithCSMPCF3(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArrayShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)
|
|
314
|
+
{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=clamp(ZINCLIP,0.,GREATEST_LESS_THAN_ONE);vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x;
|
|
315
|
+
uv+=0.5;
|
|
316
|
+
vec2 st=fract(uv);
|
|
317
|
+
vec2 base_uv=floor(uv)-0.5;
|
|
318
|
+
base_uv*=shadowMapSizeAndInverse.y;
|
|
319
|
+
vec2 uvw0=3.-2.*st;vec2 uvw1=1.+2.*st;vec2 u=vec2((2.-st.x)/uvw0.x-1.,st.x/uvw1.x+1.)*shadowMapSizeAndInverse.y;vec2 v=vec2((2.-st.y)/uvw0.y-1.,st.y/uvw1.y+1.)*shadowMapSizeAndInverse.y;float shadow=0.;shadow+=uvw0.x*uvw0.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[0],v[0]),layer,uvDepth.z));shadow+=uvw1.x*uvw0.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[1],v[0]),layer,uvDepth.z));shadow+=uvw0.x*uvw1.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[0],v[1]),layer,uvDepth.z));shadow+=uvw1.x*uvw1.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[1],v[1]),layer,uvDepth.z));shadow=shadow/16.;shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}
|
|
320
|
+
#define inline
|
|
321
|
+
float computeShadowWithCSMPCF5(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArrayShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)
|
|
322
|
+
{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=clamp(ZINCLIP,0.,GREATEST_LESS_THAN_ONE);vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x;
|
|
323
|
+
uv+=0.5;
|
|
324
|
+
vec2 st=fract(uv);
|
|
325
|
+
vec2 base_uv=floor(uv)-0.5;
|
|
326
|
+
base_uv*=shadowMapSizeAndInverse.y;
|
|
327
|
+
vec2 uvw0=4.-3.*st;vec2 uvw1=vec2(7.);vec2 uvw2=1.+3.*st;vec3 u=vec3((3.-2.*st.x)/uvw0.x-2.,(3.+st.x)/uvw1.x,st.x/uvw2.x+2.)*shadowMapSizeAndInverse.y;vec3 v=vec3((3.-2.*st.y)/uvw0.y-2.,(3.+st.y)/uvw1.y,st.y/uvw2.y+2.)*shadowMapSizeAndInverse.y;float shadow=0.;shadow+=uvw0.x*uvw0.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[0],v[0]),layer,uvDepth.z));shadow+=uvw1.x*uvw0.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[1],v[0]),layer,uvDepth.z));shadow+=uvw2.x*uvw0.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[2],v[0]),layer,uvDepth.z));shadow+=uvw0.x*uvw1.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[0],v[1]),layer,uvDepth.z));shadow+=uvw1.x*uvw1.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[1],v[1]),layer,uvDepth.z));shadow+=uvw2.x*uvw1.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[2],v[1]),layer,uvDepth.z));shadow+=uvw0.x*uvw2.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[0],v[2]),layer,uvDepth.z));shadow+=uvw1.x*uvw2.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[1],v[2]),layer,uvDepth.z));shadow+=uvw2.x*uvw2.y*texture2D(shadowSampler,vec4(base_uv.xy+vec2(u[2],v[2]),layer,uvDepth.z));shadow=shadow/144.;shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}
|
|
328
|
+
#define inline
|
|
329
|
+
float computeShadowWithPCF1(vec4 vPositionFromLight,float depthMetric,highp sampler2DShadow shadowSampler,float darkness,float frustumEdgeFalloff)
|
|
330
|
+
{if (depthMetric>1.0 || depthMetric<0.0) {return 1.0;}
|
|
331
|
+
else
|
|
332
|
+
{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=ZINCLIP;float shadow=TEXTUREFUNC(shadowSampler,uvDepth,0.);shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}}
|
|
333
|
+
#define inline
|
|
334
|
+
float computeShadowWithPCF3(vec4 vPositionFromLight,float depthMetric,highp sampler2DShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)
|
|
335
|
+
{if (depthMetric>1.0 || depthMetric<0.0) {return 1.0;}
|
|
336
|
+
else
|
|
337
|
+
{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=ZINCLIP;vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x;
|
|
338
|
+
uv+=0.5;
|
|
339
|
+
vec2 st=fract(uv);
|
|
340
|
+
vec2 base_uv=floor(uv)-0.5;
|
|
341
|
+
base_uv*=shadowMapSizeAndInverse.y;
|
|
342
|
+
vec2 uvw0=3.-2.*st;vec2 uvw1=1.+2.*st;vec2 u=vec2((2.-st.x)/uvw0.x-1.,st.x/uvw1.x+1.)*shadowMapSizeAndInverse.y;vec2 v=vec2((2.-st.y)/uvw0.y-1.,st.y/uvw1.y+1.)*shadowMapSizeAndInverse.y;float shadow=0.;shadow+=uvw0.x*uvw0.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[0]),uvDepth.z),0.);shadow+=uvw1.x*uvw0.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[0]),uvDepth.z),0.);shadow+=uvw0.x*uvw1.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[1]),uvDepth.z),0.);shadow+=uvw1.x*uvw1.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[1]),uvDepth.z),0.);shadow=shadow/16.;shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}}
|
|
343
|
+
#define inline
|
|
344
|
+
float computeShadowWithPCF5(vec4 vPositionFromLight,float depthMetric,highp sampler2DShadow shadowSampler,vec2 shadowMapSizeAndInverse,float darkness,float frustumEdgeFalloff)
|
|
345
|
+
{if (depthMetric>1.0 || depthMetric<0.0) {return 1.0;}
|
|
346
|
+
else
|
|
347
|
+
{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=ZINCLIP;vec2 uv=uvDepth.xy*shadowMapSizeAndInverse.x;
|
|
348
|
+
uv+=0.5;
|
|
349
|
+
vec2 st=fract(uv);
|
|
350
|
+
vec2 base_uv=floor(uv)-0.5;
|
|
351
|
+
base_uv*=shadowMapSizeAndInverse.y;
|
|
352
|
+
vec2 uvw0=4.-3.*st;vec2 uvw1=vec2(7.);vec2 uvw2=1.+3.*st;vec3 u=vec3((3.-2.*st.x)/uvw0.x-2.,(3.+st.x)/uvw1.x,st.x/uvw2.x+2.)*shadowMapSizeAndInverse.y;vec3 v=vec3((3.-2.*st.y)/uvw0.y-2.,(3.+st.y)/uvw1.y,st.y/uvw2.y+2.)*shadowMapSizeAndInverse.y;float shadow=0.;shadow+=uvw0.x*uvw0.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[0]),uvDepth.z),0.);shadow+=uvw1.x*uvw0.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[0]),uvDepth.z),0.);shadow+=uvw2.x*uvw0.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[0]),uvDepth.z),0.);shadow+=uvw0.x*uvw1.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[1]),uvDepth.z),0.);shadow+=uvw1.x*uvw1.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[1]),uvDepth.z),0.);shadow+=uvw2.x*uvw1.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[1]),uvDepth.z),0.);shadow+=uvw0.x*uvw2.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[0],v[2]),uvDepth.z),0.);shadow+=uvw1.x*uvw2.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[1],v[2]),uvDepth.z),0.);shadow+=uvw2.x*uvw2.y*TEXTUREFUNC(shadowSampler,vec3(base_uv.xy+vec2(u[2],v[2]),uvDepth.z),0.);shadow=shadow/144.;shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}}
|
|
353
|
+
const vec3 PoissonSamplers32[64]=vec3[64](
|
|
354
|
+
vec3(0.06407013,0.05409927,0.),
|
|
355
|
+
vec3(0.7366577,0.5789394,0.),
|
|
356
|
+
vec3(-0.6270542,-0.5320278,0.),
|
|
357
|
+
vec3(-0.4096107,0.8411095,0.),
|
|
358
|
+
vec3(0.6849564,-0.4990818,0.),
|
|
359
|
+
vec3(-0.874181,-0.04579735,0.),
|
|
360
|
+
vec3(0.9989998,0.0009880066,0.),
|
|
361
|
+
vec3(-0.004920578,-0.9151649,0.),
|
|
362
|
+
vec3(0.1805763,0.9747483,0.),
|
|
363
|
+
vec3(-0.2138451,0.2635818,0.),
|
|
364
|
+
vec3(0.109845,0.3884785,0.),
|
|
365
|
+
vec3(0.06876755,-0.3581074,0.),
|
|
366
|
+
vec3(0.374073,-0.7661266,0.),
|
|
367
|
+
vec3(0.3079132,-0.1216763,0.),
|
|
368
|
+
vec3(-0.3794335,-0.8271583,0.),
|
|
369
|
+
vec3(-0.203878,-0.07715034,0.),
|
|
370
|
+
vec3(0.5912697,0.1469799,0.),
|
|
371
|
+
vec3(-0.88069,0.3031784,0.),
|
|
372
|
+
vec3(0.5040108,0.8283722,0.),
|
|
373
|
+
vec3(-0.5844124,0.5494877,0.),
|
|
374
|
+
vec3(0.6017799,-0.1726654,0.),
|
|
375
|
+
vec3(-0.5554981,0.1559997,0.),
|
|
376
|
+
vec3(-0.3016369,-0.3900928,0.),
|
|
377
|
+
vec3(-0.5550632,-0.1723762,0.),
|
|
378
|
+
vec3(0.925029,0.2995041,0.),
|
|
379
|
+
vec3(-0.2473137,0.5538505,0.),
|
|
380
|
+
vec3(0.9183037,-0.2862392,0.),
|
|
381
|
+
vec3(0.2469421,0.6718712,0.),
|
|
382
|
+
vec3(0.3916397,-0.4328209,0.),
|
|
383
|
+
vec3(-0.03576927,-0.6220032,0.),
|
|
384
|
+
vec3(-0.04661255,0.7995201,0.),
|
|
385
|
+
vec3(0.4402924,0.3640312,0.),
|
|
386
|
+
vec3(0.),
|
|
387
|
+
vec3(0.),
|
|
388
|
+
vec3(0.),
|
|
389
|
+
vec3(0.),
|
|
390
|
+
vec3(0.),
|
|
391
|
+
vec3(0.),
|
|
392
|
+
vec3(0.),
|
|
393
|
+
vec3(0.),
|
|
394
|
+
vec3(0.),
|
|
395
|
+
vec3(0.),
|
|
396
|
+
vec3(0.),
|
|
397
|
+
vec3(0.),
|
|
398
|
+
vec3(0.),
|
|
399
|
+
vec3(0.),
|
|
400
|
+
vec3(0.),
|
|
401
|
+
vec3(0.),
|
|
402
|
+
vec3(0.),
|
|
403
|
+
vec3(0.),
|
|
404
|
+
vec3(0.),
|
|
405
|
+
vec3(0.),
|
|
406
|
+
vec3(0.),
|
|
407
|
+
vec3(0.),
|
|
408
|
+
vec3(0.),
|
|
409
|
+
vec3(0.),
|
|
410
|
+
vec3(0.),
|
|
411
|
+
vec3(0.),
|
|
412
|
+
vec3(0.),
|
|
413
|
+
vec3(0.),
|
|
414
|
+
vec3(0.),
|
|
415
|
+
vec3(0.),
|
|
416
|
+
vec3(0.),
|
|
417
|
+
vec3(0.)
|
|
418
|
+
);const vec3 PoissonSamplers64[64]=vec3[64](
|
|
419
|
+
vec3(-0.613392,0.617481,0.),
|
|
420
|
+
vec3(0.170019,-0.040254,0.),
|
|
421
|
+
vec3(-0.299417,0.791925,0.),
|
|
422
|
+
vec3(0.645680,0.493210,0.),
|
|
423
|
+
vec3(-0.651784,0.717887,0.),
|
|
424
|
+
vec3(0.421003,0.027070,0.),
|
|
425
|
+
vec3(-0.817194,-0.271096,0.),
|
|
426
|
+
vec3(-0.705374,-0.668203,0.),
|
|
427
|
+
vec3(0.977050,-0.108615,0.),
|
|
428
|
+
vec3(0.063326,0.142369,0.),
|
|
429
|
+
vec3(0.203528,0.214331,0.),
|
|
430
|
+
vec3(-0.667531,0.326090,0.),
|
|
431
|
+
vec3(-0.098422,-0.295755,0.),
|
|
432
|
+
vec3(-0.885922,0.215369,0.),
|
|
433
|
+
vec3(0.566637,0.605213,0.),
|
|
434
|
+
vec3(0.039766,-0.396100,0.),
|
|
435
|
+
vec3(0.751946,0.453352,0.),
|
|
436
|
+
vec3(0.078707,-0.715323,0.),
|
|
437
|
+
vec3(-0.075838,-0.529344,0.),
|
|
438
|
+
vec3(0.724479,-0.580798,0.),
|
|
439
|
+
vec3(0.222999,-0.215125,0.),
|
|
440
|
+
vec3(-0.467574,-0.405438,0.),
|
|
441
|
+
vec3(-0.248268,-0.814753,0.),
|
|
442
|
+
vec3(0.354411,-0.887570,0.),
|
|
443
|
+
vec3(0.175817,0.382366,0.),
|
|
444
|
+
vec3(0.487472,-0.063082,0.),
|
|
445
|
+
vec3(-0.084078,0.898312,0.),
|
|
446
|
+
vec3(0.488876,-0.783441,0.),
|
|
447
|
+
vec3(0.470016,0.217933,0.),
|
|
448
|
+
vec3(-0.696890,-0.549791,0.),
|
|
449
|
+
vec3(-0.149693,0.605762,0.),
|
|
450
|
+
vec3(0.034211,0.979980,0.),
|
|
451
|
+
vec3(0.503098,-0.308878,0.),
|
|
452
|
+
vec3(-0.016205,-0.872921,0.),
|
|
453
|
+
vec3(0.385784,-0.393902,0.),
|
|
454
|
+
vec3(-0.146886,-0.859249,0.),
|
|
455
|
+
vec3(0.643361,0.164098,0.),
|
|
456
|
+
vec3(0.634388,-0.049471,0.),
|
|
457
|
+
vec3(-0.688894,0.007843,0.),
|
|
458
|
+
vec3(0.464034,-0.188818,0.),
|
|
459
|
+
vec3(-0.440840,0.137486,0.),
|
|
460
|
+
vec3(0.364483,0.511704,0.),
|
|
461
|
+
vec3(0.034028,0.325968,0.),
|
|
462
|
+
vec3(0.099094,-0.308023,0.),
|
|
463
|
+
vec3(0.693960,-0.366253,0.),
|
|
464
|
+
vec3(0.678884,-0.204688,0.),
|
|
465
|
+
vec3(0.001801,0.780328,0.),
|
|
466
|
+
vec3(0.145177,-0.898984,0.),
|
|
467
|
+
vec3(0.062655,-0.611866,0.),
|
|
468
|
+
vec3(0.315226,-0.604297,0.),
|
|
469
|
+
vec3(-0.780145,0.486251,0.),
|
|
470
|
+
vec3(-0.371868,0.882138,0.),
|
|
471
|
+
vec3(0.200476,0.494430,0.),
|
|
472
|
+
vec3(-0.494552,-0.711051,0.),
|
|
473
|
+
vec3(0.612476,0.705252,0.),
|
|
474
|
+
vec3(-0.578845,-0.768792,0.),
|
|
475
|
+
vec3(-0.772454,-0.090976,0.),
|
|
476
|
+
vec3(0.504440,0.372295,0.),
|
|
477
|
+
vec3(0.155736,0.065157,0.),
|
|
478
|
+
vec3(0.391522,0.849605,0.),
|
|
479
|
+
vec3(-0.620106,-0.328104,0.),
|
|
480
|
+
vec3(0.789239,-0.419965,0.),
|
|
481
|
+
vec3(-0.545396,0.538133,0.),
|
|
482
|
+
vec3(-0.178564,-0.596057,0.)
|
|
483
|
+
);
|
|
484
|
+
#define inline
|
|
485
|
+
float computeShadowWithCSMPCSS(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArray depthSampler,highp sampler2DArrayShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff,int searchTapCount,int pcfTapCount,vec3[64] poissonSamplers,vec2 lightSizeUVCorrection,float depthCorrection,float penumbraDarkness)
|
|
486
|
+
{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=clamp(ZINCLIP,0.,GREATEST_LESS_THAN_ONE);vec4 uvDepthLayer=vec4(uvDepth.x,uvDepth.y,layer,uvDepth.z);float blockerDepth=0.0;float sumBlockerDepth=0.0;float numBlocker=0.0;for (int i=0; i<searchTapCount; i ++) {blockerDepth=texture2D(depthSampler,vec3(uvDepth.xy+(lightSizeUV*lightSizeUVCorrection*shadowMapSizeInverse*PoissonSamplers32[i].xy),layer)).r;if (blockerDepth<depthMetric) {sumBlockerDepth+=blockerDepth;numBlocker++;}}
|
|
487
|
+
float avgBlockerDepth=sumBlockerDepth/numBlocker;float AAOffset=shadowMapSizeInverse*10.;float penumbraRatio=((depthMetric-avgBlockerDepth)*depthCorrection+AAOffset);vec4 filterRadius=vec4(penumbraRatio*lightSizeUV*lightSizeUVCorrection*shadowMapSizeInverse,0.,0.);float random=getRand(vPositionFromLight.xy);float rotationAngle=random*3.1415926;vec2 rotationVector=vec2(cos(rotationAngle),sin(rotationAngle));float shadow=0.;for (int i=0; i<pcfTapCount; i++) {vec4 offset=vec4(poissonSamplers[i],0.);offset=vec4(offset.x*rotationVector.x-offset.y*rotationVector.y,offset.y*rotationVector.x+offset.x*rotationVector.y,0.,0.);shadow+=texture2D(shadowSampler,uvDepthLayer+offset*filterRadius);}
|
|
488
|
+
shadow/=float(pcfTapCount);shadow=mix(shadow,1.,min((depthMetric-avgBlockerDepth)*depthCorrection*penumbraDarkness,1.));shadow=mix(darkness,1.,shadow);if (numBlocker<1.0) {return 1.0;}
|
|
489
|
+
else
|
|
490
|
+
{return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}}
|
|
491
|
+
#define inline
|
|
492
|
+
float computeShadowWithPCSS(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,highp sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff,int searchTapCount,int pcfTapCount,vec3[64] poissonSamplers)
|
|
493
|
+
{if (depthMetric>1.0 || depthMetric<0.0) {return 1.0;}
|
|
494
|
+
else
|
|
495
|
+
{vec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;vec3 uvDepth=vec3(0.5*clipSpace.xyz+vec3(0.5));uvDepth.z=ZINCLIP;float blockerDepth=0.0;float sumBlockerDepth=0.0;float numBlocker=0.0;for (int i=0; i<searchTapCount; i ++) {blockerDepth=TEXTUREFUNC(depthSampler,uvDepth.xy+(lightSizeUV*shadowMapSizeInverse*PoissonSamplers32[i].xy),0.).r;if (blockerDepth<depthMetric) {sumBlockerDepth+=blockerDepth;numBlocker++;}}
|
|
496
|
+
if (numBlocker<1.0) {return 1.0;}
|
|
497
|
+
else
|
|
498
|
+
{float avgBlockerDepth=sumBlockerDepth/numBlocker;float AAOffset=shadowMapSizeInverse*10.;float penumbraRatio=((depthMetric-avgBlockerDepth)+AAOffset);float filterRadius=penumbraRatio*lightSizeUV*shadowMapSizeInverse;float random=getRand(vPositionFromLight.xy);float rotationAngle=random*3.1415926;vec2 rotationVector=vec2(cos(rotationAngle),sin(rotationAngle));float shadow=0.;for (int i=0; i<pcfTapCount; i++) {vec3 offset=poissonSamplers[i];offset=vec3(offset.x*rotationVector.x-offset.y*rotationVector.y,offset.y*rotationVector.x+offset.x*rotationVector.y,0.);shadow+=TEXTUREFUNC(shadowSampler,uvDepth+offset*filterRadius,0.);}
|
|
499
|
+
shadow/=float(pcfTapCount);shadow=mix(shadow,1.,depthMetric-avgBlockerDepth);shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}}}
|
|
500
|
+
#define inline
|
|
501
|
+
float computeShadowWithPCSS16(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,highp sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff)
|
|
502
|
+
{return computeShadowWithPCSS(vPositionFromLight,depthMetric,depthSampler,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,16,PoissonSamplers32);}
|
|
503
|
+
#define inline
|
|
504
|
+
float computeShadowWithPCSS32(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,highp sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff)
|
|
505
|
+
{return computeShadowWithPCSS(vPositionFromLight,depthMetric,depthSampler,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,32,PoissonSamplers32);}
|
|
506
|
+
#define inline
|
|
507
|
+
float computeShadowWithPCSS64(vec4 vPositionFromLight,float depthMetric,sampler2D depthSampler,highp sampler2DShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff)
|
|
508
|
+
{return computeShadowWithPCSS(vPositionFromLight,depthMetric,depthSampler,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,32,64,PoissonSamplers64);}
|
|
509
|
+
#define inline
|
|
510
|
+
float computeShadowWithCSMPCSS16(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArray depthSampler,highp sampler2DArrayShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff,vec2 lightSizeUVCorrection,float depthCorrection,float penumbraDarkness)
|
|
511
|
+
{return computeShadowWithCSMPCSS(layer,vPositionFromLight,depthMetric,depthSampler,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,16,PoissonSamplers32,lightSizeUVCorrection,depthCorrection,penumbraDarkness);}
|
|
512
|
+
#define inline
|
|
513
|
+
float computeShadowWithCSMPCSS32(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArray depthSampler,highp sampler2DArrayShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff,vec2 lightSizeUVCorrection,float depthCorrection,float penumbraDarkness)
|
|
514
|
+
{return computeShadowWithCSMPCSS(layer,vPositionFromLight,depthMetric,depthSampler,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,32,PoissonSamplers32,lightSizeUVCorrection,depthCorrection,penumbraDarkness);}
|
|
515
|
+
#define inline
|
|
516
|
+
float computeShadowWithCSMPCSS64(float layer,vec4 vPositionFromLight,float depthMetric,highp sampler2DArray depthSampler,highp sampler2DArrayShadow shadowSampler,float shadowMapSizeInverse,float lightSizeUV,float darkness,float frustumEdgeFalloff,vec2 lightSizeUVCorrection,float depthCorrection,float penumbraDarkness)
|
|
517
|
+
{return computeShadowWithCSMPCSS(layer,vPositionFromLight,depthMetric,depthSampler,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,32,64,PoissonSamplers64,lightSizeUVCorrection,depthCorrection,penumbraDarkness);}
|
|
518
|
+
#endif
|
|
519
|
+
#endif
|
|
520
|
+
`;
|
|
521
|
+
e.IncludesShadersStore[s] || (e.IncludesShadersStore[s] = F);
|
|
522
|
+
const l = "samplerFragmentDeclaration", M = `#ifdef _DEFINENAME_
|
|
523
|
+
#if _DEFINENAME_DIRECTUV==1
|
|
524
|
+
#define v_VARYINGNAME_UV vMainUV1
|
|
525
|
+
#elif _DEFINENAME_DIRECTUV==2
|
|
526
|
+
#define v_VARYINGNAME_UV vMainUV2
|
|
527
|
+
#elif _DEFINENAME_DIRECTUV==3
|
|
528
|
+
#define v_VARYINGNAME_UV vMainUV3
|
|
529
|
+
#elif _DEFINENAME_DIRECTUV==4
|
|
530
|
+
#define v_VARYINGNAME_UV vMainUV4
|
|
531
|
+
#elif _DEFINENAME_DIRECTUV==5
|
|
532
|
+
#define v_VARYINGNAME_UV vMainUV5
|
|
533
|
+
#elif _DEFINENAME_DIRECTUV==6
|
|
534
|
+
#define v_VARYINGNAME_UV vMainUV6
|
|
535
|
+
#else
|
|
536
|
+
varying vec2 v_VARYINGNAME_UV;
|
|
537
|
+
#endif
|
|
538
|
+
uniform sampler2D _SAMPLERNAME_Sampler;
|
|
539
|
+
#endif
|
|
540
|
+
`;
|
|
541
|
+
e.IncludesShadersStore[l] || (e.IncludesShadersStore[l] = M);
|
|
542
|
+
const f = "reflectionFunction", y = `vec3 computeFixedEquirectangularCoords(vec4 worldPos,vec3 worldNormal,vec3 direction)
|
|
543
|
+
{float lon=atan(direction.z,direction.x);float lat=acos(direction.y);vec2 sphereCoords=vec2(lon,lat)*RECIPROCAL_PI2*2.0;float s=sphereCoords.x*0.5+0.5;float t=sphereCoords.y;return vec3(s,t,0); }
|
|
544
|
+
vec3 computeMirroredFixedEquirectangularCoords(vec4 worldPos,vec3 worldNormal,vec3 direction)
|
|
545
|
+
{float lon=atan(direction.z,direction.x);float lat=acos(direction.y);vec2 sphereCoords=vec2(lon,lat)*RECIPROCAL_PI2*2.0;float s=sphereCoords.x*0.5+0.5;float t=sphereCoords.y;return vec3(1.0-s,t,0); }
|
|
546
|
+
vec3 computeEquirectangularCoords(vec4 worldPos,vec3 worldNormal,vec3 eyePosition,mat4 reflectionMatrix)
|
|
547
|
+
{vec3 cameraToVertex=normalize(worldPos.xyz-eyePosition);vec3 r=normalize(reflect(cameraToVertex,worldNormal));r=vec3(reflectionMatrix*vec4(r,0));float lon=atan(r.z,r.x);float lat=acos(r.y);vec2 sphereCoords=vec2(lon,lat)*RECIPROCAL_PI2*2.0;float s=sphereCoords.x*0.5+0.5;float t=sphereCoords.y;return vec3(s,t,0);}
|
|
548
|
+
vec3 computeSphericalCoords(vec4 worldPos,vec3 worldNormal,mat4 view,mat4 reflectionMatrix)
|
|
549
|
+
{vec3 viewDir=normalize(vec3(view*worldPos));vec3 viewNormal=normalize(vec3(view*vec4(worldNormal,0.0)));vec3 r=reflect(viewDir,viewNormal);r=vec3(reflectionMatrix*vec4(r,0));r.z=r.z-1.0;float m=2.0*length(r);return vec3(r.x/m+0.5,1.0-r.y/m-0.5,0);}
|
|
550
|
+
vec3 computePlanarCoords(vec4 worldPos,vec3 worldNormal,vec3 eyePosition,mat4 reflectionMatrix)
|
|
551
|
+
{vec3 viewDir=worldPos.xyz-eyePosition;vec3 coords=normalize(reflect(viewDir,worldNormal));return vec3(reflectionMatrix*vec4(coords,1));}
|
|
552
|
+
vec3 computeCubicCoords(vec4 worldPos,vec3 worldNormal,vec3 eyePosition,mat4 reflectionMatrix)
|
|
553
|
+
{vec3 viewDir=normalize(worldPos.xyz-eyePosition);vec3 coords=reflect(viewDir,worldNormal);coords=vec3(reflectionMatrix*vec4(coords,0));
|
|
554
|
+
#ifdef INVERTCUBICMAP
|
|
555
|
+
coords.y*=-1.0;
|
|
556
|
+
#endif
|
|
557
|
+
return coords;}
|
|
558
|
+
vec3 computeCubicLocalCoords(vec4 worldPos,vec3 worldNormal,vec3 eyePosition,mat4 reflectionMatrix,vec3 reflectionSize,vec3 reflectionPosition)
|
|
559
|
+
{vec3 viewDir=normalize(worldPos.xyz-eyePosition);vec3 coords=reflect(viewDir,worldNormal);coords=parallaxCorrectNormal(worldPos.xyz,coords,reflectionSize,reflectionPosition);coords=vec3(reflectionMatrix*vec4(coords,0));
|
|
560
|
+
#ifdef INVERTCUBICMAP
|
|
561
|
+
coords.y*=-1.0;
|
|
562
|
+
#endif
|
|
563
|
+
return coords;}
|
|
564
|
+
vec3 computeProjectionCoords(vec4 worldPos,mat4 view,mat4 reflectionMatrix)
|
|
565
|
+
{return vec3(reflectionMatrix*(view*worldPos));}
|
|
566
|
+
vec3 computeSkyBoxCoords(vec3 positionW,mat4 reflectionMatrix)
|
|
567
|
+
{return vec3(reflectionMatrix*vec4(positionW,1.));}
|
|
568
|
+
#ifdef REFLECTION
|
|
569
|
+
vec3 computeReflectionCoords(vec4 worldPos,vec3 worldNormal)
|
|
570
|
+
{
|
|
571
|
+
#ifdef REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED
|
|
572
|
+
vec3 direction=normalize(vDirectionW);return computeMirroredFixedEquirectangularCoords(worldPos,worldNormal,direction);
|
|
573
|
+
#endif
|
|
574
|
+
#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED
|
|
575
|
+
vec3 direction=normalize(vDirectionW);return computeFixedEquirectangularCoords(worldPos,worldNormal,direction);
|
|
576
|
+
#endif
|
|
577
|
+
#ifdef REFLECTIONMAP_EQUIRECTANGULAR
|
|
578
|
+
return computeEquirectangularCoords(worldPos,worldNormal,vEyePosition.xyz,reflectionMatrix);
|
|
579
|
+
#endif
|
|
580
|
+
#ifdef REFLECTIONMAP_SPHERICAL
|
|
581
|
+
return computeSphericalCoords(worldPos,worldNormal,view,reflectionMatrix);
|
|
582
|
+
#endif
|
|
583
|
+
#ifdef REFLECTIONMAP_PLANAR
|
|
584
|
+
return computePlanarCoords(worldPos,worldNormal,vEyePosition.xyz,reflectionMatrix);
|
|
585
|
+
#endif
|
|
586
|
+
#ifdef REFLECTIONMAP_CUBIC
|
|
587
|
+
#ifdef USE_LOCAL_REFLECTIONMAP_CUBIC
|
|
588
|
+
return computeCubicLocalCoords(worldPos,worldNormal,vEyePosition.xyz,reflectionMatrix,vReflectionSize,vReflectionPosition);
|
|
589
|
+
#else
|
|
590
|
+
return computeCubicCoords(worldPos,worldNormal,vEyePosition.xyz,reflectionMatrix);
|
|
591
|
+
#endif
|
|
592
|
+
#endif
|
|
593
|
+
#ifdef REFLECTIONMAP_PROJECTION
|
|
594
|
+
return computeProjectionCoords(worldPos,view,reflectionMatrix);
|
|
595
|
+
#endif
|
|
596
|
+
#ifdef REFLECTIONMAP_SKYBOX
|
|
597
|
+
return computeSkyBoxCoords(vPositionUVW,reflectionMatrix);
|
|
598
|
+
#endif
|
|
599
|
+
#ifdef REFLECTIONMAP_EXPLICIT
|
|
600
|
+
return vec3(0,0,0);
|
|
601
|
+
#endif
|
|
602
|
+
}
|
|
603
|
+
#endif
|
|
604
|
+
`;
|
|
605
|
+
e.IncludesShadersStore[f] || (e.IncludesShadersStore[f] = y);
|
|
606
|
+
const d = "imageProcessingDeclaration", N = `#ifdef EXPOSURE
|
|
607
|
+
uniform float exposureLinear;
|
|
608
|
+
#endif
|
|
609
|
+
#ifdef CONTRAST
|
|
610
|
+
uniform float contrast;
|
|
611
|
+
#endif
|
|
612
|
+
#if defined(VIGNETTE) || defined(DITHER)
|
|
613
|
+
uniform vec2 vInverseScreenSize;
|
|
614
|
+
#endif
|
|
615
|
+
#ifdef VIGNETTE
|
|
616
|
+
uniform vec4 vignetteSettings1;uniform vec4 vignetteSettings2;
|
|
617
|
+
#endif
|
|
618
|
+
#ifdef COLORCURVES
|
|
619
|
+
uniform vec4 vCameraColorCurveNegative;uniform vec4 vCameraColorCurveNeutral;uniform vec4 vCameraColorCurvePositive;
|
|
620
|
+
#endif
|
|
621
|
+
#ifdef COLORGRADING
|
|
622
|
+
#ifdef COLORGRADING3D
|
|
623
|
+
uniform highp sampler3D txColorTransform;
|
|
624
|
+
#else
|
|
625
|
+
uniform sampler2D txColorTransform;
|
|
626
|
+
#endif
|
|
627
|
+
uniform vec4 colorTransformSettings;
|
|
628
|
+
#endif
|
|
629
|
+
#ifdef DITHER
|
|
630
|
+
uniform float ditherIntensity;
|
|
631
|
+
#endif
|
|
632
|
+
`;
|
|
633
|
+
e.IncludesShadersStore[d] || (e.IncludesShadersStore[d] = N);
|
|
634
|
+
const c = "imageProcessingFunctions", O = `#if defined(COLORGRADING) && !defined(COLORGRADING3D)
|
|
635
|
+
/**
|
|
636
|
+
* Polyfill for SAMPLE_TEXTURE_3D,which is unsupported in WebGL.
|
|
637
|
+
* sampler3dSetting.x=textureOffset (0.5/textureSize).
|
|
638
|
+
* sampler3dSetting.y=textureSize.
|
|
639
|
+
*/
|
|
640
|
+
#define inline
|
|
641
|
+
vec3 sampleTexture3D(sampler2D colorTransform,vec3 color,vec2 sampler3dSetting)
|
|
642
|
+
{float sliceSize=2.0*sampler3dSetting.x;
|
|
643
|
+
#ifdef SAMPLER3DGREENDEPTH
|
|
644
|
+
float sliceContinuous=(color.g-sampler3dSetting.x)*sampler3dSetting.y;
|
|
645
|
+
#else
|
|
646
|
+
float sliceContinuous=(color.b-sampler3dSetting.x)*sampler3dSetting.y;
|
|
647
|
+
#endif
|
|
648
|
+
float sliceInteger=floor(sliceContinuous);float sliceFraction=sliceContinuous-sliceInteger;
|
|
649
|
+
#ifdef SAMPLER3DGREENDEPTH
|
|
650
|
+
vec2 sliceUV=color.rb;
|
|
651
|
+
#else
|
|
652
|
+
vec2 sliceUV=color.rg;
|
|
653
|
+
#endif
|
|
654
|
+
sliceUV.x*=sliceSize;sliceUV.x+=sliceInteger*sliceSize;sliceUV=saturate(sliceUV);vec4 slice0Color=texture2D(colorTransform,sliceUV);sliceUV.x+=sliceSize;sliceUV=saturate(sliceUV);vec4 slice1Color=texture2D(colorTransform,sliceUV);vec3 result=mix(slice0Color.rgb,slice1Color.rgb,sliceFraction);
|
|
655
|
+
#ifdef SAMPLER3DBGRMAP
|
|
656
|
+
color.rgb=result.rgb;
|
|
657
|
+
#else
|
|
658
|
+
color.rgb=result.bgr;
|
|
659
|
+
#endif
|
|
660
|
+
return color;}
|
|
661
|
+
#endif
|
|
662
|
+
#if TONEMAPPING==3
|
|
663
|
+
const float PBRNeutralStartCompression=0.8-0.04;const float PBRNeutralDesaturation=0.15;vec3 PBRNeutralToneMapping( vec3 color ) {float x=min(color.r,min(color.g,color.b));float offset=x<0.08 ? x-6.25*x*x : 0.04;color-=offset;float peak=max(color.r,max(color.g,color.b));if (peak<PBRNeutralStartCompression) return color;float d=1.-PBRNeutralStartCompression;float newPeak=1.-d*d/(peak+d-PBRNeutralStartCompression);color*=newPeak/peak;float g=1.-1./(PBRNeutralDesaturation*(peak-newPeak)+1.);return mix(color,newPeak*vec3(1,1,1),g);}
|
|
664
|
+
#endif
|
|
665
|
+
#if TONEMAPPING==2
|
|
666
|
+
const mat3 ACESInputMat=mat3(
|
|
667
|
+
vec3(0.59719,0.07600,0.02840),
|
|
668
|
+
vec3(0.35458,0.90834,0.13383),
|
|
669
|
+
vec3(0.04823,0.01566,0.83777)
|
|
670
|
+
);const mat3 ACESOutputMat=mat3(
|
|
671
|
+
vec3( 1.60475,-0.10208,-0.00327),
|
|
672
|
+
vec3(-0.53108, 1.10813,-0.07276),
|
|
673
|
+
vec3(-0.07367,-0.00605, 1.07602)
|
|
674
|
+
);vec3 RRTAndODTFit(vec3 v)
|
|
675
|
+
{vec3 a=v*(v+0.0245786)-0.000090537;vec3 b=v*(0.983729*v+0.4329510)+0.238081;return a/b;}
|
|
676
|
+
vec3 ACESFitted(vec3 color)
|
|
677
|
+
{color=ACESInputMat*color;color=RRTAndODTFit(color);color=ACESOutputMat*color;color=saturate(color);return color;}
|
|
678
|
+
#endif
|
|
679
|
+
#define CUSTOM_IMAGEPROCESSINGFUNCTIONS_DEFINITIONS
|
|
680
|
+
vec4 applyImageProcessing(vec4 result) {
|
|
681
|
+
#define CUSTOM_IMAGEPROCESSINGFUNCTIONS_UPDATERESULT_ATSTART
|
|
682
|
+
#ifdef EXPOSURE
|
|
683
|
+
result.rgb*=exposureLinear;
|
|
684
|
+
#endif
|
|
685
|
+
#ifdef VIGNETTE
|
|
686
|
+
vec2 viewportXY=gl_FragCoord.xy*vInverseScreenSize;viewportXY=viewportXY*2.0-1.0;vec3 vignetteXY1=vec3(viewportXY*vignetteSettings1.xy+vignetteSettings1.zw,1.0);float vignetteTerm=dot(vignetteXY1,vignetteXY1);float vignette=pow(vignetteTerm,vignetteSettings2.w);vec3 vignetteColor=vignetteSettings2.rgb;
|
|
687
|
+
#ifdef VIGNETTEBLENDMODEMULTIPLY
|
|
688
|
+
vec3 vignetteColorMultiplier=mix(vignetteColor,vec3(1,1,1),vignette);result.rgb*=vignetteColorMultiplier;
|
|
689
|
+
#endif
|
|
690
|
+
#ifdef VIGNETTEBLENDMODEOPAQUE
|
|
691
|
+
result.rgb=mix(vignetteColor,result.rgb,vignette);
|
|
692
|
+
#endif
|
|
693
|
+
#endif
|
|
694
|
+
#if TONEMAPPING==3
|
|
695
|
+
result.rgb=PBRNeutralToneMapping(result.rgb);
|
|
696
|
+
#elif TONEMAPPING==2
|
|
697
|
+
result.rgb=ACESFitted(result.rgb);
|
|
698
|
+
#elif TONEMAPPING==1
|
|
699
|
+
const float tonemappingCalibration=1.590579;result.rgb=1.0-exp2(-tonemappingCalibration*result.rgb);
|
|
700
|
+
#endif
|
|
701
|
+
result.rgb=toGammaSpace(result.rgb);result.rgb=saturate(result.rgb);
|
|
702
|
+
#ifdef CONTRAST
|
|
703
|
+
vec3 resultHighContrast=result.rgb*result.rgb*(3.0-2.0*result.rgb);if (contrast<1.0) {result.rgb=mix(vec3(0.5,0.5,0.5),result.rgb,contrast);} else {result.rgb=mix(result.rgb,resultHighContrast,contrast-1.0);}
|
|
704
|
+
#endif
|
|
705
|
+
#ifdef COLORGRADING
|
|
706
|
+
vec3 colorTransformInput=result.rgb*colorTransformSettings.xxx+colorTransformSettings.yyy;
|
|
707
|
+
#ifdef COLORGRADING3D
|
|
708
|
+
vec3 colorTransformOutput=texture(txColorTransform,colorTransformInput).rgb;
|
|
709
|
+
#else
|
|
710
|
+
vec3 colorTransformOutput=sampleTexture3D(txColorTransform,colorTransformInput,colorTransformSettings.yz).rgb;
|
|
711
|
+
#endif
|
|
712
|
+
result.rgb=mix(result.rgb,colorTransformOutput,colorTransformSettings.www);
|
|
713
|
+
#endif
|
|
714
|
+
#ifdef COLORCURVES
|
|
715
|
+
float luma=getLuminance(result.rgb);vec2 curveMix=clamp(vec2(luma*3.0-1.5,luma*-3.0+1.5),vec2(0.0),vec2(1.0));vec4 colorCurve=vCameraColorCurveNeutral+curveMix.x*vCameraColorCurvePositive-curveMix.y*vCameraColorCurveNegative;result.rgb*=colorCurve.rgb;result.rgb=mix(vec3(luma),result.rgb,colorCurve.a);
|
|
716
|
+
#endif
|
|
717
|
+
#ifdef DITHER
|
|
718
|
+
float rand=getRand(gl_FragCoord.xy*vInverseScreenSize);float dither=mix(-ditherIntensity,ditherIntensity,rand);result.rgb=saturate(result.rgb+vec3(dither));
|
|
719
|
+
#endif
|
|
720
|
+
#define CUSTOM_IMAGEPROCESSINGFUNCTIONS_UPDATERESULT_ATEND
|
|
721
|
+
return result;}`;
|
|
722
|
+
e.IncludesShadersStore[c] || (e.IncludesShadersStore[c] = O);
|
|
723
|
+
const h = "bumpFragmentMainFunctions", b = `#if defined(BUMP) || defined(CLEARCOAT_BUMP) || defined(ANISOTROPIC) || defined(DETAIL)
|
|
724
|
+
#if defined(TANGENT) && defined(NORMAL)
|
|
725
|
+
varying mat3 vTBN;
|
|
726
|
+
#endif
|
|
727
|
+
#ifdef OBJECTSPACE_NORMALMAP
|
|
728
|
+
uniform mat4 normalMatrix;
|
|
729
|
+
#if defined(WEBGL2) || defined(WEBGPU)
|
|
730
|
+
mat4 toNormalMatrix(mat4 wMatrix)
|
|
731
|
+
{mat4 ret=inverse(wMatrix);ret=transpose(ret);ret[0][3]=0.;ret[1][3]=0.;ret[2][3]=0.;ret[3]=vec4(0.,0.,0.,1.);return ret;}
|
|
732
|
+
#else
|
|
733
|
+
mat4 toNormalMatrix(mat4 m)
|
|
734
|
+
{float
|
|
735
|
+
a00=m[0][0],a01=m[0][1],a02=m[0][2],a03=m[0][3],
|
|
736
|
+
a10=m[1][0],a11=m[1][1],a12=m[1][2],a13=m[1][3],
|
|
737
|
+
a20=m[2][0],a21=m[2][1],a22=m[2][2],a23=m[2][3],
|
|
738
|
+
a30=m[3][0],a31=m[3][1],a32=m[3][2],a33=m[3][3],
|
|
739
|
+
b00=a00*a11-a01*a10,
|
|
740
|
+
b01=a00*a12-a02*a10,
|
|
741
|
+
b02=a00*a13-a03*a10,
|
|
742
|
+
b03=a01*a12-a02*a11,
|
|
743
|
+
b04=a01*a13-a03*a11,
|
|
744
|
+
b05=a02*a13-a03*a12,
|
|
745
|
+
b06=a20*a31-a21*a30,
|
|
746
|
+
b07=a20*a32-a22*a30,
|
|
747
|
+
b08=a20*a33-a23*a30,
|
|
748
|
+
b09=a21*a32-a22*a31,
|
|
749
|
+
b10=a21*a33-a23*a31,
|
|
750
|
+
b11=a22*a33-a23*a32,
|
|
751
|
+
det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;mat4 mi=mat4(
|
|
752
|
+
a11*b11-a12*b10+a13*b09,
|
|
753
|
+
a02*b10-a01*b11-a03*b09,
|
|
754
|
+
a31*b05-a32*b04+a33*b03,
|
|
755
|
+
a22*b04-a21*b05-a23*b03,
|
|
756
|
+
a12*b08-a10*b11-a13*b07,
|
|
757
|
+
a00*b11-a02*b08+a03*b07,
|
|
758
|
+
a32*b02-a30*b05-a33*b01,
|
|
759
|
+
a20*b05-a22*b02+a23*b01,
|
|
760
|
+
a10*b10-a11*b08+a13*b06,
|
|
761
|
+
a01*b08-a00*b10-a03*b06,
|
|
762
|
+
a30*b04-a31*b02+a33*b00,
|
|
763
|
+
a21*b02-a20*b04-a23*b00,
|
|
764
|
+
a11*b07-a10*b09-a12*b06,
|
|
765
|
+
a00*b09-a01*b07+a02*b06,
|
|
766
|
+
a31*b01-a30*b03-a32*b00,
|
|
767
|
+
a20*b03-a21*b01+a22*b00)/det;return mat4(mi[0][0],mi[1][0],mi[2][0],mi[3][0],
|
|
768
|
+
mi[0][1],mi[1][1],mi[2][1],mi[3][1],
|
|
769
|
+
mi[0][2],mi[1][2],mi[2][2],mi[3][2],
|
|
770
|
+
mi[0][3],mi[1][3],mi[2][3],mi[3][3]);}
|
|
771
|
+
#endif
|
|
772
|
+
#endif
|
|
773
|
+
vec3 perturbNormalBase(mat3 cotangentFrame,vec3 normal,float scale)
|
|
774
|
+
{
|
|
775
|
+
#ifdef NORMALXYSCALE
|
|
776
|
+
normal=normalize(normal*vec3(scale,scale,1.0));
|
|
777
|
+
#endif
|
|
778
|
+
return normalize(cotangentFrame*normal);}
|
|
779
|
+
vec3 perturbNormal(mat3 cotangentFrame,vec3 textureSample,float scale)
|
|
780
|
+
{return perturbNormalBase(cotangentFrame,textureSample*2.0-1.0,scale);}
|
|
781
|
+
mat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv,vec2 tangentSpaceParams)
|
|
782
|
+
{vec3 dp1=dFdx(p);vec3 dp2=dFdy(p);vec2 duv1=dFdx(uv);vec2 duv2=dFdy(uv);vec3 dp2perp=cross(dp2,normal);vec3 dp1perp=cross(normal,dp1);vec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;vec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;tangent*=tangentSpaceParams.x;bitangent*=tangentSpaceParams.y;float det=max(dot(tangent,tangent),dot(bitangent,bitangent));float invmax=det==0.0 ? 0.0 : inversesqrt(det);return mat3(tangent*invmax,bitangent*invmax,normal);}
|
|
783
|
+
#endif
|
|
784
|
+
`;
|
|
785
|
+
e.IncludesShadersStore[h] || (e.IncludesShadersStore[h] = b);
|
|
786
|
+
const v = "bumpFragmentFunctions", R = `#if defined(BUMP)
|
|
787
|
+
#include<samplerFragmentDeclaration>(_DEFINENAME_,BUMP,_VARYINGNAME_,Bump,_SAMPLERNAME_,bump)
|
|
788
|
+
#endif
|
|
789
|
+
#if defined(DETAIL)
|
|
790
|
+
#include<samplerFragmentDeclaration>(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail,_SAMPLERNAME_,detail)
|
|
791
|
+
#endif
|
|
792
|
+
#if defined(BUMP) && defined(PARALLAX)
|
|
793
|
+
const float minSamples=4.;const float maxSamples=15.;const int iMaxSamples=15;vec2 parallaxOcclusion(vec3 vViewDirCoT,vec3 vNormalCoT,vec2 texCoord,float parallaxScale) {float parallaxLimit=length(vViewDirCoT.xy)/vViewDirCoT.z;parallaxLimit*=parallaxScale;vec2 vOffsetDir=normalize(vViewDirCoT.xy);vec2 vMaxOffset=vOffsetDir*parallaxLimit;float numSamples=maxSamples+(dot(vViewDirCoT,vNormalCoT)*(minSamples-maxSamples));float stepSize=1.0/numSamples;float currRayHeight=1.0;vec2 vCurrOffset=vec2(0,0);vec2 vLastOffset=vec2(0,0);float lastSampledHeight=1.0;float currSampledHeight=1.0;bool keepWorking=true;for (int i=0; i<iMaxSamples; i++)
|
|
794
|
+
{currSampledHeight=texture2D(bumpSampler,texCoord+vCurrOffset).w;if (!keepWorking)
|
|
795
|
+
{}
|
|
796
|
+
else if (currSampledHeight>currRayHeight)
|
|
797
|
+
{float delta1=currSampledHeight-currRayHeight;float delta2=(currRayHeight+stepSize)-lastSampledHeight;float ratio=delta1/(delta1+delta2);vCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;keepWorking=false;}
|
|
798
|
+
else
|
|
799
|
+
{currRayHeight-=stepSize;vLastOffset=vCurrOffset;
|
|
800
|
+
#ifdef PARALLAX_RHS
|
|
801
|
+
vCurrOffset-=stepSize*vMaxOffset;
|
|
802
|
+
#else
|
|
803
|
+
vCurrOffset+=stepSize*vMaxOffset;
|
|
804
|
+
#endif
|
|
805
|
+
lastSampledHeight=currSampledHeight;}}
|
|
806
|
+
return vCurrOffset;}
|
|
807
|
+
vec2 parallaxOffset(vec3 viewDir,float heightScale)
|
|
808
|
+
{float height=texture2D(bumpSampler,vBumpUV).w;vec2 texCoordOffset=heightScale*viewDir.xy*height;
|
|
809
|
+
#ifdef PARALLAX_RHS
|
|
810
|
+
return texCoordOffset;
|
|
811
|
+
#else
|
|
812
|
+
return -texCoordOffset;
|
|
813
|
+
#endif
|
|
814
|
+
}
|
|
815
|
+
#endif
|
|
816
|
+
`;
|
|
817
|
+
e.IncludesShadersStore[v] || (e.IncludesShadersStore[v] = R);
|
|
818
|
+
const u = "clipPlaneFragmentDeclaration", U = `#ifdef CLIPPLANE
|
|
819
|
+
varying float fClipDistance;
|
|
820
|
+
#endif
|
|
821
|
+
#ifdef CLIPPLANE2
|
|
822
|
+
varying float fClipDistance2;
|
|
823
|
+
#endif
|
|
824
|
+
#ifdef CLIPPLANE3
|
|
825
|
+
varying float fClipDistance3;
|
|
826
|
+
#endif
|
|
827
|
+
#ifdef CLIPPLANE4
|
|
828
|
+
varying float fClipDistance4;
|
|
829
|
+
#endif
|
|
830
|
+
#ifdef CLIPPLANE5
|
|
831
|
+
varying float fClipDistance5;
|
|
832
|
+
#endif
|
|
833
|
+
#ifdef CLIPPLANE6
|
|
834
|
+
varying float fClipDistance6;
|
|
835
|
+
#endif
|
|
836
|
+
`;
|
|
837
|
+
e.IncludesShadersStore[u] || (e.IncludesShadersStore[u] = U);
|
|
838
|
+
const p = "fogFragmentDeclaration", z = `#ifdef FOG
|
|
839
|
+
#define FOGMODE_NONE 0.
|
|
840
|
+
#define FOGMODE_EXP 1.
|
|
841
|
+
#define FOGMODE_EXP2 2.
|
|
842
|
+
#define FOGMODE_LINEAR 3.
|
|
843
|
+
#define E 2.71828
|
|
844
|
+
uniform vec4 vFogInfos;uniform vec3 vFogColor;varying vec3 vFogDistance;float CalcFogFactor()
|
|
845
|
+
{float fogCoeff=1.0;float fogStart=vFogInfos.y;float fogEnd=vFogInfos.z;float fogDensity=vFogInfos.w;float fogDistance=length(vFogDistance);if (FOGMODE_LINEAR==vFogInfos.x)
|
|
846
|
+
{fogCoeff=(fogEnd-fogDistance)/(fogEnd-fogStart);}
|
|
847
|
+
else if (FOGMODE_EXP==vFogInfos.x)
|
|
848
|
+
{fogCoeff=1.0/pow(E,fogDistance*fogDensity);}
|
|
849
|
+
else if (FOGMODE_EXP2==vFogInfos.x)
|
|
850
|
+
{fogCoeff=1.0/pow(E,fogDistance*fogDistance*fogDensity*fogDensity);}
|
|
851
|
+
return clamp(fogCoeff,0.0,1.0);}
|
|
852
|
+
#endif
|
|
853
|
+
`;
|
|
854
|
+
e.IncludesShadersStore[p] || (e.IncludesShadersStore[p] = z);
|
|
855
|
+
const m = "clipPlaneFragment", _ = `#if defined(CLIPPLANE) || defined(CLIPPLANE2) || defined(CLIPPLANE3) || defined(CLIPPLANE4) || defined(CLIPPLANE5) || defined(CLIPPLANE6)
|
|
856
|
+
if (false) {}
|
|
857
|
+
#endif
|
|
858
|
+
#ifdef CLIPPLANE
|
|
859
|
+
else if (fClipDistance>0.0)
|
|
860
|
+
{discard;}
|
|
861
|
+
#endif
|
|
862
|
+
#ifdef CLIPPLANE2
|
|
863
|
+
else if (fClipDistance2>0.0)
|
|
864
|
+
{discard;}
|
|
865
|
+
#endif
|
|
866
|
+
#ifdef CLIPPLANE3
|
|
867
|
+
else if (fClipDistance3>0.0)
|
|
868
|
+
{discard;}
|
|
869
|
+
#endif
|
|
870
|
+
#ifdef CLIPPLANE4
|
|
871
|
+
else if (fClipDistance4>0.0)
|
|
872
|
+
{discard;}
|
|
873
|
+
#endif
|
|
874
|
+
#ifdef CLIPPLANE5
|
|
875
|
+
else if (fClipDistance5>0.0)
|
|
876
|
+
{discard;}
|
|
877
|
+
#endif
|
|
878
|
+
#ifdef CLIPPLANE6
|
|
879
|
+
else if (fClipDistance6>0.0)
|
|
880
|
+
{discard;}
|
|
881
|
+
#endif
|
|
882
|
+
`;
|
|
883
|
+
e.IncludesShadersStore[m] || (e.IncludesShadersStore[m] = _);
|
|
884
|
+
const S = "bumpFragment", H = `vec2 uvOffset=vec2(0.0,0.0);
|
|
885
|
+
#if defined(BUMP) || defined(PARALLAX) || defined(DETAIL)
|
|
886
|
+
#ifdef NORMALXYSCALE
|
|
887
|
+
float normalScale=1.0;
|
|
888
|
+
#elif defined(BUMP)
|
|
889
|
+
float normalScale=vBumpInfos.y;
|
|
890
|
+
#else
|
|
891
|
+
float normalScale=1.0;
|
|
892
|
+
#endif
|
|
893
|
+
#if defined(TANGENT) && defined(NORMAL)
|
|
894
|
+
mat3 TBN=vTBN;
|
|
895
|
+
#elif defined(BUMP)
|
|
896
|
+
vec2 TBNUV=gl_FrontFacing ? vBumpUV : -vBumpUV;mat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,TBNUV,vTangentSpaceParams);
|
|
897
|
+
#else
|
|
898
|
+
vec2 TBNUV=gl_FrontFacing ? vDetailUV : -vDetailUV;mat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,TBNUV,vec2(1.,1.));
|
|
899
|
+
#endif
|
|
900
|
+
#elif defined(ANISOTROPIC)
|
|
901
|
+
#if defined(TANGENT) && defined(NORMAL)
|
|
902
|
+
mat3 TBN=vTBN;
|
|
903
|
+
#else
|
|
904
|
+
vec2 TBNUV=gl_FrontFacing ? vMainUV1 : -vMainUV1;mat3 TBN=cotangent_frame(normalW,vPositionW,TBNUV,vec2(1.,1.));
|
|
905
|
+
#endif
|
|
906
|
+
#endif
|
|
907
|
+
#ifdef PARALLAX
|
|
908
|
+
mat3 invTBN=transposeMat3(TBN);
|
|
909
|
+
#ifdef PARALLAXOCCLUSION
|
|
910
|
+
uvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);
|
|
911
|
+
#else
|
|
912
|
+
uvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);
|
|
913
|
+
#endif
|
|
914
|
+
#endif
|
|
915
|
+
#ifdef DETAIL
|
|
916
|
+
vec4 detailColor=texture2D(detailSampler,vDetailUV+uvOffset);vec2 detailNormalRG=detailColor.wy*2.0-1.0;float detailNormalB=sqrt(1.-saturate(dot(detailNormalRG,detailNormalRG)));vec3 detailNormal=vec3(detailNormalRG,detailNormalB);
|
|
917
|
+
#endif
|
|
918
|
+
#ifdef BUMP
|
|
919
|
+
#ifdef OBJECTSPACE_NORMALMAP
|
|
920
|
+
#define CUSTOM_FRAGMENT_BUMP_FRAGMENT
|
|
921
|
+
normalW=normalize(texture2D(bumpSampler,vBumpUV).xyz *2.0-1.0);normalW=normalize(mat3(normalMatrix)*normalW);
|
|
922
|
+
#elif !defined(DETAIL)
|
|
923
|
+
normalW=perturbNormal(TBN,texture2D(bumpSampler,vBumpUV+uvOffset).xyz,vBumpInfos.y);
|
|
924
|
+
#else
|
|
925
|
+
vec3 bumpNormal=texture2D(bumpSampler,vBumpUV+uvOffset).xyz*2.0-1.0;
|
|
926
|
+
#if DETAIL_NORMALBLENDMETHOD==0
|
|
927
|
+
detailNormal.xy*=vDetailInfos.z;vec3 blendedNormal=normalize(vec3(bumpNormal.xy+detailNormal.xy,bumpNormal.z*detailNormal.z));
|
|
928
|
+
#elif DETAIL_NORMALBLENDMETHOD==1
|
|
929
|
+
detailNormal.xy*=vDetailInfos.z;bumpNormal+=vec3(0.0,0.0,1.0);detailNormal*=vec3(-1.0,-1.0,1.0);vec3 blendedNormal=bumpNormal*dot(bumpNormal,detailNormal)/bumpNormal.z-detailNormal;
|
|
930
|
+
#endif
|
|
931
|
+
normalW=perturbNormalBase(TBN,blendedNormal,vBumpInfos.y);
|
|
932
|
+
#endif
|
|
933
|
+
#elif defined(DETAIL)
|
|
934
|
+
detailNormal.xy*=vDetailInfos.z;normalW=perturbNormalBase(TBN,detailNormal,vDetailInfos.z);
|
|
935
|
+
#endif
|
|
936
|
+
`;
|
|
937
|
+
e.IncludesShadersStore[S] || (e.IncludesShadersStore[S] = H);
|
|
938
|
+
const g = "decalFragment", W = `#ifdef DECAL
|
|
939
|
+
#ifdef GAMMADECAL
|
|
940
|
+
decalColor.rgb=toLinearSpace(decalColor.rgb);
|
|
941
|
+
#endif
|
|
942
|
+
#ifdef DECAL_SMOOTHALPHA
|
|
943
|
+
decalColor.a*=decalColor.a;
|
|
944
|
+
#endif
|
|
945
|
+
surfaceAlbedo.rgb=mix(surfaceAlbedo.rgb,decalColor.rgb,decalColor.a);
|
|
946
|
+
#endif
|
|
947
|
+
`;
|
|
948
|
+
e.IncludesShadersStore[g] || (e.IncludesShadersStore[g] = W);
|
|
949
|
+
const w = "depthPrePass", G = `#ifdef DEPTHPREPASS
|
|
950
|
+
gl_FragColor=vec4(0.,0.,0.,1.0);return;
|
|
951
|
+
#endif
|
|
952
|
+
`;
|
|
953
|
+
e.IncludesShadersStore[w] || (e.IncludesShadersStore[w] = G);
|
|
954
|
+
const D = "lightFragment", V = `#ifdef LIGHT{X}
|
|
955
|
+
#if defined(SHADOWONLY) || defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X})
|
|
956
|
+
#else
|
|
957
|
+
vec4 diffuse{X}=light{X}.vLightDiffuse;
|
|
958
|
+
#define CUSTOM_LIGHT{X}_COLOR
|
|
959
|
+
#ifdef PBR
|
|
960
|
+
#ifdef SPOTLIGHT{X}
|
|
961
|
+
preInfo=computePointAndSpotPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW,vPositionW);
|
|
962
|
+
#elif defined(POINTLIGHT{X})
|
|
963
|
+
preInfo=computePointAndSpotPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW,vPositionW);
|
|
964
|
+
#elif defined(HEMILIGHT{X})
|
|
965
|
+
preInfo=computeHemisphericPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW);
|
|
966
|
+
#elif defined(DIRLIGHT{X})
|
|
967
|
+
preInfo=computeDirectionalPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW);
|
|
968
|
+
#elif defined(AREALIGHT{X}) && defined(AREALIGHTSUPPORTED)
|
|
969
|
+
preInfo=computeAreaPreLightingInfo(areaLightsLTC1Sampler,areaLightsLTC2Sampler,viewDirectionW,normalW,vPositionW,light{X}.vLightData,light{X}.vLightWidth.xyz,light{X}.vLightHeight.xyz,roughness);
|
|
970
|
+
#endif
|
|
971
|
+
preInfo.NdotV=NdotV;
|
|
972
|
+
#ifdef SPOTLIGHT{X}
|
|
973
|
+
#ifdef LIGHT_FALLOFF_GLTF{X}
|
|
974
|
+
preInfo.attenuation=computeDistanceLightFalloff_GLTF(preInfo.lightDistanceSquared,light{X}.vLightFalloff.y);
|
|
975
|
+
#ifdef IESLIGHTTEXTURE{X}
|
|
976
|
+
preInfo.attenuation*=computeDirectionalLightFalloff_IES(light{X}.vLightDirection.xyz,preInfo.L,iesLightTexture{X});
|
|
977
|
+
#else
|
|
978
|
+
preInfo.attenuation*=computeDirectionalLightFalloff_GLTF(light{X}.vLightDirection.xyz,preInfo.L,light{X}.vLightFalloff.z,light{X}.vLightFalloff.w);
|
|
979
|
+
#endif
|
|
980
|
+
#elif defined(LIGHT_FALLOFF_PHYSICAL{X})
|
|
981
|
+
preInfo.attenuation=computeDistanceLightFalloff_Physical(preInfo.lightDistanceSquared);
|
|
982
|
+
#ifdef IESLIGHTTEXTURE{X}
|
|
983
|
+
preInfo.attenuation*=computeDirectionalLightFalloff_IES(light{X}.vLightDirection.xyz,preInfo.L,iesLightTexture{X});
|
|
984
|
+
#else
|
|
985
|
+
preInfo.attenuation*=computeDirectionalLightFalloff_Physical(light{X}.vLightDirection.xyz,preInfo.L,light{X}.vLightDirection.w);
|
|
986
|
+
#endif
|
|
987
|
+
#elif defined(LIGHT_FALLOFF_STANDARD{X})
|
|
988
|
+
preInfo.attenuation=computeDistanceLightFalloff_Standard(preInfo.lightOffset,light{X}.vLightFalloff.x);
|
|
989
|
+
#ifdef IESLIGHTTEXTURE{X}
|
|
990
|
+
preInfo.attenuation*=computeDirectionalLightFalloff_IES(light{X}.vLightDirection.xyz,preInfo.L,iesLightTexture{X});
|
|
991
|
+
#else
|
|
992
|
+
preInfo.attenuation*=computeDirectionalLightFalloff_Standard(light{X}.vLightDirection.xyz,preInfo.L,light{X}.vLightDirection.w,light{X}.vLightData.w);
|
|
993
|
+
#endif
|
|
994
|
+
#else
|
|
995
|
+
preInfo.attenuation=computeDistanceLightFalloff(preInfo.lightOffset,preInfo.lightDistanceSquared,light{X}.vLightFalloff.x,light{X}.vLightFalloff.y);
|
|
996
|
+
#ifdef IESLIGHTTEXTURE{X}
|
|
997
|
+
preInfo.attenuation*=computeDirectionalLightFalloff_IES(light{X}.vLightDirection.xyz,preInfo.L,iesLightTexture{X});
|
|
998
|
+
#else
|
|
999
|
+
preInfo.attenuation*=computeDirectionalLightFalloff(light{X}.vLightDirection.xyz,preInfo.L,light{X}.vLightDirection.w,light{X}.vLightData.w,light{X}.vLightFalloff.z,light{X}.vLightFalloff.w);
|
|
1000
|
+
#endif
|
|
1001
|
+
#endif
|
|
1002
|
+
#elif defined(POINTLIGHT{X})
|
|
1003
|
+
#ifdef LIGHT_FALLOFF_GLTF{X}
|
|
1004
|
+
preInfo.attenuation=computeDistanceLightFalloff_GLTF(preInfo.lightDistanceSquared,light{X}.vLightFalloff.y);
|
|
1005
|
+
#elif defined(LIGHT_FALLOFF_PHYSICAL{X})
|
|
1006
|
+
preInfo.attenuation=computeDistanceLightFalloff_Physical(preInfo.lightDistanceSquared);
|
|
1007
|
+
#elif defined(LIGHT_FALLOFF_STANDARD{X})
|
|
1008
|
+
preInfo.attenuation=computeDistanceLightFalloff_Standard(preInfo.lightOffset,light{X}.vLightFalloff.x);
|
|
1009
|
+
#else
|
|
1010
|
+
preInfo.attenuation=computeDistanceLightFalloff(preInfo.lightOffset,preInfo.lightDistanceSquared,light{X}.vLightFalloff.x,light{X}.vLightFalloff.y);
|
|
1011
|
+
#endif
|
|
1012
|
+
#else
|
|
1013
|
+
preInfo.attenuation=1.0;
|
|
1014
|
+
#endif
|
|
1015
|
+
#if defined(HEMILIGHT{X}) || defined(AREALIGHT{X})
|
|
1016
|
+
preInfo.roughness=roughness;
|
|
1017
|
+
#else
|
|
1018
|
+
preInfo.roughness=adjustRoughnessFromLightProperties(roughness,light{X}.vLightSpecular.a,preInfo.lightDistance);
|
|
1019
|
+
#endif
|
|
1020
|
+
preInfo.diffuseRoughness=diffuseRoughness;preInfo.surfaceAlbedo=surfaceAlbedo;
|
|
1021
|
+
#ifdef IRIDESCENCE
|
|
1022
|
+
preInfo.iridescenceIntensity=iridescenceIntensity;
|
|
1023
|
+
#endif
|
|
1024
|
+
#ifdef SS_TRANSLUCENCY
|
|
1025
|
+
info.diffuseTransmission=vec3(0.0);
|
|
1026
|
+
#endif
|
|
1027
|
+
#ifdef HEMILIGHT{X}
|
|
1028
|
+
info.diffuse=computeHemisphericDiffuseLighting(preInfo,diffuse{X}.rgb,light{X}.vLightGround);
|
|
1029
|
+
#elif defined(AREALIGHT{X})
|
|
1030
|
+
info.diffuse=computeAreaDiffuseLighting(preInfo,diffuse{X}.rgb);
|
|
1031
|
+
#elif defined(SS_TRANSLUCENCY)
|
|
1032
|
+
#ifndef SS_TRANSLUCENCY_LEGACY
|
|
1033
|
+
info.diffuse=computeDiffuseLighting(preInfo,diffuse{X}.rgb)*(1.0-subSurfaceOut.translucencyIntensity);info.diffuseTransmission=computeDiffuseTransmittedLighting(preInfo,diffuse{X}.rgb,subSurfaceOut.transmittance);
|
|
1034
|
+
#else
|
|
1035
|
+
info.diffuse=computeDiffuseTransmittedLighting(preInfo,diffuse{X}.rgb,subSurfaceOut.transmittance);
|
|
1036
|
+
#endif
|
|
1037
|
+
#else
|
|
1038
|
+
info.diffuse=computeDiffuseLighting(preInfo,diffuse{X}.rgb);
|
|
1039
|
+
#endif
|
|
1040
|
+
#ifdef SPECULARTERM
|
|
1041
|
+
#if AREALIGHT{X}
|
|
1042
|
+
info.specular=computeAreaSpecularLighting(preInfo,light{X}.vLightSpecular.rgb,clearcoatOut.specularEnvironmentR0,reflectivityOut.colorReflectanceF90);
|
|
1043
|
+
#else
|
|
1044
|
+
#if (CONDUCTOR_SPECULAR_MODEL==CONDUCTOR_SPECULAR_MODEL_OPENPBR)
|
|
1045
|
+
{vec3 metalFresnel=reflectivityOut.specularWeight*getF82Specular(preInfo.VdotH,clearcoatOut.specularEnvironmentR0,reflectivityOut.colorReflectanceF90,reflectivityOut.roughness);vec3 dielectricFresnel=fresnelSchlickGGX(preInfo.VdotH,reflectivityOut.dielectricColorF0,reflectivityOut.colorReflectanceF90);coloredFresnel=mix(dielectricFresnel,metalFresnel,reflectivityOut.metallic);}
|
|
1046
|
+
#else
|
|
1047
|
+
coloredFresnel=fresnelSchlickGGX(preInfo.VdotH,clearcoatOut.specularEnvironmentR0,reflectivityOut.colorReflectanceF90);
|
|
1048
|
+
#endif
|
|
1049
|
+
#ifndef LEGACY_SPECULAR_ENERGY_CONSERVATION
|
|
1050
|
+
{float NdotH=dot(normalW,preInfo.H);vec3 fresnel=fresnelSchlickGGX(NdotH,vec3(reflectanceF0),specularEnvironmentR90);info.diffuse*=(vec3(1.0)-fresnel);}
|
|
1051
|
+
#endif
|
|
1052
|
+
#ifdef ANISOTROPIC
|
|
1053
|
+
info.specular=computeAnisotropicSpecularLighting(preInfo,viewDirectionW,normalW,anisotropicOut.anisotropicTangent,anisotropicOut.anisotropicBitangent,anisotropicOut.anisotropy,clearcoatOut.specularEnvironmentR0,specularEnvironmentR90,AARoughnessFactors.x,diffuse{X}.rgb);
|
|
1054
|
+
#else
|
|
1055
|
+
info.specular=computeSpecularLighting(preInfo,normalW,clearcoatOut.specularEnvironmentR0,coloredFresnel,AARoughnessFactors.x,diffuse{X}.rgb);
|
|
1056
|
+
#endif
|
|
1057
|
+
#endif
|
|
1058
|
+
#endif
|
|
1059
|
+
#ifndef AREALIGHT{X}
|
|
1060
|
+
#ifdef SHEEN
|
|
1061
|
+
#ifdef SHEEN_LINKWITHALBEDO
|
|
1062
|
+
preInfo.roughness=sheenOut.sheenIntensity;
|
|
1063
|
+
#else
|
|
1064
|
+
#ifdef HEMILIGHT{X}
|
|
1065
|
+
preInfo.roughness=sheenOut.sheenRoughness;
|
|
1066
|
+
#else
|
|
1067
|
+
preInfo.roughness=adjustRoughnessFromLightProperties(sheenOut.sheenRoughness,light{X}.vLightSpecular.a,preInfo.lightDistance);
|
|
1068
|
+
#endif
|
|
1069
|
+
#endif
|
|
1070
|
+
info.sheen=computeSheenLighting(preInfo,normalW,sheenOut.sheenColor,specularEnvironmentR90,AARoughnessFactors.x,diffuse{X}.rgb);
|
|
1071
|
+
#endif
|
|
1072
|
+
#ifdef CLEARCOAT
|
|
1073
|
+
#ifdef HEMILIGHT{X}
|
|
1074
|
+
preInfo.roughness=clearcoatOut.clearCoatRoughness;
|
|
1075
|
+
#else
|
|
1076
|
+
preInfo.roughness=adjustRoughnessFromLightProperties(clearcoatOut.clearCoatRoughness,light{X}.vLightSpecular.a,preInfo.lightDistance);
|
|
1077
|
+
#endif
|
|
1078
|
+
info.clearCoat=computeClearCoatLighting(preInfo,clearcoatOut.clearCoatNormalW,clearcoatOut.clearCoatAARoughnessFactors.x,clearcoatOut.clearCoatIntensity,diffuse{X}.rgb);
|
|
1079
|
+
#ifdef CLEARCOAT_TINT
|
|
1080
|
+
absorption=computeClearCoatLightingAbsorption(clearcoatOut.clearCoatNdotVRefract,preInfo.L,clearcoatOut.clearCoatNormalW,clearcoatOut.clearCoatColor,clearcoatOut.clearCoatThickness,clearcoatOut.clearCoatIntensity);info.diffuse*=absorption;
|
|
1081
|
+
#ifdef SS_TRANSLUCENCY
|
|
1082
|
+
info.diffuseTransmission*=absorption;
|
|
1083
|
+
#endif
|
|
1084
|
+
#ifdef SPECULARTERM
|
|
1085
|
+
info.specular*=absorption;
|
|
1086
|
+
#endif
|
|
1087
|
+
#endif
|
|
1088
|
+
info.diffuse*=info.clearCoat.w;
|
|
1089
|
+
#ifdef SS_TRANSLUCENCY
|
|
1090
|
+
info.diffuseTransmission*=info.clearCoat.w;
|
|
1091
|
+
#endif
|
|
1092
|
+
#ifdef SPECULARTERM
|
|
1093
|
+
info.specular*=info.clearCoat.w;
|
|
1094
|
+
#endif
|
|
1095
|
+
#ifdef SHEEN
|
|
1096
|
+
info.sheen*=info.clearCoat.w;
|
|
1097
|
+
#endif
|
|
1098
|
+
#endif
|
|
1099
|
+
#endif
|
|
1100
|
+
#else
|
|
1101
|
+
#ifdef SPOTLIGHT{X}
|
|
1102
|
+
#ifdef IESLIGHTTEXTURE{X}
|
|
1103
|
+
info=computeIESSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,diffuse{X}.rgb,light{X}.vLightSpecular.rgb,diffuse{X}.a,glossiness,iesLightTexture{X});
|
|
1104
|
+
#else
|
|
1105
|
+
info=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,diffuse{X}.rgb,light{X}.vLightSpecular.rgb,diffuse{X}.a,glossiness);
|
|
1106
|
+
#endif
|
|
1107
|
+
#elif defined(HEMILIGHT{X})
|
|
1108
|
+
info=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,diffuse{X}.rgb,light{X}.vLightSpecular.rgb,light{X}.vLightGround,glossiness);
|
|
1109
|
+
#elif defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})
|
|
1110
|
+
info=computeLighting(viewDirectionW,normalW,light{X}.vLightData,diffuse{X}.rgb,light{X}.vLightSpecular.rgb,diffuse{X}.a,glossiness);
|
|
1111
|
+
#elif defined(AREALIGHT{X}) && defined(AREALIGHTSUPPORTED)
|
|
1112
|
+
info=computeAreaLighting(areaLightsLTC1Sampler,areaLightsLTC2Sampler,viewDirectionW,normalW,vPositionW,light{X}.vLightData.xyz,light{X}.vLightWidth.rgb,light{X}.vLightHeight.rgb,diffuse{X}.rgb,light{X}.vLightSpecular.rgb,
|
|
1113
|
+
#ifdef AREALIGHTNOROUGHTNESS
|
|
1114
|
+
0.5
|
|
1115
|
+
#else
|
|
1116
|
+
vReflectionInfos.y
|
|
1117
|
+
#endif
|
|
1118
|
+
);
|
|
1119
|
+
#endif
|
|
1120
|
+
#endif
|
|
1121
|
+
#ifdef PROJECTEDLIGHTTEXTURE{X}
|
|
1122
|
+
info.diffuse*=computeProjectionTextureDiffuseLighting(projectionLightTexture{X},textureProjectionMatrix{X},vPositionW);
|
|
1123
|
+
#endif
|
|
1124
|
+
#endif
|
|
1125
|
+
#ifdef SHADOW{X}
|
|
1126
|
+
#ifdef SHADOWCSM{X}
|
|
1127
|
+
for (int i=0; i<SHADOWCSMNUM_CASCADES{X}; i++)
|
|
1128
|
+
{
|
|
1129
|
+
#ifdef SHADOWCSM_RIGHTHANDED{X}
|
|
1130
|
+
diff{X}=viewFrustumZ{X}[i]+vPositionFromCamera{X}.z;
|
|
1131
|
+
#else
|
|
1132
|
+
diff{X}=viewFrustumZ{X}[i]-vPositionFromCamera{X}.z;
|
|
1133
|
+
#endif
|
|
1134
|
+
if (diff{X}>=0.) {index{X}=i;break;}}
|
|
1135
|
+
#ifdef SHADOWCSMUSESHADOWMAXZ{X}
|
|
1136
|
+
if (index{X}>=0)
|
|
1137
|
+
#endif
|
|
1138
|
+
{
|
|
1139
|
+
#if defined(SHADOWPCF{X})
|
|
1140
|
+
#if defined(SHADOWLOWQUALITY{X})
|
|
1141
|
+
shadow=computeShadowWithCSMPCF1(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowTexture{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1142
|
+
#elif defined(SHADOWMEDIUMQUALITY{X})
|
|
1143
|
+
shadow=computeShadowWithCSMPCF3(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowTexture{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1144
|
+
#else
|
|
1145
|
+
shadow=computeShadowWithCSMPCF5(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowTexture{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1146
|
+
#endif
|
|
1147
|
+
#elif defined(SHADOWPCSS{X})
|
|
1148
|
+
#if defined(SHADOWLOWQUALITY{X})
|
|
1149
|
+
shadow=computeShadowWithCSMPCSS16(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthTexture{X},shadowTexture{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});
|
|
1150
|
+
#elif defined(SHADOWMEDIUMQUALITY{X})
|
|
1151
|
+
shadow=computeShadowWithCSMPCSS32(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthTexture{X},shadowTexture{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});
|
|
1152
|
+
#else
|
|
1153
|
+
shadow=computeShadowWithCSMPCSS64(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthTexture{X},shadowTexture{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});
|
|
1154
|
+
#endif
|
|
1155
|
+
#else
|
|
1156
|
+
shadow=computeShadowCSM(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowTexture{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1157
|
+
#endif
|
|
1158
|
+
#ifdef SHADOWCSMDEBUG{X}
|
|
1159
|
+
shadowDebug{X}=vec3(shadow)*vCascadeColorsMultiplier{X}[index{X}];
|
|
1160
|
+
#endif
|
|
1161
|
+
#ifndef SHADOWCSMNOBLEND{X}
|
|
1162
|
+
float frustumLength=frustumLengths{X}[index{X}];float diffRatio=clamp(diff{X}/frustumLength,0.,1.)*cascadeBlendFactor{X};if (index{X}<(SHADOWCSMNUM_CASCADES{X}-1) && diffRatio<1.)
|
|
1163
|
+
{index{X}+=1;float nextShadow=0.;
|
|
1164
|
+
#if defined(SHADOWPCF{X})
|
|
1165
|
+
#if defined(SHADOWLOWQUALITY{X})
|
|
1166
|
+
nextShadow=computeShadowWithCSMPCF1(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowTexture{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1167
|
+
#elif defined(SHADOWMEDIUMQUALITY{X})
|
|
1168
|
+
nextShadow=computeShadowWithCSMPCF3(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowTexture{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1169
|
+
#else
|
|
1170
|
+
nextShadow=computeShadowWithCSMPCF5(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowTexture{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1171
|
+
#endif
|
|
1172
|
+
#elif defined(SHADOWPCSS{X})
|
|
1173
|
+
#if defined(SHADOWLOWQUALITY{X})
|
|
1174
|
+
nextShadow=computeShadowWithCSMPCSS16(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthTexture{X},shadowTexture{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});
|
|
1175
|
+
#elif defined(SHADOWMEDIUMQUALITY{X})
|
|
1176
|
+
nextShadow=computeShadowWithCSMPCSS32(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthTexture{X},shadowTexture{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});
|
|
1177
|
+
#else
|
|
1178
|
+
nextShadow=computeShadowWithCSMPCSS64(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],depthTexture{X},shadowTexture{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w,lightSizeUVCorrection{X}[index{X}],depthCorrection{X}[index{X}],penumbraDarkness{X});
|
|
1179
|
+
#endif
|
|
1180
|
+
#else
|
|
1181
|
+
nextShadow=computeShadowCSM(float(index{X}),vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],shadowTexture{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1182
|
+
#endif
|
|
1183
|
+
shadow=mix(nextShadow,shadow,diffRatio);
|
|
1184
|
+
#ifdef SHADOWCSMDEBUG{X}
|
|
1185
|
+
shadowDebug{X}=mix(vec3(nextShadow)*vCascadeColorsMultiplier{X}[index{X}],shadowDebug{X},diffRatio);
|
|
1186
|
+
#endif
|
|
1187
|
+
}
|
|
1188
|
+
#endif
|
|
1189
|
+
}
|
|
1190
|
+
#elif defined(SHADOWCLOSEESM{X})
|
|
1191
|
+
#if defined(SHADOWCUBE{X})
|
|
1192
|
+
shadow=computeShadowWithCloseESMCube(vPositionW,light{X}.vLightData.xyz,shadowTexture{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);
|
|
1193
|
+
#else
|
|
1194
|
+
shadow=computeShadowWithCloseESM(vPositionFromLight{X},vDepthMetric{X},shadowTexture{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);
|
|
1195
|
+
#endif
|
|
1196
|
+
#elif defined(SHADOWESM{X})
|
|
1197
|
+
#if defined(SHADOWCUBE{X})
|
|
1198
|
+
shadow=computeShadowWithESMCube(vPositionW,light{X}.vLightData.xyz,shadowTexture{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);
|
|
1199
|
+
#else
|
|
1200
|
+
shadow=computeShadowWithESM(vPositionFromLight{X},vDepthMetric{X},shadowTexture{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);
|
|
1201
|
+
#endif
|
|
1202
|
+
#elif defined(SHADOWPOISSON{X})
|
|
1203
|
+
#if defined(SHADOWCUBE{X})
|
|
1204
|
+
shadow=computeShadowWithPoissonSamplingCube(vPositionW,light{X}.vLightData.xyz,shadowTexture{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.depthValues);
|
|
1205
|
+
#else
|
|
1206
|
+
shadow=computeShadowWithPoissonSampling(vPositionFromLight{X},vDepthMetric{X},shadowTexture{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1207
|
+
#endif
|
|
1208
|
+
#elif defined(SHADOWPCF{X})
|
|
1209
|
+
#if defined(SHADOWLOWQUALITY{X})
|
|
1210
|
+
shadow=computeShadowWithPCF1(vPositionFromLight{X},vDepthMetric{X},shadowTexture{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1211
|
+
#elif defined(SHADOWMEDIUMQUALITY{X})
|
|
1212
|
+
shadow=computeShadowWithPCF3(vPositionFromLight{X},vDepthMetric{X},shadowTexture{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1213
|
+
#else
|
|
1214
|
+
shadow=computeShadowWithPCF5(vPositionFromLight{X},vDepthMetric{X},shadowTexture{X},light{X}.shadowsInfo.yz,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1215
|
+
#endif
|
|
1216
|
+
#elif defined(SHADOWPCSS{X})
|
|
1217
|
+
#if defined(SHADOWLOWQUALITY{X})
|
|
1218
|
+
shadow=computeShadowWithPCSS16(vPositionFromLight{X},vDepthMetric{X},depthTexture{X},shadowTexture{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1219
|
+
#elif defined(SHADOWMEDIUMQUALITY{X})
|
|
1220
|
+
shadow=computeShadowWithPCSS32(vPositionFromLight{X},vDepthMetric{X},depthTexture{X},shadowTexture{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1221
|
+
#else
|
|
1222
|
+
shadow=computeShadowWithPCSS64(vPositionFromLight{X},vDepthMetric{X},depthTexture{X},shadowTexture{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.z,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1223
|
+
#endif
|
|
1224
|
+
#else
|
|
1225
|
+
#if defined(SHADOWCUBE{X})
|
|
1226
|
+
shadow=computeShadowCube(vPositionW,light{X}.vLightData.xyz,shadowTexture{X},light{X}.shadowsInfo.x,light{X}.depthValues);
|
|
1227
|
+
#else
|
|
1228
|
+
shadow=computeShadow(vPositionFromLight{X},vDepthMetric{X},shadowTexture{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
|
|
1229
|
+
#endif
|
|
1230
|
+
#endif
|
|
1231
|
+
#ifdef SHADOWONLY
|
|
1232
|
+
#ifndef SHADOWINUSE
|
|
1233
|
+
#define SHADOWINUSE
|
|
1234
|
+
#endif
|
|
1235
|
+
globalShadow+=shadow;shadowLightCount+=1.0;
|
|
1236
|
+
#endif
|
|
1237
|
+
#else
|
|
1238
|
+
shadow=1.;
|
|
1239
|
+
#endif
|
|
1240
|
+
aggShadow+=shadow;numLights+=1.0;
|
|
1241
|
+
#ifndef SHADOWONLY
|
|
1242
|
+
#ifdef CUSTOMUSERLIGHTING
|
|
1243
|
+
diffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);
|
|
1244
|
+
#ifdef SPECULARTERM
|
|
1245
|
+
specularBase+=computeCustomSpecularLighting(info,specularBase,shadow);
|
|
1246
|
+
#endif
|
|
1247
|
+
#elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X})
|
|
1248
|
+
diffuseBase+=lightmapColor.rgb*shadow;
|
|
1249
|
+
#ifdef SPECULARTERM
|
|
1250
|
+
#ifndef LIGHTMAPNOSPECULAR{X}
|
|
1251
|
+
specularBase+=info.specular*shadow*lightmapColor.rgb;
|
|
1252
|
+
#endif
|
|
1253
|
+
#endif
|
|
1254
|
+
#ifdef CLEARCOAT
|
|
1255
|
+
#ifndef LIGHTMAPNOSPECULAR{X}
|
|
1256
|
+
clearCoatBase+=info.clearCoat.rgb*shadow*lightmapColor.rgb;
|
|
1257
|
+
#endif
|
|
1258
|
+
#endif
|
|
1259
|
+
#ifdef SHEEN
|
|
1260
|
+
#ifndef LIGHTMAPNOSPECULAR{X}
|
|
1261
|
+
sheenBase+=info.sheen.rgb*shadow;
|
|
1262
|
+
#endif
|
|
1263
|
+
#endif
|
|
1264
|
+
#else
|
|
1265
|
+
#ifdef SHADOWCSMDEBUG{X}
|
|
1266
|
+
diffuseBase+=info.diffuse*shadowDebug{X};
|
|
1267
|
+
#else
|
|
1268
|
+
diffuseBase+=info.diffuse*shadow;
|
|
1269
|
+
#endif
|
|
1270
|
+
#ifdef SS_TRANSLUCENCY
|
|
1271
|
+
diffuseTransmissionBase+=info.diffuseTransmission*shadow;
|
|
1272
|
+
#endif
|
|
1273
|
+
#ifdef SPECULARTERM
|
|
1274
|
+
specularBase+=info.specular*shadow;
|
|
1275
|
+
#endif
|
|
1276
|
+
#ifdef CLEARCOAT
|
|
1277
|
+
clearCoatBase+=info.clearCoat.rgb*shadow;
|
|
1278
|
+
#endif
|
|
1279
|
+
#ifdef SHEEN
|
|
1280
|
+
sheenBase+=info.sheen.rgb*shadow;
|
|
1281
|
+
#endif
|
|
1282
|
+
#endif
|
|
1283
|
+
#endif
|
|
1284
|
+
#endif
|
|
1285
|
+
`;
|
|
1286
|
+
e.IncludesShadersStore[D] || (e.IncludesShadersStore[D] = V);
|
|
1287
|
+
const C = "logDepthFragment", k = `#ifdef LOGARITHMICDEPTH
|
|
1288
|
+
gl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;
|
|
1289
|
+
#endif
|
|
1290
|
+
`;
|
|
1291
|
+
e.IncludesShadersStore[C] || (e.IncludesShadersStore[C] = k);
|
|
1292
|
+
const X = "fogFragment", B = `#ifdef FOG
|
|
1293
|
+
float fog=CalcFogFactor();
|
|
1294
|
+
#ifdef PBR
|
|
1295
|
+
fog=toLinearSpace(fog);
|
|
1296
|
+
#endif
|
|
1297
|
+
color.rgb=mix(vFogColor,color.rgb,fog);
|
|
1298
|
+
#endif
|
|
1299
|
+
`;
|
|
1300
|
+
e.IncludesShadersStore[X] || (e.IncludesShadersStore[X] = B);
|
|
1301
|
+
const L = "oitFragment", Y = `#ifdef ORDER_INDEPENDENT_TRANSPARENCY
|
|
1302
|
+
float fragDepth=gl_FragCoord.z;
|
|
1303
|
+
#ifdef ORDER_INDEPENDENT_TRANSPARENCY_16BITS
|
|
1304
|
+
uint halfFloat=packHalf2x16(vec2(fragDepth));vec2 full=unpackHalf2x16(halfFloat);fragDepth=full.x;
|
|
1305
|
+
#endif
|
|
1306
|
+
ivec2 fragCoord=ivec2(gl_FragCoord.xy);vec2 lastDepth=texelFetch(oitDepthSampler,fragCoord,0).rg;vec4 lastFrontColor=texelFetch(oitFrontColorSampler,fragCoord,0);depth.rg=vec2(-MAX_DEPTH);frontColor=lastFrontColor;backColor=vec4(0.0);
|
|
1307
|
+
#ifdef USE_REVERSE_DEPTHBUFFER
|
|
1308
|
+
float furthestDepth=-lastDepth.x;float nearestDepth=lastDepth.y;
|
|
1309
|
+
#else
|
|
1310
|
+
float nearestDepth=-lastDepth.x;float furthestDepth=lastDepth.y;
|
|
1311
|
+
#endif
|
|
1312
|
+
float alphaMultiplier=1.0-lastFrontColor.a;
|
|
1313
|
+
#ifdef USE_REVERSE_DEPTHBUFFER
|
|
1314
|
+
if (fragDepth>nearestDepth || fragDepth<furthestDepth) {
|
|
1315
|
+
#else
|
|
1316
|
+
if (fragDepth<nearestDepth || fragDepth>furthestDepth) {
|
|
1317
|
+
#endif
|
|
1318
|
+
return;}
|
|
1319
|
+
#ifdef USE_REVERSE_DEPTHBUFFER
|
|
1320
|
+
if (fragDepth<nearestDepth && fragDepth>furthestDepth) {
|
|
1321
|
+
#else
|
|
1322
|
+
if (fragDepth>nearestDepth && fragDepth<furthestDepth) {
|
|
1323
|
+
#endif
|
|
1324
|
+
depth.rg=vec2(-fragDepth,fragDepth);return;}
|
|
1325
|
+
#endif
|
|
1326
|
+
`;
|
|
1327
|
+
e.IncludesShadersStore[L] || (e.IncludesShadersStore[L] = Y);
|
|
1328
|
+
//# sourceMappingURL=oitFragment-D6JBEGk0.js.map
|