@vived/component-abb-6700 1.0.0
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/.todo.md +13 -0
- package/README.md +122 -0
- package/dist/.gitkeep +0 -0
- package/dist/Adapters/aBB6700PMAdapter.d.ts +10 -0
- package/dist/Adapters/aBB6700PMAdapter.d.ts.map +1 -0
- package/dist/Controllers/createABB6700.d.ts +12 -0
- package/dist/Controllers/createABB6700.d.ts.map +1 -0
- package/dist/Controllers/getPose.d.ts +11 -0
- package/dist/Controllers/getPose.d.ts.map +1 -0
- package/dist/Controllers/setJointAngle.d.ts +12 -0
- package/dist/Controllers/setJointAngle.d.ts.map +1 -0
- package/dist/Controllers/setPose.d.ts +11 -0
- package/dist/Controllers/setPose.d.ts.map +1 -0
- package/dist/Entities/ABB6700Entity.d.ts +35 -0
- package/dist/Entities/ABB6700Entity.d.ts.map +1 -0
- package/dist/Entities/ABB6700Repo.d.ts +32 -0
- package/dist/Entities/ABB6700Repo.d.ts.map +1 -0
- package/dist/Factory/ABB6700FeatureFactory.d.ts +26 -0
- package/dist/Factory/ABB6700FeatureFactory.d.ts.map +1 -0
- package/dist/Mocks/MockABB6700PM.d.ts +11 -0
- package/dist/Mocks/MockABB6700PM.d.ts.map +1 -0
- package/dist/Mocks/MockSetJointAngleUC.d.ts +7 -0
- package/dist/Mocks/MockSetJointAngleUC.d.ts.map +1 -0
- package/dist/Mocks/MockSetPoseUC.d.ts +7 -0
- package/dist/Mocks/MockSetPoseUC.d.ts.map +1 -0
- package/dist/PMs/ABB6700PM.d.ts +32 -0
- package/dist/PMs/ABB6700PM.d.ts.map +1 -0
- package/dist/UCs/CalcStabilizerUC.d.ts +7 -0
- package/dist/UCs/CalcStabilizerUC.d.ts.map +1 -0
- package/dist/UCs/SetJointAngleUC.d.ts +15 -0
- package/dist/UCs/SetJointAngleUC.d.ts.map +1 -0
- package/dist/UCs/SetPoseUC.d.ts +22 -0
- package/dist/UCs/SetPoseUC.d.ts.map +1 -0
- package/dist/Views/ABB6700BabylonView.d.ts +27 -0
- package/dist/Views/ABB6700BabylonView.d.ts.map +1 -0
- package/dist/abb_6700.glb +0 -0
- package/dist/abstractAudioBus-CyBWsmuN.js +14 -0
- package/dist/animationGroup-BhNThqQe.js +1454 -0
- package/dist/basisTextureLoader-BT391BsV.js +310 -0
- package/dist/brdfTextureTools-DUyKBAXf.js +79 -0
- package/dist/bumpFragment-Dd-ojPA1.js +134 -0
- package/dist/bumpFragment-KE1_PuMl.js +287 -0
- package/dist/bumpVertex-BcdvVFVx.js +8 -0
- package/dist/bumpVertexDeclaration-B5Uvs-RS.js +8 -0
- package/dist/bumpVertexDeclaration-ixSg-yGI.js +8 -0
- package/dist/clipPlaneFragment-DJwQynjA.js +136 -0
- package/dist/clipPlaneVertex-D4Wk50XG.js +376 -0
- package/dist/clipPlaneVertex-eQ147Tn2.js +350 -0
- package/dist/component.config.d.ts +17 -0
- package/dist/component.config.d.ts.map +1 -0
- package/dist/ddsTextureLoader-DeoF3iGO.js +331 -0
- package/dist/default.fragment-DKnTR9nY.js +548 -0
- package/dist/default.fragment-rIGWrUS5.js +486 -0
- package/dist/default.vertex-Bt5y1VyA.js +212 -0
- package/dist/default.vertex-Dext1liJ.js +224 -0
- package/dist/defaultUboDeclaration-BwslQZX8.js +11 -0
- package/dist/defaultUboDeclaration-DSXACgip.js +9 -0
- package/dist/easing-BAt0SO-B.js +163 -0
- package/dist/envTextureLoader-CBiW_Q-U.js +40 -0
- package/dist/exrTextureLoader-5SC6PKIA.js +740 -0
- package/dist/flowGraphApplyForceBlock-6e8-wcaw.js +32 -0
- package/dist/flowGraphApplyImpulseBlock-B27EZQow.js +32 -0
- package/dist/flowGraphArrayIndexBlock-DIUn5e4i.js +31 -0
- package/dist/flowGraphBezierCurveEasingBlock-BJmiHk40.js +25 -0
- package/dist/flowGraphBinaryOperationBlock-Bj7TANCc.js +25 -0
- package/dist/flowGraphBranchBlock-7CRvIKWc.js +19 -0
- package/dist/flowGraphCachedOperationBlock-CP1ZiuIB.js +26 -0
- package/dist/flowGraphCancelDelayBlock-DqtgzBGm.js +20 -0
- package/dist/flowGraphCodeExecutionBlock-CaYXCGqo.js +23 -0
- package/dist/flowGraphConditionalDataBlock-DJ7evX8_.js +28 -0
- package/dist/flowGraphConsoleLogBlock-cMkpqLzO.js +68 -0
- package/dist/flowGraphConstantBlock-JWybwT0A.js +28 -0
- package/dist/flowGraphContextBlock-CFDXHcbn.js +19 -0
- package/dist/flowGraphCounterBlock-B0uPkgw9.js +24 -0
- package/dist/flowGraphDataSwitchBlock-B0GSifvJ.js +27 -0
- package/dist/flowGraphDebounceBlock-CSw8zKym.js +24 -0
- package/dist/flowGraphDebugBlock-DiSR6Ahn.js +65 -0
- package/dist/flowGraphDoNBlock-C-48oQ2H.js +24 -0
- package/dist/flowGraphEasingBlock-DKUaE7Rp.js +50 -0
- package/dist/flowGraphFlipFlopBlock-DX5BGhMV.js +20 -0
- package/dist/flowGraphForLoopBlock-Di-Qwg23.js +27 -0
- package/dist/flowGraphFunctionReferenceBlock-D8X5TFsO.js +20 -0
- package/dist/flowGraphGLTFDataProvider-C4j7nPQv.js +16 -0
- package/dist/flowGraphGetAngularVelocityBlock-Cq-yTQ4D.js +31 -0
- package/dist/flowGraphGetAssetBlock-B36eioor.js +21 -0
- package/dist/flowGraphGetLinearVelocityBlock-MdrV0eUD.js +31 -0
- package/dist/flowGraphGetPhysicsMassPropertiesBlock-wXDZP1wM.js +30 -0
- package/dist/flowGraphGetPropertyBlock-eP0badwf.js +46 -0
- package/dist/flowGraphGetSoundVolumeBlock-D3gXGHXa.js +29 -0
- package/dist/flowGraphGetVariableBlock-C7-qZAec.js +31 -0
- package/dist/flowGraphIndexOfBlock-CC5l9n9P.js +31 -0
- package/dist/flowGraphInterpolationBlock-B6922jzt.js +50 -0
- package/dist/flowGraphIsKeyPressedBlock-X_iuiUOX.js +31 -0
- package/dist/flowGraphIsSoundPlayingBlock-DONQX8N8.js +29 -0
- package/dist/flowGraphJsonPointerParserBlock-DBH_gN8I.js +95 -0
- package/dist/flowGraphKeyDownEventBlock-D5T1Uyfv.js +26 -0
- package/dist/flowGraphKeyUpEventBlock-BPY_Kgkm.js +21 -0
- package/dist/flowGraphKeyboardEventBlock-C49fx3TC.js +20 -0
- package/dist/flowGraphMathBlocks-CkvrN3VJ.js +864 -0
- package/dist/flowGraphMathCombineExtractBlocks-QSjGlnoz.js +248 -0
- package/dist/flowGraphMatrixMathBlocks-B3D7Cz9p.js +117 -0
- package/dist/flowGraphMeshPickEventBlock-BBTz-taa.js +35 -0
- package/dist/flowGraphMultiGateBlock-BhY1y5BG.js +50 -0
- package/dist/flowGraphPauseAnimationBlock-CHZZXMbg.js +19 -0
- package/dist/flowGraphPauseSoundBlock-B7hMmJ0c.js +31 -0
- package/dist/flowGraphPhysicsCollisionEventBlock-CxoPpT-q.js +56 -0
- package/dist/flowGraphPlayAnimationBlock-DVAvIFux.js +99 -0
- package/dist/flowGraphPlaySoundBlock-DjHGrqbC.js +32 -0
- package/dist/flowGraphPointerDownEventBlock-qI-H0JST.js +31 -0
- package/dist/flowGraphPointerMoveEventBlock-DAi4VUyy.js +31 -0
- package/dist/flowGraphPointerOutEventBlock-CFtj68aC.js +21 -0
- package/dist/flowGraphPointerOverEventBlock-VxdHhFuu.js +23 -0
- package/dist/flowGraphPointerUpEventBlock-DRR1f07q.js +31 -0
- package/dist/flowGraphReceiveCustomEventBlock-B3bwdB66.js +52 -0
- package/dist/flowGraphSceneReadyEventBlock-Dy6lDT3j.js +23 -0
- package/dist/flowGraphSceneTickEventBlock-Bl9BF_Xw.js +32 -0
- package/dist/flowGraphSendCustomEventBlock-BAR4PGFq.js +35 -0
- package/dist/flowGraphSequenceBlock-veqU32ZZ.js +32 -0
- package/dist/flowGraphSetAngularVelocityBlock-Dj9b-zu6.js +31 -0
- package/dist/flowGraphSetDelayBlock-CMjudtvk.js +131 -0
- package/dist/flowGraphSetLinearVelocityBlock-DVDhhJBd.js +31 -0
- package/dist/flowGraphSetPhysicsMotionTypeBlock-CL3cxNCO.js +36 -0
- package/dist/flowGraphSetPropertyBlock-D3sWL3Ss.js +47 -0
- package/dist/flowGraphSetSoundVolumeBlock-CxVk45yR.js +32 -0
- package/dist/flowGraphSetVariableBlock-D1oJiwLj.js +47 -0
- package/dist/flowGraphSoundEndedEventBlock-CubEwii0.js +47 -0
- package/dist/flowGraphStopAnimationBlock-B9inwIQx.js +48 -0
- package/dist/flowGraphStopSoundBlock-BijIX2jC.js +31 -0
- package/dist/flowGraphSwitchBlock-BMhPb4OX.js +54 -0
- package/dist/flowGraphThrottleBlock-C7vrnkb1.js +37 -0
- package/dist/flowGraphTransformCoordinatesSystemBlock-DoISqaUG.js +29 -0
- package/dist/flowGraphTypeToTypeBlocks-CSML6QWx.js +57 -0
- package/dist/flowGraphUnaryOperationBlock-B0Shf-lJ.js +24 -0
- package/dist/flowGraphVectorMathBlocks-DoTRR_E0.js +178 -0
- package/dist/flowGraphWaitAllBlock-BvmDMc24.js +54 -0
- package/dist/flowGraphWhileLoopBlock-BaIq4-K2.js +27 -0
- package/dist/geometry.fragment-Bsis3UG2.js +275 -0
- package/dist/geometry.vertex-DskQ5b8j.js +222 -0
- package/dist/harmonicsFunctions-CtNrRfir.js +193 -0
- package/dist/harmonicsFunctions-PEz6APC7.js +18 -0
- package/dist/hdrTextureLoader-D9rYxJ9q.js +112 -0
- package/dist/helperFunctions-Bt7Zfkrp.js +89 -0
- package/dist/helperFunctions-CPmRxd37.js +121 -0
- package/dist/iesTextureLoader-BGUFjVhI.js +93 -0
- package/dist/index-CS3Icp_r.js +67657 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/ktxTextureLoader-cUaGg9_L.js +459 -0
- package/dist/lightFragment-BRDibDKG.js +404 -0
- package/dist/lightFragment-DCqtGMp_.js +402 -0
- package/dist/logDepthDeclaration-Bwm-3KyB.js +16 -0
- package/dist/logDepthDeclaration-gUfeSnXX.js +20 -0
- package/dist/logDepthVertex-CKeuJ6ae.js +213 -0
- package/dist/logDepthVertex-CXkmZels.js +459 -0
- package/dist/mesh.vertexData.functions-Bc9lJlrU.js +74 -0
- package/dist/oitFragment-B8zuQigp.js +792 -0
- package/dist/oitFragment-DH3h3T6x.js +657 -0
- package/dist/openpbr.fragment-BglYS6LA.js +1405 -0
- package/dist/openpbr.fragment-DrOTZs4m.js +1553 -0
- package/dist/openpbr.vertex-B-PaLFOR.js +384 -0
- package/dist/openpbr.vertex-DMdFRTnX.js +268 -0
- package/dist/openpbrMaterial-HCU0aOca.js +2880 -0
- package/dist/openpbrMaterialLoadingAdapter-CWRAa-7S.js +1122 -0
- package/dist/openpbrTransmissionLayerData-CfDVObj5.js +352 -0
- package/dist/openpbrUboDeclaration-CA2pvSbt.js +9 -0
- package/dist/openpbrUboDeclaration-xU8VOaib.js +10 -0
- package/dist/pass.fragment-1mMP54bb.js +10 -0
- package/dist/pass.fragment-DzaUp_jk.js +10 -0
- package/dist/passCube.fragment-CQaXS7g3.js +29 -0
- package/dist/passCube.fragment-QJGPwAXI.js +29 -0
- package/dist/pbr.fragment-BnaAAGxb.js +2775 -0
- package/dist/pbr.fragment-CYZk_EGU.js +2619 -0
- package/dist/pbr.vertex-CyvdCw91.js +372 -0
- package/dist/pbr.vertex-DJMAkDxs.js +270 -0
- package/dist/pbrBRDFFunctions-EugoWm6O.js +175 -0
- package/dist/pbrDebug-Bk3sPoEG.js +719 -0
- package/dist/pbrDebug-Cdalzb1I.js +614 -0
- package/dist/pbrIBLFunctions-B0bVAXCF.js +47 -0
- package/dist/pbrIBLFunctions-C06z-ouZ.js +51 -0
- package/dist/pbrMaterial-C4FCKBZQ.js +1660 -0
- package/dist/pbrMaterialLoadingAdapter-BGHlS_ZN.js +1032 -0
- package/dist/pbrUboDeclaration-1lN5_-Bw.js +9 -0
- package/dist/pbrUboDeclaration-BJOUUOZ2.js +10 -0
- package/dist/procedural.vertex-CFPKczKj.js +14 -0
- package/dist/procedural.vertex-DUW7bYZt.js +13 -0
- package/dist/rgbdDecode.fragment-CEGgE4tL.js +8 -0
- package/dist/rgbdDecode.fragment-FT0wkgah.js +8 -0
- package/dist/rgbdEncode.fragment-CLnJJf6E.js +8 -0
- package/dist/rgbdEncode.fragment-CaAcMsY9.js +8 -0
- package/dist/sceneUboDeclaration-B6oxsfcj.js +8 -0
- package/dist/sceneUboDeclaration-JByfVKik.js +13 -0
- package/dist/setupABB6700InstanceFactory.d.ts +7 -0
- package/dist/setupABB6700InstanceFactory.d.ts.map +1 -0
- package/dist/studio.env +0 -0
- package/dist/textureProcessor.fragment-BYPw6SMQ.js +152 -0
- package/dist/textureProcessor.fragment-Ciw9-F3w.js +157 -0
- package/dist/textureTools-Cct_bGgp.js +40 -0
- package/dist/tgaTextureLoader-BJOIdnFr.js +198 -0
- package/dist/thinEngine-Bt9FW4dD.js +2425 -0
- package/dist/webAudioBus-BUzRHSxr.js +88 -0
- package/dist/webAudioMainBus-Dds1TgJG.js +49 -0
- package/package.json +49 -0
|
@@ -0,0 +1,657 @@
|
|
|
1
|
+
import { b0 as e } from "./index-CS3Icp_r.js";
|
|
2
|
+
const r = "prePassDeclaration", h = `#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[r] || (e.IncludesShadersStoreWGSL[r] = h);
|
|
18
|
+
const t = "oitDeclaration", m = `#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[t] || (e.IncludesShadersStoreWGSL[t] = m);
|
|
24
|
+
const a = "lightUboDeclaration", S = `#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
|
+
#elif defined(CLUSTLIGHT{X})
|
|
37
|
+
vSliceData: vec2f,
|
|
38
|
+
vSliceRanges: array<vec4f,CLUSTLIGHT_SLICES>,
|
|
39
|
+
#endif
|
|
40
|
+
#if defined(AREALIGHT{X}) && defined(AREALIGHTUSED) && defined(AREALIGHTSUPPORTED)
|
|
41
|
+
vLightWidth: vec4f,
|
|
42
|
+
vLightHeight: vec4f,
|
|
43
|
+
#endif
|
|
44
|
+
shadowsInfo: vec4f,
|
|
45
|
+
depthValues: vec2f} ;var<uniform> light{X} : Light{X};
|
|
46
|
+
#ifdef IESLIGHTTEXTURE{X}
|
|
47
|
+
var iesLightTexture{X}Sampler: sampler;var iesLightTexture{X}: texture_2d<f32>;
|
|
48
|
+
#endif
|
|
49
|
+
#ifdef RECTAREALIGHTEMISSIONTEXTURE{X}
|
|
50
|
+
var rectAreaLightEmissionTexture{X}Sampler: sampler;var rectAreaLightEmissionTexture{X}: texture_2d<f32>;
|
|
51
|
+
#endif
|
|
52
|
+
#ifdef PROJECTEDLIGHTTEXTURE{X}
|
|
53
|
+
uniform textureProjectionMatrix{X}: mat4x4f;var projectionLightTexture{X}Sampler: sampler;var projectionLightTexture{X}: texture_2d<f32>;
|
|
54
|
+
#endif
|
|
55
|
+
#ifdef CLUSTLIGHT{X}
|
|
56
|
+
var lightDataTexture{X}: texture_2d<f32>;var<storage,read> tileMaskBuffer{X}: array<u32>;
|
|
57
|
+
#endif
|
|
58
|
+
#ifdef SHADOW{X}
|
|
59
|
+
#ifdef SHADOWCSM{X}
|
|
60
|
+
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>;
|
|
61
|
+
#if defined(SHADOWPCSS{X})
|
|
62
|
+
var shadowTexture{X}Sampler: sampler_comparison;
|
|
63
|
+
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;
|
|
64
|
+
#elif defined(SHADOWPCF{X})
|
|
65
|
+
var shadowTexture{X}Sampler: sampler_comparison;var shadowTexture{X}: texture_depth_2d_array;
|
|
66
|
+
#else
|
|
67
|
+
var shadowTexture{X}Sampler: sampler;
|
|
68
|
+
var shadowTexture{X}: texture_2d_array<f32>;
|
|
69
|
+
#endif
|
|
70
|
+
#ifdef SHADOWCSMDEBUG{X}
|
|
71
|
+
const vCascadeColorsMultiplier{X}: array<vec3f,8>=array<vec3f,8>
|
|
72
|
+
(
|
|
73
|
+
vec3f ( 1.5,0.0,0.0 ),
|
|
74
|
+
vec3f ( 0.0,1.5,0.0 ),
|
|
75
|
+
vec3f ( 0.0,0.0,5.5 ),
|
|
76
|
+
vec3f ( 1.5,0.0,5.5 ),
|
|
77
|
+
vec3f ( 1.5,1.5,0.0 ),
|
|
78
|
+
vec3f ( 1.0,1.0,1.0 ),
|
|
79
|
+
vec3f ( 0.0,1.0,5.5 ),
|
|
80
|
+
vec3f ( 0.5,3.5,0.75 )
|
|
81
|
+
);
|
|
82
|
+
#endif
|
|
83
|
+
#elif defined(SHADOWCUBE{X})
|
|
84
|
+
var shadowTexture{X}Sampler: sampler;var shadowTexture{X}: texture_cube<f32>;
|
|
85
|
+
#else
|
|
86
|
+
varying vPositionFromLight{X}: vec4f;varying vDepthMetric{X}: f32;
|
|
87
|
+
#if defined(SHADOWPCSS{X})
|
|
88
|
+
var shadowTexture{X}Sampler: sampler_comparison;
|
|
89
|
+
var shadowTexture{X}: texture_depth_2d;var depthTexture{X}Sampler: sampler;
|
|
90
|
+
var depthTexture{X}: texture_2d<f32>;
|
|
91
|
+
#elif defined(SHADOWPCF{X})
|
|
92
|
+
var shadowTexture{X}Sampler: sampler_comparison;var shadowTexture{X}: texture_depth_2d;
|
|
93
|
+
#else
|
|
94
|
+
var shadowTexture{X}Sampler: sampler;
|
|
95
|
+
var shadowTexture{X}: texture_2d<f32>;
|
|
96
|
+
#endif
|
|
97
|
+
uniform lightMatrix{X}: mat4x4f;
|
|
98
|
+
#endif
|
|
99
|
+
#endif
|
|
100
|
+
#endif
|
|
101
|
+
`;
|
|
102
|
+
e.IncludesShadersStoreWGSL[a] || (e.IncludesShadersStoreWGSL[a] = S);
|
|
103
|
+
const o = "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;}
|
|
104
|
+
fn LTCClippedSphereFormFactor( f:vec3f )->f32 {var l: f32=length( f );return max( ( l*l+f.z )/( l+1.0 ),0.0 );}
|
|
105
|
+
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 )
|
|
106
|
+
{thetaSintheta=v;}
|
|
107
|
+
else
|
|
108
|
+
{thetaSintheta=0.5*inverseSqrt( max( 1.0-x*x,0.00000001 ) )-v;}
|
|
109
|
+
return cross( v1,v2 )*thetaSintheta;}
|
|
110
|
+
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 );}
|
|
111
|
+
var T1:vec3f=normalize( V-N*dot( V,N ) );var T2:vec3f=- cross( N,T1 );
|
|
112
|
+
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 );}
|
|
113
|
+
struct areaLightData
|
|
114
|
+
{Diffuse: vec3f,
|
|
115
|
+
Specular: vec3f,
|
|
116
|
+
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;
|
|
117
|
+
var rectCoords1:vec3f=lightPos-halfWidth-halfHeight;var rectCoords2:vec3f=lightPos-halfWidth+halfHeight;var rectCoords3:vec3f=lightPos+halfWidth+halfHeight;
|
|
118
|
+
#ifdef SPECULARTERM
|
|
119
|
+
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>(
|
|
120
|
+
vec3f( t1.x,0,t1.y ),
|
|
121
|
+
vec3f( 0,1, 0 ),
|
|
122
|
+
vec3f( t1.z,0,t1.w )
|
|
123
|
+
);result.Fresnel=t2;result.Specular=LTCEvaluate( normal,viewDir,position,mInv,rectCoords0,rectCoords1,rectCoords2,rectCoords3 );
|
|
124
|
+
#endif
|
|
125
|
+
var mInvEmpty:mat3x3<f32>=mat3x3<f32>(
|
|
126
|
+
vec3f( 1,0,0 ),
|
|
127
|
+
vec3f( 0,1,0 ),
|
|
128
|
+
vec3f( 0,0,1 )
|
|
129
|
+
);result.Diffuse+=LTCEvaluate( normal,viewDir,position,mInvEmpty,rectCoords0,rectCoords1,rectCoords2,rectCoords3 );return result;}
|
|
130
|
+
fn FetchDiffuseFilteredTexture(texLightFiltered: texture_2d<f32>,texLightFilteredSampler: sampler,p1_: vec3f,p2_: vec3f,p3_: vec3f,p4_: vec3f)->vec3f {var V1: vec3f=p2_-p1_;var V2: vec3f=p4_-p1_;var planeOrtho: vec3f=cross(V1,V2);var planeAreaSquared: f32=dot(planeOrtho,planeOrtho);var planeDistxPlaneArea: f32=dot(planeOrtho,p1_);var P: vec3f=planeDistxPlaneArea*planeOrtho/planeAreaSquared-p1_;var dot_V1_V2: f32=dot(V1,V2);var inv_dot_V1_V1: f32=1.0/dot(V1,V1);var V2_: vec3f=V2-V1*dot_V1_V2*inv_dot_V1_V1;var Puv: vec2f;Puv.y=dot(V2_,P)/dot(V2_,V2_);Puv.x=dot(V1,P)*inv_dot_V1_V1-dot_V1_V2*inv_dot_V1_V1*Puv.y;var d: f32=abs(planeDistxPlaneArea)/pow(planeAreaSquared,0.75);var sampleLOD: f32=log(2048.0*d)/log(3.0);var sampleUV: vec2f=vec2f(0.125,0.125)+(vec2f(0.75)*Puv);sampleUV.x=1.0-sampleUV.x;return textureSampleLevel(texLightFiltered,texLightFilteredSampler,sampleUV,sampleLOD).rgb;}
|
|
131
|
+
fn LTCEvaluateWithEmission(N: vec3f,V: vec3f,P: vec3f,mInv: mat3x3<f32>,rectCoords0: vec3f,rectCoords1: vec3f,rectCoords2: vec3f,rectCoords3: vec3f,texFilteredMap: texture_2d<f32>,texFilteredMapSampler: sampler)->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);}
|
|
132
|
+
var T1: vec3f=normalize(V-N*dot(V,N));var T2: vec3f=-cross(N,T1);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);var textureLight: vec3f=FetchDiffuseFilteredTexture(texFilteredMap,texFilteredMapSampler,coords0,coords1,coords2,coords3);coords0=normalize(coords0);coords1=normalize(coords1);coords2=normalize(coords2);coords3=normalize(coords3);var vectorFormFactor: vec3f=vec3f(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)*textureLight;}
|
|
133
|
+
fn computeAreaLightSpecularDiffuseFresnelWithEmission(ltc1: texture_2d<f32>,ltc1Sampler:sampler,ltc2:texture_2d<f32>,ltc2Sampler:sampler,emissionTexture: texture_2d<f32>,emissionTextureSampler: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;
|
|
134
|
+
var rectCoords1: vec3f=lightPos-halfWidth-halfHeight;var rectCoords2: vec3f=lightPos-halfWidth+halfHeight;var rectCoords3: vec3f=lightPos+halfWidth+halfHeight;
|
|
135
|
+
#ifdef SPECULARTERM
|
|
136
|
+
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>(
|
|
137
|
+
vec3f(t1.x,0,t1.y),
|
|
138
|
+
vec3f(0,1,0),
|
|
139
|
+
vec3f(t1.z,0,t1.w)
|
|
140
|
+
);result.Specular=LTCEvaluateWithEmission(normal,viewDir,position,mInv,rectCoords0,rectCoords1,rectCoords2,rectCoords3,emissionTexture,emissionTextureSampler);result.Fresnel=t2;
|
|
141
|
+
#endif
|
|
142
|
+
var mInvEmpty: mat3x3<f32>=mat3x3<f32>(
|
|
143
|
+
vec3f(1,0,0),
|
|
144
|
+
vec3f(0,1,0),
|
|
145
|
+
vec3f(0,0,1)
|
|
146
|
+
);result.Diffuse=LTCEvaluateWithEmission(normal,viewDir,position,mInvEmpty,rectCoords0,rectCoords1,rectCoords2,rectCoords3,emissionTexture,emissionTextureSampler);return result;}
|
|
147
|
+
`;
|
|
148
|
+
e.IncludesShadersStoreWGSL[o] || (e.IncludesShadersStoreWGSL[o] = x);
|
|
149
|
+
const f = "clusteredLightingFunctions", w = `struct ClusteredLight {vLightData: vec4f,
|
|
150
|
+
vLightDiffuse: vec4f,
|
|
151
|
+
vLightSpecular: vec4f,
|
|
152
|
+
vLightDirection: vec4f,
|
|
153
|
+
vLightFalloff: vec4f,}
|
|
154
|
+
fn getClusteredLight(lightDataTexture: texture_2d<f32>,index: u32)->ClusteredLight {return ClusteredLight(
|
|
155
|
+
textureLoad(lightDataTexture,vec2u(0,index),0),
|
|
156
|
+
textureLoad(lightDataTexture,vec2u(1,index),0),
|
|
157
|
+
textureLoad(lightDataTexture,vec2u(2,index),0),
|
|
158
|
+
textureLoad(lightDataTexture,vec2u(3,index),0),
|
|
159
|
+
textureLoad(lightDataTexture,vec2u(4,index),0)
|
|
160
|
+
);}
|
|
161
|
+
fn getClusteredSliceIndex(sliceData: vec2f,viewDepth: f32)->i32 {return i32(log(viewDepth)*sliceData.x+sliceData.y);}
|
|
162
|
+
`;
|
|
163
|
+
e.IncludesShadersStoreWGSL[f] || (e.IncludesShadersStoreWGSL[f] = w);
|
|
164
|
+
const v = "shadowsFragmentFunctions", g = `#ifdef SHADOWS
|
|
165
|
+
#ifndef SHADOWFLOAT
|
|
166
|
+
fn unpack(color: vec4f)->f32
|
|
167
|
+
{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);}
|
|
168
|
+
#endif
|
|
169
|
+
fn computeFallOff(value: f32,clipSpace: vec2f,frustumEdgeFalloff: f32)->f32
|
|
170
|
+
{var mask: f32=smoothstep(1.0-frustumEdgeFalloff,1.00000012,clamp(dot(clipSpace,clipSpace),0.,1.));return mix(value,1.0,mask);}
|
|
171
|
+
fn computeShadowCube(worldPos: vec3f,lightPosition: vec3f,shadowTexture: texture_cube<f32>,shadowSampler: sampler,darkness: f32,depthValues: vec2f)->f32
|
|
172
|
+
{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;
|
|
173
|
+
#ifndef SHADOWFLOAT
|
|
174
|
+
var shadow: f32=unpack(textureSample(shadowTexture,shadowSampler,directionToLight));
|
|
175
|
+
#else
|
|
176
|
+
var shadow: f32=textureSample(shadowTexture,shadowSampler,directionToLight).x;
|
|
177
|
+
#endif
|
|
178
|
+
return select(1.0,darkness,depth>shadow);}
|
|
179
|
+
fn computeShadowWithPoissonSamplingCube(worldPos: vec3f,lightPosition: vec3f,shadowTexture: texture_cube<f32>,shadowSampler: sampler,mapSize: f32,darkness: f32,depthValues: vec2f)->f32
|
|
180
|
+
{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);
|
|
181
|
+
#ifndef SHADOWFLOAT
|
|
182
|
+
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;};
|
|
183
|
+
#else
|
|
184
|
+
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;};
|
|
185
|
+
#endif
|
|
186
|
+
return min(1.0,visibility+darkness);}
|
|
187
|
+
fn computeShadowWithESMCube(worldPos: vec3f,lightPosition: vec3f,shadowTexture: texture_cube<f32>,shadowSampler: sampler,darkness: f32,depthScale: f32,depthValues: vec2f)->f32
|
|
188
|
+
{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;
|
|
189
|
+
#ifndef SHADOWFLOAT
|
|
190
|
+
var shadowMapSample: f32=unpack(textureSample(shadowTexture,shadowSampler,directionToLight));
|
|
191
|
+
#else
|
|
192
|
+
var shadowMapSample: f32=textureSample(shadowTexture,shadowSampler,directionToLight).x;
|
|
193
|
+
#endif
|
|
194
|
+
var esm: f32=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);return esm;}
|
|
195
|
+
fn computeShadowWithCloseESMCube(worldPos: vec3f,lightPosition: vec3f,shadowTexture: texture_cube<f32>,shadowSampler: sampler,darkness: f32,depthScale: f32,depthValues: vec2f)->f32
|
|
196
|
+
{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;
|
|
197
|
+
#ifndef SHADOWFLOAT
|
|
198
|
+
var shadowMapSample: f32=unpack(textureSample(shadowTexture,shadowSampler,directionToLight));
|
|
199
|
+
#else
|
|
200
|
+
var shadowMapSample: f32=textureSample(shadowTexture,shadowSampler,directionToLight).x;
|
|
201
|
+
#endif
|
|
202
|
+
var esm: f32=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);return esm;}
|
|
203
|
+
fn computeShadowCSM(layer: i32,vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_2d_array<f32>,shadowSampler: sampler,darkness: f32,frustumEdgeFalloff: f32)->f32
|
|
204
|
+
{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);
|
|
205
|
+
#ifndef SHADOWFLOAT
|
|
206
|
+
var shadow: f32=unpack(textureSample(shadowTexture,shadowSampler,uv,layer));
|
|
207
|
+
#else
|
|
208
|
+
var shadow: f32=textureSample(shadowTexture,shadowSampler,uv,layer).x;
|
|
209
|
+
#endif
|
|
210
|
+
return select(1.,computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff),shadowPixelDepth>shadow );}
|
|
211
|
+
fn computeShadow(vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_2d<f32>,shadowSampler: sampler,darkness: f32,frustumEdgeFalloff: f32)->f32
|
|
212
|
+
{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)
|
|
213
|
+
{return 1.0;}
|
|
214
|
+
else
|
|
215
|
+
{var shadowPixelDepth: f32=clamp(depthMetric,0.,1.0);
|
|
216
|
+
#ifndef SHADOWFLOAT
|
|
217
|
+
var shadow: f32=unpack(textureSampleLevel(shadowTexture,shadowSampler,uv,0.));
|
|
218
|
+
#else
|
|
219
|
+
var shadow: f32=textureSampleLevel(shadowTexture,shadowSampler,uv,0.).x;
|
|
220
|
+
#endif
|
|
221
|
+
return select(1.,computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff),shadowPixelDepth>shadow );}}
|
|
222
|
+
fn computeShadowWithPoissonSampling(vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_2d<f32>,shadowSampler: sampler,mapSize: f32,darkness: f32,frustumEdgeFalloff: f32)->f32
|
|
223
|
+
{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)
|
|
224
|
+
{return 1.0;}
|
|
225
|
+
else
|
|
226
|
+
{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);
|
|
227
|
+
#ifndef SHADOWFLOAT
|
|
228
|
+
if (unpack(textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[0]*mapSize,0.))<shadowPixelDepth) {visibility-=0.25;}
|
|
229
|
+
if (unpack(textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[1]*mapSize,0.))<shadowPixelDepth) {visibility-=0.25;}
|
|
230
|
+
if (unpack(textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[2]*mapSize,0.))<shadowPixelDepth) {visibility-=0.25;}
|
|
231
|
+
if (unpack(textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[3]*mapSize,0.))<shadowPixelDepth) {visibility-=0.25;}
|
|
232
|
+
#else
|
|
233
|
+
if (textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[0]*mapSize,0.).x<shadowPixelDepth) {visibility-=0.25;}
|
|
234
|
+
if (textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[1]*mapSize,0.).x<shadowPixelDepth) {visibility-=0.25;}
|
|
235
|
+
if (textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[2]*mapSize,0.).x<shadowPixelDepth) {visibility-=0.25;}
|
|
236
|
+
if (textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[3]*mapSize,0.).x<shadowPixelDepth) {visibility-=0.25;}
|
|
237
|
+
#endif
|
|
238
|
+
return computeFallOff(min(1.0,visibility+darkness),clipSpace.xy,frustumEdgeFalloff);}}
|
|
239
|
+
fn computeShadowWithESM(vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_2d<f32>,shadowSampler: sampler,darkness: f32,depthScale: f32,frustumEdgeFalloff: f32)->f32
|
|
240
|
+
{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)
|
|
241
|
+
{return 1.0;}
|
|
242
|
+
else
|
|
243
|
+
{var shadowPixelDepth: f32=clamp(depthMetric,0.,1.0);
|
|
244
|
+
#ifndef SHADOWFLOAT
|
|
245
|
+
var shadowMapSample: f32=unpack(textureSampleLevel(shadowTexture,shadowSampler,uv,0.));
|
|
246
|
+
#else
|
|
247
|
+
var shadowMapSample: f32=textureSampleLevel(shadowTexture,shadowSampler,uv,0.).x;
|
|
248
|
+
#endif
|
|
249
|
+
var esm: f32=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);return computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);}}
|
|
250
|
+
fn computeShadowWithCloseESM(vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_2d<f32>,shadowSampler: sampler,darkness: f32,depthScale: f32,frustumEdgeFalloff: f32)->f32
|
|
251
|
+
{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)
|
|
252
|
+
{return 1.0;}
|
|
253
|
+
else
|
|
254
|
+
{var shadowPixelDepth: f32=clamp(depthMetric,0.,1.0);
|
|
255
|
+
#ifndef SHADOWFLOAT
|
|
256
|
+
var shadowMapSample: f32=unpack(textureSampleLevel(shadowTexture,shadowSampler,uv,0.));
|
|
257
|
+
#else
|
|
258
|
+
var shadowMapSample: f32=textureSampleLevel(shadowTexture,shadowSampler,uv,0.).x;
|
|
259
|
+
#endif
|
|
260
|
+
var esm: f32=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);return computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);}}
|
|
261
|
+
fn getZInClip(clipSpace: vec3f,uvDepth: vec3f)->f32
|
|
262
|
+
{
|
|
263
|
+
#ifdef IS_NDC_HALF_ZRANGE
|
|
264
|
+
return clipSpace.z;
|
|
265
|
+
#else
|
|
266
|
+
return uvDepth.z;
|
|
267
|
+
#endif
|
|
268
|
+
}
|
|
269
|
+
const GREATEST_LESS_THAN_ONE: f32=0.99999994;
|
|
270
|
+
#define DISABLE_UNIFORMITY_ANALYSIS
|
|
271
|
+
fn computeShadowWithCSMPCF1(layer: i32,vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_depth_2d_array,shadowSampler: sampler_comparison,darkness: f32,frustumEdgeFalloff: f32)->f32
|
|
272
|
+
{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);}
|
|
273
|
+
fn computeShadowWithCSMPCF3(layer: i32,vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_depth_2d_array,shadowSampler: sampler_comparison,shadowMapSizeAndInverse: vec2f,darkness: f32,frustumEdgeFalloff: f32)->f32
|
|
274
|
+
{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;
|
|
275
|
+
uv+=0.5;
|
|
276
|
+
var st: vec2f=fract(uv);
|
|
277
|
+
var base_uv: vec2f=floor(uv)-0.5;
|
|
278
|
+
base_uv*=shadowMapSizeAndInverse.y;
|
|
279
|
+
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);}
|
|
280
|
+
fn computeShadowWithCSMPCF5(layer: i32,vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_depth_2d_array,shadowSampler: sampler_comparison,shadowMapSizeAndInverse: vec2f,darkness: f32,frustumEdgeFalloff: f32)->f32
|
|
281
|
+
{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;
|
|
282
|
+
uv+=0.5;
|
|
283
|
+
var st: vec2f=fract(uv);
|
|
284
|
+
var base_uv: vec2f=floor(uv)-0.5;
|
|
285
|
+
base_uv*=shadowMapSizeAndInverse.y;
|
|
286
|
+
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);}
|
|
287
|
+
fn computeShadowWithPCF1(vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_depth_2d,shadowSampler: sampler_comparison,darkness: f32,frustumEdgeFalloff: f32)->f32
|
|
288
|
+
{var clipSpace: vec3f=vPositionFromLight.xyz/vPositionFromLight.w;var uvDepth: vec3f= vec3f(0.5*clipSpace.xyz+ vec3f(0.5));uvDepth.z=getZInClip(clipSpace,uvDepth);if (depthMetric<0.0 || depthMetric>1.0 || uvDepth.x<0. || uvDepth.x>1.0 || uvDepth.y<0. || uvDepth.y>1.0) {return 1.0;} else {var shadow: f32=textureSampleCompareLevel(shadowTexture,shadowSampler,uvDepth.xy,uvDepth.z);shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}}
|
|
289
|
+
fn computeShadowWithPCF3(vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_depth_2d,shadowSampler: sampler_comparison,shadowMapSizeAndInverse: vec2f,darkness: f32,frustumEdgeFalloff: f32)->f32
|
|
290
|
+
{var clipSpace: vec3f=vPositionFromLight.xyz/vPositionFromLight.w;var uvDepth: vec3f= vec3f(0.5*clipSpace.xyz+ vec3f(0.5));uvDepth.z=getZInClip(clipSpace,uvDepth);if (depthMetric<0.0 || depthMetric>1.0 || uvDepth.x<0. || uvDepth.x>1.0 || uvDepth.y<0. || uvDepth.y>1.0) {return 1.0;} else {var uv: vec2f=uvDepth.xy*shadowMapSizeAndInverse.x;
|
|
291
|
+
uv+=0.5;
|
|
292
|
+
var st: vec2f=fract(uv);
|
|
293
|
+
var base_uv: vec2f=floor(uv)-0.5;
|
|
294
|
+
base_uv*=shadowMapSizeAndInverse.y;
|
|
295
|
+
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);}}
|
|
296
|
+
fn computeShadowWithPCF5(vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_depth_2d,shadowSampler: sampler_comparison,shadowMapSizeAndInverse: vec2f,darkness: f32,frustumEdgeFalloff: f32)->f32
|
|
297
|
+
{var clipSpace: vec3f=vPositionFromLight.xyz/vPositionFromLight.w;var uvDepth: vec3f= vec3f(0.5*clipSpace.xyz+ vec3f(0.5));uvDepth.z=getZInClip(clipSpace,uvDepth);if (depthMetric<0.0 || depthMetric>1.0 || uvDepth.x<0. || uvDepth.x>1.0 || uvDepth.y<0. || uvDepth.y>1.0) {return 1.0;} else {var uv: vec2f=uvDepth.xy*shadowMapSizeAndInverse.x;
|
|
298
|
+
uv+=0.5;
|
|
299
|
+
var st: vec2f=fract(uv);
|
|
300
|
+
var base_uv: vec2f=floor(uv)-0.5;
|
|
301
|
+
base_uv*=shadowMapSizeAndInverse.y;
|
|
302
|
+
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);}}
|
|
303
|
+
const PoissonSamplers32: array<vec3f,64>=array<vec3f,64> (
|
|
304
|
+
vec3f(0.06407013,0.05409927,0.),
|
|
305
|
+
vec3f(0.7366577,0.5789394,0.),
|
|
306
|
+
vec3f(-0.6270542,-0.5320278,0.),
|
|
307
|
+
vec3f(-0.4096107,0.8411095,0.),
|
|
308
|
+
vec3f(0.6849564,-0.4990818,0.),
|
|
309
|
+
vec3f(-0.874181,-0.04579735,0.),
|
|
310
|
+
vec3f(0.9989998,0.0009880066,0.),
|
|
311
|
+
vec3f(-0.004920578,-0.9151649,0.),
|
|
312
|
+
vec3f(0.1805763,0.9747483,0.),
|
|
313
|
+
vec3f(-0.2138451,0.2635818,0.),
|
|
314
|
+
vec3f(0.109845,0.3884785,0.),
|
|
315
|
+
vec3f(0.06876755,-0.3581074,0.),
|
|
316
|
+
vec3f(0.374073,-0.7661266,0.),
|
|
317
|
+
vec3f(0.3079132,-0.1216763,0.),
|
|
318
|
+
vec3f(-0.3794335,-0.8271583,0.),
|
|
319
|
+
vec3f(-0.203878,-0.07715034,0.),
|
|
320
|
+
vec3f(0.5912697,0.1469799,0.),
|
|
321
|
+
vec3f(-0.88069,0.3031784,0.),
|
|
322
|
+
vec3f(0.5040108,0.8283722,0.),
|
|
323
|
+
vec3f(-0.5844124,0.5494877,0.),
|
|
324
|
+
vec3f(0.6017799,-0.1726654,0.),
|
|
325
|
+
vec3f(-0.5554981,0.1559997,0.),
|
|
326
|
+
vec3f(-0.3016369,-0.3900928,0.),
|
|
327
|
+
vec3f(-0.5550632,-0.1723762,0.),
|
|
328
|
+
vec3f(0.925029,0.2995041,0.),
|
|
329
|
+
vec3f(-0.2473137,0.5538505,0.),
|
|
330
|
+
vec3f(0.9183037,-0.2862392,0.),
|
|
331
|
+
vec3f(0.2469421,0.6718712,0.),
|
|
332
|
+
vec3f(0.3916397,-0.4328209,0.),
|
|
333
|
+
vec3f(-0.03576927,-0.6220032,0.),
|
|
334
|
+
vec3f(-0.04661255,0.7995201,0.),
|
|
335
|
+
vec3f(0.4402924,0.3640312,0.),
|
|
336
|
+
vec3f(0.),
|
|
337
|
+
vec3f(0.),
|
|
338
|
+
vec3f(0.),
|
|
339
|
+
vec3f(0.),
|
|
340
|
+
vec3f(0.),
|
|
341
|
+
vec3f(0.),
|
|
342
|
+
vec3f(0.),
|
|
343
|
+
vec3f(0.),
|
|
344
|
+
vec3f(0.),
|
|
345
|
+
vec3f(0.),
|
|
346
|
+
vec3f(0.),
|
|
347
|
+
vec3f(0.),
|
|
348
|
+
vec3f(0.),
|
|
349
|
+
vec3f(0.),
|
|
350
|
+
vec3f(0.),
|
|
351
|
+
vec3f(0.),
|
|
352
|
+
vec3f(0.),
|
|
353
|
+
vec3f(0.),
|
|
354
|
+
vec3f(0.),
|
|
355
|
+
vec3f(0.),
|
|
356
|
+
vec3f(0.),
|
|
357
|
+
vec3f(0.),
|
|
358
|
+
vec3f(0.),
|
|
359
|
+
vec3f(0.),
|
|
360
|
+
vec3f(0.),
|
|
361
|
+
vec3f(0.),
|
|
362
|
+
vec3f(0.),
|
|
363
|
+
vec3f(0.),
|
|
364
|
+
vec3f(0.),
|
|
365
|
+
vec3f(0.),
|
|
366
|
+
vec3f(0.),
|
|
367
|
+
vec3f(0.)
|
|
368
|
+
);const PoissonSamplers64: array<vec3f,64>=array<vec3f,64> (
|
|
369
|
+
vec3f(-0.613392,0.617481,0.),
|
|
370
|
+
vec3f(0.170019,-0.040254,0.),
|
|
371
|
+
vec3f(-0.299417,0.791925,0.),
|
|
372
|
+
vec3f(0.645680,0.493210,0.),
|
|
373
|
+
vec3f(-0.651784,0.717887,0.),
|
|
374
|
+
vec3f(0.421003,0.027070,0.),
|
|
375
|
+
vec3f(-0.817194,-0.271096,0.),
|
|
376
|
+
vec3f(-0.705374,-0.668203,0.),
|
|
377
|
+
vec3f(0.977050,-0.108615,0.),
|
|
378
|
+
vec3f(0.063326,0.142369,0.),
|
|
379
|
+
vec3f(0.203528,0.214331,0.),
|
|
380
|
+
vec3f(-0.667531,0.326090,0.),
|
|
381
|
+
vec3f(-0.098422,-0.295755,0.),
|
|
382
|
+
vec3f(-0.885922,0.215369,0.),
|
|
383
|
+
vec3f(0.566637,0.605213,0.),
|
|
384
|
+
vec3f(0.039766,-0.396100,0.),
|
|
385
|
+
vec3f(0.751946,0.453352,0.),
|
|
386
|
+
vec3f(0.078707,-0.715323,0.),
|
|
387
|
+
vec3f(-0.075838,-0.529344,0.),
|
|
388
|
+
vec3f(0.724479,-0.580798,0.),
|
|
389
|
+
vec3f(0.222999,-0.215125,0.),
|
|
390
|
+
vec3f(-0.467574,-0.405438,0.),
|
|
391
|
+
vec3f(-0.248268,-0.814753,0.),
|
|
392
|
+
vec3f(0.354411,-0.887570,0.),
|
|
393
|
+
vec3f(0.175817,0.382366,0.),
|
|
394
|
+
vec3f(0.487472,-0.063082,0.),
|
|
395
|
+
vec3f(-0.084078,0.898312,0.),
|
|
396
|
+
vec3f(0.488876,-0.783441,0.),
|
|
397
|
+
vec3f(0.470016,0.217933,0.),
|
|
398
|
+
vec3f(-0.696890,-0.549791,0.),
|
|
399
|
+
vec3f(-0.149693,0.605762,0.),
|
|
400
|
+
vec3f(0.034211,0.979980,0.),
|
|
401
|
+
vec3f(0.503098,-0.308878,0.),
|
|
402
|
+
vec3f(-0.016205,-0.872921,0.),
|
|
403
|
+
vec3f(0.385784,-0.393902,0.),
|
|
404
|
+
vec3f(-0.146886,-0.859249,0.),
|
|
405
|
+
vec3f(0.643361,0.164098,0.),
|
|
406
|
+
vec3f(0.634388,-0.049471,0.),
|
|
407
|
+
vec3f(-0.688894,0.007843,0.),
|
|
408
|
+
vec3f(0.464034,-0.188818,0.),
|
|
409
|
+
vec3f(-0.440840,0.137486,0.),
|
|
410
|
+
vec3f(0.364483,0.511704,0.),
|
|
411
|
+
vec3f(0.034028,0.325968,0.),
|
|
412
|
+
vec3f(0.099094,-0.308023,0.),
|
|
413
|
+
vec3f(0.693960,-0.366253,0.),
|
|
414
|
+
vec3f(0.678884,-0.204688,0.),
|
|
415
|
+
vec3f(0.001801,0.780328,0.),
|
|
416
|
+
vec3f(0.145177,-0.898984,0.),
|
|
417
|
+
vec3f(0.062655,-0.611866,0.),
|
|
418
|
+
vec3f(0.315226,-0.604297,0.),
|
|
419
|
+
vec3f(-0.780145,0.486251,0.),
|
|
420
|
+
vec3f(-0.371868,0.882138,0.),
|
|
421
|
+
vec3f(0.200476,0.494430,0.),
|
|
422
|
+
vec3f(-0.494552,-0.711051,0.),
|
|
423
|
+
vec3f(0.612476,0.705252,0.),
|
|
424
|
+
vec3f(-0.578845,-0.768792,0.),
|
|
425
|
+
vec3f(-0.772454,-0.090976,0.),
|
|
426
|
+
vec3f(0.504440,0.372295,0.),
|
|
427
|
+
vec3f(0.155736,0.065157,0.),
|
|
428
|
+
vec3f(0.391522,0.849605,0.),
|
|
429
|
+
vec3f(-0.620106,-0.328104,0.),
|
|
430
|
+
vec3f(0.789239,-0.419965,0.),
|
|
431
|
+
vec3f(-0.545396,0.538133,0.),
|
|
432
|
+
vec3f(-0.178564,-0.596057,0.)
|
|
433
|
+
);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
|
|
434
|
+
{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);}
|
|
435
|
+
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);}
|
|
436
|
+
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);}
|
|
437
|
+
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
|
|
438
|
+
{var clipSpace: vec3f=vPositionFromLight.xyz/vPositionFromLight.w;var uvDepth: vec3f= vec3f(0.5*clipSpace.xyz+ vec3f(0.5));uvDepth.z=getZInClip(clipSpace,uvDepth);if (depthMetric<0.0 || depthMetric>1.0 || uvDepth.x<0. || uvDepth.x>1.0 || uvDepth.y<0. || uvDepth.y>1.0) {return 1.0;}
|
|
439
|
+
var blockerDepth: f32=0.0;var sumBlockerDepth: f32=0.0;var numBlocker: f32=0.0;for (var i: i32=0; i<searchTapCount; i ++) {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);}
|
|
440
|
+
if (numBlocker<1.0) {return 1.0;}
|
|
441
|
+
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++) {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);}
|
|
442
|
+
shadow/= f32(pcfTapCount);shadow=mix(shadow,1.,depthMetric-avgBlockerDepth);shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}
|
|
443
|
+
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
|
|
444
|
+
{return computeShadowWithPCSS(vPositionFromLight,depthMetric,depthTexture,depthSampler,shadowTexture,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,16,PoissonSamplers32);}
|
|
445
|
+
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
|
|
446
|
+
{return computeShadowWithPCSS(vPositionFromLight,depthMetric,depthTexture,depthSampler,shadowTexture,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,32,PoissonSamplers32);}
|
|
447
|
+
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
|
|
448
|
+
{return computeShadowWithPCSS(vPositionFromLight,depthMetric,depthTexture,depthSampler,shadowTexture,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,32,64,PoissonSamplers64);}
|
|
449
|
+
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
|
|
450
|
+
{return computeShadowWithCSMPCSS(layer,vPositionFromLight,depthMetric,depthTexture,depthSampler,shadowTexture,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,16,PoissonSamplers32,lightSizeUVCorrection,depthCorrection,penumbraDarkness);}
|
|
451
|
+
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
|
|
452
|
+
{return computeShadowWithCSMPCSS(layer,vPositionFromLight,depthMetric,depthTexture,depthSampler,shadowTexture,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,32,PoissonSamplers32,lightSizeUVCorrection,depthCorrection,penumbraDarkness);}
|
|
453
|
+
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
|
|
454
|
+
{return computeShadowWithCSMPCSS(layer,vPositionFromLight,depthMetric,depthTexture,depthSampler,shadowTexture,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,32,64,PoissonSamplers64,lightSizeUVCorrection,depthCorrection,penumbraDarkness);}
|
|
455
|
+
#endif
|
|
456
|
+
`;
|
|
457
|
+
e.IncludesShadersStoreWGSL[v] || (e.IncludesShadersStoreWGSL[v] = g);
|
|
458
|
+
const s = "imageProcessingDeclaration", T = `#ifdef EXPOSURE
|
|
459
|
+
uniform exposureLinear: f32;
|
|
460
|
+
#endif
|
|
461
|
+
#ifdef CONTRAST
|
|
462
|
+
uniform contrast: f32;
|
|
463
|
+
#endif
|
|
464
|
+
#if defined(VIGNETTE) || defined(DITHER)
|
|
465
|
+
uniform vInverseScreenSize: vec2f;
|
|
466
|
+
#endif
|
|
467
|
+
#ifdef VIGNETTE
|
|
468
|
+
uniform vignetteSettings1: vec4f;uniform vignetteSettings2: vec4f;
|
|
469
|
+
#endif
|
|
470
|
+
#ifdef COLORCURVES
|
|
471
|
+
uniform vCameraColorCurveNegative: vec4f;uniform vCameraColorCurveNeutral: vec4f;uniform vCameraColorCurvePositive: vec4f;
|
|
472
|
+
#endif
|
|
473
|
+
#ifdef COLORGRADING
|
|
474
|
+
#ifdef COLORGRADING3D
|
|
475
|
+
var txColorTransformSampler: sampler;var txColorTransform: texture_3d<f32>;
|
|
476
|
+
#else
|
|
477
|
+
var txColorTransformSampler: sampler;var txColorTransform: texture_2d<f32>;
|
|
478
|
+
#endif
|
|
479
|
+
uniform colorTransformSettings: vec4f;
|
|
480
|
+
#endif
|
|
481
|
+
#ifdef DITHER
|
|
482
|
+
uniform ditherIntensity: f32;
|
|
483
|
+
#endif
|
|
484
|
+
`;
|
|
485
|
+
e.IncludesShadersStoreWGSL[s] || (e.IncludesShadersStoreWGSL[s] = T);
|
|
486
|
+
const i = "imageProcessingFunctions", D = `#if TONEMAPPING==3
|
|
487
|
+
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;}
|
|
488
|
+
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);}
|
|
489
|
+
#endif
|
|
490
|
+
#if TONEMAPPING==2
|
|
491
|
+
const ACESInputMat: mat3x3f= mat3x3f(
|
|
492
|
+
vec3f(0.59719,0.07600,0.02840),
|
|
493
|
+
vec3f(0.35458,0.90834,0.13383),
|
|
494
|
+
vec3f(0.04823,0.01566,0.83777)
|
|
495
|
+
);const ACESOutputMat: mat3x3f= mat3x3f(
|
|
496
|
+
vec3f( 1.60475,-0.10208,-0.00327),
|
|
497
|
+
vec3f(-0.53108, 1.10813,-0.07276),
|
|
498
|
+
vec3f(-0.07367,-0.00605, 1.07602)
|
|
499
|
+
);fn RRTAndODTFit(v: vec3f)->vec3f
|
|
500
|
+
{var a: vec3f=v*(v+0.0245786)-0.000090537;var b: vec3f=v*(0.983729*v+0.4329510)+0.238081;return a/b;}
|
|
501
|
+
fn ACESFitted(color: vec3f)->vec3f
|
|
502
|
+
{var output=ACESInputMat*color;output=RRTAndODTFit(output);output=ACESOutputMat*output;output=saturateVec3(output);return output;}
|
|
503
|
+
#endif
|
|
504
|
+
#define CUSTOM_IMAGEPROCESSINGFUNCTIONS_DEFINITIONS
|
|
505
|
+
fn applyImageProcessing(result: vec4f)->vec4f {
|
|
506
|
+
#define CUSTOM_IMAGEPROCESSINGFUNCTIONS_UPDATERESULT_ATSTART
|
|
507
|
+
var rgb=result.rgb;;
|
|
508
|
+
#ifdef EXPOSURE
|
|
509
|
+
rgb*=uniforms.exposureLinear;
|
|
510
|
+
#endif
|
|
511
|
+
#ifdef VIGNETTE
|
|
512
|
+
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;
|
|
513
|
+
#ifdef VIGNETTEBLENDMODEMULTIPLY
|
|
514
|
+
var vignetteColorMultiplier: vec3f=mix(vignetteColor, vec3f(1,1,1),vignette);rgb*=vignetteColorMultiplier;
|
|
515
|
+
#endif
|
|
516
|
+
#ifdef VIGNETTEBLENDMODEOPAQUE
|
|
517
|
+
rgb=mix(vignetteColor,rgb,vignette);
|
|
518
|
+
#endif
|
|
519
|
+
#endif
|
|
520
|
+
#if TONEMAPPING==3
|
|
521
|
+
rgb=PBRNeutralToneMapping(rgb);
|
|
522
|
+
#elif TONEMAPPING==2
|
|
523
|
+
rgb=ACESFitted(rgb);
|
|
524
|
+
#elif TONEMAPPING==1
|
|
525
|
+
const tonemappingCalibration: f32=1.590579;rgb=1.0-exp2(-tonemappingCalibration*rgb);
|
|
526
|
+
#endif
|
|
527
|
+
rgb=toGammaSpaceVec3(rgb);rgb=saturateVec3(rgb);
|
|
528
|
+
#ifdef CONTRAST
|
|
529
|
+
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);}
|
|
530
|
+
rgb=max(rgb,vec3f(0.));
|
|
531
|
+
#endif
|
|
532
|
+
#ifdef COLORGRADING
|
|
533
|
+
var colorTransformInput: vec3f=rgb*uniforms.colorTransformSettings.xxx+uniforms.colorTransformSettings.yyy;
|
|
534
|
+
#ifdef COLORGRADING3D
|
|
535
|
+
var colorTransformOutput: vec3f=textureSample(txColorTransform,txColorTransformSampler,colorTransformInput).rgb;
|
|
536
|
+
#else
|
|
537
|
+
var colorTransformOutput: vec3f=textureSample(txColorTransform,txColorTransformSampler,colorTransformInput,uniforms.colorTransformSettings.yz).rgb;
|
|
538
|
+
#endif
|
|
539
|
+
rgb=mix(rgb,colorTransformOutput,uniforms.colorTransformSettings.www);
|
|
540
|
+
#endif
|
|
541
|
+
#ifdef COLORCURVES
|
|
542
|
+
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);
|
|
543
|
+
#endif
|
|
544
|
+
#ifdef DITHER
|
|
545
|
+
var rand: f32=getRand(fragmentInputs.position.xy*uniforms.vInverseScreenSize);var dither: f32=mix(-uniforms.ditherIntensity,uniforms.ditherIntensity,rand);rgb=saturateVec3(rgb+ vec3f(dither));
|
|
546
|
+
#endif
|
|
547
|
+
#define CUSTOM_IMAGEPROCESSINGFUNCTIONS_UPDATERESULT_ATEND
|
|
548
|
+
return vec4f(rgb,result.a);}`;
|
|
549
|
+
e.IncludesShadersStoreWGSL[i] || (e.IncludesShadersStoreWGSL[i] = D);
|
|
550
|
+
const c = "textureRepetitionFunctions", y = `#if TEXTURE_REPETITION_MODE>0
|
|
551
|
+
fn _texRepHash4(p: vec2f)->vec4f {return fract(sin(vec4f(
|
|
552
|
+
1.0+dot(p,vec2f(37.0,17.0)),
|
|
553
|
+
2.0+dot(p,vec2f(11.0,47.0)),
|
|
554
|
+
3.0+dot(p,vec2f(41.0,29.0)),
|
|
555
|
+
4.0+dot(p,vec2f(23.0,31.0))
|
|
556
|
+
))*103.0);}
|
|
557
|
+
#endif
|
|
558
|
+
#if TEXTURE_REPETITION_MODE==1
|
|
559
|
+
fn _texRepSample(tex: texture_2d<f32>,samp: sampler,uv: vec2f)->vec4f {var k: f32=textureSample(tex,samp,0.005*uv).x;var index: f32=k*8.0;var f: f32=fract(index);var i: f32=floor(index+0.5);var ib: f32=floor(index);f=min(f,1.0-f)*2.0;var offa: vec2f=sin(vec2f(3.0,7.0)*i);var offb: vec2f=sin(vec2f(3.0,7.0)*ib);var dx: vec2f=dpdx(uv);var dy: vec2f=dpdy(uv);var cola: vec4f=textureSampleGrad(tex,samp,uv+0.3*offa,dx,dy);var colb: vec4f=textureSampleGrad(tex,samp,uv+0.3*offb,dx,dy);var colSum: f32=cola.x+cola.y+cola.z-colb.x-colb.y-colb.z;return mix(cola,colb,vec4f(smoothstep(0.2,0.8,f-0.1*colSum)));}
|
|
560
|
+
#elif TEXTURE_REPETITION_MODE==2
|
|
561
|
+
fn _texRepHexHash(p: vec2f)->vec2f {var r: vec2f=mat2x2f(127.1,269.5,311.7,183.3)*p;return fract(sin(r)*43758.5453);}
|
|
562
|
+
struct _TexRepTriGrid {w1: f32,
|
|
563
|
+
w2: f32,
|
|
564
|
+
w3: f32,
|
|
565
|
+
vertex1: vec2i,
|
|
566
|
+
vertex2: vec2i,
|
|
567
|
+
vertex3: vec2i,};fn _texRepTriangleGrid(st_in: vec2f)->_TexRepTriGrid {var st: vec2f=st_in*2.0*sqrt(3.0);var gridToSkewedGrid: mat2x2f=mat2x2f(1.0,0.0,-0.57735027,1.15470054);var skewedCoord: vec2f=gridToSkewedGrid*st;var baseId: vec2i=vec2i(floor(skewedCoord));var temp: vec3f=vec3f(fract(skewedCoord),0.0);temp.z=1.0-temp.x-temp.y;var s: f32=step(0.0,-temp.z);var s2: f32=2.0*s-1.0;var result: _TexRepTriGrid;result.w1=-temp.z*s2;result.w2=s-temp.y*s2;result.w3=s-temp.x*s2;result.vertex1=baseId+vec2i(i32(s),i32(s));result.vertex2=baseId+vec2i(i32(s),i32(1.0-s));result.vertex3=baseId+vec2i(i32(1.0-s),i32(s));return result;}
|
|
568
|
+
fn _texRepMakeCenST(Vertex: vec2i)->vec2f {var invSkewMat: mat2x2f=mat2x2f(1.0,0.0,0.5,1.0/1.15470054);return (invSkewMat*vec2f(Vertex))/(2.0*sqrt(3.0));}
|
|
569
|
+
fn _texRepLoadRot2x2(idx: vec2i,rotStr: f32)->mat2x2f {var angle: f32=f32(abs(idx.x*idx.y)+abs(idx.x+idx.y))+3.14159265358979;angle=angle % (2.0*3.14159265358979);if (angle<0.0) { angle+=2.0*3.14159265358979; }
|
|
570
|
+
if (angle>3.14159265358979) { angle-=3.14159265358979; }
|
|
571
|
+
angle*=rotStr;var cs: f32=cos(angle);var si: f32=sin(angle);return mat2x2f(cs,si,-si,cs);}
|
|
572
|
+
fn _texRepGain3(x: vec3f,r: f32)->vec3f {var k: f32=log(1.0-r)/log(0.5);var s: vec3f=2.0*step(vec3f(0.5),x);var m: vec3f=2.0*(1.0-s);var res: vec3f=0.5*s+0.25*m*pow(max(vec3f(0.0),s+x*m),vec3f(k));return res/(res.x+res.y+res.z);}
|
|
573
|
+
fn _texRepSample(tex: texture_2d<f32>,samp: sampler,uv: vec2f)->vec4f {var rotStrength: f32=uniforms.vTextureRepetitionHexTilingParams.x;var fallOffContrast: f32=uniforms.vTextureRepetitionHexTilingParams.y;var expVal: f32=uniforms.vTextureRepetitionHexTilingParams.z;var r: f32=uniforms.vTextureRepetitionHexTilingParams.w;var dSTdx: vec2f=dpdx(uv);var dSTdy: vec2f=dpdy(uv);var grid: _TexRepTriGrid=_texRepTriangleGrid(uv);var rot1: mat2x2f=_texRepLoadRot2x2(grid.vertex1,rotStrength);var rot2: mat2x2f=_texRepLoadRot2x2(grid.vertex2,rotStrength);var rot3: mat2x2f=_texRepLoadRot2x2(grid.vertex3,rotStrength);var cen1: vec2f=_texRepMakeCenST(grid.vertex1);var cen2: vec2f=_texRepMakeCenST(grid.vertex2);var cen3: vec2f=_texRepMakeCenST(grid.vertex3);var st1: vec2f=(uv-cen1)*rot1+cen1+_texRepHexHash(vec2f(grid.vertex1));var st2: vec2f=(uv-cen2)*rot2+cen2+_texRepHexHash(vec2f(grid.vertex2));var st3: vec2f=(uv-cen3)*rot3+cen3+_texRepHexHash(vec2f(grid.vertex3));var c1: vec4f=textureSampleGrad(tex,samp,st1,dSTdx*rot1,dSTdy*rot1);var c2: vec4f=textureSampleGrad(tex,samp,st2,dSTdx*rot2,dSTdy*rot2);var c3: vec4f=textureSampleGrad(tex,samp,st3,dSTdx*rot3,dSTdy*rot3);var Lw: vec3f=vec3f(0.299,0.587,0.114);var Dw: vec3f=vec3f(dot(c1.rgb,Lw),dot(c2.rgb,Lw),dot(c3.rgb,Lw));Dw=mix(vec3f(1.0),Dw,fallOffContrast);var W: vec3f=Dw*pow(vec3f(grid.w1,grid.w2,grid.w3),vec3f(expVal));W=W/(W.x+W.y+W.z);if (r != 0.5) {W=_texRepGain3(W,r);}
|
|
574
|
+
return W.x*c1+W.y*c2+W.z*c3;}
|
|
575
|
+
#elif TEXTURE_REPETITION_MODE==3
|
|
576
|
+
fn _texRepSample(tex: texture_2d<f32>,samp: sampler,uv: vec2f)->vec4f {var iuv: vec2f=floor(uv);var fuv: vec2f=fract(uv);var ofa: vec4f=_texRepHash4(iuv+vec2f(0.0,0.0));var ofb: vec4f=_texRepHash4(iuv+vec2f(1.0,0.0));var ofc: vec4f=_texRepHash4(iuv+vec2f(0.0,1.0));var ofd: vec4f=_texRepHash4(iuv+vec2f(1.0,1.0));var dx: vec2f=dpdx(uv);var dy: vec2f=dpdy(uv);ofa=vec4f(ofa.xy,sign(ofa.zw-0.5));ofb=vec4f(ofb.xy,sign(ofb.zw-0.5));ofc=vec4f(ofc.xy,sign(ofc.zw-0.5));ofd=vec4f(ofd.xy,sign(ofd.zw-0.5));var uva: vec2f=uv*ofa.zw+ofa.xy; var ddxa: vec2f=dx*ofa.zw; var ddya: vec2f=dy*ofa.zw;var uvb: vec2f=uv*ofb.zw+ofb.xy; var ddxb: vec2f=dx*ofb.zw; var ddyb: vec2f=dy*ofb.zw;var uvc: vec2f=uv*ofc.zw+ofc.xy; var ddxc: vec2f=dx*ofc.zw; var ddyc: vec2f=dy*ofc.zw;var uvd: vec2f=uv*ofd.zw+ofd.xy; var ddxd: vec2f=dx*ofd.zw; var ddyd: vec2f=dy*ofd.zw;var b: vec2f=smoothstep(vec2f(0.25),vec2f(0.75),fuv);return mix(
|
|
577
|
+
mix(textureSampleGrad(tex,samp,uva,ddxa,ddya),textureSampleGrad(tex,samp,uvb,ddxb,ddyb),b.x),
|
|
578
|
+
mix(textureSampleGrad(tex,samp,uvc,ddxc,ddyc),textureSampleGrad(tex,samp,uvd,ddxd,ddyd),b.x),
|
|
579
|
+
b.y
|
|
580
|
+
);}
|
|
581
|
+
#elif TEXTURE_REPETITION_MODE==4
|
|
582
|
+
fn _texRepSample(tex: texture_2d<f32>,samp: sampler,uv: vec2f)->vec4f {var p: vec2f=floor(uv);var f: vec2f=fract(uv);var dx: vec2f=dpdx(uv);var dy: vec2f=dpdy(uv);var va: vec4f=vec4f(0.0);var wt: f32=0.0;var w2: f32=0.0;for (var j: i32=-1; j<=1; j++) {for (var i: i32=-1; i<=1; i++) {var g: vec2f=vec2f(f32(i),f32(j));var o: vec4f=_texRepHash4(p+g);var r: vec2f=g-f+o.xy;var d: f32=dot(r,r);var w: f32=exp(-5.0*d);var c: vec4f=textureSampleGrad(tex,samp,uv+o.zw,dx,dy);va+=w*c;wt+=w;w2+=w*w;}}
|
|
583
|
+
var mean: f32=0.3;var res: vec4f=mean+(va-wt*mean)/sqrt(w2);return mix(va/wt,res,0.4);}
|
|
584
|
+
#endif
|
|
585
|
+
#if TEXTURE_REPETITION_MODE>0
|
|
586
|
+
fn TEXRD(t: texture_2d<f32>,ts: sampler,uv: vec2f)->vec4f {return _texRepSample(t,ts,uv);}
|
|
587
|
+
#else
|
|
588
|
+
fn TEXRD(t: texture_2d<f32>,ts: sampler,uv: vec2f)->vec4f {return textureSample(t,ts,uv);}
|
|
589
|
+
#endif
|
|
590
|
+
#define TEXRD_DEFINED
|
|
591
|
+
`;
|
|
592
|
+
e.IncludesShadersStoreWGSL[c] || (e.IncludesShadersStoreWGSL[c] = y);
|
|
593
|
+
const d = "fogFragmentDeclaration", C = `#ifdef FOG
|
|
594
|
+
#define FOGMODE_NONE 0.
|
|
595
|
+
#define FOGMODE_EXP 1.
|
|
596
|
+
#define FOGMODE_EXP2 2.
|
|
597
|
+
#define FOGMODE_LINEAR 3.
|
|
598
|
+
const E=2.71828;uniform vFogInfos: vec4f;uniform vFogColor: vec3f;varying vFogDistance: vec3f;fn CalcFogFactor()->f32
|
|
599
|
+
{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)
|
|
600
|
+
{fogCoeff=(fogEnd-fogDistance)/(fogEnd-fogStart);}
|
|
601
|
+
else if (FOGMODE_EXP==uniforms.vFogInfos.x)
|
|
602
|
+
{fogCoeff=1.0/pow(E,fogDistance*fogDensity);}
|
|
603
|
+
else if (FOGMODE_EXP2==uniforms.vFogInfos.x)
|
|
604
|
+
{fogCoeff=1.0/pow(E,fogDistance*fogDistance*fogDensity*fogDensity);}
|
|
605
|
+
return clamp(fogCoeff,0.0,1.0);}
|
|
606
|
+
#endif
|
|
607
|
+
`;
|
|
608
|
+
e.IncludesShadersStoreWGSL[d] || (e.IncludesShadersStoreWGSL[d] = C);
|
|
609
|
+
const p = "depthPrePass", L = `#ifdef DEPTHPREPASS
|
|
610
|
+
#if !defined(PREPASS) && !defined(ORDER_INDEPENDENT_TRANSPARENCY)
|
|
611
|
+
fragmentOutputs.color= vec4f(0.,0.,0.,1.0);
|
|
612
|
+
#endif
|
|
613
|
+
return fragmentOutputs;
|
|
614
|
+
#endif
|
|
615
|
+
`;
|
|
616
|
+
e.IncludesShadersStoreWGSL[p] || (e.IncludesShadersStoreWGSL[p] = L);
|
|
617
|
+
const u = "logDepthFragment", _ = `#ifdef LOGARITHMICDEPTH
|
|
618
|
+
fragmentOutputs.fragDepth=log2(fragmentInputs.vFragmentDepth)*uniforms.logarithmicDepthConstant*0.5;
|
|
619
|
+
#endif
|
|
620
|
+
`;
|
|
621
|
+
e.IncludesShadersStoreWGSL[u] || (e.IncludesShadersStoreWGSL[u] = _);
|
|
622
|
+
const l = "fogFragment", E = `#ifdef FOG
|
|
623
|
+
var fog: f32=CalcFogFactor();
|
|
624
|
+
#ifdef PBR
|
|
625
|
+
fog=toLinearSpace(fog);
|
|
626
|
+
#endif
|
|
627
|
+
color= vec4f(mix(uniforms.vFogColor,color.rgb,fog),color.a);
|
|
628
|
+
#endif
|
|
629
|
+
`;
|
|
630
|
+
e.IncludesShadersStoreWGSL[l] || (e.IncludesShadersStoreWGSL[l] = E);
|
|
631
|
+
const n = "oitFragment", P = `#ifdef ORDER_INDEPENDENT_TRANSPARENCY
|
|
632
|
+
var fragDepth: f32=fragmentInputs.position.z;
|
|
633
|
+
#ifdef ORDER_INDEPENDENT_TRANSPARENCY_16BITS
|
|
634
|
+
var halfFloat: u32=pack2x16float( vec2f(fragDepth));var full: vec2f=unpack2x16float(halfFloat);fragDepth=full.x;
|
|
635
|
+
#endif
|
|
636
|
+
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);
|
|
637
|
+
#ifdef USE_REVERSE_DEPTHBUFFER
|
|
638
|
+
var furthestDepth: f32=-lastDepth.x;var nearestDepth: f32=lastDepth.y;
|
|
639
|
+
#else
|
|
640
|
+
var nearestDepth: f32=-lastDepth.x;var furthestDepth: f32=lastDepth.y;
|
|
641
|
+
#endif
|
|
642
|
+
var alphaMultiplier: f32=1.0-lastFrontColor.a;
|
|
643
|
+
#ifdef USE_REVERSE_DEPTHBUFFER
|
|
644
|
+
if (fragDepth>nearestDepth || fragDepth<furthestDepth) {
|
|
645
|
+
#else
|
|
646
|
+
if (fragDepth<nearestDepth || fragDepth>furthestDepth) {
|
|
647
|
+
#endif
|
|
648
|
+
return fragmentOutputs;}
|
|
649
|
+
#ifdef USE_REVERSE_DEPTHBUFFER
|
|
650
|
+
if (fragDepth<nearestDepth && fragDepth>furthestDepth) {
|
|
651
|
+
#else
|
|
652
|
+
if (fragDepth>nearestDepth && fragDepth<furthestDepth) {
|
|
653
|
+
#endif
|
|
654
|
+
fragmentOutputs.depth=vec2f(-fragDepth,fragDepth);return fragmentOutputs;}
|
|
655
|
+
#endif
|
|
656
|
+
`;
|
|
657
|
+
e.IncludesShadersStoreWGSL[n] || (e.IncludesShadersStoreWGSL[n] = P);
|