grimoire3d 0.4.2-dev.9f981f8 → 0.4.3-dev.8c28b9a

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 (119) hide show
  1. package/README.md +20 -0
  2. package/cli/cli.js +278 -22
  3. package/cli/content.js +9 -6
  4. package/cli/hall.d.ts +64 -0
  5. package/cli/hall.js +434 -0
  6. package/dist/grimoire3d.css +1 -1
  7. package/dist/site/assets/BookReader-DLYZCDb0.js +2 -0
  8. package/dist/site/assets/BookScene-CB0xQ6fn.js +4294 -0
  9. package/dist/site/assets/DiagramViewer-DDT3S71T.js +1 -0
  10. package/dist/site/assets/MermaidDiagram-DeSJSiyr.js +44 -0
  11. package/dist/site/assets/{PageMarkdown-DHG8c6wj.js → PageMarkdown-sItyD1jV.js} +4 -4
  12. package/dist/site/assets/{SearchDialog-B5cJdpzR.js → SearchDialog-Crseb7J2.js} +1 -1
  13. package/dist/site/assets/{abnfDiagram-S7VZAUFO-DGQQP6Hx.js → abnfDiagram-S7VZAUFO-CuwDSK5b.js} +1 -1
  14. package/dist/site/assets/{architecture-WOLXFQ4H-CZRz7lc_.js → architecture-WOLXFQ4H-BVnu8Tlp.js} +1 -1
  15. package/dist/site/assets/{architectureDiagram-YGSQEFNW-Ct1UNAeB.js → architectureDiagram-YGSQEFNW-WbbYUfkP.js} +1 -1
  16. package/dist/site/assets/{blockDiagram-APKKGZFW-BLx_cuqS.js → blockDiagram-APKKGZFW-Dt6iiK7N.js} +1 -1
  17. package/dist/site/assets/{c4Diagram-KJ2TOQU5-Bt1vsn1q.js → c4Diagram-KJ2TOQU5-uWvqRmeI.js} +1 -1
  18. package/dist/site/assets/{chunk-6MUBBAK2-CQhSflBP.js → chunk-6MUBBAK2-OnlTMK5J.js} +1 -1
  19. package/dist/site/assets/{chunk-AXFCVDMN-5SOYFNpg.js → chunk-AXFCVDMN-if3C6q6i.js} +1 -1
  20. package/dist/site/assets/{chunk-BG4553SI-DfNbToKS.js → chunk-BG4553SI-CBguGRB6.js} +1 -1
  21. package/dist/site/assets/{chunk-DQASFODM-hN5Uq5eQ.js → chunk-DQASFODM-CbY9f9Q2.js} +1 -1
  22. package/dist/site/assets/{chunk-HFQBQIA3-DKSq-OZn.js → chunk-HFQBQIA3-B64Hi-Sp.js} +1 -1
  23. package/dist/site/assets/{chunk-KQLB2F66-geRXRU8E.js → chunk-KQLB2F66-CTNR99Dh.js} +1 -1
  24. package/dist/site/assets/{chunk-KS47KZWR-e065oJAA.js → chunk-KS47KZWR-CEz-NGY-.js} +1 -1
  25. package/dist/site/assets/{chunk-LEVMRMFU-Ce8sJhQg.js → chunk-LEVMRMFU-Ca35cqDC.js} +1 -1
  26. package/dist/site/assets/{chunk-M57EVK23-B10tO_gN.js → chunk-M57EVK23-B940zmy1.js} +1 -1
  27. package/dist/site/assets/{chunk-OY52VR5R-DAYXQkgB.js → chunk-OY52VR5R-B7LiRtBY.js} +1 -1
  28. package/dist/site/assets/{chunk-QB3YPZ4I-DRDpGk1k.js → chunk-QB3YPZ4I-YqGZ6son.js} +1 -1
  29. package/dist/site/assets/{chunk-R3KSYZAL-BnMYVuC_.js → chunk-R3KSYZAL-R2e4FW4_.js} +1 -1
  30. package/dist/site/assets/{chunk-STOXU5M4-AXNCz8AC.js → chunk-STOXU5M4-BL317ZCT.js} +1 -1
  31. package/dist/site/assets/{chunk-TU62E6Q5-DoiRMnwG.js → chunk-TU62E6Q5-xOdUAN_a.js} +1 -1
  32. package/dist/site/assets/{chunk-X4PVCEUW-DxKwnlc-.js → chunk-X4PVCEUW-Cn--G81r.js} +1 -1
  33. package/dist/site/assets/{chunk-XXDRQBXY-CJUn5Oii.js → chunk-XXDRQBXY-CAhV92D-.js} +1 -1
  34. package/dist/site/assets/{classDiagram-v2-L25IHNXF-B41RcJk0.js → classDiagram-v2-L25IHNXF-C6KHQz05.js} +1 -1
  35. package/dist/site/assets/{cose-bilkent-JH36ORCC-Hfhuej2j.js → cose-bilkent-JH36ORCC-CtlAfqGZ.js} +1 -1
  36. package/dist/site/assets/cynefin-EF2NZ3EQ-BT63Cl1N.js +1 -0
  37. package/dist/site/assets/{cynefinDiagram-L36ESFBY-BYMvR7-Q.js → cynefinDiagram-L36ESFBY-CGTOTi8L.js} +1 -1
  38. package/dist/site/assets/{d3-selection-CI8ga2_p.js → d3-selection-DfwWYnWY.js} +1 -1
  39. package/dist/site/assets/{dagre-SPEB5RXH-as47m9kW.js → dagre-SPEB5RXH-B5j68ZWF.js} +1 -1
  40. package/dist/site/assets/{diagram-3B7GL73J-BBY5-WzS.js → diagram-3B7GL73J-B8hbXknY.js} +1 -1
  41. package/dist/site/assets/{diagram-DNEMPZML-CJPXq3cD.js → diagram-DNEMPZML-BwJNl8dX.js} +1 -1
  42. package/dist/site/assets/{diagram-L3MUGCDN-f-iNyYE_.js → diagram-L3MUGCDN-BmJ90hvp.js} +1 -1
  43. package/dist/site/assets/{diagram-LA4NIPWU-DDCgxDM8.js → diagram-LA4NIPWU-BXrTZcxH.js} +1 -1
  44. package/dist/site/assets/{diagram-MHCOC4E2-CFzWd1B3.js → diagram-MHCOC4E2-w2wXHPha.js} +1 -1
  45. package/dist/site/assets/{diagram-XPFHEONP-Cf4tD3Ah.js → diagram-XPFHEONP-BlLAb5K8.js} +1 -1
  46. package/dist/site/assets/{dist-DS3GkfcZ.js → dist-DF8TWQUI.js} +1 -1
  47. package/dist/site/assets/{ebnfDiagram-UZSYDL2S-DFDmK0yQ.js → ebnfDiagram-UZSYDL2S-BBJYcq8A.js} +1 -1
  48. package/dist/site/assets/{elk-XV6XMXQE-cIiutDbM.js → elk-XV6XMXQE-BNec2JMr.js} +1 -1
  49. package/dist/site/assets/{erDiagram-EYBAPDEH-BHL7Ovr0.js → erDiagram-EYBAPDEH-Y7Vde_YY.js} +1 -1
  50. package/dist/site/assets/{eventmodeling-K75KTNOO-uRMPk7um.js → eventmodeling-K75KTNOO-B64MOPHr.js} +1 -1
  51. package/dist/site/assets/flowDiagram-MALGAFMO-D2QRSHZa.js +1 -0
  52. package/dist/site/assets/{ganttDiagram-23REXITY-C3pymWD2.js → ganttDiagram-23REXITY-DbwO-UWV.js} +1 -1
  53. package/dist/site/assets/gitGraph-VSP46ZUC-CI36rhOW.js +1 -0
  54. package/dist/site/assets/{gitGraphDiagram-STJD7YCW-BCoyTvJ9.js → gitGraphDiagram-STJD7YCW-I-Xq3IP9.js} +1 -1
  55. package/dist/site/assets/hall-CokgDnDR.js +1 -0
  56. package/dist/site/assets/hall-CwoC1J4j.css +1 -0
  57. package/dist/site/assets/hall-alcove-ClW2UMI7.webp +0 -0
  58. package/dist/site/assets/hall-alcove-mobile-BxEUtWvY.webp +0 -0
  59. package/dist/site/assets/hall-alcove-mobile-sm-BlghnUCZ.webp +0 -0
  60. package/dist/site/assets/hall-spine-blue-CIU_8Qn_.webp +0 -0
  61. package/dist/site/assets/hall-spine-green-DprD8TSs.webp +0 -0
  62. package/dist/site/assets/hall-spine-red-t1QRvgnV.webp +0 -0
  63. package/dist/site/assets/index-B58FK2sK.css +1 -0
  64. package/dist/site/assets/index-KbmztiiE.js +2 -0
  65. package/dist/site/assets/info-OHQRW6UA-DtESxHnP.js +1 -0
  66. package/dist/site/assets/{infoDiagram-KBXO4MBG-BMUKKRqr.js → infoDiagram-KBXO4MBG-BWnzK4Yo.js} +1 -1
  67. package/dist/site/assets/{ishikawaDiagram-M35NCXHK-B4F1x9LF.js → ishikawaDiagram-M35NCXHK-29uw0hFe.js} +1 -1
  68. package/dist/site/assets/{journeyDiagram-OPLOXDXO-RRS0Nr5v.js → journeyDiagram-OPLOXDXO-B0JEs1dX.js} +1 -1
  69. package/dist/site/assets/{kanban-definition-BZKZHSQY-DlnQvxuJ.js → kanban-definition-BZKZHSQY-Dcvi_vqT.js} +1 -1
  70. package/dist/site/assets/{mermaid-parser.core-CmBZsPdM.js → mermaid-parser.core-Dl0exlcL.js} +3 -3
  71. package/dist/site/assets/{mindmap-definition-I2QAS2VK-Dnoa0qOC.js → mindmap-definition-I2QAS2VK-Bs4J6PgW.js} +1 -1
  72. package/dist/site/assets/packet-JDAUHWVQ-D4hILY2o.js +1 -0
  73. package/dist/site/assets/{pegDiagram-FD4XPPHP-y7yZh106.js → pegDiagram-FD4XPPHP-DF2U8EHy.js} +1 -1
  74. package/dist/site/assets/pie-XZMESJXO-CtsnJy9D.js +1 -0
  75. package/dist/site/assets/{pieDiagram-J4AKIIQI-n3iv70G0.js → pieDiagram-J4AKIIQI-C3AS7OAJ.js} +1 -1
  76. package/dist/site/assets/{quadrantDiagram-XTYBLID2-EGxDrEom.js → quadrantDiagram-XTYBLID2-9i24lxbN.js} +1 -1
  77. package/dist/site/assets/radar-ABXABTNO-B2gVSjCO.js +1 -0
  78. package/dist/site/assets/railroad-I3PHUGI6-up1t91bo.js +1 -0
  79. package/dist/site/assets/{railroad-abnf-LNEFI6M7-Bwq20l_E.js → railroad-abnf-LNEFI6M7-JEa60cDb.js} +1 -1
  80. package/dist/site/assets/{railroad-ebnf-DWYD2UWJ-BUavN9pu.js → railroad-ebnf-DWYD2UWJ-BfQJUjKZ.js} +1 -1
  81. package/dist/site/assets/{railroad-peg-JR7BVNR7-BToEFney.js → railroad-peg-JR7BVNR7-C_4MBTiI.js} +1 -1
  82. package/dist/site/assets/{railroadDiagram-MRQ6NCDL-BHZ9EtMa.js → railroadDiagram-MRQ6NCDL-BbaOFso-.js} +1 -1
  83. package/dist/site/assets/{requirementDiagram-Y7LWUY3S-DkuSYjSK.js → requirementDiagram-Y7LWUY3S-DsP9_6zv.js} +1 -1
  84. package/dist/site/assets/{sankeyDiagram-WGJFYUXA-CJbH3EfH.js → sankeyDiagram-WGJFYUXA-Bu59ysEI.js} +1 -1
  85. package/dist/site/assets/{sequenceDiagram-5NDRBG5M-B7agsZxt.js → sequenceDiagram-5NDRBG5M-VELz5R_k.js} +1 -1
  86. package/dist/site/assets/{stateDiagram-v2-FJ4FJNEA-Bydf2BLk.js → stateDiagram-v2-FJ4FJNEA-DMGgXTYX.js} +1 -1
  87. package/dist/site/assets/{swimlanes-UMQ2AFYF-r3fX4MpY.js → swimlanes-UMQ2AFYF-Iu9rlnay.js} +1 -1
  88. package/dist/site/assets/swimlanesDiagram-OMPLPG4O-9dbhYORP.js +8 -0
  89. package/dist/site/assets/{timeline-definition-SEUHKTQE-DeWjzMEH.js → timeline-definition-SEUHKTQE-D54-yps4.js} +1 -1
  90. package/dist/site/assets/treeView-D4JQ5SDB-SyDvQGmd.js +1 -0
  91. package/dist/site/assets/treemap-SAJKECNS-z-LPvytk.js +1 -0
  92. package/dist/site/assets/types-HX5Q6aR9.js +1 -0
  93. package/dist/site/assets/{usecaseDiagram-AFA6YXN4-YDZpIB7r.js → usecaseDiagram-AFA6YXN4-BMJp18iE.js} +1 -1
  94. package/dist/site/assets/{vennDiagram-NNMJR3RB-D1sigP0B.js → vennDiagram-NNMJR3RB-Ck38XLgD.js} +1 -1
  95. package/dist/site/assets/wardley-7MLQ67FV-BDu3spsn.js +1 -0
  96. package/dist/site/assets/{wardleyDiagram-S7YFUSEH-DGP9UWAL.js → wardleyDiagram-S7YFUSEH-C8ecIwP1.js} +1 -1
  97. package/dist/site/assets/{xychartDiagram-GGNKY7IX-8UtfN8VF.js → xychartDiagram-GGNKY7IX-BBfmyqX1.js} +1 -1
  98. package/dist/site/hall.html +15 -0
  99. package/dist/site/index.html +3 -3
  100. package/package.json +1 -1
  101. package/dist/site/assets/BookReader-DcroEKUg.js +0 -2
  102. package/dist/site/assets/BookScene-BQ0qnOky.js +0 -4294
  103. package/dist/site/assets/DiagramViewer-BUnCB7ku.js +0 -1
  104. package/dist/site/assets/MermaidDiagram-BXKKC_Kr.js +0 -44
  105. package/dist/site/assets/cynefin-EF2NZ3EQ-DTUoTqfp.js +0 -1
  106. package/dist/site/assets/flowDiagram-MALGAFMO-BBmpoSIE.js +0 -1
  107. package/dist/site/assets/gitGraph-VSP46ZUC-B15ZIQtT.js +0 -1
  108. package/dist/site/assets/index-BXk1cjOE.css +0 -1
  109. package/dist/site/assets/index-BgKsSfhH.js +0 -2
  110. package/dist/site/assets/info-OHQRW6UA-kYAlA3Y8.js +0 -1
  111. package/dist/site/assets/jsxRuntime-WpZ1bTm4.js +0 -1
  112. package/dist/site/assets/packet-JDAUHWVQ-CJp_wbox.js +0 -1
  113. package/dist/site/assets/pie-XZMESJXO-BMoXFFDK.js +0 -1
  114. package/dist/site/assets/radar-ABXABTNO-DRrhzt_O.js +0 -1
  115. package/dist/site/assets/railroad-I3PHUGI6-C-v-T810.js +0 -1
  116. package/dist/site/assets/swimlanesDiagram-OMPLPG4O-B-rD76wI.js +0 -8
  117. package/dist/site/assets/treeView-D4JQ5SDB-CM3eU6Zr.js +0 -1
  118. package/dist/site/assets/treemap-SAJKECNS-Clj7k3CO.js +0 -1
  119. package/dist/site/assets/wardley-7MLQ67FV-DmgO-Qnf.js +0 -1
@@ -0,0 +1,4294 @@
1
+ import{_ as e,c as t,g as n,s as r,v as i}from"./types-HX5Q6aR9.js";import{$ as a,$n as o,A as s,An as c,At as l,B as u,Bn as d,C as f,Cn as p,Ct as m,D as h,Dn as g,Dt as _,E as v,Et as y,F as b,Fn as x,Ft as S,G as C,Gn as w,H as T,Hn as E,I as D,In as O,J as k,Jn as A,K as j,Kn as M,L as N,Mn as P,N as F,Nn as I,O as L,On as ee,Ot as te,P as ne,Pn as re,Pt as R,Q as ie,Qn as ae,R as oe,Rn as se,S as z,Sn as ce,St as le,T as ue,Tn as de,Tt as fe,U as pe,Un as me,V as he,Vn as ge,W as _e,Wn as ve,X as ye,Xn as be,Y as xe,Yn as Se,Z as Ce,Zn as we,_ as Te,_n as Ee,_t as De,a as Oe,ar as B,at as V,b as ke,bt as Ae,c as je,cr as Me,ct as H,d as Ne,dn as Pe,dt as U,er as W,et as G,f as K,fn as Fe,ft as Ie,g as q,gn as J,gt as Le,h as Re,hn as ze,ht as Be,i as Ve,ir as He,it as Ue,j as We,jn as Ge,k as Ke,kn as qe,lt as Je,m as Ye,mt as Xe,n as Ze,nr as Qe,nt as $e,o as et,or as tt,ot as nt,p as Y,pn as rt,pt as it,q as at,qn as ot,r as st,rr as ct,rt as lt,s as ut,sr as X,st as dt,tr as ft,tt as pt,u as mt,ut as ht,v as gt,vt as _t,w as vt,wn as yt,wt as bt,x as xt,xt as St,y as Ct,yt as wt}from"./three-core-B1q6MRTI.js";import{n as Tt,t as Et}from"./BookReader-DLYZCDb0.js";function Dt(){let e=null,t=!1,n=null,r=null;function i(t,a){r=e.requestAnimationFrame(i),n(t,a)}return{start:function(){t!==!0&&n!==null&&e!==null&&(r=e.requestAnimationFrame(i),t=!0)},stop:function(){e!==null&&e.cancelAnimationFrame(r),t=!1},setAnimationLoop:function(e){n=e},setContext:function(t){e=t}}}function Ot(e){let t=new WeakMap;function n(t,n){let r=t.array,i=t.usage,a=r.byteLength,o=e.createBuffer();e.bindBuffer(n,o),e.bufferData(n,r,i),t.onUploadCallback();let s;if(r instanceof Float32Array)s=e.FLOAT;else if(typeof Float16Array<`u`&&r instanceof Float16Array)s=e.HALF_FLOAT;else if(r instanceof Uint16Array)s=t.isFloat16BufferAttribute?e.HALF_FLOAT:e.UNSIGNED_SHORT;else if(r instanceof Int16Array)s=e.SHORT;else if(r instanceof Uint32Array)s=e.UNSIGNED_INT;else if(r instanceof Int32Array)s=e.INT;else if(r instanceof Int8Array)s=e.BYTE;else if(r instanceof Uint8Array)s=e.UNSIGNED_BYTE;else if(r instanceof Uint8ClampedArray)s=e.UNSIGNED_BYTE;else throw Error(`THREE.WebGLAttributes: Unsupported buffer data format: `+r);return{buffer:o,type:s,bytesPerElement:r.BYTES_PER_ELEMENT,version:t.version,size:a}}function r(t,n,r){let i=n.array,a=n.updateRanges;if(e.bindBuffer(r,t),a.length===0)e.bufferSubData(r,0,i);else{a.sort((e,t)=>e.start-t.start);let t=0;for(let e=1;e<a.length;e++){let n=a[t],r=a[e];r.start<=n.start+n.count+1?n.count=Math.max(n.count,r.start+r.count-n.start):(++t,a[t]=r)}a.length=t+1;for(let t=0,n=a.length;t<n;t++){let n=a[t];e.bufferSubData(r,n.start*i.BYTES_PER_ELEMENT,i,n.start,n.count)}n.clearUpdateRanges()}n.onUploadCallback()}function i(e){return e.isInterleavedBufferAttribute&&(e=e.data),t.get(e)}function a(n){n.isInterleavedBufferAttribute&&(n=n.data);let r=t.get(n);r&&(e.deleteBuffer(r.buffer),t.delete(n))}function o(e,i){if(e.isInterleavedBufferAttribute&&(e=e.data),e.isGLBufferAttribute){let n=t.get(e);(!n||n.version<e.version)&&t.set(e,{buffer:e.buffer,type:e.type,bytesPerElement:e.elementSize,version:e.version});return}let a=t.get(e);if(a===void 0)t.set(e,n(e,i));else if(a.version<e.version){if(a.size!==e.array.byteLength)throw Error(`THREE.WebGLAttributes: The size of the buffer attribute's array buffer does not match the original size. Resizing buffer attributes is not supported.`);r(a.buffer,e,i),a.version=e.version}}return{get:i,remove:a,update:o}}var Z={alphahash_fragment:`#ifdef USE_ALPHAHASH
2
+ if ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;
3
+ #endif`,alphahash_pars_fragment:`#ifdef USE_ALPHAHASH
4
+ const float ALPHA_HASH_SCALE = 0.05;
5
+ float hash2D( vec2 value ) {
6
+ return fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );
7
+ }
8
+ float hash3D( vec3 value ) {
9
+ return hash2D( vec2( hash2D( value.xy ), value.z ) );
10
+ }
11
+ float getAlphaHashThreshold( vec3 position ) {
12
+ float maxDeriv = max(
13
+ length( dFdx( position.xyz ) ),
14
+ length( dFdy( position.xyz ) )
15
+ );
16
+ float pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );
17
+ vec2 pixScales = vec2(
18
+ exp2( floor( log2( pixScale ) ) ),
19
+ exp2( ceil( log2( pixScale ) ) )
20
+ );
21
+ vec2 alpha = vec2(
22
+ hash3D( floor( pixScales.x * position.xyz ) ),
23
+ hash3D( floor( pixScales.y * position.xyz ) )
24
+ );
25
+ float lerpFactor = fract( log2( pixScale ) );
26
+ float x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;
27
+ float a = min( lerpFactor, 1.0 - lerpFactor );
28
+ vec3 cases = vec3(
29
+ x * x / ( 2.0 * a * ( 1.0 - a ) ),
30
+ ( x - 0.5 * a ) / ( 1.0 - a ),
31
+ 1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )
32
+ );
33
+ float threshold = ( x < ( 1.0 - a ) )
34
+ ? ( ( x < a ) ? cases.x : cases.y )
35
+ : cases.z;
36
+ return clamp( threshold , 1.0e-6, 1.0 );
37
+ }
38
+ #endif`,alphamap_fragment:`#ifdef USE_ALPHAMAP
39
+ diffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;
40
+ #endif`,alphamap_pars_fragment:`#ifdef USE_ALPHAMAP
41
+ uniform sampler2D alphaMap;
42
+ #endif`,alphatest_fragment:`#ifdef USE_ALPHATEST
43
+ #ifdef ALPHA_TO_COVERAGE
44
+ diffuseColor.a = smoothstep( alphaTest, alphaTest + fwidth( diffuseColor.a ), diffuseColor.a );
45
+ if ( diffuseColor.a == 0.0 ) discard;
46
+ #else
47
+ if ( diffuseColor.a < alphaTest ) discard;
48
+ #endif
49
+ #endif`,alphatest_pars_fragment:`#ifdef USE_ALPHATEST
50
+ uniform float alphaTest;
51
+ #endif`,aomap_fragment:`#ifdef USE_AOMAP
52
+ float ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;
53
+ reflectedLight.indirectDiffuse *= ambientOcclusion;
54
+ #if defined( USE_CLEARCOAT )
55
+ clearcoatSpecularIndirect *= ambientOcclusion;
56
+ #endif
57
+ #if defined( USE_SHEEN )
58
+ sheenSpecularIndirect *= ambientOcclusion;
59
+ #endif
60
+ #if defined( USE_ENVMAP ) && defined( STANDARD )
61
+ float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
62
+ reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );
63
+ #endif
64
+ #endif`,aomap_pars_fragment:`#ifdef USE_AOMAP
65
+ uniform sampler2D aoMap;
66
+ uniform float aoMapIntensity;
67
+ #endif`,batching_pars_vertex:`#ifdef USE_BATCHING
68
+ #if ! defined( GL_ANGLE_multi_draw )
69
+ #define gl_DrawID _gl_DrawID
70
+ uniform int _gl_DrawID;
71
+ #endif
72
+ uniform highp sampler2D batchingTexture;
73
+ uniform highp usampler2D batchingIdTexture;
74
+ mat4 getBatchingMatrix( const in float i ) {
75
+ int size = textureSize( batchingTexture, 0 ).x;
76
+ int j = int( i ) * 4;
77
+ int x = j % size;
78
+ int y = j / size;
79
+ vec4 v1 = texelFetch( batchingTexture, ivec2( x, y ), 0 );
80
+ vec4 v2 = texelFetch( batchingTexture, ivec2( x + 1, y ), 0 );
81
+ vec4 v3 = texelFetch( batchingTexture, ivec2( x + 2, y ), 0 );
82
+ vec4 v4 = texelFetch( batchingTexture, ivec2( x + 3, y ), 0 );
83
+ return mat4( v1, v2, v3, v4 );
84
+ }
85
+ float getIndirectIndex( const in int i ) {
86
+ int size = textureSize( batchingIdTexture, 0 ).x;
87
+ int x = i % size;
88
+ int y = i / size;
89
+ return float( texelFetch( batchingIdTexture, ivec2( x, y ), 0 ).r );
90
+ }
91
+ #endif
92
+ #ifdef USE_BATCHING_COLOR
93
+ uniform sampler2D batchingColorTexture;
94
+ vec4 getBatchingColor( const in float i ) {
95
+ int size = textureSize( batchingColorTexture, 0 ).x;
96
+ int j = int( i );
97
+ int x = j % size;
98
+ int y = j / size;
99
+ return texelFetch( batchingColorTexture, ivec2( x, y ), 0 );
100
+ }
101
+ #endif`,batching_vertex:`#ifdef USE_BATCHING
102
+ mat4 batchingMatrix = getBatchingMatrix( getIndirectIndex( gl_DrawID ) );
103
+ #endif`,begin_vertex:`vec3 transformed = vec3( position );
104
+ #ifdef USE_ALPHAHASH
105
+ vPosition = vec3( position );
106
+ #endif`,beginnormal_vertex:`vec3 objectNormal = vec3( normal );
107
+ #ifdef USE_TANGENT
108
+ vec3 objectTangent = vec3( tangent.xyz );
109
+ #endif`,bsdfs:`float G_BlinnPhong_Implicit( ) {
110
+ return 0.25;
111
+ }
112
+ float D_BlinnPhong( const in float shininess, const in float dotNH ) {
113
+ return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );
114
+ }
115
+ vec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {
116
+ vec3 halfDir = normalize( lightDir + viewDir );
117
+ float dotNH = saturate( dot( normal, halfDir ) );
118
+ float dotVH = saturate( dot( viewDir, halfDir ) );
119
+ vec3 F = F_Schlick( specularColor, 1.0, dotVH );
120
+ float G = G_BlinnPhong_Implicit( );
121
+ float D = D_BlinnPhong( shininess, dotNH );
122
+ return F * ( G * D );
123
+ } // validated`,iridescence_fragment:`#ifdef USE_IRIDESCENCE
124
+ const mat3 XYZ_TO_REC709 = mat3(
125
+ 3.2404542, -0.9692660, 0.0556434,
126
+ -1.5371385, 1.8760108, -0.2040259,
127
+ -0.4985314, 0.0415560, 1.0572252
128
+ );
129
+ vec3 Fresnel0ToIor( vec3 fresnel0 ) {
130
+ vec3 sqrtF0 = sqrt( fresnel0 );
131
+ return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );
132
+ }
133
+ vec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {
134
+ return pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );
135
+ }
136
+ float IorToFresnel0( float transmittedIor, float incidentIor ) {
137
+ return pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));
138
+ }
139
+ vec3 evalSensitivity( float OPD, vec3 shift ) {
140
+ float phase = 2.0 * PI * OPD * 1.0e-9;
141
+ vec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );
142
+ vec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );
143
+ vec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );
144
+ vec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );
145
+ xyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );
146
+ xyz /= 1.0685e-7;
147
+ vec3 rgb = XYZ_TO_REC709 * xyz;
148
+ return rgb;
149
+ }
150
+ vec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {
151
+ vec3 I;
152
+ float iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );
153
+ float sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );
154
+ float cosTheta2Sq = 1.0 - sinTheta2Sq;
155
+ if ( cosTheta2Sq < 0.0 ) {
156
+ return vec3( 1.0 );
157
+ }
158
+ float cosTheta2 = sqrt( cosTheta2Sq );
159
+ float R0 = IorToFresnel0( iridescenceIOR, outsideIOR );
160
+ float R12 = F_Schlick( R0, 1.0, cosTheta1 );
161
+ float T121 = 1.0 - R12;
162
+ float phi12 = 0.0;
163
+ if ( iridescenceIOR < outsideIOR ) phi12 = PI;
164
+ float phi21 = PI - phi12;
165
+ vec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) ); vec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );
166
+ vec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );
167
+ vec3 phi23 = vec3( 0.0 );
168
+ if ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;
169
+ if ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;
170
+ if ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;
171
+ float OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;
172
+ vec3 phi = vec3( phi21 ) + phi23;
173
+ vec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );
174
+ vec3 r123 = sqrt( R123 );
175
+ vec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );
176
+ vec3 C0 = R12 + Rs;
177
+ I = C0;
178
+ vec3 Cm = Rs - T121;
179
+ for ( int m = 1; m <= 2; ++ m ) {
180
+ Cm *= r123;
181
+ vec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );
182
+ I += Cm * Sm;
183
+ }
184
+ return max( I, vec3( 0.0 ) );
185
+ }
186
+ #endif`,bumpmap_pars_fragment:`#ifdef USE_BUMPMAP
187
+ uniform sampler2D bumpMap;
188
+ uniform float bumpScale;
189
+ vec2 dHdxy_fwd() {
190
+ vec2 dSTdx = dFdx( vBumpMapUv );
191
+ vec2 dSTdy = dFdy( vBumpMapUv );
192
+ float Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;
193
+ float dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;
194
+ float dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;
195
+ return vec2( dBx, dBy );
196
+ }
197
+ vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {
198
+ vec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );
199
+ vec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );
200
+ vec3 vN = surf_norm;
201
+ vec3 R1 = cross( vSigmaY, vN );
202
+ vec3 R2 = cross( vN, vSigmaX );
203
+ float fDet = dot( vSigmaX, R1 ) * faceDirection;
204
+ vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );
205
+ return normalize( abs( fDet ) * surf_norm - vGrad );
206
+ }
207
+ #endif`,clipping_planes_fragment:`#if NUM_CLIPPING_PLANES > 0
208
+ vec4 plane;
209
+ #ifdef ALPHA_TO_COVERAGE
210
+ float distanceToPlane, distanceGradient;
211
+ float clipOpacity = 1.0;
212
+ #pragma unroll_loop_start
213
+ for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
214
+ plane = clippingPlanes[ i ];
215
+ distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
216
+ distanceGradient = fwidth( distanceToPlane ) / 2.0;
217
+ clipOpacity *= smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
218
+ if ( clipOpacity == 0.0 ) discard;
219
+ }
220
+ #pragma unroll_loop_end
221
+ #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
222
+ float unionClipOpacity = 1.0;
223
+ #pragma unroll_loop_start
224
+ for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
225
+ plane = clippingPlanes[ i ];
226
+ distanceToPlane = - dot( vClipPosition, plane.xyz ) + plane.w;
227
+ distanceGradient = fwidth( distanceToPlane ) / 2.0;
228
+ unionClipOpacity *= 1.0 - smoothstep( - distanceGradient, distanceGradient, distanceToPlane );
229
+ }
230
+ #pragma unroll_loop_end
231
+ clipOpacity *= 1.0 - unionClipOpacity;
232
+ #endif
233
+ diffuseColor.a *= clipOpacity;
234
+ if ( diffuseColor.a == 0.0 ) discard;
235
+ #else
236
+ #pragma unroll_loop_start
237
+ for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {
238
+ plane = clippingPlanes[ i ];
239
+ if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;
240
+ }
241
+ #pragma unroll_loop_end
242
+ #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
243
+ bool clipped = true;
244
+ #pragma unroll_loop_start
245
+ for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
246
+ plane = clippingPlanes[ i ];
247
+ clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;
248
+ }
249
+ #pragma unroll_loop_end
250
+ if ( clipped ) discard;
251
+ #endif
252
+ #endif
253
+ #endif`,clipping_planes_pars_fragment:`#if NUM_CLIPPING_PLANES > 0
254
+ varying vec3 vClipPosition;
255
+ uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];
256
+ #endif`,clipping_planes_pars_vertex:`#if NUM_CLIPPING_PLANES > 0
257
+ varying vec3 vClipPosition;
258
+ #endif`,clipping_planes_vertex:`#if NUM_CLIPPING_PLANES > 0
259
+ vClipPosition = - mvPosition.xyz;
260
+ #endif`,color_fragment:`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )
261
+ diffuseColor *= vColor;
262
+ #endif`,color_pars_fragment:`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA )
263
+ varying vec4 vColor;
264
+ #endif`,color_pars_vertex:`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
265
+ varying vec4 vColor;
266
+ #endif`,color_vertex:`#if defined( USE_COLOR ) || defined( USE_COLOR_ALPHA ) || defined( USE_INSTANCING_COLOR ) || defined( USE_BATCHING_COLOR )
267
+ vColor = vec4( 1.0 );
268
+ #endif
269
+ #ifdef USE_COLOR_ALPHA
270
+ vColor *= color;
271
+ #elif defined( USE_COLOR )
272
+ vColor.rgb *= color;
273
+ #endif
274
+ #ifdef USE_INSTANCING_COLOR
275
+ vColor.rgb *= instanceColor.rgb;
276
+ #endif
277
+ #ifdef USE_BATCHING_COLOR
278
+ vColor *= getBatchingColor( getIndirectIndex( gl_DrawID ) );
279
+ #endif`,common:`#define PI 3.141592653589793
280
+ #define PI2 6.283185307179586
281
+ #define PI_HALF 1.5707963267948966
282
+ #define RECIPROCAL_PI 0.3183098861837907
283
+ #define RECIPROCAL_PI2 0.15915494309189535
284
+ #define EPSILON 1e-6
285
+ #ifndef saturate
286
+ #define saturate( a ) clamp( a, 0.0, 1.0 )
287
+ #endif
288
+ #define whiteComplement( a ) ( 1.0 - saturate( a ) )
289
+ float pow2( const in float x ) { return x*x; }
290
+ vec3 pow2( const in vec3 x ) { return x*x; }
291
+ float pow3( const in float x ) { return x*x*x; }
292
+ float pow4( const in float x ) { float x2 = x*x; return x2*x2; }
293
+ float max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }
294
+ float average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }
295
+ highp float rand( const in vec2 uv ) {
296
+ const highp float a = 12.9898, b = 78.233, c = 43758.5453;
297
+ highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );
298
+ return fract( sin( sn ) * c );
299
+ }
300
+ #ifdef HIGH_PRECISION
301
+ float precisionSafeLength( vec3 v ) { return length( v ); }
302
+ #else
303
+ float precisionSafeLength( vec3 v ) {
304
+ float maxComponent = max3( abs( v ) );
305
+ return length( v / maxComponent ) * maxComponent;
306
+ }
307
+ #endif
308
+ struct IncidentLight {
309
+ vec3 color;
310
+ vec3 direction;
311
+ bool visible;
312
+ };
313
+ struct ReflectedLight {
314
+ vec3 directDiffuse;
315
+ vec3 directSpecular;
316
+ vec3 indirectDiffuse;
317
+ vec3 indirectSpecular;
318
+ };
319
+ #ifdef USE_ALPHAHASH
320
+ varying vec3 vPosition;
321
+ #endif
322
+ vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
323
+ return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
324
+ }
325
+ #define inverseTransformDirection transformDirectionByInverseViewMatrix
326
+ vec3 transformNormalByInverseViewMatrix( in vec3 normal, in mat4 viewMatrix ) {
327
+ return normalize( ( vec4( normal, 0.0 ) * viewMatrix ).xyz );
328
+ }
329
+ vec3 transformDirectionByInverseViewMatrix( in vec3 dir, in mat4 viewMatrix ) {
330
+ return normalize( ( vec4( dir, 0.0 ) * viewMatrix ).xyz );
331
+ }
332
+ bool isPerspectiveMatrix( mat4 m ) {
333
+ return m[ 2 ][ 3 ] == - 1.0;
334
+ }
335
+ vec2 equirectUv( in vec3 dir ) {
336
+ float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;
337
+ float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;
338
+ return vec2( u, v );
339
+ }
340
+ vec3 BRDF_Lambert( const in vec3 diffuseColor ) {
341
+ return RECIPROCAL_PI * diffuseColor;
342
+ }
343
+ vec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {
344
+ float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
345
+ return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
346
+ }
347
+ float F_Schlick( const in float f0, const in float f90, const in float dotVH ) {
348
+ float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );
349
+ return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );
350
+ } // validated`,defaultnormal_vertex:`vec3 transformedNormal = objectNormal;
351
+ #ifdef USE_TANGENT
352
+ vec3 transformedTangent = objectTangent;
353
+ #endif
354
+ #ifdef USE_BATCHING
355
+ mat3 bm = mat3( batchingMatrix );
356
+ transformedNormal /= vec3( dot( bm[ 0 ], bm[ 0 ] ), dot( bm[ 1 ], bm[ 1 ] ), dot( bm[ 2 ], bm[ 2 ] ) );
357
+ transformedNormal = bm * transformedNormal;
358
+ #ifdef USE_TANGENT
359
+ transformedTangent = bm * transformedTangent;
360
+ #endif
361
+ #endif
362
+ #ifdef USE_INSTANCING
363
+ mat3 im = mat3( instanceMatrix );
364
+ transformedNormal /= vec3( dot( im[ 0 ], im[ 0 ] ), dot( im[ 1 ], im[ 1 ] ), dot( im[ 2 ], im[ 2 ] ) );
365
+ transformedNormal = im * transformedNormal;
366
+ #ifdef USE_TANGENT
367
+ transformedTangent = im * transformedTangent;
368
+ #endif
369
+ #endif
370
+ transformedNormal = normalMatrix * transformedNormal;
371
+ #ifdef FLIP_SIDED
372
+ transformedNormal = - transformedNormal;
373
+ #endif
374
+ #ifdef USE_TANGENT
375
+ transformedTangent = ( modelViewMatrix * vec4( transformedTangent, 0.0 ) ).xyz;
376
+ #endif`,displacementmap_pars_vertex:`#ifdef USE_DISPLACEMENTMAP
377
+ uniform sampler2D displacementMap;
378
+ uniform float displacementScale;
379
+ uniform float displacementBias;
380
+ #endif`,displacementmap_vertex:`#ifdef USE_DISPLACEMENTMAP
381
+ transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );
382
+ #endif`,emissivemap_fragment:`#ifdef USE_EMISSIVEMAP
383
+ vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );
384
+ #ifdef DECODE_VIDEO_TEXTURE_EMISSIVE
385
+ emissiveColor = sRGBTransferEOTF( emissiveColor );
386
+ #endif
387
+ totalEmissiveRadiance *= emissiveColor.rgb;
388
+ #endif`,emissivemap_pars_fragment:`#ifdef USE_EMISSIVEMAP
389
+ uniform sampler2D emissiveMap;
390
+ #endif`,colorspace_fragment:`gl_FragColor = linearToOutputTexel( gl_FragColor );`,colorspace_pars_fragment:`vec4 LinearTransferOETF( in vec4 value ) {
391
+ return value;
392
+ }
393
+ vec4 sRGBTransferEOTF( in vec4 value ) {
394
+ return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );
395
+ }
396
+ vec4 sRGBTransferOETF( in vec4 value ) {
397
+ return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );
398
+ }`,envmap_fragment:`#ifdef USE_ENVMAP
399
+ #ifdef ENV_WORLDPOS
400
+ vec3 cameraToFrag;
401
+ if ( isOrthographic ) {
402
+ cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
403
+ } else {
404
+ cameraToFrag = normalize( vWorldPosition - cameraPosition );
405
+ }
406
+ vec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );
407
+ #ifdef ENVMAP_MODE_REFLECTION
408
+ vec3 reflectVec = reflect( cameraToFrag, worldNormal );
409
+ #else
410
+ vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );
411
+ #endif
412
+ #else
413
+ vec3 reflectVec = vReflect;
414
+ #endif
415
+ #ifdef ENVMAP_TYPE_CUBE
416
+ vec4 envColor = textureCube( envMap, envMapRotation * reflectVec );
417
+ #ifdef ENVMAP_BLENDING_MULTIPLY
418
+ outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );
419
+ #elif defined( ENVMAP_BLENDING_MIX )
420
+ outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );
421
+ #elif defined( ENVMAP_BLENDING_ADD )
422
+ outgoingLight += envColor.xyz * specularStrength * reflectivity;
423
+ #endif
424
+ #endif
425
+ #endif`,envmap_common_pars_fragment:`#ifdef USE_ENVMAP
426
+ uniform float envMapIntensity;
427
+ uniform mat3 envMapRotation;
428
+ uniform samplerCube envMap;
429
+ #ifdef ENVMAP_TYPE_PMREM
430
+ float roughnessToMip( const in float roughness ) {
431
+ float r = clamp( roughness, 0.0, 1.0 );
432
+ return ENVMAP_MAX_LOD * r * ( 2.0 - r );
433
+ }
434
+ #endif
435
+ #endif`,envmap_pars_fragment:`#ifdef USE_ENVMAP
436
+ uniform float reflectivity;
437
+ #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
438
+ #define ENV_WORLDPOS
439
+ #endif
440
+ #ifdef ENV_WORLDPOS
441
+ varying vec3 vWorldPosition;
442
+ uniform float refractionRatio;
443
+ #else
444
+ varying vec3 vReflect;
445
+ #endif
446
+ #endif`,envmap_pars_vertex:`#ifdef USE_ENVMAP
447
+ #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )
448
+ #define ENV_WORLDPOS
449
+ #endif
450
+ #ifdef ENV_WORLDPOS
451
+
452
+ varying vec3 vWorldPosition;
453
+ #else
454
+ varying vec3 vReflect;
455
+ uniform float refractionRatio;
456
+ #endif
457
+ #endif`,envmap_physical_pars_fragment:`#ifdef USE_ENVMAP
458
+ vec3 getIBLIrradiance( const in vec3 normal ) {
459
+ #ifdef ENVMAP_TYPE_PMREM
460
+ vec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );
461
+ vec4 envMapColor = textureLod( envMap, envMapRotation * worldNormal, ENVMAP_MAX_LOD );
462
+ return PI * envMapColor.rgb * envMapIntensity;
463
+ #else
464
+ return vec3( 0.0 );
465
+ #endif
466
+ }
467
+ vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {
468
+ #ifdef ENVMAP_TYPE_PMREM
469
+ vec3 reflectVec = reflect( - viewDir, normal );
470
+ reflectVec = normalize( mix( reflectVec, normal, pow4( roughness ) ) );
471
+ reflectVec = transformDirectionByInverseViewMatrix( reflectVec, viewMatrix );
472
+ vec4 envMapColor = textureLod( envMap, envMapRotation * reflectVec, roughnessToMip( roughness ) );
473
+ return envMapColor.rgb * envMapIntensity;
474
+ #else
475
+ return vec3( 0.0 );
476
+ #endif
477
+ }
478
+ #ifdef USE_RETROREFLECTION
479
+ vec3 getIBLRetroRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {
480
+ #ifdef ENVMAP_TYPE_PMREM
481
+ vec3 retroVec = normalize( mix( viewDir, normal, pow4( roughness ) ) );
482
+ retroVec = transformDirectionByInverseViewMatrix( retroVec, viewMatrix );
483
+ vec4 envMapColor = textureLod( envMap, envMapRotation * retroVec, roughnessToMip( roughness ) );
484
+ return envMapColor.rgb * envMapIntensity;
485
+ #else
486
+ return vec3( 0.0 );
487
+ #endif
488
+ }
489
+ #endif
490
+ #ifdef USE_ANISOTROPY
491
+ vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {
492
+ #ifdef ENVMAP_TYPE_PMREM
493
+ vec3 bentNormal = cross( bitangent, viewDir );
494
+ bentNormal = normalize( cross( bentNormal, bitangent ) );
495
+ bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );
496
+ return getIBLRadiance( viewDir, bentNormal, roughness );
497
+ #else
498
+ return vec3( 0.0 );
499
+ #endif
500
+ }
501
+ #ifdef USE_RETROREFLECTION
502
+ vec3 getIBLAnisotropyRetroRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {
503
+ #ifdef ENVMAP_TYPE_PMREM
504
+ vec3 bentNormal = cross( bitangent, viewDir );
505
+ bentNormal = normalize( cross( bentNormal, bitangent ) );
506
+ bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );
507
+ return getIBLRetroRadiance( viewDir, bentNormal, roughness );
508
+ #else
509
+ return vec3( 0.0 );
510
+ #endif
511
+ }
512
+ #endif
513
+ #endif
514
+ #endif`,envmap_vertex:`#ifdef USE_ENVMAP
515
+ #ifdef ENV_WORLDPOS
516
+ vWorldPosition = worldPosition.xyz;
517
+ #else
518
+ vec3 cameraToVertex;
519
+ if ( isOrthographic ) {
520
+ cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );
521
+ } else {
522
+ cameraToVertex = normalize( worldPosition.xyz - cameraPosition );
523
+ }
524
+ vec3 worldNormal = transformNormalByInverseViewMatrix( transformedNormal, viewMatrix );
525
+ #ifdef ENVMAP_MODE_REFLECTION
526
+ vReflect = reflect( cameraToVertex, worldNormal );
527
+ #else
528
+ vReflect = refract( cameraToVertex, worldNormal, refractionRatio );
529
+ #endif
530
+ #endif
531
+ #endif`,fog_vertex:`#ifdef USE_FOG
532
+ vFogDepth = - mvPosition.z;
533
+ #endif`,fog_pars_vertex:`#ifdef USE_FOG
534
+ varying float vFogDepth;
535
+ #endif`,fog_fragment:`#ifdef USE_FOG
536
+ #ifdef FOG_EXP2
537
+ float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );
538
+ #else
539
+ float fogFactor = smoothstep( fogNear, fogFar, vFogDepth );
540
+ #endif
541
+ gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );
542
+ #endif`,fog_pars_fragment:`#ifdef USE_FOG
543
+ uniform vec3 fogColor;
544
+ varying float vFogDepth;
545
+ #ifdef FOG_EXP2
546
+ uniform float fogDensity;
547
+ #else
548
+ uniform float fogNear;
549
+ uniform float fogFar;
550
+ #endif
551
+ #endif`,gradientmap_pars_fragment:`#ifdef USE_GRADIENTMAP
552
+ uniform sampler2D gradientMap;
553
+ #endif
554
+ vec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {
555
+ float dotNL = dot( normal, lightDirection );
556
+ vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );
557
+ #ifdef USE_GRADIENTMAP
558
+ return vec3( texture2D( gradientMap, coord ).r );
559
+ #else
560
+ vec2 fw = fwidth( coord ) * 0.5;
561
+ return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );
562
+ #endif
563
+ }`,lightmap_pars_fragment:`#ifdef USE_LIGHTMAP
564
+ uniform sampler2D lightMap;
565
+ uniform float lightMapIntensity;
566
+ #endif`,lights_lambert_fragment:`LambertMaterial material;
567
+ material.diffuseColor = diffuseColor.rgb;
568
+ material.specularStrength = specularStrength;`,lights_lambert_pars_fragment:`varying vec3 vViewPosition;
569
+ struct LambertMaterial {
570
+ vec3 diffuseColor;
571
+ float specularStrength;
572
+ };
573
+ void RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
574
+ float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
575
+ vec3 irradiance = dotNL * directLight.color;
576
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
577
+ }
578
+ void RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {
579
+ reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
580
+ }
581
+ #define RE_Direct RE_Direct_Lambert
582
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert`,lights_pars_begin:`uniform bool receiveShadow;
583
+ uniform vec3 ambientLightColor;
584
+ #if defined( USE_LIGHT_PROBES )
585
+ uniform vec3 lightProbe[ 9 ];
586
+ #endif
587
+ vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {
588
+ float x = normal.x, y = normal.y, z = normal.z;
589
+ vec3 result = shCoefficients[ 0 ] * 0.886227;
590
+ result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;
591
+ result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;
592
+ result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;
593
+ result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;
594
+ result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;
595
+ result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );
596
+ result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;
597
+ result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );
598
+ return result;
599
+ }
600
+ vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {
601
+ vec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );
602
+ vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );
603
+ return irradiance;
604
+ }
605
+ vec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {
606
+ vec3 irradiance = ambientLightColor;
607
+ return irradiance;
608
+ }
609
+ float getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {
610
+ float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );
611
+ if ( cutoffDistance > 0.0 ) {
612
+ distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );
613
+ }
614
+ return distanceFalloff;
615
+ }
616
+ float getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {
617
+ return smoothstep( coneCosine, penumbraCosine, angleCosine );
618
+ }
619
+ #if NUM_SUN_LIGHTS > 0
620
+ struct SunLight {
621
+ vec3 direction;
622
+ vec3 color;
623
+ };
624
+ uniform SunLight sunLights[ NUM_SUN_LIGHTS ];
625
+ void getSunLightInfo( const in SunLight sunLight, out IncidentLight light ) {
626
+ light.color = sunLight.color;
627
+ light.direction = sunLight.direction;
628
+ light.visible = true;
629
+ }
630
+ #endif
631
+ #if NUM_DIR_LIGHTS > 0
632
+ struct DirectionalLight {
633
+ vec3 direction;
634
+ vec3 color;
635
+ };
636
+ uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];
637
+ void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {
638
+ light.color = directionalLight.color;
639
+ light.direction = directionalLight.direction;
640
+ light.visible = true;
641
+ }
642
+ #endif
643
+ #if NUM_POINT_LIGHTS > 0
644
+ struct PointLight {
645
+ vec3 position;
646
+ vec3 color;
647
+ float distance;
648
+ float decay;
649
+ };
650
+ uniform PointLight pointLights[ NUM_POINT_LIGHTS ];
651
+ void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {
652
+ vec3 lVector = pointLight.position - geometryPosition;
653
+ light.direction = normalize( lVector );
654
+ float lightDistance = length( lVector );
655
+ light.color = pointLight.color;
656
+ light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );
657
+ light.visible = ( light.color != vec3( 0.0 ) );
658
+ }
659
+ #endif
660
+ #if NUM_SPOT_LIGHTS > 0
661
+ struct SpotLight {
662
+ vec3 position;
663
+ vec3 direction;
664
+ vec3 color;
665
+ float distance;
666
+ float decay;
667
+ float coneCos;
668
+ float penumbraCos;
669
+ };
670
+ uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];
671
+ void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {
672
+ vec3 lVector = spotLight.position - geometryPosition;
673
+ light.direction = normalize( lVector );
674
+ float angleCos = dot( light.direction, spotLight.direction );
675
+ float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );
676
+ if ( spotAttenuation > 0.0 ) {
677
+ float lightDistance = length( lVector );
678
+ light.color = spotLight.color * spotAttenuation;
679
+ light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );
680
+ light.visible = ( light.color != vec3( 0.0 ) );
681
+ } else {
682
+ light.color = vec3( 0.0 );
683
+ light.visible = false;
684
+ }
685
+ }
686
+ #endif
687
+ #if NUM_RECT_AREA_LIGHTS > 0
688
+ struct RectAreaLight {
689
+ vec3 color;
690
+ vec3 position;
691
+ vec3 halfWidth;
692
+ vec3 halfHeight;
693
+ };
694
+ uniform sampler2D ltc_1; uniform sampler2D ltc_2;
695
+ uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];
696
+ #endif
697
+ #if NUM_HEMI_LIGHTS > 0
698
+ struct HemisphereLight {
699
+ vec3 direction;
700
+ vec3 skyColor;
701
+ vec3 groundColor;
702
+ };
703
+ uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];
704
+ vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {
705
+ float dotNL = dot( normal, hemiLight.direction );
706
+ float hemiDiffuseWeight = 0.5 * dotNL + 0.5;
707
+ vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );
708
+ return irradiance;
709
+ }
710
+ #endif
711
+ #include <lightprobes_pars_fragment>`,lights_toon_fragment:`ToonMaterial material;
712
+ material.diffuseColor = diffuseColor.rgb;`,lights_toon_pars_fragment:`varying vec3 vViewPosition;
713
+ struct ToonMaterial {
714
+ vec3 diffuseColor;
715
+ };
716
+ void RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
717
+ vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;
718
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
719
+ }
720
+ void RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {
721
+ reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
722
+ }
723
+ #define RE_Direct RE_Direct_Toon
724
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_Toon`,lights_phong_fragment:`BlinnPhongMaterial material;
725
+ material.diffuseColor = diffuseColor.rgb;
726
+ material.specularColor = specular;
727
+ material.specularShininess = shininess;
728
+ material.specularStrength = specularStrength;`,lights_phong_pars_fragment:`varying vec3 vViewPosition;
729
+ struct BlinnPhongMaterial {
730
+ vec3 diffuseColor;
731
+ vec3 specularColor;
732
+ float specularShininess;
733
+ float specularStrength;
734
+ };
735
+ void RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
736
+ float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
737
+ vec3 irradiance = dotNL * directLight.color;
738
+ reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
739
+ reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;
740
+ }
741
+ void RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {
742
+ reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );
743
+ }
744
+ #define RE_Direct RE_Direct_BlinnPhong
745
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong`,lights_physical_fragment:`PhysicalMaterial material;
746
+ material.diffuseColor = diffuseColor.rgb;
747
+ material.diffuseContribution = diffuseColor.rgb * ( 1.0 - metalnessFactor );
748
+ material.metalness = metalnessFactor;
749
+ vec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );
750
+ float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );
751
+ material.roughness = max( roughnessFactor, 0.045 );
752
+ material.roughness += geometryRoughness;
753
+ material.roughness = min( material.roughness, 1.0 );
754
+ #ifdef USE_DIFFUSE_ROUGHNESS
755
+ float diffuseRoughnessFactor = diffuseRoughness;
756
+ #ifdef USE_DIFFUSE_ROUGHNESSMAP
757
+ diffuseRoughnessFactor *= texture2D( diffuseRoughnessMap, vDiffuseRoughnessMapUv ).r;
758
+ #endif
759
+ material.diffuseRoughness = saturate( diffuseRoughnessFactor );
760
+ #endif
761
+ #ifdef IOR
762
+ material.ior = ior;
763
+ #ifdef USE_SPECULAR
764
+ float specularIntensityFactor = specularIntensity;
765
+ vec3 specularColorFactor = specularColor;
766
+ #ifdef USE_SPECULAR_COLORMAP
767
+ specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;
768
+ #endif
769
+ #ifdef USE_SPECULAR_INTENSITYMAP
770
+ specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;
771
+ #endif
772
+ material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );
773
+ #else
774
+ float specularIntensityFactor = 1.0;
775
+ vec3 specularColorFactor = vec3( 1.0 );
776
+ material.specularF90 = 1.0;
777
+ #endif
778
+ material.specularColor = min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor;
779
+ material.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );
780
+ #else
781
+ material.specularColor = vec3( 0.04 );
782
+ material.specularColorBlended = mix( material.specularColor, diffuseColor.rgb, metalnessFactor );
783
+ material.specularF90 = 1.0;
784
+ #endif
785
+ #ifdef USE_CLEARCOAT
786
+ material.clearcoat = clearcoat;
787
+ material.clearcoatRoughness = clearcoatRoughness;
788
+ material.clearcoatF0 = vec3( 0.04 );
789
+ material.clearcoatF90 = 1.0;
790
+ #ifdef USE_CLEARCOATMAP
791
+ material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;
792
+ #endif
793
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
794
+ material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;
795
+ #endif
796
+ material.clearcoat = saturate( material.clearcoat ); material.clearcoatRoughness = max( material.clearcoatRoughness, 0.045 );
797
+ material.clearcoatRoughness += geometryRoughness;
798
+ material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );
799
+ #endif
800
+ #ifdef USE_DISPERSION
801
+ material.dispersion = dispersion;
802
+ #endif
803
+ #ifdef USE_RETROREFLECTION
804
+ material.retroreflectivity = retroreflectivity;
805
+ #endif
806
+ #ifdef USE_IRIDESCENCE
807
+ material.iridescence = iridescence;
808
+ material.iridescenceIOR = iridescenceIOR;
809
+ #ifdef USE_IRIDESCENCEMAP
810
+ material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;
811
+ #endif
812
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
813
+ material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;
814
+ #else
815
+ material.iridescenceThickness = iridescenceThicknessMaximum;
816
+ #endif
817
+ #endif
818
+ #ifdef USE_SHEEN
819
+ material.sheenColor = sheenColor;
820
+ #ifdef USE_SHEEN_COLORMAP
821
+ material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;
822
+ #endif
823
+ material.sheenRoughness = clamp( sheenRoughness, 0.0001, 1.0 );
824
+ #ifdef USE_SHEEN_ROUGHNESSMAP
825
+ material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;
826
+ #endif
827
+ #endif
828
+ #ifdef USE_ANISOTROPY
829
+ #ifdef USE_ANISOTROPYMAP
830
+ mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );
831
+ vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;
832
+ vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;
833
+ #else
834
+ vec2 anisotropyV = anisotropyVector;
835
+ #endif
836
+ material.anisotropy = length( anisotropyV );
837
+ if( material.anisotropy == 0.0 ) {
838
+ anisotropyV = vec2( 1.0, 0.0 );
839
+ } else {
840
+ anisotropyV /= material.anisotropy;
841
+ material.anisotropy = saturate( material.anisotropy );
842
+ }
843
+ material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );
844
+ material.anisotropyT = tbn[ 0 ] * anisotropyV.x + tbn[ 1 ] * anisotropyV.y;
845
+ material.anisotropyB = tbn[ 1 ] * anisotropyV.x - tbn[ 0 ] * anisotropyV.y;
846
+ #endif`,lights_physical_pars_fragment:`uniform sampler2D dfgLUT;
847
+ struct PhysicalMaterial {
848
+ vec3 diffuseColor;
849
+ vec3 diffuseContribution;
850
+ vec3 specularColor;
851
+ vec3 specularColorBlended;
852
+ float roughness;
853
+ float metalness;
854
+ float specularF90;
855
+ float dispersion;
856
+ vec2 dfg;
857
+ vec3 multiScatteringCompensation;
858
+ #ifdef USE_DIFFUSE_ROUGHNESS
859
+ float diffuseRoughness;
860
+ #endif
861
+ #ifdef USE_RETROREFLECTION
862
+ float retroreflectivity;
863
+ #endif
864
+ #ifdef USE_CLEARCOAT
865
+ float clearcoat;
866
+ float clearcoatRoughness;
867
+ vec3 clearcoatF0;
868
+ float clearcoatF90;
869
+ #endif
870
+ #ifdef USE_IRIDESCENCE
871
+ float iridescence;
872
+ float iridescenceIOR;
873
+ float iridescenceThickness;
874
+ vec3 iridescenceFresnel;
875
+ vec3 iridescenceF0Dielectric;
876
+ vec3 iridescenceF0Metallic;
877
+ #endif
878
+ #ifdef USE_SHEEN
879
+ vec3 sheenColor;
880
+ float sheenRoughness;
881
+ #endif
882
+ #ifdef IOR
883
+ float ior;
884
+ #endif
885
+ #ifdef USE_TRANSMISSION
886
+ float transmission;
887
+ float transmissionAlpha;
888
+ float thickness;
889
+ float attenuationDistance;
890
+ vec3 attenuationColor;
891
+ #endif
892
+ #ifdef USE_ANISOTROPY
893
+ float anisotropy;
894
+ float alphaT;
895
+ vec3 anisotropyT;
896
+ vec3 anisotropyB;
897
+ #endif
898
+ };
899
+ vec3 clearcoatSpecularDirect = vec3( 0.0 );
900
+ vec3 clearcoatSpecularIndirect = vec3( 0.0 );
901
+ vec3 sheenSpecularDirect = vec3( 0.0 );
902
+ vec3 sheenSpecularIndirect = vec3(0.0 );
903
+ vec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {
904
+ float x = clamp( 1.0 - dotVH, 0.0, 1.0 );
905
+ float x2 = x * x;
906
+ float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );
907
+ return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );
908
+ }
909
+ #ifdef USE_DIFFUSE_ROUGHNESS
910
+ const float EON_EPSILON = 1e-7;
911
+ float FON_DirectionalAlbedo( const in float mu, const in float roughness, const in float A ) {
912
+ float muComp = 1.0 - mu;
913
+ float gOverPi = muComp * ( 0.0571085289 + muComp * ( 0.491881867 + muComp * ( - 0.332181442 + muComp * 0.0714429953 ) ) );
914
+ return A * ( 1.0 + roughness * gOverPi );
915
+ }
916
+ vec3 BRDF_EON( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 diffuseColor, const in float roughness ) {
917
+ vec3 rho = saturate( diffuseColor );
918
+ if ( roughness <= EON_EPSILON ) return BRDF_Lambert( rho );
919
+ float dotNL = saturate( dot( normal, lightDir ) );
920
+ float dotNV = saturate( dot( normal, viewDir ) );
921
+ float s = dot( lightDir, viewDir ) - dotNL * dotNV;
922
+ float sOverT = ( s > 0.0 ) ? s / max( max( dotNL, dotNV ), EON_EPSILON ) : s;
923
+ float A = 1.0 / ( 1.0 + ( 0.5 - 2.0 / ( 3.0 * PI ) ) * roughness );
924
+ vec3 singleScatter = rho * RECIPROCAL_PI * A * ( 1.0 + roughness * sOverT );
925
+ float averageAlbedo = A * ( 1.0 + ( 2.0 / 3.0 - 28.0 / ( 15.0 * PI ) ) * roughness );
926
+ float albedoV = FON_DirectionalAlbedo( dotNV, roughness, A );
927
+ float albedoL = FON_DirectionalAlbedo( dotNL, roughness, A );
928
+ vec3 rhoMultiScatter = rho * rho * averageAlbedo / max( vec3( EON_EPSILON ), vec3( 1.0 ) - rho * ( 1.0 - averageAlbedo ) );
929
+ vec3 multiScatter = rhoMultiScatter * RECIPROCAL_PI
930
+ * max( EON_EPSILON, 1.0 - albedoV )
931
+ * max( EON_EPSILON, 1.0 - albedoL )
932
+ / max( EON_EPSILON, 1.0 - averageAlbedo );
933
+ return singleScatter + multiScatter;
934
+ }
935
+ vec3 EON_DirectionalAlbedo( const in vec3 diffuseColor, const in float roughness, const in float dotNV ) {
936
+ vec3 rho = saturate( diffuseColor );
937
+ if ( roughness <= EON_EPSILON ) return rho;
938
+ float A = 1.0 / ( 1.0 + ( 0.5 - 2.0 / ( 3.0 * PI ) ) * roughness );
939
+ float directionalAlbedo = FON_DirectionalAlbedo( dotNV, roughness, A );
940
+ float averageAlbedo = A * ( 1.0 + ( 2.0 / 3.0 - 28.0 / ( 15.0 * PI ) ) * roughness );
941
+ vec3 rhoMultiScatter = rho * rho * averageAlbedo / max( vec3( EON_EPSILON ), vec3( 1.0 ) - rho * ( 1.0 - averageAlbedo ) );
942
+ return rho * directionalAlbedo + rhoMultiScatter * ( 1.0 - directionalAlbedo );
943
+ }
944
+ #endif
945
+ float V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {
946
+ float a2 = pow2( alpha );
947
+ float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
948
+ float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
949
+ return 0.5 / max( gv + gl, EPSILON );
950
+ }
951
+ float D_GGX( const in float alpha, const in float dotNH ) {
952
+ float a2 = pow2( alpha );
953
+ float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;
954
+ return RECIPROCAL_PI * a2 / pow2( denom );
955
+ }
956
+ #ifdef USE_ANISOTROPY
957
+ float V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {
958
+ float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );
959
+ float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );
960
+ return 0.5 / max( gv + gl, EPSILON );
961
+ }
962
+ float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {
963
+ float a2 = alphaT * alphaB;
964
+ highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );
965
+ highp float v2 = dot( v, v );
966
+ float w2 = a2 / v2;
967
+ return RECIPROCAL_PI * a2 * pow2 ( w2 );
968
+ }
969
+ #endif
970
+ #ifdef USE_CLEARCOAT
971
+ vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {
972
+ vec3 f0 = material.clearcoatF0;
973
+ float f90 = material.clearcoatF90;
974
+ float roughness = max( material.clearcoatRoughness, 0.045 );
975
+ float alpha = pow2( roughness );
976
+ vec3 halfDir = normalize( lightDir + viewDir );
977
+ float dotNL = saturate( dot( normal, lightDir ) );
978
+ float dotNV = saturate( dot( normal, viewDir ) );
979
+ float dotNH = saturate( dot( normal, halfDir ) );
980
+ float dotVH = saturate( dot( viewDir, halfDir ) );
981
+ vec3 F = F_Schlick( f0, f90, dotVH );
982
+ float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
983
+ float D = D_GGX( alpha, dotNH );
984
+ return F * ( V * D );
985
+ }
986
+ #endif
987
+ vec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {
988
+ vec3 f0 = material.specularColorBlended;
989
+ float f90 = material.specularF90;
990
+ float roughness = max( material.roughness, 0.045 );
991
+ float alpha = pow2( roughness );
992
+ vec3 halfDir = normalize( lightDir + viewDir );
993
+ float dotNL = saturate( dot( normal, lightDir ) );
994
+ float dotNV = saturate( dot( normal, viewDir ) );
995
+ float dotNH = saturate( dot( normal, halfDir ) );
996
+ float dotVH = saturate( dot( viewDir, halfDir ) );
997
+ vec3 F = F_Schlick( f0, f90, dotVH );
998
+ #ifdef USE_IRIDESCENCE
999
+ F = mix( F, material.iridescenceFresnel, material.iridescence );
1000
+ #endif
1001
+ #ifdef USE_ANISOTROPY
1002
+ float dotTL = dot( material.anisotropyT, lightDir );
1003
+ float dotTV = dot( material.anisotropyT, viewDir );
1004
+ float dotTH = dot( material.anisotropyT, halfDir );
1005
+ float dotBL = dot( material.anisotropyB, lightDir );
1006
+ float dotBV = dot( material.anisotropyB, viewDir );
1007
+ float dotBH = dot( material.anisotropyB, halfDir );
1008
+ float alphaT = max( material.alphaT, alpha );
1009
+ float V = V_GGX_SmithCorrelated_Anisotropic( alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );
1010
+ float D = D_GGX_Anisotropic( alphaT, alpha, dotNH, dotTH, dotBH );
1011
+ #else
1012
+ float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );
1013
+ float D = D_GGX( alpha, dotNH );
1014
+ #endif
1015
+ return F * ( V * D );
1016
+ }
1017
+ vec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {
1018
+ const float LUT_SIZE = 64.0;
1019
+ const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;
1020
+ const float LUT_BIAS = 0.5 / LUT_SIZE;
1021
+ float dotNV = saturate( dot( N, V ) );
1022
+ vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );
1023
+ uv = uv * LUT_SCALE + LUT_BIAS;
1024
+ return uv;
1025
+ }
1026
+ float LTC_ClippedSphereFormFactor( const in vec3 f ) {
1027
+ float l = length( f );
1028
+ return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );
1029
+ }
1030
+ vec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {
1031
+ float x = dot( v1, v2 );
1032
+ float y = abs( x );
1033
+ float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;
1034
+ float b = 3.4175940 + ( 4.1616724 + y ) * y;
1035
+ float v = a / b;
1036
+ float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;
1037
+ return cross( v1, v2 ) * theta_sintheta;
1038
+ }
1039
+ vec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {
1040
+ vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];
1041
+ vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];
1042
+ vec3 lightNormal = cross( v1, v2 );
1043
+ if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );
1044
+ vec3 T1, T2;
1045
+ T1 = normalize( V - N * dot( V, N ) );
1046
+ T2 = - cross( N, T1 );
1047
+ mat3 mat = mInv * transpose( mat3( T1, T2, N ) );
1048
+ vec3 coords[ 4 ];
1049
+ coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );
1050
+ coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );
1051
+ coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );
1052
+ coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );
1053
+ coords[ 0 ] = normalize( coords[ 0 ] );
1054
+ coords[ 1 ] = normalize( coords[ 1 ] );
1055
+ coords[ 2 ] = normalize( coords[ 2 ] );
1056
+ coords[ 3 ] = normalize( coords[ 3 ] );
1057
+ vec3 vectorFormFactor = vec3( 0.0 );
1058
+ vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );
1059
+ vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );
1060
+ vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );
1061
+ vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );
1062
+ float result = LTC_ClippedSphereFormFactor( vectorFormFactor );
1063
+ return vec3( result );
1064
+ }
1065
+ #if defined( USE_SHEEN )
1066
+ float D_Charlie( float roughness, float dotNH ) {
1067
+ float alpha = pow2( roughness );
1068
+ float invAlpha = 1.0 / alpha;
1069
+ float cos2h = dotNH * dotNH;
1070
+ float sin2h = max( 1.0 - cos2h, 0.0078125 );
1071
+ return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );
1072
+ }
1073
+ float V_Neubelt( float dotNV, float dotNL ) {
1074
+ return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );
1075
+ }
1076
+ vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {
1077
+ vec3 halfDir = normalize( lightDir + viewDir );
1078
+ float dotNL = saturate( dot( normal, lightDir ) );
1079
+ float dotNV = saturate( dot( normal, viewDir ) );
1080
+ float dotNH = saturate( dot( normal, halfDir ) );
1081
+ float D = D_Charlie( sheenRoughness, dotNH );
1082
+ float V = V_Neubelt( dotNV, dotNL );
1083
+ return sheenColor * ( D * V );
1084
+ }
1085
+ #endif
1086
+ float IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {
1087
+ float dotNV = saturate( dot( normal, viewDir ) );
1088
+ float r2 = roughness * roughness;
1089
+ float rInv = 1.0 / ( roughness + 0.1 );
1090
+ float a = -1.9362 + 1.0678 * roughness + 0.4573 * r2 - 0.8469 * rInv;
1091
+ float b = -0.6014 + 0.5538 * roughness - 0.4670 * r2 - 0.1255 * rInv;
1092
+ float DG = exp( a * dotNV + b );
1093
+ return saturate( DG );
1094
+ }
1095
+ vec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {
1096
+ float dotNV = saturate( dot( normal, viewDir ) );
1097
+ vec2 fab = texture2D( dfgLUT, vec2( roughness, dotNV ) ).rg;
1098
+ return specularColor * fab.x + specularF90 * fab.y;
1099
+ }
1100
+ #ifdef USE_IRIDESCENCE
1101
+ void computeMultiscatteringIridescence( const in vec2 fab, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, inout vec3 singleScatter, inout vec3 multiScatter ) {
1102
+ #else
1103
+ void computeMultiscattering( const in vec2 fab, const in vec3 specularColor, const in float specularF90, inout vec3 singleScatter, inout vec3 multiScatter ) {
1104
+ #endif
1105
+ #ifdef USE_IRIDESCENCE
1106
+ vec3 Fr = mix( specularColor, iridescenceF0, iridescence );
1107
+ #else
1108
+ vec3 Fr = specularColor;
1109
+ #endif
1110
+ vec3 FssEss = Fr * fab.x + specularF90 * fab.y;
1111
+ float Ess = fab.x + fab.y;
1112
+ float Ems = 1.0 - Ess;
1113
+ vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );
1114
+ singleScatter += FssEss;
1115
+ multiScatter += Fms * Ems;
1116
+ }
1117
+ #if NUM_RECT_AREA_LIGHTS > 0
1118
+ void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
1119
+ vec3 normal = geometryNormal;
1120
+ vec3 viewDir = geometryViewDir;
1121
+ vec3 position = geometryPosition;
1122
+ vec3 lightPos = rectAreaLight.position;
1123
+ vec3 halfWidth = rectAreaLight.halfWidth;
1124
+ vec3 halfHeight = rectAreaLight.halfHeight;
1125
+ vec3 lightColor = rectAreaLight.color;
1126
+ float roughness = material.roughness;
1127
+ vec3 rectCoords[ 4 ];
1128
+ rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; rectCoords[ 1 ] = lightPos - halfWidth - halfHeight;
1129
+ rectCoords[ 2 ] = lightPos - halfWidth + halfHeight;
1130
+ rectCoords[ 3 ] = lightPos + halfWidth + halfHeight;
1131
+ vec2 uv = LTC_Uv( normal, viewDir, roughness );
1132
+ vec4 t1 = texture2D( ltc_1, uv );
1133
+ vec4 t2 = texture2D( ltc_2, uv );
1134
+ mat3 mInv = mat3(
1135
+ vec3( t1.x, 0, t1.y ),
1136
+ vec3( 0, 1, 0 ),
1137
+ vec3( t1.z, 0, t1.w )
1138
+ );
1139
+ vec3 fresnel = ( material.specularColorBlended * t2.x + ( material.specularF90 - material.specularColorBlended ) * t2.y );
1140
+ reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );
1141
+ reflectedLight.directDiffuse += lightColor * material.diffuseContribution * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );
1142
+ #ifdef USE_CLEARCOAT
1143
+ vec3 Ncc = geometryClearcoatNormal;
1144
+ vec2 uvClearcoat = LTC_Uv( Ncc, viewDir, material.clearcoatRoughness );
1145
+ vec4 t1Clearcoat = texture2D( ltc_1, uvClearcoat );
1146
+ vec4 t2Clearcoat = texture2D( ltc_2, uvClearcoat );
1147
+ mat3 mInvClearcoat = mat3(
1148
+ vec3( t1Clearcoat.x, 0, t1Clearcoat.y ),
1149
+ vec3( 0, 1, 0 ),
1150
+ vec3( t1Clearcoat.z, 0, t1Clearcoat.w )
1151
+ );
1152
+ vec3 fresnelClearcoat = material.clearcoatF0 * t2Clearcoat.x + ( material.clearcoatF90 - material.clearcoatF0 ) * t2Clearcoat.y;
1153
+ clearcoatSpecularDirect += lightColor * fresnelClearcoat * LTC_Evaluate( Ncc, viewDir, position, mInvClearcoat, rectCoords );
1154
+ #endif
1155
+ }
1156
+ #endif
1157
+ void RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
1158
+ float dotNL = saturate( dot( geometryNormal, directLight.direction ) );
1159
+ vec3 irradiance = dotNL * directLight.color;
1160
+ #ifdef USE_CLEARCOAT
1161
+ float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );
1162
+ vec3 ccIrradiance = dotNLcc * directLight.color;
1163
+ clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );
1164
+ #endif
1165
+ #ifdef USE_SHEEN
1166
+
1167
+ sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );
1168
+
1169
+ float sheenAlbedoV = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
1170
+ float sheenAlbedoL = IBLSheenBRDF( geometryNormal, directLight.direction, material.sheenRoughness );
1171
+
1172
+ float sheenEnergyComp = 1.0 - max3( material.sheenColor ) * max( sheenAlbedoV, sheenAlbedoL );
1173
+
1174
+ irradiance *= sheenEnergyComp;
1175
+
1176
+ #endif
1177
+ vec3 specularBRDF = BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );
1178
+ #ifdef USE_RETROREFLECTION
1179
+ vec3 retroViewDir = reflect( - geometryViewDir, geometryNormal );
1180
+ vec3 retroSpecularBRDF = BRDF_GGX( directLight.direction, retroViewDir, geometryNormal, material );
1181
+ specularBRDF = mix( specularBRDF, retroSpecularBRDF, saturate( material.retroreflectivity ) );
1182
+ #endif
1183
+ reflectedLight.directSpecular += irradiance * specularBRDF * material.multiScatteringCompensation;
1184
+ vec3 halfDir = normalize( directLight.direction + geometryViewDir );
1185
+ float dotVH = saturate( dot( geometryViewDir, halfDir ) );
1186
+ vec3 F = F_Schlick( material.specularColor, material.specularF90, dotVH );
1187
+ #ifdef USE_RETROREFLECTION
1188
+ vec3 retroHalfDir = normalize( directLight.direction + retroViewDir );
1189
+ float dotRetroVH = saturate( dot( retroViewDir, retroHalfDir ) );
1190
+ vec3 retroF = F_Schlick( material.specularColor, material.specularF90, dotRetroVH );
1191
+ F = mix( F, retroF, saturate( material.retroreflectivity ) );
1192
+ #endif
1193
+ #ifdef USE_DIFFUSE_ROUGHNESS
1194
+ vec3 diffuseBRDF = BRDF_EON( directLight.direction, geometryViewDir, geometryNormal, material.diffuseColor, material.diffuseRoughness ) * ( 1.0 - material.metalness );
1195
+ #else
1196
+ vec3 diffuseBRDF = BRDF_Lambert( material.diffuseContribution );
1197
+ #endif
1198
+ reflectedLight.directDiffuse += irradiance * diffuseBRDF * ( 1.0 - F );
1199
+ }
1200
+ void RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {
1201
+ vec3 singleScattering = vec3( 0.0 );
1202
+ vec3 multiScattering = vec3( 0.0 );
1203
+ #ifdef USE_IRIDESCENCE
1204
+ computeMultiscatteringIridescence( material.dfg, material.specularColor, material.specularF90, material.iridescence, material.iridescenceF0Dielectric, singleScattering, multiScattering );
1205
+ #else
1206
+ computeMultiscattering( material.dfg, material.specularColor, material.specularF90, singleScattering, multiScattering );
1207
+ #endif
1208
+ #ifdef USE_DIFFUSE_ROUGHNESS
1209
+ float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
1210
+ vec3 diffuseAlbedo = EON_DirectionalAlbedo( material.diffuseColor, material.diffuseRoughness, dotNV ) * ( 1.0 - material.metalness );
1211
+ vec3 diffuse = irradiance * RECIPROCAL_PI * diffuseAlbedo * ( 1.0 - singleScattering - multiScattering );
1212
+ #else
1213
+ vec3 diffuse = irradiance * BRDF_Lambert( material.diffuseContribution ) * ( 1.0 - singleScattering - multiScattering );
1214
+ #endif
1215
+ #ifdef USE_SHEEN
1216
+ float sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
1217
+ sheenSpecularIndirect += irradiance * material.sheenColor * sheenAlbedo * RECIPROCAL_PI;
1218
+ float sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;
1219
+ diffuse *= sheenEnergyComp;
1220
+ #endif
1221
+ reflectedLight.indirectDiffuse += diffuse;
1222
+ }
1223
+ void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {
1224
+ #ifdef USE_CLEARCOAT
1225
+ clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );
1226
+ #endif
1227
+ #ifdef USE_SHEEN
1228
+ sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness ) * RECIPROCAL_PI;
1229
+ #endif
1230
+ vec3 singleScatteringDielectric = vec3( 0.0 );
1231
+ vec3 multiScatteringDielectric = vec3( 0.0 );
1232
+ vec3 singleScatteringMetallic = vec3( 0.0 );
1233
+ vec3 multiScatteringMetallic = vec3( 0.0 );
1234
+ #ifdef USE_IRIDESCENCE
1235
+ computeMultiscatteringIridescence( material.dfg, material.specularColor, material.specularF90, material.iridescence, material.iridescenceF0Dielectric, singleScatteringDielectric, multiScatteringDielectric );
1236
+ computeMultiscatteringIridescence( material.dfg, material.diffuseColor, material.specularF90, material.iridescence, material.iridescenceF0Metallic, singleScatteringMetallic, multiScatteringMetallic );
1237
+ #else
1238
+ computeMultiscattering( material.dfg, material.specularColor, material.specularF90, singleScatteringDielectric, multiScatteringDielectric );
1239
+ computeMultiscattering( material.dfg, material.diffuseColor, material.specularF90, singleScatteringMetallic, multiScatteringMetallic );
1240
+ #endif
1241
+ vec3 singleScattering = mix( singleScatteringDielectric, singleScatteringMetallic, material.metalness );
1242
+ vec3 multiScattering = mix( multiScatteringDielectric, multiScatteringMetallic, material.metalness );
1243
+ vec3 totalScatteringDielectric = singleScatteringDielectric + multiScatteringDielectric;
1244
+ #ifdef USE_DIFFUSE_ROUGHNESS
1245
+ float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
1246
+ vec3 diffuse = EON_DirectionalAlbedo( material.diffuseColor, material.diffuseRoughness, dotNV ) * ( 1.0 - material.metalness ) * ( 1.0 - totalScatteringDielectric );
1247
+ #else
1248
+ vec3 diffuse = material.diffuseContribution * ( 1.0 - totalScatteringDielectric );
1249
+ #endif
1250
+ vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;
1251
+ vec3 indirectSpecular = radiance * singleScattering;
1252
+ indirectSpecular += multiScattering * cosineWeightedIrradiance;
1253
+ vec3 indirectDiffuse = diffuse * cosineWeightedIrradiance;
1254
+ #ifdef USE_SHEEN
1255
+ float sheenAlbedo = IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );
1256
+ float sheenEnergyComp = 1.0 - max3( material.sheenColor ) * sheenAlbedo;
1257
+ indirectSpecular *= sheenEnergyComp;
1258
+ indirectDiffuse *= sheenEnergyComp;
1259
+ #endif
1260
+ reflectedLight.indirectSpecular += indirectSpecular;
1261
+ reflectedLight.indirectDiffuse += indirectDiffuse;
1262
+ }
1263
+ #define RE_Direct RE_Direct_Physical
1264
+ #define RE_Direct_RectArea RE_Direct_RectArea_Physical
1265
+ #define RE_IndirectDiffuse RE_IndirectDiffuse_Physical
1266
+ #define RE_IndirectSpecular RE_IndirectSpecular_Physical
1267
+ float computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {
1268
+ return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );
1269
+ }`,lights_fragment_begin:`
1270
+ vec3 geometryPosition = - vViewPosition;
1271
+ vec3 geometryNormal = normal;
1272
+ vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
1273
+ vec3 geometryClearcoatNormal = vec3( 0.0 );
1274
+ #ifdef USE_CLEARCOAT
1275
+ geometryClearcoatNormal = clearcoatNormal;
1276
+ #endif
1277
+ #ifdef USE_IRIDESCENCE
1278
+ float dotNVi = saturate( dot( normal, geometryViewDir ) );
1279
+ if ( material.iridescenceThickness == 0.0 ) {
1280
+ material.iridescence = 0.0;
1281
+ } else {
1282
+ material.iridescence = saturate( material.iridescence );
1283
+ }
1284
+ if ( material.iridescence > 0.0 ) {
1285
+ vec3 iridescenceFresnelDielectric = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );
1286
+ vec3 iridescenceFresnelMetallic = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.diffuseColor );
1287
+ material.iridescenceFresnel = mix( iridescenceFresnelDielectric, iridescenceFresnelMetallic, material.metalness );
1288
+ material.iridescenceF0Dielectric = Schlick_to_F0( iridescenceFresnelDielectric, 1.0, dotNVi );
1289
+ material.iridescenceF0Metallic = Schlick_to_F0( iridescenceFresnelMetallic, 1.0, dotNVi );
1290
+ }
1291
+ #endif
1292
+ #ifdef STANDARD
1293
+ float dotNVms = saturate( dot( geometryNormal, geometryViewDir ) );
1294
+ material.dfg = texture2D( dfgLUT, vec2( material.roughness, dotNVms ) ).rg;
1295
+ #if ( NUM_SUN_LIGHTS > 0 || NUM_DIR_LIGHTS > 0 || NUM_POINT_LIGHTS > 0 || NUM_SPOT_LIGHTS > 0 )
1296
+ float EssMs = material.dfg.x + material.dfg.y;
1297
+ material.multiScatteringCompensation = 1.0 + material.specularColorBlended * ( 1.0 / EssMs - 1.0 );
1298
+ #endif
1299
+ #endif
1300
+ IncidentLight directLight;
1301
+ #if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )
1302
+ PointLight pointLight;
1303
+ #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0
1304
+ PointLightShadow pointLightShadow;
1305
+ #endif
1306
+ #pragma unroll_loop_start
1307
+ for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {
1308
+ pointLight = pointLights[ i ];
1309
+ getPointLightInfo( pointLight, geometryPosition, directLight );
1310
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS ) && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )
1311
+ pointLightShadow = pointLightShadows[ i ];
1312
+ directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
1313
+ #endif
1314
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1315
+ }
1316
+ #pragma unroll_loop_end
1317
+ #endif
1318
+ #if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )
1319
+ SpotLight spotLight;
1320
+ vec4 spotColor;
1321
+ vec3 spotLightCoord;
1322
+ bool inSpotLightMap;
1323
+ #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
1324
+ SpotLightShadow spotLightShadow;
1325
+ #endif
1326
+ #pragma unroll_loop_start
1327
+ for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {
1328
+ spotLight = spotLights[ i ];
1329
+ getSpotLightInfo( spotLight, geometryPosition, directLight );
1330
+ #if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
1331
+ #define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX
1332
+ #elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
1333
+ #define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS
1334
+ #else
1335
+ #define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
1336
+ #endif
1337
+ #if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )
1338
+ spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;
1339
+ inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );
1340
+ spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );
1341
+ directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;
1342
+ #endif
1343
+ #undef SPOT_LIGHT_MAP_INDEX
1344
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
1345
+ spotLightShadow = spotLightShadows[ i ];
1346
+ directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
1347
+ #endif
1348
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1349
+ }
1350
+ #pragma unroll_loop_end
1351
+ #endif
1352
+ #if ( NUM_SUN_LIGHTS > 0 ) && defined( RE_Direct )
1353
+ SunLight sunLight;
1354
+ #if defined( USE_SHADOWMAP ) && NUM_SUN_LIGHT_SHADOWS > 0
1355
+ SunLightShadow sunLightShadow;
1356
+ #endif
1357
+ #pragma unroll_loop_start
1358
+ for ( int i = 0; i < NUM_SUN_LIGHTS; i ++ ) {
1359
+ sunLight = sunLights[ i ];
1360
+ getSunLightInfo( sunLight, directLight );
1361
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SUN_LIGHT_SHADOWS )
1362
+ sunLightShadow = sunLightShadows[ i ];
1363
+ directLight.color *= ( directLight.visible && receiveShadow ) ? getSunShadow( sunShadowMap[ i ], sunLightShadow, UNROLLED_LOOP_INDEX ) : 1.0;
1364
+ #endif
1365
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1366
+ }
1367
+ #pragma unroll_loop_end
1368
+ #endif
1369
+ #if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )
1370
+ DirectionalLight directionalLight;
1371
+ #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0
1372
+ DirectionalLightShadow directionalLightShadow;
1373
+ #endif
1374
+ #pragma unroll_loop_start
1375
+ for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
1376
+ directionalLight = directionalLights[ i ];
1377
+ getDirectionalLightInfo( directionalLight, directLight );
1378
+ #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
1379
+ directionalLightShadow = directionalLightShadows[ i ];
1380
+ directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
1381
+ #endif
1382
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1383
+ }
1384
+ #pragma unroll_loop_end
1385
+ #endif
1386
+ #if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )
1387
+ RectAreaLight rectAreaLight;
1388
+ #pragma unroll_loop_start
1389
+ for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
1390
+ rectAreaLight = rectAreaLights[ i ];
1391
+ RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1392
+ }
1393
+ #pragma unroll_loop_end
1394
+ #endif
1395
+ #if defined( RE_IndirectDiffuse )
1396
+ vec3 iblIrradiance = vec3( 0.0 );
1397
+ vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );
1398
+ #if defined( USE_LIGHT_PROBES )
1399
+ irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );
1400
+ #endif
1401
+ #if ( NUM_HEMI_LIGHTS > 0 )
1402
+ #pragma unroll_loop_start
1403
+ for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
1404
+ irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );
1405
+ }
1406
+ #pragma unroll_loop_end
1407
+ #endif
1408
+ #if NUM_LIGHT_PROBE_GRIDS > 0
1409
+ vec3 probeWorldPos = ( ( vec4( geometryPosition, 1.0 ) - viewMatrix[ 3 ] ) * viewMatrix ).xyz;
1410
+ vec3 probeWorldNormal = transformNormalByInverseViewMatrix( geometryNormal, viewMatrix );
1411
+ int probeGrid = - 1;
1412
+ #pragma unroll_loop_start
1413
+ for ( int i = 0; i < NUM_LIGHT_PROBE_GRIDS; i ++ ) {
1414
+ if ( isInsideLightProbeGrid( probeWorldPos, probeWorldNormal, probesMin[ i ], probesMax[ i ], probesResolution[ i ] ) ) probeGrid = UNROLLED_LOOP_INDEX;
1415
+ }
1416
+ #pragma unroll_loop_end
1417
+ #pragma unroll_loop_start
1418
+ for ( int i = 0; i < NUM_LIGHT_PROBE_GRIDS; i ++ ) {
1419
+ if ( probeGrid == UNROLLED_LOOP_INDEX ) irradiance += getLightProbeGridIrradiance( probesSH[ i ], probesMin[ i ], probesMax[ i ], probesResolution[ i ], probeWorldPos, probeWorldNormal );
1420
+ }
1421
+ #pragma unroll_loop_end
1422
+ #endif
1423
+ #endif
1424
+ #if defined( RE_IndirectSpecular )
1425
+ vec3 radiance = vec3( 0.0 );
1426
+ vec3 clearcoatRadiance = vec3( 0.0 );
1427
+ #endif`,lights_fragment_maps:`#if defined( RE_IndirectDiffuse )
1428
+ #ifdef USE_LIGHTMAP
1429
+ vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
1430
+ vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;
1431
+ irradiance += lightMapIrradiance;
1432
+ #endif
1433
+ #if defined( USE_ENVMAP ) && defined( ENVMAP_TYPE_PMREM )
1434
+ #if defined( STANDARD ) || defined( LAMBERT ) || defined( PHONG )
1435
+ iblIrradiance += getIBLIrradiance( geometryNormal );
1436
+ #endif
1437
+ #endif
1438
+ #endif
1439
+ #if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )
1440
+ #ifdef USE_ANISOTROPY
1441
+ vec3 iblRadiance = getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );
1442
+ #else
1443
+ vec3 iblRadiance = getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );
1444
+ #endif
1445
+ #ifdef USE_RETROREFLECTION
1446
+ #ifdef USE_ANISOTROPY
1447
+ vec3 retroIBLRadiance = getIBLAnisotropyRetroRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );
1448
+ #else
1449
+ vec3 retroIBLRadiance = getIBLRetroRadiance( geometryViewDir, geometryNormal, material.roughness );
1450
+ #endif
1451
+ iblRadiance = mix( iblRadiance, retroIBLRadiance, saturate( material.retroreflectivity ) );
1452
+ #endif
1453
+ radiance += iblRadiance;
1454
+ #ifdef USE_CLEARCOAT
1455
+ clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );
1456
+ #endif
1457
+ #endif`,lights_fragment_end:`#if defined( RE_IndirectDiffuse )
1458
+ #if defined( LAMBERT ) || defined( PHONG )
1459
+ irradiance += iblIrradiance;
1460
+ #endif
1461
+ RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1462
+ #endif
1463
+ #if defined( RE_IndirectSpecular )
1464
+ RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
1465
+ #endif`,lightprobes_pars_fragment:`#if NUM_LIGHT_PROBE_GRIDS > 0
1466
+ uniform highp sampler3D probesSH[ NUM_LIGHT_PROBE_GRIDS ];
1467
+ uniform vec3 probesMin[ NUM_LIGHT_PROBE_GRIDS ];
1468
+ uniform vec3 probesMax[ NUM_LIGHT_PROBE_GRIDS ];
1469
+ uniform vec3 probesResolution[ NUM_LIGHT_PROBE_GRIDS ];
1470
+ bool isInsideLightProbeGrid( vec3 worldPos, vec3 worldNormal, vec3 probesMin, vec3 probesMax, vec3 probesResolution ) {
1471
+ vec3 spacing = ( probesMax - probesMin ) / probesResolution;
1472
+ vec3 samplePos = worldPos + worldNormal * spacing * 0.5;
1473
+ vec3 margin = spacing * 0.01;
1474
+ return all( greaterThanEqual( samplePos, probesMin - margin ) ) && all( lessThanEqual( samplePos, probesMax + margin ) );
1475
+ }
1476
+ vec3 getLightProbeGridIrradiance( highp sampler3D probesSH, vec3 probesMin, vec3 probesMax, vec3 probesResolution, vec3 worldPos, vec3 worldNormal ) {
1477
+ vec3 res = probesResolution;
1478
+ vec3 gridRange = probesMax - probesMin;
1479
+ vec3 probeSpacing = gridRange / res;
1480
+ vec3 samplePos = worldPos + worldNormal * probeSpacing * 0.5;
1481
+ vec3 uvw = clamp( ( samplePos - probesMin ) / gridRange, 0.5 / res, 1.0 - 0.5 / res );
1482
+ float nz = res.z;
1483
+ float paddedSlices = nz + 2.0;
1484
+ float atlasDepth = 7.0 * paddedSlices;
1485
+ float uvZBase = uvw.z * nz + 1.0;
1486
+ vec4 s0 = texture( probesSH, vec3( uvw.xy, ( uvZBase ) / atlasDepth ) );
1487
+ vec4 s1 = texture( probesSH, vec3( uvw.xy, ( uvZBase + paddedSlices ) / atlasDepth ) );
1488
+ vec4 s2 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 2.0 * paddedSlices ) / atlasDepth ) );
1489
+ vec4 s3 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 3.0 * paddedSlices ) / atlasDepth ) );
1490
+ vec4 s4 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 4.0 * paddedSlices ) / atlasDepth ) );
1491
+ vec4 s5 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 5.0 * paddedSlices ) / atlasDepth ) );
1492
+ vec4 s6 = texture( probesSH, vec3( uvw.xy, ( uvZBase + 6.0 * paddedSlices ) / atlasDepth ) );
1493
+ vec3 c0 = s0.xyz;
1494
+ vec3 c1 = vec3( s0.w, s1.xy );
1495
+ vec3 c2 = vec3( s1.zw, s2.x );
1496
+ vec3 c3 = s2.yzw;
1497
+ vec3 c4 = s3.xyz;
1498
+ vec3 c5 = vec3( s3.w, s4.xy );
1499
+ vec3 c6 = vec3( s4.zw, s5.x );
1500
+ vec3 c7 = s5.yzw;
1501
+ vec3 c8 = s6.xyz;
1502
+ float x = worldNormal.x, y = worldNormal.y, z = worldNormal.z;
1503
+ vec3 result = c0 * 0.886227;
1504
+ result += c1 * 2.0 * 0.511664 * y;
1505
+ result += c2 * 2.0 * 0.511664 * z;
1506
+ result += c3 * 2.0 * 0.511664 * x;
1507
+ result += c4 * 2.0 * 0.429043 * x * y;
1508
+ result += c5 * 2.0 * 0.429043 * y * z;
1509
+ result += c6 * ( 0.743125 * z * z - 0.247708 );
1510
+ result += c7 * 2.0 * 0.429043 * x * z;
1511
+ result += c8 * 0.429043 * ( x * x - y * y );
1512
+ return max( result, vec3( 0.0 ) );
1513
+ }
1514
+ #endif`,logdepthbuf_fragment:`#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )
1515
+ gl_FragDepth = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;
1516
+ #endif`,logdepthbuf_pars_fragment:`#if defined( USE_LOGARITHMIC_DEPTH_BUFFER )
1517
+ uniform float logDepthBufFC;
1518
+ varying float vFragDepth;
1519
+ varying float vIsPerspective;
1520
+ #endif`,logdepthbuf_pars_vertex:`#ifdef USE_LOGARITHMIC_DEPTH_BUFFER
1521
+ varying float vFragDepth;
1522
+ varying float vIsPerspective;
1523
+ #endif`,logdepthbuf_vertex:`#ifdef USE_LOGARITHMIC_DEPTH_BUFFER
1524
+ vFragDepth = 1.0 + gl_Position.w;
1525
+ vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );
1526
+ #endif`,map_fragment:`#ifdef USE_MAP
1527
+ vec4 sampledDiffuseColor = texture2D( map, vMapUv );
1528
+ #ifdef DECODE_VIDEO_TEXTURE
1529
+ sampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );
1530
+ #endif
1531
+ diffuseColor *= sampledDiffuseColor;
1532
+ #endif`,map_pars_fragment:`#ifdef USE_MAP
1533
+ uniform sampler2D map;
1534
+ #endif`,map_particle_fragment:`#if defined( USE_MAP ) || defined( USE_ALPHAMAP )
1535
+ #if defined( USE_POINTS_UV )
1536
+ vec2 uv = vUv;
1537
+ #else
1538
+ vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;
1539
+ #endif
1540
+ #endif
1541
+ #ifdef USE_MAP
1542
+ diffuseColor *= texture2D( map, uv );
1543
+ #endif
1544
+ #ifdef USE_ALPHAMAP
1545
+ diffuseColor.a *= texture2D( alphaMap, uv ).g;
1546
+ #endif`,map_particle_pars_fragment:`#if defined( USE_POINTS_UV )
1547
+ varying vec2 vUv;
1548
+ #else
1549
+ #if defined( USE_MAP ) || defined( USE_ALPHAMAP )
1550
+ uniform mat3 uvTransform;
1551
+ #endif
1552
+ #endif
1553
+ #ifdef USE_MAP
1554
+ uniform sampler2D map;
1555
+ #endif
1556
+ #ifdef USE_ALPHAMAP
1557
+ uniform sampler2D alphaMap;
1558
+ #endif`,metalnessmap_fragment:`float metalnessFactor = metalness;
1559
+ #ifdef USE_METALNESSMAP
1560
+ vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );
1561
+ metalnessFactor *= texelMetalness.b;
1562
+ #endif`,metalnessmap_pars_fragment:`#ifdef USE_METALNESSMAP
1563
+ uniform sampler2D metalnessMap;
1564
+ #endif`,morphinstance_vertex:`#ifdef USE_INSTANCING_MORPH
1565
+ float morphTargetInfluences[ MORPHTARGETS_COUNT ];
1566
+ float morphTargetBaseInfluence = texelFetch( morphTexture, ivec2( 0, gl_InstanceID ), 0 ).r;
1567
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
1568
+ morphTargetInfluences[i] = texelFetch( morphTexture, ivec2( i + 1, gl_InstanceID ), 0 ).r;
1569
+ }
1570
+ #endif`,morphcolor_vertex:`#if defined( USE_MORPHCOLORS )
1571
+ #if defined( USE_COLOR_ALPHA )
1572
+ vColor *= morphTargetBaseInfluence;
1573
+ #elif defined( USE_COLOR )
1574
+ vColor.rgb *= morphTargetBaseInfluence;
1575
+ #endif
1576
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
1577
+ #if defined( USE_COLOR_ALPHA )
1578
+ if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];
1579
+ #elif defined( USE_COLOR )
1580
+ if ( morphTargetInfluences[ i ] != 0.0 ) vColor.rgb += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];
1581
+ #endif
1582
+ }
1583
+ #endif`,morphnormal_vertex:`#ifdef USE_MORPHNORMALS
1584
+ objectNormal *= morphTargetBaseInfluence;
1585
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
1586
+ if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];
1587
+ }
1588
+ #endif`,morphtarget_pars_vertex:`#ifdef USE_MORPHTARGETS
1589
+ #ifndef USE_INSTANCING_MORPH
1590
+ uniform float morphTargetBaseInfluence;
1591
+ uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];
1592
+ #endif
1593
+ uniform sampler2DArray morphTargetsTexture;
1594
+ uniform ivec2 morphTargetsTextureSize;
1595
+ vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {
1596
+ int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;
1597
+ int y = texelIndex / morphTargetsTextureSize.x;
1598
+ int x = texelIndex - y * morphTargetsTextureSize.x;
1599
+ ivec3 morphUV = ivec3( x, y, morphTargetIndex );
1600
+ return texelFetch( morphTargetsTexture, morphUV, 0 );
1601
+ }
1602
+ #endif`,morphtarget_vertex:`#ifdef USE_MORPHTARGETS
1603
+ transformed *= morphTargetBaseInfluence;
1604
+ for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {
1605
+ if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];
1606
+ }
1607
+ #endif`,normal_fragment_begin:`float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;
1608
+ #ifdef FLAT_SHADED
1609
+ vec3 fdx = dFdx( vViewPosition );
1610
+ vec3 fdy = dFdy( vViewPosition );
1611
+ vec3 normal = normalize( cross( fdx, fdy ) );
1612
+ #else
1613
+ vec3 normal = normalize( vNormal );
1614
+ #ifdef DOUBLE_SIDED
1615
+ normal *= faceDirection;
1616
+ #endif
1617
+ #endif
1618
+ #if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )
1619
+ #ifdef USE_TANGENT
1620
+ mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
1621
+ #else
1622
+ mat3 tbn = getTangentFrame( - vViewPosition, normal,
1623
+ #if defined( USE_NORMALMAP )
1624
+ vNormalMapUv
1625
+ #elif defined( USE_CLEARCOAT_NORMALMAP )
1626
+ vClearcoatNormalMapUv
1627
+ #else
1628
+ vUv
1629
+ #endif
1630
+ );
1631
+ #endif
1632
+ #ifdef DOUBLE_SIDED
1633
+ tbn[0] *= faceDirection;
1634
+ tbn[1] *= faceDirection;
1635
+ #endif
1636
+ #endif
1637
+ #ifdef USE_CLEARCOAT_NORMALMAP
1638
+ #ifdef USE_TANGENT
1639
+ mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );
1640
+ #else
1641
+ mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );
1642
+ #endif
1643
+ #ifdef DOUBLE_SIDED
1644
+ tbn2[0] *= faceDirection;
1645
+ tbn2[1] *= faceDirection;
1646
+ #endif
1647
+ #endif
1648
+ vec3 nonPerturbedNormal = normal;`,normal_fragment_maps:`#ifdef USE_NORMALMAP_OBJECTSPACE
1649
+ normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
1650
+ #ifdef FLIP_SIDED
1651
+ normal = - normal;
1652
+ #endif
1653
+ #ifdef DOUBLE_SIDED
1654
+ normal = normal * faceDirection;
1655
+ #endif
1656
+ normal = normalize( normalMatrix * normal );
1657
+ #elif defined( USE_NORMALMAP_TANGENTSPACE )
1658
+ vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;
1659
+ #if defined( USE_PACKED_NORMALMAP )
1660
+ mapN = vec3( mapN.xy, sqrt( saturate( 1.0 - dot( mapN.xy, mapN.xy ) ) ) );
1661
+ #endif
1662
+ mapN.xy *= normalScale;
1663
+ normal = normalize( tbn * mapN );
1664
+ #elif defined( USE_BUMPMAP )
1665
+ normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );
1666
+ #endif`,normal_pars_fragment:`#ifndef FLAT_SHADED
1667
+ varying vec3 vNormal;
1668
+ #ifdef USE_TANGENT
1669
+ varying vec3 vTangent;
1670
+ varying vec3 vBitangent;
1671
+ #endif
1672
+ #endif`,normal_pars_vertex:`#ifndef FLAT_SHADED
1673
+ varying vec3 vNormal;
1674
+ #ifdef USE_TANGENT
1675
+ varying vec3 vTangent;
1676
+ varying vec3 vBitangent;
1677
+ #endif
1678
+ #endif`,normal_vertex:`#ifndef FLAT_SHADED
1679
+ vNormal = normalize( transformedNormal );
1680
+ #ifdef USE_TANGENT
1681
+ vTangent = normalize( transformedTangent );
1682
+ vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );
1683
+ #ifdef FLIP_SIDED
1684
+ vBitangent = - vBitangent;
1685
+ #endif
1686
+ #endif
1687
+ #endif`,normalmap_pars_fragment:`#ifdef USE_NORMALMAP
1688
+ uniform sampler2D normalMap;
1689
+ uniform vec2 normalScale;
1690
+ #endif
1691
+ #ifdef USE_NORMALMAP_OBJECTSPACE
1692
+ uniform mat3 normalMatrix;
1693
+ #endif
1694
+ #if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )
1695
+ mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {
1696
+ vec3 q0 = dFdx( eye_pos.xyz );
1697
+ vec3 q1 = dFdy( eye_pos.xyz );
1698
+ vec2 st0 = dFdx( uv.st );
1699
+ vec2 st1 = dFdy( uv.st );
1700
+ vec3 N = surf_norm;
1701
+ vec3 q1perp = cross( q1, N );
1702
+ vec3 q0perp = cross( N, q0 );
1703
+ vec3 T = q1perp * st0.x + q0perp * st1.x;
1704
+ vec3 B = q1perp * st0.y + q0perp * st1.y;
1705
+ float det = max( dot( T, T ), dot( B, B ) );
1706
+ float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );
1707
+ return mat3( T * scale, B * scale, N );
1708
+ }
1709
+ #endif`,clearcoat_normal_fragment_begin:`#ifdef USE_CLEARCOAT
1710
+ vec3 clearcoatNormal = nonPerturbedNormal;
1711
+ #endif`,clearcoat_normal_fragment_maps:`#ifdef USE_CLEARCOAT_NORMALMAP
1712
+ vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;
1713
+ clearcoatMapN.xy *= clearcoatNormalScale;
1714
+ clearcoatNormal = normalize( tbn2 * clearcoatMapN );
1715
+ #endif`,clearcoat_pars_fragment:`#ifdef USE_CLEARCOATMAP
1716
+ uniform sampler2D clearcoatMap;
1717
+ #endif
1718
+ #ifdef USE_CLEARCOAT_NORMALMAP
1719
+ uniform sampler2D clearcoatNormalMap;
1720
+ uniform vec2 clearcoatNormalScale;
1721
+ #endif
1722
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
1723
+ uniform sampler2D clearcoatRoughnessMap;
1724
+ #endif`,iridescence_pars_fragment:`#ifdef USE_IRIDESCENCEMAP
1725
+ uniform sampler2D iridescenceMap;
1726
+ #endif
1727
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
1728
+ uniform sampler2D iridescenceThicknessMap;
1729
+ #endif`,opaque_fragment:`#ifdef OPAQUE
1730
+ diffuseColor.a = 1.0;
1731
+ #endif
1732
+ #ifdef USE_TRANSMISSION
1733
+ diffuseColor.a *= material.transmissionAlpha;
1734
+ #endif
1735
+ gl_FragColor = vec4( outgoingLight, diffuseColor.a );`,packing:`vec3 packNormalToRGB( const in vec3 normal ) {
1736
+ return normalize( normal ) * 0.5 + 0.5;
1737
+ }
1738
+ vec3 unpackRGBToNormal( const in vec3 rgb ) {
1739
+ return 2.0 * rgb.xyz - 1.0;
1740
+ }
1741
+ const float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;const float ShiftRight8 = 1. / 256.;
1742
+ const float Inv255 = 1. / 255.;
1743
+ const vec4 PackFactors = vec4( 1.0, 256.0, 256.0 * 256.0, 256.0 * 256.0 * 256.0 );
1744
+ const vec2 UnpackFactors2 = vec2( UnpackDownscale, 1.0 / PackFactors.g );
1745
+ const vec3 UnpackFactors3 = vec3( UnpackDownscale / PackFactors.rg, 1.0 / PackFactors.b );
1746
+ const vec4 UnpackFactors4 = vec4( UnpackDownscale / PackFactors.rgb, 1.0 / PackFactors.a );
1747
+ vec4 packDepthToRGBA( const in float v ) {
1748
+ if( v <= 0.0 )
1749
+ return vec4( 0., 0., 0., 0. );
1750
+ if( v >= 1.0 )
1751
+ return vec4( 1., 1., 1., 1. );
1752
+ float vuf;
1753
+ float af = modf( v * PackFactors.a, vuf );
1754
+ float bf = modf( vuf * ShiftRight8, vuf );
1755
+ float gf = modf( vuf * ShiftRight8, vuf );
1756
+ return vec4( vuf * Inv255, gf * PackUpscale, bf * PackUpscale, af );
1757
+ }
1758
+ vec3 packDepthToRGB( const in float v ) {
1759
+ if( v <= 0.0 )
1760
+ return vec3( 0., 0., 0. );
1761
+ if( v >= 1.0 )
1762
+ return vec3( 1., 1., 1. );
1763
+ float vuf;
1764
+ float bf = modf( v * PackFactors.b, vuf );
1765
+ float gf = modf( vuf * ShiftRight8, vuf );
1766
+ return vec3( vuf * Inv255, gf * PackUpscale, bf );
1767
+ }
1768
+ vec2 packDepthToRG( const in float v ) {
1769
+ if( v <= 0.0 )
1770
+ return vec2( 0., 0. );
1771
+ if( v >= 1.0 )
1772
+ return vec2( 1., 1. );
1773
+ float vuf;
1774
+ float gf = modf( v * 256., vuf );
1775
+ return vec2( vuf * Inv255, gf );
1776
+ }
1777
+ float unpackRGBAToDepth( const in vec4 v ) {
1778
+ return dot( v, UnpackFactors4 );
1779
+ }
1780
+ float unpackRGBToDepth( const in vec3 v ) {
1781
+ return dot( v, UnpackFactors3 );
1782
+ }
1783
+ float unpackRGToDepth( const in vec2 v ) {
1784
+ return v.r * UnpackFactors2.r + v.g * UnpackFactors2.g;
1785
+ }
1786
+ vec4 pack2HalfToRGBA( const in vec2 v ) {
1787
+ vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );
1788
+ return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );
1789
+ }
1790
+ vec2 unpackRGBATo2Half( const in vec4 v ) {
1791
+ return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );
1792
+ }
1793
+ float viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {
1794
+ return ( viewZ + near ) / ( near - far );
1795
+ }
1796
+ float orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {
1797
+ #ifdef USE_REVERSED_DEPTH_BUFFER
1798
+
1799
+ return depth * ( far - near ) - far;
1800
+ #else
1801
+ return depth * ( near - far ) - near;
1802
+ #endif
1803
+ }
1804
+ float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
1805
+ return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );
1806
+ }
1807
+ float perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {
1808
+
1809
+ #ifdef USE_REVERSED_DEPTH_BUFFER
1810
+ return ( near * far ) / ( ( near - far ) * depth - near );
1811
+ #else
1812
+ return ( near * far ) / ( ( far - near ) * depth - far );
1813
+ #endif
1814
+ }`,premultiplied_alpha_fragment:`#ifdef PREMULTIPLIED_ALPHA
1815
+ gl_FragColor.rgb *= gl_FragColor.a;
1816
+ #endif`,project_vertex:`vec4 mvPosition = vec4( transformed, 1.0 );
1817
+ #ifdef USE_BATCHING
1818
+ mvPosition = batchingMatrix * mvPosition;
1819
+ #endif
1820
+ #ifdef USE_INSTANCING
1821
+ mvPosition = instanceMatrix * mvPosition;
1822
+ #endif
1823
+ mvPosition = modelViewMatrix * mvPosition;
1824
+ gl_Position = projectionMatrix * mvPosition;`,dithering_fragment:`#ifdef DITHERING
1825
+ gl_FragColor.rgb = dithering( gl_FragColor.rgb );
1826
+ #endif`,dithering_pars_fragment:`#ifdef DITHERING
1827
+ vec3 dithering( vec3 color ) {
1828
+ float grid_position = rand( gl_FragCoord.xy );
1829
+ vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );
1830
+ dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );
1831
+ return color + dither_shift_RGB;
1832
+ }
1833
+ #endif`,roughnessmap_fragment:`float roughnessFactor = roughness;
1834
+ #ifdef USE_ROUGHNESSMAP
1835
+ vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );
1836
+ roughnessFactor *= texelRoughness.g;
1837
+ #endif`,roughnessmap_pars_fragment:`#ifdef USE_ROUGHNESSMAP
1838
+ uniform sampler2D roughnessMap;
1839
+ #endif`,shadowmap_pars_fragment:`#if NUM_SPOT_LIGHT_COORDS > 0
1840
+ varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
1841
+ #endif
1842
+ #if NUM_SPOT_LIGHT_MAPS > 0
1843
+ uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];
1844
+ #endif
1845
+ #ifdef USE_SHADOWMAP
1846
+ #if NUM_SUN_LIGHT_SHADOWS > 0
1847
+ #define SUN_LIGHT_CASCADES 2
1848
+ #if defined( SHADOWMAP_TYPE_PCF )
1849
+ uniform sampler2DShadow sunShadowMap[ NUM_SUN_LIGHT_SHADOWS ];
1850
+ #else
1851
+ uniform sampler2D sunShadowMap[ NUM_SUN_LIGHT_SHADOWS ];
1852
+ #endif
1853
+ uniform mat4 sunShadowMatrix[ NUM_SUN_LIGHT_SHADOWS * SUN_LIGHT_CASCADES ];
1854
+ uniform vec4 sunShadowCascade[ NUM_SUN_LIGHT_SHADOWS * SUN_LIGHT_CASCADES ];
1855
+ varying vec4 vSunShadowWorldPosition;
1856
+ varying vec3 vSunShadowWorldNormal;
1857
+ struct SunLightShadow {
1858
+ float shadowIntensity;
1859
+ float shadowBias;
1860
+ float shadowNormalBias;
1861
+ float shadowRadius;
1862
+ vec2 shadowMapSize;
1863
+ };
1864
+ uniform SunLightShadow sunLightShadows[ NUM_SUN_LIGHT_SHADOWS ];
1865
+ #endif
1866
+ #if NUM_DIR_LIGHT_SHADOWS > 0
1867
+ #if defined( SHADOWMAP_TYPE_PCF )
1868
+ uniform sampler2DShadow directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
1869
+ #else
1870
+ uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];
1871
+ #endif
1872
+ varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
1873
+ struct DirectionalLightShadow {
1874
+ float shadowIntensity;
1875
+ float shadowBias;
1876
+ float shadowNormalBias;
1877
+ float shadowRadius;
1878
+ vec2 shadowMapSize;
1879
+ };
1880
+ uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
1881
+ #endif
1882
+ #if NUM_SPOT_LIGHT_SHADOWS > 0
1883
+ #if defined( SHADOWMAP_TYPE_PCF )
1884
+ uniform sampler2DShadow spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
1885
+ #else
1886
+ uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
1887
+ #endif
1888
+ struct SpotLightShadow {
1889
+ float shadowIntensity;
1890
+ float shadowBias;
1891
+ float shadowNormalBias;
1892
+ float shadowRadius;
1893
+ vec2 shadowMapSize;
1894
+ };
1895
+ uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
1896
+ #endif
1897
+ #if NUM_POINT_LIGHT_SHADOWS > 0
1898
+ #if defined( SHADOWMAP_TYPE_PCF )
1899
+ uniform samplerCubeShadow pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];
1900
+ #elif defined( SHADOWMAP_TYPE_BASIC )
1901
+ uniform samplerCube pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];
1902
+ #endif
1903
+ varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
1904
+ struct PointLightShadow {
1905
+ float shadowIntensity;
1906
+ float shadowBias;
1907
+ float shadowNormalBias;
1908
+ float shadowRadius;
1909
+ vec2 shadowMapSize;
1910
+ float shadowCameraNear;
1911
+ float shadowCameraFar;
1912
+ };
1913
+ uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
1914
+ #endif
1915
+ #if defined( SHADOWMAP_TYPE_PCF )
1916
+ float interleavedGradientNoise( vec2 position ) {
1917
+ return fract( 52.9829189 * fract( dot( position, vec2( 0.06711056, 0.00583715 ) ) ) );
1918
+ }
1919
+ vec2 vogelDiskSample( int sampleIndex, int samplesCount, float phi ) {
1920
+ const float goldenAngle = 2.399963229728653;
1921
+ float r = sqrt( ( float( sampleIndex ) + 0.5 ) / float( samplesCount ) );
1922
+ float theta = float( sampleIndex ) * goldenAngle + phi;
1923
+ return vec2( cos( theta ), sin( theta ) ) * r;
1924
+ }
1925
+ #endif
1926
+ #if defined( SHADOWMAP_TYPE_PCF )
1927
+ float getShadow( sampler2DShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
1928
+ float shadow = 1.0;
1929
+ shadowCoord.xyz /= shadowCoord.w;
1930
+ #ifdef USE_REVERSED_DEPTH_BUFFER
1931
+ shadowCoord.z -= shadowBias;
1932
+ #else
1933
+ shadowCoord.z += shadowBias;
1934
+ #endif
1935
+ bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
1936
+ bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
1937
+ if ( frustumTest ) {
1938
+ vec2 texelSize = vec2( 1.0 ) / shadowMapSize;
1939
+ vec2 radius = shadowRadius * texelSize;
1940
+ float phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;
1941
+ shadow = (
1942
+ texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 0, 5, phi ) * radius, shadowCoord.z ) ) +
1943
+ texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 1, 5, phi ) * radius, shadowCoord.z ) ) +
1944
+ texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 2, 5, phi ) * radius, shadowCoord.z ) ) +
1945
+ texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 3, 5, phi ) * radius, shadowCoord.z ) ) +
1946
+ texture( shadowMap, vec3( shadowCoord.xy + vogelDiskSample( 4, 5, phi ) * radius, shadowCoord.z ) )
1947
+ ) * 0.2;
1948
+ }
1949
+ return mix( 1.0, shadow, shadowIntensity );
1950
+ }
1951
+ #elif defined( SHADOWMAP_TYPE_VSM )
1952
+ float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
1953
+ float shadow = 1.0;
1954
+ shadowCoord.xyz /= shadowCoord.w;
1955
+ #ifdef USE_REVERSED_DEPTH_BUFFER
1956
+ shadowCoord.z -= shadowBias;
1957
+ #else
1958
+ shadowCoord.z += shadowBias;
1959
+ #endif
1960
+ bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
1961
+ bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
1962
+ if ( frustumTest ) {
1963
+ vec2 distribution = texture2D( shadowMap, shadowCoord.xy ).rg;
1964
+ float mean = distribution.x;
1965
+ float variance = distribution.y * distribution.y;
1966
+ #ifdef USE_REVERSED_DEPTH_BUFFER
1967
+ float hard_shadow = step( mean, shadowCoord.z );
1968
+ #else
1969
+ float hard_shadow = step( shadowCoord.z, mean );
1970
+ #endif
1971
+
1972
+ if ( hard_shadow == 1.0 ) {
1973
+ shadow = 1.0;
1974
+ } else {
1975
+ variance = max( variance, 0.0000001 );
1976
+ float d = shadowCoord.z - mean;
1977
+ float p_max = variance / ( variance + d * d );
1978
+ p_max = clamp( ( p_max - 0.3 ) / 0.65, 0.0, 1.0 );
1979
+ shadow = max( hard_shadow, p_max );
1980
+ }
1981
+ }
1982
+ return mix( 1.0, shadow, shadowIntensity );
1983
+ }
1984
+ #else
1985
+ float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
1986
+ float shadow = 1.0;
1987
+ shadowCoord.xyz /= shadowCoord.w;
1988
+ #ifdef USE_REVERSED_DEPTH_BUFFER
1989
+ shadowCoord.z -= shadowBias;
1990
+ #else
1991
+ shadowCoord.z += shadowBias;
1992
+ #endif
1993
+ bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
1994
+ bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
1995
+ if ( frustumTest ) {
1996
+ float depth = texture2D( shadowMap, shadowCoord.xy ).r;
1997
+ #ifdef USE_REVERSED_DEPTH_BUFFER
1998
+ shadow = step( depth, shadowCoord.z );
1999
+ #else
2000
+ shadow = step( shadowCoord.z, depth );
2001
+ #endif
2002
+ }
2003
+ return mix( 1.0, shadow, shadowIntensity );
2004
+ }
2005
+ #endif
2006
+ #if NUM_SUN_LIGHT_SHADOWS > 0
2007
+ float getSunShadow(
2008
+ #if defined( SHADOWMAP_TYPE_PCF )
2009
+ sampler2DShadow shadowMap,
2010
+ #else
2011
+ sampler2D shadowMap,
2012
+ #endif
2013
+ SunLightShadow sunLightShadow,
2014
+ int shadowIndex
2015
+ ) {
2016
+ vec4 shadowWorldPosition = vec4( vSunShadowWorldPosition.xyz + vSunShadowWorldNormal * sunLightShadow.shadowNormalBias, 1.0 );
2017
+ float viewDepth = vSunShadowWorldPosition.w;
2018
+ int cascadeOffset = shadowIndex * SUN_LIGHT_CASCADES;
2019
+ float shadow = 1.0;
2020
+ for ( int i = SUN_LIGHT_CASCADES - 1; i >= 0; i -- ) {
2021
+ vec4 cascade = sunShadowCascade[ cascadeOffset + i ];
2022
+ if ( viewDepth >= cascade.x && viewDepth < cascade.y ) {
2023
+ float cascadeShadow = getShadow(
2024
+ shadowMap,
2025
+ sunLightShadow.shadowMapSize,
2026
+ sunLightShadow.shadowIntensity,
2027
+ sunLightShadow.shadowBias,
2028
+ sunLightShadow.shadowRadius,
2029
+ sunShadowMatrix[ cascadeOffset + i ] * shadowWorldPosition
2030
+ );
2031
+ shadow = mix( cascadeShadow, shadow, smoothstep( cascade.z, cascade.y, viewDepth ) );
2032
+ }
2033
+ }
2034
+ return shadow;
2035
+ }
2036
+ #endif
2037
+ #if NUM_POINT_LIGHT_SHADOWS > 0
2038
+ #if defined( SHADOWMAP_TYPE_PCF )
2039
+ float getPointShadow( samplerCubeShadow shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
2040
+ float shadow = 1.0;
2041
+ vec3 lightToPosition = shadowCoord.xyz;
2042
+ vec3 bd3D = normalize( lightToPosition );
2043
+ vec3 absVec = abs( lightToPosition );
2044
+ float viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );
2045
+ if ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {
2046
+ float lightDistance = length( lightToPosition );
2047
+ float depthRange = shadowCameraFar - shadowCameraNear;
2048
+ #ifdef USE_REVERSED_DEPTH_BUFFER
2049
+ float depthA = - shadowCameraNear / depthRange - shadowBias;
2050
+ float depthB = shadowCameraNear * shadowCameraFar / ( depthRange * lightDistance );
2051
+ #else
2052
+ float depthA = shadowCameraFar / depthRange + shadowBias;
2053
+ float depthB = - shadowCameraNear * shadowCameraFar / ( depthRange * lightDistance );
2054
+ #endif
2055
+ float texelSize = shadowRadius / shadowMapSize.x;
2056
+ vec3 absDir = abs( bd3D );
2057
+ vec3 tangent = absDir.x > absDir.z ? vec3( 0.0, 1.0, 0.0 ) : vec3( 1.0, 0.0, 0.0 );
2058
+ tangent = normalize( cross( bd3D, tangent ) );
2059
+ vec3 bitangent = cross( bd3D, tangent );
2060
+ float phi = interleavedGradientNoise( gl_FragCoord.xy ) * PI2;
2061
+ shadow = 0.0;
2062
+ for ( int i = 0; i < 5; i ++ ) {
2063
+ vec2 offset = vogelDiskSample( i, 5, phi );
2064
+ vec3 direction = bd3D + ( tangent * offset.x + bitangent * offset.y ) * texelSize;
2065
+ vec3 absDirection = abs( direction );
2066
+ float dp = depthA + depthB / max( max( absDirection.x, absDirection.y ), absDirection.z );
2067
+ shadow += texture( shadowMap, vec4( direction, dp ) );
2068
+ }
2069
+ shadow *= 0.2;
2070
+ }
2071
+ return mix( 1.0, shadow, shadowIntensity );
2072
+ }
2073
+ #elif defined( SHADOWMAP_TYPE_BASIC )
2074
+ float getPointShadow( samplerCube shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
2075
+ float shadow = 1.0;
2076
+ vec3 lightToPosition = shadowCoord.xyz;
2077
+ vec3 absVec = abs( lightToPosition );
2078
+ float viewSpaceZ = max( max( absVec.x, absVec.y ), absVec.z );
2079
+ if ( viewSpaceZ - shadowCameraFar <= 0.0 && viewSpaceZ - shadowCameraNear >= 0.0 ) {
2080
+ float dp = ( shadowCameraFar * ( viewSpaceZ - shadowCameraNear ) ) / ( viewSpaceZ * ( shadowCameraFar - shadowCameraNear ) );
2081
+ dp += shadowBias;
2082
+ vec3 bd3D = normalize( lightToPosition );
2083
+ float depth = textureCube( shadowMap, bd3D ).r;
2084
+ #ifdef USE_REVERSED_DEPTH_BUFFER
2085
+ depth = 1.0 - depth;
2086
+ #endif
2087
+ shadow = step( dp, depth );
2088
+ }
2089
+ return mix( 1.0, shadow, shadowIntensity );
2090
+ }
2091
+ #endif
2092
+ #endif
2093
+ #endif`,shadowmap_pars_vertex:`#if NUM_SPOT_LIGHT_COORDS > 0
2094
+ uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];
2095
+ varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];
2096
+ #endif
2097
+ #ifdef USE_SHADOWMAP
2098
+ #if NUM_SUN_LIGHT_SHADOWS > 0
2099
+ varying vec4 vSunShadowWorldPosition;
2100
+ varying vec3 vSunShadowWorldNormal;
2101
+ #endif
2102
+ #if NUM_DIR_LIGHT_SHADOWS > 0
2103
+ uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];
2104
+ varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
2105
+ struct DirectionalLightShadow {
2106
+ float shadowIntensity;
2107
+ float shadowBias;
2108
+ float shadowNormalBias;
2109
+ float shadowRadius;
2110
+ vec2 shadowMapSize;
2111
+ };
2112
+ uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];
2113
+ #endif
2114
+ #if NUM_SPOT_LIGHT_SHADOWS > 0
2115
+ struct SpotLightShadow {
2116
+ float shadowIntensity;
2117
+ float shadowBias;
2118
+ float shadowNormalBias;
2119
+ float shadowRadius;
2120
+ vec2 shadowMapSize;
2121
+ };
2122
+ uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];
2123
+ #endif
2124
+ #if NUM_POINT_LIGHT_SHADOWS > 0
2125
+ uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];
2126
+ varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
2127
+ struct PointLightShadow {
2128
+ float shadowIntensity;
2129
+ float shadowBias;
2130
+ float shadowNormalBias;
2131
+ float shadowRadius;
2132
+ vec2 shadowMapSize;
2133
+ float shadowCameraNear;
2134
+ float shadowCameraFar;
2135
+ };
2136
+ uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];
2137
+ #endif
2138
+ #endif`,shadowmap_vertex:`#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_SUN_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )
2139
+ #ifdef HAS_NORMAL
2140
+ vec3 shadowWorldNormal = transformNormalByInverseViewMatrix( transformedNormal, viewMatrix );
2141
+ #else
2142
+ vec3 shadowWorldNormal = vec3( 0.0 );
2143
+ #endif
2144
+ vec4 shadowWorldPosition;
2145
+ #endif
2146
+ #if defined( USE_SHADOWMAP )
2147
+ #if NUM_SUN_LIGHT_SHADOWS > 0
2148
+ vSunShadowWorldPosition = vec4( worldPosition.xyz, - mvPosition.z );
2149
+ vSunShadowWorldNormal = shadowWorldNormal;
2150
+ #endif
2151
+ #if NUM_DIR_LIGHT_SHADOWS > 0
2152
+ #pragma unroll_loop_start
2153
+ for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
2154
+ shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );
2155
+ vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;
2156
+ }
2157
+ #pragma unroll_loop_end
2158
+ #endif
2159
+ #if NUM_POINT_LIGHT_SHADOWS > 0
2160
+ #pragma unroll_loop_start
2161
+ for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
2162
+ shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );
2163
+ vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;
2164
+ }
2165
+ #pragma unroll_loop_end
2166
+ #endif
2167
+ #endif
2168
+ #if NUM_SPOT_LIGHT_COORDS > 0
2169
+ #pragma unroll_loop_start
2170
+ for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {
2171
+ shadowWorldPosition = worldPosition;
2172
+ #if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
2173
+ shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;
2174
+ #endif
2175
+ vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;
2176
+ }
2177
+ #pragma unroll_loop_end
2178
+ #endif`,shadowmask_pars_fragment:`float getShadowMask() {
2179
+ float shadow = 1.0;
2180
+ #ifdef USE_SHADOWMAP
2181
+ #if NUM_SUN_LIGHT_SHADOWS > 0
2182
+ SunLightShadow sunLight;
2183
+ #pragma unroll_loop_start
2184
+ for ( int i = 0; i < NUM_SUN_LIGHT_SHADOWS; i ++ ) {
2185
+ sunLight = sunLightShadows[ i ];
2186
+ shadow *= receiveShadow ? getSunShadow( sunShadowMap[ i ], sunLight, UNROLLED_LOOP_INDEX ) : 1.0;
2187
+ }
2188
+ #pragma unroll_loop_end
2189
+ #endif
2190
+ #if NUM_DIR_LIGHT_SHADOWS > 0
2191
+ DirectionalLightShadow directionalLight;
2192
+ #pragma unroll_loop_start
2193
+ for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
2194
+ directionalLight = directionalLightShadows[ i ];
2195
+ shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
2196
+ }
2197
+ #pragma unroll_loop_end
2198
+ #endif
2199
+ #if NUM_SPOT_LIGHT_SHADOWS > 0
2200
+ SpotLightShadow spotLight;
2201
+ #pragma unroll_loop_start
2202
+ for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {
2203
+ spotLight = spotLightShadows[ i ];
2204
+ shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
2205
+ }
2206
+ #pragma unroll_loop_end
2207
+ #endif
2208
+ #if NUM_POINT_LIGHT_SHADOWS > 0 && ( defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_BASIC ) )
2209
+ PointLightShadow pointLight;
2210
+ #pragma unroll_loop_start
2211
+ for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
2212
+ pointLight = pointLightShadows[ i ];
2213
+ shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
2214
+ }
2215
+ #pragma unroll_loop_end
2216
+ #endif
2217
+ #endif
2218
+ return shadow;
2219
+ }`,skinbase_vertex:`#ifdef USE_SKINNING
2220
+ mat4 boneMatX = getBoneMatrix( skinIndex.x );
2221
+ mat4 boneMatY = getBoneMatrix( skinIndex.y );
2222
+ mat4 boneMatZ = getBoneMatrix( skinIndex.z );
2223
+ mat4 boneMatW = getBoneMatrix( skinIndex.w );
2224
+ #endif`,skinning_pars_vertex:`#ifdef USE_SKINNING
2225
+ uniform mat4 bindMatrix;
2226
+ uniform mat4 bindMatrixInverse;
2227
+ uniform highp sampler2D boneTexture;
2228
+ mat4 getBoneMatrix( const in float i ) {
2229
+ int size = textureSize( boneTexture, 0 ).x;
2230
+ int j = int( i ) * 4;
2231
+ int x = j % size;
2232
+ int y = j / size;
2233
+ vec4 v1 = texelFetch( boneTexture, ivec2( x, y ), 0 );
2234
+ vec4 v2 = texelFetch( boneTexture, ivec2( x + 1, y ), 0 );
2235
+ vec4 v3 = texelFetch( boneTexture, ivec2( x + 2, y ), 0 );
2236
+ vec4 v4 = texelFetch( boneTexture, ivec2( x + 3, y ), 0 );
2237
+ return mat4( v1, v2, v3, v4 );
2238
+ }
2239
+ #endif`,skinning_vertex:`#ifdef USE_SKINNING
2240
+ vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );
2241
+ vec4 skinned = vec4( 0.0 );
2242
+ skinned += boneMatX * skinVertex * skinWeight.x;
2243
+ skinned += boneMatY * skinVertex * skinWeight.y;
2244
+ skinned += boneMatZ * skinVertex * skinWeight.z;
2245
+ skinned += boneMatW * skinVertex * skinWeight.w;
2246
+ transformed = ( bindMatrixInverse * skinned ).xyz;
2247
+ #endif`,skinnormal_vertex:`#ifdef USE_SKINNING
2248
+ mat4 skinMatrix = mat4( 0.0 );
2249
+ skinMatrix += skinWeight.x * boneMatX;
2250
+ skinMatrix += skinWeight.y * boneMatY;
2251
+ skinMatrix += skinWeight.z * boneMatZ;
2252
+ skinMatrix += skinWeight.w * boneMatW;
2253
+ skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;
2254
+ objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;
2255
+ #ifdef USE_TANGENT
2256
+ objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;
2257
+ #endif
2258
+ #endif`,specularmap_fragment:`float specularStrength;
2259
+ #ifdef USE_SPECULARMAP
2260
+ vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );
2261
+ specularStrength = texelSpecular.r;
2262
+ #else
2263
+ specularStrength = 1.0;
2264
+ #endif`,specularmap_pars_fragment:`#ifdef USE_SPECULARMAP
2265
+ uniform sampler2D specularMap;
2266
+ #endif`,tonemapping_fragment:`#if defined( TONE_MAPPING )
2267
+ gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );
2268
+ #endif`,tonemapping_pars_fragment:`#ifndef saturate
2269
+ #define saturate( a ) clamp( a, 0.0, 1.0 )
2270
+ #endif
2271
+ uniform float toneMappingExposure;
2272
+ vec3 LinearToneMapping( vec3 color ) {
2273
+ return saturate( toneMappingExposure * color );
2274
+ }
2275
+ vec3 ReinhardToneMapping( vec3 color ) {
2276
+ color *= toneMappingExposure;
2277
+ return saturate( color / ( vec3( 1.0 ) + color ) );
2278
+ }
2279
+ vec3 CineonToneMapping( vec3 color ) {
2280
+ color *= toneMappingExposure;
2281
+ color = max( vec3( 0.0 ), color - 0.004 );
2282
+ return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );
2283
+ }
2284
+ vec3 RRTAndODTFit( vec3 v ) {
2285
+ vec3 a = v * ( v + 0.0245786 ) - 0.000090537;
2286
+ vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;
2287
+ return a / b;
2288
+ }
2289
+ vec3 ACESFilmicToneMapping( vec3 color ) {
2290
+ const mat3 ACESInputMat = mat3(
2291
+ vec3( 0.59719, 0.07600, 0.02840 ), vec3( 0.35458, 0.90834, 0.13383 ),
2292
+ vec3( 0.04823, 0.01566, 0.83777 )
2293
+ );
2294
+ const mat3 ACESOutputMat = mat3(
2295
+ vec3( 1.60475, -0.10208, -0.00327 ), vec3( -0.53108, 1.10813, -0.07276 ),
2296
+ vec3( -0.07367, -0.00605, 1.07602 )
2297
+ );
2298
+ color *= toneMappingExposure / 0.6;
2299
+ color = ACESInputMat * color;
2300
+ color = RRTAndODTFit( color );
2301
+ color = ACESOutputMat * color;
2302
+ return saturate( color );
2303
+ }
2304
+ const mat3 LINEAR_REC2020_TO_LINEAR_SRGB = mat3(
2305
+ vec3( 1.6605, - 0.1246, - 0.0182 ),
2306
+ vec3( - 0.5876, 1.1329, - 0.1006 ),
2307
+ vec3( - 0.0728, - 0.0083, 1.1187 )
2308
+ );
2309
+ const mat3 LINEAR_SRGB_TO_LINEAR_REC2020 = mat3(
2310
+ vec3( 0.6274, 0.0691, 0.0164 ),
2311
+ vec3( 0.3293, 0.9195, 0.0880 ),
2312
+ vec3( 0.0433, 0.0113, 0.8956 )
2313
+ );
2314
+ vec3 agxDefaultContrastApprox( vec3 x ) {
2315
+ vec3 x2 = x * x;
2316
+ vec3 x4 = x2 * x2;
2317
+ return + 15.5 * x4 * x2
2318
+ - 40.14 * x4 * x
2319
+ + 31.96 * x4
2320
+ - 6.868 * x2 * x
2321
+ + 0.4298 * x2
2322
+ + 0.1191 * x
2323
+ - 0.00232;
2324
+ }
2325
+ vec3 AgXToneMapping( vec3 color ) {
2326
+ const mat3 AgXInsetMatrix = mat3(
2327
+ vec3( 0.856627153315983, 0.137318972929847, 0.11189821299995 ),
2328
+ vec3( 0.0951212405381588, 0.761241990602591, 0.0767994186031903 ),
2329
+ vec3( 0.0482516061458583, 0.101439036467562, 0.811302368396859 )
2330
+ );
2331
+ const mat3 AgXOutsetMatrix = mat3(
2332
+ vec3( 1.1271005818144368, - 0.1413297634984383, - 0.14132976349843826 ),
2333
+ vec3( - 0.11060664309660323, 1.157823702216272, - 0.11060664309660294 ),
2334
+ vec3( - 0.016493938717834573, - 0.016493938717834257, 1.2519364065950405 )
2335
+ );
2336
+ const float AgxMinEv = - 12.47393; const float AgxMaxEv = 4.026069;
2337
+ color *= toneMappingExposure;
2338
+ color = LINEAR_SRGB_TO_LINEAR_REC2020 * color;
2339
+ color = AgXInsetMatrix * color;
2340
+ color = max( color, 1e-10 ); color = log2( color );
2341
+ color = ( color - AgxMinEv ) / ( AgxMaxEv - AgxMinEv );
2342
+ color = clamp( color, 0.0, 1.0 );
2343
+ color = agxDefaultContrastApprox( color );
2344
+ color = AgXOutsetMatrix * color;
2345
+ color = pow( max( vec3( 0.0 ), color ), vec3( 2.2 ) );
2346
+ color = LINEAR_REC2020_TO_LINEAR_SRGB * color;
2347
+ color = clamp( color, 0.0, 1.0 );
2348
+ return color;
2349
+ }
2350
+ vec3 NeutralToneMapping( vec3 color ) {
2351
+ const float StartCompression = 0.8 - 0.04;
2352
+ const float Desaturation = 0.15;
2353
+ color *= toneMappingExposure;
2354
+ float x = min( color.r, min( color.g, color.b ) );
2355
+ float offset = x < 0.08 ? x - 6.25 * x * x : 0.04;
2356
+ color -= offset;
2357
+ float peak = max( color.r, max( color.g, color.b ) );
2358
+ if ( peak < StartCompression ) return color;
2359
+ float d = 1. - StartCompression;
2360
+ float newPeak = 1. - d * d / ( peak + d - StartCompression );
2361
+ color *= newPeak / peak;
2362
+ float g = 1. - 1. / ( Desaturation * ( peak - newPeak ) + 1. );
2363
+ return mix( color, vec3( newPeak ), g );
2364
+ }
2365
+ vec3 CustomToneMapping( vec3 color ) { return color; }`,transmission_fragment:`#ifdef USE_TRANSMISSION
2366
+ material.transmission = transmission;
2367
+ material.transmissionAlpha = 1.0;
2368
+ material.thickness = thickness;
2369
+ material.attenuationDistance = attenuationDistance;
2370
+ material.attenuationColor = attenuationColor;
2371
+ #ifdef USE_TRANSMISSIONMAP
2372
+ material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;
2373
+ #endif
2374
+ #ifdef USE_THICKNESSMAP
2375
+ material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;
2376
+ #endif
2377
+ vec3 pos = vWorldPosition;
2378
+ vec3 v = normalize( cameraPosition - pos );
2379
+ vec3 n = transformNormalByInverseViewMatrix( normal, viewMatrix );
2380
+ vec4 transmitted = getIBLVolumeRefraction(
2381
+ n, v, material.roughness, material.diffuseContribution, material.specularColorBlended, material.specularF90,
2382
+ pos, modelMatrix, viewMatrix, projectionMatrix, material.dispersion, material.ior, material.thickness,
2383
+ material.attenuationColor, material.attenuationDistance );
2384
+ material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );
2385
+ totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );
2386
+ #endif`,transmission_pars_fragment:`#ifdef USE_TRANSMISSION
2387
+ uniform float transmission;
2388
+ uniform float thickness;
2389
+ uniform float attenuationDistance;
2390
+ uniform vec3 attenuationColor;
2391
+ #ifdef USE_TRANSMISSIONMAP
2392
+ uniform sampler2D transmissionMap;
2393
+ #endif
2394
+ #ifdef USE_THICKNESSMAP
2395
+ uniform sampler2D thicknessMap;
2396
+ #endif
2397
+ uniform vec2 transmissionSamplerSize;
2398
+ uniform sampler2D transmissionSamplerMap;
2399
+ uniform mat4 modelMatrix;
2400
+ uniform mat4 projectionMatrix;
2401
+ varying vec3 vWorldPosition;
2402
+ float w0( float a ) {
2403
+ return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );
2404
+ }
2405
+ float w1( float a ) {
2406
+ return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );
2407
+ }
2408
+ float w2( float a ){
2409
+ return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );
2410
+ }
2411
+ float w3( float a ) {
2412
+ return ( 1.0 / 6.0 ) * ( a * a * a );
2413
+ }
2414
+ float g0( float a ) {
2415
+ return w0( a ) + w1( a );
2416
+ }
2417
+ float g1( float a ) {
2418
+ return w2( a ) + w3( a );
2419
+ }
2420
+ float h0( float a ) {
2421
+ return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );
2422
+ }
2423
+ float h1( float a ) {
2424
+ return 1.0 + w3( a ) / ( w2( a ) + w3( a ) );
2425
+ }
2426
+ vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {
2427
+ uv = uv * texelSize.zw + 0.5;
2428
+ vec2 iuv = floor( uv );
2429
+ vec2 fuv = fract( uv );
2430
+ float g0x = g0( fuv.x );
2431
+ float g1x = g1( fuv.x );
2432
+ float h0x = h0( fuv.x );
2433
+ float h1x = h1( fuv.x );
2434
+ float h0y = h0( fuv.y );
2435
+ float h1y = h1( fuv.y );
2436
+ vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
2437
+ vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;
2438
+ vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
2439
+ vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;
2440
+ return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +
2441
+ g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );
2442
+ }
2443
+ vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {
2444
+ vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );
2445
+ vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );
2446
+ vec2 fLodSizeInv = 1.0 / fLodSize;
2447
+ vec2 cLodSizeInv = 1.0 / cLodSize;
2448
+ vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );
2449
+ vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );
2450
+ return mix( fSample, cSample, fract( lod ) );
2451
+ }
2452
+ vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {
2453
+ vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );
2454
+ vec3 modelScale;
2455
+ modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );
2456
+ modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );
2457
+ modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );
2458
+ return normalize( refractionVector ) * thickness * modelScale;
2459
+ }
2460
+ float applyIorToRoughness( const in float roughness, const in float ior ) {
2461
+ return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );
2462
+ }
2463
+ vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {
2464
+ float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );
2465
+ return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );
2466
+ }
2467
+ vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {
2468
+ if ( isinf( attenuationDistance ) ) {
2469
+ return vec3( 1.0 );
2470
+ } else {
2471
+ vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;
2472
+ vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance;
2473
+ }
2474
+ }
2475
+ vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,
2476
+ const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,
2477
+ const in mat4 viewMatrix, const in mat4 projMatrix, const in float dispersion, const in float ior, const in float thickness,
2478
+ const in vec3 attenuationColor, const in float attenuationDistance ) {
2479
+ vec4 transmittedLight;
2480
+ vec3 transmittance;
2481
+ #ifdef USE_DISPERSION
2482
+ float halfSpread = ( ior - 1.0 ) * 0.025 * dispersion;
2483
+ vec3 iors = vec3( ior - halfSpread, ior, ior + halfSpread );
2484
+ for ( int i = 0; i < 3; i ++ ) {
2485
+ vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, iors[ i ], modelMatrix );
2486
+ vec3 refractedRayExit = position + transmissionRay;
2487
+ vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
2488
+ vec2 refractionCoords = ndcPos.xy / ndcPos.w;
2489
+ refractionCoords += 1.0;
2490
+ refractionCoords /= 2.0;
2491
+ vec4 transmissionSample = getTransmissionSample( refractionCoords, roughness, iors[ i ] );
2492
+ transmittedLight[ i ] = transmissionSample[ i ];
2493
+ transmittedLight.a += transmissionSample.a;
2494
+ transmittance[ i ] = diffuseColor[ i ] * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance )[ i ];
2495
+ }
2496
+ transmittedLight.a /= 3.0;
2497
+ #else
2498
+ vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
2499
+ vec3 refractedRayExit = position + transmissionRay;
2500
+ vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
2501
+ vec2 refractionCoords = ndcPos.xy / ndcPos.w;
2502
+ refractionCoords += 1.0;
2503
+ refractionCoords /= 2.0;
2504
+ transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
2505
+ transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );
2506
+ #endif
2507
+ vec3 attenuatedColor = transmittance * transmittedLight.rgb;
2508
+ vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );
2509
+ float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;
2510
+ return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );
2511
+ }
2512
+ #endif`,uv_pars_fragment:`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
2513
+ varying vec2 vUv;
2514
+ #endif
2515
+ #ifdef USE_MAP
2516
+ varying vec2 vMapUv;
2517
+ #endif
2518
+ #ifdef USE_ALPHAMAP
2519
+ varying vec2 vAlphaMapUv;
2520
+ #endif
2521
+ #ifdef USE_LIGHTMAP
2522
+ varying vec2 vLightMapUv;
2523
+ #endif
2524
+ #ifdef USE_AOMAP
2525
+ varying vec2 vAoMapUv;
2526
+ #endif
2527
+ #ifdef USE_BUMPMAP
2528
+ varying vec2 vBumpMapUv;
2529
+ #endif
2530
+ #ifdef USE_NORMALMAP
2531
+ varying vec2 vNormalMapUv;
2532
+ #endif
2533
+ #ifdef USE_EMISSIVEMAP
2534
+ varying vec2 vEmissiveMapUv;
2535
+ #endif
2536
+ #ifdef USE_METALNESSMAP
2537
+ varying vec2 vMetalnessMapUv;
2538
+ #endif
2539
+ #ifdef USE_ROUGHNESSMAP
2540
+ varying vec2 vRoughnessMapUv;
2541
+ #endif
2542
+ #ifdef USE_DIFFUSE_ROUGHNESSMAP
2543
+ varying vec2 vDiffuseRoughnessMapUv;
2544
+ #endif
2545
+ #ifdef USE_ANISOTROPYMAP
2546
+ varying vec2 vAnisotropyMapUv;
2547
+ #endif
2548
+ #ifdef USE_CLEARCOATMAP
2549
+ varying vec2 vClearcoatMapUv;
2550
+ #endif
2551
+ #ifdef USE_CLEARCOAT_NORMALMAP
2552
+ varying vec2 vClearcoatNormalMapUv;
2553
+ #endif
2554
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
2555
+ varying vec2 vClearcoatRoughnessMapUv;
2556
+ #endif
2557
+ #ifdef USE_IRIDESCENCEMAP
2558
+ varying vec2 vIridescenceMapUv;
2559
+ #endif
2560
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
2561
+ varying vec2 vIridescenceThicknessMapUv;
2562
+ #endif
2563
+ #ifdef USE_SHEEN_COLORMAP
2564
+ varying vec2 vSheenColorMapUv;
2565
+ #endif
2566
+ #ifdef USE_SHEEN_ROUGHNESSMAP
2567
+ varying vec2 vSheenRoughnessMapUv;
2568
+ #endif
2569
+ #ifdef USE_SPECULARMAP
2570
+ varying vec2 vSpecularMapUv;
2571
+ #endif
2572
+ #ifdef USE_SPECULAR_COLORMAP
2573
+ varying vec2 vSpecularColorMapUv;
2574
+ #endif
2575
+ #ifdef USE_SPECULAR_INTENSITYMAP
2576
+ varying vec2 vSpecularIntensityMapUv;
2577
+ #endif
2578
+ #ifdef USE_TRANSMISSIONMAP
2579
+ uniform mat3 transmissionMapTransform;
2580
+ varying vec2 vTransmissionMapUv;
2581
+ #endif
2582
+ #ifdef USE_THICKNESSMAP
2583
+ uniform mat3 thicknessMapTransform;
2584
+ varying vec2 vThicknessMapUv;
2585
+ #endif`,uv_pars_vertex:`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
2586
+ varying vec2 vUv;
2587
+ #endif
2588
+ #ifdef USE_MAP
2589
+ uniform mat3 mapTransform;
2590
+ varying vec2 vMapUv;
2591
+ #endif
2592
+ #ifdef USE_ALPHAMAP
2593
+ uniform mat3 alphaMapTransform;
2594
+ varying vec2 vAlphaMapUv;
2595
+ #endif
2596
+ #ifdef USE_LIGHTMAP
2597
+ uniform mat3 lightMapTransform;
2598
+ varying vec2 vLightMapUv;
2599
+ #endif
2600
+ #ifdef USE_AOMAP
2601
+ uniform mat3 aoMapTransform;
2602
+ varying vec2 vAoMapUv;
2603
+ #endif
2604
+ #ifdef USE_BUMPMAP
2605
+ uniform mat3 bumpMapTransform;
2606
+ varying vec2 vBumpMapUv;
2607
+ #endif
2608
+ #ifdef USE_NORMALMAP
2609
+ uniform mat3 normalMapTransform;
2610
+ varying vec2 vNormalMapUv;
2611
+ #endif
2612
+ #ifdef USE_DISPLACEMENTMAP
2613
+ uniform mat3 displacementMapTransform;
2614
+ varying vec2 vDisplacementMapUv;
2615
+ #endif
2616
+ #ifdef USE_EMISSIVEMAP
2617
+ uniform mat3 emissiveMapTransform;
2618
+ varying vec2 vEmissiveMapUv;
2619
+ #endif
2620
+ #ifdef USE_METALNESSMAP
2621
+ uniform mat3 metalnessMapTransform;
2622
+ varying vec2 vMetalnessMapUv;
2623
+ #endif
2624
+ #ifdef USE_ROUGHNESSMAP
2625
+ uniform mat3 roughnessMapTransform;
2626
+ varying vec2 vRoughnessMapUv;
2627
+ #endif
2628
+ #ifdef USE_DIFFUSE_ROUGHNESSMAP
2629
+ uniform mat3 diffuseRoughnessMapTransform;
2630
+ varying vec2 vDiffuseRoughnessMapUv;
2631
+ #endif
2632
+ #ifdef USE_ANISOTROPYMAP
2633
+ uniform mat3 anisotropyMapTransform;
2634
+ varying vec2 vAnisotropyMapUv;
2635
+ #endif
2636
+ #ifdef USE_CLEARCOATMAP
2637
+ uniform mat3 clearcoatMapTransform;
2638
+ varying vec2 vClearcoatMapUv;
2639
+ #endif
2640
+ #ifdef USE_CLEARCOAT_NORMALMAP
2641
+ uniform mat3 clearcoatNormalMapTransform;
2642
+ varying vec2 vClearcoatNormalMapUv;
2643
+ #endif
2644
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
2645
+ uniform mat3 clearcoatRoughnessMapTransform;
2646
+ varying vec2 vClearcoatRoughnessMapUv;
2647
+ #endif
2648
+ #ifdef USE_SHEEN_COLORMAP
2649
+ uniform mat3 sheenColorMapTransform;
2650
+ varying vec2 vSheenColorMapUv;
2651
+ #endif
2652
+ #ifdef USE_SHEEN_ROUGHNESSMAP
2653
+ uniform mat3 sheenRoughnessMapTransform;
2654
+ varying vec2 vSheenRoughnessMapUv;
2655
+ #endif
2656
+ #ifdef USE_IRIDESCENCEMAP
2657
+ uniform mat3 iridescenceMapTransform;
2658
+ varying vec2 vIridescenceMapUv;
2659
+ #endif
2660
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
2661
+ uniform mat3 iridescenceThicknessMapTransform;
2662
+ varying vec2 vIridescenceThicknessMapUv;
2663
+ #endif
2664
+ #ifdef USE_SPECULARMAP
2665
+ uniform mat3 specularMapTransform;
2666
+ varying vec2 vSpecularMapUv;
2667
+ #endif
2668
+ #ifdef USE_SPECULAR_COLORMAP
2669
+ uniform mat3 specularColorMapTransform;
2670
+ varying vec2 vSpecularColorMapUv;
2671
+ #endif
2672
+ #ifdef USE_SPECULAR_INTENSITYMAP
2673
+ uniform mat3 specularIntensityMapTransform;
2674
+ varying vec2 vSpecularIntensityMapUv;
2675
+ #endif
2676
+ #ifdef USE_TRANSMISSIONMAP
2677
+ uniform mat3 transmissionMapTransform;
2678
+ varying vec2 vTransmissionMapUv;
2679
+ #endif
2680
+ #ifdef USE_THICKNESSMAP
2681
+ uniform mat3 thicknessMapTransform;
2682
+ varying vec2 vThicknessMapUv;
2683
+ #endif`,uv_vertex:`#if defined( USE_UV ) || defined( USE_ANISOTROPY )
2684
+ vUv = vec3( uv, 1 ).xy;
2685
+ #endif
2686
+ #ifdef USE_MAP
2687
+ vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;
2688
+ #endif
2689
+ #ifdef USE_ALPHAMAP
2690
+ vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;
2691
+ #endif
2692
+ #ifdef USE_LIGHTMAP
2693
+ vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;
2694
+ #endif
2695
+ #ifdef USE_AOMAP
2696
+ vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;
2697
+ #endif
2698
+ #ifdef USE_BUMPMAP
2699
+ vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;
2700
+ #endif
2701
+ #ifdef USE_NORMALMAP
2702
+ vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;
2703
+ #endif
2704
+ #ifdef USE_DISPLACEMENTMAP
2705
+ vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;
2706
+ #endif
2707
+ #ifdef USE_EMISSIVEMAP
2708
+ vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;
2709
+ #endif
2710
+ #ifdef USE_METALNESSMAP
2711
+ vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;
2712
+ #endif
2713
+ #ifdef USE_ROUGHNESSMAP
2714
+ vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;
2715
+ #endif
2716
+ #ifdef USE_DIFFUSE_ROUGHNESSMAP
2717
+ vDiffuseRoughnessMapUv = ( diffuseRoughnessMapTransform * vec3( DIFFUSE_ROUGHNESSMAP_UV, 1 ) ).xy;
2718
+ #endif
2719
+ #ifdef USE_ANISOTROPYMAP
2720
+ vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;
2721
+ #endif
2722
+ #ifdef USE_CLEARCOATMAP
2723
+ vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;
2724
+ #endif
2725
+ #ifdef USE_CLEARCOAT_NORMALMAP
2726
+ vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;
2727
+ #endif
2728
+ #ifdef USE_CLEARCOAT_ROUGHNESSMAP
2729
+ vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;
2730
+ #endif
2731
+ #ifdef USE_IRIDESCENCEMAP
2732
+ vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;
2733
+ #endif
2734
+ #ifdef USE_IRIDESCENCE_THICKNESSMAP
2735
+ vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;
2736
+ #endif
2737
+ #ifdef USE_SHEEN_COLORMAP
2738
+ vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;
2739
+ #endif
2740
+ #ifdef USE_SHEEN_ROUGHNESSMAP
2741
+ vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;
2742
+ #endif
2743
+ #ifdef USE_SPECULARMAP
2744
+ vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;
2745
+ #endif
2746
+ #ifdef USE_SPECULAR_COLORMAP
2747
+ vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;
2748
+ #endif
2749
+ #ifdef USE_SPECULAR_INTENSITYMAP
2750
+ vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;
2751
+ #endif
2752
+ #ifdef USE_TRANSMISSIONMAP
2753
+ vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;
2754
+ #endif
2755
+ #ifdef USE_THICKNESSMAP
2756
+ vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;
2757
+ #endif`,worldpos_vertex:`#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0
2758
+ vec4 worldPosition = vec4( transformed, 1.0 );
2759
+ #ifdef USE_BATCHING
2760
+ worldPosition = batchingMatrix * worldPosition;
2761
+ #endif
2762
+ #ifdef USE_INSTANCING
2763
+ worldPosition = instanceMatrix * worldPosition;
2764
+ #endif
2765
+ worldPosition = modelMatrix * worldPosition;
2766
+ #endif`,background_vert:`varying vec2 vUv;
2767
+ uniform mat3 uvTransform;
2768
+ void main() {
2769
+ vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
2770
+ gl_Position = vec4( position.xy, 1.0, 1.0 );
2771
+ }`,background_frag:`uniform sampler2D t2D;
2772
+ uniform float backgroundIntensity;
2773
+ varying vec2 vUv;
2774
+ void main() {
2775
+ vec4 texColor = texture2D( t2D, vUv );
2776
+ #ifdef DECODE_VIDEO_TEXTURE
2777
+ texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );
2778
+ #endif
2779
+ texColor.rgb *= backgroundIntensity;
2780
+ gl_FragColor = texColor;
2781
+ #include <tonemapping_fragment>
2782
+ #include <colorspace_fragment>
2783
+ }`,backgroundCube_vert:`varying vec3 vWorldDirection;
2784
+ #include <common>
2785
+ void main() {
2786
+ vWorldDirection = transformDirection( position, modelMatrix );
2787
+ #include <begin_vertex>
2788
+ #include <project_vertex>
2789
+ gl_Position.z = gl_Position.w;
2790
+ }`,backgroundCube_frag:`uniform float backgroundBlurriness;
2791
+ uniform float backgroundIntensity;
2792
+ uniform mat3 backgroundRotation;
2793
+ varying vec3 vWorldDirection;
2794
+ #include <envmap_common_pars_fragment>
2795
+ void main() {
2796
+ #ifdef ENVMAP_TYPE_PMREM
2797
+ vec4 texColor = textureLod( envMap, backgroundRotation * vWorldDirection, roughnessToMip( backgroundBlurriness ) );
2798
+ #else
2799
+ vec4 texColor = textureCube( envMap, backgroundRotation * vWorldDirection );
2800
+ #endif
2801
+ texColor.rgb *= backgroundIntensity;
2802
+ gl_FragColor = texColor;
2803
+ #include <tonemapping_fragment>
2804
+ #include <colorspace_fragment>
2805
+ }`,cube_vert:`varying vec3 vWorldDirection;
2806
+ #include <common>
2807
+ void main() {
2808
+ vWorldDirection = transformDirection( position, modelMatrix );
2809
+ #include <begin_vertex>
2810
+ #include <project_vertex>
2811
+ gl_Position.z = gl_Position.w;
2812
+ }`,cube_frag:`uniform samplerCube tCube;
2813
+ uniform float tFlip;
2814
+ uniform float opacity;
2815
+ varying vec3 vWorldDirection;
2816
+ void main() {
2817
+ vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );
2818
+ gl_FragColor = texColor;
2819
+ gl_FragColor.a *= opacity;
2820
+ #include <tonemapping_fragment>
2821
+ #include <colorspace_fragment>
2822
+ }`,depth_vert:`#include <common>
2823
+ #include <batching_pars_vertex>
2824
+ #include <uv_pars_vertex>
2825
+ #include <displacementmap_pars_vertex>
2826
+ #include <morphtarget_pars_vertex>
2827
+ #include <skinning_pars_vertex>
2828
+ #include <logdepthbuf_pars_vertex>
2829
+ #include <clipping_planes_pars_vertex>
2830
+ varying vec2 vHighPrecisionZW;
2831
+ void main() {
2832
+ #include <uv_vertex>
2833
+ #include <batching_vertex>
2834
+ #include <skinbase_vertex>
2835
+ #include <morphinstance_vertex>
2836
+ #ifdef USE_DISPLACEMENTMAP
2837
+ #include <beginnormal_vertex>
2838
+ #include <morphnormal_vertex>
2839
+ #include <skinnormal_vertex>
2840
+ #endif
2841
+ #include <begin_vertex>
2842
+ #include <morphtarget_vertex>
2843
+ #include <skinning_vertex>
2844
+ #include <displacementmap_vertex>
2845
+ #include <project_vertex>
2846
+ #include <logdepthbuf_vertex>
2847
+ #include <clipping_planes_vertex>
2848
+ vHighPrecisionZW = gl_Position.zw;
2849
+ }`,depth_frag:`#if DEPTH_PACKING == 3200
2850
+ uniform float opacity;
2851
+ #endif
2852
+ #include <common>
2853
+ #include <packing>
2854
+ #include <uv_pars_fragment>
2855
+ #include <map_pars_fragment>
2856
+ #include <alphamap_pars_fragment>
2857
+ #include <alphatest_pars_fragment>
2858
+ #include <alphahash_pars_fragment>
2859
+ #include <logdepthbuf_pars_fragment>
2860
+ #include <clipping_planes_pars_fragment>
2861
+ varying vec2 vHighPrecisionZW;
2862
+ void main() {
2863
+ vec4 diffuseColor = vec4( 1.0 );
2864
+ #include <clipping_planes_fragment>
2865
+ #if DEPTH_PACKING == 3200
2866
+ diffuseColor.a = opacity;
2867
+ #endif
2868
+ #include <map_fragment>
2869
+ #include <alphamap_fragment>
2870
+ #include <alphatest_fragment>
2871
+ #include <alphahash_fragment>
2872
+ #include <logdepthbuf_fragment>
2873
+ #ifdef USE_REVERSED_DEPTH_BUFFER
2874
+ float fragCoordZ = vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ];
2875
+ #else
2876
+ float fragCoordZ = 0.5 * vHighPrecisionZW[ 0 ] / vHighPrecisionZW[ 1 ] + 0.5;
2877
+ #endif
2878
+ #if DEPTH_PACKING == 3200
2879
+ gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );
2880
+ #elif DEPTH_PACKING == 3201
2881
+ gl_FragColor = packDepthToRGBA( fragCoordZ );
2882
+ #elif DEPTH_PACKING == 3202
2883
+ gl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );
2884
+ #elif DEPTH_PACKING == 3203
2885
+ gl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );
2886
+ #endif
2887
+ }`,distance_vert:`#define DISTANCE
2888
+ varying vec3 vWorldPosition;
2889
+ #include <common>
2890
+ #include <batching_pars_vertex>
2891
+ #include <uv_pars_vertex>
2892
+ #include <displacementmap_pars_vertex>
2893
+ #include <morphtarget_pars_vertex>
2894
+ #include <skinning_pars_vertex>
2895
+ #include <clipping_planes_pars_vertex>
2896
+ void main() {
2897
+ #include <uv_vertex>
2898
+ #include <batching_vertex>
2899
+ #include <skinbase_vertex>
2900
+ #include <morphinstance_vertex>
2901
+ #ifdef USE_DISPLACEMENTMAP
2902
+ #include <beginnormal_vertex>
2903
+ #include <morphnormal_vertex>
2904
+ #include <skinnormal_vertex>
2905
+ #endif
2906
+ #include <begin_vertex>
2907
+ #include <morphtarget_vertex>
2908
+ #include <skinning_vertex>
2909
+ #include <displacementmap_vertex>
2910
+ #include <project_vertex>
2911
+ #include <worldpos_vertex>
2912
+ #include <clipping_planes_vertex>
2913
+ vWorldPosition = worldPosition.xyz;
2914
+ }`,distance_frag:`#define DISTANCE
2915
+ uniform vec3 referencePosition;
2916
+ uniform float nearDistance;
2917
+ uniform float farDistance;
2918
+ varying vec3 vWorldPosition;
2919
+ #include <common>
2920
+ #include <uv_pars_fragment>
2921
+ #include <map_pars_fragment>
2922
+ #include <alphamap_pars_fragment>
2923
+ #include <alphatest_pars_fragment>
2924
+ #include <alphahash_pars_fragment>
2925
+ #include <clipping_planes_pars_fragment>
2926
+ void main() {
2927
+ vec4 diffuseColor = vec4( 1.0 );
2928
+ #include <clipping_planes_fragment>
2929
+ #include <map_fragment>
2930
+ #include <alphamap_fragment>
2931
+ #include <alphatest_fragment>
2932
+ #include <alphahash_fragment>
2933
+ float dist = length( vWorldPosition - referencePosition );
2934
+ dist = ( dist - nearDistance ) / ( farDistance - nearDistance );
2935
+ dist = saturate( dist );
2936
+ gl_FragColor = vec4( dist, 0.0, 0.0, 1.0 );
2937
+ }`,equirect_vert:`varying vec3 vWorldDirection;
2938
+ #include <common>
2939
+ void main() {
2940
+ vWorldDirection = transformDirection( position, modelMatrix );
2941
+ #include <begin_vertex>
2942
+ #include <project_vertex>
2943
+ }`,equirect_frag:`uniform sampler2D tEquirect;
2944
+ varying vec3 vWorldDirection;
2945
+ #include <common>
2946
+ void main() {
2947
+ vec3 direction = normalize( vWorldDirection );
2948
+ vec2 sampleUV = equirectUv( direction );
2949
+ gl_FragColor = texture2D( tEquirect, sampleUV );
2950
+ #include <tonemapping_fragment>
2951
+ #include <colorspace_fragment>
2952
+ }`,linedashed_vert:`uniform float scale;
2953
+ attribute float lineDistance;
2954
+ varying float vLineDistance;
2955
+ #include <common>
2956
+ #include <uv_pars_vertex>
2957
+ #include <color_pars_vertex>
2958
+ #include <fog_pars_vertex>
2959
+ #include <morphtarget_pars_vertex>
2960
+ #include <logdepthbuf_pars_vertex>
2961
+ #include <clipping_planes_pars_vertex>
2962
+ void main() {
2963
+ vLineDistance = scale * lineDistance;
2964
+ #include <uv_vertex>
2965
+ #include <color_vertex>
2966
+ #include <morphinstance_vertex>
2967
+ #include <morphcolor_vertex>
2968
+ #include <begin_vertex>
2969
+ #include <morphtarget_vertex>
2970
+ #include <project_vertex>
2971
+ #include <logdepthbuf_vertex>
2972
+ #include <clipping_planes_vertex>
2973
+ #include <fog_vertex>
2974
+ }`,linedashed_frag:`uniform vec3 diffuse;
2975
+ uniform float opacity;
2976
+ uniform float dashSize;
2977
+ uniform float totalSize;
2978
+ varying float vLineDistance;
2979
+ #include <common>
2980
+ #include <color_pars_fragment>
2981
+ #include <uv_pars_fragment>
2982
+ #include <map_pars_fragment>
2983
+ #include <fog_pars_fragment>
2984
+ #include <logdepthbuf_pars_fragment>
2985
+ #include <clipping_planes_pars_fragment>
2986
+ void main() {
2987
+ vec4 diffuseColor = vec4( diffuse, opacity );
2988
+ #include <clipping_planes_fragment>
2989
+ if ( mod( vLineDistance, totalSize ) > dashSize ) {
2990
+ discard;
2991
+ }
2992
+ vec3 outgoingLight = vec3( 0.0 );
2993
+ #include <logdepthbuf_fragment>
2994
+ #include <map_fragment>
2995
+ #include <color_fragment>
2996
+ outgoingLight = diffuseColor.rgb;
2997
+ #include <opaque_fragment>
2998
+ #include <tonemapping_fragment>
2999
+ #include <colorspace_fragment>
3000
+ #include <fog_fragment>
3001
+ #include <premultiplied_alpha_fragment>
3002
+ }`,meshbasic_vert:`#include <common>
3003
+ #include <batching_pars_vertex>
3004
+ #include <uv_pars_vertex>
3005
+ #include <envmap_pars_vertex>
3006
+ #include <color_pars_vertex>
3007
+ #include <fog_pars_vertex>
3008
+ #include <morphtarget_pars_vertex>
3009
+ #include <skinning_pars_vertex>
3010
+ #include <logdepthbuf_pars_vertex>
3011
+ #include <clipping_planes_pars_vertex>
3012
+ void main() {
3013
+ #include <uv_vertex>
3014
+ #include <color_vertex>
3015
+ #include <morphinstance_vertex>
3016
+ #include <morphcolor_vertex>
3017
+ #include <batching_vertex>
3018
+ #if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )
3019
+ #include <beginnormal_vertex>
3020
+ #include <morphnormal_vertex>
3021
+ #include <skinbase_vertex>
3022
+ #include <skinnormal_vertex>
3023
+ #include <defaultnormal_vertex>
3024
+ #endif
3025
+ #include <begin_vertex>
3026
+ #include <morphtarget_vertex>
3027
+ #include <skinning_vertex>
3028
+ #include <project_vertex>
3029
+ #include <logdepthbuf_vertex>
3030
+ #include <clipping_planes_vertex>
3031
+ #include <worldpos_vertex>
3032
+ #include <envmap_vertex>
3033
+ #include <fog_vertex>
3034
+ }`,meshbasic_frag:`uniform vec3 diffuse;
3035
+ uniform float opacity;
3036
+ #ifndef FLAT_SHADED
3037
+ varying vec3 vNormal;
3038
+ #endif
3039
+ #include <common>
3040
+ #include <dithering_pars_fragment>
3041
+ #include <color_pars_fragment>
3042
+ #include <uv_pars_fragment>
3043
+ #include <map_pars_fragment>
3044
+ #include <alphamap_pars_fragment>
3045
+ #include <alphatest_pars_fragment>
3046
+ #include <alphahash_pars_fragment>
3047
+ #include <aomap_pars_fragment>
3048
+ #include <lightmap_pars_fragment>
3049
+ #include <envmap_common_pars_fragment>
3050
+ #include <envmap_pars_fragment>
3051
+ #include <fog_pars_fragment>
3052
+ #include <specularmap_pars_fragment>
3053
+ #include <logdepthbuf_pars_fragment>
3054
+ #include <clipping_planes_pars_fragment>
3055
+ void main() {
3056
+ vec4 diffuseColor = vec4( diffuse, opacity );
3057
+ #include <clipping_planes_fragment>
3058
+ #include <logdepthbuf_fragment>
3059
+ #include <map_fragment>
3060
+ #include <color_fragment>
3061
+ #include <alphamap_fragment>
3062
+ #include <alphatest_fragment>
3063
+ #include <alphahash_fragment>
3064
+ #include <specularmap_fragment>
3065
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
3066
+ #ifdef USE_LIGHTMAP
3067
+ vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
3068
+ reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;
3069
+ #else
3070
+ reflectedLight.indirectDiffuse += vec3( 1.0 );
3071
+ #endif
3072
+ #include <aomap_fragment>
3073
+ reflectedLight.indirectDiffuse *= diffuseColor.rgb;
3074
+ vec3 outgoingLight = reflectedLight.indirectDiffuse;
3075
+ #include <envmap_fragment>
3076
+ #include <opaque_fragment>
3077
+ #include <tonemapping_fragment>
3078
+ #include <colorspace_fragment>
3079
+ #include <fog_fragment>
3080
+ #include <premultiplied_alpha_fragment>
3081
+ #include <dithering_fragment>
3082
+ }`,meshlambert_vert:`#define LAMBERT
3083
+ varying vec3 vViewPosition;
3084
+ #include <common>
3085
+ #include <batching_pars_vertex>
3086
+ #include <uv_pars_vertex>
3087
+ #include <displacementmap_pars_vertex>
3088
+ #include <envmap_pars_vertex>
3089
+ #include <color_pars_vertex>
3090
+ #include <fog_pars_vertex>
3091
+ #include <normal_pars_vertex>
3092
+ #include <morphtarget_pars_vertex>
3093
+ #include <skinning_pars_vertex>
3094
+ #include <shadowmap_pars_vertex>
3095
+ #include <logdepthbuf_pars_vertex>
3096
+ #include <clipping_planes_pars_vertex>
3097
+ void main() {
3098
+ #include <uv_vertex>
3099
+ #include <color_vertex>
3100
+ #include <morphinstance_vertex>
3101
+ #include <morphcolor_vertex>
3102
+ #include <batching_vertex>
3103
+ #include <beginnormal_vertex>
3104
+ #include <morphnormal_vertex>
3105
+ #include <skinbase_vertex>
3106
+ #include <skinnormal_vertex>
3107
+ #include <defaultnormal_vertex>
3108
+ #include <normal_vertex>
3109
+ #include <begin_vertex>
3110
+ #include <morphtarget_vertex>
3111
+ #include <skinning_vertex>
3112
+ #include <displacementmap_vertex>
3113
+ #include <project_vertex>
3114
+ #include <logdepthbuf_vertex>
3115
+ #include <clipping_planes_vertex>
3116
+ vViewPosition = - mvPosition.xyz;
3117
+ #include <worldpos_vertex>
3118
+ #include <envmap_vertex>
3119
+ #include <shadowmap_vertex>
3120
+ #include <fog_vertex>
3121
+ }`,meshlambert_frag:`#define LAMBERT
3122
+ uniform vec3 diffuse;
3123
+ uniform vec3 emissive;
3124
+ uniform float opacity;
3125
+ #include <common>
3126
+ #include <dithering_pars_fragment>
3127
+ #include <color_pars_fragment>
3128
+ #include <uv_pars_fragment>
3129
+ #include <map_pars_fragment>
3130
+ #include <alphamap_pars_fragment>
3131
+ #include <alphatest_pars_fragment>
3132
+ #include <alphahash_pars_fragment>
3133
+ #include <aomap_pars_fragment>
3134
+ #include <lightmap_pars_fragment>
3135
+ #include <emissivemap_pars_fragment>
3136
+ #include <envmap_common_pars_fragment>
3137
+ #include <envmap_pars_fragment>
3138
+ #include <envmap_physical_pars_fragment>
3139
+ #include <fog_pars_fragment>
3140
+ #include <bsdfs>
3141
+ #include <lights_pars_begin>
3142
+ #include <normal_pars_fragment>
3143
+ #include <lights_lambert_pars_fragment>
3144
+ #include <shadowmap_pars_fragment>
3145
+ #include <bumpmap_pars_fragment>
3146
+ #include <normalmap_pars_fragment>
3147
+ #include <specularmap_pars_fragment>
3148
+ #include <logdepthbuf_pars_fragment>
3149
+ #include <clipping_planes_pars_fragment>
3150
+ void main() {
3151
+ vec4 diffuseColor = vec4( diffuse, opacity );
3152
+ #include <clipping_planes_fragment>
3153
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
3154
+ vec3 totalEmissiveRadiance = emissive;
3155
+ #include <logdepthbuf_fragment>
3156
+ #include <map_fragment>
3157
+ #include <color_fragment>
3158
+ #include <alphamap_fragment>
3159
+ #include <alphatest_fragment>
3160
+ #include <alphahash_fragment>
3161
+ #include <specularmap_fragment>
3162
+ #include <normal_fragment_begin>
3163
+ #include <normal_fragment_maps>
3164
+ #include <emissivemap_fragment>
3165
+ #include <lights_lambert_fragment>
3166
+ #include <lights_fragment_begin>
3167
+ #include <lights_fragment_maps>
3168
+ #include <lights_fragment_end>
3169
+ #include <aomap_fragment>
3170
+ vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
3171
+ #include <envmap_fragment>
3172
+ #include <opaque_fragment>
3173
+ #include <tonemapping_fragment>
3174
+ #include <colorspace_fragment>
3175
+ #include <fog_fragment>
3176
+ #include <premultiplied_alpha_fragment>
3177
+ #include <dithering_fragment>
3178
+ }`,meshmatcap_vert:`#define MATCAP
3179
+ varying vec3 vViewPosition;
3180
+ #include <common>
3181
+ #include <batching_pars_vertex>
3182
+ #include <uv_pars_vertex>
3183
+ #include <color_pars_vertex>
3184
+ #include <displacementmap_pars_vertex>
3185
+ #include <fog_pars_vertex>
3186
+ #include <normal_pars_vertex>
3187
+ #include <morphtarget_pars_vertex>
3188
+ #include <skinning_pars_vertex>
3189
+ #include <logdepthbuf_pars_vertex>
3190
+ #include <clipping_planes_pars_vertex>
3191
+ void main() {
3192
+ #include <uv_vertex>
3193
+ #include <color_vertex>
3194
+ #include <morphinstance_vertex>
3195
+ #include <morphcolor_vertex>
3196
+ #include <batching_vertex>
3197
+ #include <beginnormal_vertex>
3198
+ #include <morphnormal_vertex>
3199
+ #include <skinbase_vertex>
3200
+ #include <skinnormal_vertex>
3201
+ #include <defaultnormal_vertex>
3202
+ #include <normal_vertex>
3203
+ #include <begin_vertex>
3204
+ #include <morphtarget_vertex>
3205
+ #include <skinning_vertex>
3206
+ #include <displacementmap_vertex>
3207
+ #include <project_vertex>
3208
+ #include <logdepthbuf_vertex>
3209
+ #include <clipping_planes_vertex>
3210
+ #include <fog_vertex>
3211
+ vViewPosition = - mvPosition.xyz;
3212
+ }`,meshmatcap_frag:`#define MATCAP
3213
+ uniform vec3 diffuse;
3214
+ uniform float opacity;
3215
+ uniform sampler2D matcap;
3216
+ varying vec3 vViewPosition;
3217
+ #include <common>
3218
+ #include <dithering_pars_fragment>
3219
+ #include <color_pars_fragment>
3220
+ #include <uv_pars_fragment>
3221
+ #include <map_pars_fragment>
3222
+ #include <alphamap_pars_fragment>
3223
+ #include <alphatest_pars_fragment>
3224
+ #include <alphahash_pars_fragment>
3225
+ #include <fog_pars_fragment>
3226
+ #include <normal_pars_fragment>
3227
+ #include <bumpmap_pars_fragment>
3228
+ #include <normalmap_pars_fragment>
3229
+ #include <logdepthbuf_pars_fragment>
3230
+ #include <clipping_planes_pars_fragment>
3231
+ void main() {
3232
+ vec4 diffuseColor = vec4( diffuse, opacity );
3233
+ #include <clipping_planes_fragment>
3234
+ #include <logdepthbuf_fragment>
3235
+ #include <map_fragment>
3236
+ #include <color_fragment>
3237
+ #include <alphamap_fragment>
3238
+ #include <alphatest_fragment>
3239
+ #include <alphahash_fragment>
3240
+ #include <normal_fragment_begin>
3241
+ #include <normal_fragment_maps>
3242
+ vec3 viewDir = normalize( vViewPosition );
3243
+ vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );
3244
+ vec3 y = cross( viewDir, x );
3245
+ vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;
3246
+ #ifdef USE_MATCAP
3247
+ vec4 matcapColor = texture2D( matcap, uv );
3248
+ #else
3249
+ vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );
3250
+ #endif
3251
+ vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;
3252
+ #include <opaque_fragment>
3253
+ #include <tonemapping_fragment>
3254
+ #include <colorspace_fragment>
3255
+ #include <fog_fragment>
3256
+ #include <premultiplied_alpha_fragment>
3257
+ #include <dithering_fragment>
3258
+ }`,meshnormal_vert:`#define NORMAL
3259
+ #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
3260
+ varying vec3 vViewPosition;
3261
+ #endif
3262
+ #include <common>
3263
+ #include <batching_pars_vertex>
3264
+ #include <uv_pars_vertex>
3265
+ #include <displacementmap_pars_vertex>
3266
+ #include <normal_pars_vertex>
3267
+ #include <morphtarget_pars_vertex>
3268
+ #include <skinning_pars_vertex>
3269
+ #include <logdepthbuf_pars_vertex>
3270
+ #include <clipping_planes_pars_vertex>
3271
+ void main() {
3272
+ #include <uv_vertex>
3273
+ #include <batching_vertex>
3274
+ #include <beginnormal_vertex>
3275
+ #include <morphinstance_vertex>
3276
+ #include <morphnormal_vertex>
3277
+ #include <skinbase_vertex>
3278
+ #include <skinnormal_vertex>
3279
+ #include <defaultnormal_vertex>
3280
+ #include <normal_vertex>
3281
+ #include <begin_vertex>
3282
+ #include <morphtarget_vertex>
3283
+ #include <skinning_vertex>
3284
+ #include <displacementmap_vertex>
3285
+ #include <project_vertex>
3286
+ #include <logdepthbuf_vertex>
3287
+ #include <clipping_planes_vertex>
3288
+ #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
3289
+ vViewPosition = - mvPosition.xyz;
3290
+ #endif
3291
+ }`,meshnormal_frag:`#define NORMAL
3292
+ uniform float opacity;
3293
+ #if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )
3294
+ varying vec3 vViewPosition;
3295
+ #endif
3296
+ #include <uv_pars_fragment>
3297
+ #include <normal_pars_fragment>
3298
+ #include <bumpmap_pars_fragment>
3299
+ #include <normalmap_pars_fragment>
3300
+ #include <logdepthbuf_pars_fragment>
3301
+ #include <clipping_planes_pars_fragment>
3302
+ void main() {
3303
+ vec4 diffuseColor = vec4( 0.0, 0.0, 0.0, opacity );
3304
+ #include <clipping_planes_fragment>
3305
+ #include <logdepthbuf_fragment>
3306
+ #include <normal_fragment_begin>
3307
+ #include <normal_fragment_maps>
3308
+ gl_FragColor = vec4( normalize( normal ) * 0.5 + 0.5, diffuseColor.a );
3309
+ #ifdef OPAQUE
3310
+ gl_FragColor.a = 1.0;
3311
+ #endif
3312
+ }`,meshphong_vert:`#define PHONG
3313
+ varying vec3 vViewPosition;
3314
+ #include <common>
3315
+ #include <batching_pars_vertex>
3316
+ #include <uv_pars_vertex>
3317
+ #include <displacementmap_pars_vertex>
3318
+ #include <envmap_pars_vertex>
3319
+ #include <color_pars_vertex>
3320
+ #include <fog_pars_vertex>
3321
+ #include <normal_pars_vertex>
3322
+ #include <morphtarget_pars_vertex>
3323
+ #include <skinning_pars_vertex>
3324
+ #include <shadowmap_pars_vertex>
3325
+ #include <logdepthbuf_pars_vertex>
3326
+ #include <clipping_planes_pars_vertex>
3327
+ void main() {
3328
+ #include <uv_vertex>
3329
+ #include <color_vertex>
3330
+ #include <morphcolor_vertex>
3331
+ #include <batching_vertex>
3332
+ #include <beginnormal_vertex>
3333
+ #include <morphinstance_vertex>
3334
+ #include <morphnormal_vertex>
3335
+ #include <skinbase_vertex>
3336
+ #include <skinnormal_vertex>
3337
+ #include <defaultnormal_vertex>
3338
+ #include <normal_vertex>
3339
+ #include <begin_vertex>
3340
+ #include <morphtarget_vertex>
3341
+ #include <skinning_vertex>
3342
+ #include <displacementmap_vertex>
3343
+ #include <project_vertex>
3344
+ #include <logdepthbuf_vertex>
3345
+ #include <clipping_planes_vertex>
3346
+ vViewPosition = - mvPosition.xyz;
3347
+ #include <worldpos_vertex>
3348
+ #include <envmap_vertex>
3349
+ #include <shadowmap_vertex>
3350
+ #include <fog_vertex>
3351
+ }`,meshphong_frag:`#define PHONG
3352
+ uniform vec3 diffuse;
3353
+ uniform vec3 emissive;
3354
+ uniform vec3 specular;
3355
+ uniform float shininess;
3356
+ uniform float opacity;
3357
+ #include <common>
3358
+ #include <dithering_pars_fragment>
3359
+ #include <color_pars_fragment>
3360
+ #include <uv_pars_fragment>
3361
+ #include <map_pars_fragment>
3362
+ #include <alphamap_pars_fragment>
3363
+ #include <alphatest_pars_fragment>
3364
+ #include <alphahash_pars_fragment>
3365
+ #include <aomap_pars_fragment>
3366
+ #include <lightmap_pars_fragment>
3367
+ #include <emissivemap_pars_fragment>
3368
+ #include <envmap_common_pars_fragment>
3369
+ #include <envmap_pars_fragment>
3370
+ #include <envmap_physical_pars_fragment>
3371
+ #include <fog_pars_fragment>
3372
+ #include <bsdfs>
3373
+ #include <lights_pars_begin>
3374
+ #include <normal_pars_fragment>
3375
+ #include <lights_phong_pars_fragment>
3376
+ #include <shadowmap_pars_fragment>
3377
+ #include <bumpmap_pars_fragment>
3378
+ #include <normalmap_pars_fragment>
3379
+ #include <specularmap_pars_fragment>
3380
+ #include <logdepthbuf_pars_fragment>
3381
+ #include <clipping_planes_pars_fragment>
3382
+ void main() {
3383
+ vec4 diffuseColor = vec4( diffuse, opacity );
3384
+ #include <clipping_planes_fragment>
3385
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
3386
+ vec3 totalEmissiveRadiance = emissive;
3387
+ #include <logdepthbuf_fragment>
3388
+ #include <map_fragment>
3389
+ #include <color_fragment>
3390
+ #include <alphamap_fragment>
3391
+ #include <alphatest_fragment>
3392
+ #include <alphahash_fragment>
3393
+ #include <specularmap_fragment>
3394
+ #include <normal_fragment_begin>
3395
+ #include <normal_fragment_maps>
3396
+ #include <emissivemap_fragment>
3397
+ #include <lights_phong_fragment>
3398
+ #include <lights_fragment_begin>
3399
+ #include <lights_fragment_maps>
3400
+ #include <lights_fragment_end>
3401
+ #include <aomap_fragment>
3402
+ vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;
3403
+ #include <envmap_fragment>
3404
+ #include <opaque_fragment>
3405
+ #include <tonemapping_fragment>
3406
+ #include <colorspace_fragment>
3407
+ #include <fog_fragment>
3408
+ #include <premultiplied_alpha_fragment>
3409
+ #include <dithering_fragment>
3410
+ }`,meshphysical_vert:`#define STANDARD
3411
+ varying vec3 vViewPosition;
3412
+ #ifdef USE_TRANSMISSION
3413
+ varying vec3 vWorldPosition;
3414
+ #endif
3415
+ #include <common>
3416
+ #include <batching_pars_vertex>
3417
+ #include <uv_pars_vertex>
3418
+ #include <displacementmap_pars_vertex>
3419
+ #include <color_pars_vertex>
3420
+ #include <fog_pars_vertex>
3421
+ #include <normal_pars_vertex>
3422
+ #include <morphtarget_pars_vertex>
3423
+ #include <skinning_pars_vertex>
3424
+ #include <shadowmap_pars_vertex>
3425
+ #include <logdepthbuf_pars_vertex>
3426
+ #include <clipping_planes_pars_vertex>
3427
+ void main() {
3428
+ #include <uv_vertex>
3429
+ #include <color_vertex>
3430
+ #include <morphinstance_vertex>
3431
+ #include <morphcolor_vertex>
3432
+ #include <batching_vertex>
3433
+ #include <beginnormal_vertex>
3434
+ #include <morphnormal_vertex>
3435
+ #include <skinbase_vertex>
3436
+ #include <skinnormal_vertex>
3437
+ #include <defaultnormal_vertex>
3438
+ #include <normal_vertex>
3439
+ #include <begin_vertex>
3440
+ #include <morphtarget_vertex>
3441
+ #include <skinning_vertex>
3442
+ #include <displacementmap_vertex>
3443
+ #include <project_vertex>
3444
+ #include <logdepthbuf_vertex>
3445
+ #include <clipping_planes_vertex>
3446
+ vViewPosition = - mvPosition.xyz;
3447
+ #include <worldpos_vertex>
3448
+ #include <shadowmap_vertex>
3449
+ #include <fog_vertex>
3450
+ #ifdef USE_TRANSMISSION
3451
+ vWorldPosition = worldPosition.xyz;
3452
+ #endif
3453
+ }`,meshphysical_frag:`#define STANDARD
3454
+ #ifdef PHYSICAL
3455
+ #define IOR
3456
+ #define USE_SPECULAR
3457
+ #endif
3458
+ uniform vec3 diffuse;
3459
+ uniform vec3 emissive;
3460
+ uniform float roughness;
3461
+ uniform float metalness;
3462
+ uniform float opacity;
3463
+ #ifdef IOR
3464
+ uniform float ior;
3465
+ #endif
3466
+ #ifdef USE_SPECULAR
3467
+ uniform float specularIntensity;
3468
+ uniform vec3 specularColor;
3469
+ #ifdef USE_SPECULAR_COLORMAP
3470
+ uniform sampler2D specularColorMap;
3471
+ #endif
3472
+ #ifdef USE_SPECULAR_INTENSITYMAP
3473
+ uniform sampler2D specularIntensityMap;
3474
+ #endif
3475
+ #endif
3476
+ #ifdef USE_CLEARCOAT
3477
+ uniform float clearcoat;
3478
+ uniform float clearcoatRoughness;
3479
+ #endif
3480
+ #ifdef USE_DIFFUSE_ROUGHNESS
3481
+ uniform float diffuseRoughness;
3482
+ #ifdef USE_DIFFUSE_ROUGHNESSMAP
3483
+ uniform sampler2D diffuseRoughnessMap;
3484
+ #endif
3485
+ #endif
3486
+ #ifdef USE_DISPERSION
3487
+ uniform float dispersion;
3488
+ #endif
3489
+ #ifdef USE_RETROREFLECTION
3490
+ uniform float retroreflectivity;
3491
+ #endif
3492
+ #ifdef USE_IRIDESCENCE
3493
+ uniform float iridescence;
3494
+ uniform float iridescenceIOR;
3495
+ uniform float iridescenceThicknessMinimum;
3496
+ uniform float iridescenceThicknessMaximum;
3497
+ #endif
3498
+ #ifdef USE_SHEEN
3499
+ uniform vec3 sheenColor;
3500
+ uniform float sheenRoughness;
3501
+ #ifdef USE_SHEEN_COLORMAP
3502
+ uniform sampler2D sheenColorMap;
3503
+ #endif
3504
+ #ifdef USE_SHEEN_ROUGHNESSMAP
3505
+ uniform sampler2D sheenRoughnessMap;
3506
+ #endif
3507
+ #endif
3508
+ #ifdef USE_ANISOTROPY
3509
+ uniform vec2 anisotropyVector;
3510
+ #ifdef USE_ANISOTROPYMAP
3511
+ uniform sampler2D anisotropyMap;
3512
+ #endif
3513
+ #endif
3514
+ varying vec3 vViewPosition;
3515
+ #include <common>
3516
+ #include <dithering_pars_fragment>
3517
+ #include <color_pars_fragment>
3518
+ #include <uv_pars_fragment>
3519
+ #include <map_pars_fragment>
3520
+ #include <alphamap_pars_fragment>
3521
+ #include <alphatest_pars_fragment>
3522
+ #include <alphahash_pars_fragment>
3523
+ #include <aomap_pars_fragment>
3524
+ #include <lightmap_pars_fragment>
3525
+ #include <emissivemap_pars_fragment>
3526
+ #include <iridescence_fragment>
3527
+ #include <envmap_common_pars_fragment>
3528
+ #include <envmap_physical_pars_fragment>
3529
+ #include <fog_pars_fragment>
3530
+ #include <lights_pars_begin>
3531
+ #include <normal_pars_fragment>
3532
+ #include <lights_physical_pars_fragment>
3533
+ #include <transmission_pars_fragment>
3534
+ #include <shadowmap_pars_fragment>
3535
+ #include <bumpmap_pars_fragment>
3536
+ #include <normalmap_pars_fragment>
3537
+ #include <clearcoat_pars_fragment>
3538
+ #include <iridescence_pars_fragment>
3539
+ #include <roughnessmap_pars_fragment>
3540
+ #include <metalnessmap_pars_fragment>
3541
+ #include <logdepthbuf_pars_fragment>
3542
+ #include <clipping_planes_pars_fragment>
3543
+ void main() {
3544
+ vec4 diffuseColor = vec4( diffuse, opacity );
3545
+ #include <clipping_planes_fragment>
3546
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
3547
+ vec3 totalEmissiveRadiance = emissive;
3548
+ #include <logdepthbuf_fragment>
3549
+ #include <map_fragment>
3550
+ #include <color_fragment>
3551
+ #include <alphamap_fragment>
3552
+ #include <alphatest_fragment>
3553
+ #include <alphahash_fragment>
3554
+ #include <roughnessmap_fragment>
3555
+ #include <metalnessmap_fragment>
3556
+ #include <normal_fragment_begin>
3557
+ #include <normal_fragment_maps>
3558
+ #include <clearcoat_normal_fragment_begin>
3559
+ #include <clearcoat_normal_fragment_maps>
3560
+ #include <emissivemap_fragment>
3561
+ #include <lights_physical_fragment>
3562
+ #include <lights_fragment_begin>
3563
+ #include <lights_fragment_maps>
3564
+ #include <lights_fragment_end>
3565
+ #include <aomap_fragment>
3566
+ vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;
3567
+ vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;
3568
+ #include <transmission_fragment>
3569
+ vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;
3570
+ #ifdef USE_SHEEN
3571
+
3572
+ outgoingLight = outgoingLight + sheenSpecularDirect + sheenSpecularIndirect;
3573
+
3574
+ #endif
3575
+ #ifdef USE_CLEARCOAT
3576
+ float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );
3577
+ vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );
3578
+ outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;
3579
+ #endif
3580
+ #include <opaque_fragment>
3581
+ #include <tonemapping_fragment>
3582
+ #include <colorspace_fragment>
3583
+ #include <fog_fragment>
3584
+ #include <premultiplied_alpha_fragment>
3585
+ #include <dithering_fragment>
3586
+ }`,meshtoon_vert:`#define TOON
3587
+ varying vec3 vViewPosition;
3588
+ #include <common>
3589
+ #include <batching_pars_vertex>
3590
+ #include <uv_pars_vertex>
3591
+ #include <displacementmap_pars_vertex>
3592
+ #include <color_pars_vertex>
3593
+ #include <fog_pars_vertex>
3594
+ #include <normal_pars_vertex>
3595
+ #include <morphtarget_pars_vertex>
3596
+ #include <skinning_pars_vertex>
3597
+ #include <shadowmap_pars_vertex>
3598
+ #include <logdepthbuf_pars_vertex>
3599
+ #include <clipping_planes_pars_vertex>
3600
+ void main() {
3601
+ #include <uv_vertex>
3602
+ #include <color_vertex>
3603
+ #include <morphinstance_vertex>
3604
+ #include <morphcolor_vertex>
3605
+ #include <batching_vertex>
3606
+ #include <beginnormal_vertex>
3607
+ #include <morphnormal_vertex>
3608
+ #include <skinbase_vertex>
3609
+ #include <skinnormal_vertex>
3610
+ #include <defaultnormal_vertex>
3611
+ #include <normal_vertex>
3612
+ #include <begin_vertex>
3613
+ #include <morphtarget_vertex>
3614
+ #include <skinning_vertex>
3615
+ #include <displacementmap_vertex>
3616
+ #include <project_vertex>
3617
+ #include <logdepthbuf_vertex>
3618
+ #include <clipping_planes_vertex>
3619
+ vViewPosition = - mvPosition.xyz;
3620
+ #include <worldpos_vertex>
3621
+ #include <shadowmap_vertex>
3622
+ #include <fog_vertex>
3623
+ }`,meshtoon_frag:`#define TOON
3624
+ uniform vec3 diffuse;
3625
+ uniform vec3 emissive;
3626
+ uniform float opacity;
3627
+ #include <common>
3628
+ #include <dithering_pars_fragment>
3629
+ #include <color_pars_fragment>
3630
+ #include <uv_pars_fragment>
3631
+ #include <map_pars_fragment>
3632
+ #include <alphamap_pars_fragment>
3633
+ #include <alphatest_pars_fragment>
3634
+ #include <alphahash_pars_fragment>
3635
+ #include <aomap_pars_fragment>
3636
+ #include <lightmap_pars_fragment>
3637
+ #include <emissivemap_pars_fragment>
3638
+ #include <gradientmap_pars_fragment>
3639
+ #include <fog_pars_fragment>
3640
+ #include <bsdfs>
3641
+ #include <lights_pars_begin>
3642
+ #include <normal_pars_fragment>
3643
+ #include <lights_toon_pars_fragment>
3644
+ #include <shadowmap_pars_fragment>
3645
+ #include <bumpmap_pars_fragment>
3646
+ #include <normalmap_pars_fragment>
3647
+ #include <logdepthbuf_pars_fragment>
3648
+ #include <clipping_planes_pars_fragment>
3649
+ void main() {
3650
+ vec4 diffuseColor = vec4( diffuse, opacity );
3651
+ #include <clipping_planes_fragment>
3652
+ ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );
3653
+ vec3 totalEmissiveRadiance = emissive;
3654
+ #include <logdepthbuf_fragment>
3655
+ #include <map_fragment>
3656
+ #include <color_fragment>
3657
+ #include <alphamap_fragment>
3658
+ #include <alphatest_fragment>
3659
+ #include <alphahash_fragment>
3660
+ #include <normal_fragment_begin>
3661
+ #include <normal_fragment_maps>
3662
+ #include <emissivemap_fragment>
3663
+ #include <lights_toon_fragment>
3664
+ #include <lights_fragment_begin>
3665
+ #include <lights_fragment_maps>
3666
+ #include <lights_fragment_end>
3667
+ #include <aomap_fragment>
3668
+ vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;
3669
+ #include <opaque_fragment>
3670
+ #include <tonemapping_fragment>
3671
+ #include <colorspace_fragment>
3672
+ #include <fog_fragment>
3673
+ #include <premultiplied_alpha_fragment>
3674
+ #include <dithering_fragment>
3675
+ }`,points_vert:`uniform float size;
3676
+ uniform float scale;
3677
+ #include <common>
3678
+ #include <color_pars_vertex>
3679
+ #include <fog_pars_vertex>
3680
+ #include <morphtarget_pars_vertex>
3681
+ #include <logdepthbuf_pars_vertex>
3682
+ #include <clipping_planes_pars_vertex>
3683
+ #ifdef USE_POINTS_UV
3684
+ varying vec2 vUv;
3685
+ uniform mat3 uvTransform;
3686
+ #endif
3687
+ void main() {
3688
+ #ifdef USE_POINTS_UV
3689
+ vUv = ( uvTransform * vec3( uv, 1 ) ).xy;
3690
+ #endif
3691
+ #include <color_vertex>
3692
+ #include <morphinstance_vertex>
3693
+ #include <morphcolor_vertex>
3694
+ #include <begin_vertex>
3695
+ #include <morphtarget_vertex>
3696
+ #include <project_vertex>
3697
+ gl_PointSize = size;
3698
+ #ifdef USE_SIZEATTENUATION
3699
+ bool isPerspective = isPerspectiveMatrix( projectionMatrix );
3700
+ if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );
3701
+ #endif
3702
+ #include <logdepthbuf_vertex>
3703
+ #include <clipping_planes_vertex>
3704
+ #include <worldpos_vertex>
3705
+ #include <fog_vertex>
3706
+ }`,points_frag:`uniform vec3 diffuse;
3707
+ uniform float opacity;
3708
+ #include <common>
3709
+ #include <color_pars_fragment>
3710
+ #include <map_particle_pars_fragment>
3711
+ #include <alphatest_pars_fragment>
3712
+ #include <alphahash_pars_fragment>
3713
+ #include <fog_pars_fragment>
3714
+ #include <logdepthbuf_pars_fragment>
3715
+ #include <clipping_planes_pars_fragment>
3716
+ void main() {
3717
+ vec4 diffuseColor = vec4( diffuse, opacity );
3718
+ #include <clipping_planes_fragment>
3719
+ vec3 outgoingLight = vec3( 0.0 );
3720
+ #include <logdepthbuf_fragment>
3721
+ #include <map_particle_fragment>
3722
+ #include <color_fragment>
3723
+ #include <alphatest_fragment>
3724
+ #include <alphahash_fragment>
3725
+ outgoingLight = diffuseColor.rgb;
3726
+ #include <opaque_fragment>
3727
+ #include <tonemapping_fragment>
3728
+ #include <colorspace_fragment>
3729
+ #include <fog_fragment>
3730
+ #include <premultiplied_alpha_fragment>
3731
+ }`,shadow_vert:`#include <common>
3732
+ #include <batching_pars_vertex>
3733
+ #include <fog_pars_vertex>
3734
+ #include <morphtarget_pars_vertex>
3735
+ #include <skinning_pars_vertex>
3736
+ #include <logdepthbuf_pars_vertex>
3737
+ #include <shadowmap_pars_vertex>
3738
+ void main() {
3739
+ #include <batching_vertex>
3740
+ #include <beginnormal_vertex>
3741
+ #include <morphinstance_vertex>
3742
+ #include <morphnormal_vertex>
3743
+ #include <skinbase_vertex>
3744
+ #include <skinnormal_vertex>
3745
+ #include <defaultnormal_vertex>
3746
+ #include <begin_vertex>
3747
+ #include <morphtarget_vertex>
3748
+ #include <skinning_vertex>
3749
+ #include <project_vertex>
3750
+ #include <logdepthbuf_vertex>
3751
+ #include <worldpos_vertex>
3752
+ #include <shadowmap_vertex>
3753
+ #include <fog_vertex>
3754
+ }`,shadow_frag:`uniform vec3 color;
3755
+ uniform float opacity;
3756
+ #include <common>
3757
+ #include <fog_pars_fragment>
3758
+ #include <bsdfs>
3759
+ #include <lights_pars_begin>
3760
+ #include <logdepthbuf_pars_fragment>
3761
+ #include <shadowmap_pars_fragment>
3762
+ #include <shadowmask_pars_fragment>
3763
+ void main() {
3764
+ #include <logdepthbuf_fragment>
3765
+ gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );
3766
+ #include <tonemapping_fragment>
3767
+ #include <colorspace_fragment>
3768
+ #include <fog_fragment>
3769
+ #include <premultiplied_alpha_fragment>
3770
+ }`,sprite_vert:`uniform float rotation;
3771
+ uniform vec2 center;
3772
+ #include <common>
3773
+ #include <uv_pars_vertex>
3774
+ #include <fog_pars_vertex>
3775
+ #include <logdepthbuf_pars_vertex>
3776
+ #include <clipping_planes_pars_vertex>
3777
+ void main() {
3778
+ #include <uv_vertex>
3779
+ vec4 mvPosition = modelViewMatrix[ 3 ];
3780
+ vec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );
3781
+ #ifndef USE_SIZEATTENUATION
3782
+ bool isPerspective = isPerspectiveMatrix( projectionMatrix );
3783
+ if ( isPerspective ) scale *= - mvPosition.z;
3784
+ #endif
3785
+ vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;
3786
+ vec2 rotatedPosition;
3787
+ rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
3788
+ rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;
3789
+ mvPosition.xy += rotatedPosition;
3790
+ gl_Position = projectionMatrix * mvPosition;
3791
+ #include <logdepthbuf_vertex>
3792
+ #include <clipping_planes_vertex>
3793
+ #include <fog_vertex>
3794
+ }`,sprite_frag:`uniform vec3 diffuse;
3795
+ uniform float opacity;
3796
+ #include <common>
3797
+ #include <uv_pars_fragment>
3798
+ #include <map_pars_fragment>
3799
+ #include <alphamap_pars_fragment>
3800
+ #include <alphatest_pars_fragment>
3801
+ #include <alphahash_pars_fragment>
3802
+ #include <fog_pars_fragment>
3803
+ #include <logdepthbuf_pars_fragment>
3804
+ #include <clipping_planes_pars_fragment>
3805
+ void main() {
3806
+ vec4 diffuseColor = vec4( diffuse, opacity );
3807
+ #include <clipping_planes_fragment>
3808
+ vec3 outgoingLight = vec3( 0.0 );
3809
+ #include <logdepthbuf_fragment>
3810
+ #include <map_fragment>
3811
+ #include <alphamap_fragment>
3812
+ #include <alphatest_fragment>
3813
+ #include <alphahash_fragment>
3814
+ outgoingLight = diffuseColor.rgb;
3815
+ #include <opaque_fragment>
3816
+ #include <tonemapping_fragment>
3817
+ #include <colorspace_fragment>
3818
+ #include <fog_fragment>
3819
+ }`},Q={common:{diffuse:{value:new K(16777215)},opacity:{value:1},map:{value:null},mapTransform:{value:new V},alphaMap:{value:null},alphaMapTransform:{value:new V},alphaTest:{value:0}},specularmap:{specularMap:{value:null},specularMapTransform:{value:new V}},envmap:{envMap:{value:null},envMapRotation:{value:new V},reflectivity:{value:1},ior:{value:1.5},refractionRatio:{value:.98},dfgLUT:{value:null}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1},aoMapTransform:{value:new V}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1},lightMapTransform:{value:new V}},bumpmap:{bumpMap:{value:null},bumpMapTransform:{value:new V},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalMapTransform:{value:new V},normalScale:{value:new ve(1,1)}},displacementmap:{displacementMap:{value:null},displacementMapTransform:{value:new V},displacementScale:{value:1},displacementBias:{value:0}},emissivemap:{emissiveMap:{value:null},emissiveMapTransform:{value:new V}},metalnessmap:{metalnessMap:{value:null},metalnessMapTransform:{value:new V}},roughnessmap:{roughnessMap:{value:null},roughnessMapTransform:{value:new V}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:25e-5},fogNear:{value:1},fogFar:{value:2e3},fogColor:{value:new K(16777215)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},sunLights:{value:[],properties:{direction:{},color:{}}},sunLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},sunShadowMatrix:{value:[]},sunShadowCascade:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{}}},spotLightMap:{value:[]},spotLightMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowIntensity:1,shadowBias:{},shadowNormalBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}},ltc_1:{value:null},ltc_2:{value:null},probesSH:{value:[]},probesMin:{value:[]},probesMax:{value:[]},probesResolution:{value:[]}},points:{diffuse:{value:new K(16777215)},opacity:{value:1},size:{value:1},scale:{value:1},map:{value:null},alphaMap:{value:null},alphaMapTransform:{value:new V},alphaTest:{value:0},uvTransform:{value:new V}},sprite:{diffuse:{value:new K(16777215)},opacity:{value:1},center:{value:new ve(.5,.5)},rotation:{value:0},map:{value:null},mapTransform:{value:new V},alphaMap:{value:null},alphaMapTransform:{value:new V},alphaTest:{value:0}}},kt={basic:{uniforms:B([Q.common,Q.specularmap,Q.envmap,Q.aomap,Q.lightmap,Q.fog]),vertexShader:Z.meshbasic_vert,fragmentShader:Z.meshbasic_frag},lambert:{uniforms:B([Q.common,Q.specularmap,Q.envmap,Q.aomap,Q.lightmap,Q.emissivemap,Q.bumpmap,Q.normalmap,Q.displacementmap,Q.fog,Q.lights,{emissive:{value:new K(0)},envMapIntensity:{value:1}}]),vertexShader:Z.meshlambert_vert,fragmentShader:Z.meshlambert_frag},phong:{uniforms:B([Q.common,Q.specularmap,Q.envmap,Q.aomap,Q.lightmap,Q.emissivemap,Q.bumpmap,Q.normalmap,Q.displacementmap,Q.fog,Q.lights,{emissive:{value:new K(0)},specular:{value:new K(1118481)},shininess:{value:30},envMapIntensity:{value:1}}]),vertexShader:Z.meshphong_vert,fragmentShader:Z.meshphong_frag},standard:{uniforms:B([Q.common,Q.envmap,Q.aomap,Q.lightmap,Q.emissivemap,Q.bumpmap,Q.normalmap,Q.displacementmap,Q.roughnessmap,Q.metalnessmap,Q.fog,Q.lights,{emissive:{value:new K(0)},roughness:{value:1},metalness:{value:0},envMapIntensity:{value:1}}]),vertexShader:Z.meshphysical_vert,fragmentShader:Z.meshphysical_frag},toon:{uniforms:B([Q.common,Q.aomap,Q.lightmap,Q.emissivemap,Q.bumpmap,Q.normalmap,Q.displacementmap,Q.gradientmap,Q.fog,Q.lights,{emissive:{value:new K(0)}}]),vertexShader:Z.meshtoon_vert,fragmentShader:Z.meshtoon_frag},matcap:{uniforms:B([Q.common,Q.bumpmap,Q.normalmap,Q.displacementmap,Q.fog,{matcap:{value:null}}]),vertexShader:Z.meshmatcap_vert,fragmentShader:Z.meshmatcap_frag},points:{uniforms:B([Q.points,Q.fog]),vertexShader:Z.points_vert,fragmentShader:Z.points_frag},dashed:{uniforms:B([Q.common,Q.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:Z.linedashed_vert,fragmentShader:Z.linedashed_frag},depth:{uniforms:B([Q.common,Q.displacementmap]),vertexShader:Z.depth_vert,fragmentShader:Z.depth_frag},normal:{uniforms:B([Q.common,Q.bumpmap,Q.normalmap,Q.displacementmap,{opacity:{value:1}}]),vertexShader:Z.meshnormal_vert,fragmentShader:Z.meshnormal_frag},sprite:{uniforms:B([Q.sprite,Q.fog]),vertexShader:Z.sprite_vert,fragmentShader:Z.sprite_frag},background:{uniforms:{uvTransform:{value:new V},t2D:{value:null},backgroundIntensity:{value:1}},vertexShader:Z.background_vert,fragmentShader:Z.background_frag},backgroundCube:{uniforms:{envMap:{value:null},backgroundBlurriness:{value:0},backgroundIntensity:{value:1},backgroundRotation:{value:new V}},vertexShader:Z.backgroundCube_vert,fragmentShader:Z.backgroundCube_frag},cube:{uniforms:{tCube:{value:null},tFlip:{value:-1},opacity:{value:1}},vertexShader:Z.cube_vert,fragmentShader:Z.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:Z.equirect_vert,fragmentShader:Z.equirect_frag},distance:{uniforms:B([Q.common,Q.displacementmap,{referencePosition:{value:new w},nearDistance:{value:1},farDistance:{value:1e3}}]),vertexShader:Z.distance_vert,fragmentShader:Z.distance_frag},shadow:{uniforms:B([Q.lights,Q.fog,{color:{value:new K(0)},opacity:{value:1}}]),vertexShader:Z.shadow_vert,fragmentShader:Z.shadow_frag}};kt.physical={uniforms:B([kt.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatMapTransform:{value:new V},clearcoatNormalMap:{value:null},clearcoatNormalMapTransform:{value:new V},clearcoatNormalScale:{value:new ve(1,1)},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatRoughnessMapTransform:{value:new V},diffuseRoughness:{value:0},diffuseRoughnessMap:{value:null},diffuseRoughnessMapTransform:{value:new V},dispersion:{value:0},retroreflectivity:{value:0},iridescence:{value:0},iridescenceMap:{value:null},iridescenceMapTransform:{value:new V},iridescenceIOR:{value:1.3},iridescenceThicknessMinimum:{value:100},iridescenceThicknessMaximum:{value:400},iridescenceThicknessMap:{value:null},iridescenceThicknessMapTransform:{value:new V},sheen:{value:0},sheenColor:{value:new K(0)},sheenColorMap:{value:null},sheenColorMapTransform:{value:new V},sheenRoughness:{value:1},sheenRoughnessMap:{value:null},sheenRoughnessMapTransform:{value:new V},transmission:{value:0},transmissionMap:{value:null},transmissionMapTransform:{value:new V},transmissionSamplerSize:{value:new ve},transmissionSamplerMap:{value:null},thickness:{value:0},thicknessMap:{value:null},thicknessMapTransform:{value:new V},attenuationDistance:{value:0},attenuationColor:{value:new K(0)},specularColor:{value:new K(1,1,1)},specularColorMap:{value:null},specularColorMapTransform:{value:new V},specularIntensity:{value:1},specularIntensityMap:{value:null},specularIntensityMapTransform:{value:new V},anisotropyVector:{value:new ve},anisotropyMap:{value:null},anisotropyMapTransform:{value:new V}}]),vertexShader:Z.meshphysical_vert,fragmentShader:Z.meshphysical_frag};var At={r:0,b:0,g:0},jt=new nt,Mt=new V;Mt.set(-1,0,0,0,1,0,0,0,1);function Nt(e,t,n,r,i,a){let o=new K(0),s=i===!0?0:1,c,l,u=null,d=0,f=null;function m(e){let n=e.isScene===!0?e.background:null;if(n&&n.isTexture){let r=e.backgroundBlurriness>0;n=t.get(n,r)}return n}function h(t){let r=!1,i=m(t);i===null?_(o,s):i&&i.isColor&&(_(i,1),r=!0);let c=e.xr.getEnvironmentBlendMode();c===`additive`?n.buffers.color.setClear(0,0,0,1,a):c===`alpha-blend`&&n.buffers.color.setClear(0,0,0,0,a),(e.autoClear||r)&&(n.buffers.depth.setTest(!0),n.buffers.depth.setMask(!0),n.buffers.color.setMask(!0),e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil))}function g(t,n){let i=m(n);i&&i.isCubeTexture?(l===void 0&&(l=new dt(new et(1,1,1),new de({name:`BackgroundCubeMaterial`,uniforms:we(kt.backgroundCube.uniforms),vertexShader:kt.backgroundCube.vertexShader,fragmentShader:kt.backgroundCube.fragmentShader,side:1,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),l.geometry.deleteAttribute(`normal`),l.geometry.deleteAttribute(`uv`),l.onBeforeRender=function(e,t,n){this.matrixWorld.copyPosition(n.matrixWorld)},Object.defineProperty(l.material,"envMap",{get:function(){return this.uniforms.envMap.value}}),r.update(l)),l.material.uniforms.envMap.value=i,l.material.uniforms.backgroundBlurriness.value=n.backgroundBlurriness,l.material.uniforms.backgroundIntensity.value=n.backgroundIntensity,l.material.uniforms.backgroundRotation.value.setFromMatrix4(jt.makeRotationFromEuler(n.backgroundRotation)).transpose(),i.isRenderTargetTexture===!1&&l.material.uniforms.backgroundRotation.value.premultiply(Mt),l.material.toneMapped=Y.getTransfer(i.colorSpace)!==p,(u!==i||d!==i.version||f!==e.toneMapping)&&(l.material.needsUpdate=!0,u=i,d=i.version,f=e.toneMapping),l.layers.enableAll(),t.unshift(l,l.geometry,l.material,0,0,null)):i&&i.isTexture&&(c===void 0&&(c=new dt(new le(2,2),new de({name:`BackgroundMaterial`,uniforms:we(kt.background.uniforms),vertexShader:kt.background.vertexShader,fragmentShader:kt.background.fragmentShader,side:0,depthTest:!1,depthWrite:!1,fog:!1,allowOverride:!1})),c.geometry.deleteAttribute(`normal`),Object.defineProperty(c.material,"map",{get:function(){return this.uniforms.t2D.value}}),r.update(c)),c.material.uniforms.t2D.value=i,c.material.uniforms.backgroundIntensity.value=n.backgroundIntensity,c.material.toneMapped=Y.getTransfer(i.colorSpace)!==p,i.matrixAutoUpdate===!0&&i.updateMatrix(),c.material.uniforms.uvTransform.value.copy(i.matrix),(u!==i||d!==i.version||f!==e.toneMapping)&&(c.material.needsUpdate=!0,u=i,d=i.version,f=e.toneMapping),c.layers.enableAll(),t.unshift(c,c.geometry,c.material,0,0,null))}function _(t,r){t.getRGB(At,ct(e)),n.buffers.color.setClear(At.r,At.g,At.b,r,a)}function v(){l!==void 0&&(l.geometry.dispose(),l.material.dispose(),l=void 0),c!==void 0&&(c.geometry.dispose(),c.material.dispose(),c=void 0)}return{getClearColor:function(){return o},setClearColor:function(e,t=1){o.set(e),s=t,_(o,s)},getClearAlpha:function(){return s},setClearAlpha:function(e){s=e,_(o,s)},render:h,addToRenderList:g,dispose:v}}function Pt(e,t){let n=e.getParameter(e.MAX_VERTEX_ATTRIBS),r={},i=f(null),a=i,o=!1;function s(n,r,i,s,c){let u=!1,f=d(n,s,i,r);a!==f&&(a=f,l(a.object)),u=p(n,s,i,c),u&&m(n,s,i,c),c!==null&&t.update(c,e.ELEMENT_ARRAY_BUFFER),(u||o)&&(o=!1,b(n,r,i,s),c!==null&&e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,t.get(c).buffer))}function c(){return e.createVertexArray()}function l(t){return e.bindVertexArray(t)}function u(t){return e.deleteVertexArray(t)}function d(e,t,n,i){let a=i.wireframe===!0,o=r[t.id];o===void 0&&(o={},r[t.id]=o);let s=e.isInstancedMesh===!0?e.id:0,l=o[s];l===void 0&&(l={},o[s]=l);let u=l[n.id];u===void 0&&(u={},l[n.id]=u);let d=u[a];return d===void 0&&(d=f(c()),u[a]=d),d}function f(e){let t=[],r=[],i=[];for(let e=0;e<n;e++)t[e]=0,r[e]=0,i[e]=0;return{geometry:null,program:null,wireframe:!1,newAttributes:t,enabledAttributes:r,attributeDivisors:i,object:e,attributes:{},index:null}}function p(e,t,n,r){let i=a.attributes,o=t.attributes,s=0,c=n.getAttributes();for(let t in c)if(c[t].location>=0){let n=i[t],r=o[t];if(r===void 0&&(t===`instanceMatrix`&&e.instanceMatrix&&(r=e.instanceMatrix),t===`instanceColor`&&e.instanceColor&&(r=e.instanceColor)),n===void 0||n.attribute!==r||r&&n.data!==r.data)return!0;s++}return a.attributesNum!==s||a.index!==r}function m(e,t,n,r){let i={},o=t.attributes,s=0,c=n.getAttributes();for(let t in c)if(c[t].location>=0){let n=o[t];n===void 0&&(t===`instanceMatrix`&&e.instanceMatrix&&(n=e.instanceMatrix),t===`instanceColor`&&e.instanceColor&&(n=e.instanceColor));let r={};r.attribute=n,n&&n.data&&(r.data=n.data),i[t]=r,s++}a.attributes=i,a.attributesNum=s,a.index=r}function h(){let e=a.newAttributes;for(let t=0,n=e.length;t<n;t++)e[t]=0}function g(e){_(e,0)}function _(t,n){let r=a.newAttributes,i=a.enabledAttributes,o=a.attributeDivisors;r[t]=1,i[t]===0&&(e.enableVertexAttribArray(t),i[t]=1),o[t]!==n&&(e.vertexAttribDivisor(t,n),o[t]=n)}function v(){let t=a.newAttributes,n=a.enabledAttributes;for(let r=0,i=n.length;r<i;r++)n[r]!==t[r]&&(e.disableVertexAttribArray(r),n[r]=0)}function y(t,n,r,i,a,o,s){s===!0?e.vertexAttribIPointer(t,n,r,a,o):e.vertexAttribPointer(t,n,r,i,a,o)}function b(n,r,i,a){h();let o=a.attributes,s=i.getAttributes(),c=r.defaultAttributeValues;for(let r in s){let i=s[r];if(i.location>=0){let s=o[r];if(s===void 0&&(r===`instanceMatrix`&&n.instanceMatrix&&(s=n.instanceMatrix),r===`instanceColor`&&n.instanceColor&&(s=n.instanceColor)),s!==void 0){let r=s.normalized,o=s.itemSize,c=t.get(s);if(c===void 0)continue;let l=c.buffer,u=c.type,d=c.bytesPerElement,f=u===e.INT||u===e.UNSIGNED_INT||s.gpuType===1013;if(s.isInterleavedBufferAttribute){let t=s.data,c=t.isInterleavedBuffer===!0?t.stride:t.itemSize,p=s.offset;if(t.isInstancedInterleavedBuffer||t.isInstancedBufferAttribute){for(let e=0;e<i.locationSize;e++)_(i.location+e,t.meshPerAttribute);n.isInstancedMesh!==!0&&a._maxInstanceCount===void 0&&(a._maxInstanceCount=t.meshPerAttribute*t.count)}else for(let e=0;e<i.locationSize;e++)g(i.location+e);e.bindBuffer(e.ARRAY_BUFFER,l);for(let e=0;e<i.locationSize;e++)y(i.location+e,o/i.locationSize,u,r,c*d,(p+o/i.locationSize*e)*d,f)}else{if(s.isInstancedBufferAttribute){for(let e=0;e<i.locationSize;e++)_(i.location+e,s.meshPerAttribute);n.isInstancedMesh!==!0&&a._maxInstanceCount===void 0&&(a._maxInstanceCount=s.meshPerAttribute*s.count)}else for(let e=0;e<i.locationSize;e++)g(i.location+e);e.bindBuffer(e.ARRAY_BUFFER,l);for(let e=0;e<i.locationSize;e++)y(i.location+e,o/i.locationSize,u,r,o*d,o/i.locationSize*e*d,f)}}else if(c!==void 0){let t=c[r];if(t!==void 0)switch(t.length){case 2:e.vertexAttrib2fv(i.location,t);break;case 3:e.vertexAttrib3fv(i.location,t);break;case 4:e.vertexAttrib4fv(i.location,t);break;default:e.vertexAttrib1fv(i.location,t)}}}}v()}function x(){T();for(let e in r){let t=r[e];for(let e in t){let n=t[e];for(let e in n){let t=n[e];for(let e in t)u(t[e].object),delete t[e];delete n[e]}}delete r[e]}}function S(e){if(r[e.id]===void 0)return;let t=r[e.id];for(let e in t){let n=t[e];for(let e in n){let t=n[e];for(let e in t)u(t[e].object),delete t[e];delete n[e]}}delete r[e.id]}function C(e){for(let t in r){let n=r[t];for(let t in n){let r=n[t];if(r[e.id]===void 0)continue;let i=r[e.id];for(let e in i)u(i[e].object),delete i[e];delete r[e.id]}}}function w(e){for(let t in r){let n=r[t],i=e.isInstancedMesh===!0?e.id:0,a=n[i];if(a!==void 0){for(let e in a){let t=a[e];for(let e in t)u(t[e].object),delete t[e];delete a[e]}delete n[i],Object.keys(n).length===0&&delete r[t]}}}function T(){E(),o=!0,a!==i&&(a=i,l(a.object))}function E(){i.geometry=null,i.program=null,i.wireframe=!1}return{setup:s,reset:T,resetDefaultState:E,dispose:x,releaseStatesOfGeometry:S,releaseStatesOfObject:w,releaseStatesOfProgram:C,initAttributes:h,enableAttribute:g,disableUnusedAttributes:v}}function Ft(e,t,n){let r;function i(e){r=e}function a(t,i){e.drawArrays(r,t,i),n.update(i,r,1)}function o(t,i,a){a!==0&&(e.drawArraysInstanced(r,t,i,a),n.update(i,r,a))}function s(e,i,a){if(a===0)return;t.get(`WEBGL_multi_draw`).multiDrawArraysWEBGL(r,e,0,i,0,a);let o=0;for(let e=0;e<a;e++)o+=i[e];n.update(o,r,1)}this.setMode=i,this.render=a,this.renderInstances=o,this.renderMultiDraw=s}function It(e,t,n,r){let i;function a(){if(i!==void 0)return i;if(t.has(`EXT_texture_filter_anisotropic`)===!0){let n=t.get(`EXT_texture_filter_anisotropic`);i=e.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT)}else i=0;return i}function o(t){return t===1023||r.convert(t)===e.getParameter(e.IMPLEMENTATION_COLOR_READ_FORMAT)}function s(n){let i=n===1016&&(t.has(`EXT_color_buffer_half_float`)||t.has(`EXT_color_buffer_float`));return!(n!==1009&&n!==1015&&!i&&r.convert(n)!==e.getParameter(e.IMPLEMENTATION_COLOR_READ_TYPE))}function c(t){if(t===`highp`){if(e.getShaderPrecisionFormat(e.VERTEX_SHADER,e.HIGH_FLOAT).precision>0&&e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision>0)return`highp`;t=`mediump`}return t===`mediump`&&e.getShaderPrecisionFormat(e.VERTEX_SHADER,e.MEDIUM_FLOAT).precision>0&&e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.MEDIUM_FLOAT).precision>0?`mediump`:`lowp`}let l=n.precision===void 0?`highp`:n.precision,u=c(l);u!==l&&(X(`WebGLRenderer:`,l,`not supported, using`,u,`instead.`),l=u);let d=n.reversedDepthBuffer===!0&&t.has(`EXT_clip_control`),f=n.logarithmicDepthBuffer===!0&&d===!1;n.reversedDepthBuffer===!0&&d===!1&&X(`WebGLRenderer: Unable to use reversed depth buffer due to missing EXT_clip_control extension. Fallback to default depth buffer.`),n.logarithmicDepthBuffer===!0&&d===!0&&X(`WebGLRenderer: Logarithmic depth buffer is ignored when reversed depth buffer is enabled.`);let p=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),m=e.getParameter(e.MAX_VERTEX_TEXTURE_IMAGE_UNITS),h=e.getParameter(e.MAX_TEXTURE_SIZE),g=e.getParameter(e.MAX_CUBE_MAP_TEXTURE_SIZE),_=e.getParameter(e.MAX_VERTEX_ATTRIBS),v=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS),y=e.getParameter(e.MAX_VARYING_VECTORS),b=e.getParameter(e.MAX_FRAGMENT_UNIFORM_VECTORS),x=e.getParameter(e.MAX_SAMPLES),S=e.getParameter(e.SAMPLES);return{isWebGL2:!0,getMaxAnisotropy:a,getMaxPrecision:c,textureFormatReadable:o,textureTypeReadable:s,precision:l,logarithmicDepthBuffer:f,reversedDepthBuffer:d,maxTextures:p,maxVertexTextures:m,maxTextureSize:h,maxCubemapSize:g,maxAttributes:_,maxVertexUniforms:v,maxVaryings:y,maxFragmentUniforms:b,maxSamples:x,samples:S}}function Lt(e){let t=this,n=null,r=0,i=!1,a=!1,o=new St,s=new V,c={value:null,needsUpdate:!1};this.uniform=c,this.numPlanes=0,this.numIntersection=0,this.init=function(e,t){let n=e.length!==0||t||r!==0||i;return i=t,r=e.length,n},this.beginShadows=function(){a=!0,u(null)},this.endShadows=function(){a=!1},this.setGlobalState=function(e,t){n=u(e,t,0)},this.setState=function(t,o,s){let d=t.clippingPlanes,f=t.clipIntersection,p=t.clipShadows,m=e.get(t);if(!i||d===null||d.length===0||a&&!p)a?u(null):l();else{let e=a?0:r,t=e*4,i=m.clippingState||null;c.value=i,i=u(d,o,t,s);for(let e=0;e!==t;++e)i[e]=n[e];m.clippingState=i,this.numIntersection=f?this.numPlanes:0,this.numPlanes+=e}};function l(){c.value!==n&&(c.value=n,c.needsUpdate=r>0),t.numPlanes=r,t.numIntersection=0}function u(e,n,r,i){let a=e===null?0:e.length,l=null;if(a!==0){if(l=c.value,i!==!0||l===null){let t=r+a*4,i=n.matrixWorldInverse;s.getNormalMatrix(i),(l===null||l.length<t)&&(l=new Float32Array(t));for(let t=0,n=r;t!==a;++t,n+=4)o.copy(e[t]).applyMatrix4(i,s),o.normal.toArray(l,n),l[n+3]=o.constant}c.value=l,c.needsUpdate=!0}return t.numPlanes=a,t.numIntersection=0,l}}var Rt=class extends Se{constructor(e=1,t={}){super(e,e,t),this.isWebGLCubeRenderTarget=!0;let n={width:e,height:e,depth:1},r=[n,n,n,n,n,n];this.texture=new q(r),this._setTextureOptions(t),this.texture.isRenderTargetTexture=!0}fromEquirectangularTexture(e,t){this.texture.type=t.type,this.texture.colorSpace=t.colorSpace,this.texture.generateMipmaps=t.generateMipmaps,this.texture.minFilter=t.minFilter,this.texture.magFilter=t.magFilter;let n={uniforms:{tEquirect:{value:null}},vertexShader:`
3820
+
3821
+ varying vec3 vWorldDirection;
3822
+
3823
+ vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
3824
+
3825
+ return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
3826
+
3827
+ }
3828
+
3829
+ void main() {
3830
+
3831
+ vWorldDirection = transformDirection( position, modelMatrix );
3832
+
3833
+ #include <begin_vertex>
3834
+ #include <project_vertex>
3835
+
3836
+ }
3837
+ `,fragmentShader:`
3838
+
3839
+ uniform sampler2D tEquirect;
3840
+
3841
+ varying vec3 vWorldDirection;
3842
+
3843
+ #include <common>
3844
+
3845
+ void main() {
3846
+
3847
+ vec3 direction = normalize( vWorldDirection );
3848
+
3849
+ vec2 sampleUV = equirectUv( direction );
3850
+
3851
+ gl_FragColor = texture2D( tEquirect, sampleUV );
3852
+
3853
+ }
3854
+ `},r=new et(5,5,5),i=new de({name:`CubemapFromEquirect`,uniforms:we(n.uniforms),vertexShader:n.vertexShader,fragmentShader:n.fragmentShader,side:1,blending:0});i.uniforms.tEquirect.value=t;let a=new dt(r,i),o=t.minFilter;return t.minFilter===1008&&(t.minFilter=ye),new Ye(1,10,this).update(e,a),t.minFilter=o,a.geometry.dispose(),a.material.dispose(),this}clear(e,t=!0,n=!0,r=!0){let i=e.getRenderTarget();for(let i=0;i<6;i++)e.setRenderTarget(this,i),e.clear(t,n,r);e.setRenderTarget(i)}},zt=256,Bt=3,Vt=20,Ht=256,Ut=16,Wt=3,Gt=new w,Kt=new K,qt=class e{constructor(e){this._renderer=e,this._cubeSize=0,this._sourceTarget=null,this._cubeCamera=new Ye(1,10,null),this._boxMesh=new dt(new et(5,5,5),null),this._cubemapMaterial=null,this._equirectMaterial=null,this._blurMaterial=null,this._ggxMaterial=null,this._integrationMaterial=null}fromScene(e,t=0,n=.1,r=100,i={}){let{size:a=256,position:o=Gt}=i,s=this._renderer;this._setSize(a);let c=this._allocateTarget(),l=this._getSourceTarget(!0);t>0&&(l.texture.mipmapsAutoUpdate=!1);let u=s.autoClear,d=s.autoClearColor,f=s.autoClearDepth,p=s.autoClearStencil,m=e.background;s.autoClear=!0,s.autoClearColor=!0,s.autoClearDepth=!0,s.autoClearStencil=!0,m===null&&(e.background=s.getClearColor(Kt));let h=new Ye(n,r,l);return h.position.copy(o),h.update(s,e),s.autoClear=u,s.autoClearColor=d,s.autoClearDepth=f,s.autoClearStencil=p,e.background=m,t>0&&(l.texture.mipmapsAutoUpdate=!0,this._blur(c,t)),this._applyPMREM(c),c}fromEquirectangular(e,t=null){return this._fromTexture(e,t)}fromCubemap(e,t=null){return this._fromTexture(e,t)}compileCubemapShader(){this._cubemapMaterial===null&&(this._cubemapMaterial=en(),this._compileMaterial(this._cubemapMaterial))}compileEquirectangularShader(){this._equirectMaterial===null&&(this._equirectMaterial=$t(),this._compileMaterial(this._equirectMaterial))}dispose(){this._sourceTarget!==null&&this._sourceTarget.dispose(),this._cubemapMaterial!==null&&this._cubemapMaterial.dispose(),this._equirectMaterial!==null&&this._equirectMaterial.dispose(),this._blurMaterial!==null&&this._blurMaterial.dispose(),this._ggxMaterial!==null&&this._ggxMaterial.dispose(),this._integrationMaterial!==null&&this._integrationMaterial.dispose(),this._boxMesh.geometry.dispose()}static lodToRoughness(e,t){return t>0?1-Math.sqrt(1-e/t):0}_setSize(e){this._cubeSize=Math.max(zt,ft(e))}_fromTexture(e,t){e.mapping===301||e.mapping===302?this._setSize(e.image.length===0?zt:e.image[0].width||e.image[0].image.width):this._setSize(e.image.width/4);let n=t||this._allocateTarget();return this._textureToCubemap(e),this._applyPMREM(n),n}_allocateTarget(){let e=this._cubeSize,t=Jt(e,!1,!1),n=Math.log2(e)-Bt;for(let r=0;r<=n;r++)t.texture.mipmaps.push({width:e>>r,height:e>>r});return t.texture.name=`PMREM`,t.texture.isPMREMTexture=!0,t}_getSourceTarget(e=!1){let t=this._cubeSize,n=this._sourceTarget;return(n===null||n.width!==t||e&&n.depthBuffer===!1)&&(n!==null&&n.dispose(),this._sourceTarget=Jt(t,!0,e)),this._sourceTarget}_compileMaterial(e){this._boxMesh.material=e,this._renderer.compile(this._boxMesh,this._cubeCamera.children[0])}_renderCube(e,t,n){let r=this._boxMesh,i=this._cubeCamera;r.material=n,i.renderTarget=e,i.activeMipmapLevel=t;let a=e.width>>t;e.viewport.set(0,0,a,a),i.update(this._renderer,r),e.viewport.set(0,0,e.width,e.height)}_textureToCubemap(e){let t;e.mapping===301||e.mapping===302?(this._cubemapMaterial===null&&(this._cubemapMaterial=en()),t=this._cubemapMaterial,t.uniforms.flipEnvMap.value=e.isRenderTargetTexture===!1?-1:1):(this._equirectMaterial===null&&(this._equirectMaterial=$t()),t=this._equirectMaterial),t.uniforms.envMap.value=e,this._renderCube(this._getSourceTarget(),0,t)}_applyPMREM(t){this._ggxMaterial===null&&(this._ggxMaterial=Xt(),this._integrationMaterial=Zt());let n=this._cubeSize,r=t.texture.mipmaps.length-1,i=this._ggxMaterial.uniforms;i.envMap.value=this._sourceTarget.texture;let a=this._integrationMaterial.uniforms;a.envMap.value=this._sourceTarget.texture,a.sourceLod.value=Math.log2(n/Ut);for(let o=0;o<=r;o++){let s=e.lodToRoughness(o,r);if(o>r-Wt)a.roughness.value=s,this._renderCube(t,o,this._integrationMaterial);else{let e=s>0?Math.log2(n)+.5*Math.log2(6/(Ht*s**4))+.5:0;i.roughness.value=s,i.lodBias.value=e,this._renderCube(t,o,this._ggxMaterial)}}}_blur(e,t){this._blurMaterial===null&&(this._blurMaterial=Qt());let n=this._blurMaterial,r=n.uniforms,i=this._sourceTarget;r.sigma.value=Math.min(t,Math.PI)/Math.SQRT2,r.envMap.value=i.texture,this._renderCube(e,0,n),r.envMap.value=e.texture,this._renderCube(i,0,n)}};function Jt(e,t,n){return new Rt(e,{minFilter:Ce,generateMipmaps:t,type:ne,colorSpace:a,depthBuffer:n})}function Yt(e,t,n){return new de({name:e,uniforms:t,vertexShader:Z.cube_vert,fragmentShader:n,side:1,blending:0,depthTest:!1,depthWrite:!1})}function Xt(){return Yt(`PMREMGGXConvolution`,{envMap:{value:null},roughness:{value:0},lodBias:{value:0}},`
3855
+
3856
+ #define GGX_SAMPLES ${Ht}u
3857
+
3858
+ varying vec3 vWorldDirection;
3859
+
3860
+ uniform samplerCube envMap;
3861
+ uniform float roughness;
3862
+ uniform float lodBias;
3863
+
3864
+ #include <common>
3865
+
3866
+ // Van der Corput radical inverse
3867
+ float radicalInverse_VdC( uint bits ) {
3868
+
3869
+ bits = ( bits << 16u ) | ( bits >> 16u );
3870
+ bits = ( ( bits & 0x55555555u ) << 1u ) | ( ( bits & 0xAAAAAAAAu ) >> 1u );
3871
+ bits = ( ( bits & 0x33333333u ) << 2u ) | ( ( bits & 0xCCCCCCCCu ) >> 2u );
3872
+ bits = ( ( bits & 0x0F0F0F0Fu ) << 4u ) | ( ( bits & 0xF0F0F0F0u ) >> 4u );
3873
+ bits = ( ( bits & 0x00FF00FFu ) << 8u ) | ( ( bits & 0xFF00FF00u ) >> 8u );
3874
+ return float( bits ) * 2.3283064365386963e-10; // / 0x100000000
3875
+
3876
+ }
3877
+
3878
+ // Hammersley sequence
3879
+ vec2 hammersley( uint i, uint N ) {
3880
+
3881
+ return vec2( float( i ) / float( N ), radicalInverse_VdC( i ) );
3882
+
3883
+ }
3884
+
3885
+ void main() {
3886
+
3887
+ vec3 N = normalize( vWorldDirection );
3888
+
3889
+ // For very low roughness, just sample the environment directly
3890
+ if ( roughness < 0.001 ) {
3891
+
3892
+ gl_FragColor = vec4( textureLod( envMap, N, 0.0 ).rgb, 1.0 );
3893
+ return;
3894
+
3895
+ }
3896
+
3897
+ float alpha = roughness * roughness;
3898
+ float alpha2 = alpha * alpha;
3899
+
3900
+ // Tangent space basis for VNDF sampling
3901
+ vec3 up = abs( N.z ) < 0.999 ? vec3( 0.0, 0.0, 1.0 ) : vec3( 1.0, 0.0, 0.0 );
3902
+ vec3 tangent = normalize( cross( up, N ) );
3903
+ vec3 bitangent = cross( N, tangent );
3904
+
3905
+ vec3 prefilteredColor = vec3( 0.0 );
3906
+ float totalWeight = 0.0;
3907
+
3908
+ for ( uint i = 0u; i < GGX_SAMPLES; i ++ ) {
3909
+
3910
+ vec2 Xi = hammersley( i, GGX_SAMPLES );
3911
+
3912
+ // With V = N, sample the reflected direction directly.
3913
+ float invQ = 1.0 / ( 1.0 - Xi.x + alpha2 * Xi.x );
3914
+ float NdotL = ( 1.0 - Xi.x - alpha2 * Xi.x ) * invQ;
3915
+
3916
+ if ( NdotL > 0.0 ) {
3917
+
3918
+ float phi = 2.0 * PI * Xi.y;
3919
+ float sinTheta = 2.0 * alpha * sqrt( Xi.x * ( 1.0 - Xi.x ) ) * invQ;
3920
+ vec3 L = N * NdotL + ( tangent * cos( phi ) + bitangent * sin( phi ) ) * sinTheta;
3921
+
3922
+ // Match the source mip to the sample's solid angle. The terms
3923
+ // independent of the sample are precomputed in lodBias.
3924
+ float d = alpha2 * invQ;
3925
+ float lod = max( log2( d ) + lodBias, 0.0 );
3926
+
3927
+ // Weight by NdotL for the split-sum approximation
3928
+ prefilteredColor += textureLod( envMap, L, lod ).rgb * NdotL;
3929
+ totalWeight += NdotL;
3930
+
3931
+ }
3932
+
3933
+ }
3934
+
3935
+ gl_FragColor = vec4( prefilteredColor / totalWeight, 1.0 );
3936
+
3937
+ }
3938
+ `)}function Zt(){return Yt(`PMREMGGXIntegration`,{envMap:{value:null},roughness:{value:0},sourceLod:{value:0},sourceSize:{value:Ut}},`
3939
+
3940
+ varying vec3 vWorldDirection;
3941
+
3942
+ uniform samplerCube envMap;
3943
+ uniform float roughness;
3944
+ uniform float sourceLod;
3945
+ uniform int sourceSize;
3946
+
3947
+ void main() {
3948
+
3949
+ vec3 N = normalize( vWorldDirection );
3950
+
3951
+ float alpha = roughness * roughness;
3952
+ float alpha2 = alpha * alpha;
3953
+
3954
+ float texelSize = 2.0 / float( sourceSize );
3955
+
3956
+ vec3 prefilteredColor = vec3( 0.0 );
3957
+ float totalWeight = 0.0;
3958
+
3959
+ // Pair opposite texels: only the one in N's hemisphere contributes.
3960
+ for ( int face = 0; face < 3; face ++ ) {
3961
+
3962
+ for ( int y = 0; y < sourceSize; y ++ ) {
3963
+
3964
+ for ( int x = 0; x < sourceSize; x ++ ) {
3965
+
3966
+ vec2 uv = ( vec2( x, y ) + 0.5 ) * texelSize - 1.0;
3967
+ vec3 texelDirection = face == 0 ? vec3( 1.0, uv ) : ( face == 1 ? vec3( uv.x, 1.0, uv.y ) : vec3( uv, 1.0 ) );
3968
+
3969
+ float invDistance = inversesqrt( 1.0 + dot( uv, uv ) );
3970
+ float NdotL = dot( N, texelDirection );
3971
+ texelDirection *= NdotL < 0.0 ? - 1.0 : 1.0;
3972
+ NdotL = abs( NdotL ) * invDistance;
3973
+
3974
+ // With V = N, NdotH squared is ( 1 + NdotL ) / 2. Common factors
3975
+ // in the GGX distribution and texel solid angle cancel when normalized.
3976
+ float d = 1.0 + alpha2 + ( alpha2 - 1.0 ) * NdotL;
3977
+ float weight = NdotL * invDistance * invDistance * invDistance / ( d * d );
3978
+
3979
+ prefilteredColor += textureLod( envMap, texelDirection, sourceLod ).rgb * weight;
3980
+ totalWeight += weight;
3981
+
3982
+ }
3983
+
3984
+ }
3985
+
3986
+ }
3987
+
3988
+ gl_FragColor = vec4( prefilteredColor / totalWeight, 1.0 );
3989
+
3990
+ }
3991
+ `)}function Qt(){return Yt(`PMREMSphericalGaussianBlur`,{envMap:{value:null},sigma:{value:0}},`
3992
+
3993
+ #define SAMPLES ${Vt}
3994
+ #define GOLDEN_ANGLE 2.39996322973
3995
+
3996
+ varying vec3 vWorldDirection;
3997
+
3998
+ uniform samplerCube envMap;
3999
+ uniform float sigma;
4000
+
4001
+ #include <common>
4002
+
4003
+ void main() {
4004
+
4005
+ vec3 outputDirection = normalize( vWorldDirection );
4006
+
4007
+ vec3 up = abs( outputDirection.z ) < 0.999 ? vec3( 0.0, 0.0, 1.0 ) : vec3( 1.0, 0.0, 0.0 );
4008
+ vec3 tangent = normalize( cross( up, outputDirection ) );
4009
+ vec3 bitangent = cross( outputDirection, tangent );
4010
+
4011
+ // Truncate the kernel at three standard deviations or at the antipode.
4012
+ float thetaMax = min( 3.0 * sigma, PI );
4013
+ float truncation = 1.0 - exp( - 0.5 * thetaMax * thetaMax / ( sigma * sigma ) );
4014
+
4015
+ vec3 accumColor = vec3( 0.0 );
4016
+ float accumWeight = 0.0;
4017
+
4018
+ for ( int i = 0; i < SAMPLES; i ++ ) {
4019
+
4020
+ // Stratified inverse-CDF sampling of the Gaussian, placed on a golden-angle spiral.
4021
+ float stratum = ( float( i ) + 0.5 ) / float( SAMPLES );
4022
+ float theta = sigma * sqrt( - 2.0 * log( 1.0 - stratum * truncation ) );
4023
+ float phi = float( i ) * GOLDEN_ANGLE;
4024
+
4025
+ vec3 offset = cos( phi ) * tangent + sin( phi ) * bitangent;
4026
+ vec3 sampleDirection = cos( theta ) * outputDirection + sin( theta ) * offset;
4027
+
4028
+ // Correct the planar sample density to solid angle.
4029
+ float weight = sin( theta ) / theta;
4030
+
4031
+ accumColor += weight * textureLod( envMap, sampleDirection, 0.0 ).rgb;
4032
+ accumWeight += weight;
4033
+
4034
+ }
4035
+
4036
+ gl_FragColor = vec4( accumColor / accumWeight, 1.0 );
4037
+
4038
+ }
4039
+ `)}function $t(){return Yt(`PMREMEquirectangularToCubemap`,{envMap:{value:null}},`
4040
+
4041
+ varying vec3 vWorldDirection;
4042
+
4043
+ uniform sampler2D envMap;
4044
+
4045
+ #include <common>
4046
+
4047
+ void main() {
4048
+
4049
+ // Average four subpixel samples to preserve small, bright features.
4050
+ vec3 direction = normalize( vWorldDirection );
4051
+ vec3 dx = dFdx( direction ) * 0.25;
4052
+ vec3 dy = dFdy( direction ) * 0.25;
4053
+
4054
+ vec3 color = textureLod( envMap, equirectUv( normalize( direction - dx - dy ) ), 0.0 ).rgb;
4055
+ color += textureLod( envMap, equirectUv( normalize( direction + dx - dy ) ), 0.0 ).rgb;
4056
+ color += textureLod( envMap, equirectUv( normalize( direction - dx + dy ) ), 0.0 ).rgb;
4057
+ color += textureLod( envMap, equirectUv( normalize( direction + dx + dy ) ), 0.0 ).rgb;
4058
+ gl_FragColor = vec4( color * 0.25, 1.0 );
4059
+
4060
+ }
4061
+ `)}function en(){return Yt(`PMREMCubemapToCubemap`,{envMap:{value:null},flipEnvMap:{value:-1}},`
4062
+
4063
+ varying vec3 vWorldDirection;
4064
+
4065
+ uniform samplerCube envMap;
4066
+ uniform float flipEnvMap;
4067
+
4068
+ void main() {
4069
+
4070
+ gl_FragColor = vec4( textureCube( envMap, vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) ).rgb, 1.0 );
4071
+
4072
+ }
4073
+ `)}function tn(e){let t=new WeakMap,n=new WeakMap,r=null;function i(e,t=!1){return e==null?null:t?o(e):a(e)}function a(n){if(n&&n.isTexture){let r=n.mapping;if(r===303||r===304){if(t.has(n)){let e=t.get(n).texture;return s(e,n.mapping)}{let r=n.image;if(r&&r.height>0){let i=new Rt(r.height);return i.fromEquirectangularTexture(e,n),t.set(n,i),n.addEventListener(`dispose`,l),s(i.texture,n.mapping)}return null}}}return n}function o(t){if(t&&t.isTexture&&t.isPMREMTexture!==!0){let i=t.mapping,a=i===303||i===304,o=i===301||i===302;if(a||o){let i=n.get(t),s=i===void 0?0:i.texture.pmremVersion;if(t.isRenderTargetTexture&&t.pmremVersion!==s)return r===null&&(r=new qt(e)),i=a?r.fromEquirectangular(t,i):r.fromCubemap(t,i),i.texture.pmremVersion=t.pmremVersion,n.set(t,i),i.texture;if(i!==void 0)return i.texture;{let s=t.image;return a&&s&&s.height>0||o&&s&&c(s)?(r===null&&(r=new qt(e)),i=a?r.fromEquirectangular(t):r.fromCubemap(t),i.texture.pmremVersion=t.pmremVersion,n.set(t,i),t.addEventListener(`dispose`,u),i.texture):null}}}return t}function s(e,t){return t===303?e.mapping=301:t===304&&(e.mapping=302),e}function c(e){let t=0;for(let n=0;n<6;n++)e[n]!==void 0&&t++;return t===6}function l(e){let n=e.target;n.removeEventListener(`dispose`,l);let r=t.get(n);r!==void 0&&(t.delete(n),r.dispose())}function u(e){let t=e.target;t.removeEventListener(`dispose`,u);let r=n.get(t);r!==void 0&&(n.delete(t),r.dispose())}function d(){t=new WeakMap,n=new WeakMap,r!==null&&(r.dispose(),r=null)}return{get:i,dispose:d}}function nn(e){let t={};function n(n){if(t[n]!==void 0)return t[n];let r=e.getExtension(n);return t[n]=r,r}return{has:function(e){return n(e)!==null},init:function(){n(`EXT_color_buffer_float`),n(`WEBGL_clip_cull_distance`),n(`OES_texture_float_linear`),n(`EXT_color_buffer_half_float`),n(`WEBGL_multisampled_render_to_texture`),n(`WEBGL_render_shared_exponent`)},get:function(e){let t=n(e);return t===null&&Me(`WebGLRenderer: `+e+` extension not supported.`),t}}}function rn(e,t,n,r){let i={},a=new WeakMap,o=new FinalizationRegistry(e=>delete i[e]);function s(e){c(e.target)}function c(e){e.index!==null&&t.remove(e.index);for(let n in e.attributes)t.remove(e.attributes[n]);e.removeEventListener(`dispose`,s),delete i[e.id],o.unregister(e);let c=a.get(e);c&&(t.remove(c),a.delete(e)),r.releaseStatesOfGeometry(e),e.isInstancedBufferGeometry===!0&&delete e._maxInstanceCount,n.memory.geometries--}function l(e,t){return i[t.id]===void 0&&(t.addEventListener(`dispose`,s),i[t.id]=new WeakRef(t),o.register(t,t.id,t),n.memory.geometries++),t}function u(n){let r=n.attributes;for(let n in r)t.update(r[n],e.ARRAY_BUFFER)}function d(e){let n=e.index,r=e.attributes.position,i=0;if(r===void 0)return;let o=n===null?r.array.length/3-1:n.array.length,s=new(r.count>=65535?re:I)(Math.ceil(o/3)*6,1),c=s.array;if(n!==null){let e=n.array;i=n.version;for(let t=0,n=0;t<o;t+=3){let r=e[t+0],i=e[t+1],a=e[t+2];c[n++]=r,c[n++]=i,c[n++]=i,c[n++]=a,c[n++]=a,c[n++]=r}}else{i=r.version;for(let e=0,t=0;e<o;e+=3){let n=e+0,r=e+1,i=e+2;c[t++]=n,c[t++]=r,c[t++]=r,c[t++]=i,c[t++]=i,c[t++]=n}}s.version=i;let l=a.get(e);l&&t.remove(l),a.set(e,s)}function f(e){let t=a.get(e);if(t){let n=e.index;n!==null&&t.version<n.version&&d(e)}else d(e);return a.get(e)}function p(){for(let e in i){let t=i[e].deref();t!==void 0&&c(t)}}return{get:l,update:u,getWireframeAttribute:f,dispose:p}}function an(e,t,n){let r;function i(e){r=e}let a,o;function s(e){a=e.type,o=e.bytesPerElement}function c(t,i){e.drawElements(r,i,a,t*o),n.update(i,r,1)}function l(t,i,s){s!==0&&(e.drawElementsInstanced(r,i,a,t*o,s),n.update(i,r,s))}function u(e,i,o){if(o===0)return;t.get(`WEBGL_multi_draw`).multiDrawElementsWEBGL(r,i,0,a,e,0,o);let s=0;for(let e=0;e<o;e++)s+=i[e];n.update(s,r,1)}this.setMode=i,this.setIndex=s,this.render=c,this.renderInstances=l,this.renderMultiDraw=u}function on(e){let t={geometries:0,textures:0},n={frame:0,calls:0,triangles:0,points:0,lines:0};function r(t,r,i){switch(n.calls++,r){case e.TRIANGLES:n.triangles+=t/3*i;break;case e.LINES:n.lines+=t/2*i;break;case e.LINE_STRIP:n.lines+=i*(t-1);break;case e.LINE_LOOP:n.lines+=i*t;break;case e.POINTS:n.points+=i*t;break;default:W(`WebGLInfo: Unknown draw mode:`,r)}}function i(){n.calls=0,n.triangles=0,n.points=0,n.lines=0}return{memory:t,render:n,programs:null,autoReset:!0,reset:i,update:r}}function sn(e,t,n){let r=new WeakMap,i=new M;function a(a,o,s){let c=a.morphTargetInfluences,l=o.morphAttributes.position||o.morphAttributes.normal||o.morphAttributes.color,u=l===void 0?0:l.length,d=r.get(o);if(d===void 0||d.count!==u){d!==void 0&&d.texture.dispose();let e=o.morphAttributes.position!==void 0,n=o.morphAttributes.normal!==void 0,a=o.morphAttributes.color!==void 0,s=o.morphAttributes.position||[],c=o.morphAttributes.normal||[],l=o.morphAttributes.color||[],f=0;e===!0&&(f=1),n===!0&&(f=2),a===!0&&(f=3);let p=o.attributes.position.count*f,m=1;p>t.maxTextureSize&&(m=Math.ceil(p/t.maxTextureSize),p=t.maxTextureSize);let h=new Float32Array(p*m*4*u),g=new gt(h,p,m,u);g.type=Ke,g.needsUpdate=!0;let _=f*4;for(let t=0;t<u;t++){let r=s[t],o=c[t],u=l[t],d=p*m*4*t;for(let t=0;t<r.count;t++){let s=t*_;e===!0&&(i.fromBufferAttribute(r,t),h[d+s+0]=i.x,h[d+s+1]=i.y,h[d+s+2]=i.z,h[d+s+3]=0),n===!0&&(i.fromBufferAttribute(o,t),h[d+s+4]=i.x,h[d+s+5]=i.y,h[d+s+6]=i.z,h[d+s+7]=0),a===!0&&(i.fromBufferAttribute(u,t),h[d+s+8]=i.x,h[d+s+9]=i.y,h[d+s+10]=i.z,h[d+s+11]=u.itemSize===4?i.w:1)}}d={count:u,texture:g,size:new ve(p,m)},r.set(o,d);function v(){g.dispose(),r.delete(o),o.removeEventListener(`dispose`,v)}o.addEventListener(`dispose`,v)}if(a.isInstancedMesh===!0&&a.morphTexture!==null)s.getUniforms().setValue(e,`morphTexture`,a.morphTexture,n);else{let t=0;for(let e=0;e<c.length;e++)t+=c[e];let n=o.morphTargetsRelative?1:1-t;s.getUniforms().setValue(e,`morphTargetBaseInfluence`,n),s.getUniforms().setValue(e,`morphTargetInfluences`,c)}s.getUniforms().setValue(e,`morphTargetsTexture`,d.texture,n),s.getUniforms().setValue(e,`morphTargetsTextureSize`,d.size)}return{update:a}}function cn(e,t,n,r,i){let a=new WeakMap;function o(r){let o=i.render.frame,s=r.geometry,l=t.get(r,s);if(a.get(l)!==o&&(t.update(l),a.set(l,o)),r.isInstancedMesh&&(r.hasEventListener(`dispose`,c)===!1&&r.addEventListener(`dispose`,c),a.get(r)!==o&&(n.update(r.instanceMatrix,e.ARRAY_BUFFER),r.instanceColor!==null&&n.update(r.instanceColor,e.ARRAY_BUFFER),a.set(r,o))),r.isSkinnedMesh){let e=r.skeleton;a.get(e)!==o&&(e.update(),a.set(e,o))}return l}function s(){a=new WeakMap}function c(e){let t=e.target;t.removeEventListener(`dispose`,c),r.releaseStatesOfObject(t),n.remove(t.instanceMatrix),t.instanceColor!==null&&n.remove(t.instanceColor)}return{update:o,dispose:s}}var ln={1:`LINEAR_TONE_MAPPING`,2:`REINHARD_TONE_MAPPING`,3:`CINEON_TONE_MAPPING`,4:`ACES_FILMIC_TONE_MAPPING`,6:`AGX_TONE_MAPPING`,7:`NEUTRAL_TONE_MAPPING`,5:`CUSTOM_TONE_MAPPING`};function un(e,t,n,r,i,a){let o=new Se(t,n,{type:e,depthBuffer:i,stencilBuffer:a,samples:r?4:0,storeMultisampledDepthBuffer:!1,storeMultisampledStencilBuffer:!1,resolveDepthBuffer:!1,resolveStencilBuffer:!1}),s=null,c=null,l=null,u=new je;u.setAttribute(`position`,new L([-1,3,0,-1,-1,0,3,-1,0],3)),u.setAttribute(`uv`,new L([0,2,0,0,2,0],2));let d=new rt({uniforms:{tDiffuse:{value:null}},vertexShader:`
4074
+ precision highp float;
4075
+
4076
+ uniform mat4 modelViewMatrix;
4077
+ uniform mat4 projectionMatrix;
4078
+
4079
+ attribute vec3 position;
4080
+ attribute vec2 uv;
4081
+
4082
+ varying vec2 vUv;
4083
+
4084
+ void main() {
4085
+ vUv = uv;
4086
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
4087
+ }`,fragmentShader:`
4088
+ precision highp float;
4089
+
4090
+ uniform sampler2D tDiffuse;
4091
+
4092
+ varying vec2 vUv;
4093
+
4094
+ #include <tonemapping_pars_fragment>
4095
+ #include <colorspace_pars_fragment>
4096
+
4097
+ void main() {
4098
+ gl_FragColor = texture2D( tDiffuse, vUv );
4099
+
4100
+ #ifdef LINEAR_TONE_MAPPING
4101
+ gl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );
4102
+ #elif defined( REINHARD_TONE_MAPPING )
4103
+ gl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );
4104
+ #elif defined( CINEON_TONE_MAPPING )
4105
+ gl_FragColor.rgb = CineonToneMapping( gl_FragColor.rgb );
4106
+ #elif defined( ACES_FILMIC_TONE_MAPPING )
4107
+ gl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );
4108
+ #elif defined( AGX_TONE_MAPPING )
4109
+ gl_FragColor.rgb = AgXToneMapping( gl_FragColor.rgb );
4110
+ #elif defined( NEUTRAL_TONE_MAPPING )
4111
+ gl_FragColor.rgb = NeutralToneMapping( gl_FragColor.rgb );
4112
+ #elif defined( CUSTOM_TONE_MAPPING )
4113
+ gl_FragColor.rgb = CustomToneMapping( gl_FragColor.rgb );
4114
+ #endif
4115
+
4116
+ #ifdef SRGB_TRANSFER
4117
+ gl_FragColor = sRGBTransferOETF( gl_FragColor );
4118
+ #endif
4119
+ }`,depthTest:!1,depthWrite:!1}),f=new dt(u,d),p=new wt(-1,1,1,-1,0,1),m=null,h=null,g=!1,_,v=null,y=[],b=!1;this.setSize=function(e,t){o.setSize(e,t),s!==null&&s.setSize(e,t),c!==null&&c.setSize(e,t);for(let n=0;n<y.length;n++){let r=y[n];r.setSize&&r.setSize(e,t)}},this.setEffects=function(e){y=e,b=y.length>0&&y[0].isRenderPass===!0;let t=o.width,n=o.height;y.length>0&&s===null&&(s=new Se(t,n,{type:ne,depthBuffer:!1,stencilBuffer:!1}),c=new Se(t,n,{type:ne,depthBuffer:!1,stencilBuffer:!1}));let r=i===!0&&y.some(e=>e.needsDepthTexture===!0);r!==(o.depthTexture!==null)&&(r===!0&&l===null&&(l=new z(t,n),a===!0&&(l.format=xt,l.type=se)),o.dispose(),o.depthTexture=r?l:null,o.resolveDepthBuffer=r,o.storeMultisampledDepthBuffer=r);for(let e=0;e<y.length;e++){let i=y[e];i.setSize&&i.setSize(t,n),r&&i.needsDepthTexture===!0&&i.setDepthTexture&&i.setDepthTexture(l)}},this.begin=function(e,t){if(g||e.toneMapping===0&&y.length===0)return!1;if(v=t,t!==null){let e=t.width,n=t.height;(o.width!==e||o.height!==n)&&this.setSize(e,n)}return b===!1&&e.setRenderTarget(o),_=e.toneMapping,e.toneMapping=0,!0},this.hasRenderPass=function(){return b},this.end=function(e,t){e.toneMapping=_,g=!0;let n=o,r=s;for(let i=0;i<y.length;i++){let a=y[i];a.enabled!==!1&&(a.render(e,r,n,t),a.needsSwap!==!1&&(n=r,r=r===s?c:s))}if(m!==e.outputColorSpace||h!==e.toneMapping){m=e.outputColorSpace,h=e.toneMapping,d.defines={},Y.getTransfer(m)===`srgb`&&(d.defines.SRGB_TRANSFER=``);let t=ln[h];t&&(d.defines[t]=``),d.needsUpdate=!0}d.uniforms.tDiffuse.value=n.texture,e.setRenderTarget(v),e.render(f,p),v=null,g=!1},this.isCompositing=function(){return g},this.dispose=function(){o.dispose(),s!==null&&s.dispose(),c!==null&&c.dispose(),u.dispose(),d.dispose()}}var dn=new Ge,fn=new z(1,1),pn=new Re(1),mn=new gt,hn=new Te,gn=new q,_n=[],vn=[],yn=new Float32Array(16),bn=new Float32Array(9),xn=new Float32Array(4);function Sn(e,t,n){let r=e[0];if(r<=0||r>0)return e;let i=t*n,a=_n[i];if(a===void 0&&(a=new Float32Array(i),_n[i]=a),t!==0){r.toArray(a,0);for(let r=1,i=0;r!==t;++r)i+=n,e[r].toArray(a,i)}return a}function Cn(e,t){if(e.length!==t.length)return!1;for(let n=0,r=e.length;n<r;n++)if(e[n]!==t[n])return!1;return!0}function wn(e,t){for(let n=0,r=t.length;n<r;n++)e[n]=t[n]}function Tn(e,t){let n=vn[t];n===void 0&&(n=new Int32Array(t),vn[t]=n);for(let r=0;r!==t;++r)n[r]=e.allocateTextureUnit();return n}function En(e,t){let n=this.cache;n[0]!==t&&(e.uniform1f(this.addr,t),n[0]=t)}function Dn(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y)&&(e.uniform2f(this.addr,t.x,t.y),n[0]=t.x,n[1]=t.y);else{if(Cn(n,t))return;e.uniform2fv(this.addr,t),wn(n,t)}}function On(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z)&&(e.uniform3f(this.addr,t.x,t.y,t.z),n[0]=t.x,n[1]=t.y,n[2]=t.z);else if(t.r!==void 0)(n[0]!==t.r||n[1]!==t.g||n[2]!==t.b)&&(e.uniform3f(this.addr,t.r,t.g,t.b),n[0]=t.r,n[1]=t.g,n[2]=t.b);else{if(Cn(n,t))return;e.uniform3fv(this.addr,t),wn(n,t)}}function kn(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z||n[3]!==t.w)&&(e.uniform4f(this.addr,t.x,t.y,t.z,t.w),n[0]=t.x,n[1]=t.y,n[2]=t.z,n[3]=t.w);else{if(Cn(n,t))return;e.uniform4fv(this.addr,t),wn(n,t)}}function An(e,t){let n=this.cache,r=t.elements;if(r===void 0){if(Cn(n,t))return;e.uniformMatrix2fv(this.addr,!1,t),wn(n,t)}else{if(Cn(n,r))return;xn.set(r),e.uniformMatrix2fv(this.addr,!1,xn),wn(n,r)}}function jn(e,t){let n=this.cache,r=t.elements;if(r===void 0){if(Cn(n,t))return;e.uniformMatrix3fv(this.addr,!1,t),wn(n,t)}else{if(Cn(n,r))return;bn.set(r),e.uniformMatrix3fv(this.addr,!1,bn),wn(n,r)}}function Mn(e,t){let n=this.cache,r=t.elements;if(r===void 0){if(Cn(n,t))return;e.uniformMatrix4fv(this.addr,!1,t),wn(n,t)}else{if(Cn(n,r))return;yn.set(r),e.uniformMatrix4fv(this.addr,!1,yn),wn(n,r)}}function Nn(e,t){let n=this.cache;n[0]!==t&&(e.uniform1i(this.addr,t),n[0]=t)}function Pn(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y)&&(e.uniform2i(this.addr,t.x,t.y),n[0]=t.x,n[1]=t.y);else{if(Cn(n,t))return;e.uniform2iv(this.addr,t),wn(n,t)}}function Fn(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z)&&(e.uniform3i(this.addr,t.x,t.y,t.z),n[0]=t.x,n[1]=t.y,n[2]=t.z);else{if(Cn(n,t))return;e.uniform3iv(this.addr,t),wn(n,t)}}function In(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z||n[3]!==t.w)&&(e.uniform4i(this.addr,t.x,t.y,t.z,t.w),n[0]=t.x,n[1]=t.y,n[2]=t.z,n[3]=t.w);else{if(Cn(n,t))return;e.uniform4iv(this.addr,t),wn(n,t)}}function Ln(e,t){let n=this.cache;n[0]!==t&&(e.uniform1ui(this.addr,t),n[0]=t)}function Rn(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y)&&(e.uniform2ui(this.addr,t.x,t.y),n[0]=t.x,n[1]=t.y);else{if(Cn(n,t))return;e.uniform2uiv(this.addr,t),wn(n,t)}}function zn(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z)&&(e.uniform3ui(this.addr,t.x,t.y,t.z),n[0]=t.x,n[1]=t.y,n[2]=t.z);else{if(Cn(n,t))return;e.uniform3uiv(this.addr,t),wn(n,t)}}function Bn(e,t){let n=this.cache;if(t.x!==void 0)(n[0]!==t.x||n[1]!==t.y||n[2]!==t.z||n[3]!==t.w)&&(e.uniform4ui(this.addr,t.x,t.y,t.z,t.w),n[0]=t.x,n[1]=t.y,n[2]=t.z,n[3]=t.w);else{if(Cn(n,t))return;e.uniform4uiv(this.addr,t),wn(n,t)}}function Vn(e){return e.version===0&&(e.compareFunction=519,e.needsUpdate=!0),e}function Hn(e,t,n){let r=this.cache,i=n.allocateTextureUnit();r[0]!==i&&(e.uniform1i(this.addr,i),r[0]=i);let a;a=this.type===e.SAMPLER_2D_SHADOW?Vn(fn):dn,n.setTexture2D(t||a,i)}function Un(e,t,n){let r=this.cache,i=n.allocateTextureUnit();r[0]!==i&&(e.uniform1i(this.addr,i),r[0]=i),n.setTexture3D(t||hn,i)}function Wn(e,t,n){let r=this.cache,i=n.allocateTextureUnit();r[0]!==i&&(e.uniform1i(this.addr,i),r[0]=i);let a;a=this.type===e.SAMPLER_CUBE_SHADOW?Vn(pn):gn,n.setTextureCube(t||a,i)}function Gn(e,t,n){let r=this.cache,i=n.allocateTextureUnit();r[0]!==i&&(e.uniform1i(this.addr,i),r[0]=i),n.setTexture2DArray(t||mn,i)}function Kn(e){switch(e){case 5126:return En;case 35664:return Dn;case 35665:return On;case 35666:return kn;case 35674:return An;case 35675:return jn;case 35676:return Mn;case 5124:case 35670:return Nn;case 35667:case 35671:return Pn;case 35668:case 35672:return Fn;case 35669:case 35673:return In;case 5125:return Ln;case 36294:return Rn;case 36295:return zn;case 36296:return Bn;case 35678:case 36198:case 36298:case 36306:case 35682:return Hn;case 35679:case 36299:case 36307:return Un;case 35680:case 36300:case 36308:case 36293:return Wn;case 36289:case 36303:case 36311:case 36292:return Gn}}function qn(e,t){e.uniform1fv(this.addr,t)}function Jn(e,t){let n=Sn(t,this.size,2);e.uniform2fv(this.addr,n)}function Yn(e,t){let n=Sn(t,this.size,3);e.uniform3fv(this.addr,n)}function Xn(e,t){let n=Sn(t,this.size,4);e.uniform4fv(this.addr,n)}function Zn(e,t){let n=Sn(t,this.size,4);e.uniformMatrix2fv(this.addr,!1,n)}function Qn(e,t){let n=Sn(t,this.size,9);e.uniformMatrix3fv(this.addr,!1,n)}function $n(e,t){let n=Sn(t,this.size,16);e.uniformMatrix4fv(this.addr,!1,n)}function er(e,t){e.uniform1iv(this.addr,t)}function tr(e,t){e.uniform2iv(this.addr,t)}function nr(e,t){e.uniform3iv(this.addr,t)}function rr(e,t){e.uniform4iv(this.addr,t)}function ir(e,t){e.uniform1uiv(this.addr,t)}function ar(e,t){e.uniform2uiv(this.addr,t)}function or(e,t){e.uniform3uiv(this.addr,t)}function sr(e,t){e.uniform4uiv(this.addr,t)}function cr(e,t,n){let r=this.cache,i=t.length,a=Tn(n,i);Cn(r,a)||(e.uniform1iv(this.addr,a),wn(r,a));let o;o=this.type===e.SAMPLER_2D_SHADOW?Vn(fn):dn;for(let e=0;e!==i;++e)n.setTexture2D(t[e]||o,a[e])}function lr(e,t,n){let r=this.cache,i=t.length,a=Tn(n,i);Cn(r,a)||(e.uniform1iv(this.addr,a),wn(r,a));for(let e=0;e!==i;++e)n.setTexture3D(t[e]||hn,a[e])}function ur(e,t,n){let r=this.cache,i=t.length,a=Tn(n,i);Cn(r,a)||(e.uniform1iv(this.addr,a),wn(r,a));let o;o=this.type===e.SAMPLER_CUBE_SHADOW?Vn(pn):gn;for(let e=0;e!==i;++e)n.setTextureCube(t[e]||o,a[e])}function dr(e,t,n){let r=this.cache,i=t.length,a=Tn(n,i);Cn(r,a)||(e.uniform1iv(this.addr,a),wn(r,a));for(let e=0;e!==i;++e)n.setTexture2DArray(t[e]||mn,a[e])}function fr(e){switch(e){case 5126:return qn;case 35664:return Jn;case 35665:return Yn;case 35666:return Xn;case 35674:return Zn;case 35675:return Qn;case 35676:return $n;case 5124:case 35670:return er;case 35667:case 35671:return tr;case 35668:case 35672:return nr;case 35669:case 35673:return rr;case 5125:return ir;case 36294:return ar;case 36295:return or;case 36296:return sr;case 35678:case 36198:case 36298:case 36306:case 35682:return cr;case 35679:case 36299:case 36307:return lr;case 35680:case 36300:case 36308:case 36293:return ur;case 36289:case 36303:case 36311:case 36292:return dr}}var pr=class{constructor(e,t,n){this.id=e,this.addr=n,this.cache=[],this.type=t.type,this.setValue=Kn(t.type)}},mr=class{constructor(e,t,n){this.id=e,this.addr=n,this.cache=[],this.type=t.type,this.size=t.size,this.setValue=fr(t.type)}},hr=class{constructor(e){this.id=e,this.seq=[],this.map={}}setValue(e,t,n){let r=this.seq;for(let i=0,a=r.length;i!==a;++i){let a=r[i];a.setValue(e,t[a.id],n)}}},gr=/(\w+)(\])?(\[|\.)?/g;function _r(e,t){e.seq.push(t),e.map[t.id]=t}function vr(e,t,n){let r=e.name,i=r.length;for(gr.lastIndex=0;;){let a=gr.exec(r),o=gr.lastIndex,s=a[1],c=a[2]===`]`,l=a[3];if(c&&(s|=0),l===void 0||l===`[`&&o+2===i){_r(n,l===void 0?new pr(s,e,t):new mr(s,e,t));break}{let e=n.map[s];e===void 0&&(e=new hr(s),_r(n,e)),n=e}}}var yr=class{constructor(e,t){this.seq=[],this.map={};let n=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let r=0;r<n;++r){let n=e.getActiveUniform(t,r);vr(n,e.getUniformLocation(t,n.name),this)}let r=[],i=[];for(let t of this.seq)t.type===e.SAMPLER_2D_SHADOW||t.type===e.SAMPLER_CUBE_SHADOW||t.type===e.SAMPLER_2D_ARRAY_SHADOW?r.push(t):i.push(t);r.length>0&&(this.seq=r.concat(i))}setValue(e,t,n,r){let i=this.map[t];i!==void 0&&i.setValue(e,n,r)}setOptional(e,t,n){let r=t[n];r!==void 0&&this.setValue(e,n,r)}static upload(e,t,n,r){for(let i=0,a=t.length;i!==a;++i){let a=t[i],o=n[a.id];o.needsUpdate!==!1&&a.setValue(e,o.value,r)}}static seqWithValue(e,t){let n=[];for(let r=0,i=e.length;r!==i;++r){let i=e[r];i.id in t&&n.push(i)}return n}};function br(e,t,n){let r=e.createShader(t);return e.shaderSource(r,n),e.compileShader(r),r}var xr=37297,Sr=0;function Cr(e,t){let n=e.split(`
4120
+ `),r=[],i=Math.max(t-6,0),a=Math.min(t+6,n.length);for(let e=i;e<a;e++){let i=e+1;r.push(`${i===t?`>`:` `} ${i}: ${n[e]}`)}return r.join(`
4121
+ `)}var wr=new V;function Tr(e){Y._getMatrix(wr,Y.workingColorSpace,e);let t=`mat3( ${wr.elements.map(e=>e.toFixed(4))} )`;switch(Y.getTransfer(e)){case G:return[t,`LinearTransferOETF`];case p:return[t,`sRGBTransferOETF`];default:return X(`WebGLProgram: Unsupported color space: `,e),[t,`LinearTransferOETF`]}}function Er(e,t,n){let r=e.getShaderParameter(t,e.COMPILE_STATUS),i=(e.getShaderInfoLog(t)||``).trim();if(r&&i===``)return``;let a=/ERROR: 0:(\d+)/.exec(i);if(a){let r=parseInt(a[1]);return n.toUpperCase()+`
4122
+
4123
+ `+i+`
4124
+
4125
+ `+Cr(e.getShaderSource(t),r)}return i}function Dr(e,t){let n=Tr(t);return[`vec4 ${e}( vec4 value ) {`,` return ${n[1]}( vec4( ${n[0]} * value.rgb, value.a ) );`,`}`].join(`
4126
+ `)}var Or={1:`Linear`,2:`Reinhard`,3:`Cineon`,4:`ACESFilmic`,6:`AgX`,7:`Neutral`,5:`Custom`};function kr(e,t){let n=Or[t];return n===void 0?(X(`WebGLProgram: Unsupported toneMapping:`,t),`vec3 `+e+`( vec3 color ) { return LinearToneMapping( color ); }`):`vec3 `+e+`( vec3 color ) { return `+n+`ToneMapping( color ); }`}var Ar=new w;function jr(){return Y.getLuminanceCoefficients(Ar),[`float luminance( const in vec3 rgb ) {`,` const vec3 weights = vec3( ${Ar.x.toFixed(4)}, ${Ar.y.toFixed(4)}, ${Ar.z.toFixed(4)} );`,` return dot( weights, rgb );`,`}`].join(`
4127
+ `)}function Mr(e){return[e.extensionClipCullDistance?`#extension GL_ANGLE_clip_cull_distance : require`:``,e.extensionMultiDraw?`#extension GL_ANGLE_multi_draw : require`:``].filter(Fr).join(`
4128
+ `)}function Nr(e){let t=[];for(let n in e){let r=e[n];r!==!1&&t.push(`#define `+n+` `+r)}return t.join(`
4129
+ `)}function Pr(e,t){let n={},r=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let i=0;i<r;i++){let r=e.getActiveAttrib(t,i),a=r.name,o=1;r.type===e.FLOAT_MAT2&&(o=2),r.type===e.FLOAT_MAT3&&(o=3),r.type===e.FLOAT_MAT4&&(o=4),n[a]={type:r.type,location:e.getAttribLocation(t,a),locationSize:o}}return n}function Fr(e){return e!==``}function Ir(e,t){let n=t.numSpotLightShadows+t.numSpotLightMaps-t.numSpotLightShadowsWithMaps;return e.replace(/NUM_SUN_LIGHTS/g,t.numSunLights).replace(/NUM_DIR_LIGHTS/g,t.numDirLights).replace(/NUM_SPOT_LIGHTS/g,t.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g,t.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g,n).replace(/NUM_RECT_AREA_LIGHTS/g,t.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,t.numPointLights).replace(/NUM_HEMI_LIGHTS/g,t.numHemiLights).replace(/NUM_SUN_LIGHT_SHADOWS/g,t.numSunLightShadows).replace(/NUM_DIR_LIGHT_SHADOWS/g,t.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g,t.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g,t.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,t.numPointLightShadows).replace(/NUM_LIGHT_PROBE_GRIDS/g,t.numLightProbeGrids)}function Lr(e,t){return e.replace(/NUM_CLIPPING_PLANES/g,t.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,t.numClippingPlanes-t.numClipIntersection)}var Rr=/^[ \t]*#include +<([\w\d./]+)>/gm;function zr(e){return e.replace(Rr,Br)}function Br(e,t){let n=Z[t];if(n===void 0)throw Error(`THREE.WebGLProgram: Can not resolve #include <`+t+`>`);return zr(n)}var Vr=/#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g;function Hr(e){return e.replace(Vr,Ur)}function Ur(e,t,n,r){let i=``;for(let e=parseInt(t);e<parseInt(n);e++)i+=r.replace(/\[\s*i\s*\]/g,`[ `+e+` ]`).replace(/UNROLLED_LOOP_INDEX/g,e);return i}function Wr(e){let t=`precision ${e.precision} float;
4130
+ precision ${e.precision} int;
4131
+ precision ${e.precision} sampler2D;
4132
+ precision ${e.precision} samplerCube;
4133
+ precision ${e.precision} sampler3D;
4134
+ precision ${e.precision} sampler2DArray;
4135
+ precision ${e.precision} sampler2DShadow;
4136
+ precision ${e.precision} samplerCubeShadow;
4137
+ precision ${e.precision} sampler2DArrayShadow;
4138
+ precision ${e.precision} isampler2D;
4139
+ precision ${e.precision} isampler3D;
4140
+ precision ${e.precision} isamplerCube;
4141
+ precision ${e.precision} isampler2DArray;
4142
+ precision ${e.precision} usampler2D;
4143
+ precision ${e.precision} usampler3D;
4144
+ precision ${e.precision} usamplerCube;
4145
+ precision ${e.precision} usampler2DArray;
4146
+ `;return e.precision===`highp`?t+=`
4147
+ #define HIGH_PRECISION`:e.precision===`mediump`?t+=`
4148
+ #define MEDIUM_PRECISION`:e.precision===`lowp`&&(t+=`
4149
+ #define LOW_PRECISION`),t}var Gr={1:`SHADOWMAP_TYPE_PCF`,3:`SHADOWMAP_TYPE_VSM`};function Kr(e){return Gr[e.shadowMapType]||`SHADOWMAP_TYPE_BASIC`}var qr={302:`ENVMAP_MODE_REFRACTION`};function Jr(e){return e.envMap===!1?`ENVMAP_MODE_REFLECTION`:qr[e.envMapMode]||`ENVMAP_MODE_REFLECTION`}var Yr={0:`ENVMAP_BLENDING_MULTIPLY`,1:`ENVMAP_BLENDING_MIX`,2:`ENVMAP_BLENDING_ADD`};function Xr(e){return e.envMap===!1?`ENVMAP_BLENDING_NONE`:Yr[e.combine]||`ENVMAP_BLENDING_NONE`}function Zr(e,t,n,r){let i=e.getContext(),a=n.defines,o=n.vertexShader,s=n.fragmentShader,c=Kr(n),l=n.envMapPMREM===!0?`ENVMAP_TYPE_PMREM`:`ENVMAP_TYPE_CUBE`,u=Jr(n),d=Xr(n),f=Mr(n),p=Nr(a),m=i.createProgram(),h,g,_=n.glslVersion?`#version `+n.glslVersion+`
4150
+ `:``;n.isRawShaderMaterial?(h=[`#define SHADER_TYPE `+n.shaderType,`#define SHADER_NAME `+n.shaderName,p].filter(Fr).join(`
4151
+ `),h.length>0&&(h+=`
4152
+ `),g=[`#define SHADER_TYPE `+n.shaderType,`#define SHADER_NAME `+n.shaderName,p].filter(Fr).join(`
4153
+ `),g.length>0&&(g+=`
4154
+ `)):(h=[Wr(n),`#define SHADER_TYPE `+n.shaderType,`#define SHADER_NAME `+n.shaderName,p,n.extensionClipCullDistance?`#define USE_CLIP_DISTANCE`:``,n.batching?`#define USE_BATCHING`:``,n.batchingColor?`#define USE_BATCHING_COLOR`:``,n.instancing?`#define USE_INSTANCING`:``,n.instancingColor?`#define USE_INSTANCING_COLOR`:``,n.instancingMorph?`#define USE_INSTANCING_MORPH`:``,n.useFog&&n.fog?`#define USE_FOG`:``,n.useFog&&n.fogExp2?`#define FOG_EXP2`:``,n.map?`#define USE_MAP`:``,n.envMap?`#define USE_ENVMAP`:``,n.envMap?`#define `+u:``,n.lightMap?`#define USE_LIGHTMAP`:``,n.aoMap?`#define USE_AOMAP`:``,n.bumpMap?`#define USE_BUMPMAP`:``,n.normalMap?`#define USE_NORMALMAP`:``,n.normalMapObjectSpace?`#define USE_NORMALMAP_OBJECTSPACE`:``,n.normalMapTangentSpace?`#define USE_NORMALMAP_TANGENTSPACE`:``,n.displacementMap?`#define USE_DISPLACEMENTMAP`:``,n.emissiveMap?`#define USE_EMISSIVEMAP`:``,n.anisotropy?`#define USE_ANISOTROPY`:``,n.anisotropyMap?`#define USE_ANISOTROPYMAP`:``,n.clearcoatMap?`#define USE_CLEARCOATMAP`:``,n.clearcoatRoughnessMap?`#define USE_CLEARCOAT_ROUGHNESSMAP`:``,n.clearcoatNormalMap?`#define USE_CLEARCOAT_NORMALMAP`:``,n.diffuseRoughnessMap?`#define USE_DIFFUSE_ROUGHNESSMAP`:``,n.iridescenceMap?`#define USE_IRIDESCENCEMAP`:``,n.iridescenceThicknessMap?`#define USE_IRIDESCENCE_THICKNESSMAP`:``,n.specularMap?`#define USE_SPECULARMAP`:``,n.specularColorMap?`#define USE_SPECULAR_COLORMAP`:``,n.specularIntensityMap?`#define USE_SPECULAR_INTENSITYMAP`:``,n.roughnessMap?`#define USE_ROUGHNESSMAP`:``,n.metalnessMap?`#define USE_METALNESSMAP`:``,n.alphaMap?`#define USE_ALPHAMAP`:``,n.alphaHash?`#define USE_ALPHAHASH`:``,n.transmission?`#define USE_TRANSMISSION`:``,n.transmissionMap?`#define USE_TRANSMISSIONMAP`:``,n.thicknessMap?`#define USE_THICKNESSMAP`:``,n.sheenColorMap?`#define USE_SHEEN_COLORMAP`:``,n.sheenRoughnessMap?`#define USE_SHEEN_ROUGHNESSMAP`:``,n.mapUv?`#define MAP_UV `+n.mapUv:``,n.alphaMapUv?`#define ALPHAMAP_UV `+n.alphaMapUv:``,n.lightMapUv?`#define LIGHTMAP_UV `+n.lightMapUv:``,n.aoMapUv?`#define AOMAP_UV `+n.aoMapUv:``,n.emissiveMapUv?`#define EMISSIVEMAP_UV `+n.emissiveMapUv:``,n.bumpMapUv?`#define BUMPMAP_UV `+n.bumpMapUv:``,n.normalMapUv?`#define NORMALMAP_UV `+n.normalMapUv:``,n.displacementMapUv?`#define DISPLACEMENTMAP_UV `+n.displacementMapUv:``,n.metalnessMapUv?`#define METALNESSMAP_UV `+n.metalnessMapUv:``,n.roughnessMapUv?`#define ROUGHNESSMAP_UV `+n.roughnessMapUv:``,n.anisotropyMapUv?`#define ANISOTROPYMAP_UV `+n.anisotropyMapUv:``,n.clearcoatMapUv?`#define CLEARCOATMAP_UV `+n.clearcoatMapUv:``,n.clearcoatNormalMapUv?`#define CLEARCOAT_NORMALMAP_UV `+n.clearcoatNormalMapUv:``,n.clearcoatRoughnessMapUv?`#define CLEARCOAT_ROUGHNESSMAP_UV `+n.clearcoatRoughnessMapUv:``,n.diffuseRoughnessMapUv?`#define DIFFUSE_ROUGHNESSMAP_UV `+n.diffuseRoughnessMapUv:``,n.iridescenceMapUv?`#define IRIDESCENCEMAP_UV `+n.iridescenceMapUv:``,n.iridescenceThicknessMapUv?`#define IRIDESCENCE_THICKNESSMAP_UV `+n.iridescenceThicknessMapUv:``,n.sheenColorMapUv?`#define SHEEN_COLORMAP_UV `+n.sheenColorMapUv:``,n.sheenRoughnessMapUv?`#define SHEEN_ROUGHNESSMAP_UV `+n.sheenRoughnessMapUv:``,n.specularMapUv?`#define SPECULARMAP_UV `+n.specularMapUv:``,n.specularColorMapUv?`#define SPECULAR_COLORMAP_UV `+n.specularColorMapUv:``,n.specularIntensityMapUv?`#define SPECULAR_INTENSITYMAP_UV `+n.specularIntensityMapUv:``,n.transmissionMapUv?`#define TRANSMISSIONMAP_UV `+n.transmissionMapUv:``,n.thicknessMapUv?`#define THICKNESSMAP_UV `+n.thicknessMapUv:``,n.vertexTangents&&n.flatShading===!1?`#define USE_TANGENT`:``,n.vertexNormals?`#define HAS_NORMAL`:``,n.vertexColors?`#define USE_COLOR`:``,n.vertexAlphas?`#define USE_COLOR_ALPHA`:``,n.vertexUv1s?`#define USE_UV1`:``,n.vertexUv2s?`#define USE_UV2`:``,n.vertexUv3s?`#define USE_UV3`:``,n.pointsUvs?`#define USE_POINTS_UV`:``,n.flatShading?`#define FLAT_SHADED`:``,n.skinning?`#define USE_SKINNING`:``,n.morphTargets?`#define USE_MORPHTARGETS`:``,n.morphNormals&&n.flatShading===!1?`#define USE_MORPHNORMALS`:``,n.morphColors?`#define USE_MORPHCOLORS`:``,n.morphTargetsCount>0?`#define MORPHTARGETS_TEXTURE_STRIDE `+n.morphTextureStride:``,n.morphTargetsCount>0?`#define MORPHTARGETS_COUNT `+n.morphTargetsCount:``,n.doubleSided?`#define DOUBLE_SIDED`:``,n.flipSided?`#define FLIP_SIDED`:``,n.shadowMapEnabled?`#define USE_SHADOWMAP`:``,n.shadowMapEnabled?`#define `+c:``,n.sizeAttenuation?`#define USE_SIZEATTENUATION`:``,n.numLightProbes>0?`#define USE_LIGHT_PROBES`:``,n.logarithmicDepthBuffer?`#define USE_LOGARITHMIC_DEPTH_BUFFER`:``,n.reversedDepthBuffer?`#define USE_REVERSED_DEPTH_BUFFER`:``,`uniform mat4 modelMatrix;`,`uniform mat4 modelViewMatrix;`,`uniform mat4 projectionMatrix;`,`uniform mat4 viewMatrix;`,`uniform mat3 normalMatrix;`,`uniform vec3 cameraPosition;`,`uniform bool isOrthographic;`,`#ifdef USE_INSTANCING`,` attribute mat4 instanceMatrix;`,`#endif`,`#ifdef USE_INSTANCING_COLOR`,` attribute vec3 instanceColor;`,`#endif`,`#ifdef USE_INSTANCING_MORPH`,` uniform sampler2D morphTexture;`,`#endif`,`attribute vec3 position;`,`attribute vec3 normal;`,`attribute vec2 uv;`,`#ifdef USE_UV1`,` attribute vec2 uv1;`,`#endif`,`#ifdef USE_UV2`,` attribute vec2 uv2;`,`#endif`,`#ifdef USE_UV3`,` attribute vec2 uv3;`,`#endif`,`#ifdef USE_TANGENT`,` attribute vec4 tangent;`,`#endif`,`#if defined( USE_COLOR_ALPHA )`,` attribute vec4 color;`,`#elif defined( USE_COLOR )`,` attribute vec3 color;`,`#endif`,`#ifdef USE_SKINNING`,` attribute vec4 skinIndex;`,` attribute vec4 skinWeight;`,`#endif`,`
4155
+ `].filter(Fr).join(`
4156
+ `),g=[Wr(n),`#define SHADER_TYPE `+n.shaderType,`#define SHADER_NAME `+n.shaderName,p,n.useFog&&n.fog?`#define USE_FOG`:``,n.useFog&&n.fogExp2?`#define FOG_EXP2`:``,n.alphaToCoverage?`#define ALPHA_TO_COVERAGE`:``,n.map?`#define USE_MAP`:``,n.matcap?`#define USE_MATCAP`:``,n.envMap?`#define USE_ENVMAP`:``,n.envMap?`#define `+l:``,n.envMap?`#define `+u:``,n.envMap?`#define `+d:``,n.envMapPMREM?`#define ENVMAP_MAX_LOD `+n.envMapMaxLod+`.0`:``,n.envMapPMREM?`#define ENVMAP_SIZE `+n.envMapSize+`.0`:``,n.lightMap?`#define USE_LIGHTMAP`:``,n.aoMap?`#define USE_AOMAP`:``,n.bumpMap?`#define USE_BUMPMAP`:``,n.normalMap?`#define USE_NORMALMAP`:``,n.normalMapObjectSpace?`#define USE_NORMALMAP_OBJECTSPACE`:``,n.normalMapTangentSpace?`#define USE_NORMALMAP_TANGENTSPACE`:``,n.packedNormalMap?`#define USE_PACKED_NORMALMAP`:``,n.emissiveMap?`#define USE_EMISSIVEMAP`:``,n.anisotropy?`#define USE_ANISOTROPY`:``,n.anisotropyMap?`#define USE_ANISOTROPYMAP`:``,n.clearcoat?`#define USE_CLEARCOAT`:``,n.clearcoatMap?`#define USE_CLEARCOATMAP`:``,n.clearcoatRoughnessMap?`#define USE_CLEARCOAT_ROUGHNESSMAP`:``,n.clearcoatNormalMap?`#define USE_CLEARCOAT_NORMALMAP`:``,n.diffuseRoughness?`#define USE_DIFFUSE_ROUGHNESS`:``,n.diffuseRoughnessMap?`#define USE_DIFFUSE_ROUGHNESSMAP`:``,n.dispersion?`#define USE_DISPERSION`:``,n.retroreflection?`#define USE_RETROREFLECTION`:``,n.iridescence?`#define USE_IRIDESCENCE`:``,n.iridescenceMap?`#define USE_IRIDESCENCEMAP`:``,n.iridescenceThicknessMap?`#define USE_IRIDESCENCE_THICKNESSMAP`:``,n.specularMap?`#define USE_SPECULARMAP`:``,n.specularColorMap?`#define USE_SPECULAR_COLORMAP`:``,n.specularIntensityMap?`#define USE_SPECULAR_INTENSITYMAP`:``,n.roughnessMap?`#define USE_ROUGHNESSMAP`:``,n.metalnessMap?`#define USE_METALNESSMAP`:``,n.alphaMap?`#define USE_ALPHAMAP`:``,n.alphaTest?`#define USE_ALPHATEST`:``,n.alphaHash?`#define USE_ALPHAHASH`:``,n.sheen?`#define USE_SHEEN`:``,n.sheenColorMap?`#define USE_SHEEN_COLORMAP`:``,n.sheenRoughnessMap?`#define USE_SHEEN_ROUGHNESSMAP`:``,n.transmission?`#define USE_TRANSMISSION`:``,n.transmissionMap?`#define USE_TRANSMISSIONMAP`:``,n.thicknessMap?`#define USE_THICKNESSMAP`:``,n.vertexTangents&&n.flatShading===!1?`#define USE_TANGENT`:``,n.vertexColors||n.instancingColor?`#define USE_COLOR`:``,n.vertexAlphas||n.batchingColor?`#define USE_COLOR_ALPHA`:``,n.vertexUv1s?`#define USE_UV1`:``,n.vertexUv2s?`#define USE_UV2`:``,n.vertexUv3s?`#define USE_UV3`:``,n.pointsUvs?`#define USE_POINTS_UV`:``,n.gradientMap?`#define USE_GRADIENTMAP`:``,n.flatShading?`#define FLAT_SHADED`:``,n.doubleSided?`#define DOUBLE_SIDED`:``,n.flipSided?`#define FLIP_SIDED`:``,n.shadowMapEnabled?`#define USE_SHADOWMAP`:``,n.shadowMapEnabled?`#define `+c:``,n.premultipliedAlpha?`#define PREMULTIPLIED_ALPHA`:``,n.numLightProbes>0?`#define USE_LIGHT_PROBES`:``,n.decodeVideoTexture?`#define DECODE_VIDEO_TEXTURE`:``,n.decodeVideoTextureEmissive?`#define DECODE_VIDEO_TEXTURE_EMISSIVE`:``,n.logarithmicDepthBuffer?`#define USE_LOGARITHMIC_DEPTH_BUFFER`:``,n.reversedDepthBuffer?`#define USE_REVERSED_DEPTH_BUFFER`:``,`uniform mat4 viewMatrix;`,`uniform vec3 cameraPosition;`,`uniform bool isOrthographic;`,n.toneMapping===0?``:`#define TONE_MAPPING`,n.toneMapping===0?``:Z.tonemapping_pars_fragment,n.toneMapping===0?``:kr(`toneMapping`,n.toneMapping),n.dithering?`#define DITHERING`:``,n.opaque?`#define OPAQUE`:``,Z.colorspace_pars_fragment,Dr(`linearToOutputTexel`,n.outputColorSpace),jr(),n.useDepthPacking?`#define DEPTH_PACKING `+n.depthPacking:``,`
4157
+ `].filter(Fr).join(`
4158
+ `)),o=zr(o),o=Ir(o,n),o=Lr(o,n),s=zr(s),s=Ir(s,n),s=Lr(s,n),o=Hr(o),s=Hr(s),n.isRawShaderMaterial!==!0&&(_=`#version 300 es
4159
+ `,h=[f,`#define attribute in`,`#define varying out`,`#define texture2D texture`].join(`
4160
+ `)+`
4161
+ `+h,g=[`#define varying in`,n.glslVersion===`300 es`?``:`layout(location = 0) out highp vec4 pc_fragColor;`,n.glslVersion===`300 es`?``:`#define gl_FragColor pc_fragColor`,`#define gl_FragDepthEXT gl_FragDepth`,`#define texture2D texture`,`#define textureCube texture`,`#define texture2DProj textureProj`,`#define texture2DLodEXT textureLod`,`#define texture2DProjLodEXT textureProjLod`,`#define textureCubeLodEXT textureLod`,`#define texture2DGradEXT textureGrad`,`#define texture2DProjGradEXT textureProjGrad`,`#define textureCubeGradEXT textureGrad`].join(`
4162
+ `)+`
4163
+ `+g);let v=_+h+o,y=_+g+s,b=br(i,i.VERTEX_SHADER,v),x=br(i,i.FRAGMENT_SHADER,y);i.attachShader(m,b),i.attachShader(m,x),n.index0AttributeName===void 0?n.hasPositionAttribute===!0&&i.bindAttribLocation(m,0,`position`):i.bindAttribLocation(m,0,n.index0AttributeName),i.linkProgram(m);function S(t){if(e.debug.checkShaderErrors){let n=i.getProgramInfoLog(m)||``,r=i.getShaderInfoLog(b)||``,a=i.getShaderInfoLog(x)||``,o=n.trim(),s=r.trim(),c=a.trim(),l=!0,u=!0;if(i.getProgramParameter(m,i.LINK_STATUS)===!1){if(l=!1,typeof e.debug.onShaderError==`function`)e.debug.onShaderError(i,m,b,x);else{let e=Er(i,b,`vertex`),n=Er(i,x,`fragment`);W(`WebGLProgram: Shader Error `+i.getError()+` - VALIDATE_STATUS `+i.getProgramParameter(m,i.VALIDATE_STATUS)+`
4164
+
4165
+ Material Name: `+t.name+`
4166
+ Material Type: `+t.type+`
4167
+
4168
+ Program Info Log: `+o+`
4169
+ `+e+`
4170
+ `+n)}}else o===``?(s===``||c===``)&&(u=!1):X(`WebGLProgram: Program Info Log:`,o);u&&(t.diagnostics={runnable:l,programLog:o,vertexShader:{log:s,prefix:h},fragmentShader:{log:c,prefix:g}})}i.deleteShader(b),i.deleteShader(x),C=new yr(i,m),w=Pr(i,m)}let C;this.getUniforms=function(){return C===void 0&&S(this),C};let w;this.getAttributes=function(){return w===void 0&&S(this),w};let T=n.rendererExtensionParallelShaderCompile===!1;return this.isReady=function(){return T===!1&&(T=i.getProgramParameter(m,xr)),T},this.destroy=function(){r.releaseStatesOfProgram(this),i.deleteProgram(m),this.program=void 0},this.type=n.shaderType,this.name=n.shaderName,this.id=Sr++,this.cacheKey=t,this.usedTimes=1,this.program=m,this.vertexShader=b,this.fragmentShader=x,this}var Qr=0,$r=class{constructor(){this.shaderCache=new Map,this.materialCache=new Map}update(e,t,n){let r=this._getShaderCacheForMaterial(e);return r.has(t)===!1&&(r.add(t),t.usedTimes++),r.has(n)===!1&&(r.add(n),n.usedTimes++),this}remove(e){let t=this.materialCache.get(e);for(let e of t)e.usedTimes--,e.usedTimes===0&&this.shaderCache.delete(e.code);return this.materialCache.delete(e),this}getVertexShaderStage(e){return this._getShaderStage(e.vertexShader)}getFragmentShaderStage(e){return this._getShaderStage(e.fragmentShader)}dispose(){this.shaderCache.clear(),this.materialCache.clear()}_getShaderCacheForMaterial(e){let t=this.materialCache,n=t.get(e);return n===void 0&&(n=new Set,t.set(e,n)),n}_getShaderStage(e){let t=this.shaderCache,n=t.get(e);return n===void 0&&(n=new ei(e),t.set(e,n)),n}},ei=class{constructor(e){this.id=Qr++,this.code=e,this.usedTimes=0}};function ti(e){return e===1030||e===37490||e===36285}function ni(e,t,n,r,i,a){let o=new C,s=new $r,c=new Set,l=[],u=new Map,d=r.logarithmicDepthBuffer,f={MeshDepthMaterial:`depth`,MeshDistanceMaterial:`distance`,MeshNormalMaterial:`normal`,MeshBasicMaterial:`basic`,MeshLambertMaterial:`lambert`,MeshPhongMaterial:`phong`,MeshToonMaterial:`toon`,MeshStandardMaterial:`physical`,MeshPhysicalMaterial:`physical`,MeshMatcapMaterial:`matcap`,LineBasicMaterial:`basic`,LineDashedMaterial:`dashed`,PointsMaterial:`points`,ShadowMaterial:`shadow`,SpriteMaterial:`sprite`};function p(e){return c.add(e),e===0?`uv`:`uv${e}`}function m(i,o,l,u,m,h){let g=u.fog,_=m.geometry,v=i.isMeshStandardMaterial||i.isMeshLambertMaterial||i.isMeshPhongMaterial?u.environment:null,y=i.isMeshStandardMaterial||i.isMeshLambertMaterial&&!i.envMap||i.isMeshPhongMaterial&&!i.envMap,b=t.get(i.envMap||v,y),x=f[i.type],S=r.precision;i.precision!==null&&(S=r.getMaxPrecision(i.precision),S!==i.precision&&X(`WebGLProgram.getParameters:`,i.precision,`not supported, using`,S,`instead.`));let C=_.morphAttributes.position||_.morphAttributes.normal||_.morphAttributes.color,w=C===void 0?0:C.length,T=0;_.morphAttributes.position!==void 0&&(T=1),_.morphAttributes.normal!==void 0&&(T=2),_.morphAttributes.color!==void 0&&(T=3);let E,D,O,k;if(x){let e=kt[x];E=e.vertexShader,D=e.fragmentShader}else{E=i.vertexShader,D=i.fragmentShader;let e=s.getVertexShaderStage(i),t=s.getFragmentShaderStage(i);s.update(i,e,t),O=e.id,k=t.id}let A=e.getRenderTarget(),j=e.state.buffers.depth.getReversed(),M=m.isInstancedMesh===!0,N=m.isBatchedMesh===!0,P=!!i.map,F=!!i.matcap,I=!!b,L=I&&b.isPMREMTexture===!0,ee=!!i.aoMap,te=!!i.lightMap,ne=!!i.bumpMap&&i.wireframe===!1,re=!!i.normalMap,R=!!i.displacementMap,ie=!!i.emissiveMap,ae=!!i.metalnessMap,oe=!!i.roughnessMap,se=i.anisotropy>0,z=i.clearcoat>0,ce=i.diffuseRoughness>0,le=i.dispersion>0,ue=i.retroreflectivity>0,de=i.iridescence>0,fe=i.sheen>0,pe=i.transmission>0,me=se&&!!i.anisotropyMap,he=z&&!!i.clearcoatMap,ge=z&&!!i.clearcoatNormalMap,_e=z&&!!i.clearcoatRoughnessMap,ve=ce&&!!i.diffuseRoughnessMap,ye=de&&!!i.iridescenceMap,be=de&&!!i.iridescenceThicknessMap,xe=fe&&!!i.sheenColorMap,Se=fe&&!!i.sheenRoughnessMap,Ce=!!i.specularMap,we=!!i.specularColorMap,Te=!!i.specularIntensityMap,Ee=pe&&!!i.transmissionMap,De=pe&&!!i.thicknessMap,Oe=!!i.gradientMap,B=!!i.alphaMap,V=i.alphaTest>0,ke=!!i.alphaHash,Ae=!!i.extensions,je=0;i.toneMapped&&(A===null||A.isXRRenderTarget===!0)&&(je=e.toneMapping);let Me=L?b.isCompressedCubeTexture?b.image[0].mipmaps:b.mipmaps:null,H={shaderID:x,shaderType:i.type,shaderName:i.name,vertexShader:E,fragmentShader:D,defines:i.defines,customVertexShaderID:O,customFragmentShaderID:k,isRawShaderMaterial:i.isRawShaderMaterial===!0,glslVersion:i.glslVersion,precision:S,batching:N,batchingColor:N&&m._colorsTexture!==null,instancing:M,instancingColor:M&&m.instanceColor!==null,instancingMorph:M&&m.morphTexture!==null,outputColorSpace:A===null?e.outputColorSpace:A.isXRRenderTarget===!0?A.texture.colorSpace:Y.workingColorSpace,alphaToCoverage:!!i.alphaToCoverage,map:P,matcap:F,envMap:I,envMapMode:I&&b.mapping,envMapPMREM:L,envMapMaxLod:L?Me.length-1:null,envMapSize:L?Me[0].width:null,aoMap:ee,lightMap:te,bumpMap:ne,normalMap:re,displacementMap:R,emissiveMap:ie,normalMapObjectSpace:re&&i.normalMapType===1,normalMapTangentSpace:re&&i.normalMapType===0,packedNormalMap:re&&i.normalMapType===0&&ti(i.normalMap.format),metalnessMap:ae,roughnessMap:oe,anisotropy:se,anisotropyMap:me,clearcoat:z,clearcoatMap:he,clearcoatNormalMap:ge,clearcoatRoughnessMap:_e,diffuseRoughness:ce,diffuseRoughnessMap:ve,dispersion:le,retroreflection:ue,iridescence:de,iridescenceMap:ye,iridescenceThicknessMap:be,sheen:fe,sheenColorMap:xe,sheenRoughnessMap:Se,specularMap:Ce,specularColorMap:we,specularIntensityMap:Te,transmission:pe,transmissionMap:Ee,thicknessMap:De,gradientMap:Oe,opaque:i.transparent===!1&&i.blending===1&&i.alphaToCoverage===!1,alphaMap:B,alphaTest:V,alphaHash:ke,combine:i.combine,mapUv:P&&p(i.map.channel),aoMapUv:ee&&p(i.aoMap.channel),lightMapUv:te&&p(i.lightMap.channel),bumpMapUv:ne&&p(i.bumpMap.channel),normalMapUv:re&&p(i.normalMap.channel),displacementMapUv:R&&p(i.displacementMap.channel),emissiveMapUv:ie&&p(i.emissiveMap.channel),metalnessMapUv:ae&&p(i.metalnessMap.channel),roughnessMapUv:oe&&p(i.roughnessMap.channel),anisotropyMapUv:me&&p(i.anisotropyMap.channel),clearcoatMapUv:he&&p(i.clearcoatMap.channel),clearcoatNormalMapUv:ge&&p(i.clearcoatNormalMap.channel),clearcoatRoughnessMapUv:_e&&p(i.clearcoatRoughnessMap.channel),diffuseRoughnessMapUv:ve&&p(i.diffuseRoughnessMap.channel),iridescenceMapUv:ye&&p(i.iridescenceMap.channel),iridescenceThicknessMapUv:be&&p(i.iridescenceThicknessMap.channel),sheenColorMapUv:xe&&p(i.sheenColorMap.channel),sheenRoughnessMapUv:Se&&p(i.sheenRoughnessMap.channel),specularMapUv:Ce&&p(i.specularMap.channel),specularColorMapUv:we&&p(i.specularColorMap.channel),specularIntensityMapUv:Te&&p(i.specularIntensityMap.channel),transmissionMapUv:Ee&&p(i.transmissionMap.channel),thicknessMapUv:De&&p(i.thicknessMap.channel),alphaMapUv:B&&p(i.alphaMap.channel),vertexTangents:!!_.attributes.tangent&&(re||se),vertexNormals:!!_.attributes.normal,vertexColors:i.vertexColors,vertexAlphas:i.vertexColors===!0&&!!_.attributes.color&&_.attributes.color.itemSize===4,pointsUvs:m.isPoints===!0&&!!_.attributes.uv&&(P||B),fog:!!g,useFog:i.fog===!0,fogExp2:!!g&&g.isFogExp2,flatShading:i.wireframe===!1&&(i.flatShading===!0||_.attributes.normal===void 0&&re===!1&&(i.isMeshLambertMaterial||i.isMeshPhongMaterial||i.isMeshStandardMaterial||i.isMeshPhysicalMaterial)),sizeAttenuation:i.sizeAttenuation===!0,logarithmicDepthBuffer:d,reversedDepthBuffer:j,skinning:m.isSkinnedMesh===!0,hasPositionAttribute:_.attributes.position!==void 0,morphTargets:_.morphAttributes.position!==void 0,morphNormals:_.morphAttributes.normal!==void 0,morphColors:_.morphAttributes.color!==void 0,morphTargetsCount:w,morphTextureStride:T,numSunLights:o.sun.length,numDirLights:o.directional.length,numPointLights:o.point.length,numSpotLights:o.spot.length,numSpotLightMaps:o.spotLightMap.length,numRectAreaLights:o.rectArea.length,numHemiLights:o.hemi.length,numSunLightShadows:o.sunShadowMap.length,numDirLightShadows:o.directionalShadowMap.length,numPointLightShadows:o.pointShadowMap.length,numSpotLightShadows:o.spotShadowMap.length,numSpotLightShadowsWithMaps:o.numSpotLightShadowsWithMaps,numLightProbes:o.numLightProbes,numLightProbeGrids:h.filter(e=>e.texture!==null).length,numClippingPlanes:a.numPlanes,numClipIntersection:a.numIntersection,dithering:i.dithering,shadowMapEnabled:e.shadowMap.enabled&&l.length>0,shadowMapType:e.shadowMap.type,toneMapping:je,decodeVideoTexture:P&&i.map.isVideoTexture===!0&&Y.getTransfer(i.map.colorSpace)===`srgb`,decodeVideoTextureEmissive:ie&&i.emissiveMap.isVideoTexture===!0&&Y.getTransfer(i.emissiveMap.colorSpace)===`srgb`,premultipliedAlpha:i.premultipliedAlpha,doubleSided:i.side===2,flipSided:i.side===1,useDepthPacking:i.depthPacking>=0,depthPacking:i.depthPacking||0,index0AttributeName:i.index0AttributeName,extensionClipCullDistance:Ae&&i.extensions.clipCullDistance===!0&&n.has(`WEBGL_clip_cull_distance`),extensionMultiDraw:(Ae&&i.extensions.multiDraw===!0||N)&&n.has(`WEBGL_multi_draw`),rendererExtensionParallelShaderCompile:n.has(`KHR_parallel_shader_compile`),customProgramCacheKey:i.customProgramCacheKey()};return H.vertexUv1s=c.has(1),H.vertexUv2s=c.has(2),H.vertexUv3s=c.has(3),c.clear(),H}function h(t){let n=[];if(t.shaderID?n.push(t.shaderID):(n.push(t.customVertexShaderID),n.push(t.customFragmentShaderID)),t.defines!==void 0)for(let e in t.defines)n.push(e),n.push(t.defines[e]);return t.isRawShaderMaterial===!1&&(g(n,t),_(n,t),n.push(e.outputColorSpace)),n.push(t.customProgramCacheKey),n.join()}function g(e,t){e.push(t.precision),e.push(t.outputColorSpace),e.push(t.envMapMode),e.push(t.envMapPMREM),e.push(t.envMapMaxLod),e.push(t.envMapSize),e.push(t.mapUv),e.push(t.alphaMapUv),e.push(t.lightMapUv),e.push(t.aoMapUv),e.push(t.bumpMapUv),e.push(t.normalMapUv),e.push(t.displacementMapUv),e.push(t.emissiveMapUv),e.push(t.metalnessMapUv),e.push(t.roughnessMapUv),e.push(t.anisotropyMapUv),e.push(t.clearcoatMapUv),e.push(t.clearcoatNormalMapUv),e.push(t.clearcoatRoughnessMapUv),e.push(t.diffuseRoughnessMapUv),e.push(t.iridescenceMapUv),e.push(t.iridescenceThicknessMapUv),e.push(t.sheenColorMapUv),e.push(t.sheenRoughnessMapUv),e.push(t.specularMapUv),e.push(t.specularColorMapUv),e.push(t.specularIntensityMapUv),e.push(t.transmissionMapUv),e.push(t.thicknessMapUv),e.push(t.combine),e.push(t.fogExp2),e.push(t.sizeAttenuation),e.push(t.morphTargetsCount),e.push(t.numSunLights),e.push(t.numDirLights),e.push(t.numPointLights),e.push(t.numSpotLights),e.push(t.numSpotLightMaps),e.push(t.numHemiLights),e.push(t.numRectAreaLights),e.push(t.numSunLightShadows),e.push(t.numDirLightShadows),e.push(t.numPointLightShadows),e.push(t.numSpotLightShadows),e.push(t.numSpotLightShadowsWithMaps),e.push(t.numLightProbes),e.push(t.numLightProbeGrids),e.push(t.shadowMapType),e.push(t.toneMapping),e.push(t.numClippingPlanes),e.push(t.numClipIntersection),e.push(t.depthPacking)}function _(e,t){o.disableAll(),t.instancing&&o.enable(0),t.instancingColor&&o.enable(1),t.instancingMorph&&o.enable(2),t.matcap&&o.enable(3),t.envMap&&o.enable(4),t.normalMapObjectSpace&&o.enable(5),t.normalMapTangentSpace&&o.enable(6),t.clearcoat&&o.enable(7),t.iridescence&&o.enable(8),t.alphaTest&&o.enable(9),t.vertexColors&&o.enable(10),t.vertexAlphas&&o.enable(11),t.vertexUv1s&&o.enable(12),t.vertexUv2s&&o.enable(13),t.vertexUv3s&&o.enable(14),t.vertexTangents&&o.enable(15),t.anisotropy&&o.enable(16),t.alphaHash&&o.enable(17),t.batching&&o.enable(18),t.dispersion&&o.enable(19),t.retroreflection&&o.enable(24),t.diffuseRoughness&&o.enable(25),t.batchingColor&&o.enable(20),t.gradientMap&&o.enable(21),t.packedNormalMap&&o.enable(22),t.vertexNormals&&o.enable(23),e.push(o.mask),o.disableAll(),t.fog&&o.enable(0),t.useFog&&o.enable(1),t.flatShading&&o.enable(2),t.logarithmicDepthBuffer&&o.enable(3),t.reversedDepthBuffer&&o.enable(4),t.skinning&&o.enable(5),t.morphTargets&&o.enable(6),t.morphNormals&&o.enable(7),t.morphColors&&o.enable(8),t.premultipliedAlpha&&o.enable(9),t.shadowMapEnabled&&o.enable(10),t.doubleSided&&o.enable(11),t.flipSided&&o.enable(12),t.useDepthPacking&&o.enable(13),t.dithering&&o.enable(14),t.transmission&&o.enable(15),t.sheen&&o.enable(16),t.opaque&&o.enable(17),t.pointsUvs&&o.enable(18),t.decodeVideoTexture&&o.enable(19),t.decodeVideoTextureEmissive&&o.enable(20),t.alphaToCoverage&&o.enable(21),t.numLightProbeGrids>0&&o.enable(22),t.hasPositionAttribute&&o.enable(23),e.push(o.mask)}function v(e){let t=f[e.type],n;if(t){let e=kt[t];n=x.clone(e.uniforms)}else n=e.uniforms;return n}function y(t,n){let r=u.get(n);return r===void 0?(r=new Zr(e,n,t,i),l.push(r),u.set(n,r)):++r.usedTimes,r}function b(e){if(--e.usedTimes===0){let t=l.indexOf(e);l[t]=l[l.length-1],l.pop(),u.delete(e.cacheKey),e.destroy()}}function S(e){s.remove(e)}function w(){s.dispose()}return{getParameters:m,getProgramCacheKey:h,getUniforms:v,acquireProgram:y,releaseProgram:b,releaseShaderCache:S,programs:l,dispose:w}}function ri(){let e=new WeakMap;function t(t){return e.has(t)}function n(t){let n=e.get(t);return n===void 0&&(n={},e.set(t,n)),n}function r(t){e.delete(t)}function i(t,n,r){e.get(t)[n]=r}function a(){e=new WeakMap}return{has:t,get:n,remove:r,update:i,dispose:a}}function ii(e,t){return e.groupOrder===t.groupOrder?e.renderOrder===t.renderOrder?e.material.id===t.material.id?e.materialVariant===t.materialVariant?e.z===t.z?e.id-t.id:e.z-t.z:e.materialVariant-t.materialVariant:e.material.id-t.material.id:e.renderOrder-t.renderOrder:e.groupOrder-t.groupOrder}function ai(e,t){return e.groupOrder===t.groupOrder?e.renderOrder===t.renderOrder?e.z===t.z?e.id-t.id:t.z-e.z:e.renderOrder-t.renderOrder:e.groupOrder-t.groupOrder}function oi(){let e=[],t=0,n=[],r=[],i=[];function a(){t=0,n.length=0,r.length=0,i.length=0}function o(e){let t=0;return e.isInstancedMesh&&(t+=2),e.isSkinnedMesh&&(t+=1),t}function s(n,r,i,a,s,c){let l=e[t];return l===void 0?(l={id:n.id,object:n,geometry:r,material:i,materialVariant:o(n),groupOrder:a,renderOrder:n.renderOrder,z:s,group:c},e[t]=l):(l.id=n.id,l.object=n,l.geometry=r,l.material=i,l.materialVariant=o(n),l.groupOrder=a,l.renderOrder=n.renderOrder,l.z=s,l.group=c),t++,l}function c(e,t,a,o,c,l,u){u.reversedDepth===!0&&(c=-c);let d=s(e,t,a,o,c,l);a.transmission>0?r.push(d):a.transparent===!0?i.push(d):n.push(d)}function l(e,t,a,o,c,l){let u=s(e,t,a,o,c,l);a.transmission>0?r.unshift(u):a.transparent===!0?i.unshift(u):n.unshift(u)}function u(e,t){n.length>1&&n.sort(e||ii),r.length>1&&r.sort(t||ai),i.length>1&&i.sort(t||ai)}function d(){for(let n=t,r=e.length;n<r;n++){let t=e[n];if(t.id===null)break;t.id=null,t.object=null,t.geometry=null,t.material=null,t.group=null}}return{opaque:n,transmissive:r,transparent:i,init:a,push:c,unshift:l,finish:d,sort:u}}function si(){let e=new WeakMap;function t(t,n){let r=e.get(t),i;return r===void 0?(i=new oi,e.set(t,[i])):n>=r.length?(i=new oi,r.push(i)):i=r[n],i}function n(){e=new WeakMap}return{get:t,dispose:n}}function ci(){let e={};return{get:function(t){if(e[t.id]!==void 0)return e[t.id];let n;switch(t.type){case`SunLight`:case`DirectionalLight`:n={direction:new w,color:new K};break;case`SpotLight`:n={position:new w,direction:new w,color:new K,distance:0,coneCos:0,penumbraCos:0,decay:0};break;case`PointLight`:n={position:new w,color:new K,distance:0,decay:0};break;case`HemisphereLight`:n={direction:new w,skyColor:new K,groundColor:new K};break;case`RectAreaLight`:n={color:new K,position:new w,halfWidth:new w,halfHeight:new w}}return e[t.id]=n,n}}}function li(){let e={};return{get:function(t){if(e[t.id]!==void 0)return e[t.id];let n;switch(t.type){case`SunLight`:case`DirectionalLight`:n={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new ve};break;case`SpotLight`:n={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new ve};break;case`PointLight`:n={shadowIntensity:1,shadowBias:0,shadowNormalBias:0,shadowRadius:1,shadowMapSize:new ve,shadowCameraNear:1,shadowCameraFar:1e3}}return e[t.id]=n,n}}}var ui=0;function di(e,t){return(t.castShadow?2:0)-(e.castShadow?2:0)+ +!!t.map-!!e.map}function fi(e){let t=new ci,n=li(),r={version:0,hash:{sunLength:-1,directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numSunShadows:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1,numSpotMaps:-1,numLightProbes:-1},ambient:[0,0,0],probe:[],sun:[],sunShadow:[],sunShadowMap:[],sunShadowMatrix:[],sunShadowCascade:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotLightMap:[],spotShadow:[],spotShadowMap:[],spotLightMatrix:[],rectArea:[],rectAreaLTC1:null,rectAreaLTC2:null,point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[],numSpotLightShadowsWithMaps:0,numLightProbes:0};for(let e=0;e<9;e++)r.probe.push(new w);let i=new w,a=new nt,o=new nt;function s(i){let a=0,o=0,s=0;for(let e=0;e<9;e++)r.probe[e].set(0,0,0);let c=0,l=0,u=0,d=0,f=0,p=0,m=0,h=0,g=0,_=0,v=0,y=0,b=0,x=0;i.sort(di);for(let e=0,S=i.length;e<S;e++){let S=i[e],C=S.color,w=S.intensity,T=S.distance,E=null;if(S.shadow&&S.shadow.map&&(E=S.shadow.map.texture.format===1030?S.shadow.map.texture:S.shadow.map.depthTexture||S.shadow.map.texture),S.isAmbientLight)a+=C.r*w,o+=C.g*w,s+=C.b*w;else if(S.isLightProbe){for(let e=0;e<9;e++)r.probe[e].addScaledVector(S.sh.coefficients[e],w);x++}else if(S.isSunLight){let e=t.get(S);if(e.color.copy(S.color).multiplyScalar(S.intensity),S.castShadow){let e=S.shadow,t=n.get(S);t.shadowIntensity=e.intensity,t.shadowBias=e.bias,t.shadowNormalBias=e.normalBias,t.shadowRadius=e.radius,t.shadowMapSize.copy(e.mapSize).multiply(e.getFrameExtents()),r.sunShadow[l]=t,r.sunShadowMap[l]=E;let i=e.getViewportCount();for(let t=0;t<i;t++)r.sunShadowMatrix[u+t]=e.getMatrix(t),r.sunShadowCascade[u+t]=e._cascadeData[t];u+=i,l++}r.sun[c]=e,c++}else if(S.isDirectionalLight){let e=t.get(S);if(e.color.copy(S.color).multiplyScalar(S.intensity),S.castShadow){let e=S.shadow,t=n.get(S);t.shadowIntensity=e.intensity,t.shadowBias=e.bias,t.shadowNormalBias=e.normalBias,t.shadowRadius=e.radius,t.shadowMapSize=e.mapSize,r.directionalShadow[d]=t,r.directionalShadowMap[d]=E,r.directionalShadowMatrix[d]=S.shadow.matrix,g++}r.directional[d]=e,d++}else if(S.isSpotLight){let e=t.get(S);e.position.setFromMatrixPosition(S.matrixWorld),e.color.copy(C).multiplyScalar(w),e.distance=T,e.coneCos=Math.cos(S.angle),e.penumbraCos=Math.cos(S.angle*(1-S.penumbra)),e.decay=S.decay,r.spot[p]=e;let i=S.shadow;if(S.map&&(r.spotLightMap[y]=S.map,y++,i.updateMatrices(S),S.castShadow&&b++),r.spotLightMatrix[p]=i.matrix,S.castShadow){let e=n.get(S);e.shadowIntensity=i.intensity,e.shadowBias=i.bias,e.shadowNormalBias=i.normalBias,e.shadowRadius=i.radius,e.shadowMapSize=i.mapSize,r.spotShadow[p]=e,r.spotShadowMap[p]=E,v++}p++}else if(S.isRectAreaLight){let e=t.get(S);e.color.copy(C).multiplyScalar(w),e.halfWidth.set(S.width*.5,0,0),e.halfHeight.set(0,S.height*.5,0),r.rectArea[m]=e,m++}else if(S.isPointLight){let e=t.get(S);if(e.color.copy(S.color).multiplyScalar(S.intensity),e.distance=S.distance,e.decay=S.decay,S.castShadow){let e=S.shadow,t=n.get(S);t.shadowIntensity=e.intensity,t.shadowBias=e.bias,t.shadowNormalBias=e.normalBias,t.shadowRadius=e.radius,t.shadowMapSize=e.mapSize,t.shadowCameraNear=e.camera.near,t.shadowCameraFar=e.camera.far,r.pointShadow[f]=t,r.pointShadowMap[f]=E,r.pointShadowMatrix[f]=S.shadow.matrix,_++}r.point[f]=e,f++}else if(S.isHemisphereLight){let e=t.get(S);e.skyColor.copy(S.color).multiplyScalar(w),e.groundColor.copy(S.groundColor).multiplyScalar(w),r.hemi[h]=e,h++}}m>0&&(e.has(`OES_texture_float_linear`)===!0?(r.rectAreaLTC1=Q.LTC_FLOAT_1,r.rectAreaLTC2=Q.LTC_FLOAT_2):(r.rectAreaLTC1=Q.LTC_HALF_1,r.rectAreaLTC2=Q.LTC_HALF_2)),r.ambient[0]=a,r.ambient[1]=o,r.ambient[2]=s;let S=r.hash;(S.sunLength!==c||S.directionalLength!==d||S.pointLength!==f||S.spotLength!==p||S.rectAreaLength!==m||S.hemiLength!==h||S.numSunShadows!==l||S.numDirectionalShadows!==g||S.numPointShadows!==_||S.numSpotShadows!==v||S.numSpotMaps!==y||S.numLightProbes!==x)&&(r.sun.length=c,r.directional.length=d,r.spot.length=p,r.rectArea.length=m,r.point.length=f,r.hemi.length=h,r.sunShadow.length=l,r.sunShadowMap.length=l,r.sunShadowMatrix.length=u,r.sunShadowCascade.length=u,r.directionalShadow.length=g,r.directionalShadowMap.length=g,r.directionalShadowMatrix.length=g,r.pointShadow.length=_,r.pointShadowMap.length=_,r.pointShadowMatrix.length=_,r.spotShadow.length=v,r.spotShadowMap.length=v,r.spotLightMatrix.length=v+y-b,r.spotLightMap.length=y,r.numSpotLightShadowsWithMaps=b,r.numLightProbes=x,S.sunLength=c,S.directionalLength=d,S.pointLength=f,S.spotLength=p,S.rectAreaLength=m,S.hemiLength=h,S.numSunShadows=l,S.numDirectionalShadows=g,S.numPointShadows=_,S.numSpotShadows=v,S.numSpotMaps=y,S.numLightProbes=x,r.version=ui++)}function c(e,t){let n=0,s=0,c=0,l=0,u=0,d=0,f=t.matrixWorldInverse;for(let t=0,p=e.length;t<p;t++){let p=e[t];if(p.isSunLight){let e=r.sun[n];e.direction.setFromMatrixPosition(p.matrixWorld),e.direction.transformDirection(f),n++}else if(p.isDirectionalLight){let e=r.directional[s];e.direction.setFromMatrixPosition(p.matrixWorld),i.setFromMatrixPosition(p.target.matrixWorld),e.direction.sub(i),e.direction.transformDirection(f),s++}else if(p.isSpotLight){let e=r.spot[l];e.position.setFromMatrixPosition(p.matrixWorld),e.position.applyMatrix4(f),e.direction.setFromMatrixPosition(p.matrixWorld),i.setFromMatrixPosition(p.target.matrixWorld),e.direction.sub(i),e.direction.transformDirection(f),l++}else if(p.isRectAreaLight){let e=r.rectArea[u];e.position.setFromMatrixPosition(p.matrixWorld),e.position.applyMatrix4(f),o.identity(),a.copy(p.matrixWorld),a.premultiply(f),o.extractRotation(a),e.halfWidth.set(p.width*.5,0,0),e.halfHeight.set(0,p.height*.5,0),e.halfWidth.applyMatrix4(o),e.halfHeight.applyMatrix4(o),u++}else if(p.isPointLight){let e=r.point[c];e.position.setFromMatrixPosition(p.matrixWorld),e.position.applyMatrix4(f),c++}else if(p.isHemisphereLight){let e=r.hemi[d];e.direction.setFromMatrixPosition(p.matrixWorld),e.direction.transformDirection(f),d++}}}return{setup:s,setupView:c,state:r}}function pi(e){let t=new fi(e),n=[],r=[],i=[];function a(e){u.camera=e,n.length=0,r.length=0,i.length=0}function o(e){e.isLightProbeGrid?i.push(e):n.push(e)}function s(e){r.push(e)}function c(){t.setup(n),i.sort((e,t)=>e.priority-t.priority||e.id-t.id)}function l(e){t.setupView(n,e)}let u={lightsArray:n,shadowsArray:r,lightProbeGridArray:i,camera:null,lights:t,transmissionRenderTarget:{},textureUnits:0};return{init:a,state:u,setupLights:c,setupLightsView:l,pushLight:o,pushShadow:s}}function mi(e){let t=new WeakMap;function n(n,r=0){let i=t.get(n),a;return i===void 0?(a=new pi(e),t.set(n,[a])):r>=i.length?(a=new pi(e),i.push(a)):a=i[r],a}function r(){t=new WeakMap}return{get:n,dispose:r}}var hi=`void main() {
4171
+ gl_Position = vec4( position, 1.0 );
4172
+ }`,gi=`uniform sampler2D shadow_pass;
4173
+ uniform vec2 resolution;
4174
+ uniform float radius;
4175
+ void main() {
4176
+ const float samples = float( VSM_SAMPLES );
4177
+ float mean = 0.0;
4178
+ float squared_mean = 0.0;
4179
+ float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );
4180
+ float uvStart = samples <= 1.0 ? 0.0 : - 1.0;
4181
+ for ( float i = 0.0; i < samples; i ++ ) {
4182
+ float uvOffset = uvStart + i * uvStride;
4183
+ #ifdef HORIZONTAL_PASS
4184
+ vec2 distribution = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ).rg;
4185
+ mean += distribution.x;
4186
+ squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;
4187
+ #else
4188
+ float depth = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ).r;
4189
+ mean += depth;
4190
+ squared_mean += depth * depth;
4191
+ #endif
4192
+ }
4193
+ mean = mean / samples;
4194
+ squared_mean = squared_mean / samples;
4195
+ float std_dev = sqrt( max( 0.0, squared_mean - mean * mean ) );
4196
+ gl_FragColor = vec4( mean, std_dev, 0.0, 1.0 );
4197
+ }`,_i=[new w(1,0,0),new w(-1,0,0),new w(0,1,0),new w(0,-1,0),new w(0,0,1),new w(0,0,-1)],vi=[new w(0,-1,0),new w(0,-1,0),new w(0,0,1),new w(0,0,-1),new w(0,-1,0),new w(0,-1,0)],yi=new nt,bi=new w,xi=new w;function Si(e,t,n){let r=new s,i=new ve,a=new ve,o=new M,c=new Je,l=new ht,u={},f=n.maxTextureSize,p={0:1,1:0,2:2},m=new de({defines:{VSM_SAMPLES:8},uniforms:{shadow_pass:{value:null},resolution:{value:new ve},radius:{value:4}},vertexShader:hi,fragmentShader:gi}),h=m.clone();h.defines.HORIZONTAL_PASS=1;let g=new je;g.setAttribute(`position`,new ut(new Float32Array([-1,-1,.5,3,-1,.5,-1,3,.5]),3));let _=new dt(g,m),v=this;this.enabled=!1,this.autoUpdate=!0,this.needsUpdate=!1,this.type=1;let y=this.type;this.render=function(t,n,s){if(v.enabled===!1||v.autoUpdate===!1&&v.needsUpdate===!1||t.length===0)return;this.type===2&&(X(`WebGLShadowMap: PCFSoftShadowMap has been removed. Using PCFShadowMap instead.`),this.type=1);let c=e.getRenderTarget(),l=e.getActiveCubeFace(),u=e.getActiveMipmapLevel(),p=e.state;p.setBlending(0),p.buffers.depth.getReversed()===!0?p.buffers.color.setClear(0,0,0,0):p.buffers.color.setClear(1,1,1,1),p.buffers.depth.setTest(!0),p.setScissorTest(!1);let m=y!==this.type;m&&n.traverse(function(e){e.material&&(Array.isArray(e.material)?e.material.forEach(e=>e.needsUpdate=!0):e.material.needsUpdate=!0)});for(let c=0,l=t.length;c<l;c++){let l=t[c],u=l.shadow;if(u===void 0){X(`WebGLShadowMap:`,l,`has no shadow.`);continue}if(u.autoUpdate===!1&&u.needsUpdate===!1)continue;i.copy(u.mapSize);let h=u.getFrameExtents();i.multiply(h),a.copy(u.mapSize),(i.x>f||i.y>f)&&(i.x>f&&(a.x=Math.floor(f/h.x),i.x=a.x*h.x,u.mapSize.x=a.x),i.y>f&&(a.y=Math.floor(f/h.y),i.y=a.y*h.y,u.mapSize.y=a.y));let g=e.state.buffers.depth.getReversed();if(u.camera._reversedDepth=g,u.map===null||m===!0){if(u.map!==null&&(u.map.depthTexture!==null&&(u.map.depthTexture.dispose(),u.map.depthTexture=null),u.map.dispose()),this.type===3){if(l.isPointLight){X(`WebGLShadowMap: VSM shadow maps are not supported for PointLights. Use PCF or BasicShadowMap instead.`);continue}u.map=new Se(i.x,i.y,{format:Pe,type:ne,minFilter:ye,magFilter:ye,generateMipmaps:!1}),u.map.texture.name=l.name+`.shadowMap`,u.map.depthTexture=new z(i.x,i.y,Ke),u.map.depthTexture.name=l.name+`.shadowMapDepth`,u.map.depthTexture.format=ke,u.map.depthTexture.compareFunction=null,u.map.depthTexture.minFilter=Xe,u.map.depthTexture.magFilter=Xe}else l.isPointLight?(u.map=new Rt(i.x),u.map.depthTexture=new Re(i.x,d)):(u.map=new Se(i.x,i.y),u.map.depthTexture=new z(i.x,i.y,d)),u.map.depthTexture.name=l.name+`.shadowMap`,u.map.depthTexture.format=ke,this.type===1?(u.map.depthTexture.compareFunction=g?518:515,u.map.depthTexture.minFilter=ye,u.map.depthTexture.magFilter=ye):(u.map.depthTexture.compareFunction=null,u.map.depthTexture.minFilter=Xe,u.map.depthTexture.magFilter=Xe);u.camera.updateProjectionMatrix()}u.map.isWebGLCubeRenderTarget!==!0&&(u.map.width!==i.x||u.map.height!==i.y)&&u.map.setSize(i.x,i.y);let _=u.map.isWebGLCubeRenderTarget?6:u.getViewportCount();l.isPointLight!==!0&&u.updateMatrices(l,s);let v=u.camera.layers.mask&4294967294?u.camera.layers:s.layers;for(let t=0;t<_;t++){let i=u.getCamera(t);if(l.isPointLight){let e=u.camera,n=u.matrix,r=l.distance||e.far;r!==e.far&&(e.far=r,e.updateProjectionMatrix()),bi.setFromMatrixPosition(l.matrixWorld),e.position.copy(bi),xi.copy(e.position),xi.add(_i[t]),e.up.copy(vi[t]),e.lookAt(xi),e.updateMatrixWorld(),n.makeTranslation(-bi.x,-bi.y,-bi.z),yi.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),u._frustum.setFromProjectionMatrix(yi,e.coordinateSystem,e.reversedDepth)}if(u.map.isWebGLCubeRenderTarget)e.setRenderTarget(u.map,t),e.clear();else{t===0&&(e.setRenderTarget(u.map),e.clear());let n=u.getViewport(t);o.set(a.x*n.x,a.y*n.y,a.x*n.z,a.y*n.w),p.viewport(o)}r=u.getFrustum(t),S(n,s,i,l,v,this.type)}u.isPointLightShadow!==!0&&this.type===3&&b(u,s),u.needsUpdate=!1}y=this.type,v.needsUpdate=!1,e.setRenderTarget(c,l,u)};function b(n,r){let a=t.update(_);m.defines.VSM_SAMPLES!==n.blurSamples&&(m.defines.VSM_SAMPLES=n.blurSamples,h.defines.VSM_SAMPLES=n.blurSamples,m.needsUpdate=!0,h.needsUpdate=!0),n.mapPass===null?n.mapPass=new Se(i.x,i.y,{format:Pe,type:ne}):(n.mapPass.width!==n.map.width||n.mapPass.height!==n.map.height)&&n.mapPass.setSize(n.map.width,n.map.height),m.uniforms.shadow_pass.value=n.map.depthTexture,m.uniforms.resolution.value.set(n.map.width,n.map.height),m.uniforms.radius.value=n.radius,e.setRenderTarget(n.mapPass),e.clear(),e.renderBufferDirect(r,null,a,m,_,null),h.uniforms.shadow_pass.value=n.mapPass.texture,h.uniforms.resolution.value.set(n.map.width,n.map.height),h.uniforms.radius.value=n.radius,e.setRenderTarget(n.map),e.clear(),e.renderBufferDirect(r,null,a,h,_,null)}function x(t,n,r,i){let a=null,o=r.isPointLight===!0?t.customDistanceMaterial:t.customDepthMaterial;if(o!==void 0)a=o;else if(a=r.isPointLight===!0?l:c,e.localClippingEnabled&&n.clipShadows===!0&&Array.isArray(n.clippingPlanes)&&n.clippingPlanes.length!==0||n.displacementMap&&n.displacementScale!==0||n.alphaMap&&n.alphaTest>0||n.map&&n.alphaTest>0||n.alphaToCoverage===!0){let e=a.uuid,t=n.uuid,r=u[e];r===void 0&&(r={},u[e]=r);let i=r[t];i===void 0&&(i=a.clone(),r[t]=i,n.addEventListener(`dispose`,C)),a=i}if(a.visible=n.visible,a.wireframe=n.wireframe,i===3?a.side=n.shadowSide===null?n.side:n.shadowSide:a.side=n.shadowSide===null?p[n.side]:n.shadowSide,a.alphaMap=n.alphaMap,a.alphaTest=n.alphaToCoverage===!0?.5:n.alphaTest,a.map=n.map,a.clipShadows=n.clipShadows,a.clippingPlanes=n.clippingPlanes,a.clipIntersection=n.clipIntersection,a.displacementMap=n.displacementMap,a.displacementScale=n.displacementScale,a.displacementBias=n.displacementBias,a.wireframeLinewidth=n.wireframeLinewidth,a.linewidth=n.linewidth,r.isPointLight===!0&&a.isMeshDistanceMaterial===!0){let t=e.properties.get(a);t.light=r}return a}function S(n,i,a,o,s,c){if(n.visible===!1)return;if(n.layers.test(s)&&(n.isMesh||n.isLine||n.isPoints)&&(n.castShadow||n.receiveShadow&&c===3)&&(!n.frustumCulled||n.intersectsFrustum(r))){n.modelViewMatrix.multiplyMatrices(a.matrixWorldInverse,n.matrixWorld);let r=t.update(n),s=n.material;if(Array.isArray(s)){let t=r.groups;for(let l=0,u=t.length;l<u;l++){let u=t[l],d=s[u.materialIndex];if(d&&d.visible){let t=x(n,d,o,c);n.onBeforeShadow(e,n,i,a,r,t,u),e.renderBufferDirect(a,null,r,t,n,u),n.onAfterShadow(e,n,i,a,r,t,u)}}}else if(s.visible){let t=x(n,s,o,c);n.onBeforeShadow(e,n,i,a,r,t,null),e.renderBufferDirect(a,null,r,t,n,null),n.onAfterShadow(e,n,i,a,r,t,null)}}let l=n.children;for(let e=0,t=l.length;e<t;e++)S(l[e],i,a,o,s,c)}function C(e){e.target.removeEventListener(`dispose`,C);for(let t in u){let n=u[t],r=e.target.uuid;r in n&&(n[r].dispose(),delete n[r])}}}function Ci(e,t){function n(){let t=!1,n=new M,r=null,i=new M(0,0,0,0);return{setMask:function(n){r!==n&&!t&&(e.colorMask(n,n,n,n),r=n)},setLocked:function(e){t=e},setClear:function(t,r,a,o,s){s===!0&&(t*=o,r*=o,a*=o),n.set(t,r,a,o),i.equals(n)===!1&&(e.clearColor(t,r,a,o),i.copy(n))},reset:function(){t=!1,r=null,i.set(-1,0,0,0)}}}function r(){let n=!1,r=!1,i=null,a=null,o=null;return{setReversed:function(e){if(r!==e){let n=t.get(`EXT_clip_control`);e?n.clipControlEXT(n.LOWER_LEFT_EXT,n.ZERO_TO_ONE_EXT):n.clipControlEXT(n.LOWER_LEFT_EXT,n.NEGATIVE_ONE_TO_ONE_EXT),r=e;let i=o;o=null,this.setClear(i)}},getReversed:function(){return r},setTest:function(t){t?oe(e.DEPTH_TEST):se(e.DEPTH_TEST)},setMask:function(t){i!==t&&!n&&(e.depthMask(t),i=t)},setFunc:function(t){if(r&&(t=Ee[t]),a!==t){switch(t){case 0:e.depthFunc(e.NEVER);break;case 1:e.depthFunc(e.ALWAYS);break;case 2:e.depthFunc(e.LESS);break;case 3:e.depthFunc(e.LEQUAL);break;case 4:e.depthFunc(e.EQUAL);break;case 5:e.depthFunc(e.GEQUAL);break;case 6:e.depthFunc(e.GREATER);break;case 7:e.depthFunc(e.NOTEQUAL);break;default:e.depthFunc(e.LEQUAL)}a=t}},setLocked:function(e){n=e},setClear:function(t){o!==t&&(o=t,r&&(t=1-t),e.clearDepth(t))},reset:function(){n=!1,i=null,a=null,o=null,r=!1}}}function i(){let t=!1,n=null,r=null,i=null,a=null,o=null,s=null,c=null,l=null;return{setTest:function(n){t||(n?oe(e.STENCIL_TEST):se(e.STENCIL_TEST))},setMask:function(r){n!==r&&!t&&(e.stencilMask(r),n=r)},setFunc:function(t,n,o){(r!==t||i!==n||a!==o)&&(e.stencilFunc(t,n,o),r=t,i=n,a=o)},setOp:function(t,n,r){(o!==t||s!==n||c!==r)&&(e.stencilOp(t,n,r),o=t,s=n,c=r)},setLocked:function(e){t=e},setClear:function(t){l!==t&&(e.clearStencil(t),l=t)},reset:function(){t=!1,n=null,r=null,i=null,a=null,o=null,s=null,c=null,l=null}}}let a=new n,o=new r,s=new i,c={},l=new WeakMap,u={},d={},f={},p=new WeakMap,m=[],h=null,g=!1,_=null,v=null,y=null,b=null,x=null,S=null,C=null,w=new K(0,0,0),T=0,E=!1,D=null,O=null,k=null,A=null,j=null,N=e.getParameter(e.MAX_COMBINED_TEXTURE_IMAGE_UNITS),P=!1,F=0,I=e.getParameter(e.VERSION);I.indexOf(`WebGL`)===-1?I.indexOf(`OpenGL ES`)!==-1&&(F=parseFloat(/^OpenGL ES (\d)/.exec(I)[1]),P=F>=2):(F=parseFloat(/^WebGL (\d)/.exec(I)[1]),P=F>=1);let L=null,ee={},te=e.getParameter(e.SCISSOR_BOX),ne=e.getParameter(e.VIEWPORT),re=new M().fromArray(te),R=new M().fromArray(ne);function ie(t,n,r,i){let a=new Uint8Array(4),o=e.createTexture();e.bindTexture(t,o),e.texParameteri(t,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(t,e.TEXTURE_MAG_FILTER,e.NEAREST);for(let o=0;o<r;o++)t===e.TEXTURE_3D||t===e.TEXTURE_2D_ARRAY?e.texImage3D(n,0,e.RGBA,1,1,i,0,e.RGBA,e.UNSIGNED_BYTE,a):e.texImage2D(n+o,0,e.RGBA,1,1,0,e.RGBA,e.UNSIGNED_BYTE,a);return o}let ae={};ae[e.TEXTURE_2D]=ie(e.TEXTURE_2D,e.TEXTURE_2D,1),ae[e.TEXTURE_CUBE_MAP]=ie(e.TEXTURE_CUBE_MAP,e.TEXTURE_CUBE_MAP_POSITIVE_X,6),ae[e.TEXTURE_2D_ARRAY]=ie(e.TEXTURE_2D_ARRAY,e.TEXTURE_2D_ARRAY,1,1),ae[e.TEXTURE_3D]=ie(e.TEXTURE_3D,e.TEXTURE_3D,1,1),a.setClear(0,0,0,1),o.setClear(1),s.setClear(0),oe(e.DEPTH_TEST),o.setFunc(3),me(!1),he(1),oe(e.CULL_FACE),fe(0);function oe(t){u[t]!==!0&&(e.enable(t),u[t]=!0)}function se(t){u[t]!==!1&&(e.disable(t),u[t]=!1)}function z(t,n){return f[t]!==n&&(e.bindFramebuffer(t,n),f[t]=n,t===e.DRAW_FRAMEBUFFER&&(f[e.FRAMEBUFFER]=n),t===e.FRAMEBUFFER&&(f[e.DRAW_FRAMEBUFFER]=n),!0)}function ce(t,n){let r=m,i=!1;if(t){r=p.get(n),r===void 0&&(r=[],p.set(n,r));let a=t.textures;if(r.length!==a.length||r[0]!==e.COLOR_ATTACHMENT0){for(let t=0,n=a.length;t<n;t++)r[t]=e.COLOR_ATTACHMENT0+t;r.length=a.length,i=!0}}else r[0]!==e.BACK&&(r[0]=e.BACK,i=!0);i&&e.drawBuffers(r)}function le(t){return h!==t&&(e.useProgram(t),h=t,!0)}let ue={100:e.FUNC_ADD,101:e.FUNC_SUBTRACT,102:e.FUNC_REVERSE_SUBTRACT};ue[103]=e.MIN,ue[104]=e.MAX;let de={200:e.ZERO,201:e.ONE,202:e.SRC_COLOR,204:e.SRC_ALPHA,210:e.SRC_ALPHA_SATURATE,208:e.DST_COLOR,206:e.DST_ALPHA,203:e.ONE_MINUS_SRC_COLOR,205:e.ONE_MINUS_SRC_ALPHA,209:e.ONE_MINUS_DST_COLOR,207:e.ONE_MINUS_DST_ALPHA,211:e.CONSTANT_COLOR,212:e.ONE_MINUS_CONSTANT_COLOR,213:e.CONSTANT_ALPHA,214:e.ONE_MINUS_CONSTANT_ALPHA};function fe(t,n,r,i,a,o,s,c,l,u){if(t===0)g===!0&&(se(e.BLEND),g=!1);else if(g===!1&&(oe(e.BLEND),g=!0),t!==5){if(t!==_||u!==E){if((v!==100||x!==100)&&(e.blendEquation(e.FUNC_ADD),v=100,x=100),u)switch(t){case 1:e.blendFuncSeparate(e.ONE,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 2:e.blendFunc(e.ONE,e.ONE);break;case 3:e.blendFuncSeparate(e.ZERO,e.ONE_MINUS_SRC_COLOR,e.ZERO,e.ONE);break;case 4:e.blendFuncSeparate(e.DST_COLOR,e.ONE_MINUS_SRC_ALPHA,e.ZERO,e.ONE);break;default:W(`WebGLState: Invalid blending: `,t)}else switch(t){case 1:e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 2:e.blendFuncSeparate(e.SRC_ALPHA,e.ONE,e.ONE,e.ONE);break;case 3:W(`WebGLState: SubtractiveBlending requires material.premultipliedAlpha = true`);break;case 4:W(`WebGLState: MultiplyBlending requires material.premultipliedAlpha = true`);break;default:W(`WebGLState: Invalid blending: `,t)}y=null,b=null,S=null,C=null,w.set(0,0,0),T=0,_=t,E=u}}else a||=n,o||=r,s||=i,(n!==v||a!==x)&&(e.blendEquationSeparate(ue[n],ue[a]),v=n,x=a),(r!==y||i!==b||o!==S||s!==C)&&(e.blendFuncSeparate(de[r],de[i],de[o],de[s]),y=r,b=i,S=o,C=s),(c.equals(w)===!1||l!==T)&&(e.blendColor(c.r,c.g,c.b,l),w.copy(c),T=l),_=t,E=!1}function pe(t,n){t.side===2?se(e.CULL_FACE):oe(e.CULL_FACE);let r=t.side===1;n&&(r=!r),me(r),t.blending===1&&t.transparent===!1?fe(0):fe(t.blending,t.blendEquation,t.blendSrc,t.blendDst,t.blendEquationAlpha,t.blendSrcAlpha,t.blendDstAlpha,t.blendColor,t.blendAlpha,t.premultipliedAlpha),o.setFunc(t.depthFunc),o.setTest(t.depthTest),o.setMask(t.depthWrite),a.setMask(t.colorWrite);let i=t.stencilWrite;s.setTest(i),i&&(s.setMask(t.stencilWriteMask),s.setFunc(t.stencilFunc,t.stencilRef,t.stencilFuncMask),s.setOp(t.stencilFail,t.stencilZFail,t.stencilZPass)),_e(t.polygonOffset,t.polygonOffsetFactor,t.polygonOffsetUnits),t.alphaToCoverage===!0?oe(e.SAMPLE_ALPHA_TO_COVERAGE):se(e.SAMPLE_ALPHA_TO_COVERAGE)}function me(t){D!==t&&(t?e.frontFace(e.CW):e.frontFace(e.CCW),D=t)}function he(t){t===0?se(e.CULL_FACE):(oe(e.CULL_FACE),t!==O&&(t===1?e.cullFace(e.BACK):t===2?e.cullFace(e.FRONT):e.cullFace(e.FRONT_AND_BACK))),O=t}function ge(t){t!==k&&(P&&e.lineWidth(t),k=t)}function _e(t,n,r){t?(oe(e.POLYGON_OFFSET_FILL),(A!==n||j!==r)&&(A=n,j=r,o.getReversed()&&(n=-n,r=-r),e.polygonOffset(n,r))):se(e.POLYGON_OFFSET_FILL)}function ve(t){t?oe(e.SCISSOR_TEST):se(e.SCISSOR_TEST)}function ye(t){t===void 0&&(t=e.TEXTURE0+N-1),L!==t&&(e.activeTexture(t),L=t)}function be(t,n,r){r===void 0&&(r=L===null?e.TEXTURE0+N-1:L);let i=ee[r];i===void 0&&(i={type:void 0,texture:void 0},ee[r]=i),(i.type!==t||i.texture!==n)&&(L!==r&&(e.activeTexture(r),L=r),e.bindTexture(t,n||ae[t]),i.type=t,i.texture=n)}function xe(){let t=ee[L];t!==void 0&&t.type!==void 0&&(e.bindTexture(t.type,null),t.type=void 0,t.texture=void 0)}function Se(){try{e.compressedTexImage2D(...arguments)}catch(e){W(`WebGLState:`,e)}}function Ce(){try{e.compressedTexImage3D(...arguments)}catch(e){W(`WebGLState:`,e)}}function we(){try{e.texSubImage2D(...arguments)}catch(e){W(`WebGLState:`,e)}}function Te(){try{e.texSubImage3D(...arguments)}catch(e){W(`WebGLState:`,e)}}function De(){try{e.compressedTexSubImage2D(...arguments)}catch(e){W(`WebGLState:`,e)}}function Oe(){try{e.compressedTexSubImage3D(...arguments)}catch(e){W(`WebGLState:`,e)}}function B(){try{e.texStorage2D(...arguments)}catch(e){W(`WebGLState:`,e)}}function V(){try{e.texStorage3D(...arguments)}catch(e){W(`WebGLState:`,e)}}function ke(){try{e.texImage2D(...arguments)}catch(e){W(`WebGLState:`,e)}}function Ae(){try{e.texImage3D(...arguments)}catch(e){W(`WebGLState:`,e)}}function je(t){return d[t]===void 0?e.getParameter(t):d[t]}function Me(t,n){d[t]!==n&&(e.pixelStorei(t,n),d[t]=n)}function H(t){re.equals(t)===!1&&(e.scissor(t.x,t.y,t.z,t.w),re.copy(t))}function Ne(t){R.equals(t)===!1&&(e.viewport(t.x,t.y,t.z,t.w),R.copy(t))}function Pe(t,n){let r=l.get(n);r===void 0&&(r=new WeakMap,l.set(n,r));let i=r.get(t);i===void 0&&(i=e.getUniformBlockIndex(n,t.name),e.uniformBlockBinding(n,i,i),r.set(t,i))}function U(t,n,r){let i=l.get(n).get(t);c[i]!==r&&(e.bindBufferBase(e.UNIFORM_BUFFER,i,r),c[i]=r)}function G(){e.disable(e.BLEND),e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.POLYGON_OFFSET_FILL),e.disable(e.SCISSOR_TEST),e.disable(e.STENCIL_TEST),e.disable(e.SAMPLE_ALPHA_TO_COVERAGE),e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ZERO),e.blendFuncSeparate(e.ONE,e.ZERO,e.ONE,e.ZERO),e.blendColor(0,0,0,0),e.colorMask(!0,!0,!0,!0),e.clearColor(0,0,0,0),e.depthMask(!0),e.depthFunc(e.LESS),o.setReversed(!1),e.clearDepth(1),e.stencilMask(4294967295),e.stencilFunc(e.ALWAYS,0,4294967295),e.stencilOp(e.KEEP,e.KEEP,e.KEEP),e.clearStencil(0),e.cullFace(e.BACK),e.frontFace(e.CCW),e.polygonOffset(0,0),e.activeTexture(e.TEXTURE0),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindFramebuffer(e.DRAW_FRAMEBUFFER,null),e.bindFramebuffer(e.READ_FRAMEBUFFER,null),e.useProgram(null),e.lineWidth(1),e.scissor(0,0,e.canvas.width,e.canvas.height),e.viewport(0,0,e.canvas.width,e.canvas.height),e.pixelStorei(e.PACK_ALIGNMENT,4),e.pixelStorei(e.UNPACK_ALIGNMENT,4),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.BROWSER_DEFAULT_WEBGL),e.pixelStorei(e.PACK_ROW_LENGTH,0),e.pixelStorei(e.PACK_SKIP_PIXELS,0),e.pixelStorei(e.PACK_SKIP_ROWS,0),e.pixelStorei(e.UNPACK_ROW_LENGTH,0),e.pixelStorei(e.UNPACK_IMAGE_HEIGHT,0),e.pixelStorei(e.UNPACK_SKIP_PIXELS,0),e.pixelStorei(e.UNPACK_SKIP_ROWS,0),e.pixelStorei(e.UNPACK_SKIP_IMAGES,0),u={},d={},L=null,ee={},f={},c={},p=new WeakMap,m=[],h=null,g=!1,_=null,v=null,y=null,b=null,x=null,S=null,C=null,w=new K(0,0,0),T=0,E=!1,D=null,O=null,k=null,A=null,j=null,re.set(0,0,e.canvas.width,e.canvas.height),R.set(0,0,e.canvas.width,e.canvas.height),a.reset(),o.reset(),s.reset()}return{buffers:{color:a,depth:o,stencil:s},enable:oe,disable:se,bindFramebuffer:z,drawBuffers:ce,useProgram:le,setBlending:fe,setMaterial:pe,setFlipSided:me,setCullFace:he,setLineWidth:ge,setPolygonOffset:_e,setScissorTest:ve,activeTexture:ye,bindTexture:be,unbindTexture:xe,compressedTexImage2D:Se,compressedTexImage3D:Ce,texImage2D:ke,texImage3D:Ae,pixelStorei:Me,getParameter:je,updateUBOMapping:Pe,uniformBlockBinding:U,texStorage2D:B,texStorage3D:V,texSubImage2D:we,texSubImage3D:Te,compressedTexSubImage2D:De,compressedTexSubImage3D:Oe,scissor:H,viewport:Ne,reset:G}}function wi(e,t,n,r,i,a,s){let c=t.has(`WEBGL_multisampled_render_to_texture`)?t.get(`WEBGL_multisampled_render_to_texture`):null,l=typeof navigator>`u`?!1:/OculusBrowser/g.test(navigator.userAgent),u=new ve,d=new WeakMap,f=new Set,p,m=new WeakMap,h=new Set,g=new FinalizationRegistry(e=>h.delete(e)),_=!1;try{_=typeof OffscreenCanvas<`u`&&new OffscreenCanvas(1,1).getContext(`2d`)!==null}catch{}function v(e,t){return _?new OffscreenCanvas(e,t):o(`canvas`)}function y(e,t,n){let r=1,i=Ae(e);if((i.width>n||i.height>n)&&(r=n/Math.max(i.width,i.height)),r<1){if(typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement||typeof HTMLCanvasElement<`u`&&e instanceof HTMLCanvasElement||typeof ImageBitmap<`u`&&e instanceof ImageBitmap||typeof VideoFrame<`u`&&e instanceof VideoFrame){let n=Math.floor(r*i.width),a=Math.floor(r*i.height);p===void 0&&(p=v(n,a));let o=t?v(n,a):p;return o.width=n,o.height=a,o.getContext(`2d`).drawImage(e,0,0,n,a),X(`WebGLRenderer: Texture has been resized from (`+i.width+`x`+i.height+`) to (`+n+`x`+a+`).`),o}return`data`in e&&X(`WebGLRenderer: Image in DataTexture is too big (`+i.width+`x`+i.height+`).`),e}return e}function b(e){return e.generateMipmaps}function x(t){e.generateMipmap(t)}function S(t){return t.isWebGLCubeRenderTarget?e.TEXTURE_CUBE_MAP:t.isWebGL3DRenderTarget?e.TEXTURE_3D:t.isWebGLArrayRenderTarget||t.isCompressedArrayTexture?e.TEXTURE_2D_ARRAY:e.TEXTURE_2D}function C(n,r,i,a,o,s=!1){if(n!==null){if(e[n]!==void 0)return e[n];X(`WebGLRenderer: Attempt to use non-existing WebGL internal format '`+n+`'`)}let c;a&&(c=t.get(`EXT_texture_norm16`),c||X(`WebGLRenderer: Unable to use normalized textures without EXT_texture_norm16 extension`));let l=r;if(r===e.RED&&(i===e.FLOAT&&(l=e.R32F),i===e.HALF_FLOAT&&(l=e.R16F),i===e.UNSIGNED_BYTE&&(l=e.R8),i===e.UNSIGNED_SHORT&&c&&(l=c.R16_EXT),i===e.SHORT&&c&&(l=c.R16_SNORM_EXT)),r===e.RED_INTEGER&&(i===e.UNSIGNED_BYTE&&(l=e.R8UI),i===e.UNSIGNED_SHORT&&(l=e.R16UI),i===e.UNSIGNED_INT&&(l=e.R32UI),i===e.BYTE&&(l=e.R8I),i===e.SHORT&&(l=e.R16I),i===e.INT&&(l=e.R32I)),r===e.RG&&(i===e.FLOAT&&(l=e.RG32F),i===e.HALF_FLOAT&&(l=e.RG16F),i===e.UNSIGNED_BYTE&&(l=e.RG8),i===e.UNSIGNED_SHORT&&c&&(l=c.RG16_EXT),i===e.SHORT&&c&&(l=c.RG16_SNORM_EXT)),r===e.RG_INTEGER&&(i===e.UNSIGNED_BYTE&&(l=e.RG8UI),i===e.UNSIGNED_SHORT&&(l=e.RG16UI),i===e.UNSIGNED_INT&&(l=e.RG32UI),i===e.BYTE&&(l=e.RG8I),i===e.SHORT&&(l=e.RG16I),i===e.INT&&(l=e.RG32I)),r===e.RGB_INTEGER&&(i===e.UNSIGNED_BYTE&&(l=e.RGB8UI),i===e.UNSIGNED_SHORT&&(l=e.RGB16UI),i===e.UNSIGNED_INT&&(l=e.RGB32UI),i===e.BYTE&&(l=e.RGB8I),i===e.SHORT&&(l=e.RGB16I),i===e.INT&&(l=e.RGB32I)),r===e.RGBA_INTEGER&&(i===e.UNSIGNED_BYTE&&(l=e.RGBA8UI),i===e.UNSIGNED_SHORT&&(l=e.RGBA16UI),i===e.UNSIGNED_INT&&(l=e.RGBA32UI),i===e.BYTE&&(l=e.RGBA8I),i===e.SHORT&&(l=e.RGBA16I),i===e.INT&&(l=e.RGBA32I)),r===e.RGB&&(i===e.UNSIGNED_SHORT&&c&&(l=c.RGB16_EXT),i===e.SHORT&&c&&(l=c.RGB16_SNORM_EXT),i===e.UNSIGNED_INT_5_9_9_9_REV&&(l=e.RGB9_E5),i===e.UNSIGNED_INT_10F_11F_11F_REV&&(l=e.R11F_G11F_B10F)),r===e.RGBA){let t=s?G:Y.getTransfer(o);i===e.FLOAT&&(l=e.RGBA32F),i===e.HALF_FLOAT&&(l=e.RGBA16F),i===e.UNSIGNED_BYTE&&(l=t===`srgb`?e.SRGB8_ALPHA8:e.RGBA8),i===e.UNSIGNED_SHORT&&c&&(l=c.RGBA16_EXT),i===e.SHORT&&c&&(l=c.RGBA16_SNORM_EXT),i===e.UNSIGNED_SHORT_4_4_4_4&&(l=e.RGBA4),i===e.UNSIGNED_SHORT_5_5_5_1&&(l=e.RGB5_A1)}return(l===e.R16F||l===e.R32F||l===e.RG16F||l===e.RG32F||l===e.RGBA16F||l===e.RGBA32F)&&t.get(`EXT_color_buffer_float`),l}function w(t,n){let r;return t?n===null||n===1014||n===1020?r=e.DEPTH24_STENCIL8:n===1015?r=e.DEPTH32F_STENCIL8:n===1012&&(r=e.DEPTH24_STENCIL8,X(`DepthTexture: 16 bit depth attachment is not supported with stencil. Using 24-bit attachment.`)):n===null||n===1014||n===1020?r=e.DEPTH_COMPONENT24:n===1015?r=e.DEPTH_COMPONENT32F:n===1012&&(r=e.DEPTH_COMPONENT16),r}function T(e,t){return b(e)===!0||e.isFramebufferTexture&&e.minFilter!==1003&&e.minFilter!==1006?Math.log2(Math.max(t.width,t.height))+1:e.mipmaps.length>0?e.mipmaps.length:e.isCompressedTexture&&Array.isArray(e.image)?t.mipmaps.length:1}function E(e){let t=new WeakRef(e);r.get(e).__ref=t,h.add(t),g.register(e,t,t)}function D(e){let t=r.get(e).__ref;t!==void 0&&(h.delete(t),g.unregister(t))}function O(e){A(e.target)}function k(e){j(e.target)}function A(e){e.removeEventListener(`dispose`,O),D(e),N(e),e.isVideoTexture&&d.delete(e),e.isHTMLTexture&&f.delete(e)}function j(e){e.removeEventListener(`dispose`,k),D(e),F(e)}function M(){for(let e of h){let t=e.deref();t!==void 0&&(t.isRenderTarget===!0?j(t):A(t))}h.clear(),f.clear()}function N(e){let t=r.get(e);if(t.__webglInit===void 0)return;let n=e.source,i=m.get(n);if(i){let r=i[t.__cacheKey];r.usedTimes--,r.usedTimes===0&&P(e),Object.keys(i).length===0&&m.delete(n)}r.remove(e)}function P(t){let n=r.get(t);e.deleteTexture(n.__webglTexture);let i=t.source,a=m.get(i);delete a[n.__cacheKey],s.memory.textures--}function F(t){let n=r.get(t);n.__depthDisposeCallback&&n.__depthDisposeCallback();let i=t.depthTexture;if(i&&i.renderTarget===t&&A(i),t.isWebGLCubeRenderTarget)for(let t=0;t<6;t++){if(Array.isArray(n.__webglFramebuffer[t]))for(let r=0;r<n.__webglFramebuffer[t].length;r++)e.deleteFramebuffer(n.__webglFramebuffer[t][r]);else e.deleteFramebuffer(n.__webglFramebuffer[t]);n.__webglDepthbuffer&&e.deleteRenderbuffer(n.__webglDepthbuffer[t])}else{if(Array.isArray(n.__webglFramebuffer))for(let t=0;t<n.__webglFramebuffer.length;t++)e.deleteFramebuffer(n.__webglFramebuffer[t]);else e.deleteFramebuffer(n.__webglFramebuffer);if(n.__webglDepthbuffer&&e.deleteRenderbuffer(n.__webglDepthbuffer),n.__webglMultisampledFramebuffer&&e.deleteFramebuffer(n.__webglMultisampledFramebuffer),n.__webglColorRenderbuffer)for(let t=0;t<n.__webglColorRenderbuffer.length;t++)n.__webglColorRenderbuffer[t]&&e.deleteRenderbuffer(n.__webglColorRenderbuffer[t]);n.__webglDepthRenderbuffer&&e.deleteRenderbuffer(n.__webglDepthRenderbuffer)}let a=t.textures;for(let t=0,n=a.length;t<n;t++){let n=r.get(a[t]);n.__webglTexture&&(e.deleteTexture(n.__webglTexture),s.memory.textures--),r.remove(a[t])}r.remove(t)}let I=0;function L(){I=0}function ee(){return I}function te(e){I=e}function ne(){let e=I;return e>=i.maxTextures&&X(`WebGLTextures: Trying to use `+(e+1)+` texture units while this GPU supports only `+i.maxTextures),I+=1,e}function re(e){let t=[];return t.push(e.wrapS),t.push(e.wrapT),t.push(e.wrapR||0),t.push(e.magFilter),t.push(e.minFilter),t.push(e.anisotropy),t.push(e.internalFormat),t.push(e.format),t.push(e.type),t.push(e.generateMipmaps),t.push(e.mipmapsAutoUpdate),t.push(e.premultiplyAlpha),t.push(e.flipY),t.push(e.unpackAlignment),t.push(e.colorSpace),t.join()}function R(t,i){let a=r.get(t);if(t.isVideoTexture&&V(t),t.isRenderTargetTexture===!1&&t.isExternalTexture!==!0&&t.version>0&&a.__version!==t.version){let e=t.image;if(e===null)X(`WebGLRenderer: Texture marked for update but no image data found.`);else if(e.complete===!1)X(`WebGLRenderer: Texture marked for update but image is incomplete`);else{me(a,t,i);return}}else t.isExternalTexture&&(a.__webglTexture=t.sourceTexture?t.sourceTexture:null);n.bindTexture(e.TEXTURE_2D,a.__webglTexture,e.TEXTURE0+i)}function ae(t,i){let a=r.get(t);t.isRenderTargetTexture===!1&&t.version>0&&a.__version!==t.version?me(a,t,i):(t.isExternalTexture&&(a.__webglTexture=t.sourceTexture?t.sourceTexture:null),n.bindTexture(e.TEXTURE_2D_ARRAY,a.__webglTexture,e.TEXTURE0+i))}function oe(t,i){let a=r.get(t);t.isRenderTargetTexture===!1&&t.version>0&&a.__version!==t.version?me(a,t,i):n.bindTexture(e.TEXTURE_3D,a.__webglTexture,e.TEXTURE0+i)}function se(t,i){let a=r.get(t);t.version>0&&a.__version!==t.version?he(a,t,i):n.bindTexture(e.TEXTURE_CUBE_MAP,a.__webglTexture,e.TEXTURE0+i)}let z={[J]:e.REPEAT,[Ne]:e.CLAMP_TO_EDGE,[it]:e.MIRRORED_REPEAT},ce={[Xe]:e.NEAREST,[Le]:e.NEAREST_MIPMAP_NEAREST,[Be]:e.NEAREST_MIPMAP_LINEAR,[ye]:e.LINEAR,[ie]:e.LINEAR_MIPMAP_NEAREST,[Ce]:e.LINEAR_MIPMAP_LINEAR},le={512:e.NEVER,519:e.ALWAYS,513:e.LESS,515:e.LEQUAL,514:e.EQUAL,518:e.GEQUAL,516:e.GREATER,517:e.NOTEQUAL};function ue(n,a){if(a.type===1015&&t.has(`OES_texture_float_linear`)===!1&&(a.magFilter===1006||a.magFilter===1007||a.magFilter===1005||a.magFilter===1008||a.minFilter===1006||a.minFilter===1007||a.minFilter===1005||a.minFilter===1008)&&X(`WebGLRenderer: Unable to use linear filtering with floating point textures. OES_texture_float_linear not supported on this device.`),e.texParameteri(n,e.TEXTURE_WRAP_S,z[a.wrapS]),e.texParameteri(n,e.TEXTURE_WRAP_T,z[a.wrapT]),(n===e.TEXTURE_3D||n===e.TEXTURE_2D_ARRAY)&&e.texParameteri(n,e.TEXTURE_WRAP_R,z[a.wrapR]),e.texParameteri(n,e.TEXTURE_MAG_FILTER,ce[a.magFilter]),e.texParameteri(n,e.TEXTURE_MIN_FILTER,ce[a.minFilter]),a.compareFunction&&(e.texParameteri(n,e.TEXTURE_COMPARE_MODE,e.COMPARE_REF_TO_TEXTURE),e.texParameteri(n,e.TEXTURE_COMPARE_FUNC,le[a.compareFunction])),t.has(`EXT_texture_filter_anisotropic`)===!0){if(a.magFilter===1003||a.minFilter!==1005&&a.minFilter!==1008||a.type===1015&&t.has(`OES_texture_float_linear`)===!1)return;if(a.anisotropy>1||r.get(a).__currentAnisotropy){let o=t.get(`EXT_texture_filter_anisotropic`);e.texParameterf(n,o.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(a.anisotropy,i.getMaxAnisotropy())),r.get(a).__currentAnisotropy=a.anisotropy}}}function de(t,n){let r=!1;t.__webglInit===void 0&&(t.__webglInit=!0,n.addEventListener(`dispose`,O),E(n));let i=n.source,a=m.get(i);a===void 0&&(a={},m.set(i,a));let o=re(n);if(o!==t.__cacheKey){a[o]===void 0&&(a[o]={texture:e.createTexture(),usedTimes:0},s.memory.textures++,r=!0),a[o].usedTimes++;let i=a[t.__cacheKey];i!==void 0&&(a[t.__cacheKey].usedTimes--,i.usedTimes===0&&P(n)),t.__cacheKey=o,t.__webglTexture=a[o].texture}return r}function fe(e,t,n){return Math.floor(Math.floor(e/n)/t)}function pe(t,r,i,a){let o=t.updateRanges;if(o.length===0)n.texSubImage2D(e.TEXTURE_2D,0,0,0,r.width,r.height,i,a,r.data);else{o.sort((e,t)=>e.start-t.start);let s=0;for(let e=1;e<o.length;e++){let t=o[s],n=o[e],i=t.start+t.count,a=fe(n.start,r.width,4),c=fe(t.start,r.width,4);n.start<=i+1&&a===c&&fe(n.start+n.count-1,r.width,4)===a?t.count=Math.max(t.count,n.start+n.count-t.start):(++s,o[s]=n)}o.length=s+1;let c=n.getParameter(e.UNPACK_ROW_LENGTH),l=n.getParameter(e.UNPACK_SKIP_PIXELS),u=n.getParameter(e.UNPACK_SKIP_ROWS);n.pixelStorei(e.UNPACK_ROW_LENGTH,r.width);for(let t=0,s=o.length;t<s;t++){let s=o[t],c=Math.floor(s.start/4),l=Math.ceil(s.count/4),u=c%r.width,d=Math.floor(c/r.width),f=l;n.pixelStorei(e.UNPACK_SKIP_PIXELS,u),n.pixelStorei(e.UNPACK_SKIP_ROWS,d),n.texSubImage2D(e.TEXTURE_2D,0,u,d,f,1,i,a,r.data)}t.clearUpdateRanges(),n.pixelStorei(e.UNPACK_ROW_LENGTH,c),n.pixelStorei(e.UNPACK_SKIP_PIXELS,l),n.pixelStorei(e.UNPACK_SKIP_ROWS,u)}}function me(t,o,s){let c=e.TEXTURE_2D;(o.isDataArrayTexture||o.isCompressedArrayTexture)&&(c=e.TEXTURE_2D_ARRAY),o.isData3DTexture&&(c=e.TEXTURE_3D);let l=de(t,o),u=o.source;n.bindTexture(c,t.__webglTexture,e.TEXTURE0+s);let d=r.get(u);if(u.version!==d.__version||l===!0){if(n.activeTexture(e.TEXTURE0+s),!(typeof ImageBitmap<`u`&&o.image instanceof ImageBitmap)){let t=Y.getPrimaries(Y.workingColorSpace),r=o.colorSpace===``?null:Y.getPrimaries(o.colorSpace),i=o.colorSpace===``||t===r?e.NONE:e.BROWSER_DEFAULT_WEBGL;n.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,o.flipY),n.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,o.premultiplyAlpha),n.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,i)}n.pixelStorei(e.UNPACK_ALIGNMENT,o.unpackAlignment);let t=y(o.image,!1,i.maxTextureSize);t=ke(o,t);let r=a.convert(o.format,o.colorSpace),p=a.convert(o.type),m=C(o.internalFormat,r,p,o.normalized,o.colorSpace,o.isVideoTexture);ue(c,o);let h,g=o.mipmaps,_=o.isVideoTexture!==!0,v=d.__version===void 0||l===!0,S=u.dataReady,E=T(o,t);if(o.isDepthTexture)m=w(o.format===xt,o.type),v&&(_?n.texStorage2D(e.TEXTURE_2D,1,m,t.width,t.height):n.texImage2D(e.TEXTURE_2D,0,m,t.width,t.height,0,r,p,null));else if(o.isDataTexture){if(g.length>0){_&&v&&n.texStorage2D(e.TEXTURE_2D,E,m,g[0].width,g[0].height);for(let t=0,i=g.length;t<i;t++)h=g[t],_?S&&n.texSubImage2D(e.TEXTURE_2D,t,0,0,h.width,h.height,r,p,h.data):n.texImage2D(e.TEXTURE_2D,t,m,h.width,h.height,0,r,p,h.data);o.generateMipmaps=!1}else _?(v&&n.texStorage2D(e.TEXTURE_2D,E,m,t.width,t.height),S&&pe(o,t,r,p)):n.texImage2D(e.TEXTURE_2D,0,m,t.width,t.height,0,r,p,t.data)}else if(o.isCompressedTexture){if(o.isCompressedArrayTexture){_&&v&&n.texStorage3D(e.TEXTURE_2D_ARRAY,E,m,g[0].width,g[0].height,t.depth);for(let i=0,a=g.length;i<a;i++)if(h=g[i],o.format!==1023){if(r!==null){if(_){if(S){if(o.layerUpdates.size>0){let t=Qe(h.width,h.height,o.format,o.type);for(let a of o.layerUpdates){let o=h.data.subarray(a*t/h.data.BYTES_PER_ELEMENT,(a+1)*t/h.data.BYTES_PER_ELEMENT);n.compressedTexSubImage3D(e.TEXTURE_2D_ARRAY,i,0,0,a,h.width,h.height,1,r,o)}}else n.compressedTexSubImage3D(e.TEXTURE_2D_ARRAY,i,0,0,0,h.width,h.height,t.depth,r,h.data)}}else n.compressedTexImage3D(e.TEXTURE_2D_ARRAY,i,m,h.width,h.height,t.depth,0,h.data,0,0)}else X(`WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()`)}else _?S&&n.texSubImage3D(e.TEXTURE_2D_ARRAY,i,0,0,0,h.width,h.height,t.depth,r,p,h.data):n.texImage3D(e.TEXTURE_2D_ARRAY,i,m,h.width,h.height,t.depth,0,r,p,h.data);o.layerUpdates.size>0&&o.clearLayerUpdates()}else{_&&v&&n.texStorage2D(e.TEXTURE_2D,E,m,g[0].width,g[0].height);for(let t=0,i=g.length;t<i;t++)h=g[t],o.format===1023?_?S&&n.texSubImage2D(e.TEXTURE_2D,t,0,0,h.width,h.height,r,p,h.data):n.texImage2D(e.TEXTURE_2D,t,m,h.width,h.height,0,r,p,h.data):r===null?X(`WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()`):_?S&&n.compressedTexSubImage2D(e.TEXTURE_2D,t,0,0,h.width,h.height,r,h.data):n.compressedTexImage2D(e.TEXTURE_2D,t,m,h.width,h.height,0,h.data)}}else if(o.isDataArrayTexture){if(_){if(v&&n.texStorage3D(e.TEXTURE_2D_ARRAY,E,m,t.width,t.height,t.depth),S){if(o.layerUpdates.size>0){let i=Qe(t.width,t.height,o.format,o.type);for(let a of o.layerUpdates){let o=t.data.subarray(a*i/t.data.BYTES_PER_ELEMENT,(a+1)*i/t.data.BYTES_PER_ELEMENT);n.texSubImage3D(e.TEXTURE_2D_ARRAY,0,0,0,a,t.width,t.height,1,r,p,o)}o.clearLayerUpdates()}else n.texSubImage3D(e.TEXTURE_2D_ARRAY,0,0,0,0,t.width,t.height,t.depth,r,p,t.data)}}else n.texImage3D(e.TEXTURE_2D_ARRAY,0,m,t.width,t.height,t.depth,0,r,p,t.data)}else if(o.isData3DTexture)_?(v&&n.texStorage3D(e.TEXTURE_3D,E,m,t.width,t.height,t.depth),S&&n.texSubImage3D(e.TEXTURE_3D,0,0,0,0,t.width,t.height,t.depth,r,p,t.data)):n.texImage3D(e.TEXTURE_3D,0,m,t.width,t.height,t.depth,0,r,p,t.data);else if(o.isFramebufferTexture){if(v){if(_)n.texStorage2D(e.TEXTURE_2D,E,m,t.width,t.height);else{let i=t.width,a=t.height;for(let t=0;t<E;t++)n.texImage2D(e.TEXTURE_2D,t,m,i,a,0,r,p,null),i>>=1,a>>=1}}}else if(o.isHTMLTexture){if(`texElementImage2D`in e){let n=e.canvas;if(n.hasAttribute(`layoutsubtree`)||n.setAttribute(`layoutsubtree`,`true`),t.parentNode!==n){n.appendChild(t),f.add(o),n.onpaint=e=>{let t=e.changedElements;for(let e of f)t.includes(e.image)&&(e.needsUpdate=!0)},n.requestPaint();return}if(e.texElementImage2D.length===3)e.texElementImage2D(e.TEXTURE_2D,e.RGBA8,t);else{let n=e.RGBA,r=e.RGBA,i=e.UNSIGNED_BYTE;e.texElementImage2D(e.TEXTURE_2D,0,n,r,i,t)}e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE)}}else if(g.length>0){if(_&&v){let t=Ae(g[0]);n.texStorage2D(e.TEXTURE_2D,E,m,t.width,t.height)}for(let t=0,i=g.length;t<i;t++)h=g[t],_?S&&n.texSubImage2D(e.TEXTURE_2D,t,0,0,r,p,h):n.texImage2D(e.TEXTURE_2D,t,m,r,p,h);o.generateMipmaps=!1}else if(_){if(v){let r=Ae(t);n.texStorage2D(e.TEXTURE_2D,E,m,r.width,r.height)}S&&n.texSubImage2D(e.TEXTURE_2D,0,0,0,r,p,t)}else n.texImage2D(e.TEXTURE_2D,0,m,r,p,t);b(o)&&o.mipmapsAutoUpdate===!0&&x(c),d.__version=u.version,o.onUpdate&&o.onUpdate(o)}t.__version=o.version}function he(t,o,s){if(o.image.length!==6)return;let c=de(t,o),l=o.source;n.bindTexture(e.TEXTURE_CUBE_MAP,t.__webglTexture,e.TEXTURE0+s);let u=r.get(l);if(l.version!==u.__version||c===!0){n.activeTexture(e.TEXTURE0+s);let t=Y.getPrimaries(Y.workingColorSpace),r=o.colorSpace===``?null:Y.getPrimaries(o.colorSpace),d=o.colorSpace===``||t===r?e.NONE:e.BROWSER_DEFAULT_WEBGL;n.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,o.flipY),n.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,o.premultiplyAlpha),n.pixelStorei(e.UNPACK_ALIGNMENT,o.unpackAlignment),n.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,d);let f=o.isCompressedTexture||o.image[0].isCompressedTexture,p=o.image[0]&&o.image[0].isDataTexture,m=[];for(let e=0;e<6;e++)!f&&!p?m[e]=y(o.image[e],!0,i.maxCubemapSize):m[e]=p?o.image[e].image:o.image[e],m[e]=ke(o,m[e]);let h=m[0],g=a.convert(o.format,o.colorSpace),_=a.convert(o.type),v=C(o.internalFormat,g,_,o.normalized,o.colorSpace),S=o.isVideoTexture!==!0,E=u.__version===void 0||c===!0,D=l.dataReady,O=T(o,h);ue(e.TEXTURE_CUBE_MAP,o);let k;if(o.isDepthTexture){if(v=w(o.format===xt,o.type),E){if(S)n.texStorage2D(e.TEXTURE_CUBE_MAP,1,v,h.width,h.height);else for(let t=0;t<6;t++)n.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,v,h.width,h.height,0,g,_,null)}}else if(f){S&&E&&n.texStorage2D(e.TEXTURE_CUBE_MAP,O,v,h.width,h.height);for(let t=0;t<6;t++){k=m[t].mipmaps;for(let r=0;r<k.length;r++){let i=k[r];o.format===1023?S?D&&n.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,r,0,0,i.width,i.height,g,_,i.data):n.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,r,v,i.width,i.height,0,g,_,i.data):g===null?X(`WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()`):S?D&&n.compressedTexSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,r,0,0,i.width,i.height,g,i.data):n.compressedTexImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,r,v,i.width,i.height,0,i.data)}}}else{if(k=o.mipmaps,S&&E){k.length>0&&O++;let t=Ae(m[0]);n.texStorage2D(e.TEXTURE_CUBE_MAP,O,v,t.width,t.height)}for(let t=0;t<6;t++)if(p){S?D&&n.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,0,0,m[t].width,m[t].height,g,_,m[t].data):n.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,v,m[t].width,m[t].height,0,g,_,m[t].data);for(let r=0;r<k.length;r++){let i=k[r].image[t].image;S?D&&n.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,r+1,0,0,i.width,i.height,g,_,i.data):n.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,r+1,v,i.width,i.height,0,g,_,i.data)}}else{S?D&&n.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,0,0,g,_,m[t]):n.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,v,g,_,m[t]);for(let r=0;r<k.length;r++){let i=k[r];S?D&&n.texSubImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,r+1,0,0,g,_,i.image[t]):n.texImage2D(e.TEXTURE_CUBE_MAP_POSITIVE_X+t,r+1,v,g,_,i.image[t])}}}b(o)&&o.mipmapsAutoUpdate===!0&&x(e.TEXTURE_CUBE_MAP),u.__version=l.version,o.onUpdate&&o.onUpdate(o)}t.__version=o.version}function ge(t,i,o,s,l,u){let d=a.convert(o.format,o.colorSpace),f=a.convert(o.type),p=C(o.internalFormat,d,f,o.normalized,o.colorSpace),m=r.get(i),h=r.get(o);if(h.__renderTarget=i,!m.__hasExternalTextures){let t=Math.max(1,i.width>>u),r=Math.max(1,i.height>>u);l===e.TEXTURE_3D||l===e.TEXTURE_2D_ARRAY?n.texImage3D(l,u,p,t,r,i.depth,0,d,f,null):n.texImage2D(l,u,p,t,r,0,d,f,null)}n.bindFramebuffer(e.FRAMEBUFFER,t),B(i)?c.framebufferTexture2DMultisampleEXT(e.FRAMEBUFFER,s,l,h.__webglTexture,0,Oe(i)):(l===e.TEXTURE_2D||l>=e.TEXTURE_CUBE_MAP_POSITIVE_X&&l<=e.TEXTURE_CUBE_MAP_NEGATIVE_Z)&&e.framebufferTexture2D(e.FRAMEBUFFER,s,l,h.__webglTexture,u),n.bindFramebuffer(e.FRAMEBUFFER,null)}function _e(t,n,r){if(e.bindRenderbuffer(e.RENDERBUFFER,t),n.depthBuffer){let i=n.depthTexture,a=i&&i.isDepthTexture?i.type:null,o=w(n.stencilBuffer,a),s=n.stencilBuffer?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT;B(n)?c.renderbufferStorageMultisampleEXT(e.RENDERBUFFER,Oe(n),o,n.width,n.height):r?e.renderbufferStorageMultisample(e.RENDERBUFFER,Oe(n),o,n.width,n.height):e.renderbufferStorage(e.RENDERBUFFER,o,n.width,n.height),e.framebufferRenderbuffer(e.FRAMEBUFFER,s,e.RENDERBUFFER,t)}else{let t=n.textures;for(let i=0;i<t.length;i++){let o=t[i],s=a.convert(o.format,o.colorSpace),l=a.convert(o.type),u=C(o.internalFormat,s,l,o.normalized,o.colorSpace);B(n)?c.renderbufferStorageMultisampleEXT(e.RENDERBUFFER,Oe(n),u,n.width,n.height):r?e.renderbufferStorageMultisample(e.RENDERBUFFER,Oe(n),u,n.width,n.height):e.renderbufferStorage(e.RENDERBUFFER,u,n.width,n.height)}}e.bindRenderbuffer(e.RENDERBUFFER,null)}function be(t,i,a){let o=i.isWebGLCubeRenderTarget===!0;if(n.bindFramebuffer(e.FRAMEBUFFER,t),!(i.depthTexture&&i.depthTexture.isDepthTexture))throw Error(`THREE.WebGLTextures: renderTarget.depthTexture must be an instance of THREE.DepthTexture.`);let s=r.get(i.depthTexture);s.__renderTarget=i;let l=o?i.depthTexture.image[0]:i.depthTexture.image;s.__webglTexture&&l.width===i.width&&l.height===i.height||(l.width=i.width,l.height=i.height,i.depthTexture.needsUpdate=!0),o?se(i.depthTexture,0):R(i.depthTexture,0);let u=s.__webglTexture,d=Oe(i),f=o?e.TEXTURE_CUBE_MAP_POSITIVE_X+a:e.TEXTURE_2D,p=i.depthTexture.format===1027?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT;if(i.depthTexture.format===1026)B(i)?c.framebufferTexture2DMultisampleEXT(e.FRAMEBUFFER,p,f,u,0,d):e.framebufferTexture2D(e.FRAMEBUFFER,p,f,u,0);else if(i.depthTexture.format===1027)B(i)?c.framebufferTexture2DMultisampleEXT(e.FRAMEBUFFER,p,f,u,0,d):e.framebufferTexture2D(e.FRAMEBUFFER,p,f,u,0);else throw Error(`THREE.WebGLTextures: Unknown depthTexture format.`)}function xe(t){let i=r.get(t),a=t.isWebGLCubeRenderTarget===!0;if(i.__boundDepthTexture!==t.depthTexture){let e=t.depthTexture;if(i.__depthDisposeCallback&&i.__depthDisposeCallback(),e){let t=()=>{delete i.__boundDepthTexture,delete i.__depthDisposeCallback,e.removeEventListener(`dispose`,t)};e.addEventListener(`dispose`,t),i.__depthDisposeCallback=t}i.__boundDepthTexture=e}if(t.depthTexture&&!i.__autoAllocateDepthBuffer){if(a)for(let e=0;e<6;e++)be(i.__webglFramebuffer[e],t,e);else t.texture.mipmaps.length>0?be(i.__webglFramebuffer[0],t,0):be(i.__webglFramebuffer,t,0)}else if(a){i.__webglDepthbuffer=[];for(let r=0;r<6;r++)if(n.bindFramebuffer(e.FRAMEBUFFER,i.__webglFramebuffer[r]),i.__webglDepthbuffer[r]===void 0)i.__webglDepthbuffer[r]=e.createRenderbuffer(),_e(i.__webglDepthbuffer[r],t,!1);else{let n=t.stencilBuffer?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT,a=i.__webglDepthbuffer[r];e.bindRenderbuffer(e.RENDERBUFFER,a),e.framebufferRenderbuffer(e.FRAMEBUFFER,n,e.RENDERBUFFER,a)}}else if(t.texture.mipmaps.length>0?n.bindFramebuffer(e.FRAMEBUFFER,i.__webglFramebuffer[0]):n.bindFramebuffer(e.FRAMEBUFFER,i.__webglFramebuffer),i.__webglDepthbuffer===void 0)i.__webglDepthbuffer=e.createRenderbuffer(),_e(i.__webglDepthbuffer,t,!1);else{let n=t.stencilBuffer?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT,r=i.__webglDepthbuffer;e.bindRenderbuffer(e.RENDERBUFFER,r),e.framebufferRenderbuffer(e.FRAMEBUFFER,n,e.RENDERBUFFER,r)}n.bindFramebuffer(e.FRAMEBUFFER,null)}function Se(t,n,i){let a=r.get(t);n!==void 0&&ge(a.__webglFramebuffer,t,t.texture,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,0),i!==void 0&&xe(t)}function we(t){let i=t.texture,o=r.get(t),c=r.get(i);t.addEventListener(`dispose`,k),E(t);let l=t.textures,u=t.isWebGLCubeRenderTarget===!0,d=l.length>1;if(d||(c.__webglTexture===void 0&&(c.__webglTexture=e.createTexture()),c.__version=i.version,s.memory.textures++),u){o.__webglFramebuffer=[];for(let t=0;t<6;t++)if(i.mipmaps.length>0){o.__webglFramebuffer[t]=[];for(let n=0;n<i.mipmaps.length;n++)o.__webglFramebuffer[t][n]=e.createFramebuffer()}else o.__webglFramebuffer[t]=e.createFramebuffer()}else{if(i.mipmaps.length>0){o.__webglFramebuffer=[];for(let t=0;t<i.mipmaps.length;t++)o.__webglFramebuffer[t]=e.createFramebuffer()}else o.__webglFramebuffer=e.createFramebuffer();if(d)for(let t=0,n=l.length;t<n;t++){let n=r.get(l[t]);n.__webglTexture===void 0&&(n.__webglTexture=e.createTexture(),s.memory.textures++)}if(t.samples>0&&B(t)===!1){o.__webglMultisampledFramebuffer=e.createFramebuffer(),o.__webglColorRenderbuffer=[],n.bindFramebuffer(e.FRAMEBUFFER,o.__webglMultisampledFramebuffer);for(let n=0;n<l.length;n++){let r=l[n];o.__webglColorRenderbuffer[n]=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,o.__webglColorRenderbuffer[n]);let i=a.convert(r.format,r.colorSpace),s=a.convert(r.type),c=C(r.internalFormat,i,s,r.normalized,r.colorSpace,t.isXRRenderTarget===!0),u=Oe(t);e.renderbufferStorageMultisample(e.RENDERBUFFER,u,c,t.width,t.height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+n,e.RENDERBUFFER,o.__webglColorRenderbuffer[n])}e.bindRenderbuffer(e.RENDERBUFFER,null),t.depthBuffer&&(o.__webglDepthRenderbuffer=e.createRenderbuffer(),_e(o.__webglDepthRenderbuffer,t,!0)),n.bindFramebuffer(e.FRAMEBUFFER,null)}}if(u){n.bindTexture(e.TEXTURE_CUBE_MAP,c.__webglTexture),ue(e.TEXTURE_CUBE_MAP,i);for(let n=0;n<6;n++)if(i.mipmaps.length>0)for(let r=0;r<i.mipmaps.length;r++)ge(o.__webglFramebuffer[n][r],t,i,e.COLOR_ATTACHMENT0,e.TEXTURE_CUBE_MAP_POSITIVE_X+n,r);else ge(o.__webglFramebuffer[n],t,i,e.COLOR_ATTACHMENT0,e.TEXTURE_CUBE_MAP_POSITIVE_X+n,0);b(i)?x(e.TEXTURE_CUBE_MAP):i.mipmaps.length>0&&e.texParameteri(e.TEXTURE_CUBE_MAP,e.TEXTURE_MAX_LEVEL,i.mipmaps.length-1),n.unbindTexture()}else if(d){for(let i=0,a=l.length;i<a;i++){let a=l[i],s=r.get(a),c=e.TEXTURE_2D;(t.isWebGL3DRenderTarget||t.isWebGLArrayRenderTarget)&&(c=t.isWebGL3DRenderTarget?e.TEXTURE_3D:e.TEXTURE_2D_ARRAY),n.bindTexture(c,s.__webglTexture),ue(c,a),ge(o.__webglFramebuffer,t,a,e.COLOR_ATTACHMENT0+i,c,0),b(a)&&x(c)}n.unbindTexture()}else{let r=e.TEXTURE_2D;if((t.isWebGL3DRenderTarget||t.isWebGLArrayRenderTarget)&&(r=t.isWebGL3DRenderTarget?e.TEXTURE_3D:e.TEXTURE_2D_ARRAY),n.bindTexture(r,c.__webglTexture),ue(r,i),i.mipmaps.length>0)for(let n=0;n<i.mipmaps.length;n++)ge(o.__webglFramebuffer[n],t,i,e.COLOR_ATTACHMENT0,r,n);else ge(o.__webglFramebuffer,t,i,e.COLOR_ATTACHMENT0,r,0);b(i)?x(r):i.mipmaps.length>0&&e.texParameteri(r,e.TEXTURE_MAX_LEVEL,i.mipmaps.length-1),n.unbindTexture()}t.depthBuffer&&xe(t)}function Te(e){let t=e.textures;for(let i=0,a=t.length;i<a;i++){let a=t[i];if(b(a)&&a.mipmapsAutoUpdate===!0){let t=S(e),i=r.get(a).__webglTexture;n.bindTexture(t,i),x(t),n.unbindTexture()}}}let Ee=[];function De(t){if(t.samples>0){if(B(t)===!1){let i=t.textures,a=t.width,o=t.height,s=e.COLOR_BUFFER_BIT,c=t.stencilBuffer?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT,u=r.get(t),d=i.length>1;if(d)for(let t=0;t<i.length;t++)n.bindFramebuffer(e.FRAMEBUFFER,u.__webglMultisampledFramebuffer),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+t,e.RENDERBUFFER,null),n.bindFramebuffer(e.FRAMEBUFFER,u.__webglFramebuffer),e.framebufferTexture2D(e.DRAW_FRAMEBUFFER,e.COLOR_ATTACHMENT0+t,e.TEXTURE_2D,null,0);n.bindFramebuffer(e.READ_FRAMEBUFFER,u.__webglMultisampledFramebuffer),t.texture.mipmaps.length>0?n.bindFramebuffer(e.DRAW_FRAMEBUFFER,u.__webglFramebuffer[0]):n.bindFramebuffer(e.DRAW_FRAMEBUFFER,u.__webglFramebuffer);for(let n=0;n<i.length;n++){if(t.resolveDepthBuffer&&(t.depthBuffer&&(s|=e.DEPTH_BUFFER_BIT),t.stencilBuffer&&t.resolveStencilBuffer&&(s|=e.STENCIL_BUFFER_BIT)),d){e.framebufferRenderbuffer(e.READ_FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.RENDERBUFFER,u.__webglColorRenderbuffer[n]);let t=r.get(i[n]).__webglTexture;e.framebufferTexture2D(e.DRAW_FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,t,0)}e.blitFramebuffer(0,0,a,o,0,0,a,o,s,e.NEAREST),l===!0&&(Ee.length=0,Ee.push(e.COLOR_ATTACHMENT0+n),t.depthBuffer&&t.storeMultisampledDepthBuffer===!1&&Ee.push(c),e.invalidateFramebuffer(e.READ_FRAMEBUFFER,Ee))}if(n.bindFramebuffer(e.READ_FRAMEBUFFER,null),n.bindFramebuffer(e.DRAW_FRAMEBUFFER,null),d)for(let t=0;t<i.length;t++){n.bindFramebuffer(e.FRAMEBUFFER,u.__webglMultisampledFramebuffer),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+t,e.RENDERBUFFER,u.__webglColorRenderbuffer[t]);let a=r.get(i[t]).__webglTexture;n.bindFramebuffer(e.FRAMEBUFFER,u.__webglFramebuffer),e.framebufferTexture2D(e.DRAW_FRAMEBUFFER,e.COLOR_ATTACHMENT0+t,e.TEXTURE_2D,a,0)}n.bindFramebuffer(e.DRAW_FRAMEBUFFER,u.__webglMultisampledFramebuffer)}else if(t.depthBuffer&&t.storeMultisampledDepthBuffer===!1&&l){let n=t.stencilBuffer?e.DEPTH_STENCIL_ATTACHMENT:e.DEPTH_ATTACHMENT;e.invalidateFramebuffer(e.DRAW_FRAMEBUFFER,[n])}}}function Oe(e){return Math.min(i.maxSamples,e.samples)}function B(e){let n=r.get(e);return e.samples>0&&t.has(`WEBGL_multisampled_render_to_texture`)===!0&&n.__useRenderToTexture!==!1}function V(e){let t=s.render.frame;d.get(e)!==t&&(d.set(e,t),e.update())}function ke(e,t){let n=e.colorSpace,r=e.format,i=e.type;return e.isCompressedTexture===!0||e.isVideoTexture===!0||n!==`srgb-linear`&&n!==``&&(Y.getTransfer(n)===`srgb`?(r!==1023||i!==1009)&&X(`WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType.`):W(`WebGLTextures: Unsupported texture color space:`,n)),t}function Ae(e){return typeof HTMLImageElement<`u`&&e instanceof HTMLImageElement?(u.width=e.naturalWidth||e.width,u.height=e.naturalHeight||e.height):typeof VideoFrame<`u`&&e instanceof VideoFrame?(u.width=e.displayWidth,u.height=e.displayHeight):(u.width=e.width,u.height=e.height),u}this.allocateTextureUnit=ne,this.resetTextureUnits=L,this.getTextureUnits=ee,this.setTextureUnits=te,this.setTexture2D=R,this.setTexture2DArray=ae,this.setTexture3D=oe,this.setTextureCube=se,this.rebindTextures=Se,this.setupRenderTarget=we,this.updateRenderTargetMipmap=Te,this.updateMultisampleRenderTarget=De,this.setupDepthRenderbuffer=xe,this.setupFrameBufferTexture=ge,this.useMultisampledRTT=B,this.dispose=M}function Ti(e,t){function n(n,r=``){let i,a=Y.getTransfer(r);if(n===1009)return e.UNSIGNED_BYTE;if(n===1017)return e.UNSIGNED_SHORT_4_4_4_4;if(n===1018)return e.UNSIGNED_SHORT_5_5_5_1;if(n===35902)return e.UNSIGNED_INT_5_9_9_9_REV;if(n===35899)return e.UNSIGNED_INT_10F_11F_11F_REV;if(n===1010)return e.BYTE;if(n===1011)return e.SHORT;if(n===1012)return e.UNSIGNED_SHORT;if(n===1013)return e.INT;if(n===1014)return e.UNSIGNED_INT;if(n===1015)return e.FLOAT;if(n===1016)return e.HALF_FLOAT;if(n===1021)return e.ALPHA;if(n===1022)return e.RGB;if(n===1023)return e.RGBA;if(n===1026)return e.DEPTH_COMPONENT;if(n===1027)return e.DEPTH_STENCIL;if(n===1028)return e.RED;if(n===1029)return e.RED_INTEGER;if(n===1030)return e.RG;if(n===1031)return e.RG_INTEGER;if(n===1033)return e.RGBA_INTEGER;if(n===33776||n===33777||n===33778||n===33779){if(a===`srgb`){if(i=t.get(`WEBGL_compressed_texture_s3tc_srgb`),i!==null){if(n===33776)return i.COMPRESSED_SRGB_S3TC_DXT1_EXT;if(n===33777)return i.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;if(n===33778)return i.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;if(n===33779)return i.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}else return null}else if(i=t.get(`WEBGL_compressed_texture_s3tc`),i!==null){if(n===33776)return i.COMPRESSED_RGB_S3TC_DXT1_EXT;if(n===33777)return i.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(n===33778)return i.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(n===33779)return i.COMPRESSED_RGBA_S3TC_DXT5_EXT}else return null}if(n===35840||n===35841||n===35842||n===35843){if(i=t.get(`WEBGL_compressed_texture_pvrtc`),i!==null){if(n===35840)return i.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(n===35841)return i.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(n===35842)return i.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(n===35843)return i.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}else return null}if(n===36196||n===37492||n===37496||n===37488||n===37489||n===37490||n===37491){if(i=t.get(`WEBGL_compressed_texture_etc`),i!==null){if(n===36196||n===37492)return a===`srgb`?i.COMPRESSED_SRGB8_ETC2:i.COMPRESSED_RGB8_ETC2;if(n===37496)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:i.COMPRESSED_RGBA8_ETC2_EAC;if(n===37488)return i.COMPRESSED_R11_EAC;if(n===37489)return i.COMPRESSED_SIGNED_R11_EAC;if(n===37490)return i.COMPRESSED_RG11_EAC;if(n===37491)return i.COMPRESSED_SIGNED_RG11_EAC}else return null}if(n===37808||n===37809||n===37810||n===37811||n===37812||n===37813||n===37814||n===37815||n===37816||n===37817||n===37818||n===37819||n===37820||n===37821){if(i=t.get(`WEBGL_compressed_texture_astc`),i!==null){if(n===37808)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:i.COMPRESSED_RGBA_ASTC_4x4_KHR;if(n===37809)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:i.COMPRESSED_RGBA_ASTC_5x4_KHR;if(n===37810)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:i.COMPRESSED_RGBA_ASTC_5x5_KHR;if(n===37811)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:i.COMPRESSED_RGBA_ASTC_6x5_KHR;if(n===37812)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:i.COMPRESSED_RGBA_ASTC_6x6_KHR;if(n===37813)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:i.COMPRESSED_RGBA_ASTC_8x5_KHR;if(n===37814)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:i.COMPRESSED_RGBA_ASTC_8x6_KHR;if(n===37815)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:i.COMPRESSED_RGBA_ASTC_8x8_KHR;if(n===37816)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:i.COMPRESSED_RGBA_ASTC_10x5_KHR;if(n===37817)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:i.COMPRESSED_RGBA_ASTC_10x6_KHR;if(n===37818)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:i.COMPRESSED_RGBA_ASTC_10x8_KHR;if(n===37819)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:i.COMPRESSED_RGBA_ASTC_10x10_KHR;if(n===37820)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:i.COMPRESSED_RGBA_ASTC_12x10_KHR;if(n===37821)return a===`srgb`?i.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:i.COMPRESSED_RGBA_ASTC_12x12_KHR}else return null}if(n===36492||n===36494||n===36495){if(i=t.get(`EXT_texture_compression_bptc`),i!==null){if(n===36492)return a===`srgb`?i.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT:i.COMPRESSED_RGBA_BPTC_UNORM_EXT;if(n===36494)return i.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT;if(n===36495)return i.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT}else return null}if(n===36283||n===36284||n===36285||n===36286){if(i=t.get(`EXT_texture_compression_rgtc`),i!==null){if(n===36283)return i.COMPRESSED_RED_RGTC1_EXT;if(n===36284)return i.COMPRESSED_SIGNED_RED_RGTC1_EXT;if(n===36285)return i.COMPRESSED_RED_GREEN_RGTC2_EXT;if(n===36286)return i.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}else return null}return n===1020?e.UNSIGNED_INT_24_8:e[n]===void 0?null:e[n]}return{convert:n}}var Ei=`
4198
+ void main() {
4199
+
4200
+ gl_Position = vec4( position, 1.0 );
4201
+
4202
+ }`,Di=`
4203
+ uniform sampler2DArray depthColor;
4204
+ uniform float depthWidth;
4205
+ uniform float depthHeight;
4206
+
4207
+ void main() {
4208
+
4209
+ vec2 coord = vec2( gl_FragCoord.x / depthWidth, gl_FragCoord.y / depthHeight );
4210
+
4211
+ if ( coord.x >= 1.0 ) {
4212
+
4213
+ gl_FragDepth = texture( depthColor, vec3( coord.x - 1.0, coord.y, 1 ) ).r;
4214
+
4215
+ } else {
4216
+
4217
+ gl_FragDepth = texture( depthColor, vec3( coord.x, coord.y, 0 ) ).r;
4218
+
4219
+ }
4220
+
4221
+ }`,Oi=class{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t){if(this.texture===null){let n=new v(e.texture);(e.depthNear!==t.depthNear||e.depthFar!==t.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=n}}getMesh(e){if(this.texture!==null&&this.mesh===null){let t=e.cameras[0].viewport,n=new de({vertexShader:Ei,fragmentShader:Di,uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new dt(new le(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}},ki=class extends ue{constructor(e,t){super();let n=this,r=null,i=1,a=null,o=`local-floor`,s=1,c=null,u=null,f=null,p=null,m=null,h=null,g=typeof XRWebGLBinding<`u`,_=new Oi,y={},b=t.getContextAttributes(),x=null,S=null,C=[],w=[],T=new ve,E=null,D=null,k=new Ae;k.viewport=new M;let A=new Ae;A.viewport=new M;let j=[k,A],N=new st,P=null,F=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(e){let t=C[e];return t===void 0&&(t=new be,C[e]=t),t.getTargetRaySpace()},this.getControllerGrip=function(e){let t=C[e];return t===void 0&&(t=new be,C[e]=t),t.getGripSpace()},this.getHand=function(e){let t=C[e];return t===void 0&&(t=new be,C[e]=t),t.getHandSpace()};function I(e){let t=w.indexOf(e.inputSource);if(t===-1)return;let n=C[t];n!==void 0&&(n.update(e.inputSource,e.frame,c||a),n.dispatchEvent({type:e.type,data:e.inputSource}))}function L(){r.removeEventListener(`select`,I),r.removeEventListener(`selectstart`,I),r.removeEventListener(`selectend`,I),r.removeEventListener(`squeeze`,I),r.removeEventListener(`squeezestart`,I),r.removeEventListener(`squeezeend`,I),r.removeEventListener(`end`,L),r.removeEventListener(`inputsourceschange`,ee);for(let e=0;e<C.length;e++){let t=w[e];t!==null&&(w[e]=null,C[e].disconnect(t))}P=null,F=null,_.reset();for(let e in y)delete y[e];if(e.setRenderTarget(x),m=null,p=null,f=null,r=null,S=null,ae.stop(),n.isPresenting=!1,e.setPixelRatio(E),e.setSize(T.width,T.height,!1),D!==null){let e=D.camera;e.fov=D.fov,e.zoom=D.zoom,e.updateProjectionMatrix(),D=null}n.dispatchEvent({type:`sessionend`})}this.setFramebufferScaleFactor=function(e){i=e,n.isPresenting===!0&&X(`WebXRManager: Cannot change framebuffer scale while presenting.`)},this.setReferenceSpaceType=function(e){o=e,n.isPresenting===!0&&X(`WebXRManager: Cannot change reference space type while presenting.`)},this.getReferenceSpace=function(){return c||a},this.setReferenceSpace=function(e){c=e},this.getBaseLayer=function(){return p===null?m:p},this.getBinding=function(){return f===null&&g&&(f=new XRWebGLBinding(r,t)),f},this.getFrame=function(){return h},this.getSession=function(){return r},this.setSession=async function(l){if(r=l,r!==null){if(x=e.getRenderTarget(),r.addEventListener(`select`,I),r.addEventListener(`selectstart`,I),r.addEventListener(`selectend`,I),r.addEventListener(`squeeze`,I),r.addEventListener(`squeezestart`,I),r.addEventListener(`squeezeend`,I),r.addEventListener(`end`,L),r.addEventListener(`inputsourceschange`,ee),b.xrCompatible!==!0&&await t.makeXRCompatible(),E=e.getPixelRatio(),e.getSize(T),g&&`createProjectionLayer`in XRWebGLBinding.prototype){let n=null,a=null,o=null;b.depth&&(o=b.stencil?t.DEPTH24_STENCIL8:t.DEPTH_COMPONENT24,n=b.stencil?xt:ke,a=b.stencil?se:d);let s={colorFormat:t.RGBA8,depthFormat:o,scaleFactor:i};f=this.getBinding(),p=f.createProjectionLayer(s),r.updateRenderState({layers:[p]}),e.setPixelRatio(1),e.setSize(p.textureWidth,p.textureHeight,!1),S=new Se(p.textureWidth,p.textureHeight,{format:R,type:O,depthTexture:new z(p.textureWidth,p.textureHeight,a,void 0,void 0,void 0,void 0,void 0,void 0,n),stencilBuffer:b.stencil,colorSpace:e.outputColorSpace,samples:b.antialias?4:0,resolveDepthBuffer:p.ignoreDepthValues===!1,resolveStencilBuffer:p.ignoreDepthValues===!1,storeMultisampledDepthBuffer:p.ignoreDepthValues===!1,storeMultisampledStencilBuffer:p.ignoreDepthValues===!1})}else{let n={antialias:b.antialias,alpha:!0,depth:b.depth,stencil:b.stencil,framebufferScaleFactor:i};m=new XRWebGLLayer(r,t,n),r.updateRenderState({baseLayer:m}),e.setPixelRatio(1),e.setSize(m.framebufferWidth,m.framebufferHeight,!1),S=new Se(m.framebufferWidth,m.framebufferHeight,{format:R,type:O,colorSpace:e.outputColorSpace,stencilBuffer:b.stencil,resolveDepthBuffer:m.ignoreDepthValues===!1,resolveStencilBuffer:m.ignoreDepthValues===!1,storeMultisampledDepthBuffer:m.ignoreDepthValues===!1,storeMultisampledStencilBuffer:m.ignoreDepthValues===!1})}S.isXRRenderTarget=!0,this.setFoveation(s),c=null,a=await r.requestReferenceSpace(o),ae.setContext(r),ae.start(),n.isPresenting=!0,n.dispatchEvent({type:`sessionstart`})}},this.getEnvironmentBlendMode=function(){if(r!==null)return r.environmentBlendMode},this.getDepthTexture=function(){return _.getDepthTexture()};function ee(e){for(let t=0;t<e.removed.length;t++){let n=e.removed[t],r=w.indexOf(n);r>=0&&(w[r]=null,C[r].disconnect(n))}for(let t=0;t<e.added.length;t++){let n=e.added[t],r=w.indexOf(n);if(r===-1){for(let e=0;e<C.length;e++)if(e>=w.length){w.push(n),r=e;break}else if(w[e]===null){w[e]=n,r=e;break}if(r===-1)break}let i=C[r];i&&i.connect(n)}}function te(e,t){t===null?e.matrixWorld.copy(e.matrix):e.matrixWorld.multiplyMatrices(t.matrixWorld,e.matrix),e.matrixWorldInverse.copy(e.matrixWorld).invert()}this.updateCamera=function(e){if(r===null)return;let t=e.near,n=e.far;_.texture!==null&&(_.depthNear>0&&(t=_.depthNear),_.depthFar>0&&(n=_.depthFar)),N.near=A.near=k.near=t,N.far=A.far=k.far=n,(P!==N.near||F!==N.far)&&(r.updateRenderState({depthNear:N.near,depthFar:N.far}),P=N.near,F=N.far),N.layers.mask=e.layers.mask|6,k.layers.mask=N.layers.mask&-5,A.layers.mask=N.layers.mask&-3;let i=e.parent,a=N.cameras;te(N,i);for(let e=0;e<a.length;e++)te(a[e],i);N.projectionMatrix.copy(k.projectionMatrix),N.projectionMatrixInverse.copy(k.projectionMatrixInverse),D===null&&e.isPerspectiveCamera&&(D={camera:e,fov:e.fov,zoom:e.zoom}),ne(e,N,i)};function ne(e,t,n){n===null?e.matrix.copy(t.matrixWorld):(e.matrix.copy(n.matrixWorld),e.matrix.invert(),e.matrix.multiply(t.matrixWorld)),e.matrix.decompose(e.position,e.quaternion,e.scale),e.updateMatrixWorld(!0),e.projectionMatrix.copy(t.projectionMatrix),e.projectionMatrixInverse.copy(t.projectionMatrixInverse),e.isPerspectiveCamera&&(e.fov=l*2*Math.atan(1/e.projectionMatrix.elements[5]),e.zoom=1)}this.getCamera=function(){return N},this.getFoveation=function(){if(p!==null||m!==null)return s},this.setFoveation=function(e){s=e,p!==null&&(p.fixedFoveation=e),m!==null&&m.fixedFoveation!==void 0&&(m.fixedFoveation=e)},this.hasDepthSensing=function(){return _.texture!==null},this.getDepthSensingMesh=function(){return _.getMesh(N)},this.getCameraTexture=function(e){return y[e]};let re=null;function ie(t,i){if(u=i.getViewerPose(c||a),h=i,u!==null){let t=u.views;m!==null&&(e.setRenderTargetFramebuffer(S,m.framebuffer),e.setRenderTarget(S));let i=!1;t.length!==N.cameras.length&&(N.cameras.length=0,i=!0);for(let n=0;n<t.length;n++){let r=t[n],a=null;if(m!==null)a=m.getViewport(r);else{let t=f.getViewSubImage(p,r);a=t.viewport,n===0&&(e.setRenderTargetTextures(S,t.colorTexture,t.depthStencilTexture),e.setRenderTarget(S))}let o=j[n];o===void 0&&(o=new Ae,o.layers.enable(n),o.viewport=new M,j[n]=o),o.matrix.fromArray(r.transform.matrix),o.matrix.decompose(o.position,o.quaternion,o.scale),o.projectionMatrix.fromArray(r.projectionMatrix),o.projectionMatrixInverse.copy(o.projectionMatrix).invert(),o.viewport.set(a.x,a.y,a.width,a.height),n===0&&(N.matrix.copy(o.matrix),N.matrix.decompose(N.position,N.quaternion,N.scale)),i===!0&&N.cameras.push(o)}let a=r.enabledFeatures;if(a&&a.includes(`depth-sensing`)&&r.depthUsage==`gpu-optimized`&&g){f=n.getBinding();let e=f.getDepthInformation(t[0]);e&&e.isValid&&e.texture&&_.init(e,r.renderState)}if(a&&a.includes(`camera-access`)&&g){e.state.unbindTexture(),f=n.getBinding();for(let e=0;e<t.length;e++){let n=t[e].camera;if(n){let e=y[n];e||(e=new v,y[n]=e);let t=f.getCameraImage(n);e.sourceTexture=t}}}}for(let e=0;e<C.length;e++){let t=w[e],n=C[e];t!==null&&n!==void 0&&n.update(t,i,c||a)}re&&re(t,i),i.detectedPlanes&&n.dispatchEvent({type:`planesdetected`,data:i}),h=null}let ae=new Dt;ae.setAnimationLoop(ie),this.setAnimationLoop=function(e){re=e},this.dispose=function(){}}},Ai=new nt,ji=new V;ji.set(-1,0,0,0,1,0,0,0,1);function Mi(e,t){function n(e,t){e.matrixAutoUpdate===!0&&e.updateMatrix(),t.value.copy(e.matrix)}function r(t,n){n.color.getRGB(t.fogColor.value,ct(e)),n.isFog?(t.fogNear.value=n.near,t.fogFar.value=n.far):n.isFogExp2&&(t.fogDensity.value=n.density)}function i(e,t,n,r,i){t.isNodeMaterial?t.uniformsNeedUpdate=!1:t.isMeshBasicMaterial?a(e,t):t.isMeshLambertMaterial?(a(e,t),t.envMap&&(e.envMapIntensity.value=t.envMapIntensity)):t.isMeshToonMaterial?(a(e,t),d(e,t)):t.isMeshPhongMaterial?(a(e,t),u(e,t),t.envMap&&(e.envMapIntensity.value=t.envMapIntensity)):t.isMeshStandardMaterial?(a(e,t),f(e,t),t.isMeshPhysicalMaterial&&p(e,t,i)):t.isMeshMatcapMaterial?(a(e,t),m(e,t)):t.isMeshDepthMaterial?a(e,t):t.isMeshDistanceMaterial?(a(e,t),h(e,t)):t.isMeshNormalMaterial?a(e,t):t.isLineBasicMaterial?(o(e,t),t.isLineDashedMaterial&&s(e,t)):t.isPointsMaterial?c(e,t,n,r):t.isSpriteMaterial?l(e,t):t.isShadowMaterial?(e.color.value.copy(t.color),e.opacity.value=t.opacity):t.isShaderMaterial&&(t.uniformsNeedUpdate=!1)}function a(e,r){e.opacity.value=r.opacity,r.color&&e.diffuse.value.copy(r.color),r.emissive&&e.emissive.value.copy(r.emissive).multiplyScalar(r.emissiveIntensity),r.map&&(e.map.value=r.map,n(r.map,e.mapTransform)),r.alphaMap&&(e.alphaMap.value=r.alphaMap,n(r.alphaMap,e.alphaMapTransform)),r.bumpMap&&(e.bumpMap.value=r.bumpMap,n(r.bumpMap,e.bumpMapTransform),e.bumpScale.value=r.bumpScale,r.side===1&&(e.bumpScale.value*=-1)),r.normalMap&&(e.normalMap.value=r.normalMap,n(r.normalMap,e.normalMapTransform),e.normalScale.value.copy(r.normalScale),r.side===1&&e.normalScale.value.negate()),r.displacementMap&&(e.displacementMap.value=r.displacementMap,n(r.displacementMap,e.displacementMapTransform),e.displacementScale.value=r.displacementScale,e.displacementBias.value=r.displacementBias),r.emissiveMap&&(e.emissiveMap.value=r.emissiveMap,n(r.emissiveMap,e.emissiveMapTransform)),r.specularMap&&(e.specularMap.value=r.specularMap,n(r.specularMap,e.specularMapTransform)),r.alphaTest>0&&(e.alphaTest.value=r.alphaTest);let i=t.get(r),a=i.envMap,o=i.envMapRotation;a&&(e.envMap.value=a,e.envMapRotation.value.setFromMatrix4(Ai.makeRotationFromEuler(o)).transpose(),a.isCubeTexture&&a.isRenderTargetTexture===!1&&e.envMapRotation.value.premultiply(ji),e.reflectivity.value=r.reflectivity,e.ior.value=r.ior,e.refractionRatio.value=r.refractionRatio),r.lightMap&&(e.lightMap.value=r.lightMap,e.lightMapIntensity.value=r.lightMapIntensity,n(r.lightMap,e.lightMapTransform)),r.aoMap&&(e.aoMap.value=r.aoMap,e.aoMapIntensity.value=r.aoMapIntensity,n(r.aoMap,e.aoMapTransform))}function o(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,t.map&&(e.map.value=t.map,n(t.map,e.mapTransform))}function s(e,t){e.dashSize.value=t.dashSize,e.totalSize.value=t.dashSize+t.gapSize,e.scale.value=t.scale}function c(e,t,r,i){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.size.value=t.size*r,e.scale.value=i*.5,t.map&&(e.map.value=t.map,n(t.map,e.uvTransform)),t.alphaMap&&(e.alphaMap.value=t.alphaMap,n(t.alphaMap,e.alphaMapTransform)),t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}function l(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.rotation.value=t.rotation,t.map&&(e.map.value=t.map,n(t.map,e.mapTransform)),t.alphaMap&&(e.alphaMap.value=t.alphaMap,n(t.alphaMap,e.alphaMapTransform)),t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}function u(e,t){e.specular.value.copy(t.specular),e.shininess.value=Math.max(t.shininess,1e-4)}function d(e,t){t.gradientMap&&(e.gradientMap.value=t.gradientMap)}function f(e,t){e.metalness.value=t.metalness,t.metalnessMap&&(e.metalnessMap.value=t.metalnessMap,n(t.metalnessMap,e.metalnessMapTransform)),e.roughness.value=t.roughness,t.roughnessMap&&(e.roughnessMap.value=t.roughnessMap,n(t.roughnessMap,e.roughnessMapTransform)),t.envMap&&(e.envMapIntensity.value=t.envMapIntensity)}function p(e,t,r){e.ior.value=t.ior,t.diffuseRoughness>0&&(e.diffuseRoughness.value=t.diffuseRoughness,t.diffuseRoughnessMap&&(e.diffuseRoughnessMap.value=t.diffuseRoughnessMap,n(t.diffuseRoughnessMap,e.diffuseRoughnessMapTransform))),t.sheen>0&&(e.sheenColor.value.copy(t.sheenColor).multiplyScalar(t.sheen),e.sheenRoughness.value=t.sheenRoughness,t.sheenColorMap&&(e.sheenColorMap.value=t.sheenColorMap,n(t.sheenColorMap,e.sheenColorMapTransform)),t.sheenRoughnessMap&&(e.sheenRoughnessMap.value=t.sheenRoughnessMap,n(t.sheenRoughnessMap,e.sheenRoughnessMapTransform))),t.clearcoat>0&&(e.clearcoat.value=t.clearcoat,e.clearcoatRoughness.value=t.clearcoatRoughness,t.clearcoatMap&&(e.clearcoatMap.value=t.clearcoatMap,n(t.clearcoatMap,e.clearcoatMapTransform)),t.clearcoatRoughnessMap&&(e.clearcoatRoughnessMap.value=t.clearcoatRoughnessMap,n(t.clearcoatRoughnessMap,e.clearcoatRoughnessMapTransform)),t.clearcoatNormalMap&&(e.clearcoatNormalMap.value=t.clearcoatNormalMap,n(t.clearcoatNormalMap,e.clearcoatNormalMapTransform),e.clearcoatNormalScale.value.copy(t.clearcoatNormalScale),t.side===1&&e.clearcoatNormalScale.value.negate())),t.dispersion>0&&(e.dispersion.value=t.dispersion),t.retroreflectivity>0&&(e.retroreflectivity.value=t.retroreflectivity),t.iridescence>0&&(e.iridescence.value=t.iridescence,e.iridescenceIOR.value=t.iridescenceIOR,e.iridescenceThicknessMinimum.value=t.iridescenceThicknessMinimum,e.iridescenceThicknessMaximum.value=t.iridescenceThicknessMaximum,t.iridescenceMap&&(e.iridescenceMap.value=t.iridescenceMap,n(t.iridescenceMap,e.iridescenceMapTransform)),t.iridescenceThicknessMap&&(e.iridescenceThicknessMap.value=t.iridescenceThicknessMap,n(t.iridescenceThicknessMap,e.iridescenceThicknessMapTransform))),t.transmission>0&&(e.transmission.value=t.transmission,e.transmissionSamplerMap.value=r.texture,e.transmissionSamplerSize.value.set(r.width,r.height),t.transmissionMap&&(e.transmissionMap.value=t.transmissionMap,n(t.transmissionMap,e.transmissionMapTransform)),e.thickness.value=t.thickness,t.thicknessMap&&(e.thicknessMap.value=t.thicknessMap,n(t.thicknessMap,e.thicknessMapTransform)),e.attenuationDistance.value=t.attenuationDistance,e.attenuationColor.value.copy(t.attenuationColor)),t.anisotropy>0&&(e.anisotropyVector.value.set(t.anisotropy*Math.cos(t.anisotropyRotation),t.anisotropy*Math.sin(t.anisotropyRotation)),t.anisotropyMap&&(e.anisotropyMap.value=t.anisotropyMap,n(t.anisotropyMap,e.anisotropyMapTransform))),e.specularIntensity.value=t.specularIntensity,e.specularColor.value.copy(t.specularColor),t.specularColorMap&&(e.specularColorMap.value=t.specularColorMap,n(t.specularColorMap,e.specularColorMapTransform)),t.specularIntensityMap&&(e.specularIntensityMap.value=t.specularIntensityMap,n(t.specularIntensityMap,e.specularIntensityMapTransform))}function m(e,t){t.matcap&&(e.matcap.value=t.matcap)}function h(e,n){let r=t.get(n).light;e.referencePosition.value.setFromMatrixPosition(r.matrixWorld),e.nearDistance.value=r.shadow.camera.near,e.farDistance.value=r.shadow.camera.far}return{refreshFogUniforms:r,refreshMaterialUniforms:i}}function Ni(e,t,n,r){let i={},a={};function o(e,t){let n=t.program;r.uniformBlockBinding(e,n,i[e.id])}function s(e,n){let o=i[e.id];o===void 0&&(m(e),o=c(e),i[e.id]=o,e.addEventListener(`dispose`,g));let s=n.program;r.updateUBOMapping(e,s);let u=t.render.frame;a[e.id]!==u&&(l(e),a[e.id]=u)}function c(t){let n=e.createBuffer(),r=t.__size,i=t.usage;return e.bindBuffer(e.UNIFORM_BUFFER,n),e.bufferData(e.UNIFORM_BUFFER,r,i),e.bindBuffer(e.UNIFORM_BUFFER,null),n}function l(t){let n=i[t.id],r=t.uniforms,a=t.__cache;e.bindBuffer(e.UNIFORM_BUFFER,n);for(let e=0,t=r.length;e<t;e++){let t=r[e];if(Array.isArray(t))for(let n=0,r=t.length;n<r;n++)u(t[n],e,n,a);else u(t,e,0,a)}e.bindBuffer(e.UNIFORM_BUFFER,null)}function u(t,n,r,i){if(f(t,n,r,i)===!0){let n=t.__offset,r=t.value;if(Array.isArray(r)){let e=0;for(let n=0;n<r.length;n++){let i=r[n],a=h(i,!0);d(i,t.__data,e),e+=a.storage/Float32Array.BYTES_PER_ELEMENT}}else d(r,t.__data,0);e.bufferSubData(e.UNIFORM_BUFFER,n,t.__data)}}function d(e,t,n){typeof e==`number`||typeof e==`boolean`?t[n]=e:e.isMatrix3?(t[n]=e.elements[0],t[n+1]=e.elements[1],t[n+2]=e.elements[2],t[n+3]=0,t[n+4]=e.elements[3],t[n+5]=e.elements[4],t[n+6]=e.elements[5],t[n+7]=0,t[n+8]=e.elements[6],t[n+9]=e.elements[7],t[n+10]=e.elements[8],t[n+11]=0):ArrayBuffer.isView(e)?t.set(e.subarray(0,t.length-n),n):e.toArray(t,n)}function f(e,t,n,r){let i=e.value,a=t+`_`+n;if(Array.isArray(i)){r[a]===void 0&&(r[a]=[]);let e=r[a],t=!1;for(let n=0;n<i.length;n++)p(i[n],e,n)===!0&&(t=!0);return t}return p(i,r,a)}function p(e,t,n){if(t[n]===void 0)return t[n]=typeof e==`number`||typeof e==`boolean`?e:ArrayBuffer.isView(e)?e.slice():e.clone(),!0;{let r=t[n];if(typeof e==`number`||typeof e==`boolean`){if(r!==e)return t[n]=e,!0}else if(ArrayBuffer.isView(e))return!0;else if(r.equals(e)===!1)return r.copy(e),!0}return!1}function m(e){let t=e.uniforms,n=0;for(let e=0,r=t.length;e<r;e++){let r=Array.isArray(t[e])?t[e]:[t[e]];for(let i=0,a=r.length;i<a;i++){let a=r[i],o=Array.isArray(a.value)?a.value:[a.value],s=Array.isArray(t[e])||Array.isArray(a.value),c=n;for(let e=0,t=o.length;e<t;e++){let t=o[e],r=h(t,s),i=n%16,a=i%r.boundary,l=i+a;n+=a,l!==0&&16-l<r.storage&&(n+=16-l),e===0&&(c=n),n+=r.storage}a.__data=new(a.type===`int`?Int32Array:a.type===`uint`?Uint32Array:Float32Array)((n-c)/Float32Array.BYTES_PER_ELEMENT),a.__offset=c}}let r=n%16;return r>0&&(n+=16-r),e.__size=n,e.__cache={},this}function h(e,t){let n={boundary:0,storage:0};return typeof e==`number`||typeof e==`boolean`?(n.boundary=4,n.storage=4):e.isVector2?(n.boundary=8,n.storage=8):e.isVector3||e.isColor?(n.boundary=16,n.storage=12):e.isVector4?(n.boundary=16,n.storage=16):e.isMatrix3?(n.boundary=16,n.storage=48):e.isMatrix4?(n.boundary=16,n.storage=64):e.isTexture?X(`WebGLRenderer: Texture samplers can not be part of an uniforms group.`):ArrayBuffer.isView(e)?(n.boundary=16,n.storage=e.byteLength):X(`WebGLRenderer: Unsupported uniform value type.`,e),t===!0&&(n.boundary=16,n.storage=Math.ceil(n.storage/16)*16),n}function g(t){let n=t.target;n.removeEventListener(`dispose`,g),e.deleteBuffer(i[n.id]),delete i[n.id],delete a[n.id]}function _(){for(let t in i)e.deleteBuffer(i[t]);i={},a={}}return{bind:o,update:s,dispose:_}}var Pi=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]),Fi=null;function Ii(){return Fi===null&&(Fi=new Ct(Pi,16,16,Pe,ne),Fi.name=`DFG_LUT`,Fi.minFilter=ye,Fi.magFilter=ye,Fi.wrapS=Ne,Fi.wrapT=Ne,Fi.generateMipmaps=!1,Fi.needsUpdate=!0),Fi}var Li=class{constructor(e={}){let{canvas:t=ae(),context:n=null,depth:r=!0,stencil:i=!1,alpha:a=!1,antialias:o=!1,premultipliedAlpha:c=!0,preserveDrawingBuffer:l=!1,powerPreference:u=`default`,failIfMajorPerformanceCaveat:f=!1,reversedDepthBuffer:p=!1,outputBufferType:m=O}=e;this.isWebGLRenderer=!0;let h;if(n!==null){if(typeof WebGLRenderingContext<`u`&&n instanceof WebGLRenderingContext)throw Error(`THREE.WebGLRenderer: WebGL 1 is not supported since r163.`);h=n.getContextAttributes().alpha}else h=a;let g=m,_=new Set([S,Fe,ze]),v=new Set([O,d,me,se,ge,E]),y=new Uint32Array(4),b=new Int32Array(4),x={textures:[],min:[],max:[],resolution:[]},C=null,T=null,D=[],k=[],j=null;this.domElement=t,this.debug={checkShaderErrors:!0,diagnostics:{keywords:!1},onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=0,this.toneMappingExposure=1,this.transmissionResolutionScale=1;let N=this,P=!1,F=null,I=null,L=null,ee=null;this._outputColorSpace=ce;let te=0,re=0,R=null,ie=-1,oe=null,z=new M,le=new M,ue=null,de=new K(0),fe=0,pe=t.width,he=t.height,_e=1,ve=null,ye=null,be=new M(0,0,pe,he),xe=new M(0,0,pe,he),we=!1,Te=new s,Ee=new We,De=!1,Oe=!1,B=new nt,V=new w,ke=new M,Ae={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0},je=!1;function Me(){return R===null?_e:1}let H=n;function Ne(e,n){return t.getContext(e,n)}let Pe,U,G,Ie,q,J,Le,Re,Be,Ve,Ue,Ge,Ke,qe,Je,Ye,Xe,Ze,Qe,$e,et,rt,it;try{let e={alpha:!0,depth:r,stencil:i,antialias:o,premultipliedAlpha:c,preserveDrawingBuffer:l,powerPreference:u,failIfMajorPerformanceCaveat:f};if(`setAttribute`in t&&t.setAttribute(`data-engine`,`three.js r187`),t.addEventListener(`webglcontextlost`,st,!1),t.addEventListener(`webglcontextrestored`,ct,!1),t.addEventListener(`webglcontextcreationerror`,lt,!1),H===null){let t=`webgl2`;if(H=Ne(t,e),H===null)throw Ne(t)?Error(`THREE.WebGLRenderer: Error creating WebGL context with your selected attributes.`):Error(`THREE.WebGLRenderer: Error creating WebGL context.`)}at()}catch(e){throw t.removeEventListener(`webglcontextlost`,st,!1),t.removeEventListener(`webglcontextrestored`,ct,!1),t.removeEventListener(`webglcontextcreationerror`,lt,!1),W(`WebGLRenderer: `+e.message),e}function at(){Pe=new nn(H),Pe.init(),et=new Ti(H,Pe),U=new It(H,Pe,e,et),G=new Ci(H,Pe),U.reversedDepthBuffer&&p&&G.buffers.depth.setReversed(!0),I=H.createFramebuffer(),L=H.createFramebuffer(),ee=H.createFramebuffer(),Ie=new on(H),q=new ri,J=new wi(H,Pe,G,q,U,et,Ie),Le=new tn(N),Re=new Ot(H),rt=new Pt(H,Re),Be=new rn(H,Re,Ie,rt),Ve=new cn(H,Be,Re,rt,Ie),Ze=new sn(H,U,J),Je=new Lt(q),Ue=new ni(N,Le,Pe,U,rt,Je),Ge=new Mi(N,q),Ke=new si,qe=new mi(Pe),Xe=new Nt(N,Le,G,Ve,h,c),Ye=new Si(N,Ve,U),it=new Ni(H,Ie,U,G),Qe=new Ft(H,Pe,Ie),$e=new an(H,Pe,Ie),Ie.programs=Ue.programs,N.capabilities=U,N.extensions=Pe,N.properties=q,N.renderLists=Ke,N.shadowMap=Ye,N.state=G,N.info=Ie}g!==1009&&(j=new un(g,t.width,t.height,o,r,i));let ot=new ki(N,H);this.xr=ot,this.getContext=function(){return H},this.getContextAttributes=function(){return H.getContextAttributes()},this.forceContextLoss=function(){let e=Pe.get(`WEBGL_lose_context`);e&&e.loseContext()},this.forceContextRestore=function(){let e=Pe.get(`WEBGL_lose_context`);e&&e.restoreContext()},this.getPixelRatio=function(){return _e},this.setPixelRatio=function(e){e!==void 0&&(_e=e,this.setSize(pe,he,!1))},this.getSize=function(e){return e.set(pe,he)},this.setSize=function(e,n,r=!0){ot.isPresenting?X(`WebGLRenderer: Can't change size while VR device is presenting.`):(pe=e,he=n,t.width=Math.floor(e*_e),t.height=Math.floor(n*_e),r===!0&&(t.style.width=e+`px`,t.style.height=n+`px`),j!==null&&j.setSize(t.width,t.height),this.setViewport(0,0,e,n))},this.getDrawingBufferSize=function(e){return e.set(pe*_e,he*_e).floor()},this.setDrawingBufferSize=function(e,n,r){pe=e,he=n,_e=r,t.width=Math.floor(e*r),t.height=Math.floor(n*r),this.setViewport(0,0,e,n)},this.setEffects=function(e){if(g===1009)W(`WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.`);else{if(e){for(let t=0;t<e.length;t++)if(e[t].isOutputPass===!0){X(`WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.`);break}}j.setEffects(e||[])}},this.getCurrentViewport=function(e){return e.copy(z)},this.getViewport=function(e){return e.copy(be)},this.setViewport=function(e,t,n,r){e.isVector4?be.set(e.x,e.y,e.z,e.w):be.set(e,t,n,r),G.viewport(z.copy(be).multiplyScalar(Me()).round())},this.getScissor=function(e){return e.copy(xe)},this.setScissor=function(e,t,n,r){e.isVector4?xe.set(e.x,e.y,e.z,e.w):xe.set(e,t,n,r),G.scissor(le.copy(xe).multiplyScalar(Me()).round())},this.getScissorTest=function(){return we},this.setScissorTest=function(e){G.setScissorTest(we=e)},this.setOpaqueSort=function(e){ve=e},this.setTransparentSort=function(e){ye=e},this.getClearColor=function(e){return e.copy(Xe.getClearColor())},this.setClearColor=function(){Xe.setClearColor(...arguments)},this.getClearAlpha=function(){return Xe.getClearAlpha()},this.setClearAlpha=function(){Xe.setClearAlpha(...arguments)},this.clear=function(e=!0,t=!0,n=!0){let r=0;if(e){let e=!1;if(R!==null){let t=R.texture.format;e=_.has(t)}if(e){let e=R.texture.type,t=v.has(e),n=Xe.getClearColor(),r=Xe.getClearAlpha(),i=n.r,a=n.g,o=n.b;t?(y[0]=i,y[1]=a,y[2]=o,y[3]=r,H.clearBufferuiv(H.COLOR,0,y)):(b[0]=i,b[1]=a,b[2]=o,b[3]=r,H.clearBufferiv(H.COLOR,0,b))}else r|=H.COLOR_BUFFER_BIT}t&&(r|=H.DEPTH_BUFFER_BIT,this.state.buffers.depth.setMask(!0)),n&&(r|=H.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),r!==0&&H.clear(r)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.setNodesHandler=function(e){e.setRenderer(this),F=e},this.dispose=function(){t.removeEventListener(`webglcontextlost`,st,!1),t.removeEventListener(`webglcontextrestored`,ct,!1),t.removeEventListener(`webglcontextcreationerror`,lt,!1),Xe.dispose(),Ke.dispose(),qe.dispose(),J.dispose(),q.dispose(),Le.dispose(),Ve.dispose(),Be.dispose(),rt.dispose(),it.dispose(),Ue.dispose(),ot.dispose(),ot.removeEventListener(`sessionstart`,gt),ot.removeEventListener(`sessionend`,_t),vt.stop()};function st(e){e.preventDefault(),He(`WebGLRenderer: Context Lost.`),P=!0}function ct(){He(`WebGLRenderer: Context Restored.`),P=!1;let e=Ie.autoReset,t=Ye.enabled,n=Ye.autoUpdate,r=Ye.needsUpdate,i=Ye.type;at(),Ie.autoReset=e,Ye.enabled=t,Ye.autoUpdate=n,Ye.needsUpdate=r,Ye.type=i}function lt(e){W(`WebGLRenderer: A WebGL context could not be created. Reason: `,e.statusMessage)}function ut(e){let t=e.target;t.removeEventListener(`dispose`,ut),dt(t)}function dt(e){ft(e),q.remove(e)}function ft(e){let t=q.get(e).programs;t!==void 0&&(t.forEach(function(e){Ue.releaseProgram(e)}),e.isShaderMaterial&&Ue.releaseShaderCache(e))}this.renderBufferDirect=function(e,t,n,r,i,a){t===null&&(t=Ae);let o=i.isMesh&&i.matrixWorld.determinantAffine()<0,s=kt(e,t,n,r,i);G.setMaterial(r,o);let c=n.index,l=1;if(r.wireframe===!0){if(c=Be.getWireframeAttribute(n),c===void 0)return;l=2}let u=n.drawRange,d=n.attributes.position,f=u.start*l,p=(u.start+u.count)*l;a!==null&&(f=Math.max(f,a.start*l),p=Math.min(p,(a.start+a.count)*l)),c===null?d!=null&&(f=Math.max(f,0),p=Math.min(p,d.count)):(f=Math.max(f,0),p=Math.min(p,c.count));let m=p-f;if(m<0||m===1/0)return;rt.setup(i,r,s,n,c);let h,g=Qe;if(c!==null&&(h=Re.get(c),g=$e,g.setIndex(h)),i.isMesh)r.wireframe===!0?(G.setLineWidth(r.wireframeLinewidth*Me()),g.setMode(H.LINES)):g.setMode(H.TRIANGLES);else if(i.isLine){let e=r.linewidth;e===void 0&&(e=1),G.setLineWidth(e*Me()),i.isLineSegments?g.setMode(H.LINES):i.isLineLoop?g.setMode(H.LINE_LOOP):g.setMode(H.LINE_STRIP)}else i.isPoints?g.setMode(H.POINTS):i.isSprite&&g.setMode(H.TRIANGLES);if(i.isBatchedMesh){if(Pe.get(`WEBGL_multi_draw`))g.renderMultiDraw(i._multiDrawStarts,i._multiDrawCounts,i._multiDrawCount);else{let e=i._multiDrawStarts,t=i._multiDrawCounts,n=i._multiDrawCount,a=c?Re.get(c).bytesPerElement:1,o=q.get(r).currentProgram.getUniforms();for(let r=0;r<n;r++)o.setValue(H,`_gl_DrawID`,r),g.render(e[r]/a,t[r])}}else if(i.isInstancedMesh)g.renderInstances(f,m,i.count);else if(n.isInstancedBufferGeometry){let e=n._maxInstanceCount===void 0?1/0:n._maxInstanceCount,t=Math.min(n.instanceCount,e);g.renderInstances(f,m,t)}else g.render(f,m)};function pt(e,t,n,r){F!==null&&e.isNodeMaterial&&F.setObject(r,e),De===!0&&Je.setState(e,n,!1),e.transparent===!0&&e.side===2&&e.forceSinglePass===!1?(e.side=1,e.needsUpdate=!0,Tt(e,t,r),e.side=0,e.needsUpdate=!0,Tt(e,t,r),e.side=2):Tt(e,t,r)}this.compile=function(e,t,n=null){n===null&&(n=e),F!==null&&F.renderStart(e,t,n),T=qe.get(n),T.init(t),k.push(T),n.traverseVisible(function(e){e.isLight&&e.layers.test(t.layers)&&(T.pushLight(e),e.castShadow&&T.pushShadow(e))}),e!==n&&e.traverseVisible(function(e){e.isLight&&e.layers.test(t.layers)&&(T.pushLight(e),e.castShadow&&T.pushShadow(e))}),T.setupLights(),F!==null&&F.updateLights(T.state.lightsArray),Oe=this.localClippingEnabled,De=Je.init(this.clippingPlanes,Oe),De===!0&&Je.setGlobalState(this.clippingPlanes,t),F!==null&&Ye.render(T.state.shadowsArray,n,t);let r=new Set;return e.traverse(function(e){if(!(e.isMesh||e.isPoints||e.isLine||e.isSprite))return;let i=e.material;if(i){if(Array.isArray(i))for(let a=0;a<i.length;a++){let o=i[a];pt(o,n,t,e),r.add(o)}else pt(i,n,t,e),r.add(i)}}),T=k.pop(),F!==null&&F.renderEnd(),r},this.compileAsync=function(e,t,n=null){let r=this.compile(e,t,n);return new Promise(t=>{function n(){r.forEach(function(e){let t=q.get(e).currentProgram;(t===void 0||t.isReady())&&r.delete(e)}),r.size===0?t(e):setTimeout(n,10)}Pe.get(`KHR_parallel_shader_compile`)===null?setTimeout(n,10):n()})};let mt=null;function ht(e){mt&&mt(e)}function gt(){vt.stop()}function _t(){vt.start()}let vt=new Dt;vt.setAnimationLoop(ht),typeof self<`u`&&vt.setContext(self),this.setAnimationLoop=function(e){mt=e,ot.setAnimationLoop(e),e===null?vt.stop():vt.start()},ot.addEventListener(`sessionstart`,gt),ot.addEventListener(`sessionend`,_t),this.render=function(e,t){if(t!==void 0&&t.isCamera!==!0){W(`WebGLRenderer.render: camera is not an instance of THREE.Camera.`);return}if(P===!0)return;F!==null&&F.renderStart(e,t);let n=ot.enabled===!0&&ot.isPresenting===!0,r=j!==null&&(R===null||n)&&j.begin(N,R);if(e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t.parent===null&&t.matrixWorldAutoUpdate===!0&&t.updateMatrixWorld(),ot.enabled===!0&&ot.isPresenting===!0&&(j===null||j.isCompositing()===!1)&&(ot.cameraAutoUpdate===!0&&ot.updateCamera(t),t=ot.getCamera()),e.isScene===!0&&e.onBeforeRender(N,e,t,R),T=qe.get(e,k.length),T.init(t),T.state.textureUnits=J.getTextureUnits(),k.push(T),B.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),t.isArrayCamera?Ee.setFromArrayCamera(t):Te.setFromProjectionMatrix(B,A,t.reversedDepth),Oe=this.localClippingEnabled,De=Je.init(this.clippingPlanes,Oe),C=Ke.get(e,D.length),C.init(),D.push(C),this.info.render.frame++,ot.enabled===!0&&ot.isPresenting===!0){let e=N.xr.getDepthSensingMesh();e!==null&&yt(e,t,-1/0,N.sortObjects)}yt(e,t,0,N.sortObjects),C.finish(),F!==null&&F.updateLights(T.state.lightsArray),N.sortObjects===!0&&C.sort(ve,ye),je=ot.enabled===!1||ot.isPresenting===!1||ot.hasDepthSensing()===!1,je&&Xe.addToRenderList(C,e),this.info.autoReset===!0&&this.info.reset(),De===!0&&Je.beginShadows();let i=T.state.shadowsArray;if(Ye.render(i,e,t),De===!0&&Je.endShadows(),(r&&j.hasRenderPass())===!1){let n=C.opaque,r=C.transmissive;if(T.setupLights(),t.isArrayCamera){let i=t.cameras;if(r.length>0)for(let t=0,a=i.length;t<a;t++){let a=i[t];xt(n,r,e,a)}je&&Xe.render(e);for(let t=0,n=i.length;t<n;t++){let n=i[t];bt(C,e,n,n.viewport)}}else r.length>0&&xt(n,r,e,t),je&&Xe.render(e),bt(C,e,t)}R!==null&&re===0&&(J.updateMultisampleRenderTarget(R),J.updateRenderTargetMipmap(R)),r&&j.end(N),e.isScene===!0&&e.onAfterRender(N,e,t),rt.resetDefaultState(),ie=-1,oe=null,k.pop(),k.length>0?(T=k[k.length-1],J.setTextureUnits(T.state.textureUnits),De===!0&&Je.setGlobalState(N.clippingPlanes,T.state.camera)):T=null,D.pop(),C=D.length>0?D[D.length-1]:null,F!==null&&F.renderEnd()};function yt(e,t,n,r){if(e.visible===!1)return;if(e.layers.test(t.layers)){if(e.isGroup)n=e.renderOrder;else if(e.isLOD)e.autoUpdate===!0&&e.update(t);else if(e.isLight)T.pushLight(e),e.castShadow&&T.pushShadow(e);else if(e.isSprite){let i=t.isArrayCamera?Ee:Te;if(!e.frustumCulled||e.intersectsFrustum(i)){r&&ke.setFromMatrixPosition(e.matrixWorld).applyMatrix4(B);let i=Ve.update(e),a=e.material;a.visible&&C.push(e,i,a,n,ke.z,null,t)}}else if(e.isMesh||e.isLine||e.isPoints){let i=t.isArrayCamera?Ee:Te;if(!e.frustumCulled||e.intersectsFrustum(i)){let i=Ve.update(e),a=e.material;if(r&&(e.boundingSphere===void 0?(i.boundingSphere===null&&i.computeBoundingSphere(),ke.copy(i.boundingSphere.center)):(e.boundingSphere===null&&e.computeBoundingSphere(),ke.copy(e.boundingSphere.center)),ke.applyMatrix4(e.matrixWorld).applyMatrix4(B)),Array.isArray(a)){let r=i.groups;for(let o=0,s=r.length;o<s;o++){let s=r[o],c=a[s.materialIndex];c&&c.visible&&C.push(e,i,c,n,ke.z,s,t)}}else a.visible&&C.push(e,i,a,n,ke.z,null,t)}}}let i=e.children;for(let e=0,a=i.length;e<a;e++)yt(i[e],t,n,r)}function bt(e,t,n,r){let{opaque:i,transmissive:a,transparent:o}=e;T.setupLightsView(n),De===!0&&Je.setGlobalState(N.clippingPlanes,n),r&&G.viewport(z.copy(r)),i.length>0&&St(i,t,n),a.length>0&&St(a,t,n),o.length>0&&St(o,t,n),G.buffers.depth.setTest(!0),G.buffers.depth.setMask(!0),G.buffers.color.setMask(!0),G.setPolygonOffset(!1)}function xt(e,t,n,r){if((n.isScene===!0?n.overrideMaterial:null)!==null)return;if(T.state.transmissionRenderTarget[r.id]===void 0){let e=Pe.has(`EXT_color_buffer_half_float`)||Pe.has(`EXT_color_buffer_float`);T.state.transmissionRenderTarget[r.id]=new Se(1,1,{generateMipmaps:!0,type:e?ne:O,minFilter:Ce,samples:Math.max(4,U.samples),stencilBuffer:i,resolveDepthBuffer:!1,resolveStencilBuffer:!1,storeMultisampledDepthBuffer:!1,storeMultisampledStencilBuffer:!1,colorSpace:Y.workingColorSpace})}let a=T.state.transmissionRenderTarget[r.id],o=r.viewport||z;a.setSize(o.z*N.transmissionResolutionScale,o.w*N.transmissionResolutionScale);let s=N.getRenderTarget(),c=N.getActiveCubeFace(),l=N.getActiveMipmapLevel();N.setRenderTarget(a),N.getClearColor(de),fe=N.getClearAlpha(),fe<1&&N.setClearColor(16777215,.5),N.clear(),je&&Xe.render(n);let u=N.toneMapping;N.toneMapping=0;let d=r.viewport;if(r.viewport!==void 0&&(r.viewport=void 0),T.setupLightsView(r),De===!0&&Je.setGlobalState(N.clippingPlanes,r),St(e,n,r),J.updateMultisampleRenderTarget(a),J.updateRenderTargetMipmap(a),Pe.has(`WEBGL_multisampled_render_to_texture`)===!1){let e=!1;for(let i=0,a=t.length;i<a;i++){let{object:a,geometry:o,material:s,group:c}=t[i];if(s.side===2&&a.layers.test(r.layers)){let t=s.side;s.side=1,s.needsUpdate=!0,Ct(a,n,r,o,s,c),s.side=t,s.needsUpdate=!0,e=!0}}e===!0&&(J.updateMultisampleRenderTarget(a),J.updateRenderTargetMipmap(a))}N.setRenderTarget(s,c,l),N.setClearColor(de,fe),d!==void 0&&(r.viewport=d),N.toneMapping=u}function St(e,t,n){let r=t.isScene===!0?t.overrideMaterial:null;for(let i=0,a=e.length;i<a;i++){let a=e[i],{object:o,geometry:s,group:c}=a,l=a.material;l.allowOverride===!0&&r!==null&&(l=r),o.layers.test(n.layers)&&Ct(o,t,n,s,l,c)}}function Ct(e,t,n,r,i,a){F!==null&&i.isNodeMaterial&&F.setObject(e,i),e.onBeforeRender(N,t,n,r,i,a),e.modelViewMatrix.multiplyMatrices(n.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix),i.onBeforeRender(N,t,n,r,e,a),i.transparent===!0&&i.side===2&&i.forceSinglePass===!1?(i.side=1,i.needsUpdate=!0,N.renderBufferDirect(n,t,r,i,e,a),i.side=0,i.needsUpdate=!0,N.renderBufferDirect(n,t,r,i,e,a),i.side=2):N.renderBufferDirect(n,t,r,i,e,a),e.onAfterRender(N,t,n,r,i,a)}function wt(e){let t=0;for(let n of e)n.texture!==null&&t++;return t}function Tt(e,t,n){t.isScene!==!0&&(t=Ae);let r=q.get(e),i=T.state.lights,a=T.state.shadowsArray,o=i.state.version,s=Ue.getParameters(e,i.state,a,t,n,T.state.lightProbeGridArray),c=Ue.getProgramCacheKey(s),l=r.programs;r.environment=e.isMeshStandardMaterial||e.isMeshLambertMaterial||e.isMeshPhongMaterial?t.environment:null,r.fog=t.fog;let u=e.isMeshStandardMaterial||e.isMeshLambertMaterial&&!e.envMap||e.isMeshPhongMaterial&&!e.envMap;r.envMap=Le.get(e.envMap||r.environment,u),r.envMapRotation=r.environment!==null&&e.envMap===null?t.environmentRotation:e.envMapRotation,l===void 0&&(e.addEventListener(`dispose`,ut),l=new Map,r.programs=l,r.programVariants=new Map);let d=l.get(c);if(d!==void 0){if(r.currentProgram===d&&r.lightsStateVersion===o)return Q(e,s),d}else s.uniforms=Ue.getUniforms(e),F!==null&&e.isNodeMaterial&&F.build(e,n,s),e.onBeforeCompile(s,N),d=Ue.acquireProgram(s,c),l.set(c,d),r.uniforms=s.uniforms;let f=r.uniforms;return(!e.isShaderMaterial&&!e.isRawShaderMaterial||e.clipping===!0)&&(f.clippingPlanes=Je.uniform),Q(e,s),r.needsLights=jt(e),r.lightsStateVersion=o,r.needsLights&&(f.ambientLightColor.value=i.state.ambient,f.lightProbe.value=i.state.probe,f.sunLights.value=i.state.sun,f.sunLightShadows.value=i.state.sunShadow,f.directionalLights.value=i.state.directional,f.directionalLightShadows.value=i.state.directionalShadow,f.spotLights.value=i.state.spot,f.spotLightShadows.value=i.state.spotShadow,f.rectAreaLights.value=i.state.rectArea,f.ltc_1.value=i.state.rectAreaLTC1,f.ltc_2.value=i.state.rectAreaLTC2,f.pointLights.value=i.state.point,f.pointLightShadows.value=i.state.pointShadow,f.hemisphereLights.value=i.state.hemi,f.sunShadowMatrix.value=i.state.sunShadowMatrix,f.sunShadowCascade.value=i.state.sunShadowCascade,f.directionalShadowMatrix.value=i.state.directionalShadowMatrix,f.spotLightMatrix.value=i.state.spotLightMatrix,f.spotLightMap.value=i.state.spotLightMap,f.pointShadowMatrix.value=i.state.pointShadowMatrix),r.numLightProbeGrids=wt(T.state.lightProbeGridArray),r.currentProgram=d,r.uniformsList=null,d}function Et(e,t,n,r,i){let a=q.get(e),o=a.currentProgram.id+`,`+r+`,`+i,s=a.programVariants.get(o);return s===void 0?(s=Tt(e,t,n),a.programVariants.set(o,s)):(a.currentProgram=s,a.uniformsList=null,a.outputColorSpace=r,a.toneMapping=i),s}function Z(e){if(e.uniformsList===null){let t=e.currentProgram.getUniforms();e.uniformsList=yr.seqWithValue(t.seq,e.uniforms)}return e.uniformsList}function Q(e,t){let n=q.get(e);n.outputColorSpace=t.outputColorSpace,n.batching=t.batching,n.batchingColor=t.batchingColor,n.instancing=t.instancing,n.instancingColor=t.instancingColor,n.instancingMorph=t.instancingMorph,n.skinning=t.skinning,n.morphTargets=t.morphTargets,n.morphNormals=t.morphNormals,n.morphColors=t.morphColors,n.morphTargetsCount=t.morphTargetsCount,n.numClippingPlanes=t.numClippingPlanes,n.numIntersection=t.numClipIntersection,n.vertexAlphas=t.vertexAlphas,n.vertexTangents=t.vertexTangents,n.toneMapping=t.toneMapping}function kt(e,t,n,r,i){t.isScene!==!0&&(t=Ae),J.resetTextureUnits();let a=t.fog,o=r.isMeshStandardMaterial||r.isMeshLambertMaterial||r.isMeshPhongMaterial?t.environment:null,s=R===null?N.outputColorSpace:R.isXRRenderTarget===!0?R.texture.colorSpace:Y.workingColorSpace,c=r.isMeshStandardMaterial||r.isMeshLambertMaterial&&!r.envMap||r.isMeshPhongMaterial&&!r.envMap,l=Le.get(r.envMap||o,c),u=r.vertexColors===!0&&!!n.attributes.color&&n.attributes.color.itemSize===4,d=!!n.attributes.tangent&&(!!r.normalMap||r.anisotropy>0),f=!!n.morphAttributes.position,p=!!n.morphAttributes.normal,m=!!n.morphAttributes.color,h=0;r.toneMapped&&(R===null||R.isXRRenderTarget===!0)&&(h=N.toneMapping);let g=n.morphAttributes.position||n.morphAttributes.normal||n.morphAttributes.color,_=g===void 0?0:g.length,v=q.get(r),y=T.state.lights;if(De===!0&&(Oe===!0||e!==oe)){let t=e===oe&&r.id===ie;Je.setState(r,e,t)}let b=!1,S=!1;r.version===v.__version?v.needsLights&&v.lightsStateVersion!==y.state.version||i.isBatchedMesh&&v.batching===!1||!i.isBatchedMesh&&v.batching===!0||i.isBatchedMesh&&v.batchingColor===!0&&i._colorsTexture===null||i.isBatchedMesh&&v.batchingColor===!1&&i._colorsTexture!==null||i.isInstancedMesh&&v.instancing===!1||!i.isInstancedMesh&&v.instancing===!0||i.isSkinnedMesh&&v.skinning===!1||!i.isSkinnedMesh&&v.skinning===!0||i.isInstancedMesh&&v.instancingColor===!0&&i.instanceColor===null||i.isInstancedMesh&&v.instancingColor===!1&&i.instanceColor!==null||i.isInstancedMesh&&v.instancingMorph===!0&&i.morphTexture===null||i.isInstancedMesh&&v.instancingMorph===!1&&i.morphTexture!==null?b=!0:v.envMap===l?r.fog===!0&&v.fog!==a||v.numClippingPlanes!==void 0&&(v.numClippingPlanes!==Je.numPlanes||v.numIntersection!==Je.numIntersection)?b=!0:v.vertexAlphas===u&&v.vertexTangents===d&&v.morphTargets===f&&v.morphNormals===p&&v.morphColors===m&&v.morphTargetsCount===_&&v.numLightProbeGrids===wt(T.state.lightProbeGridArray)?(v.outputColorSpace!==s||v.toneMapping!==h)&&(S=!0):b=!0:b=!0:(b=!0,v.__version=r.version);let C=v.currentProgram;(b===!0||S===!0)&&(C=S===!0?Et(r,t,i,s,h):Tt(r,t,i),F&&r.isNodeMaterial&&F.onUpdateProgram(r,C,v));let w=!1,E=!1,D=!1,O=C.getUniforms(),k=v.uniforms;if(G.useProgram(C.program)&&(w=!0,E=!0,D=!0),r.id!==ie&&(ie=r.id,E=!0),w||oe!==e){G.buffers.depth.getReversed()&&e.reversedDepth!==!0&&(e._reversedDepth=!0,e.updateProjectionMatrix()),O.setValue(H,`projectionMatrix`,e.projectionMatrix),O.setValue(H,`viewMatrix`,e.matrixWorldInverse);let t=O.map.cameraPosition;t!==void 0&&t.setValue(H,V.setFromMatrixPosition(e.matrixWorld)),U.logarithmicDepthBuffer&&O.setValue(H,`logDepthBufFC`,2/(Math.log(e.far+1)/Math.LN2)),(r.isMeshPhongMaterial||r.isMeshToonMaterial||r.isMeshLambertMaterial||r.isMeshBasicMaterial||r.isMeshStandardMaterial||r.isShaderMaterial)&&O.setValue(H,`isOrthographic`,e.isOrthographicCamera===!0),oe!==e&&(oe=e,E=!0,D=!0)}if(v.needsLights&&(y.state.sunShadowMap.length>0&&O.setValue(H,`sunShadowMap`,y.state.sunShadowMap,J),y.state.directionalShadowMap.length>0&&O.setValue(H,`directionalShadowMap`,y.state.directionalShadowMap,J),y.state.spotShadowMap.length>0&&O.setValue(H,`spotShadowMap`,y.state.spotShadowMap,J),y.state.pointShadowMap.length>0&&O.setValue(H,`pointShadowMap`,y.state.pointShadowMap,J)),i.isSkinnedMesh){O.setOptional(H,i,`bindMatrix`),O.setOptional(H,i,`bindMatrixInverse`);let e=i.skeleton;e&&(e.boneTexture===null&&e.computeBoneTexture(),O.setValue(H,`boneTexture`,e.boneTexture,J))}i.isBatchedMesh&&(O.setOptional(H,i,`batchingTexture`),O.setValue(H,`batchingTexture`,i._matricesTexture,J),O.setOptional(H,i,`batchingIdTexture`),O.setValue(H,`batchingIdTexture`,i._indirectTexture,J),O.setOptional(H,i,`batchingColorTexture`),i._colorsTexture!==null&&O.setValue(H,`batchingColorTexture`,i._colorsTexture,J));let A=n.morphAttributes;if((A.position!==void 0||A.normal!==void 0||A.color!==void 0)&&Ze.update(i,n,C),(E||v.receiveShadow!==i.receiveShadow)&&(v.receiveShadow=i.receiveShadow,O.setValue(H,`receiveShadow`,i.receiveShadow)),(r.isMeshStandardMaterial||r.isMeshLambertMaterial||r.isMeshPhongMaterial)&&r.envMap===null&&t.environment!==null&&(k.envMapIntensity.value=t.environmentIntensity),k.dfgLUT!==void 0&&(k.dfgLUT.value=Ii()),E){if(O.setValue(H,`toneMappingExposure`,N.toneMappingExposure),v.needsLights&&At(k,D),a&&r.fog===!0&&Ge.refreshFogUniforms(k,a),Ge.refreshMaterialUniforms(k,r,_e,he,T.state.transmissionRenderTarget[e.id]),v.needsLights&&v.numLightProbeGrids>0){let e=x,t=0;for(let n of T.state.lightProbeGridArray)n.texture!==null&&(e.textures[t]=n.texture,e.min[t]=n.boundingBox.min,e.max[t]=n.boundingBox.max,e.resolution[t]=n.resolution,t++);for(let n in e)e[n].length=t;k.probesSH.value=e.textures,k.probesMin.value=e.min,k.probesMax.value=e.max,k.probesResolution.value=e.resolution}yr.upload(H,Z(v),k,J)}if(r.isShaderMaterial&&r.uniformsNeedUpdate===!0&&(yr.upload(H,Z(v),k,J),r.uniformsNeedUpdate=!1),r.isSpriteMaterial&&O.setValue(H,`center`,i.center),O.setValue(H,`modelViewMatrix`,i.modelViewMatrix),O.setValue(H,`normalMatrix`,i.normalMatrix),O.setValue(H,`modelMatrix`,i.matrixWorld),r.uniformsGroups!==void 0){let e=r.uniformsGroups;for(let t=0,n=e.length;t<n;t++){let n=e[t];it.update(n,C),it.bind(n,C)}}return C}function At(e,t){e.ambientLightColor.needsUpdate=t,e.lightProbe.needsUpdate=t,e.sunLights.needsUpdate=t,e.sunLightShadows.needsUpdate=t,e.directionalLights.needsUpdate=t,e.directionalLightShadows.needsUpdate=t,e.pointLights.needsUpdate=t,e.pointLightShadows.needsUpdate=t,e.spotLights.needsUpdate=t,e.spotLightShadows.needsUpdate=t,e.rectAreaLights.needsUpdate=t,e.hemisphereLights.needsUpdate=t}function jt(e){return e.isMeshLambertMaterial||e.isMeshToonMaterial||e.isMeshPhongMaterial||e.isMeshStandardMaterial||e.isShadowMaterial||e.isShaderMaterial&&e.lights===!0}this.getActiveCubeFace=function(){return te},this.getActiveMipmapLevel=function(){return re},this.getRenderTarget=function(){return R},this.setRenderTargetTextures=function(e,t,n){let r=q.get(e);r.__autoAllocateDepthBuffer=e.resolveDepthBuffer===!1,r.__autoAllocateDepthBuffer===!1&&(r.__useRenderToTexture=!1),q.get(e.texture).__webglTexture=t,q.get(e.depthTexture).__webglTexture=r.__autoAllocateDepthBuffer?void 0:n,r.__hasExternalTextures=!0},this.setRenderTargetFramebuffer=function(e,t){let n=q.get(e);n.__webglFramebuffer=t,n.__useDefaultFramebuffer=t===void 0},this.setRenderTarget=function(e,t=0,n=0){R=e,te=t,re=n;let r=null,i=!1,a=!1;if(e){let o=q.get(e);if(o.__useDefaultFramebuffer!==void 0){G.bindFramebuffer(H.FRAMEBUFFER,o.__webglFramebuffer),z.copy(e.viewport),le.copy(e.scissor),ue=e.scissorTest,G.viewport(z),G.scissor(le),G.setScissorTest(ue),ie=-1;return}if(o.__webglFramebuffer===void 0)J.setupRenderTarget(e);else if(o.__hasExternalTextures)J.rebindTextures(e,q.get(e.texture).__webglTexture,q.get(e.depthTexture).__webglTexture);else if(e.depthBuffer){let t=e.depthTexture;if(o.__boundDepthTexture!==t){if(t!==null&&q.has(t)&&(e.width!==t.image.width||e.height!==t.image.height))throw Error(`THREE.WebGLRenderer: Attached DepthTexture is initialized to the incorrect size.`);J.setupDepthRenderbuffer(e)}}let s=e.texture;(s.isData3DTexture||s.isDataArrayTexture||s.isCompressedArrayTexture)&&(a=!0);let c=q.get(e).__webglFramebuffer;e.isWebGLCubeRenderTarget?(r=Array.isArray(c[t])?c[t][n]:c[t],i=!0):r=e.samples>0&&J.useMultisampledRTT(e)===!1?q.get(e).__webglMultisampledFramebuffer:Array.isArray(c)?c[n]:c,z.copy(e.viewport),le.copy(e.scissor),ue=e.scissorTest}else z.copy(be).multiplyScalar(_e).floor(),le.copy(xe).multiplyScalar(_e).floor(),ue=we;if(n!==0&&(r=I),G.bindFramebuffer(H.FRAMEBUFFER,r)&&G.drawBuffers(e,r),G.viewport(z),G.scissor(le),G.setScissorTest(ue),i){let r=q.get(e.texture);H.framebufferTexture2D(H.FRAMEBUFFER,H.COLOR_ATTACHMENT0,H.TEXTURE_CUBE_MAP_POSITIVE_X+t,r.__webglTexture,n)}else if(a){let r=t;for(let t=0;t<e.textures.length;t++){let i=q.get(e.textures[t]);H.framebufferTextureLayer(H.FRAMEBUFFER,H.COLOR_ATTACHMENT0+t,i.__webglTexture,n,r)}}else if(e!==null&&n!==0){let t=q.get(e.texture);H.framebufferTexture2D(H.FRAMEBUFFER,H.COLOR_ATTACHMENT0,H.TEXTURE_2D,t.__webglTexture,n)}ie=-1};function Mt(e){let t=q.get(e);return(t.__readFormat!==e.format||t.__readType!==e.type)&&(t.__readFormat=e.format,t.__readType=e.type,t.__formatReadable=U.textureFormatReadable(e.format),t.__typeReadable=U.textureTypeReadable(e.type)),t}this.readRenderTargetPixels=function(e,t,n,r,i,a,o,s=0){if(!(e&&e.isWebGLRenderTarget)){W(`WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.`);return}let c=q.get(e).__webglFramebuffer;if(e.isWebGLCubeRenderTarget&&o!==void 0&&(c=c[o],Array.isArray(c)&&(c=c[0])),c){G.bindFramebuffer(H.FRAMEBUFFER,c);try{let o=e.textures[s],c=o.format,l=o.type;e.textures.length>1&&H.readBuffer(H.COLOR_ATTACHMENT0+s);let u=Mt(o);if(u.__formatReadable===!1){W(`WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.`);return}if(u.__typeReadable===!1){W(`WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.`);return}t>=0&&t<=e.width-r&&n>=0&&n<=e.height-i&&H.readPixels(t,n,r,i,et.convert(c),et.convert(l),a)}finally{let e=R===null?null:q.get(R).__webglFramebuffer;G.bindFramebuffer(H.FRAMEBUFFER,e)}}},this.readRenderTargetPixelsAsync=async function(e,t,n,r,i,a,o,s=0){if(!(e&&e.isWebGLRenderTarget))throw Error(`THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.`);let c=q.get(e).__webglFramebuffer;if(e.isWebGLCubeRenderTarget&&o!==void 0&&(c=c[o],Array.isArray(c)&&(c=c[0])),c){if(t>=0&&t<=e.width-r&&n>=0&&n<=e.height-i){G.bindFramebuffer(H.FRAMEBUFFER,c);let o=e.textures[s],l=o.format,u=o.type;e.textures.length>1&&H.readBuffer(H.COLOR_ATTACHMENT0+s);let d=Mt(o);if(d.__formatReadable===!1)throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.`);if(d.__typeReadable===!1)throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.`);let f=H.createBuffer();H.bindBuffer(H.PIXEL_PACK_BUFFER,f),H.bufferData(H.PIXEL_PACK_BUFFER,a.byteLength,H.STREAM_READ),H.readPixels(t,n,r,i,et.convert(l),et.convert(u),0),H.bindBuffer(H.PIXEL_PACK_BUFFER,null);let p=R===null?null:q.get(R).__webglFramebuffer;G.bindFramebuffer(H.FRAMEBUFFER,p);let m=H.fenceSync(H.SYNC_GPU_COMMANDS_COMPLETE,0);return H.flush(),await tt(H,m,4),H.bindBuffer(H.PIXEL_PACK_BUFFER,f),H.getBufferSubData(H.PIXEL_PACK_BUFFER,0,a),H.bindBuffer(H.PIXEL_PACK_BUFFER,null),H.deleteBuffer(f),H.deleteSync(m),a}throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.`)}},this.copyFramebufferToTexture=function(e,t=null,n=0){let r=2**-n,i=Math.floor(e.image.width*r),a=Math.floor(e.image.height*r),o=t===null?0:t.x,s=t===null?0:t.y;J.setTexture2D(e,0),H.copyTexSubImage2D(H.TEXTURE_2D,n,0,0,o,s,i,a),G.unbindTexture()},this.copyTextureToTexture=function(e,t,n=null,r=null,i=0,a=0){let o,s,c,l,u,d,f,p,m,h=e.isCompressedTexture?e.mipmaps[a]:e.image;if(n!==null)o=n.max.x-n.min.x,s=n.max.y-n.min.y,c=n.isBox3?n.max.z-n.min.z:1,l=n.min.x,u=n.min.y,d=n.isBox3?n.min.z:0;else{let t=2**-i;o=Math.floor(h.width*t),s=Math.floor(h.height*t),c=e.isDataArrayTexture?h.depth:e.isData3DTexture?Math.floor(h.depth*t):1,l=0,u=0,d=0}r===null?(f=0,p=0,m=0):(f=r.x,p=r.y,m=r.z);let g=et.convert(t.format),_=et.convert(t.type),v;t.isData3DTexture?(J.setTexture3D(t,0),v=H.TEXTURE_3D):t.isDataArrayTexture||t.isCompressedArrayTexture?(J.setTexture2DArray(t,0),v=H.TEXTURE_2D_ARRAY):(J.setTexture2D(t,0),v=H.TEXTURE_2D),G.activeTexture(H.TEXTURE0),G.pixelStorei(H.UNPACK_FLIP_Y_WEBGL,t.flipY),G.pixelStorei(H.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),G.pixelStorei(H.UNPACK_ALIGNMENT,t.unpackAlignment);let y=G.getParameter(H.UNPACK_ROW_LENGTH),b=G.getParameter(H.UNPACK_IMAGE_HEIGHT),x=G.getParameter(H.UNPACK_SKIP_PIXELS),S=G.getParameter(H.UNPACK_SKIP_ROWS),C=G.getParameter(H.UNPACK_SKIP_IMAGES);G.pixelStorei(H.UNPACK_ROW_LENGTH,h.width),G.pixelStorei(H.UNPACK_IMAGE_HEIGHT,h.height),G.pixelStorei(H.UNPACK_SKIP_PIXELS,l),G.pixelStorei(H.UNPACK_SKIP_ROWS,u),G.pixelStorei(H.UNPACK_SKIP_IMAGES,d);let w=e.isDataArrayTexture||e.isData3DTexture,T=t.isDataArrayTexture||t.isData3DTexture;if(e.isDepthTexture){let n=q.get(e),r=q.get(t),h=q.get(n.__renderTarget),g=q.get(r.__renderTarget);G.bindFramebuffer(H.READ_FRAMEBUFFER,h.__webglFramebuffer),G.bindFramebuffer(H.DRAW_FRAMEBUFFER,g.__webglFramebuffer);for(let n=0;n<c;n++)w&&(H.framebufferTextureLayer(H.READ_FRAMEBUFFER,H.COLOR_ATTACHMENT0,q.get(e).__webglTexture,i,d+n),H.framebufferTextureLayer(H.DRAW_FRAMEBUFFER,H.COLOR_ATTACHMENT0,q.get(t).__webglTexture,a,m+n)),H.blitFramebuffer(l,u,l+o,u+s,f,p,f+o,p+s,H.DEPTH_BUFFER_BIT,H.NEAREST);G.bindFramebuffer(H.READ_FRAMEBUFFER,null),G.bindFramebuffer(H.DRAW_FRAMEBUFFER,null)}else if(i!==0||e.isRenderTargetTexture||q.has(e)){let n=q.get(e),r=q.get(t);G.bindFramebuffer(H.READ_FRAMEBUFFER,L),G.bindFramebuffer(H.DRAW_FRAMEBUFFER,ee);for(let e=0;e<c;e++)w?H.framebufferTextureLayer(H.READ_FRAMEBUFFER,H.COLOR_ATTACHMENT0,n.__webglTexture,i,d+e):H.framebufferTexture2D(H.READ_FRAMEBUFFER,H.COLOR_ATTACHMENT0,H.TEXTURE_2D,n.__webglTexture,i),T?H.framebufferTextureLayer(H.DRAW_FRAMEBUFFER,H.COLOR_ATTACHMENT0,r.__webglTexture,a,m+e):H.framebufferTexture2D(H.DRAW_FRAMEBUFFER,H.COLOR_ATTACHMENT0,H.TEXTURE_2D,r.__webglTexture,a),i===0?T?H.copyTexSubImage3D(v,a,f,p,m+e,l,u,o,s):H.copyTexSubImage2D(v,a,f,p,l,u,o,s):H.blitFramebuffer(l,u,l+o,u+s,f,p,f+o,p+s,H.COLOR_BUFFER_BIT,H.NEAREST);G.bindFramebuffer(H.READ_FRAMEBUFFER,null),G.bindFramebuffer(H.DRAW_FRAMEBUFFER,null)}else T?e.isDataTexture||e.isData3DTexture?H.texSubImage3D(v,a,f,p,m,o,s,c,g,_,h.data):t.isCompressedArrayTexture?H.compressedTexSubImage3D(v,a,f,p,m,o,s,c,g,h.data):H.texSubImage3D(v,a,f,p,m,o,s,c,g,_,h):e.isDataTexture?H.texSubImage2D(H.TEXTURE_2D,a,f,p,o,s,g,_,h.data):e.isCompressedTexture?H.compressedTexSubImage2D(H.TEXTURE_2D,a,f,p,h.width,h.height,g,h.data):H.texSubImage2D(H.TEXTURE_2D,a,f,p,o,s,g,_,h);G.pixelStorei(H.UNPACK_ROW_LENGTH,y),G.pixelStorei(H.UNPACK_IMAGE_HEIGHT,b),G.pixelStorei(H.UNPACK_SKIP_PIXELS,x),G.pixelStorei(H.UNPACK_SKIP_ROWS,S),G.pixelStorei(H.UNPACK_SKIP_IMAGES,C),a===0&&t.generateMipmaps===!0&&t.mipmapsAutoUpdate===!0&&H.generateMipmap(v),G.unbindTexture()},this.initRenderTarget=function(e){q.get(e).__webglFramebuffer===void 0&&J.setupRenderTarget(e)},this.initTexture=function(e){e.isCubeTexture?J.setTextureCube(e,0):e.isData3DTexture?J.setTexture3D(e,0):e.isDataArrayTexture||e.isCompressedArrayTexture?J.setTexture2DArray(e,0):J.setTexture2D(e,0),G.unbindTexture()},this.resetState=function(){te=0,re=0,R=null,G.reset(),rt.reset()},typeof __THREE_DEVTOOLS__<`u`&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent(`observe`,{detail:this}))}get coordinateSystem(){return A}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(e){this._outputColorSpace=e;let t=this.getContext();t.drawingBufferColorSpace=Y._getDrawingBufferColorSpace(e),t.unpackColorSpace=Y._getUnpackColorSpace()}};function Ri(e,t){if(t===0)return console.warn(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.`),e;if(t===2||t===1){let n=e.getIndex();if(n===null){let t=[],r=e.getAttribute(`position`);if(r!==void 0){for(let e=0;e<r.count;e++)t.push(e);e.setIndex(t),n=e.getIndex()}else return console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.`),e}let r=n.count-2,i=[];if(t===2)for(let e=1;e<=r;e++)i.push(n.getX(0)),i.push(n.getX(e)),i.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(i.push(n.getX(e)),i.push(n.getX(e+1)),i.push(n.getX(e+2))):(i.push(n.getX(e+2)),i.push(n.getX(e+1)),i.push(n.getX(e)));return i.length/3!==r&&console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.`),e.setIndex(i),e.clearGroups(),e}return console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:`,t),e}function zi(e){let t=new Map,n=new Map,r=e.clone();return Bi(e,r,function(e,r){t.set(r,e),n.set(e,r)}),r.traverse(function(e){if(!e.isSkinnedMesh)return;let r=e,i=t.get(e),a=i.skeleton.bones;r.skeleton=i.skeleton.clone(),r.bindMatrix.copy(i.bindMatrix),r.skeleton.bones=a.map(function(e){return n.get(e)}),r.bind(r.skeleton,r.bindMatrix)}),r}function Bi(e,t,n){n(e,t);for(let r=0;r<e.children.length;r++)Bi(e.children[r],t.children[r],n)}var Vi=class extends pt{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new qi(e)}),this.register(function(e){return new Ji(e)}),this.register(function(e){return new Yi(e)}),this.register(function(e){return new ia(e)}),this.register(function(e){return new aa(e)}),this.register(function(e){return new oa(e)}),this.register(function(e){return new Zi(e)}),this.register(function(e){return new Qi(e)}),this.register(function(e){return new $i(e)}),this.register(function(e){return new ea(e)}),this.register(function(e){return new Ki(e)}),this.register(function(e){return new ta(e)}),this.register(function(e){return new Xi(e)}),this.register(function(e){return new ra(e)}),this.register(function(e){return new na(e)}),this.register(function(e){return new Wi(e)}),this.register(function(e){return new sa(e,$.EXT_MESHOPT_COMPRESSION)}),this.register(function(e){return new sa(e,$.KHR_MESHOPT_COMPRESSION)}),this.register(function(e){return new ca(e)})}load(e,t,n,r){let i=this,a;if(this.resourcePath!==``)a=this.resourcePath;else if(this.path!==``){let t=$e.extractUrlBase(e);a=$e.resolveURL(t,this.path)}else a=$e.extractUrlBase(e);this.manager.itemStart(e);let o=function(t){r?r(t):console.error(t),i.manager.itemError(e),i.manager.itemEnd(e)},s=new h(this.manager);s.setPriority(this.priority),s.setCache(this.cache),s.setPath(this.path),s.setResponseType(`arraybuffer`),s.setRequestHeader(this.requestHeader),s.setWithCredentials(this.withCredentials),s.load(e,function(n){try{i.parse(n,a,function(n){t(n),i.manager.itemEnd(e)},o)}catch(e){o(e)}},n,o)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,r){let i,a={},o={},s=new TextDecoder;if(typeof e==`string`)i=JSON.parse(e);else if(e instanceof ArrayBuffer){if(s.decode(new Uint8Array(e,0,4))===la){try{a[$.KHR_BINARY_GLTF]=new fa(e)}catch(e){r&&r(e);return}i=JSON.parse(a[$.KHR_BINARY_GLTF].content)}else i=JSON.parse(s.decode(e))}else i=e;if(i.asset===void 0||i.asset.version[0]<2){r&&r(Error(`THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.`));return}let c=new Ra(i,{path:t||this.resourcePath||``,crossOrigin:this.crossOrigin,priority:this.priority,cache:this.cache,withCredentials:this.withCredentials,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){let t=this.pluginCallbacks[e](c);t.name||console.error(`THREE.GLTFLoader: Invalid plugin found: missing name`),o[t.name]=t,a[t.name]=!0}if(i.extensionsUsed)for(let e=0;e<i.extensionsUsed.length;++e){let t=i.extensionsUsed[e],n=i.extensionsRequired||[];switch(t){case $.KHR_MATERIALS_UNLIT:a[t]=new Gi;break;case $.KHR_DRACO_MESH_COMPRESSION:a[t]=new pa(i,this.dracoLoader);break;case $.KHR_TEXTURE_TRANSFORM:a[t]=new ma;break;case $.KHR_MESH_QUANTIZATION:a[t]=new ha;break;default:n.indexOf(t)>=0&&o[t]===void 0&&console.warn(`THREE.GLTFLoader: Unknown extension "`+t+`".`)}}c.setExtensions(a),c.setPlugins(o),c.parse(n,r)}parseAsync(e,t){let n=this;return new Promise(function(r,i){n.parse(e,t,r,i)})}};function Hi(){let e={};return{get:function(t){return e[t]},add:function(t,n){e[t]=n},remove:function(t){delete e[t]},removeAll:function(){e={}}}}function Ui(e,t,n){let r=e.json.materials[t];return r.extensions&&r.extensions[n]?r.extensions[n]:null}var $={KHR_BINARY_GLTF:`KHR_binary_glTF`,KHR_DRACO_MESH_COMPRESSION:`KHR_draco_mesh_compression`,KHR_LIGHTS_PUNCTUAL:`KHR_lights_punctual`,KHR_MATERIALS_CLEARCOAT:`KHR_materials_clearcoat`,KHR_MATERIALS_DIFFUSE_ROUGHNESS:`KHR_materials_diffuse_roughness`,KHR_MATERIALS_DISPERSION:`KHR_materials_dispersion`,KHR_MATERIALS_IOR:`KHR_materials_ior`,KHR_MATERIALS_SHEEN:`KHR_materials_sheen`,KHR_MATERIALS_SPECULAR:`KHR_materials_specular`,KHR_MATERIALS_TRANSMISSION:`KHR_materials_transmission`,KHR_MATERIALS_IRIDESCENCE:`KHR_materials_iridescence`,KHR_MATERIALS_ANISOTROPY:`KHR_materials_anisotropy`,KHR_MATERIALS_UNLIT:`KHR_materials_unlit`,KHR_MATERIALS_VOLUME:`KHR_materials_volume`,KHR_TEXTURE_BASISU:`KHR_texture_basisu`,KHR_TEXTURE_TRANSFORM:`KHR_texture_transform`,KHR_MESH_QUANTIZATION:`KHR_mesh_quantization`,KHR_MATERIALS_EMISSIVE_STRENGTH:`KHR_materials_emissive_strength`,EXT_MATERIALS_BUMP:`EXT_materials_bump`,EXT_TEXTURE_WEBP:`EXT_texture_webp`,EXT_TEXTURE_AVIF:`EXT_texture_avif`,EXT_MESHOPT_COMPRESSION:`EXT_meshopt_compression`,KHR_MESHOPT_COMPRESSION:`KHR_meshopt_compression`,EXT_MESH_GPU_INSTANCING:`EXT_mesh_gpu_instancing`},Wi=class{constructor(e){this.parser=e,this.name=$.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){let e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n<r;n++){let r=t[n];r.extensions&&r.extensions[this.name]&&r.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,r.extensions[this.name].light)}}_loadLight(e){let t=this.parser,n=`light:`+e,r=t.cache.get(n);if(r)return r;let i=t.json,o=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e],s,l=new K(16777215);o.color!==void 0&&l.setRGB(o.color[0],o.color[1],o.color[2],a);let u=o.range===void 0?0:o.range;switch(o.type){case`directional`:s=new f(l),s.target.position.set(0,0,-1),s.add(s.target);break;case`point`:s=new m(l),s.distance=u;break;case`spot`:s=new c(l),s.distance=u,o.spot=o.spot||{},o.spot.innerConeAngle=o.spot.innerConeAngle===void 0?0:o.spot.innerConeAngle,o.spot.outerConeAngle=o.spot.outerConeAngle===void 0?Math.PI/4:o.spot.outerConeAngle,s.angle=o.spot.outerConeAngle,s.penumbra=1-o.spot.innerConeAngle/o.spot.outerConeAngle,s.target.position.set(0,0,-1),s.add(s.target);break;default:throw Error(`THREE.GLTFLoader: Unexpected light type: `+o.type)}return s.position.set(0,0,0),Aa(s,o),o.intensity!==void 0&&(s.intensity=o.intensity),s.name=t.createUniqueName(o.name||`light_`+e),r=Promise.resolve(s),t.cache.add(n,r),r}getDependency(e,t){if(e===`light`)return this._loadLight(t)}createNodeAttachment(e){let t=this,n=this.parser,r=n.json.nodes[e],i=(r.extensions&&r.extensions[this.name]||{}).light;return i===void 0?null:this._loadLight(i).then(function(e){return n._getNodeRef(t.cache,i,e)})}},Gi=class{constructor(){this.name=$.KHR_MATERIALS_UNLIT}getMaterialType(){return H}extendParams(e,t,n){let r=[];e.color=new K(1,1,1),e.opacity=1;let i=t.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){let t=i.baseColorFactor;e.color.setRGB(t[0],t[1],t[2],a),e.opacity=t[3]}i.baseColorTexture!==void 0&&r.push(n.assignTexture(e,`map`,i.baseColorTexture,ce))}return Promise.all(r)}},Ki=class{constructor(e){this.parser=e,this.name=$.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){let n=Ui(this.parser,e,this.name);return n===null||n.emissiveStrength!==void 0&&(t.emissiveIntensity=n.emissiveStrength),Promise.resolve()}},qi=class{constructor(e){this.parser=e,this.name=$.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){return Ui(this.parser,e,this.name)===null?null:U}extendMaterialParams(e,t){let n=Ui(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];if(n.clearcoatFactor!==void 0&&(t.clearcoat=n.clearcoatFactor),n.clearcoatTexture!==void 0&&r.push(this.parser.assignTexture(t,`clearcoatMap`,n.clearcoatTexture)),n.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=n.clearcoatRoughnessFactor),n.clearcoatRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,`clearcoatRoughnessMap`,n.clearcoatRoughnessTexture)),n.clearcoatNormalTexture!==void 0&&(r.push(this.parser.assignTexture(t,`clearcoatNormalMap`,n.clearcoatNormalTexture)),n.clearcoatNormalTexture.scale!==void 0)){let e=n.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new ve(e,e)}return Promise.all(r)}},Ji=class{constructor(e){this.parser=e,this.name=$.KHR_MATERIALS_DIFFUSE_ROUGHNESS}getMaterialType(e){return Ui(this.parser,e,this.name)===null?null:U}extendMaterialParams(e,t){let n=Ui(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return t.diffuseRoughness=n.diffuseRoughnessFactor===void 0?0:n.diffuseRoughnessFactor,n.diffuseRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,`diffuseRoughnessMap`,n.diffuseRoughnessTexture)),Promise.all(r)}},Yi=class{constructor(e){this.parser=e,this.name=$.KHR_MATERIALS_DISPERSION}getMaterialType(e){return Ui(this.parser,e,this.name)===null?null:U}extendMaterialParams(e,t){let n=Ui(this.parser,e,this.name);return n===null||(t.dispersion=n.dispersion===void 0?0:n.dispersion),Promise.resolve()}},Xi=class{constructor(e){this.parser=e,this.name=$.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){return Ui(this.parser,e,this.name)===null?null:U}extendMaterialParams(e,t){let n=Ui(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.iridescenceFactor!==void 0&&(t.iridescence=n.iridescenceFactor),n.iridescenceTexture!==void 0&&r.push(this.parser.assignTexture(t,`iridescenceMap`,n.iridescenceTexture)),n.iridescenceIor!==void 0&&(t.iridescenceIOR=n.iridescenceIor),n.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessMinimum=n.iridescenceThicknessMinimum),n.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessMaximum=n.iridescenceThicknessMaximum),n.iridescenceThicknessTexture!==void 0&&r.push(this.parser.assignTexture(t,`iridescenceThicknessMap`,n.iridescenceThicknessTexture)),Promise.all(r)}},Zi=class{constructor(e){this.parser=e,this.name=$.KHR_MATERIALS_SHEEN}getMaterialType(e){return Ui(this.parser,e,this.name)===null?null:U}extendMaterialParams(e,t){let n=Ui(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];if(t.sheenColor=new K(0,0,0),t.sheenRoughness=0,t.sheen=1,n.sheenColorFactor!==void 0){let e=n.sheenColorFactor;t.sheenColor.setRGB(e[0],e[1],e[2],a)}return n.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=n.sheenRoughnessFactor),n.sheenColorTexture!==void 0&&r.push(this.parser.assignTexture(t,`sheenColorMap`,n.sheenColorTexture,ce)),n.sheenRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,`sheenRoughnessMap`,n.sheenRoughnessTexture)),Promise.all(r)}},Qi=class{constructor(e){this.parser=e,this.name=$.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){return Ui(this.parser,e,this.name)===null?null:U}extendMaterialParams(e,t){let n=Ui(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.transmissionFactor!==void 0&&(t.transmission=n.transmissionFactor),n.transmissionTexture!==void 0&&r.push(this.parser.assignTexture(t,`transmissionMap`,n.transmissionTexture)),Promise.all(r)}},$i=class{constructor(e){this.parser=e,this.name=$.KHR_MATERIALS_VOLUME}getMaterialType(e){return Ui(this.parser,e,this.name)===null?null:U}extendMaterialParams(e,t){let n=Ui(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];t.thickness=n.thicknessFactor===void 0?0:n.thicknessFactor,n.thicknessTexture!==void 0&&r.push(this.parser.assignTexture(t,`thicknessMap`,n.thicknessTexture)),t.attenuationDistance=n.attenuationDistance||1/0;let i=n.attenuationColor||[1,1,1];return t.attenuationColor=new K().setRGB(i[0],i[1],i[2],a),Promise.all(r)}},ea=class{constructor(e){this.parser=e,this.name=$.KHR_MATERIALS_IOR}getMaterialType(e){return Ui(this.parser,e,this.name)===null?null:U}extendMaterialParams(e,t){let n=Ui(this.parser,e,this.name);return n===null||(t.ior=n.ior===void 0?1.5:n.ior,t.ior===0&&(t.ior=1e3)),Promise.resolve()}},ta=class{constructor(e){this.parser=e,this.name=$.KHR_MATERIALS_SPECULAR}getMaterialType(e){return Ui(this.parser,e,this.name)===null?null:U}extendMaterialParams(e,t){let n=Ui(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];t.specularIntensity=n.specularFactor===void 0?1:n.specularFactor,n.specularTexture!==void 0&&r.push(this.parser.assignTexture(t,`specularIntensityMap`,n.specularTexture));let i=n.specularColorFactor||[1,1,1];return t.specularColor=new K().setRGB(i[0],i[1],i[2],a),n.specularColorTexture!==void 0&&r.push(this.parser.assignTexture(t,`specularColorMap`,n.specularColorTexture,ce)),Promise.all(r)}},na=class{constructor(e){this.parser=e,this.name=$.EXT_MATERIALS_BUMP}getMaterialType(e){return Ui(this.parser,e,this.name)===null?null:U}extendMaterialParams(e,t){let n=Ui(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return t.bumpScale=n.bumpFactor===void 0?1:n.bumpFactor,n.bumpTexture!==void 0&&r.push(this.parser.assignTexture(t,`bumpMap`,n.bumpTexture)),Promise.all(r)}},ra=class{constructor(e){this.parser=e,this.name=$.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){return Ui(this.parser,e,this.name)===null?null:U}extendMaterialParams(e,t){let n=Ui(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.anisotropyStrength!==void 0&&(t.anisotropy=n.anisotropyStrength),n.anisotropyRotation!==void 0&&(t.anisotropyRotation=n.anisotropyRotation),n.anisotropyTexture!==void 0&&r.push(this.parser.assignTexture(t,`anisotropyMap`,n.anisotropyTexture)),Promise.all(r)}},ia=class{constructor(e){this.parser=e,this.name=$.KHR_TEXTURE_BASISU}loadTexture(e){let t=this.parser,n=t.json,r=n.textures[e];if(!r.extensions||!r.extensions[this.name])return null;let i=r.extensions[this.name],a=t.options.ktx2Loader;if(!a){if(n.extensionsRequired&&n.extensionsRequired.indexOf(this.name)>=0)throw Error(`THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures`);return null}return t.loadTextureImage(e,i.source,a)}},aa=class{constructor(e){this.parser=e,this.name=$.EXT_TEXTURE_WEBP}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let a=i.extensions[t],o=r.images[a.source],s=n.textureLoader;if(o.uri){let e=n.options.manager.getHandler(o.uri);e!==null&&(s=e)}return n.loadTextureImage(e,a.source,s)}},oa=class{constructor(e){this.parser=e,this.name=$.EXT_TEXTURE_AVIF}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let a=i.extensions[t],o=r.images[a.source],s=n.textureLoader;if(o.uri){let e=n.options.manager.getHandler(o.uri);e!==null&&(s=e)}return n.loadTextureImage(e,a.source,s)}},sa=class{constructor(e,t){this.name=t,this.parser=e}loadBufferView(e){let t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){let e=n.extensions[this.name],r=this.parser.getDependency(`buffer`,e.buffer),i=this.parser.options.meshoptDecoder;if(!i||!i.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw Error(`THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files`);return null}return r.then(function(t){let n=e.byteOffset||0,r=e.byteLength||0,a=e.count,o=e.byteStride,s=new Uint8Array(t,n,r);return i.decodeGltfBufferAsync?i.decodeGltfBufferAsync(a,o,s,e.mode,e.filter).then(function(e){return e.buffer}):i.ready.then(function(){let t=new ArrayBuffer(a*o);return i.decodeGltfBuffer(new Uint8Array(t),a,o,s,e.mode,e.filter),t})})}return null}},ca=class{constructor(e){this.name=$.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){let t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||n.mesh===void 0)return null;let r=t.meshes[n.mesh];for(let e of r.primitives)if(e.mode!==ya.TRIANGLES&&e.mode!==ya.TRIANGLE_STRIP&&e.mode!==ya.TRIANGLE_FAN&&e.mode!==void 0)return null;let i=n.extensions[this.name].attributes,a=[],o={};for(let e in i)a.push(this.parser.getDependency(`accessor`,i[e]).then(t=>(o[e]=t,o[e])));return a.length<1?null:(a.push(this.parser.createNodeMesh(e)),Promise.all(a).then(e=>{let t=e.pop(),n=t.isGroup?t.children:[t],r=e[0].count,i=[];for(let e of n){let t=new nt,n=new w,a=new _,s=new w(1,1,1),c=new oe(e.geometry,e.material,r);for(let e=0;e<r;e++)o.TRANSLATION&&n.fromBufferAttribute(o.TRANSLATION,e),o.ROTATION&&a.fromBufferAttribute(o.ROTATION,e),o.SCALE&&s.fromBufferAttribute(o.SCALE,e),c.setMatrixAt(e,t.compose(n,a,s));let l=null;for(let e in o)if(e===`_COLOR_0`){let t=o[e];c.instanceColor=new N(t.array,t.itemSize,t.normalized)}else if(e!==`TRANSLATION`&&e!==`ROTATION`&&e!==`SCALE`){if(l===null){let e=c.geometry;l=new je,l.name=e.name;for(let t in e.attributes)l.setAttribute(t,e.attributes[t]);for(let t in e.morphAttributes)l.morphAttributes[t]=e.morphAttributes[t];e.index!==null&&l.setIndex(e.index),l.morphTargetsRelative=e.morphTargetsRelative;for(let t of e.groups)l.addGroup(t.start,t.count,t.materialIndex);e.boundingBox!==null&&(l.boundingBox=e.boundingBox.clone()),e.boundingSphere!==null&&(l.boundingSphere=e.boundingSphere.clone()),l.drawRange.start=e.drawRange.start,l.drawRange.count=e.drawRange.count,l.userData=Object.assign({},e.userData),c.geometry=l}let t=o[e];l.setAttribute(e,new N(t.array,t.itemSize,t.normalized))}_t.prototype.copy.call(c,e),this.parser.assignFinalMaterial(c),i.push(c)}return t.isGroup?(t.clear(),t.add(...i),t):i[0]}))}},la=`glTF`,ua=12,da={JSON:1313821514,BIN:5130562},fa=class{constructor(e){this.name=$.KHR_BINARY_GLTF,this.content=null,this.body=null;let t=new DataView(e,0,ua),n=new TextDecoder;if(this.header={magic:n.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==la)throw Error(`THREE.GLTFLoader: Unsupported glTF-Binary header.`);if(this.header.version<2)throw Error(`THREE.GLTFLoader: Legacy binary file detected.`);let r=this.header.length-ua,i=new DataView(e,ua),a=0;for(;a<r;){let t=i.getUint32(a,!0);a+=4;let r=i.getUint32(a,!0);if(a+=4,r===da.JSON){let r=new Uint8Array(e,ua+a,t);this.content=n.decode(r)}else if(r===da.BIN){let n=ua+a;this.body=e.slice(n,n+t)}a+=t}if(this.content===null)throw Error(`THREE.GLTFLoader: JSON content not found.`)}},pa=class{constructor(e,t){if(!t)throw Error(`THREE.GLTFLoader: No DRACOLoader instance provided.`);this.name=$.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){let n=this.json,r=this.dracoLoader,i=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,s={},c={},l={};for(let e in o){let t=wa[e]||e.toLowerCase();s[t]=o[e]}for(let t in e.attributes){let r=wa[t]||t.toLowerCase();if(o[t]!==void 0){let i=n.accessors[e.attributes[t]];l[r]=ba[i.componentType].name,c[r]=i.normalized===!0}}return t.getDependency(`bufferView`,i).then(function(e){return new Promise(function(t,n){r.decodeDracoFile(e,function(e){for(let t in e.attributes){let n=e.attributes[t],r=c[t];r!==void 0&&(n.normalized=r)}t(e)},s,l,a,n)})})}},ma=class{constructor(){this.name=$.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){if((t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0)return e;if(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),t.rotation!==void 0){let t=Math.cos(e.rotation),n=Math.sin(e.rotation);e.matrix.set(e.repeat.x*t,e.repeat.y*n,e.offset.x,-e.repeat.x*n,e.repeat.y*t,e.offset.y,0,0,1),e.matrixAutoUpdate=!1}return e.needsUpdate=!0,e}},ha=class{constructor(){this.name=$.KHR_MESH_QUANTIZATION}},ga=class extends T{constructor(e,t,n,r){super(e,t,n,r)}copySampleValue_(e){let t=this.resultBuffer,n=this.sampleValues,r=this.valueSize,i=e*r*3+r;for(let e=0;e!==r;e++)t[e]=n[i+e];return t}interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=o*2,c=o*3,l=r-t,u=(n-t)/l,d=u*u,f=d*u,p=e*c,m=p-c,h=-2*f+3*d,g=f-d,_=1-h,v=g-d+u;for(let e=0;e!==o;e++){let t=a[m+e+o],n=a[m+e+s]*l,r=a[p+e+o],c=a[p+e]*l;i[e]=_*t+v*n+h*r+g*c}return i}},_a=new _,va=class extends ga{interpolate_(e,t,n,r){let i=super.interpolate_(e,t,n,r);return _a.fromArray(i).normalize().toArray(i),i}},ya={FLOAT:5126,FLOAT_MAT3:35675,FLOAT_MAT4:35676,FLOAT_VEC2:35664,FLOAT_VEC3:35665,FLOAT_VEC4:35666,LINEAR:9729,REPEAT:10497,SAMPLER_2D:35678,POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,UNSIGNED_BYTE:5121,UNSIGNED_SHORT:5123},ba={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},xa={9728:Xe,9729:ye,9984:Le,9985:ie,9986:Be,9987:Ce},Sa={33071:Ne,33648:it,10497:J},Ca={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},wa={POSITION:`position`,NORMAL:`normal`,TANGENT:`tangent`,TEXCOORD_0:`uv`,TEXCOORD_1:`uv1`,TEXCOORD_2:`uv2`,TEXCOORD_3:`uv3`,COLOR_0:`color`,WEIGHTS_0:`skinWeight`,JOINTS_0:`skinIndex`},Ta={scale:`scale`,translation:`position`,rotation:`quaternion`,weights:`morphTargetInfluences`},Ea={CUBICSPLINE:void 0,LINEAR:_e,STEP:pe},Da={OPAQUE:`OPAQUE`,MASK:`MASK`,BLEND:`BLEND`};function Oa(e){return e.DefaultMaterial===void 0&&(e.DefaultMaterial=new Ie({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:0})),e.DefaultMaterial}function ka(e,t,n){for(let r in n.extensions)e[r]===void 0&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[r]=n.extensions[r])}function Aa(e,t){t.extras!==void 0&&(typeof t.extras==`object`?Object.assign(e.userData,t.extras):console.warn(`THREE.GLTFLoader: Ignoring primitive type .extras, `+t.extras))}function ja(e,t,n){let r=!1,i=!1,a=!1;for(let e=0,n=t.length;e<n;e++){let n=t[e];if(n.POSITION!==void 0&&(r=!0),n.NORMAL!==void 0&&(i=!0),n.COLOR_0!==void 0&&(a=!0),r&&i&&a)break}if(!r&&!i&&!a)return Promise.resolve(e);let o=[],s=[],c=[];for(let l=0,u=t.length;l<u;l++){let u=t[l];if(r){let t=u.POSITION===void 0?e.attributes.position:n.getDependency(`accessor`,u.POSITION);o.push(t)}if(i){let t=u.NORMAL===void 0?e.attributes.normal:n.getDependency(`accessor`,u.NORMAL);s.push(t)}if(a){let t=u.COLOR_0===void 0?e.attributes.color:n.getDependency(`accessor`,u.COLOR_0);c.push(t)}}return Promise.all([Promise.all(o),Promise.all(s),Promise.all(c)]).then(function(t){let n=t[0],o=t[1],s=t[2];return r&&(e.morphAttributes.position=n),i&&(e.morphAttributes.normal=o),a&&(e.morphAttributes.color=s),e.morphTargetsRelative=!0,e})}function Ma(e,t){if(e.updateMorphTargets(),t.weights!==void 0)for(let n=0,r=t.weights.length;n<r;n++)e.morphTargetInfluences[n]=t.weights[n];if(t.extras&&Array.isArray(t.extras.targetNames)){let n=t.extras.targetNames;if(e.morphTargetInfluences.length===n.length){e.morphTargetDictionary={};for(let t=0,r=n.length;t<r;t++)e.morphTargetDictionary[n[t]]=t}else console.warn(`THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.`)}}function Na(e){let t,n=e.extensions&&e.extensions[$.KHR_DRACO_MESH_COMPRESSION];if(t=n?`draco:`+n.bufferView+`:`+n.indices+`:`+Pa(n.attributes):e.indices+`:`+Pa(e.attributes)+`:`+e.mode,e.targets!==void 0)for(let n=0,r=e.targets.length;n<r;n++)t+=`:`+Pa(e.targets[n]);return t}function Pa(e){let t=``,n=Object.keys(e).sort();for(let r=0,i=n.length;r<i;r++)t+=n[r]+`:`+e[n[r]]+`;`;return t}function Fa(e){switch(e){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw Error(`THREE.GLTFLoader: Unsupported normalized accessor component type.`)}}function Ia(e){return e.search(/\.jpe?g($|\?)/i)>0||e.search(/^data\:image\/jpeg/)===0?`image/jpeg`:e.search(/\.webp($|\?)/i)>0||e.search(/^data\:image\/webp/)===0?`image/webp`:e.search(/\.ktx2($|\?)/i)>0||e.search(/^data\:image\/ktx2/)===0?`image/ktx2`:`image/png`}var La=new nt,Ra=class{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new Hi,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let n=!1,r=-1,i=!1,a=-1;if(typeof navigator<`u`&&navigator.userAgent!==void 0){let e=navigator.userAgent;n=/^((?!chrome|android).)*safari/i.test(e)===!0;let t=e.match(/Version\/(\d+)/);r=n&&t?parseInt(t[1],10):-1,i=e.indexOf(`Firefox`)>-1,a=i?e.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>`u`||n&&r<17||i&&a<98?(this.textureLoader=new P(this.options.manager),this.textureLoader.setPriority(this.options.priority),this.textureLoader.setCache(this.options.cache)):(this.textureLoader=new D(this.options.manager),this.textureLoader.setPriority(this.options.priority),this.textureLoader.setCache(this.options.cache)),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setWithCredentials(this.options.withCredentials),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new h(this.options.manager),this.fileLoader.setPriority(this.options.priority),this.fileLoader.setCache(this.options.cache),this.fileLoader.setResponseType(`arraybuffer`),(this.options.withCredentials||this.options.crossOrigin===`use-credentials`)&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){let n=this,r=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(e){return e._markDefs&&e._markDefs()}),Promise.all(this._invokeAll(function(e){return e.beforeRoot&&e.beforeRoot()})).then(function(){return Promise.all([n.getDependencies(`scene`),n.getDependencies(`animation`),n.getDependencies(`camera`)])}).then(function(t){let a={scene:t[0][r.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:r.asset,parser:n,userData:{}};return ka(i,a,r),Aa(a,r),Promise.all(n._invokeAll(function(e){return e.afterRoot&&e.afterRoot(a)})).then(function(){for(let e of a.scenes)e.updateMatrixWorld();e(a)})}).catch(t)}_markDefs(){let e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let n=0,r=t.length;n<r;n++){let r=t[n].joints;for(let t=0,n=r.length;t<n;t++)e[r[t]].isBone=!0}for(let t=0,r=e.length;t<r;t++){let r=e[t];r.mesh!==void 0&&(this._addNodeRef(this.meshCache,r.mesh),r.skin!==void 0&&(n[r.mesh].isSkinnedMesh=!0)),r.camera!==void 0&&this._addNodeRef(this.cameraCache,r.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,n){if(e.refs[t]<=1)return n;let r=n.clone(),i=(e,t)=>{let n=this.associations.get(e);n!=null&&this.associations.set(t,n);for(let[n,r]of e.children.entries())i(r,t.children[n])};return i(n,r),r.name+=`_instance_`+e.uses[t]++,r}_invokeOne(e){let t=Object.values(this.plugins);t.push(this);for(let n=0;n<t.length;n++){let r=e(t[n]);if(r)return r}return null}_invokeAll(e){let t=Object.values(this.plugins);t.unshift(this);let n=[];for(let r=0;r<t.length;r++){let i=e(t[r]);i&&n.push(i)}return n}getDependency(e,t){let n=e+`:`+t,r=this.cache.get(n);if(!r){switch(e){case`scene`:r=this.loadScene(t);break;case`node`:r=this._invokeOne(function(e){return e.loadNode&&e.loadNode(t)});break;case`mesh`:r=this._invokeOne(function(e){return e.loadMesh&&e.loadMesh(t)});break;case`accessor`:r=this.loadAccessor(t);break;case`bufferView`:r=this._invokeOne(function(e){return e.loadBufferView&&e.loadBufferView(t)});break;case`buffer`:r=this.loadBuffer(t);break;case`material`:r=this._invokeOne(function(e){return e.loadMaterial&&e.loadMaterial(t)});break;case`texture`:r=this._invokeOne(function(e){return e.loadTexture&&e.loadTexture(t)});break;case`skin`:r=this.loadSkin(t);break;case`animation`:r=this._invokeOne(function(e){return e.loadAnimation&&e.loadAnimation(t)});break;case`camera`:r=this.loadCamera(t);break;default:if(r=this._invokeOne(function(n){return n!=this&&n.getDependency&&n.getDependency(e,t)}),!r)throw Error(`Unknown type: `+e)}this.cache.add(n,r)}return r}getDependencies(e){let t=this.cache.get(e);if(!t){let n=this,r=this.json[e+(e===`mesh`?`es`:`s`)]||[];t=Promise.all(r.map(function(t,r){return n.getDependency(e,r)})),this.cache.add(e,t)}return t}loadBuffer(e){let t=this.json.buffers[e],n=this.fileLoader;if(t.type&&t.type!==`arraybuffer`)throw Error(`THREE.GLTFLoader: `+t.type+` buffer type is not supported.`);if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[$.KHR_BINARY_GLTF].body);let r=this.options;return new Promise(function(e,i){n.load($e.resolveURL(t.uri,r.path),e,void 0,function(){i(Error(`THREE.GLTFLoader: Failed to load buffer "`+t.uri+`".`))})})}loadBufferView(e){let t=this.json.bufferViews[e];return this.getDependency(`buffer`,t.buffer).then(function(e){let n=t.byteLength||0,r=t.byteOffset||0;return e.slice(r,r+n)})}loadAccessor(e){let t=this,n=this.json,r=this.json.accessors[e];if(r.bufferView===void 0&&r.sparse===void 0){let e=Ca[r.type],t=ba[r.componentType],n=r.normalized===!0,i=new t(r.count*e);return Promise.resolve(new ut(i,e,n))}let i=[];return r.bufferView===void 0?i.push(null):i.push(this.getDependency(`bufferView`,r.bufferView)),r.sparse!==void 0&&(i.push(this.getDependency(`bufferView`,r.sparse.indices.bufferView)),i.push(this.getDependency(`bufferView`,r.sparse.values.bufferView))),Promise.all(i).then(function(e){let i=e[0],a=Ca[r.type],o=ba[r.componentType],s=o.BYTES_PER_ELEMENT,c=s*a,l=r.byteOffset||0,d=r.bufferView===void 0?void 0:n.bufferViews[r.bufferView].byteStride,f=r.normalized===!0,p,m;if(d&&d!==c){let e=Math.floor(l/d),n=`InterleavedBuffer:`+r.bufferView+`:`+r.componentType+`:`+e+`:`+r.count,c=t.cache.get(n);c||(p=new o(i,e*d,r.count*d/s),c=new u(p,d/s),t.cache.add(n,c)),m=new he(c,a,l%d/s,f)}else p=i===null?new o(r.count*a):new o(i,l,r.count*a),m=new ut(p,a,f);if(r.sparse!==void 0){let t=Ca.SCALAR,n=ba[r.sparse.indices.componentType],s=r.sparse.indices.byteOffset||0,c=r.sparse.values.byteOffset||0,l=new n(e[1],s,r.sparse.count*t),u=new o(e[2],c,r.sparse.count*a);i!==null&&(m=new ut(m.array.slice(),m.itemSize,m.normalized)),m.normalized=!1;for(let e=0,t=l.length;e<t;e++){let t=l[e];if(m.setX(t,u[e*a]),a>=2&&m.setY(t,u[e*a+1]),a>=3&&m.setZ(t,u[e*a+2]),a>=4&&m.setW(t,u[e*a+3]),a>=5)throw Error(`THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.`)}m.normalized=f}return m})}loadTexture(e){let t=this.json,n=this.options,r=t.textures[e].source,i=t.images[r],a=this.textureLoader;if(i.uri){let e=n.manager.getHandler(i.uri);e!==null&&(a=e)}return this.loadTextureImage(e,r,a)}loadTextureImage(e,t,n){let r=this,i=this.json,a=i.textures[e],o=i.images[t],s=(o.uri||o.bufferView)+`:`+a.sampler;if(this.textureCache[s])return this.textureCache[s];let c=this.loadImageSource(t,n).then(function(t){t.flipY=!1,t.name=a.name||o.name||``,t.name===``&&typeof o.uri==`string`&&o.uri.startsWith(`data:image/`)===!1&&(t.name=o.uri);let n=(i.samplers||{})[a.sampler]||{};return t.magFilter=xa[n.magFilter]||1006,t.minFilter=xa[n.minFilter]||1008,t.wrapS=Sa[n.wrapS]||1e3,t.wrapT=Sa[n.wrapT]||1e3,t.generateMipmaps=!t.isCompressedTexture&&t.minFilter!==1003&&t.minFilter!==1006,r.associations.set(t,{textures:e}),t}).catch(function(){return null});return this.textureCache[s]=c,c}loadImageSource(e,t){let n=this,r=this.json,i=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(e=>e.clone());let a=r.images[e],o=self.URL||self.webkitURL,s=a.uri||``,c=!1,l;if(t.isKTX2Loader===!0&&a.bufferView!==void 0)l=n.getDependency(`bufferView`,a.bufferView).then(function(e){return new Promise(function(n,r){t.parse(e,n,r)})});else{if(a.bufferView!==void 0)s=n.getDependency(`bufferView`,a.bufferView).then(function(e){c=!0;let t=new Blob([e],{type:a.mimeType});return s=o.createObjectURL(t),s});else if(a.uri===void 0)throw Error(`THREE.GLTFLoader: Image `+e+` is missing URI and bufferView`);l=Promise.resolve(s).then(function(e){return new Promise(function(n,r){let a=n;t.isImageBitmapLoader===!0&&(a=function(e){let t=new Ge(e);t.needsUpdate=!0,n(t)}),t.load($e.resolveURL(e,i.path),a,void 0,r)})})}let u=l.then(function(e){return c===!0&&o.revokeObjectURL(s),Aa(e,a),e.userData.mimeType=a.mimeType||Ia(a.uri),e}).catch(function(e){throw console.error(`THREE.GLTFLoader: Couldn't load texture`,s),e});return this.sourceCache[e]=u,u}assignTexture(e,t,n,r){let i=this;return this.getDependency(`texture`,n.index).then(function(a){if(!a)return null;if(n.texCoord!==void 0&&n.texCoord>0&&(a=a.clone(),a.channel=n.texCoord),i.extensions[$.KHR_TEXTURE_TRANSFORM]){let e=n.extensions===void 0?void 0:n.extensions[$.KHR_TEXTURE_TRANSFORM];if(e){let t=i.associations.get(a);a=i.extensions[$.KHR_TEXTURE_TRANSFORM].extendTexture(a,e),i.associations.set(a,t)}}return r!==void 0&&(a.colorSpace=r),e[t]=a,a})}assignFinalMaterial(e){let t=e.geometry,n=e.material,r=t.attributes.tangent===void 0,i=t.attributes.color!==void 0,a=t.attributes.normal===void 0;if(e.isPoints){let e=`PointsMaterial:`+n.uuid,t=this.cache.get(e);t||(t=new fe,lt.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,t.sizeAttenuation=!1,this.cache.add(e,t)),n=t}else if(e.isLine){let e=`LineBasicMaterial:`+n.uuid,t=this.cache.get(e);t||(t=new at,lt.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,this.cache.add(e,t)),n=t}if(r||i||a){let e=`ClonedMaterial:`+n.uuid+`:`;r&&(e+=`derivative-tangents:`),i&&(e+=`vertex-colors:`),a&&(e+=`flat-shading:`);let t=this.cache.get(e);t||(t=n.clone(),i&&(t.vertexColors=!0),a&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}e.material=n}getMaterialType(){return Ie}loadMaterial(e){let t=this,n=this.json,r=this.extensions,i=n.materials[e],o,s={},c=i.extensions||{},l=[];if(c[$.KHR_MATERIALS_UNLIT]){let e=r[$.KHR_MATERIALS_UNLIT];o=e.getMaterialType(),l.push(e.extendParams(s,i,t))}else{let n=i.pbrMetallicRoughness||{};if(s.color=new K(1,1,1),s.opacity=1,Array.isArray(n.baseColorFactor)){let e=n.baseColorFactor;s.color.setRGB(e[0],e[1],e[2],a),s.opacity=e[3]}n.baseColorTexture!==void 0&&l.push(t.assignTexture(s,`map`,n.baseColorTexture,ce)),s.metalness=n.metallicFactor===void 0?1:n.metallicFactor,s.roughness=n.roughnessFactor===void 0?1:n.roughnessFactor,n.metallicRoughnessTexture!==void 0&&(l.push(t.assignTexture(s,`metalnessMap`,n.metallicRoughnessTexture)),l.push(t.assignTexture(s,`roughnessMap`,n.metallicRoughnessTexture))),o=this._invokeOne(function(t){return t.getMaterialType&&t.getMaterialType(e)}),l.push(Promise.all(this._invokeAll(function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,s)})))}i.doubleSided===!0&&(s.side=2);let u=i.alphaMode||Da.OPAQUE;if(u===Da.BLEND?(s.transparent=!0,s.depthWrite=!1):(s.transparent=!1,u===Da.MASK&&(s.alphaTest=i.alphaCutoff===void 0?.5:i.alphaCutoff)),i.normalTexture!==void 0&&o!==H&&(l.push(t.assignTexture(s,`normalMap`,i.normalTexture)),s.normalScale=new ve(1,1),i.normalTexture.scale!==void 0)){let e=i.normalTexture.scale;s.normalScale.set(e,e)}if(i.occlusionTexture!==void 0&&o!==H&&(l.push(t.assignTexture(s,`aoMap`,i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(s.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&o!==H){let e=i.emissiveFactor;s.emissive=new K().setRGB(e[0],e[1],e[2],a)}return i.emissiveTexture!==void 0&&o!==H&&l.push(t.assignTexture(s,`emissiveMap`,i.emissiveTexture,ce)),Promise.all(l).then(function(){let n=new o(s);return i.name&&(n.name=i.name),Aa(n,i),t.associations.set(n,{materials:e}),i.extensions&&ka(r,n,i),n})}createUniqueName(e){let t=y.sanitizeNodeName(e||``);return t in this.nodeNamesUsed?t+`_`+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){let t=this,n=this.extensions,r=this.primitiveCache;function i(e){return n[$.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,t).then(function(n){return Ba(n,e,t)})}let a=[];for(let n=0,o=e.length;n<o;n++){let o=e[n],s=Na(o),c=r[s];if(c)a.push(c.promise);else{let e;e=o.extensions&&o.extensions[$.KHR_DRACO_MESH_COMPRESSION]?i(o):Ba(new je,o,t),o.mode===ya.TRIANGLE_STRIP?e=e.then(e=>Ri(e,1)):o.mode===ya.TRIANGLE_FAN&&(e=e.then(e=>Ri(e,2))),r[s]={primitive:o,promise:e},a.push(e)}}return Promise.all(a)}loadMesh(e){let t=this,n=this.json,r=this.extensions,i=n.meshes[e],a=i.primitives,o=[];for(let e=0,t=a.length;e<t;e++){let t=a[e].material===void 0?Oa(this.cache):this.getDependency(`material`,a[e].material);o.push(t)}return o.push(t.loadGeometries(a)),Promise.all(o).then(async function(n){let o=n.slice(0,n.length-1),s=n[n.length-1],c=[];for(let n=0,l=s.length;n<l;n++){let l=s[n],u=a[n],d,f=o[n];if(u.mode===ya.TRIANGLES||u.mode===ya.TRIANGLE_STRIP||u.mode===ya.TRIANGLE_FAN||u.mode===void 0){let e=i.isSkinnedMesh===!0,t=l.hasAttribute(`skinIndex`)&&l.hasAttribute(`skinWeight`);e&&t===!1&&console.warn(`THREE.GLTFLoader: Missing skinIndex or skinWeight attributes. Skinning disabled.`),d=e&&t?new ee(l,f):new dt(l,f),d.isSkinnedMesh===!0&&d.normalizeSkinWeights()}else if(u.mode===ya.LINES)d=new xe(l,f);else if(u.mode===ya.LINE_STRIP)d=new j(l,f);else if(u.mode===ya.LINE_LOOP)d=new k(l,f);else if(u.mode===ya.POINTS)d=new bt(l,f);else throw Error(`THREE.GLTFLoader: Primitive mode unsupported: `+u.mode);Object.keys(d.geometry.morphAttributes).length>0&&Ma(d,i),d.name=t.createUniqueName(i.name||`mesh_`+e),Aa(d,i),u.extensions&&ka(r,d,u),t.assignFinalMaterial(d),c.push(d)}for(let n=0,r=c.length;n<r;n++)t.associations.set(c[n],{meshes:e,primitives:n});if(c.length===1)return i.extensions&&ka(r,c[0],i),c[0];let l=new F;i.extensions&&ka(r,l,i),t.associations.set(l,{meshes:e});for(let e=0,t=c.length;e<t;e++)l.add(c[e]);return l})}loadCamera(e){let t,n=this.json.cameras[e],r=n[n.type];if(!r)console.warn(`THREE.GLTFLoader: Missing camera parameters.`);else return n.type===`perspective`?t=new Ae(Ue.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):n.type===`orthographic`&&(t=new wt(-r.xmag,r.xmag,r.ymag,-r.ymag,r.znear,r.zfar)),n.name&&(t.name=this.createUniqueName(n.name)),Aa(t,n),Promise.resolve(t)}loadSkin(e){let t=this.json.skins[e],n=[];for(let e=0,r=t.joints.length;e<r;e++)n.push(this._loadNodeShallow(t.joints[e]));return t.inverseBindMatrices===void 0?n.push(null):n.push(this.getDependency(`accessor`,t.inverseBindMatrices)),Promise.all(n).then(function(e){let n=e.pop(),r=e,i=[],a=[];for(let e=0,o=r.length;e<o;e++){let o=r[e];if(o){i.push(o);let t=new nt;n!==null&&t.fromArray(n.array,e*16),a.push(t)}else console.warn(`THREE.GLTFLoader: Joint "%s" could not be found.`,t.joints[e])}return new g(i,a)})}loadAnimation(e){let t=this.json,n=this,r=t.animations[e],i=r.name?r.name:`animation_`+e,a=[],o=[],s=[],c=[],l=[];for(let e=0,t=r.channels.length;e<t;e++){let t=r.channels[e],n=r.samplers[t.sampler],i=t.target,u=i.node,d=r.parameters===void 0?n.input:r.parameters[n.input],f=r.parameters===void 0?n.output:r.parameters[n.output];i.node!==void 0&&(a.push(this.getDependency(`node`,u)),o.push(this.getDependency(`accessor`,d)),s.push(this.getDependency(`accessor`,f)),c.push(n),l.push(i))}return Promise.all([Promise.all(a),Promise.all(o),Promise.all(s),Promise.all(c),Promise.all(l)]).then(function(e){let t=e[0],a=e[1],o=e[2],s=e[3],c=e[4],l=[];for(let e=0,r=t.length;e<r;e++){let r=t[e],i=a[e],u=o[e],d=s[e],f=c[e];if(r===void 0)continue;r.updateMatrix&&r.updateMatrix();let p=n._createAnimationTracks(r,i,u,d,f);if(p)for(let e=0;e<p.length;e++)l.push(p[e])}let u=new Ze(i,void 0,l);return Aa(u,r),u})}createNodeMesh(e){let t=this.json,n=this,r=t.nodes[e];return r.mesh===void 0?null:n.getDependency(`mesh`,r.mesh).then(function(e){let t=n._getNodeRef(n.meshCache,r.mesh,e);return r.weights!==void 0&&t.traverse(function(e){if(e.isMesh)for(let t=0,n=r.weights.length;t<n;t++)e.morphTargetInfluences[t]=r.weights[t]}),t})}loadNode(e){let t=this.json,n=this,r=t.nodes[e],i=n._loadNodeShallow(e),a=[],o=r.children||[];for(let e=0,t=o.length;e<t;e++)a.push(n.getDependency(`node`,o[e]));let s=r.skin===void 0?Promise.resolve(null):n.getDependency(`skin`,r.skin);return Promise.all([i,Promise.all(a),s]).then(function(e){let t=e[0],n=e[1],r=e[2];r!==null&&t.traverse(function(e){e.isSkinnedMesh&&e.bind(r,La)});for(let e=0,r=n.length;e<r;e++)t.add(n[e]);if(t.userData.pivot!==void 0&&n.length>0){let e=t.userData.pivot,r=n[0];t.pivot=new w().fromArray(e),t.position.x-=e[0],t.position.y-=e[1],t.position.z-=e[2],r.position.set(0,0,0),delete t.userData.pivot}return t})}_loadNodeShallow(e){let t=this.json,n=this.extensions,r=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];let i=t.nodes[e],a=i.name?r.createUniqueName(i.name):``,o=[],s=r._invokeOne(function(t){return t.createNodeMesh&&t.createNodeMesh(e)});return s&&o.push(s),i.camera!==void 0&&o.push(r.getDependency(`camera`,i.camera).then(function(e){return r._getNodeRef(r.cameraCache,i.camera,e)})),r._invokeAll(function(t){return t.createNodeAttachment&&t.createNodeAttachment(e)}).forEach(function(e){o.push(e)}),this.nodeCache[e]=Promise.all(o).then(function(t){let o;if(o=i.isBone===!0?new Ve:t.length>1?new F:t.length===1?t[0]:new _t,o!==t[0])for(let e=0,n=t.length;e<n;e++)o.add(t[e]);if(i.name&&(o.userData.name=i.name,o.name=a),Aa(o,i),i.extensions&&ka(n,o,i),i.matrix!==void 0){let e=new nt;e.fromArray(i.matrix),o.applyMatrix4(e)}else i.translation!==void 0&&o.position.fromArray(i.translation),i.rotation!==void 0&&o.quaternion.fromArray(i.rotation),i.scale!==void 0&&o.scale.fromArray(i.scale);if(!r.associations.has(o))r.associations.set(o,{});else if(i.mesh!==void 0&&r.meshCache.refs[i.mesh]>1){let e=r.associations.get(o);r.associations.set(o,{...e})}return r.associations.get(o).nodes=e,o}),this.nodeCache[e]}loadScene(e){let t=this.extensions,n=this.json.scenes[e],r=this,i=new F;n.name&&(i.name=r.createUniqueName(n.name)),Aa(i,n),n.extensions&&ka(t,i,n);let a=n.nodes||[],o=[];for(let e=0,t=a.length;e<t;e++)o.push(r.getDependency(`node`,a[e]));return Promise.all(o).then(function(e){for(let t=0,n=e.length;t<n;t++){let n=e[t];n.parent===null?i.add(n):i.add(zi(n))}return r.associations=(e=>{let t=new Map;for(let[e,n]of r.associations)(e instanceof lt||e instanceof Ge)&&t.set(e,n);return e.traverse(e=>{let n=r.associations.get(e);n!=null&&t.set(e,n)}),t})(i),i})}_createAnimationTracks(e,t,n,r,i){let a=[],o=e.name?e.name:e.uuid,s=[];function c(e){e.morphTargetInfluences&&s.push(e.name?e.name:e.uuid)}Ta[i.path]===Ta.weights?(c(e),e.isGroup&&e.children.forEach(c)):s.push(o);let l;switch(Ta[i.path]){case Ta.weights:l=De;break;case Ta.rotation:l=te;break;case Ta.translation:case Ta.scale:l=ot;break;default:switch(n.itemSize){case 1:l=De;break;default:l=ot}}let u=r.interpolation===void 0?_e:Ea[r.interpolation],d=this._getArrayFromAccessor(n);for(let e=0,n=s.length;e<n;e++){let n=new l(s[e]+`.`+Ta[i.path],t.array,d,u);r.interpolation===`CUBICSPLINE`&&this._createCubicSplineTrackInterpolant(n),a.push(n)}return a}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){let e=Fa(t.constructor),n=new Float32Array(t.length);for(let r=0,i=t.length;r<i;r++)n[r]=t[r]*e;t=n}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(e){return new(this instanceof te?va:ga)(this.times,this.values,this.getValueSize()/3,e)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}};function za(e,t,n){let r=t.attributes,i=new Oe;if(r.POSITION!==void 0){let e=n.json.accessors[r.POSITION],t=e.min,a=e.max;if(t!==void 0&&a!==void 0){if(i.set(new w(t[0],t[1],t[2]),new w(a[0],a[1],a[2])),e.normalized){let t=Fa(ba[e.componentType]);i.min.multiplyScalar(t),i.max.multiplyScalar(t)}}else{console.warn(`THREE.GLTFLoader: Missing min/max properties for accessor POSITION.`);return}}else return;let a=t.targets;if(a!==void 0){let e=new w,t=new w;for(let r=0,i=a.length;r<i;r++){let i=a[r];if(i.POSITION!==void 0){let r=n.json.accessors[i.POSITION],a=r.min,o=r.max;if(a!==void 0&&o!==void 0){if(t.setX(Math.max(Math.abs(a[0]),Math.abs(o[0]))),t.setY(Math.max(Math.abs(a[1]),Math.abs(o[1]))),t.setZ(Math.max(Math.abs(a[2]),Math.abs(o[2]))),r.normalized){let e=Fa(ba[r.componentType]);t.multiplyScalar(e)}e.max(t)}else console.warn(`THREE.GLTFLoader: Missing min/max properties for accessor POSITION.`)}}i.expandByVector(e)}e.boundingBox=i;let o=new qe;i.getCenter(o.center),o.radius=i.min.distanceTo(i.max)/2,e.boundingSphere=o}function Ba(e,t,n){let r=t.attributes,i=[];function a(t,r){return n.getDependency(`accessor`,t).then(function(t){e.setAttribute(r,t)})}for(let t in r){let n=wa[t]||t.toLowerCase();n in e.attributes||i.push(a(r[t],n))}if(t.indices!==void 0&&!e.index){let r=n.getDependency(`accessor`,t.indices).then(function(t){e.setIndex(t)});i.push(r)}return Y.workingColorSpace!==`srgb-linear`&&`COLOR_0`in r&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${Y.workingColorSpace}" not supported.`),Aa(e,t),za(e,t,n),Promise.all(i).then(function(){return t.targets===void 0?e:ja(e,t.targets,n)})}var Va=new URL(new URL(`open-nWGD2hyb.glb`,import.meta.url).href,``+import.meta.url).href,Ha=3.88,Ua={position:[0,-3.78985,24.21046],rotation:[.149987,0,0],lens:88.6082},Wa=new _().setFromAxisAngle(new w(1,0,0),-Math.PI/2);function Ga(e){let t=new Set,n=new Set,r=new Set;e.traverse(e=>{if(e instanceof dt){t.add(e.geometry);for(let t of Array.isArray(e.material)?e.material:[e.material]){n.add(t);for(let e of Object.values(t))e instanceof Ge&&r.add(e)}}});for(let e of t)e.dispose();for(let e of n)e.dispose();for(let e of r)e.dispose(),typeof ImageBitmap<`u`&&e.source.data instanceof ImageBitmap&&e.source.data.close()}function Ka(e){let t=e.geometry.getAttribute(`position`),n=new Map;for(let e=0;e<t.count;e++){let r=t.getX(e),i=n.get(r)??[];i.push(e),n.set(r,i)}let r=[...n].sort(([e],[t])=>e-t).map(([,e])=>e.sort((e,n)=>t.getZ(e)-t.getZ(n))),i=Array.from({length:2},(e,t)=>Array.from({length:2},(e,n)=>{let i=r[Math.round(n/1*(r.length-1))];return i?.[Math.round(t/1*(i.length-1))]??0})),a=new w;return t=>i.map(n=>n.map(n=>(e.getVertexPosition(n,a),a.applyMatrix4(e.matrixWorld).project(t),{x:(a.x+1)/2,y:(1-a.y)/2})))}function qa(e){let t=e[0],n=e.at(-1),r=t?.[0],i=t?.at(-1),a=n?.[0],o=n?.at(-1);if(!r||!i||!a||!o)throw Error(`Empty paper mesh`);return{topLeft:r,topRight:i,bottomLeft:a,bottomRight:o}}function Ja(e,t){let n=new ut(new Float32Array(e.geometry.getAttribute(`position`).count*3),3);return e.geometry.setAttribute(t,n),n}function Ya(e,t,n){let r=new nt().multiplyMatrices(n.projectionMatrix,n.matrixWorldInverse).multiply(e.matrixWorld),i=new w,a=new M;for(let n=0;n<t.count;n+=1)e.getVertexPosition(n,i),a.set(i.x,i.y,i.z,1).applyMatrix4(r),t.setXYZ(n,a.x,a.y,a.w);t.needsUpdate=!0}function Xa(e,t){let n=e.morphTargetInfluences;if(n)for(let e=0;e<n.length;e+=1)n[e]=Math.max(0,1-Math.abs(t*4-(e+1)))}function Za(e,t,n,r,i){let a=e.geometry.getAttribute(`position`),o=-1/0;for(let e=0;e<a.count;e++)o=Math.max(o,a.getX(e));let s=Array.from({length:a.count},(e,t)=>t).filter(e=>a.getX(e)>=o-1e-5).sort((e,t)=>a.getZ(e)-a.getZ(t)),c=Array.from({length:9},()=>new w),l={value:0},u={value:c};for(let e of[t,n]){if(!(e.material instanceof Ie))continue;let t=e.material.clone();e.material=t;let a=e===n;t.customProgramCacheKey=()=>a?`paper-shadow-right`:`paper-shadow-left`,t.onBeforeCompile=e=>{e.uniforms.sheetEdge=u,e.uniforms.sheetShadow=l,e.uniforms.paperInk=a?r.right:r.left,e.uniforms.printTurning=i,e.vertexShader=`attribute vec3 inkFrontFrame; varying vec3 flatInkFrame; varying vec3 paperPosition;
4222
+ `+e.vertexShader.replace(`#include <uv_vertex>`,`#include <uv_vertex>
4223
+ flatInkFrame=inkFrontFrame;`).replace(`#include <project_vertex>`,`#include <project_vertex>
4224
+ paperPosition=(modelMatrix*vec4(transformed,1.)).xyz;`),e.fragmentShader=`uniform vec3 sheetEdge[9]; uniform float sheetShadow; varying vec3 paperPosition;
4225
+ uniform sampler2D paperInk; uniform float printTurning; varying vec3 flatInkFrame;
4226
+ float castCoverage(float x,float extent,float blur){
4227
+ return (1.-smoothstep(extent-blur,extent+blur,x))*smoothstep(-.08,.11,x);
4228
+ }
4229
+ float foldCoverage(float x,float reach,float width){
4230
+ return (1.-smoothstep(reach,reach+width,-x))*(1.-smoothstep(-.022,.08,x));
4231
+ }
4232
+ `+e.fragmentShader.replace(`#include <color_fragment>`,`#include <color_fragment>
4233
+ if(printTurning>0.){
4234
+ vec4 printed=texture2D(paperInk,flatInkFrame.xy/flatInkFrame.z*.5+.5);
4235
+ diffuseColor.rgb=mix(diffuseColor.rgb,printed.rgb,printed.a);
4236
+ }
4237
+ float row = clamp((paperPosition.z+${Ha/2})/${Ha}*8.,0.,7.9999);
4238
+ int i=int(floor(row));
4239
+ vec3 tip=mix(sheetEdge[i],sheetEdge[i+1],fract(row));
4240
+ float height=max(tip.y-paperPosition.y,0.);
4241
+ float x=paperPosition.x;
4242
+ // Rows can cross the spine at different times as a leaf flexes.
4243
+ float rightSide=smoothstep(-.18,.18,tip.x);
4244
+ float extent=abs(tip.x)*.96;
4245
+ float blur=.06+height*.24;
4246
+ float coverage=mix(castCoverage(-x,extent,blur),castCoverage(x,extent,blur),rightSide);
4247
+ // The far end receives more fill than the near fold.
4248
+ float nearFold=smoothstep(-1.7,1.8,paperPosition.z);
4249
+ float contact=mix(.67,1.,nearFold);
4250
+ float shade=clamp(sheetShadow*coverage*contact,0.,1.);
4251
+ diffuseColor.rgb*=mix(vec3(1.),vec3(.37,.18,.06),shade);
4252
+ // The paper curves over the binding, blocking fill on the other side too.
4253
+ float lean=smoothstep(0.,.25,abs(tip.x));
4254
+ float creaseWidth=mix(.3,1.33,nearFold)*mix(.3,1.,lean);
4255
+ float foldReach=.22*nearFold*nearFold*nearFold*lean;
4256
+ float crease=mix(foldCoverage(-x,foldReach,creaseWidth),
4257
+ foldCoverage(x,foldReach,creaseWidth),rightSide);
4258
+ float occlusion=clamp(sheetShadow*crease*mix(.36,1.1,nearFold)*lean,0.,1.);
4259
+ diffuseColor.rgb*=mix(vec3(1.),vec3(.31,.135,.045),occlusion);
4260
+ `)}}let d=new w;return t=>{l.value=Math.min(1,8*t,8*(1-t)),c.forEach((t,n)=>{let r=s[Math.round(n/8*(s.length-1))];r!==void 0&&(e.getVertexPosition(r,d),t.copy(e.localToWorld(d)))})}}function Qa(e,n,r,i,a){let o=new Li({alpha:!0,antialias:!0,powerPreference:`low-power`});o.setClearColor(0,0);let s=o.getContext(),c=s.getExtension(`WEBGL_debug_renderer_info`),l=c&&/swiftshader|llvmpipe|software rasterizer|basic render/i.test(String(s.getParameter(c.UNMASKED_RENDERER_WEBGL))),u=o.domElement;u.setAttribute(`aria-hidden`,`true`),Object.assign(u.style,{width:`100%`,height:`100%`,display:`block`}),e.append(u);let d=new yt,p=new Ct(new Uint8Array([0,0,0,0]),1,1);p.needsUpdate=!0;let m={left:{value:p},right:{value:p},front:{value:p},back:{value:p}},h={value:0};function g(e,t){if(!(t&&e.value.source.data===t)){if(e.value!==p&&e.value.dispose(),t){let n=new mt(t);n.colorSpace=ce,n.anisotropy=Math.min(4,o.capabilities.getMaxAnisotropy()),e.value=n}else e.value=p}}let _=new Ae(30,1,.1,65),v=new b(16777215,12038579,2.05);v.color.setRGB(1.035,1.09,1.125);let y=new f(16777215,1.4);y.position.set(-.6,8,.5);let x=new f(16777215,.42);x.position.set(4,4,4);let S=new dt(new le(15,12),new de({transparent:!0,depthWrite:!1,vertexShader:`varying vec2 local;
4261
+ void main(){ local=position.xy; gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.); }`,fragmentShader:`varying vec2 local;
4262
+ void main(){
4263
+ vec2 d=abs(local-vec2(.015,-.075))-vec2(3.42,1.96);
4264
+ float outside=length(max(d,0.))+min(max(d.x,d.y),0.);
4265
+ float shadow=.64*exp(-max(outside,0.)*10.)+.12*exp(-max(outside,0.)*3.);
4266
+ float bounce=.46*exp(-pow((local.y+2.12)/.45,2.)-pow(local.x/1.65,4.));
4267
+ float alpha=shadow+bounce*(1.-shadow);
4268
+ vec3 color=(shadow*vec3(.014,.002,.003)+(1.-shadow)*bounce*vec3(.45,.105,.095))/max(.0001,alpha);
4269
+ gl_FragColor=vec4(color,alpha);
4270
+ }`}));S.rotation.x=-Math.PI/2,S.position.y=-.085,S.renderOrder=-1,d.add(v,y,x,S);let C=n,w,T,E,D,O,k,A,j=!1,M=!1,N=0,P=1,F=1,I=0,L=null,ee,te=new nt;function ne(){let e=Ue.clamp((1920-P)/640,0,1),t=1+.085474*e;w&&(w.scale.x=t),S.scale.x=t,_.position.fromArray(Ua.position),_.position.y+=e*(-1.795895-Ua.position[1]),_.position.applyQuaternion(Wa);let[n,r,i]=Ua.rotation;if(_.quaternion.setFromEuler(new vt(n+e*(.069131-n),r,i,`ZYX`)).premultiply(Wa),_.aspect=P/F,_.fov=Ue.radToDeg(2*Math.atan(18/((Ua.lens+e*(86.64898-Ua.lens))*_.aspect))),_.updateProjectionMatrix(),_.updateMatrixWorld(),C&&w&&O&&A){w.updateMatrixWorld(!0);let e=[...O(_).flat(),...A(_).flat()],t=Math.min(...e.map(e=>e.x)),n=Math.max(...e.map(e=>e.x)),r=Math.min(...e.map(e=>e.y)),i=Math.max(...e.map(e=>e.y)),a=Et(P,F),o=a.width/(P*(n-t)),s=a.height/(F*(i-r));te.set(o,0,0,o*(1-t-n),0,s,0,s*(r+i-1),0,0,1,0,0,0,0,1),_.projectionMatrix.premultiply(te),_.projectionMatrixInverse.copy(_.projectionMatrix).invert()}}function re(t){if(N=0,j||M||!w||!E||!O||!k)return;let n=null;if(ee&&L){let e=Math.min((t-ee.start)/670,1),r=e*e*(3-2*e),i=+(L.plan.direction>0);I=Ue.lerp(ee.from,i,r),e===1&&(ee=void 0,n=L)}Xa(E,I),e.dataset.turning=L?`true`:`false`,h.value=+!!L,D?.(I),ne(),o.render(d,_);let r=O(_),i=k(_);e.dispatchEvent(new CustomEvent(`grimoire-projection`,{bubbles:!0,detail:{left:qa(r),right:qa(i)}})),n&&a(n),ee&&R()}function R(){j||M||N||(N=requestAnimationFrame(re))}function ie(e){e.preventDefault(),M=!0,cancelAnimationFrame(N),N=0,i(!1)}function ae(){M=!1,w&&O&&k&&(re(performance.now()),i(!0))}function oe(){e.clientWidth&&e.clientHeight&&(P=e.clientWidth,F=e.clientHeight,o.setPixelRatio(l?Math.min(1,1024/P):Math.min(window.devicePixelRatio||1,1.5,2200/P)),o.setSize(P,F,!1),R())}function se(e){C=e,R()}function z(e){if(L===e)return;L=e;for(let t of Tt)g(m[t],e?.ink[t]??null);let t=performance.now();I=+(e?.plan.direction===-1),ee=e?{start:t,from:I}:void 0,cancelAnimationFrame(N),e&&T?.(),re(t)}let ue=new ResizeObserver(oe);return ue.observe(e),u.addEventListener(`webglcontextlost`,ie),u.addEventListener(`webglcontextrestored`,ae),oe(),new Vi().load(Va,({scene:e})=>{if(j)return Ga(e);w=e;let n=e.getObjectByName(`LeftPage`),a=e.getObjectByName(`RightPage`);if(!(n instanceof dt&&a instanceof dt)){i(!1);return}let o=Ja(a,`inkFrontFrame`),s=Ja(a,`inkBackFrame`),c=Ja(n,`inkFrontFrame`);if(a.material instanceof Ie){let e=a.material;e.onBeforeCompile=e=>{e.uniforms.frontInk=m.front,e.uniforms.backInk=m.back,e.uniforms.printTurning=h,e.vertexShader=`attribute vec3 inkFrontFrame; attribute vec3 inkBackFrame; varying vec3 frontFrame; varying vec3 backFrame;
4271
+ ${e.vertexShader.replace(`#include <uv_vertex>`,`#include <uv_vertex>
4272
+ frontFrame=inkFrontFrame;backFrame=inkBackFrame;`)}`,e.fragmentShader=`uniform sampler2D frontInk; uniform sampler2D backInk; uniform float printTurning; varying vec3 frontFrame; varying vec3 backFrame;
4273
+ ${e.fragmentShader.replace(`#include <color_fragment>`,`#include <color_fragment>
4274
+ if(printTurning>0.){
4275
+ vec4 ink;
4276
+ if(gl_FrontFacing){
4277
+ ink=texture2D(frontInk,frontFrame.xy/frontFrame.z*.5+.5);
4278
+ }else{
4279
+ diffuseColor.rgb*=vec3(.73,.65,.54);
4280
+ ink=texture2D(backInk,backFrame.xy/backFrame.z*.5+.5);
4281
+ }
4282
+ diffuseColor.rgb=mix(diffuseColor.rgb,ink.rgb,ink.a);
4283
+ }`)}`}}E=a,O=Ka(n),k=Ka(a);let l=e.getObjectByName(`UnderPage`);if(e.traverse(e=>{if(!(e instanceof dt)||!(e.material instanceof Ie))return;let n=e.material.name;if(n===`Cut edges`){e.material.onBeforeCompile=e=>{e.fragmentShader=e.fragmentShader.replace(`#include <opaque_fragment>`,`
4284
+ vec3 edgeNormal=inverseTransformDirection(normal,viewMatrix);
4285
+ float endGrain=smoothstep(.44,.94,abs(edgeNormal.z));
4286
+ outgoingLight*=mix(vec3(1.),vec3(.57,.42,.33),endGrain);
4287
+ #include <opaque_fragment>`)},e.material.customProgramCacheKey=()=>`paper-stack-edges`;return}let i=n===`Antique gold`;if(!i&&n!==`Oxblood leather`)return;let{dye:a,light:o}=t(``,r);e.material.onBeforeCompile=e=>{!i&&a&&(e.fragmentShader=e.fragmentShader.replace(`#include <color_fragment>`,`#include <color_fragment>
4288
+ float leatherGrain = dot(diffuseColor.rgb, vec3(.55,.30,.15));
4289
+ diffuseColor.rgb = leatherGrain * vec3(${a});`)),e.fragmentShader=e.fragmentShader.replace(`#include <opaque_fragment>`,`
4290
+ vec3 reflected=inverseTransformDirection(reflect(-normalize(vViewPosition),normal),viewMatrix);
4291
+ float angle=atan(reflected.x,reflected.y);
4292
+ float strip=exp(-.5*pow((angle-${i?`.075`:`.74`})/(${i?`.21+.22`:`.075+.16`}*roughnessFactor),2.))*smoothstep(-.5,.1,reflected.y);
4293
+ ${i?`outgoingLight=outgoingLight*vec3(.93,.94,1.22)+vec3(.39,.29,.15)*strip;`:`outgoingLight+=vec3(${o})*strip;`}
4294
+ #include <opaque_fragment>`)},e.material.customProgramCacheKey=()=>i?`foil-studio`:`leather-studio-${r}`}),l instanceof dt){l.geometry===n.geometry&&(l.geometry=l.geometry.clone());let t=Ja(l,`inkFrontFrame`);T=()=>{ne(),e.updateMatrixWorld(!0),Ya(n,c,_),Ya(l,t,_),Xa(a,0),Ya(a,o,_),Xa(a,1),Ya(a,s,_),Xa(a,I)},A=Ka(l),D=Za(a,n,l,m,h)}d.add(e),re(performance.now()),i(!M)},void 0,()=>{j||i(!1)}),{setFittedRead:se,setTurn:z,dispose(){j=!0,ue.disconnect(),cancelAnimationFrame(N),u.removeEventListener(`webglcontextlost`,ie),u.removeEventListener(`webglcontextrestored`,ae);for(let e of Tt)m[e].value!==p&&m[e].value.dispose();p.dispose(),w&&Ga(w),S.geometry.dispose(),S.material.dispose(),o.dispose(),u.remove()}}}function $a(t){let a=i(null),o=i(t);o.current=t;let s=i(null);return n(()=>{if(a.current){try{s.current=Qa(a.current,o.current.fittedRead,o.current.binding,e=>o.current.onReady(e),e=>o.current.onTurnDone(e))}catch{o.current.onReady(!1)}return()=>{s.current?.dispose(),s.current=null}}},[]),e(()=>{s.current?.setFittedRead(t.fittedRead)},[t.fittedRead]),e(()=>{s.current?.setTurn(t.turn)},[t.turn]),r(`div`,{ref:a,style:{position:`absolute`,inset:0}})}export{$a as default};