@uptimizr/dashboard 0.1.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.
Files changed (130) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +76 -0
  3. package/out/404.html +1 -0
  4. package/out/__next.__PAGE__.txt +9 -0
  5. package/out/__next._full.txt +20 -0
  6. package/out/__next._head.txt +6 -0
  7. package/out/__next._index.txt +5 -0
  8. package/out/__next._tree.txt +4 -0
  9. package/out/_next/static/93W3szqylNKDg-afLRmVW/_buildManifest.js +11 -0
  10. package/out/_next/static/93W3szqylNKDg-afLRmVW/_clientMiddlewareManifest.js +1 -0
  11. package/out/_next/static/93W3szqylNKDg-afLRmVW/_ssgManifest.js +1 -0
  12. package/out/_next/static/chunks/0-2y-_oomza2l.js +87 -0
  13. package/out/_next/static/chunks/00k_j_r7bv_eb.js +266 -0
  14. package/out/_next/static/chunks/00zdau6mcqeae.js +1 -0
  15. package/out/_next/static/chunks/023axeoslq39i.js +1 -0
  16. package/out/_next/static/chunks/068j6934u8j16.js +1 -0
  17. package/out/_next/static/chunks/0_rf76jneiwal.js +176 -0
  18. package/out/_next/static/chunks/0aznt7717miff.js +1 -0
  19. package/out/_next/static/chunks/0cu-q5q3a7uf3.js +1 -0
  20. package/out/_next/static/chunks/0cz1d0mv5g_q7.js +1 -0
  21. package/out/_next/static/chunks/0dm32-jq30tg8.js +1 -0
  22. package/out/_next/static/chunks/0dn0yx0rn6mpf.js +1 -0
  23. package/out/_next/static/chunks/0flc7nppbmsl1.js +3 -0
  24. package/out/_next/static/chunks/0fskcfh9vbhtv.js +1 -0
  25. package/out/_next/static/chunks/0gv7mblzv3dl3.js +87 -0
  26. package/out/_next/static/chunks/0impkpmxx3ttp.js +1 -0
  27. package/out/_next/static/chunks/0jmn7u31w95ly.js +91 -0
  28. package/out/_next/static/chunks/0n8n481szj90g.js +1 -0
  29. package/out/_next/static/chunks/0o6ayai0s01js.js +1 -0
  30. package/out/_next/static/chunks/0rys92_73hdb0.js +22 -0
  31. package/out/_next/static/chunks/0tl_moiyi2txt.js +1 -0
  32. package/out/_next/static/chunks/0tx1j_ghpz7rc.css +3 -0
  33. package/out/_next/static/chunks/0ufbyo1x3qkmo.js +1 -0
  34. package/out/_next/static/chunks/0v82oqyoy9zol.js +1 -0
  35. package/out/_next/static/chunks/0wrm9jr-9bw0e.js +1893 -0
  36. package/out/_next/static/chunks/0wwcfw8i3j_zx.js +1 -0
  37. package/out/_next/static/chunks/0ys9-ozuluawt.js +1 -0
  38. package/out/_next/static/chunks/1-61zh4waha61.js +1 -0
  39. package/out/_next/static/chunks/10r_824wzt8hj.js +1 -0
  40. package/out/_next/static/chunks/112hws17nz665.js +7 -0
  41. package/out/_next/static/chunks/123xxske5c9na.js +1 -0
  42. package/out/_next/static/chunks/13isnf0--pmx1.js +1 -0
  43. package/out/_next/static/chunks/157d9euci08yu.js +1 -0
  44. package/out/_next/static/chunks/15s7425ffrec9.js +3 -0
  45. package/out/_next/static/chunks/163fa70v4mgxj.js +1 -0
  46. package/out/_next/static/chunks/17q0c2h5ui10r.js +4 -0
  47. package/out/_next/static/chunks/18u58lorfahxi.js +4 -0
  48. package/out/_next/static/chunks/1_aahautsz2v_.js +1 -0
  49. package/out/_next/static/chunks/1a9l89j7e6mqu.js +23 -0
  50. package/out/_next/static/chunks/1dsy2ngmfflis.js +123 -0
  51. package/out/_next/static/chunks/1flb8adpj6_2o.js +62 -0
  52. package/out/_next/static/chunks/1lsg-22yob8dx.js +1 -0
  53. package/out/_next/static/chunks/1nj82er7msdto.js +2 -0
  54. package/out/_next/static/chunks/1o1d0p-v1z8ty.js +1 -0
  55. package/out/_next/static/chunks/1pdep2_c530sg.js +1 -0
  56. package/out/_next/static/chunks/1thjncpj7u6pq.js +1 -0
  57. package/out/_next/static/chunks/1vdjn0pkoyypn.js +1 -0
  58. package/out/_next/static/chunks/1yehxf-fmeicg.js +1 -0
  59. package/out/_next/static/chunks/1zvc1tv--w8nn.js +1 -0
  60. package/out/_next/static/chunks/1zx2q-r32thv1.js +4 -0
  61. package/out/_next/static/chunks/2-sjjedfr0kfq.js +1 -0
  62. package/out/_next/static/chunks/21o42k82w4llc.js +1 -0
  63. package/out/_next/static/chunks/25b9x-li-tvk2.js +1 -0
  64. package/out/_next/static/chunks/2712627rfsmwn.js +1 -0
  65. package/out/_next/static/chunks/296w2ke-v5tbm.js +9 -0
  66. package/out/_next/static/chunks/29tfeb6amdkjb.js +23 -0
  67. package/out/_next/static/chunks/2a3spdq-m8drh.js +3 -0
  68. package/out/_next/static/chunks/2aelw3far6rii.js +1 -0
  69. package/out/_next/static/chunks/2aor7m-wbis85.js +1 -0
  70. package/out/_next/static/chunks/2cbmf9m7lqv6k.js +4 -0
  71. package/out/_next/static/chunks/2d09v5u7dfq0q.js +1 -0
  72. package/out/_next/static/chunks/2feca0xcipcyt.js +850 -0
  73. package/out/_next/static/chunks/2fh-_9b6tqhvb.js +1 -0
  74. package/out/_next/static/chunks/2g5gecypj0rqe.js +1 -0
  75. package/out/_next/static/chunks/2kazjq29jeamx.js +1109 -0
  76. package/out/_next/static/chunks/2p2vv6cc9i-3q.js +255 -0
  77. package/out/_next/static/chunks/2szdcpl41-kzv.js +1 -0
  78. package/out/_next/static/chunks/2tws5udjdcmh3.js +1 -0
  79. package/out/_next/static/chunks/2u6shh3oeycm-.js +1 -0
  80. package/out/_next/static/chunks/2unhhuv0arlcv.js +1 -0
  81. package/out/_next/static/chunks/2xwy0-qfho1iz.js +91 -0
  82. package/out/_next/static/chunks/2ycvtdd68gub7.js +1 -0
  83. package/out/_next/static/chunks/2yiy_l8bwiw2_.js +3 -0
  84. package/out/_next/static/chunks/2yph6f7khgqii.js +1 -0
  85. package/out/_next/static/chunks/3-shckrcpvbxu.js +1681 -0
  86. package/out/_next/static/chunks/30fq_t9e2_fv-.js +1 -0
  87. package/out/_next/static/chunks/30yzu213bqtq0.js +5 -0
  88. package/out/_next/static/chunks/310uz81hnnzsu.js +1 -0
  89. package/out/_next/static/chunks/3218lp8l0a5g_.js +1 -0
  90. package/out/_next/static/chunks/35h5n42wxwgzk.js +123 -0
  91. package/out/_next/static/chunks/37vzwr3ciejf1.js +1 -0
  92. package/out/_next/static/chunks/38fhw7fatsyvd.js +3 -0
  93. package/out/_next/static/chunks/3be6s4_kn9q-o.js +1 -0
  94. package/out/_next/static/chunks/3i3gbhccmhu7j.js +210 -0
  95. package/out/_next/static/chunks/3l1dr_qm_x5kp.js +1 -0
  96. package/out/_next/static/chunks/3mqy-84_ul3t2.js +1 -0
  97. package/out/_next/static/chunks/3nz-dh9d7cehk.js +1 -0
  98. package/out/_next/static/chunks/3pufs8g4ui943.js +1 -0
  99. package/out/_next/static/chunks/3sjq_xoi4rbyg.js +31 -0
  100. package/out/_next/static/chunks/3t06schbtqonl.js +1 -0
  101. package/out/_next/static/chunks/3v3-7fio3nw_t.js +1 -0
  102. package/out/_next/static/chunks/3v5ha25nxo43j.js +1 -0
  103. package/out/_next/static/chunks/3yfrsm8lfi6ls.js +22 -0
  104. package/out/_next/static/chunks/3zskk1hxu3-_o.js +1 -0
  105. package/out/_next/static/chunks/turbopack-2ropzf0axp1x9.js +1 -0
  106. package/out/_next/static/media/0c89a48fa5027cee-s.p.2cyn07wtgehh0.woff2 +0 -0
  107. package/out/_next/static/media/13bf9871fe164e7f-s.2f7nqdagzwx2-.woff2 +0 -0
  108. package/out/_next/static/media/28868e710e86be81-s.2eksvhm1z0jwa.woff2 +0 -0
  109. package/out/_next/static/media/32687112bd2dd8db-s.1gepa_7fcx9fm.woff2 +0 -0
  110. package/out/_next/static/media/3fe682a82f50d426-s.0vfdmo25voy_0.woff2 +0 -0
  111. package/out/_next/static/media/70bc3e132a0a741e-s.p.3t6q91iet4nsy.woff2 +0 -0
  112. package/out/_next/static/media/71b036adf157cdcf-s.0bp8oijd_gu96.woff2 +0 -0
  113. package/out/_next/static/media/89b21bb081cb7469-s.1fby2rem9ngyr.woff2 +0 -0
  114. package/out/_next/static/media/cc545e633e20c56d-s.176arc174-8zp.woff2 +0 -0
  115. package/out/_next/static/media/icon.08h29dad3pcxg.svg +4 -0
  116. package/out/_not-found/__next._full.txt +16 -0
  117. package/out/_not-found/__next._head.txt +6 -0
  118. package/out/_not-found/__next._index.txt +5 -0
  119. package/out/_not-found/__next._not-found.__PAGE__.txt +5 -0
  120. package/out/_not-found/__next._not-found.txt +5 -0
  121. package/out/_not-found/__next._tree.txt +2 -0
  122. package/out/_not-found.html +1 -0
  123. package/out/_not-found.txt +16 -0
  124. package/out/api/projects +1 -0
  125. package/out/icon.svg +4 -0
  126. package/out/index.html +1 -0
  127. package/out/index.txt +20 -0
  128. package/out/logo.svg +46 -0
  129. package/package.json +67 -0
  130. package/server/standalone.mjs +182 -0
@@ -0,0 +1,1681 @@
1
+ (globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,26022,e=>{"use strict";var r=e.i(12423),t=e.i(60106),a=e.i(50008),i=e.i(84933);let o="prePassDeclaration",f=`#ifdef PREPASS
2
+ #ifdef PREPASS_LOCAL_POSITION
3
+ varying vPosition : vec3f;
4
+ #endif
5
+ #ifdef PREPASS_DEPTH
6
+ varying vViewPos: vec3f;
7
+ #endif
8
+ #ifdef PREPASS_NORMALIZED_VIEW_DEPTH
9
+ varying vNormViewDepth: f32;
10
+ #endif
11
+ #if defined(PREPASS_VELOCITY) || defined(PREPASS_VELOCITY_LINEAR)
12
+ varying vCurrentPosition: vec4f;varying vPreviousPosition: vec4f;
13
+ #endif
14
+ #endif
15
+ `;r.ShaderStore.IncludesShadersStoreWGSL[o]||(r.ShaderStore.IncludesShadersStoreWGSL[o]=f);let n="oitDeclaration",s=`#ifdef ORDER_INDEPENDENT_TRANSPARENCY
16
+ #define MAX_DEPTH 99999.0
17
+ var oitDepthSamplerSampler: sampler;var oitDepthSampler: texture_2d<f32>;var oitFrontColorSamplerSampler: sampler;var oitFrontColorSampler: texture_2d<f32>;
18
+ #endif
19
+ `;r.ShaderStore.IncludesShadersStoreWGSL[n]||(r.ShaderStore.IncludesShadersStoreWGSL[n]=s);var l=e.i(39780),d=e.i(4357);let c="lightUboDeclaration",v=`#ifdef LIGHT{X}
20
+ struct Light{X}
21
+ {vLightData: vec4f,
22
+ vLightDiffuse: vec4f,
23
+ vLightSpecular: vec4f,
24
+ #ifdef SPOTLIGHT{X}
25
+ vLightDirection: vec4f,
26
+ vLightFalloff: vec4f,
27
+ #elif defined(POINTLIGHT{X})
28
+ vLightFalloff: vec4f,
29
+ #elif defined(HEMILIGHT{X})
30
+ vLightGround: vec3f,
31
+ #elif defined(CLUSTLIGHT{X})
32
+ vSliceData: vec2f,
33
+ vSliceRanges: array<vec4f,CLUSTLIGHT_SLICES>,
34
+ #endif
35
+ #if defined(AREALIGHT{X}) && defined(AREALIGHTUSED) && defined(AREALIGHTSUPPORTED)
36
+ vLightWidth: vec4f,
37
+ vLightHeight: vec4f,
38
+ #endif
39
+ shadowsInfo: vec4f,
40
+ depthValues: vec2f} ;var<uniform> light{X} : Light{X};
41
+ #ifdef IESLIGHTTEXTURE{X}
42
+ var iesLightTexture{X}Sampler: sampler;var iesLightTexture{X}: texture_2d<f32>;
43
+ #endif
44
+ #ifdef RECTAREALIGHTEMISSIONTEXTURE{X}
45
+ var rectAreaLightEmissionTexture{X}Sampler: sampler;var rectAreaLightEmissionTexture{X}: texture_2d<f32>;
46
+ #endif
47
+ #ifdef PROJECTEDLIGHTTEXTURE{X}
48
+ uniform textureProjectionMatrix{X}: mat4x4f;var projectionLightTexture{X}Sampler: sampler;var projectionLightTexture{X}: texture_2d<f32>;
49
+ #endif
50
+ #ifdef CLUSTLIGHT{X}
51
+ var lightDataTexture{X}: texture_2d<f32>;var<storage,read> tileMaskBuffer{X}: array<u32>;
52
+ #endif
53
+ #ifdef SHADOW{X}
54
+ #ifdef SHADOWCSM{X}
55
+ 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>;
56
+ #if defined(SHADOWPCSS{X})
57
+ var shadowTexture{X}Sampler: sampler_comparison;
58
+ 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;
59
+ #elif defined(SHADOWPCF{X})
60
+ var shadowTexture{X}Sampler: sampler_comparison;var shadowTexture{X}: texture_depth_2d_array;
61
+ #else
62
+ var shadowTexture{X}Sampler: sampler;
63
+ var shadowTexture{X}: texture_2d_array<f32>;
64
+ #endif
65
+ #ifdef SHADOWCSMDEBUG{X}
66
+ const vCascadeColorsMultiplier{X}: array<vec3f,8>=array<vec3f,8>
67
+ (
68
+ vec3f ( 1.5,0.0,0.0 ),
69
+ vec3f ( 0.0,1.5,0.0 ),
70
+ vec3f ( 0.0,0.0,5.5 ),
71
+ vec3f ( 1.5,0.0,5.5 ),
72
+ vec3f ( 1.5,1.5,0.0 ),
73
+ vec3f ( 1.0,1.0,1.0 ),
74
+ vec3f ( 0.0,1.0,5.5 ),
75
+ vec3f ( 0.5,3.5,0.75 )
76
+ );
77
+ #endif
78
+ #elif defined(SHADOWCUBE{X})
79
+ var shadowTexture{X}Sampler: sampler;var shadowTexture{X}: texture_cube<f32>;
80
+ #else
81
+ varying vPositionFromLight{X}: vec4f;varying vDepthMetric{X}: f32;
82
+ #if defined(SHADOWPCSS{X})
83
+ var shadowTexture{X}Sampler: sampler_comparison;
84
+ var shadowTexture{X}: texture_depth_2d;var depthTexture{X}Sampler: sampler;
85
+ var depthTexture{X}: texture_2d<f32>;
86
+ #elif defined(SHADOWPCF{X})
87
+ var shadowTexture{X}Sampler: sampler_comparison;var shadowTexture{X}: texture_depth_2d;
88
+ #else
89
+ var shadowTexture{X}Sampler: sampler;
90
+ var shadowTexture{X}: texture_2d<f32>;
91
+ #endif
92
+ uniform lightMatrix{X}: mat4x4f;
93
+ #endif
94
+ #endif
95
+ #endif
96
+ `;r.ShaderStore.IncludesShadersStoreWGSL[c]||(r.ShaderStore.IncludesShadersStoreWGSL[c]=v);let u="ltcHelperFunctions",p=`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;}
97
+ fn LTCClippedSphereFormFactor( f:vec3f )->f32 {var l: f32=length( f );return max( ( l*l+f.z )/( l+1.0 ),0.0 );}
98
+ 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 )
99
+ {thetaSintheta=v;}
100
+ else
101
+ {thetaSintheta=0.5*inverseSqrt( max( 1.0-x*x,0.00000001 ) )-v;}
102
+ return cross( v1,v2 )*thetaSintheta;}
103
+ 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 );}
104
+ var T1:vec3f=normalize( V-N*dot( V,N ) );var T2:vec3f=- cross( N,T1 );
105
+ 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 );}
106
+ struct areaLightData
107
+ {Diffuse: vec3f,
108
+ Specular: vec3f,
109
+ 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;
110
+ var rectCoords1:vec3f=lightPos-halfWidth-halfHeight;var rectCoords2:vec3f=lightPos-halfWidth+halfHeight;var rectCoords3:vec3f=lightPos+halfWidth+halfHeight;
111
+ #ifdef SPECULARTERM
112
+ 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>(
113
+ vec3f( t1.x,0,t1.y ),
114
+ vec3f( 0,1, 0 ),
115
+ vec3f( t1.z,0,t1.w )
116
+ );result.Fresnel=t2;result.Specular=LTCEvaluate( normal,viewDir,position,mInv,rectCoords0,rectCoords1,rectCoords2,rectCoords3 );
117
+ #endif
118
+ var mInvEmpty:mat3x3<f32>=mat3x3<f32>(
119
+ vec3f( 1,0,0 ),
120
+ vec3f( 0,1,0 ),
121
+ vec3f( 0,0,1 )
122
+ );result.Diffuse+=LTCEvaluate( normal,viewDir,position,mInvEmpty,rectCoords0,rectCoords1,rectCoords2,rectCoords3 );return result;}
123
+ 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;}
124
+ 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);}
125
+ 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;}
126
+ 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;
127
+ var rectCoords1: vec3f=lightPos-halfWidth-halfHeight;var rectCoords2: vec3f=lightPos-halfWidth+halfHeight;var rectCoords3: vec3f=lightPos+halfWidth+halfHeight;
128
+ #ifdef SPECULARTERM
129
+ 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>(
130
+ vec3f(t1.x,0,t1.y),
131
+ vec3f(0,1,0),
132
+ vec3f(t1.z,0,t1.w)
133
+ );result.Specular=LTCEvaluateWithEmission(normal,viewDir,position,mInv,rectCoords0,rectCoords1,rectCoords2,rectCoords3,emissionTexture,emissionTextureSampler);result.Fresnel=t2;
134
+ #endif
135
+ var mInvEmpty: mat3x3<f32>=mat3x3<f32>(
136
+ vec3f(1,0,0),
137
+ vec3f(0,1,0),
138
+ vec3f(0,0,1)
139
+ );result.Diffuse=LTCEvaluateWithEmission(normal,viewDir,position,mInvEmpty,rectCoords0,rectCoords1,rectCoords2,rectCoords3,emissionTexture,emissionTextureSampler);return result;}
140
+ `;r.ShaderStore.IncludesShadersStoreWGSL[u]||(r.ShaderStore.IncludesShadersStoreWGSL[u]=p);let h="clusteredLightingFunctions",m=`struct ClusteredLight {vLightData: vec4f,
141
+ vLightDiffuse: vec4f,
142
+ vLightSpecular: vec4f,
143
+ vLightDirection: vec4f,
144
+ vLightFalloff: vec4f,}
145
+ fn getClusteredLight(lightDataTexture: texture_2d<f32>,index: u32)->ClusteredLight {return ClusteredLight(
146
+ textureLoad(lightDataTexture,vec2u(0,index),0),
147
+ textureLoad(lightDataTexture,vec2u(1,index),0),
148
+ textureLoad(lightDataTexture,vec2u(2,index),0),
149
+ textureLoad(lightDataTexture,vec2u(3,index),0),
150
+ textureLoad(lightDataTexture,vec2u(4,index),0)
151
+ );}
152
+ fn getClusteredSliceIndex(sliceData: vec2f,viewDepth: f32)->i32 {return i32(log(viewDepth)*sliceData.x+sliceData.y);}
153
+ `;r.ShaderStore.IncludesShadersStoreWGSL[h]||(r.ShaderStore.IncludesShadersStoreWGSL[h]=m);let S="lightsFragmentFunctions",g=`struct lightingInfo
154
+ {diffuse: vec3f,
155
+ #ifdef SPECULARTERM
156
+ specular: vec3f,
157
+ #endif
158
+ #ifdef NDOTL
159
+ ndl: f32,
160
+ #endif
161
+ };fn computeLighting(viewDirectionW: vec3f,vNormal: vec3f,lightData: vec4f,diffuseColor: vec3f,specularColor: vec3f,range: f32,glossiness: f32)->lightingInfo {var result: lightingInfo;var lightVectorW: vec3f;var attenuation: f32=1.0;if (lightData.w==0.)
162
+ {var direction: vec3f=lightData.xyz-fragmentInputs.vPositionW;attenuation=max(0.,1.0-length(direction)/range);lightVectorW=normalize(direction);}
163
+ else
164
+ {lightVectorW=normalize(-lightData.xyz);}
165
+ var ndl: f32=max(0.,dot(vNormal,lightVectorW));
166
+ #ifdef NDOTL
167
+ result.ndl=ndl;
168
+ #endif
169
+ result.diffuse=ndl*diffuseColor*attenuation;
170
+ #ifdef SPECULARTERM
171
+ var angleW: vec3f=normalize(viewDirectionW+lightVectorW);var specComp: f32=max(0.,dot(vNormal,angleW));specComp=pow(specComp,max(1.,glossiness));result.specular=specComp*specularColor*attenuation;
172
+ #endif
173
+ return result;}
174
+ fn getAttenuation(cosAngle: f32,exponent: f32)->f32 {return max(0.,pow(cosAngle,exponent));}
175
+ fn getIESAttenuation(cosAngle: f32,iesLightTexture: texture_2d<f32>,iesLightTextureSampler: sampler)->f32 {var angle=acos(cosAngle)/PI;return textureSampleLevel(iesLightTexture,iesLightTextureSampler,vec2f(angle,0),0.).r;}
176
+ fn computeBasicSpotLighting(viewDirectionW: vec3f,lightVectorW: vec3f,vNormal: vec3f,attenuation: f32,diffuseColor: vec3f,specularColor: vec3f,glossiness: f32)->lightingInfo {var result: lightingInfo;var ndl: f32=max(0.,dot(vNormal,lightVectorW));
177
+ #ifdef NDOTL
178
+ result.ndl=ndl;
179
+ #endif
180
+ result.diffuse=ndl*diffuseColor*attenuation;
181
+ #ifdef SPECULARTERM
182
+ var angleW: vec3f=normalize(viewDirectionW+lightVectorW);var specComp: f32=max(0.,dot(vNormal,angleW));specComp=pow(specComp,max(1.,glossiness));result.specular=specComp*specularColor*attenuation;
183
+ #endif
184
+ return result;}
185
+ fn computeIESSpotLighting(viewDirectionW: vec3f,vNormal: vec3f,lightData: vec4f,lightDirection: vec4f,diffuseColor: vec3f,specularColor: vec3f,range: f32,glossiness: f32,iesLightTexture: texture_2d<f32>,iesLightTextureSampler: sampler)->lightingInfo {var direction: vec3f=lightData.xyz-fragmentInputs.vPositionW;var lightVectorW: vec3f=normalize(direction);var attenuation: f32=max(0.,1.0-length(direction)/range);var dotProduct=dot(lightDirection.xyz,-lightVectorW);var cosAngle: f32=max(0.,dotProduct);if (cosAngle>=lightDirection.w)
186
+ {attenuation*=getIESAttenuation(dotProduct,iesLightTexture,iesLightTextureSampler);return computeBasicSpotLighting(viewDirectionW,lightVectorW,vNormal,attenuation,diffuseColor,specularColor,glossiness);}
187
+ var result: lightingInfo;result.diffuse=vec3f(0.);
188
+ #ifdef SPECULARTERM
189
+ result.specular=vec3f(0.);
190
+ #endif
191
+ #ifdef NDOTL
192
+ result.ndl=0.;
193
+ #endif
194
+ return result;}
195
+ fn computeSpotLighting(viewDirectionW: vec3f,vNormal: vec3f ,lightData: vec4f,lightDirection: vec4f,diffuseColor: vec3f,specularColor: vec3f,range: f32,glossiness: f32)->lightingInfo {var direction: vec3f=lightData.xyz-fragmentInputs.vPositionW;var lightVectorW: vec3f=normalize(direction);var attenuation: f32=max(0.,1.0-length(direction)/range);var cosAngle: f32=max(0.,dot(lightDirection.xyz,-lightVectorW));if (cosAngle>=lightDirection.w)
196
+ {attenuation*=getAttenuation(cosAngle,lightData.w);return computeBasicSpotLighting(viewDirectionW,lightVectorW,vNormal,attenuation,diffuseColor,specularColor,glossiness);}
197
+ var result: lightingInfo;result.diffuse=vec3f(0.);
198
+ #ifdef SPECULARTERM
199
+ result.specular=vec3f(0.);
200
+ #endif
201
+ #ifdef NDOTL
202
+ result.ndl=0.;
203
+ #endif
204
+ return result;}
205
+ fn computeHemisphericLighting(viewDirectionW: vec3f,vNormal: vec3f,lightData: vec4f,diffuseColor: vec3f,specularColor: vec3f,groundColor: vec3f,glossiness: f32)->lightingInfo {var result: lightingInfo;var ndl: f32=dot(vNormal,lightData.xyz)*0.5+0.5;
206
+ #ifdef NDOTL
207
+ result.ndl=ndl;
208
+ #endif
209
+ result.diffuse=mix(groundColor,diffuseColor,ndl);
210
+ #ifdef SPECULARTERM
211
+ var angleW: vec3f=normalize(viewDirectionW+lightData.xyz);var specComp: f32=max(0.,dot(vNormal,angleW));specComp=pow(specComp,max(1.,glossiness));result.specular=specComp*specularColor;
212
+ #endif
213
+ return result;}
214
+ fn computeProjectionTextureDiffuseLighting(projectionLightTexture: texture_2d<f32>,projectionLightSampler: sampler,textureProjectionMatrix: mat4x4f,posW: vec3f)->vec3f {var strq: vec4f=textureProjectionMatrix*vec4f(posW,1.0);strq/=strq.w;var textureColor: vec3f=textureSample(projectionLightTexture,projectionLightSampler,strq.xy).rgb;return textureColor;}
215
+ #if defined(AREALIGHTUSED) && defined(AREALIGHTSUPPORTED)
216
+ #include<ltcHelperFunctions>
217
+ var areaLightsLTC1SamplerSampler: sampler;var areaLightsLTC1Sampler: texture_2d<f32>;var areaLightsLTC2SamplerSampler: sampler;var areaLightsLTC2Sampler: texture_2d<f32>;fn computeAreaLighting(ltc1: texture_2d<f32>,ltc1Sampler:sampler,ltc2:texture_2d<f32>,ltc2Sampler:sampler,viewDirectionW: vec3f,vNormal:vec3f,vPosition:vec3f,lightPosition:vec3f,halfWidth:vec3f, halfHeight:vec3f,diffuseColor:vec3f,specularColor:vec3f,roughness:f32 )->lightingInfo
218
+ {var result: lightingInfo;var data: areaLightData=computeAreaLightSpecularDiffuseFresnel(ltc1,ltc1Sampler,ltc2,ltc2Sampler,viewDirectionW,vNormal,vPosition,lightPosition,halfWidth,halfHeight,roughness);
219
+ #ifdef SPECULARTERM
220
+ var fresnel:vec3f=( specularColor*data.Fresnel.x+( vec3f( 1.0 )-specularColor )*data.Fresnel.y );result.specular+=specularColor*fresnel*data.Specular;
221
+ #endif
222
+ result.diffuse+=diffuseColor*data.Diffuse;return result;}
223
+ fn computeAreaLightingWithTexture(ltc1: texture_2d<f32>,ltc1Sampler:sampler,ltc2:texture_2d<f32>,ltc2Sampler:sampler,emissionTexture: texture_2d<f32>,emissionTextureSampler:sampler,viewDirectionW: vec3f,vNormal:vec3f,vPosition:vec3f,lightPosition:vec3f,halfWidth:vec3f, halfHeight:vec3f,diffuseColor:vec3f,specularColor:vec3f,roughness:f32 )->lightingInfo
224
+ {var result: lightingInfo;var data: areaLightData=computeAreaLightSpecularDiffuseFresnelWithEmission(ltc1,ltc1Sampler,ltc2,ltc2Sampler,emissionTexture,emissionTextureSampler,viewDirectionW,vNormal,vPosition,lightPosition,halfWidth,halfHeight,roughness);
225
+ #ifdef SPECULARTERM
226
+ var fresnel: vec3f=( specularColor*data.Fresnel.x+( vec3f( 1.0 )-specularColor )*data.Fresnel.y );result.specular+=specularColor*fresnel*data.Specular;
227
+ #endif
228
+ result.diffuse+=diffuseColor*data.Diffuse;return result;}
229
+ #endif
230
+ #if defined(CLUSTLIGHT_BATCH) && CLUSTLIGHT_BATCH>0
231
+ #include<clusteredLightingFunctions>
232
+ fn computeClusteredLighting(
233
+ lightDataTexture: texture_2d<f32>,
234
+ tileMaskBuffer: ptr<storage,array<u32>>,
235
+ viewDirectionW: vec3f,
236
+ vNormal: vec3f,
237
+ lightData: vec4f,
238
+ sliceRange: vec2u,
239
+ glossiness: f32
240
+ )->lightingInfo {var result: lightingInfo;let tilePosition=vec2u(fragmentInputs.position.xy*lightData.xy);let maskResolution=vec2u(lightData.zw);var tileIndex=(tilePosition.x*maskResolution.x+tilePosition.y)*maskResolution.y;let batchRange=sliceRange/CLUSTLIGHT_BATCH;var batchOffset=batchRange.x*CLUSTLIGHT_BATCH;tileIndex+=batchRange.x;for (var i=batchRange.x; i<=batchRange.y; i+=1) {var mask=tileMaskBuffer[tileIndex];tileIndex+=1;let maskOffset=max(sliceRange.x,batchOffset)-batchOffset;
241
+ let maskWidth=min(sliceRange.y-batchOffset+1,CLUSTLIGHT_BATCH);mask=extractBits(mask,maskOffset,maskWidth);while mask != 0 {let trailing=firstTrailingBit(mask);mask ^= 1u<<trailing;let light=getClusteredLight(lightDataTexture,batchOffset+maskOffset+trailing);var info: lightingInfo;if light.vLightDirection.w<0.0 {info=computeLighting(viewDirectionW,vNormal,light.vLightData,light.vLightDiffuse.rgb,light.vLightSpecular.rgb,light.vLightDiffuse.a,glossiness);} else {info=computeSpotLighting(viewDirectionW,vNormal,light.vLightData,light.vLightDirection,light.vLightDiffuse.rgb,light.vLightSpecular.rgb,light.vLightDiffuse.a,glossiness);}
242
+ result.diffuse+=info.diffuse;
243
+ #ifdef SPECULARTERM
244
+ result.specular+=info.specular;
245
+ #endif
246
+ }
247
+ batchOffset+=CLUSTLIGHT_BATCH;}
248
+ return result;}
249
+ #endif
250
+ `;r.ShaderStore.IncludesShadersStoreWGSL[S]||(r.ShaderStore.IncludesShadersStoreWGSL[S]=g);let x="shadowsFragmentFunctions",T=`#ifdef SHADOWS
251
+ #ifndef SHADOWFLOAT
252
+ fn unpack(color: vec4f)->f32
253
+ {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);}
254
+ #endif
255
+ fn computeFallOff(value: f32,clipSpace: vec2f,frustumEdgeFalloff: f32)->f32
256
+ {var mask: f32=smoothstep(1.0-frustumEdgeFalloff,1.00000012,clamp(dot(clipSpace,clipSpace),0.,1.));return mix(value,1.0,mask);}
257
+ fn computeShadowCube(worldPos: vec3f,lightPosition: vec3f,shadowTexture: texture_cube<f32>,shadowSampler: sampler,darkness: f32,depthValues: vec2f)->f32
258
+ {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;
259
+ #ifndef SHADOWFLOAT
260
+ var shadow: f32=unpack(textureSample(shadowTexture,shadowSampler,directionToLight));
261
+ #else
262
+ var shadow: f32=textureSample(shadowTexture,shadowSampler,directionToLight).x;
263
+ #endif
264
+ return select(1.0,darkness,depth>shadow);}
265
+ fn computeShadowWithPoissonSamplingCube(worldPos: vec3f,lightPosition: vec3f,shadowTexture: texture_cube<f32>,shadowSampler: sampler,mapSize: f32,darkness: f32,depthValues: vec2f)->f32
266
+ {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);
267
+ #ifndef SHADOWFLOAT
268
+ 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;};
269
+ #else
270
+ 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;};
271
+ #endif
272
+ return min(1.0,visibility+darkness);}
273
+ fn computeShadowWithESMCube(worldPos: vec3f,lightPosition: vec3f,shadowTexture: texture_cube<f32>,shadowSampler: sampler,darkness: f32,depthScale: f32,depthValues: vec2f)->f32
274
+ {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;
275
+ #ifndef SHADOWFLOAT
276
+ var shadowMapSample: f32=unpack(textureSample(shadowTexture,shadowSampler,directionToLight));
277
+ #else
278
+ var shadowMapSample: f32=textureSample(shadowTexture,shadowSampler,directionToLight).x;
279
+ #endif
280
+ var esm: f32=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);return esm;}
281
+ fn computeShadowWithCloseESMCube(worldPos: vec3f,lightPosition: vec3f,shadowTexture: texture_cube<f32>,shadowSampler: sampler,darkness: f32,depthScale: f32,depthValues: vec2f)->f32
282
+ {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;
283
+ #ifndef SHADOWFLOAT
284
+ var shadowMapSample: f32=unpack(textureSample(shadowTexture,shadowSampler,directionToLight));
285
+ #else
286
+ var shadowMapSample: f32=textureSample(shadowTexture,shadowSampler,directionToLight).x;
287
+ #endif
288
+ var esm: f32=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);return esm;}
289
+ fn computeShadowCSM(layer: i32,vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_2d_array<f32>,shadowSampler: sampler,darkness: f32,frustumEdgeFalloff: f32)->f32
290
+ {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);
291
+ #ifndef SHADOWFLOAT
292
+ var shadow: f32=unpack(textureSample(shadowTexture,shadowSampler,uv,layer));
293
+ #else
294
+ var shadow: f32=textureSample(shadowTexture,shadowSampler,uv,layer).x;
295
+ #endif
296
+ return select(1.,computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff),shadowPixelDepth>shadow );}
297
+ fn computeShadow(vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_2d<f32>,shadowSampler: sampler,darkness: f32,frustumEdgeFalloff: f32)->f32
298
+ {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)
299
+ {return 1.0;}
300
+ else
301
+ {var shadowPixelDepth: f32=clamp(depthMetric,0.,1.0);
302
+ #ifndef SHADOWFLOAT
303
+ var shadow: f32=unpack(textureSampleLevel(shadowTexture,shadowSampler,uv,0.));
304
+ #else
305
+ var shadow: f32=textureSampleLevel(shadowTexture,shadowSampler,uv,0.).x;
306
+ #endif
307
+ return select(1.,computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff),shadowPixelDepth>shadow );}}
308
+ fn computeShadowWithPoissonSampling(vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_2d<f32>,shadowSampler: sampler,mapSize: f32,darkness: f32,frustumEdgeFalloff: f32)->f32
309
+ {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)
310
+ {return 1.0;}
311
+ else
312
+ {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);
313
+ #ifndef SHADOWFLOAT
314
+ if (unpack(textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[0]*mapSize,0.))<shadowPixelDepth) {visibility-=0.25;}
315
+ if (unpack(textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[1]*mapSize,0.))<shadowPixelDepth) {visibility-=0.25;}
316
+ if (unpack(textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[2]*mapSize,0.))<shadowPixelDepth) {visibility-=0.25;}
317
+ if (unpack(textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[3]*mapSize,0.))<shadowPixelDepth) {visibility-=0.25;}
318
+ #else
319
+ if (textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[0]*mapSize,0.).x<shadowPixelDepth) {visibility-=0.25;}
320
+ if (textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[1]*mapSize,0.).x<shadowPixelDepth) {visibility-=0.25;}
321
+ if (textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[2]*mapSize,0.).x<shadowPixelDepth) {visibility-=0.25;}
322
+ if (textureSampleLevel(shadowTexture,shadowSampler,uv+poissonDisk[3]*mapSize,0.).x<shadowPixelDepth) {visibility-=0.25;}
323
+ #endif
324
+ return computeFallOff(min(1.0,visibility+darkness),clipSpace.xy,frustumEdgeFalloff);}}
325
+ fn computeShadowWithESM(vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_2d<f32>,shadowSampler: sampler,darkness: f32,depthScale: f32,frustumEdgeFalloff: f32)->f32
326
+ {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)
327
+ {return 1.0;}
328
+ else
329
+ {var shadowPixelDepth: f32=clamp(depthMetric,0.,1.0);
330
+ #ifndef SHADOWFLOAT
331
+ var shadowMapSample: f32=unpack(textureSampleLevel(shadowTexture,shadowSampler,uv,0.));
332
+ #else
333
+ var shadowMapSample: f32=textureSampleLevel(shadowTexture,shadowSampler,uv,0.).x;
334
+ #endif
335
+ var esm: f32=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);return computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);}}
336
+ fn computeShadowWithCloseESM(vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_2d<f32>,shadowSampler: sampler,darkness: f32,depthScale: f32,frustumEdgeFalloff: f32)->f32
337
+ {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)
338
+ {return 1.0;}
339
+ else
340
+ {var shadowPixelDepth: f32=clamp(depthMetric,0.,1.0);
341
+ #ifndef SHADOWFLOAT
342
+ var shadowMapSample: f32=unpack(textureSampleLevel(shadowTexture,shadowSampler,uv,0.));
343
+ #else
344
+ var shadowMapSample: f32=textureSampleLevel(shadowTexture,shadowSampler,uv,0.).x;
345
+ #endif
346
+ var esm: f32=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);return computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);}}
347
+ fn getZInClip(clipSpace: vec3f,uvDepth: vec3f)->f32
348
+ {
349
+ #ifdef IS_NDC_HALF_ZRANGE
350
+ return clipSpace.z;
351
+ #else
352
+ return uvDepth.z;
353
+ #endif
354
+ }
355
+ const GREATEST_LESS_THAN_ONE: f32=0.99999994;
356
+ #define DISABLE_UNIFORMITY_ANALYSIS
357
+ fn computeShadowWithCSMPCF1(layer: i32,vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_depth_2d_array,shadowSampler: sampler_comparison,darkness: f32,frustumEdgeFalloff: f32)->f32
358
+ {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);}
359
+ fn computeShadowWithCSMPCF3(layer: i32,vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_depth_2d_array,shadowSampler: sampler_comparison,shadowMapSizeAndInverse: vec2f,darkness: f32,frustumEdgeFalloff: f32)->f32
360
+ {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;
361
+ uv+=0.5;
362
+ var st: vec2f=fract(uv);
363
+ var base_uv: vec2f=floor(uv)-0.5;
364
+ base_uv*=shadowMapSizeAndInverse.y;
365
+ 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);}
366
+ fn computeShadowWithCSMPCF5(layer: i32,vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_depth_2d_array,shadowSampler: sampler_comparison,shadowMapSizeAndInverse: vec2f,darkness: f32,frustumEdgeFalloff: f32)->f32
367
+ {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;
368
+ uv+=0.5;
369
+ var st: vec2f=fract(uv);
370
+ var base_uv: vec2f=floor(uv)-0.5;
371
+ base_uv*=shadowMapSizeAndInverse.y;
372
+ 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);}
373
+ fn computeShadowWithPCF1(vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_depth_2d,shadowSampler: sampler_comparison,darkness: f32,frustumEdgeFalloff: f32)->f32
374
+ {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);}}
375
+ fn computeShadowWithPCF3(vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_depth_2d,shadowSampler: sampler_comparison,shadowMapSizeAndInverse: vec2f,darkness: f32,frustumEdgeFalloff: f32)->f32
376
+ {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;
377
+ uv+=0.5;
378
+ var st: vec2f=fract(uv);
379
+ var base_uv: vec2f=floor(uv)-0.5;
380
+ base_uv*=shadowMapSizeAndInverse.y;
381
+ 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);}}
382
+ fn computeShadowWithPCF5(vPositionFromLight: vec4f,depthMetric: f32,shadowTexture: texture_depth_2d,shadowSampler: sampler_comparison,shadowMapSizeAndInverse: vec2f,darkness: f32,frustumEdgeFalloff: f32)->f32
383
+ {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;
384
+ uv+=0.5;
385
+ var st: vec2f=fract(uv);
386
+ var base_uv: vec2f=floor(uv)-0.5;
387
+ base_uv*=shadowMapSizeAndInverse.y;
388
+ 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);}}
389
+ const PoissonSamplers32: array<vec3f,64>=array<vec3f,64> (
390
+ vec3f(0.06407013,0.05409927,0.),
391
+ vec3f(0.7366577,0.5789394,0.),
392
+ vec3f(-0.6270542,-0.5320278,0.),
393
+ vec3f(-0.4096107,0.8411095,0.),
394
+ vec3f(0.6849564,-0.4990818,0.),
395
+ vec3f(-0.874181,-0.04579735,0.),
396
+ vec3f(0.9989998,0.0009880066,0.),
397
+ vec3f(-0.004920578,-0.9151649,0.),
398
+ vec3f(0.1805763,0.9747483,0.),
399
+ vec3f(-0.2138451,0.2635818,0.),
400
+ vec3f(0.109845,0.3884785,0.),
401
+ vec3f(0.06876755,-0.3581074,0.),
402
+ vec3f(0.374073,-0.7661266,0.),
403
+ vec3f(0.3079132,-0.1216763,0.),
404
+ vec3f(-0.3794335,-0.8271583,0.),
405
+ vec3f(-0.203878,-0.07715034,0.),
406
+ vec3f(0.5912697,0.1469799,0.),
407
+ vec3f(-0.88069,0.3031784,0.),
408
+ vec3f(0.5040108,0.8283722,0.),
409
+ vec3f(-0.5844124,0.5494877,0.),
410
+ vec3f(0.6017799,-0.1726654,0.),
411
+ vec3f(-0.5554981,0.1559997,0.),
412
+ vec3f(-0.3016369,-0.3900928,0.),
413
+ vec3f(-0.5550632,-0.1723762,0.),
414
+ vec3f(0.925029,0.2995041,0.),
415
+ vec3f(-0.2473137,0.5538505,0.),
416
+ vec3f(0.9183037,-0.2862392,0.),
417
+ vec3f(0.2469421,0.6718712,0.),
418
+ vec3f(0.3916397,-0.4328209,0.),
419
+ vec3f(-0.03576927,-0.6220032,0.),
420
+ vec3f(-0.04661255,0.7995201,0.),
421
+ vec3f(0.4402924,0.3640312,0.),
422
+ vec3f(0.),
423
+ vec3f(0.),
424
+ vec3f(0.),
425
+ vec3f(0.),
426
+ vec3f(0.),
427
+ vec3f(0.),
428
+ vec3f(0.),
429
+ vec3f(0.),
430
+ vec3f(0.),
431
+ vec3f(0.),
432
+ vec3f(0.),
433
+ vec3f(0.),
434
+ vec3f(0.),
435
+ vec3f(0.),
436
+ vec3f(0.),
437
+ vec3f(0.),
438
+ vec3f(0.),
439
+ vec3f(0.),
440
+ vec3f(0.),
441
+ vec3f(0.),
442
+ vec3f(0.),
443
+ vec3f(0.),
444
+ vec3f(0.),
445
+ vec3f(0.),
446
+ vec3f(0.),
447
+ vec3f(0.),
448
+ vec3f(0.),
449
+ vec3f(0.),
450
+ vec3f(0.),
451
+ vec3f(0.),
452
+ vec3f(0.),
453
+ vec3f(0.)
454
+ );const PoissonSamplers64: array<vec3f,64>=array<vec3f,64> (
455
+ vec3f(-0.613392,0.617481,0.),
456
+ vec3f(0.170019,-0.040254,0.),
457
+ vec3f(-0.299417,0.791925,0.),
458
+ vec3f(0.645680,0.493210,0.),
459
+ vec3f(-0.651784,0.717887,0.),
460
+ vec3f(0.421003,0.027070,0.),
461
+ vec3f(-0.817194,-0.271096,0.),
462
+ vec3f(-0.705374,-0.668203,0.),
463
+ vec3f(0.977050,-0.108615,0.),
464
+ vec3f(0.063326,0.142369,0.),
465
+ vec3f(0.203528,0.214331,0.),
466
+ vec3f(-0.667531,0.326090,0.),
467
+ vec3f(-0.098422,-0.295755,0.),
468
+ vec3f(-0.885922,0.215369,0.),
469
+ vec3f(0.566637,0.605213,0.),
470
+ vec3f(0.039766,-0.396100,0.),
471
+ vec3f(0.751946,0.453352,0.),
472
+ vec3f(0.078707,-0.715323,0.),
473
+ vec3f(-0.075838,-0.529344,0.),
474
+ vec3f(0.724479,-0.580798,0.),
475
+ vec3f(0.222999,-0.215125,0.),
476
+ vec3f(-0.467574,-0.405438,0.),
477
+ vec3f(-0.248268,-0.814753,0.),
478
+ vec3f(0.354411,-0.887570,0.),
479
+ vec3f(0.175817,0.382366,0.),
480
+ vec3f(0.487472,-0.063082,0.),
481
+ vec3f(-0.084078,0.898312,0.),
482
+ vec3f(0.488876,-0.783441,0.),
483
+ vec3f(0.470016,0.217933,0.),
484
+ vec3f(-0.696890,-0.549791,0.),
485
+ vec3f(-0.149693,0.605762,0.),
486
+ vec3f(0.034211,0.979980,0.),
487
+ vec3f(0.503098,-0.308878,0.),
488
+ vec3f(-0.016205,-0.872921,0.),
489
+ vec3f(0.385784,-0.393902,0.),
490
+ vec3f(-0.146886,-0.859249,0.),
491
+ vec3f(0.643361,0.164098,0.),
492
+ vec3f(0.634388,-0.049471,0.),
493
+ vec3f(-0.688894,0.007843,0.),
494
+ vec3f(0.464034,-0.188818,0.),
495
+ vec3f(-0.440840,0.137486,0.),
496
+ vec3f(0.364483,0.511704,0.),
497
+ vec3f(0.034028,0.325968,0.),
498
+ vec3f(0.099094,-0.308023,0.),
499
+ vec3f(0.693960,-0.366253,0.),
500
+ vec3f(0.678884,-0.204688,0.),
501
+ vec3f(0.001801,0.780328,0.),
502
+ vec3f(0.145177,-0.898984,0.),
503
+ vec3f(0.062655,-0.611866,0.),
504
+ vec3f(0.315226,-0.604297,0.),
505
+ vec3f(-0.780145,0.486251,0.),
506
+ vec3f(-0.371868,0.882138,0.),
507
+ vec3f(0.200476,0.494430,0.),
508
+ vec3f(-0.494552,-0.711051,0.),
509
+ vec3f(0.612476,0.705252,0.),
510
+ vec3f(-0.578845,-0.768792,0.),
511
+ vec3f(-0.772454,-0.090976,0.),
512
+ vec3f(0.504440,0.372295,0.),
513
+ vec3f(0.155736,0.065157,0.),
514
+ vec3f(0.391522,0.849605,0.),
515
+ vec3f(-0.620106,-0.328104,0.),
516
+ vec3f(0.789239,-0.419965,0.),
517
+ vec3f(-0.545396,0.538133,0.),
518
+ vec3f(-0.178564,-0.596057,0.)
519
+ );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
520
+ {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);}
521
+ 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);}
522
+ 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);}
523
+ 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
524
+ {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;}
525
+ 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);}
526
+ if (numBlocker<1.0) {return 1.0;}
527
+ 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);}
528
+ shadow/= f32(pcfTapCount);shadow=mix(shadow,1.,depthMetric-avgBlockerDepth);shadow=mix(darkness,1.,shadow);return computeFallOff(shadow,clipSpace.xy,frustumEdgeFalloff);}
529
+ 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
530
+ {return computeShadowWithPCSS(vPositionFromLight,depthMetric,depthTexture,depthSampler,shadowTexture,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,16,PoissonSamplers32);}
531
+ 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
532
+ {return computeShadowWithPCSS(vPositionFromLight,depthMetric,depthTexture,depthSampler,shadowTexture,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,32,PoissonSamplers32);}
533
+ 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
534
+ {return computeShadowWithPCSS(vPositionFromLight,depthMetric,depthTexture,depthSampler,shadowTexture,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,32,64,PoissonSamplers64);}
535
+ 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
536
+ {return computeShadowWithCSMPCSS(layer,vPositionFromLight,depthMetric,depthTexture,depthSampler,shadowTexture,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,16,PoissonSamplers32,lightSizeUVCorrection,depthCorrection,penumbraDarkness);}
537
+ 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
538
+ {return computeShadowWithCSMPCSS(layer,vPositionFromLight,depthMetric,depthTexture,depthSampler,shadowTexture,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,16,32,PoissonSamplers32,lightSizeUVCorrection,depthCorrection,penumbraDarkness);}
539
+ 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
540
+ {return computeShadowWithCSMPCSS(layer,vPositionFromLight,depthMetric,depthTexture,depthSampler,shadowTexture,shadowSampler,shadowMapSizeInverse,lightSizeUV,darkness,frustumEdgeFalloff,32,64,PoissonSamplers64,lightSizeUVCorrection,depthCorrection,penumbraDarkness);}
541
+ #endif
542
+ `;r.ShaderStore.IncludesShadersStoreWGSL[x]||(r.ShaderStore.IncludesShadersStoreWGSL[x]=T);let L="samplerFragmentDeclaration",C=`#ifdef _DEFINENAME_
543
+ #if _DEFINENAME_DIRECTUV==1
544
+ #define v_VARYINGNAME_UV vMainUV1
545
+ #elif _DEFINENAME_DIRECTUV==2
546
+ #define v_VARYINGNAME_UV vMainUV2
547
+ #elif _DEFINENAME_DIRECTUV==3
548
+ #define v_VARYINGNAME_UV vMainUV3
549
+ #elif _DEFINENAME_DIRECTUV==4
550
+ #define v_VARYINGNAME_UV vMainUV4
551
+ #elif _DEFINENAME_DIRECTUV==5
552
+ #define v_VARYINGNAME_UV vMainUV5
553
+ #elif _DEFINENAME_DIRECTUV==6
554
+ #define v_VARYINGNAME_UV vMainUV6
555
+ #else
556
+ varying v_VARYINGNAME_UV: vec2f;
557
+ #endif
558
+ var _SAMPLERNAME_SamplerSampler: sampler;var _SAMPLERNAME_Sampler: texture_2d<f32>;
559
+ #endif
560
+ `;r.ShaderStore.IncludesShadersStoreWGSL[L]||(r.ShaderStore.IncludesShadersStoreWGSL[L]=C);let w="fresnelFunction",E=`#ifdef FRESNEL
561
+ fn computeFresnelTerm(viewDirection: vec3f,worldNormal: vec3f,bias: f32,power: f32)->f32
562
+ {let fresnelTerm: f32=pow(bias+abs(dot(viewDirection,worldNormal)),power);return clamp(fresnelTerm,0.,1.);}
563
+ #endif
564
+ `;r.ShaderStore.IncludesShadersStoreWGSL[w]||(r.ShaderStore.IncludesShadersStoreWGSL[w]=E);let I="reflectionFunction",D=`fn computeFixedEquirectangularCoords(worldPos: vec4f,worldNormal: vec3f,direction: vec3f)->vec3f
565
+ {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); }
566
+ fn computeMirroredFixedEquirectangularCoords(worldPos: vec4f,worldNormal: vec3f,direction: vec3f)->vec3f
567
+ {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); }
568
+ fn computeEquirectangularCoords(worldPos: vec4f,worldNormal: vec3f,eyePosition: vec3f,reflectionMatrix: mat4x4f)->vec3f
569
+ {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);}
570
+ fn computeSphericalCoords(worldPos: vec4f,worldNormal: vec3f,view: mat4x4f,reflectionMatrix: mat4x4f)->vec3f
571
+ {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);}
572
+ fn computePlanarCoords(worldPos: vec4f,worldNormal: vec3f,eyePosition: vec3f,reflectionMatrix: mat4x4f)->vec3f
573
+ {var viewDir: vec3f=worldPos.xyz-eyePosition;var coords: vec3f=normalize(reflect(viewDir,worldNormal));return (reflectionMatrix* vec4f(coords,1)).xyz;}
574
+ fn computeCubicCoords(worldPos: vec4f,worldNormal: vec3f,eyePosition: vec3f,reflectionMatrix: mat4x4f)->vec3f
575
+ {var viewDir: vec3f=normalize(worldPos.xyz-eyePosition);var coords: vec3f=reflect(viewDir,worldNormal);coords= (reflectionMatrix* vec4f(coords,0)).xyz;
576
+ #ifdef INVERTCUBICMAP
577
+ coords.y*=-1.0;
578
+ #endif
579
+ return coords;}
580
+ fn computeCubicLocalCoords(worldPos: vec4f,worldNormal: vec3f,eyePosition: vec3f,reflectionMatrix: mat4x4f,reflectionSize: vec3f,reflectionPosition: vec3f)->vec3f
581
+ {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;
582
+ #ifdef INVERTCUBICMAP
583
+ coords.y*=-1.0;
584
+ #endif
585
+ return coords;}
586
+ fn computeProjectionCoords(worldPos: vec4f,view: mat4x4f,reflectionMatrix: mat4x4f)->vec3f
587
+ {return (reflectionMatrix*(view*worldPos)).xyz;}
588
+ fn computeSkyBoxCoords(positionW: vec3f,reflectionMatrix: mat4x4f)->vec3f
589
+ {return (reflectionMatrix* vec4f(positionW,1.)).xyz;}
590
+ #ifdef REFLECTION
591
+ fn computeReflectionCoords(worldPos: vec4f,worldNormal: vec3f)->vec3f
592
+ {
593
+ #ifdef REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED
594
+ var direction: vec3f=normalize(fragmentInputs.vDirectionW);return computeMirroredFixedEquirectangularCoords(worldPos,worldNormal,direction);
595
+ #endif
596
+ #ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED
597
+ var direction: vec3f=normalize(fragmentInputs.vDirectionW);return computeFixedEquirectangularCoords(worldPos,worldNormal,direction);
598
+ #endif
599
+ #ifdef REFLECTIONMAP_EQUIRECTANGULAR
600
+ return computeEquirectangularCoords(worldPos,worldNormal,scene.vEyePosition.xyz,uniforms.reflectionMatrix);
601
+ #endif
602
+ #ifdef REFLECTIONMAP_SPHERICAL
603
+ return computeSphericalCoords(worldPos,worldNormal,scene.view,uniforms.reflectionMatrix);
604
+ #endif
605
+ #ifdef REFLECTIONMAP_PLANAR
606
+ return computePlanarCoords(worldPos,worldNormal,scene.vEyePosition.xyz,uniforms.reflectionMatrix);
607
+ #endif
608
+ #ifdef REFLECTIONMAP_CUBIC
609
+ #ifdef USE_LOCAL_REFLECTIONMAP_CUBIC
610
+ return computeCubicLocalCoords(worldPos,worldNormal,scene.vEyePosition.xyz,uniforms.reflectionMatrix,uniforms.vReflectionSize,uniforms.vReflectionPosition);
611
+ #else
612
+ return computeCubicCoords(worldPos,worldNormal,scene.vEyePosition.xyz,uniforms.reflectionMatrix);
613
+ #endif
614
+ #endif
615
+ #ifdef REFLECTIONMAP_PROJECTION
616
+ return computeProjectionCoords(worldPos,scene.view,uniforms.reflectionMatrix);
617
+ #endif
618
+ #ifndef REFLECTIONMAP_CUBIC
619
+ #ifdef REFLECTIONMAP_SKYBOX
620
+ return computeSkyBoxCoords(fragmentInputs.vPositionUVW,uniforms.reflectionMatrix);
621
+ #endif
622
+ #endif
623
+ #ifdef REFLECTIONMAP_EXPLICIT
624
+ return vec3f(0,0,0);
625
+ #endif
626
+ }
627
+ #endif
628
+ `;r.ShaderStore.IncludesShadersStoreWGSL[I]||(r.ShaderStore.IncludesShadersStoreWGSL[I]=D);let A="imageProcessingDeclaration",P=`#ifdef EXPOSURE
629
+ uniform exposureLinear: f32;
630
+ #endif
631
+ #ifdef CONTRAST
632
+ uniform contrast: f32;
633
+ #endif
634
+ #if defined(VIGNETTE) || defined(DITHER)
635
+ uniform vInverseScreenSize: vec2f;
636
+ #endif
637
+ #ifdef VIGNETTE
638
+ uniform vignetteSettings1: vec4f;uniform vignetteSettings2: vec4f;
639
+ #endif
640
+ #ifdef COLORCURVES
641
+ uniform vCameraColorCurveNegative: vec4f;uniform vCameraColorCurveNeutral: vec4f;uniform vCameraColorCurvePositive: vec4f;
642
+ #endif
643
+ #ifdef COLORGRADING
644
+ #ifdef COLORGRADING3D
645
+ var txColorTransformSampler: sampler;var txColorTransform: texture_3d<f32>;
646
+ #else
647
+ var txColorTransformSampler: sampler;var txColorTransform: texture_2d<f32>;
648
+ #endif
649
+ uniform colorTransformSettings: vec4f;
650
+ #endif
651
+ #ifdef DITHER
652
+ uniform ditherIntensity: f32;
653
+ #endif
654
+ `;r.ShaderStore.IncludesShadersStoreWGSL[A]||(r.ShaderStore.IncludesShadersStoreWGSL[A]=P);let X="imageProcessingFunctions",R=`#if TONEMAPPING==3
655
+ 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;}
656
+ 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);}
657
+ #endif
658
+ #if TONEMAPPING==2
659
+ const ACESInputMat: mat3x3f= mat3x3f(
660
+ vec3f(0.59719,0.07600,0.02840),
661
+ vec3f(0.35458,0.90834,0.13383),
662
+ vec3f(0.04823,0.01566,0.83777)
663
+ );const ACESOutputMat: mat3x3f= mat3x3f(
664
+ vec3f( 1.60475,-0.10208,-0.00327),
665
+ vec3f(-0.53108, 1.10813,-0.07276),
666
+ vec3f(-0.07367,-0.00605, 1.07602)
667
+ );fn RRTAndODTFit(v: vec3f)->vec3f
668
+ {var a: vec3f=v*(v+0.0245786)-0.000090537;var b: vec3f=v*(0.983729*v+0.4329510)+0.238081;return a/b;}
669
+ fn ACESFitted(color: vec3f)->vec3f
670
+ {var output=ACESInputMat*color;output=RRTAndODTFit(output);output=ACESOutputMat*output;output=saturateVec3(output);return output;}
671
+ #endif
672
+ #define CUSTOM_IMAGEPROCESSINGFUNCTIONS_DEFINITIONS
673
+ fn applyImageProcessing(result: vec4f)->vec4f {
674
+ #define CUSTOM_IMAGEPROCESSINGFUNCTIONS_UPDATERESULT_ATSTART
675
+ var rgb=result.rgb;;
676
+ #ifdef EXPOSURE
677
+ rgb*=uniforms.exposureLinear;
678
+ #endif
679
+ #ifdef VIGNETTE
680
+ 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;
681
+ #ifdef VIGNETTEBLENDMODEMULTIPLY
682
+ var vignetteColorMultiplier: vec3f=mix(vignetteColor, vec3f(1,1,1),vignette);rgb*=vignetteColorMultiplier;
683
+ #endif
684
+ #ifdef VIGNETTEBLENDMODEOPAQUE
685
+ rgb=mix(vignetteColor,rgb,vignette);
686
+ #endif
687
+ #endif
688
+ #if TONEMAPPING==3
689
+ rgb=PBRNeutralToneMapping(rgb);
690
+ #elif TONEMAPPING==2
691
+ rgb=ACESFitted(rgb);
692
+ #elif TONEMAPPING==1
693
+ const tonemappingCalibration: f32=1.590579;rgb=1.0-exp2(-tonemappingCalibration*rgb);
694
+ #endif
695
+ rgb=toGammaSpaceVec3(rgb);rgb=saturateVec3(rgb);
696
+ #ifdef CONTRAST
697
+ 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);}
698
+ rgb=max(rgb,vec3f(0.));
699
+ #endif
700
+ #ifdef COLORGRADING
701
+ var colorTransformInput: vec3f=rgb*uniforms.colorTransformSettings.xxx+uniforms.colorTransformSettings.yyy;
702
+ #ifdef COLORGRADING3D
703
+ var colorTransformOutput: vec3f=textureSample(txColorTransform,txColorTransformSampler,colorTransformInput).rgb;
704
+ #else
705
+ var colorTransformOutput: vec3f=textureSample(txColorTransform,txColorTransformSampler,colorTransformInput,uniforms.colorTransformSettings.yz).rgb;
706
+ #endif
707
+ rgb=mix(rgb,colorTransformOutput,uniforms.colorTransformSettings.www);
708
+ #endif
709
+ #ifdef COLORCURVES
710
+ 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);
711
+ #endif
712
+ #ifdef DITHER
713
+ var rand: f32=getRand(fragmentInputs.position.xy*uniforms.vInverseScreenSize);var dither: f32=mix(-uniforms.ditherIntensity,uniforms.ditherIntensity,rand);rgb=saturateVec3(rgb+ vec3f(dither));
714
+ #endif
715
+ #define CUSTOM_IMAGEPROCESSINGFUNCTIONS_UPDATERESULT_ATEND
716
+ return vec4f(rgb,result.a);}`;r.ShaderStore.IncludesShadersStoreWGSL[X]||(r.ShaderStore.IncludesShadersStoreWGSL[X]=R);let _="textureRepetitionFunctions",y=`#if TEXTURE_REPETITION_MODE>0
717
+ fn _texRepHash4(p: vec2f)->vec4f {return fract(sin(vec4f(
718
+ 1.0+dot(p,vec2f(37.0,17.0)),
719
+ 2.0+dot(p,vec2f(11.0,47.0)),
720
+ 3.0+dot(p,vec2f(41.0,29.0)),
721
+ 4.0+dot(p,vec2f(23.0,31.0))
722
+ ))*103.0);}
723
+ #endif
724
+ #if TEXTURE_REPETITION_MODE==1
725
+ 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)));}
726
+ #elif TEXTURE_REPETITION_MODE==2
727
+ fn _texRepHexHash(p: vec2f)->vec2f {var r: vec2f=mat2x2f(127.1,269.5,311.7,183.3)*p;return fract(sin(r)*43758.5453);}
728
+ struct _TexRepTriGrid {w1: f32,
729
+ w2: f32,
730
+ w3: f32,
731
+ vertex1: vec2i,
732
+ vertex2: vec2i,
733
+ 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;}
734
+ 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));}
735
+ 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; }
736
+ if (angle>3.14159265358979) { angle-=3.14159265358979; }
737
+ angle*=rotStr;var cs: f32=cos(angle);var si: f32=sin(angle);return mat2x2f(cs,si,-si,cs);}
738
+ 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);}
739
+ 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);}
740
+ return W.x*c1+W.y*c2+W.z*c3;}
741
+ #elif TEXTURE_REPETITION_MODE==3
742
+ 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(
743
+ mix(textureSampleGrad(tex,samp,uva,ddxa,ddya),textureSampleGrad(tex,samp,uvb,ddxb,ddyb),b.x),
744
+ mix(textureSampleGrad(tex,samp,uvc,ddxc,ddyc),textureSampleGrad(tex,samp,uvd,ddxd,ddyd),b.x),
745
+ b.y
746
+ );}
747
+ #elif TEXTURE_REPETITION_MODE==4
748
+ 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;}}
749
+ var mean: f32=0.3;var res: vec4f=mean+(va-wt*mean)/sqrt(w2);return mix(va/wt,res,0.4);}
750
+ #endif
751
+ #if TEXTURE_REPETITION_MODE>0
752
+ fn TEXRD(t: texture_2d<f32>,ts: sampler,uv: vec2f)->vec4f {return _texRepSample(t,ts,uv);}
753
+ #else
754
+ fn TEXRD(t: texture_2d<f32>,ts: sampler,uv: vec2f)->vec4f {return textureSample(t,ts,uv);}
755
+ #endif
756
+ #define TEXRD_DEFINED
757
+ `;r.ShaderStore.IncludesShadersStoreWGSL[_]||(r.ShaderStore.IncludesShadersStoreWGSL[_]=y);let N="bumpFragmentMainFunctions",M=`#ifndef TEXRD_DEFINED
758
+ fn TEXRD(t: texture_2d<f32>,ts: sampler,uv: vec2f)->vec4f {return textureSample(t,ts,uv);}
759
+ #define TEXRD_DEFINED
760
+ #endif
761
+ #if defined(BUMP) || defined(CLEARCOAT_BUMP) || defined(ANISOTROPIC) || defined(DETAIL)
762
+ #if defined(TANGENT) && defined(NORMAL)
763
+ varying vTBN0: vec3f;varying vTBN1: vec3f;varying vTBN2: vec3f;
764
+ #endif
765
+ #ifdef OBJECTSPACE_NORMALMAP
766
+ uniform normalMatrix: mat4x4f;fn toNormalMatrix(m: mat4x4f)->mat4x4f
767
+ {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];
768
+ var a21=m[2][1];var a22=m[2][2];var a23=m[2][3];var a30=m[3][0];
769
+ 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>(
770
+ (a11*b11-a12*b10+a13*b09)/det,
771
+ (a02*b10-a01*b11-a03*b09)/det,
772
+ (a31*b05-a32*b04+a33*b03)/det,
773
+ (a22*b04-a21*b05-a23*b03)/det,
774
+ (a12*b08-a10*b11-a13*b07)/det,
775
+ (a00*b11-a02*b08+a03*b07)/det,
776
+ (a32*b02-a30*b05-a33*b01)/det,
777
+ (a20*b05-a22*b02+a23*b01)/det,
778
+ (a10*b10-a11*b08+a13*b06)/det,
779
+ (a01*b08-a00*b10-a03*b06)/det,
780
+ (a30*b04-a31*b02+a33*b00)/det,
781
+ (a21*b02-a20*b04-a23*b00)/det,
782
+ (a11*b07-a10*b09-a12*b06)/det,
783
+ (a00*b09-a01*b07+a02*b06)/det,
784
+ (a31*b01-a30*b03-a32*b00)/det,
785
+ (a20*b03-a21*b01+a22*b00)/det);return mat4x4<f32>(mi[0][0],mi[1][0],mi[2][0],mi[3][0],
786
+ mi[0][1],mi[1][1],mi[2][1],mi[3][1],
787
+ mi[0][2],mi[1][2],mi[2][2],mi[3][2],
788
+ mi[0][3],mi[1][3],mi[2][3],mi[3][3]);}
789
+ #endif
790
+ fn perturbNormalBase(cotangentFrame: mat3x3f,normal: vec3f,scale: f32)->vec3f
791
+ {var output=normal;
792
+ #ifdef NORMALXYSCALE
793
+ output=normalize(output* vec3f(scale,scale,1.0));
794
+ #endif
795
+ return normalize(cotangentFrame*output);}
796
+ fn perturbNormal(cotangentFrame: mat3x3f,textureSample: vec3f,scale: f32)->vec3f
797
+ {return perturbNormalBase(cotangentFrame,textureSample*2.0-1.0,scale);}
798
+ fn cotangent_frame(normal: vec3f,p: vec3f,uv: vec2f,tangentSpaceParams: vec2f)->mat3x3f
799
+ {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);}
800
+ #endif
801
+ `;r.ShaderStore.IncludesShadersStoreWGSL[N]||(r.ShaderStore.IncludesShadersStoreWGSL[N]=M);let F="bumpFragmentFunctions",O=`#if defined(BUMP)
802
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,BUMP,_VARYINGNAME_,Bump,_SAMPLERNAME_,bump)
803
+ #endif
804
+ #if defined(DETAIL)
805
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,DETAIL,_VARYINGNAME_,Detail,_SAMPLERNAME_,detail)
806
+ #endif
807
+ #if defined(BUMP) && defined(PARALLAX)
808
+ 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++)
809
+ {currSampledHeight=textureSample(bumpSampler,bumpSamplerSampler,texCoord+vCurrOffset).w;if (!keepWorking)
810
+ {}
811
+ else if (currSampledHeight>currRayHeight)
812
+ {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;}
813
+ else
814
+ {currRayHeight-=stepSize;vLastOffset=vCurrOffset;
815
+ #ifdef PARALLAX_RHS
816
+ vCurrOffset-=stepSize*vMaxOffset;
817
+ #else
818
+ vCurrOffset+=stepSize*vMaxOffset;
819
+ #endif
820
+ lastSampledHeight=currSampledHeight;}}
821
+ return vCurrOffset;}
822
+ fn parallaxOffset(viewDir: vec3f,heightScale: f32)->vec2f
823
+ {var height: f32=textureSample(bumpSampler,bumpSamplerSampler,fragmentInputs.vBumpUV).w;var texCoordOffset: vec2f=heightScale*viewDir.xy*height;
824
+ #ifdef PARALLAX_RHS
825
+ return texCoordOffset;
826
+ #else
827
+ return -texCoordOffset;
828
+ #endif
829
+ }
830
+ #endif
831
+ `;r.ShaderStore.IncludesShadersStoreWGSL[F]||(r.ShaderStore.IncludesShadersStoreWGSL[F]=O);var b=e.i(35182),W=e.i(54758),z=e.i(25626),U=e.i(63406);let G="bumpFragment",H=`var uvOffset: vec2f= vec2f(0.0,0.0);
832
+ #if defined(BUMP) || defined(PARALLAX) || defined(DETAIL)
833
+ #ifdef NORMALXYSCALE
834
+ var normalScale: f32=1.0;
835
+ #elif defined(BUMP)
836
+ var normalScale: f32=uniforms.vBumpInfos.y;
837
+ #else
838
+ var normalScale: f32=1.0;
839
+ #endif
840
+ #if defined(TANGENT) && defined(NORMAL)
841
+ var TBN: mat3x3f=mat3x3<f32>(input.vTBN0,input.vTBN1,input.vTBN2);
842
+ #elif defined(BUMP)
843
+ var TBNUV: vec2f=select(-fragmentInputs.vBumpUV,fragmentInputs.vBumpUV,fragmentInputs.frontFacing);var TBN: mat3x3f=cotangent_frame(normalW*normalScale,input.vPositionW,TBNUV,uniforms.vTangentSpaceParams);
844
+ #else
845
+ var TBNUV: vec2f=select(-fragmentInputs.vDetailUV,fragmentInputs.vDetailUV,fragmentInputs.frontFacing);var TBN: mat3x3f=cotangent_frame(normalW*normalScale,input.vPositionW,TBNUV, vec2f(1.,1.));
846
+ #endif
847
+ #elif defined(ANISOTROPIC)
848
+ #if defined(TANGENT) && defined(NORMAL)
849
+ var TBN: mat3x3f=mat3x3<f32>(input.vTBN0,input.vTBN1,input.vTBN2);
850
+ #else
851
+ var TBNUV: vec2f=select( -fragmentInputs.vMainUV1,fragmentInputs.vMainUV1,fragmentInputs.frontFacing);var TBN: mat3x3f=cotangent_frame(normalW,input.vPositionW,TBNUV, vec2f(1.,1.));
852
+ #endif
853
+ #endif
854
+ #ifdef PARALLAX
855
+ var invTBN: mat3x3f=transposeMat3(TBN);
856
+ #ifdef PARALLAXOCCLUSION
857
+ uvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,fragmentInputs.vBumpUV,uniforms.vBumpInfos.z);
858
+ #else
859
+ uvOffset=parallaxOffset(invTBN*viewDirectionW,uniforms.vBumpInfos.z);
860
+ #endif
861
+ #endif
862
+ #ifdef DETAIL
863
+ 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);
864
+ #endif
865
+ #ifdef BUMP
866
+ #ifdef OBJECTSPACE_NORMALMAP
867
+ #define CUSTOM_FRAGMENT_BUMP_FRAGMENT
868
+ normalW=normalize(TEXRD(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);
869
+ #elif !defined(DETAIL)
870
+ normalW=perturbNormal(TBN,TEXRD(bumpSampler,bumpSamplerSampler,fragmentInputs.vBumpUV+uvOffset).xyz,uniforms.vBumpInfos.y);
871
+ #else
872
+ var bumpNormal: vec3f=TEXRD(bumpSampler,bumpSamplerSampler,fragmentInputs.vBumpUV+uvOffset).xyz*2.0-1.0;
873
+ #if DETAIL_NORMALBLENDMETHOD==0
874
+ detailNormal=vec3f(detailNormal.xy*uniforms.vDetailInfos.z,detailNormal.z);var blendedNormal: vec3f=normalize( vec3f(bumpNormal.xy+detailNormal.xy,bumpNormal.z*detailNormal.z));
875
+ #elif DETAIL_NORMALBLENDMETHOD==1
876
+ 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;
877
+ #endif
878
+ normalW=perturbNormalBase(TBN,blendedNormal,uniforms.vBumpInfos.y);
879
+ #endif
880
+ #elif defined(DETAIL)
881
+ detailNormal=vec3f(detailNormal.xy*uniforms.vDetailInfos.z,detailNormal.z);normalW=perturbNormalBase(TBN,detailNormal,uniforms.vDetailInfos.z);
882
+ #endif
883
+ `;r.ShaderStore.IncludesShadersStoreWGSL[G]||(r.ShaderStore.IncludesShadersStoreWGSL[G]=H);let V="decalFragment",k=`#ifdef DECAL
884
+ var decalTempColor=decalColor.rgb;var decalTempAlpha=decalColor.a;
885
+ #ifdef GAMMADECAL
886
+ decalTempColor=toLinearSpaceVec3(decalColor.rgb);
887
+ #endif
888
+ #ifdef DECAL_SMOOTHALPHA
889
+ decalTempAlpha=decalColor.a*decalColor.a;
890
+ #endif
891
+ surfaceAlbedo=mix(surfaceAlbedo.rgb,decalTempColor,decalTempAlpha);
892
+ #endif
893
+ `;r.ShaderStore.IncludesShadersStoreWGSL[V]||(r.ShaderStore.IncludesShadersStoreWGSL[V]=k);let B="depthPrePass",Y=`#ifdef DEPTHPREPASS
894
+ #if !defined(PREPASS) && !defined(ORDER_INDEPENDENT_TRANSPARENCY)
895
+ fragmentOutputs.color= vec4f(0.,0.,0.,1.0);
896
+ #endif
897
+ return fragmentOutputs;
898
+ #endif
899
+ `;r.ShaderStore.IncludesShadersStoreWGSL[B]||(r.ShaderStore.IncludesShadersStoreWGSL[B]=Y);let q="lightFragment",j=`#ifdef LIGHT{X}
900
+ #if defined(SHADOWONLY) || defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X})
901
+ #else
902
+ var diffuse{X}: vec4f=light{X}.vLightDiffuse;
903
+ #define CUSTOM_LIGHT{X}_COLOR
904
+ #if defined(PBR) && defined(CLUSTLIGHT{X})
905
+ {let sliceIndex=min(getClusteredSliceIndex(light{X}.vSliceData,fragmentInputs.vViewDepth),CLUSTLIGHT_SLICES-1);info=computeClusteredLighting(
906
+ lightDataTexture{X},
907
+ &tileMaskBuffer{X},
908
+ light{X}.vLightData,
909
+ vec2u(light{X}.vSliceRanges[sliceIndex].xy),
910
+ viewDirectionW,
911
+ normalW,
912
+ fragmentInputs.vPositionW,
913
+ surfaceAlbedo,
914
+ reflectivityOut,
915
+ #ifdef IRIDESCENCE
916
+ iridescenceIntensity,
917
+ #endif
918
+ #ifdef SS_TRANSLUCENCY
919
+ subSurfaceOut,
920
+ #endif
921
+ #ifdef SPECULARTERM
922
+ AARoughnessFactors.x,
923
+ #endif
924
+ #ifdef ANISOTROPIC
925
+ anisotropicOut,
926
+ #endif
927
+ #ifdef SHEEN
928
+ sheenOut,
929
+ #endif
930
+ #ifdef CLEARCOAT
931
+ clearcoatOut,
932
+ #endif
933
+ );}
934
+ #elif defined(PBR)
935
+ #ifdef SPOTLIGHT{X}
936
+ preInfo=computePointAndSpotPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW,fragmentInputs.vPositionW);
937
+ #elif defined(POINTLIGHT{X})
938
+ preInfo=computePointAndSpotPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW,fragmentInputs.vPositionW);
939
+ #elif defined(HEMILIGHT{X})
940
+ preInfo=computeHemisphericPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW);
941
+ #elif defined(DIRLIGHT{X})
942
+ preInfo=computeDirectionalPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW);
943
+ #elif defined(AREALIGHT{X}) && defined(AREALIGHTUSED) && defined(AREALIGHTSUPPORTED)
944
+ #if defined(RECTAREALIGHTEMISSIONTEXTURE{X})
945
+ preInfo=computeAreaPreLightingInfoWithTexture(areaLightsLTC1Sampler,areaLightsLTC1SamplerSampler,areaLightsLTC2Sampler,areaLightsLTC2SamplerSampler,rectAreaLightEmissionTexture{X},rectAreaLightEmissionTexture{X}Sampler,viewDirectionW,normalW,fragmentInputs.vPositionW,light{X}.vLightData.xyz,light{X}.vLightWidth.xyz,light{X}.vLightHeight.xyz,roughness);
946
+ #else
947
+ preInfo=computeAreaPreLightingInfo(areaLightsLTC1Sampler,areaLightsLTC1SamplerSampler,areaLightsLTC2Sampler,areaLightsLTC2SamplerSampler,viewDirectionW,normalW,fragmentInputs.vPositionW,light{X}.vLightData.xyz,light{X}.vLightWidth.xyz,light{X}.vLightHeight.xyz,roughness);
948
+ #endif
949
+ #endif
950
+ preInfo.NdotV=NdotV;
951
+ #ifdef SPOTLIGHT{X}
952
+ #ifdef LIGHT_FALLOFF_GLTF{X}
953
+ preInfo.attenuation=computeDistanceLightFalloff_GLTF(preInfo.lightDistanceSquared,light{X}.vLightFalloff.y);
954
+ #ifdef IESLIGHTTEXTURE{X}
955
+ preInfo.attenuation*=computeDirectionalLightFalloff_IES(light{X}.vLightDirection.xyz,preInfo.L,iesLightTexture{X},iesLightTexture{X}Sampler);
956
+ #else
957
+ preInfo.attenuation*=computeDirectionalLightFalloff_GLTF(light{X}.vLightDirection.xyz,preInfo.L,light{X}.vLightFalloff.z,light{X}.vLightFalloff.w);
958
+ #endif
959
+ #elif defined(LIGHT_FALLOFF_PHYSICAL{X})
960
+ preInfo.attenuation=computeDistanceLightFalloff_Physical(preInfo.lightDistanceSquared);
961
+ #ifdef IESLIGHTTEXTURE{X}
962
+ preInfo.attenuation*=computeDirectionalLightFalloff_IES(light{X}.vLightDirection.xyz,preInfo.L,iesLightTexture{X},iesLightTexture{X}Sampler);
963
+ #else
964
+ preInfo.attenuation*=computeDirectionalLightFalloff_Physical(light{X}.vLightDirection.xyz,preInfo.L,light{X}.vLightDirection.w);
965
+ #endif
966
+ #elif defined(LIGHT_FALLOFF_STANDARD{X})
967
+ preInfo.attenuation=computeDistanceLightFalloff_Standard(preInfo.lightOffset,light{X}.vLightFalloff.x);
968
+ #ifdef IESLIGHTTEXTURE{X}
969
+ preInfo.attenuation*=computeDirectionalLightFalloff_IES(light{X}.vLightDirection.xyz,preInfo.L,iesLightTexture{X},iesLightTexture{X}Sampler);
970
+ #else
971
+ preInfo.attenuation*=computeDirectionalLightFalloff_Standard(light{X}.vLightDirection.xyz,preInfo.L,light{X}.vLightDirection.w,light{X}.vLightData.w);
972
+ #endif
973
+ #else
974
+ preInfo.attenuation=computeDistanceLightFalloff(preInfo.lightOffset,preInfo.lightDistanceSquared,light{X}.vLightFalloff.x,light{X}.vLightFalloff.y);
975
+ #ifdef IESLIGHTTEXTURE{X}
976
+ preInfo.attenuation*=computeDirectionalLightFalloff_IES(light{X}.vLightDirection.xyz,preInfo.L,iesLightTexture{X},iesLightTexture{X}Sampler);
977
+ #else
978
+ 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);
979
+ #endif
980
+ #endif
981
+ #elif defined(POINTLIGHT{X})
982
+ #ifdef LIGHT_FALLOFF_GLTF{X}
983
+ preInfo.attenuation=computeDistanceLightFalloff_GLTF(preInfo.lightDistanceSquared,light{X}.vLightFalloff.y);
984
+ #elif defined(LIGHT_FALLOFF_PHYSICAL{X})
985
+ preInfo.attenuation=computeDistanceLightFalloff_Physical(preInfo.lightDistanceSquared);
986
+ #elif defined(LIGHT_FALLOFF_STANDARD{X})
987
+ preInfo.attenuation=computeDistanceLightFalloff_Standard(preInfo.lightOffset,light{X}.vLightFalloff.x);
988
+ #else
989
+ preInfo.attenuation=computeDistanceLightFalloff(preInfo.lightOffset,preInfo.lightDistanceSquared,light{X}.vLightFalloff.x,light{X}.vLightFalloff.y);
990
+ #endif
991
+ #else
992
+ preInfo.attenuation=1.0;
993
+ #endif
994
+ #if defined(HEMILIGHT{X})
995
+ preInfo.roughness=roughness;
996
+ #elif defined(AREALIGHT{X}) && defined(AREALIGHTUSED) && defined(AREALIGHTSUPPORTED)
997
+ preInfo.roughness=roughness;
998
+ #else
999
+ preInfo.roughness=adjustRoughnessFromLightProperties(roughness,light{X}.vLightSpecular.a,preInfo.lightDistance);
1000
+ #endif
1001
+ preInfo.diffuseRoughness=diffuseRoughness;preInfo.surfaceAlbedo=surfaceAlbedo;
1002
+ #ifdef IRIDESCENCE
1003
+ preInfo.iridescenceIntensity=iridescenceIntensity;
1004
+ #endif
1005
+ #ifdef SS_TRANSLUCENCY
1006
+ info.diffuseTransmission=vec3f(0.0);
1007
+ #endif
1008
+ #ifdef HEMILIGHT{X}
1009
+ info.diffuse=computeHemisphericDiffuseLighting(preInfo,diffuse{X}.rgb,light{X}.vLightGround);
1010
+ #elif defined(AREALIGHT{X}) && defined(AREALIGHTUSED) && defined(AREALIGHTSUPPORTED)
1011
+ info.diffuse=computeAreaDiffuseLighting(preInfo,diffuse{X}.rgb);
1012
+ #elif defined(SS_TRANSLUCENCY)
1013
+ #ifndef SS_TRANSLUCENCY_LEGACY
1014
+ info.diffuse=computeDiffuseLighting(preInfo,diffuse{X}.rgb)*(1.0-subSurfaceOut.translucencyIntensity);info.diffuseTransmission=computeDiffuseTransmittedLighting(preInfo,diffuse{X}.rgb,subSurfaceOut.transmittance);
1015
+ #else
1016
+ info.diffuse=computeDiffuseTransmittedLighting(preInfo,diffuse{X}.rgb,subSurfaceOut.transmittance);
1017
+ #endif
1018
+ #else
1019
+ info.diffuse=computeDiffuseLighting(preInfo,diffuse{X}.rgb);
1020
+ #endif
1021
+ #ifdef SPECULARTERM
1022
+ #if defined(AREALIGHT{X}) && defined(AREALIGHTUSED) && defined(AREALIGHTSUPPORTED)
1023
+ info.specular=computeAreaSpecularLighting(preInfo,light{X}.vLightSpecular.rgb,clearcoatOut.specularEnvironmentR0,reflectivityOut.colorReflectanceF90);
1024
+ #else
1025
+ #if (CONDUCTOR_SPECULAR_MODEL==CONDUCTOR_SPECULAR_MODEL_OPENPBR)
1026
+ {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);}
1027
+ #else
1028
+ coloredFresnel=fresnelSchlickGGXVec3(preInfo.VdotH,clearcoatOut.specularEnvironmentR0,reflectivityOut.colorReflectanceF90);
1029
+ #endif
1030
+ #ifndef LEGACY_SPECULAR_ENERGY_CONSERVATION
1031
+ {let NdotH: f32=dot(normalW,preInfo.H);let fresnel: vec3f=fresnelSchlickGGXVec3(NdotH,vec3f(reflectanceF0),specularEnvironmentR90);info.diffuse*=(vec3f(1.0)-fresnel);}
1032
+ #endif
1033
+ #ifdef ANISOTROPIC
1034
+ info.specular=computeAnisotropicSpecularLighting(preInfo,viewDirectionW,normalW,anisotropicOut.anisotropicTangent,anisotropicOut.anisotropicBitangent,anisotropicOut.anisotropy,clearcoatOut.specularEnvironmentR0,specularEnvironmentR90,AARoughnessFactors.x,diffuse{X}.rgb);
1035
+ #else
1036
+ info.specular=computeSpecularLighting(preInfo,normalW,clearcoatOut.specularEnvironmentR0,coloredFresnel,AARoughnessFactors.x,diffuse{X}.rgb);
1037
+ #endif
1038
+ #endif
1039
+ #endif
1040
+ #ifndef AREALIGHT{X}
1041
+ #ifdef SHEEN
1042
+ #ifdef SHEEN_LINKWITHALBEDO
1043
+ preInfo.roughness=sheenOut.sheenIntensity;
1044
+ #else
1045
+ #ifdef HEMILIGHT{X}
1046
+ preInfo.roughness=sheenOut.sheenRoughness;
1047
+ #else
1048
+ preInfo.roughness=adjustRoughnessFromLightProperties(sheenOut.sheenRoughness,light{X}.vLightSpecular.a,preInfo.lightDistance);
1049
+ #endif
1050
+ #endif
1051
+ info.sheen=computeSheenLighting(preInfo,normalW,sheenOut.sheenColor,specularEnvironmentR90,AARoughnessFactors.x,diffuse{X}.rgb);
1052
+ #endif
1053
+ #ifdef CLEARCOAT
1054
+ #ifdef HEMILIGHT{X}
1055
+ preInfo.roughness=clearcoatOut.clearCoatRoughness;
1056
+ #else
1057
+ preInfo.roughness=adjustRoughnessFromLightProperties(clearcoatOut.clearCoatRoughness,light{X}.vLightSpecular.a,preInfo.lightDistance);
1058
+ #endif
1059
+ info.clearCoat=computeClearCoatLighting(preInfo,clearcoatOut.clearCoatNormalW,clearcoatOut.clearCoatAARoughnessFactors.x,clearcoatOut.clearCoatIntensity,diffuse{X}.rgb);
1060
+ #ifdef CLEARCOAT_TINT
1061
+ absorption=computeClearCoatLightingAbsorption(clearcoatOut.clearCoatNdotVRefract,preInfo.L,clearcoatOut.clearCoatNormalW,clearcoatOut.clearCoatColor,clearcoatOut.clearCoatThickness,clearcoatOut.clearCoatIntensity);info.diffuse*=absorption;
1062
+ #ifdef SS_TRANSLUCENCY
1063
+ info.diffuseTransmission*=absorption;
1064
+ #endif
1065
+ #ifdef SPECULARTERM
1066
+ info.specular*=absorption;
1067
+ #endif
1068
+ #endif
1069
+ info.diffuse*=info.clearCoat.w;
1070
+ #ifdef SS_TRANSLUCENCY
1071
+ info.diffuseTransmission*=info.clearCoat.w;
1072
+ #endif
1073
+ #ifdef SPECULARTERM
1074
+ info.specular*=info.clearCoat.w;
1075
+ #endif
1076
+ #ifdef SHEEN
1077
+ info.sheen*=info.clearCoat.w;
1078
+ #endif
1079
+ #endif
1080
+ #endif
1081
+ #else
1082
+ #ifdef SPOTLIGHT{X}
1083
+ #ifdef IESLIGHTTEXTURE{X}
1084
+ 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);
1085
+ #else
1086
+ info=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,diffuse{X}.rgb,light{X}.vLightSpecular.rgb,diffuse{X}.a,glossiness);
1087
+ #endif
1088
+ #elif defined(HEMILIGHT{X})
1089
+ info=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,diffuse{X}.rgb,light{X}.vLightSpecular.rgb,light{X}.vLightGround,glossiness);
1090
+ #elif defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})
1091
+ info=computeLighting(viewDirectionW,normalW,light{X}.vLightData,diffuse{X}.rgb,light{X}.vLightSpecular.rgb,diffuse{X}.a,glossiness);
1092
+ #elif define(AREALIGHT{X}) && defined(AREALIGHTSUPPORTED)
1093
+ #if defined(RECTAREALIGHTEMISSIONTEXTURE{X})
1094
+ info=computeAreaLightingWithTexture(areaLightsLTC1Sampler,areaLightsLTC1SamplerSampler,areaLightsLTC2Sampler,areaLightsLTC2SamplerSampler,rectAreaLightEmissionTexture{X},rectAreaLightEmissionTexture{X}Sampler,viewDirectionW,normalW,fragmentInputs.vPositionW,light{X}.vLightData.xyz,light{X}.vLightWidth.xyz,light{X}.vLightHeight.xyz,diffuse{X}.rgb,light{X}.vLightSpecular.rgb,
1095
+ #ifdef AREALIGHTNOROUGHTNESS
1096
+ 0.5
1097
+ #else
1098
+ uniforms.vReflectionInfos.y
1099
+ #endif
1100
+ );
1101
+ #else
1102
+ 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,
1103
+ #ifdef AREALIGHTNOROUGHTNESS
1104
+ 0.5
1105
+ #else
1106
+ uniforms.vReflectionInfos.y
1107
+ #endif
1108
+ );
1109
+ #endif
1110
+ #elif defined(CLUSTLIGHT{X})
1111
+ {let sliceIndex=min(getClusteredSliceIndex(light{X}.vSliceData,fragmentInputs.vViewDepth),CLUSTLIGHT_SLICES-1);info=computeClusteredLighting(lightDataTexture{X},&tileMaskBuffer{X},viewDirectionW,normalW,light{X}.vLightData,vec2u(light{X}.vSliceRanges[sliceIndex].xy),glossiness);}
1112
+ #endif
1113
+ #endif
1114
+ #ifdef PROJECTEDLIGHTTEXTURE{X}
1115
+ info.diffuse*=computeProjectionTextureDiffuseLighting(projectionLightTexture{X},projectionLightTexture{X}Sampler,uniforms.textureProjectionMatrix{X},fragmentInputs.vPositionW);
1116
+ #endif
1117
+ #endif
1118
+ #ifdef SHADOW{X}
1119
+ #ifdef SHADOWCSMDEBUG{X}
1120
+ var shadowDebug{X}: vec3f;
1121
+ #endif
1122
+ #ifdef SHADOWCSM{X}
1123
+ #ifdef SHADOWCSMUSESHADOWMAXZ{X}
1124
+ var index{X}: i32=-1;
1125
+ #else
1126
+ var index{X}: i32=SHADOWCSMNUM_CASCADES{X}-1;
1127
+ #endif
1128
+ 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++)
1129
+ {
1130
+ #ifdef SHADOWCSM_RIGHTHANDED{X}
1131
+ diff{X}=uniforms.viewFrustumZ{X}[i]+fragmentInputs.vPositionFromCamera{X}.z;
1132
+ #else
1133
+ diff{X}=uniforms.viewFrustumZ{X}[i]-fragmentInputs.vPositionFromCamera{X}.z;
1134
+ #endif
1135
+ if (diff{X}>=0.) {index{X}=i;break;}}
1136
+ #ifdef SHADOWCSMUSESHADOWMAXZ{X}
1137
+ if (index{X}>=0)
1138
+ #endif
1139
+ {
1140
+ #if defined(SHADOWPCF{X})
1141
+ #if defined(SHADOWLOWQUALITY{X})
1142
+ 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);
1143
+ #elif defined(SHADOWMEDIUMQUALITY{X})
1144
+ 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);
1145
+ #else
1146
+ 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);
1147
+ #endif
1148
+ #elif defined(SHADOWPCSS{X})
1149
+ #if defined(SHADOWLOWQUALITY{X})
1150
+ 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});
1151
+ #elif defined(SHADOWMEDIUMQUALITY{X})
1152
+ 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});
1153
+ #else
1154
+ 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});
1155
+ #endif
1156
+ #else
1157
+ 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);
1158
+ #endif
1159
+ #ifdef SHADOWCSMDEBUG{X}
1160
+ shadowDebug{X}=vec3f(shadow)*vCascadeColorsMultiplier{X}[index{X}];
1161
+ #endif
1162
+ #ifndef SHADOWCSMNOBLEND{X}
1163
+ 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.)
1164
+ {index{X}+=1;var nextShadow: f32=0.;
1165
+ #if defined(SHADOWPCF{X})
1166
+ #if defined(SHADOWLOWQUALITY{X})
1167
+ nextShadow=computeShadowWithCSMPCF1(index{X},vPositionFromLight{X}[index{X}],vDepthMetric{X}[index{X}],,shadowTexture{X}Sampler,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
1168
+ #elif defined(SHADOWMEDIUMQUALITY{X})
1169
+ 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);
1170
+ #else
1171
+ 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);
1172
+ #endif
1173
+ #elif defined(SHADOWPCSS{X})
1174
+ #if defined(SHADOWLOWQUALITY{X})
1175
+ 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});
1176
+ #elif defined(SHADOWMEDIUMQUALITY{X})
1177
+ 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});
1178
+ #else
1179
+ 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});
1180
+ #endif
1181
+ #else
1182
+ 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);
1183
+ #endif
1184
+ shadow=mix(nextShadow,shadow,diffRatio);
1185
+ #ifdef SHADOWCSMDEBUG{X}
1186
+ shadowDebug{X}=mix(vec3(nextShadow)*vCascadeColorsMultiplier{X}[index{X}],shadowDebug{X},diffRatio);
1187
+ #endif
1188
+ }
1189
+ #endif
1190
+ }
1191
+ #elif defined(SHADOWCLOSEESM{X})
1192
+ #if defined(SHADOWCUBE{X})
1193
+ shadow=computeShadowWithCloseESMCube(fragmentInputs.vPositionW,light{X}.vLightData.xyz,shadowTexture{X},shadowTexture{X}Sampler,light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);
1194
+ #else
1195
+ 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);
1196
+ #endif
1197
+ #elif defined(SHADOWESM{X})
1198
+ #if defined(SHADOWCUBE{X})
1199
+ shadow=computeShadowWithESMCube(fragmentInputs.vPositionW,light{X}.vLightData.xyz,shadowTexture{X},shadowTexture{X}Sampler,light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);
1200
+ #else
1201
+ 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);
1202
+ #endif
1203
+ #elif defined(SHADOWPOISSON{X})
1204
+ #if defined(SHADOWCUBE{X})
1205
+ shadow=computeShadowWithPoissonSamplingCube(fragmentInputs.vPositionW,light{X}.vLightData.xyz,shadowTexture{X},shadowTexture{X}Sampler,light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.depthValues);
1206
+ #else
1207
+ 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);
1208
+ #endif
1209
+ #elif defined(SHADOWPCF{X})
1210
+ #if defined(SHADOWLOWQUALITY{X})
1211
+ shadow=computeShadowWithPCF1(fragmentInputs.vPositionFromLight{X},fragmentInputs.vDepthMetric{X},shadowTexture{X},shadowTexture{X}Sampler,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
1212
+ #elif defined(SHADOWMEDIUMQUALITY{X})
1213
+ 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);
1214
+ #else
1215
+ 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);
1216
+ #endif
1217
+ #elif defined(SHADOWPCSS{X})
1218
+ #if defined(SHADOWLOWQUALITY{X})
1219
+ 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);
1220
+ #elif defined(SHADOWMEDIUMQUALITY{X})
1221
+ 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);
1222
+ #else
1223
+ 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);
1224
+ #endif
1225
+ #else
1226
+ #if defined(SHADOWCUBE{X})
1227
+ shadow=computeShadowCube(fragmentInputs.vPositionW,light{X}.vLightData.xyz,shadowTexture{X},shadowTexture{X}Sampler,light{X}.shadowsInfo.x,light{X}.depthValues);
1228
+ #else
1229
+ shadow=computeShadow(fragmentInputs.vPositionFromLight{X},fragmentInputs.vDepthMetric{X},shadowTexture{X},shadowTexture{X}Sampler,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);
1230
+ #endif
1231
+ #endif
1232
+ #ifdef SHADOWONLY
1233
+ #ifndef SHADOWINUSE
1234
+ #define SHADOWINUSE
1235
+ #endif
1236
+ globalShadow+=shadow;shadowLightCount+=1.0;
1237
+ #endif
1238
+ #else
1239
+ shadow=1.;
1240
+ #endif
1241
+ aggShadow+=shadow;numLights+=1.0;
1242
+ #ifndef SHADOWONLY
1243
+ #ifdef CUSTOMUSERLIGHTING
1244
+ diffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);
1245
+ #ifdef SPECULARTERM
1246
+ specularBase+=computeCustomSpecularLighting(info,specularBase,shadow);
1247
+ #endif
1248
+ #elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X})
1249
+ diffuseBase+=lightmapColor.rgb*shadow;
1250
+ #ifdef SPECULARTERM
1251
+ #ifndef LIGHTMAPNOSPECULAR{X}
1252
+ specularBase+=info.specular*shadow*lightmapColor.rgb;
1253
+ #endif
1254
+ #endif
1255
+ #ifdef CLEARCOAT
1256
+ #ifndef LIGHTMAPNOSPECULAR{X}
1257
+ clearCoatBase+=info.clearCoat.rgb*shadow*lightmapColor.rgb;
1258
+ #endif
1259
+ #endif
1260
+ #ifdef SHEEN
1261
+ #ifndef LIGHTMAPNOSPECULAR{X}
1262
+ sheenBase+=info.sheen.rgb*shadow;
1263
+ #endif
1264
+ #endif
1265
+ #else
1266
+ #ifdef SHADOWCSMDEBUG{X}
1267
+ diffuseBase+=info.diffuse*shadowDebug{X};
1268
+ #else
1269
+ diffuseBase+=info.diffuse*shadow;
1270
+ #endif
1271
+ #ifdef SS_TRANSLUCENCY
1272
+ diffuseTransmissionBase+=info.diffuseTransmission*shadow;
1273
+ #endif
1274
+ #ifdef SPECULARTERM
1275
+ specularBase+=info.specular*shadow;
1276
+ #endif
1277
+ #ifdef CLEARCOAT
1278
+ clearCoatBase+=info.clearCoat.rgb*shadow;
1279
+ #endif
1280
+ #ifdef SHEEN
1281
+ sheenBase+=info.sheen.rgb*shadow;
1282
+ #endif
1283
+ #endif
1284
+ #endif
1285
+ #endif
1286
+ `;r.ShaderStore.IncludesShadersStoreWGSL[q]||(r.ShaderStore.IncludesShadersStoreWGSL[q]=j);let Z="logDepthFragment",Q=`#ifdef LOGARITHMICDEPTH
1287
+ fragmentOutputs.fragDepth=log2(fragmentInputs.vFragmentDepth)*uniforms.logarithmicDepthConstant*0.5;
1288
+ #endif
1289
+ `;r.ShaderStore.IncludesShadersStoreWGSL[Z]||(r.ShaderStore.IncludesShadersStoreWGSL[Z]=Q);var J=e.i(31213);let K="oitFragment",$=`#ifdef ORDER_INDEPENDENT_TRANSPARENCY
1290
+ var fragDepth: f32=fragmentInputs.position.z;
1291
+ #ifdef ORDER_INDEPENDENT_TRANSPARENCY_16BITS
1292
+ var halfFloat: u32=pack2x16float( vec2f(fragDepth));var full: vec2f=unpack2x16float(halfFloat);fragDepth=full.x;
1293
+ #endif
1294
+ 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);
1295
+ #ifdef USE_REVERSE_DEPTHBUFFER
1296
+ var furthestDepth: f32=-lastDepth.x;var nearestDepth: f32=lastDepth.y;
1297
+ #else
1298
+ var nearestDepth: f32=-lastDepth.x;var furthestDepth: f32=lastDepth.y;
1299
+ #endif
1300
+ var alphaMultiplier: f32=1.0-lastFrontColor.a;
1301
+ #ifdef USE_REVERSE_DEPTHBUFFER
1302
+ if (fragDepth>nearestDepth || fragDepth<furthestDepth) {
1303
+ #else
1304
+ if (fragDepth<nearestDepth || fragDepth>furthestDepth) {
1305
+ #endif
1306
+ return fragmentOutputs;}
1307
+ #ifdef USE_REVERSE_DEPTHBUFFER
1308
+ if (fragDepth<nearestDepth && fragDepth>furthestDepth) {
1309
+ #else
1310
+ if (fragDepth>nearestDepth && fragDepth<furthestDepth) {
1311
+ #endif
1312
+ fragmentOutputs.depth=vec2f(-fragDepth,fragDepth);return fragmentOutputs;}
1313
+ #endif
1314
+ `;r.ShaderStore.IncludesShadersStoreWGSL[K]||(r.ShaderStore.IncludesShadersStoreWGSL[K]=$);let ee="defaultPixelShader",er=`#include<defaultUboDeclaration>
1315
+ #include<prePassDeclaration>[SCENE_MRT_COUNT]
1316
+ #include<oitDeclaration>
1317
+ #define CUSTOM_FRAGMENT_BEGIN
1318
+ varying vPositionW: vec3f;
1319
+ #ifdef NORMAL
1320
+ varying vNormalW: vec3f;
1321
+ #endif
1322
+ #if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)
1323
+ varying vColor: vec4f;
1324
+ #endif
1325
+ #if defined(CLUSTLIGHT_BATCH) && CLUSTLIGHT_BATCH>0
1326
+ varying vViewDepth: f32;
1327
+ #endif
1328
+ #include<mainUVVaryingDeclaration>[1..7]
1329
+ #include<helperFunctions>
1330
+ #include<lightUboDeclaration>[0..maxSimultaneousLights]
1331
+ #include<lightsFragmentFunctions>
1332
+ #include<shadowsFragmentFunctions>
1333
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,DIFFUSE,_VARYINGNAME_,Diffuse,_SAMPLERNAME_,diffuse)
1334
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient,_SAMPLERNAME_,ambient)
1335
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity,_SAMPLERNAME_,opacity)
1336
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive,_SAMPLERNAME_,emissive)
1337
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap,_SAMPLERNAME_,lightmap)
1338
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal,_SAMPLERNAME_,decal)
1339
+ #ifdef REFRACTION
1340
+ #ifdef REFRACTIONMAP_3D
1341
+ var refractionCubeSamplerSampler: sampler;var refractionCubeSampler: texture_cube<f32>;
1342
+ #else
1343
+ var refraction2DSamplerSampler: sampler;var refraction2DSampler: texture_2d<f32>;
1344
+ #endif
1345
+ #endif
1346
+ #if defined(SPECULARTERM)
1347
+ #include<samplerFragmentDeclaration>(_DEFINENAME_,SPECULAR,_VARYINGNAME_,Specular,_SAMPLERNAME_,specular)
1348
+ #endif
1349
+ #include<fresnelFunction>
1350
+ #ifdef REFLECTION
1351
+ #ifdef REFLECTIONMAP_3D
1352
+ var reflectionCubeSamplerSampler: sampler;var reflectionCubeSampler: texture_cube<f32>;
1353
+ #else
1354
+ var reflection2DSamplerSampler: sampler;var reflection2DSampler: texture_2d<f32>;
1355
+ #endif
1356
+ #ifdef REFLECTIONMAP_SKYBOX
1357
+ varying vPositionUVW: vec3f;
1358
+ #else
1359
+ #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)
1360
+ varying vDirectionW: vec3f;
1361
+ #endif
1362
+ #endif
1363
+ #include<reflectionFunction>
1364
+ #endif
1365
+ #include<imageProcessingDeclaration>
1366
+ #include<imageProcessingFunctions>
1367
+ #include<textureRepetitionFunctions>
1368
+ #include<bumpFragmentMainFunctions>
1369
+ #include<bumpFragmentFunctions>
1370
+ #include<clipPlaneFragmentDeclaration>
1371
+ #include<logDepthDeclaration>
1372
+ #include<fogFragmentDeclaration>
1373
+ #define CUSTOM_FRAGMENT_DEFINITIONS
1374
+ @fragment
1375
+ fn main(input: FragmentInputs)->FragmentOutputs {
1376
+ #define CUSTOM_FRAGMENT_MAIN_BEGIN
1377
+ #include<clipPlaneFragment>
1378
+ var viewDirectionW: vec3f=normalize(scene.vEyePosition.xyz-fragmentInputs.vPositionW);var baseColor: vec4f= vec4f(1.,1.,1.,1.);var diffuseColor: vec3f=uniforms.vDiffuseColor.rgb;var alpha: f32=uniforms.vDiffuseColor.a;
1379
+ #ifdef NORMAL
1380
+ var normalW: vec3f=normalize(fragmentInputs.vNormalW);
1381
+ #else
1382
+ var normalW: vec3f=normalize(cross(dpdx(fragmentInputs.vPositionW),dpdy(fragmentInputs.vPositionW)))* scene.vEyePosition.w;
1383
+ #endif
1384
+ #include<bumpFragment>
1385
+ #ifdef TWOSIDEDLIGHTING
1386
+ normalW=select(-normalW,normalW,fragmentInputs.frontFacing);
1387
+ #endif
1388
+ #ifdef DIFFUSE
1389
+ baseColor=TEXRD(diffuseSampler,diffuseSamplerSampler,fragmentInputs.vDiffuseUV+uvOffset);
1390
+ #if defined(ALPHATEST) && !defined(ALPHATEST_AFTERALLALPHACOMPUTATIONS)
1391
+ if (baseColor.a<uniforms.alphaCutOff) {discard;}
1392
+ #endif
1393
+ #ifdef ALPHAFROMDIFFUSE
1394
+ alpha*=baseColor.a;
1395
+ #endif
1396
+ #define CUSTOM_FRAGMENT_UPDATE_ALPHA
1397
+ baseColor=vec4f(baseColor.rgb*uniforms.vDiffuseInfos.y,baseColor.a);
1398
+ #endif
1399
+ #if defined(DECAL) && !defined(DECAL_AFTER_DETAIL)
1400
+ var decalColor: vec4f=textureSample(decalSampler,decalSamplerSampler,fragmentInputs.vDecalUV+uvOffset);
1401
+ #include<decalFragment>(surfaceAlbedo,baseColor,GAMMADECAL,_GAMMADECAL_NOTUSED_)
1402
+ #endif
1403
+ #include<depthPrePass>
1404
+ #if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)
1405
+ baseColor=vec4f(baseColor.rgb*fragmentInputs.vColor.rgb,baseColor.a);
1406
+ #endif
1407
+ #ifdef DETAIL
1408
+ baseColor=vec4f(baseColor.rgb*2.0*mix(0.5,detailColor.r,uniforms.vDetailInfos.y),baseColor.a);
1409
+ #endif
1410
+ #if defined(DECAL) && defined(DECAL_AFTER_DETAIL)
1411
+ var decalColor: vec4f=textureSample(decalSampler,decalSamplerSampler,fragmentInputs.vDecalUV+uvOffset);
1412
+ #include<decalFragment>(surfaceAlbedo,baseColor,GAMMADECAL,_GAMMADECAL_NOTUSED_)
1413
+ #endif
1414
+ #define CUSTOM_FRAGMENT_UPDATE_DIFFUSE
1415
+ var baseAmbientColor: vec3f= vec3f(1.,1.,1.);
1416
+ #ifdef AMBIENT
1417
+ baseAmbientColor=TEXRD(ambientSampler,ambientSamplerSampler,fragmentInputs.vAmbientUV+uvOffset).rgb*uniforms.vAmbientInfos.y;
1418
+ #endif
1419
+ #define CUSTOM_FRAGMENT_BEFORE_LIGHTS
1420
+ var glossiness: f32=uniforms.vSpecularColor.a;var specularColor: vec3f=uniforms.vSpecularColor.rgb;
1421
+ #ifdef SPECULARTERM
1422
+ #ifdef SPECULAR
1423
+ var specularMapColor: vec4f=TEXRD(specularSampler,specularSamplerSampler,fragmentInputs.vSpecularUV+uvOffset);specularColor=specularMapColor.rgb;
1424
+ #ifdef GLOSSINESS
1425
+ glossiness=glossiness*specularMapColor.a;
1426
+ #endif
1427
+ #endif
1428
+ #endif
1429
+ var diffuseBase: vec3f= vec3f(0.,0.,0.);var info: lightingInfo;
1430
+ #ifdef SPECULARTERM
1431
+ var specularBase: vec3f= vec3f(0.,0.,0.);
1432
+ #endif
1433
+ var shadow: f32=1.;var aggShadow: f32=0.;var numLights: f32=0.;
1434
+ #ifdef LIGHTMAP
1435
+ var lightmapColor: vec4f=TEXRD(lightmapSampler,lightmapSamplerSampler,fragmentInputs.vLightmapUV+uvOffset);
1436
+ #ifdef RGBDLIGHTMAP
1437
+ lightmapColor=vec4f(fromRGBD(lightmapColor),lightmapColor.a);
1438
+ #endif
1439
+ lightmapColor=vec4f(lightmapColor.rgb*uniforms.vLightmapInfos.y,lightmapColor.a);
1440
+ #endif
1441
+ #include<lightFragment>[0..maxSimultaneousLights]
1442
+ aggShadow=aggShadow/numLights;var refractionColor: vec4f= vec4f(0.,0.,0.,1.);
1443
+ #ifdef REFRACTION
1444
+ var refractionVector: vec3f=normalize(refract(-viewDirectionW,normalW,uniforms.vRefractionInfos.y));
1445
+ #ifdef REFRACTIONMAP_3D
1446
+ #ifdef USE_LOCAL_REFRACTIONMAP_CUBIC
1447
+ refractionVector=parallaxCorrectNormal(fragmentInputs.vPositionW,refractionVector,uniforms.vRefractionSize,uniforms.vRefractionPosition);
1448
+ #endif
1449
+ refractionVector.y=refractionVector.y*uniforms.vRefractionInfos.w;var refractionLookup: vec4f=textureSample(refractionCubeSampler,refractionCubeSamplerSampler,refractionVector);if (dot(refractionVector,viewDirectionW)<1.0) {refractionColor=refractionLookup;}
1450
+ #else
1451
+ var vRefractionUVW: vec3f= (uniforms.refractionMatrix*(scene.view* vec4f(fragmentInputs.vPositionW+refractionVector*uniforms.vRefractionInfos.z,1.0))).xyz;var refractionCoords: vec2f=vRefractionUVW.xy/vRefractionUVW.z;refractionCoords.y=1.0-refractionCoords.y;refractionColor=textureSample(refraction2DSampler,refraction2DSamplerSampler,refractionCoords);
1452
+ #endif
1453
+ #ifdef RGBDREFRACTION
1454
+ refractionColor=vec4f(fromRGBD(refractionColor),refractionColor.a);
1455
+ #endif
1456
+ #ifdef IS_REFRACTION_LINEAR
1457
+ refractionColor=vec4f(toGammaSpaceVec3(refractionColor.rgb),refractionColor.a);
1458
+ #endif
1459
+ refractionColor=vec4f(refractionColor.rgb*uniforms.vRefractionInfos.x,refractionColor.a);
1460
+ #endif
1461
+ var reflectionColor: vec4f= vec4f(0.,0.,0.,1.);
1462
+ #ifdef REFLECTION
1463
+ var vReflectionUVW: vec3f=computeReflectionCoords( vec4f(fragmentInputs.vPositionW,1.0),normalW);
1464
+ #ifdef REFLECTIONMAP_OPPOSITEZ
1465
+ vReflectionUVW=vec3f(vReflectionUVW.x,vReflectionUVW.y,vReflectionUVW.z*-1.0);
1466
+ #endif
1467
+ #ifdef REFLECTIONMAP_3D
1468
+ #ifdef ROUGHNESS
1469
+ var bias: f32=uniforms.vReflectionInfos.y;
1470
+ #ifdef SPECULARTERM
1471
+ #ifdef SPECULAR
1472
+ #ifdef GLOSSINESS
1473
+ bias*=(1.0-specularMapColor.a);
1474
+ #endif
1475
+ #endif
1476
+ #endif
1477
+ reflectionColor=textureSampleLevel(reflectionCubeSampler,reflectionCubeSamplerSampler,vReflectionUVW,bias);
1478
+ #else
1479
+ reflectionColor=textureSample(reflectionCubeSampler,reflectionCubeSamplerSampler,vReflectionUVW);
1480
+ #endif
1481
+ #else
1482
+ var coords: vec2f=vReflectionUVW.xy;
1483
+ #ifdef REFLECTIONMAP_PROJECTION
1484
+ coords/=vReflectionUVW.z;
1485
+ #endif
1486
+ coords.y=1.0-coords.y;reflectionColor=textureSample(reflection2DSampler,reflection2DSamplerSampler,coords);
1487
+ #endif
1488
+ #ifdef RGBDREFLECTION
1489
+ reflectionColor=vec4f(fromRGBD(reflectionColor),reflectionColor.a);
1490
+ #endif
1491
+ #ifdef IS_REFLECTION_LINEAR
1492
+ reflectionColor=vec4f(toGammaSpaceVec3(reflectionColor.rgb),reflectionColor.a);
1493
+ #endif
1494
+ reflectionColor=vec4f(reflectionColor.rgb*uniforms.vReflectionInfos.x,reflectionColor.a);
1495
+ #ifdef REFLECTIONFRESNEL
1496
+ var reflectionFresnelTerm: f32=computeFresnelTerm(viewDirectionW,normalW,uniforms.reflectionRightColor.a,uniforms.reflectionLeftColor.a);
1497
+ #ifdef REFLECTIONFRESNELFROMSPECULAR
1498
+ #ifdef SPECULARTERM
1499
+ reflectionColor=vec4f(reflectionColor.rgb*specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*uniforms.reflectionRightColor.rgb,reflectionColor.a);
1500
+ #else
1501
+ reflectionColor=vec4f(reflectionColor.rgb*uniforms.reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*uniforms.reflectionRightColor.rgb,reflectionColor.a);
1502
+ #endif
1503
+ #else
1504
+ reflectionColor=vec4f(reflectionColor.rgb*uniforms.reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*uniforms.reflectionRightColor.rgb,reflectionColor.a);
1505
+ #endif
1506
+ #endif
1507
+ #endif
1508
+ #ifdef REFRACTIONFRESNEL
1509
+ var refractionFresnelTerm: f32=computeFresnelTerm(viewDirectionW,normalW,uniforms.refractionRightColor.a,uniforms.refractionLeftColor.a);refractionColor=vec4f(refractionColor.rgb*uniforms.refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*uniforms.refractionRightColor.rgb,refractionColor.a);
1510
+ #endif
1511
+ #ifdef OPACITY
1512
+ var opacityMap: vec4f=TEXRD(opacitySampler,opacitySamplerSampler,fragmentInputs.vOpacityUV+uvOffset);
1513
+ #ifdef OPACITYRGB
1514
+ opacityMap=vec4f(opacityMap.rgb* vec3f(0.3,0.59,0.11),opacityMap.a);alpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* uniforms.vOpacityInfos.y;
1515
+ #else
1516
+ alpha*=opacityMap.a*uniforms.vOpacityInfos.y;
1517
+ #endif
1518
+ #endif
1519
+ #if defined(VERTEXALPHA) || defined(INSTANCESCOLOR) && defined(INSTANCES)
1520
+ alpha*=fragmentInputs.vColor.a;
1521
+ #endif
1522
+ #ifdef OPACITYFRESNEL
1523
+ var opacityFresnelTerm: f32=computeFresnelTerm(viewDirectionW,normalW,uniforms.opacityParts.z,uniforms.opacityParts.w);alpha+=uniforms.opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*uniforms.opacityParts.y;
1524
+ #endif
1525
+ #ifdef ALPHATEST
1526
+ #ifdef ALPHATEST_AFTERALLALPHACOMPUTATIONS
1527
+ if (alpha<uniforms.alphaCutOff) {discard;}
1528
+ #endif
1529
+ #ifndef ALPHABLEND
1530
+ alpha=1.0;
1531
+ #endif
1532
+ #endif
1533
+ var emissiveColor: vec3f=uniforms.vEmissiveColor;
1534
+ #ifdef EMISSIVE
1535
+ emissiveColor+=TEXRD(emissiveSampler,emissiveSamplerSampler,fragmentInputs.vEmissiveUV+uvOffset).rgb*uniforms.vEmissiveInfos.y;
1536
+ #endif
1537
+ #ifdef EMISSIVEFRESNEL
1538
+ var emissiveFresnelTerm: f32=computeFresnelTerm(viewDirectionW,normalW,uniforms.emissiveRightColor.a,uniforms.emissiveLeftColor.a);emissiveColor*=uniforms.emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*uniforms.emissiveRightColor.rgb;
1539
+ #endif
1540
+ #ifdef DIFFUSEFRESNEL
1541
+ var diffuseFresnelTerm: f32=computeFresnelTerm(viewDirectionW,normalW,uniforms.diffuseRightColor.a,uniforms.diffuseLeftColor.a);diffuseBase*=uniforms.diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*uniforms.diffuseRightColor.rgb;
1542
+ #endif
1543
+ #ifdef EMISSIVEASILLUMINATION
1544
+ var finalDiffuse: vec3f=clamp(diffuseBase*diffuseColor+uniforms.vAmbientColor,vec3f(0.0),vec3f(1.0))*baseColor.rgb;
1545
+ #else
1546
+ #ifdef LINKEMISSIVEWITHDIFFUSE
1547
+ var finalDiffuse: vec3f=clamp((diffuseBase+emissiveColor)*diffuseColor+uniforms.vAmbientColor,vec3f(0.0),vec3f(1.0))*baseColor.rgb;
1548
+ #else
1549
+ var finalDiffuse: vec3f=clamp(diffuseBase*diffuseColor+emissiveColor+uniforms.vAmbientColor,vec3f(0.0),vec3f(1.0))*baseColor.rgb;
1550
+ #endif
1551
+ #endif
1552
+ #ifdef SPECULARTERM
1553
+ var finalSpecular: vec3f=specularBase*specularColor;
1554
+ #ifdef SPECULAROVERALPHA
1555
+ alpha=clamp(alpha+dot(finalSpecular, vec3f(0.3,0.59,0.11)),0.0,1.0);
1556
+ #endif
1557
+ #else
1558
+ var finalSpecular: vec3f= vec3f(0.0);
1559
+ #endif
1560
+ #ifdef REFLECTIONOVERALPHA
1561
+ alpha=clamp(alpha+dot(reflectionColor.rgb, vec3f(0.3,0.59,0.11)),0.0,1.0);
1562
+ #endif
1563
+ #ifdef EMISSIVEASILLUMINATION
1564
+ var color: vec4f= vec4f(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor.rgb+emissiveColor+refractionColor.rgb,vec3f(0.0),vec3f(1.0)),alpha);
1565
+ #else
1566
+ var color: vec4f= vec4f(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor.rgb+refractionColor.rgb,alpha);
1567
+ #endif
1568
+ #ifdef LIGHTMAP
1569
+ #ifndef LIGHTMAPEXCLUDED
1570
+ #ifdef USELIGHTMAPASSHADOWMAP
1571
+ color=vec4f(color.rgb*lightmapColor.rgb,color.a);
1572
+ #else
1573
+ color=vec4f(color.rgb+lightmapColor.rgb,color.a);
1574
+ #endif
1575
+ #endif
1576
+ #endif
1577
+ #define CUSTOM_FRAGMENT_BEFORE_FOG
1578
+ color=vec4f(max(color.rgb,vec3f(0.)),color.a);
1579
+ #include<logDepthFragment>
1580
+ #include<fogFragment>
1581
+ #ifdef IMAGEPROCESSINGPOSTPROCESS
1582
+ color=vec4f(toLinearSpaceVec3(color.rgb),color.a);
1583
+ #else
1584
+ #ifdef IMAGEPROCESSING
1585
+ color=vec4f(toLinearSpaceVec3(color.rgb),color.a);color=applyImageProcessing(color);
1586
+ #endif
1587
+ #endif
1588
+ color=vec4f(color.rgb,color.a*mesh.visibility);
1589
+ #ifdef PREMULTIPLYALPHA
1590
+ color=vec4f(color.rgb*color.a, color.a);
1591
+ #endif
1592
+ #define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR
1593
+ #ifdef PREPASS
1594
+ #if SCENE_MRT_COUNT>0
1595
+ var writeGeometryInfo: f32=select(0.0,1.0,color.a>0.4);var fragData: array<vec4<f32>,SCENE_MRT_COUNT>;
1596
+ #ifdef PREPASS_COLOR
1597
+ fragData[PREPASS_COLOR_INDEX]=color;
1598
+ #endif
1599
+ #ifdef PREPASS_POSITION
1600
+ fragData[PREPASS_POSITION_INDEX]=vec4f(fragmentInputs.vPositionW,writeGeometryInfo);
1601
+ #endif
1602
+ #ifdef PREPASS_LOCAL_POSITION
1603
+ fragData[PREPASS_LOCAL_POSITION_INDEX]=vec4f(fragmentInputs.vPosition,writeGeometryInfo);
1604
+ #endif
1605
+ #ifdef PREPASS_VELOCITY
1606
+ var a: vec2f=(fragmentInputs.vCurrentPosition.xy/fragmentInputs.vCurrentPosition.w)*0.5+0.5;var b: vec2f=(fragmentInputs.vPreviousPosition.xy/fragmentInputs.vPreviousPosition.w)*0.5+0.5;var velocity: vec2f=abs(a-b);velocity= vec2f(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;fragData[PREPASS_VELOCITY_INDEX]= vec4f(velocity,0.0,writeGeometryInfo);
1607
+ #elif defined(PREPASS_VELOCITY_LINEAR)
1608
+ var velocity : vec2f=vec2f(0.5)*((fragmentInputs.vPreviousPosition.xy/fragmentInputs.vPreviousPosition.w) -
1609
+ (fragmentInputs.vCurrentPosition.xy/fragmentInputs.vCurrentPosition.w));fragData[PREPASS_VELOCITY_LINEAR_INDEX]=vec4f(velocity,0.0,writeGeometryInfo);
1610
+ #endif
1611
+ #ifdef PREPASS_IRRADIANCE
1612
+ fragData[PREPASS_IRRADIANCE_INDEX]=vec4f(0.0,0.0,0.0,writeGeometryInfo);
1613
+ #endif
1614
+ #ifdef PREPASS_DEPTH
1615
+ fragData[PREPASS_DEPTH_INDEX]=vec4f(fragmentInputs.vViewPos.z,0.0,0.0,writeGeometryInfo);
1616
+ #endif
1617
+ #ifdef PREPASS_SCREENSPACE_DEPTH
1618
+ fragData[PREPASS_SCREENSPACE_DEPTH_INDEX]=vec4f(fragmentInputs.position.z,0.0,0.0,writeGeometryInfo);
1619
+ #endif
1620
+ #ifdef PREPASS_NORMALIZED_VIEW_DEPTH
1621
+ fragData[PREPASS_NORMALIZED_VIEW_DEPTH_INDEX]=vec4f(fragmentInputs.vNormViewDepth,0.0,0.0,writeGeometryInfo);
1622
+ #endif
1623
+ #ifdef PREPASS_NORMAL
1624
+ #ifdef PREPASS_NORMAL_WORLDSPACE
1625
+ fragData[PREPASS_NORMAL_INDEX]=vec4f(normalW,writeGeometryInfo);
1626
+ #else
1627
+ fragData[PREPASS_NORMAL_INDEX]=vec4f(normalize((scene.view*vec4f(normalW,0.0)).rgb),writeGeometryInfo);
1628
+ #endif
1629
+ #endif
1630
+ #ifdef PREPASS_WORLD_NORMAL
1631
+ fragData[PREPASS_WORLD_NORMAL_INDEX]=vec4f(normalW*0.5+0.5,writeGeometryInfo);
1632
+ #endif
1633
+ #ifdef PREPASS_ALBEDO
1634
+ fragData[PREPASS_ALBEDO_INDEX]=vec4f(baseColor.rgb,writeGeometryInfo);
1635
+ #endif
1636
+ #ifdef PREPASS_ALBEDO_SQRT
1637
+ fragData[PREPASS_ALBEDO_SQRT_INDEX]=vec4f(sqrt(baseColor.rgb),writeGeometryInfo);
1638
+ #endif
1639
+ #ifdef PREPASS_REFLECTIVITY
1640
+ #if defined(SPECULAR)
1641
+ fragData[PREPASS_REFLECTIVITY_INDEX]=vec4f(toLinearSpaceVec4(specularMapColor))*writeGeometryInfo;
1642
+ #else
1643
+ fragData[PREPASS_REFLECTIVITY_INDEX]=vec4f(toLinearSpaceVec3(specularColor),1.0)*writeGeometryInfo;
1644
+ #endif
1645
+ #endif
1646
+ #if SCENE_MRT_COUNT>0
1647
+ fragmentOutputs.fragData0=fragData[0];
1648
+ #endif
1649
+ #if SCENE_MRT_COUNT>1
1650
+ fragmentOutputs.fragData1=fragData[1];
1651
+ #endif
1652
+ #if SCENE_MRT_COUNT>2
1653
+ fragmentOutputs.fragData2=fragData[2];
1654
+ #endif
1655
+ #if SCENE_MRT_COUNT>3
1656
+ fragmentOutputs.fragData3=fragData[3];
1657
+ #endif
1658
+ #if SCENE_MRT_COUNT>4
1659
+ fragmentOutputs.fragData4=fragData[4];
1660
+ #endif
1661
+ #if SCENE_MRT_COUNT>5
1662
+ fragmentOutputs.fragData5=fragData[5];
1663
+ #endif
1664
+ #if SCENE_MRT_COUNT>6
1665
+ fragmentOutputs.fragData6=fragData[6];
1666
+ #endif
1667
+ #if SCENE_MRT_COUNT>7
1668
+ fragmentOutputs.fragData7=fragData[7];
1669
+ #endif
1670
+ #endif
1671
+ #endif
1672
+ #if !defined(PREPASS) && !defined(ORDER_INDEPENDENT_TRANSPARENCY)
1673
+ fragmentOutputs.color=color;
1674
+ #endif
1675
+ #include<oitFragment>
1676
+ #if ORDER_INDEPENDENT_TRANSPARENCY
1677
+ if (fragDepth==nearestDepth) {fragmentOutputs.frontColor=vec4f(fragmentOutputs.frontColor.rgb+color.rgb*color.a*alphaMultiplier,1.0-alphaMultiplier*(1.0-color.a));} else {fragmentOutputs.backColor+=color;}
1678
+ #endif
1679
+ #define CUSTOM_FRAGMENT_MAIN_END
1680
+ }
1681
+ `;for(let e of(r.ShaderStore.ShadersStoreWGSL[ee]||(r.ShaderStore.ShadersStoreWGSL[ee]=er),[t.sceneUboDeclarationWGSL,a.meshUboDeclarationWGSL,i.defaultUboDeclarationWGSL,{name:o,shader:f},{name:n,shader:s},l.mainUVVaryingDeclarationWGSL,d.helperFunctionsWGSL,{name:c,shader:v},{name:u,shader:p},{name:h,shader:m},{name:S,shader:g},{name:x,shader:T},{name:L,shader:C},{name:w,shader:E},{name:I,shader:D},{name:A,shader:P},{name:X,shader:R},{name:_,shader:y},{name:N,shader:M},{name:F,shader:O},b.clipPlaneFragmentDeclarationWGSL,W.logDepthDeclarationWGSL,z.fogFragmentDeclarationWGSL,U.clipPlaneFragmentWGSL,{name:G,shader:H},{name:V,shader:k},{name:B,shader:Y},{name:q,shader:j},{name:Z,shader:Q},J.fogFragmentWGSL,{name:K,shader:$}]))r.ShaderStore.IncludesShadersStoreWGSL[e.name]||(r.ShaderStore.IncludesShadersStoreWGSL[e.name]=e.shader);e.s(["defaultPixelShaderWGSL",0,{name:ee,shader:er}],26022)}]);