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