diff --git a/angular.json b/angular.json index 2c7dd7a..6ef4946 100644 --- a/angular.json +++ b/angular.json @@ -81,8 +81,8 @@ "budgets": [ { "type": "initial", - "maximumWarning": "500kb", - "maximumError": "1mb" + "maximumWarning": "1mb", + "maximumError": "5mb" }, { "type": "anyComponentStyle", diff --git a/docs/3rdpartylicenses.txt b/docs/3rdpartylicenses.txt new file mode 100644 index 0000000..5f9d817 --- /dev/null +++ b/docs/3rdpartylicenses.txt @@ -0,0 +1,372 @@ + +-------------------------------------------------------------------------------- +Package: xhr2 +License: "MIT" + +Copyright (c) 2013 Victor Costan + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +-------------------------------------------------------------------------------- +Package: @angular/core +License: "MIT" + + +-------------------------------------------------------------------------------- +Package: rxjs +License: "Apache-2.0" + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright (c) 2015-2018 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +-------------------------------------------------------------------------------- +Package: tslib +License: "0BSD" + +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +-------------------------------------------------------------------------------- +Package: @angular/common +License: "MIT" + + +-------------------------------------------------------------------------------- +Package: @angular/platform-browser +License: "MIT" + + +-------------------------------------------------------------------------------- +Package: @angular/router +License: "MIT" + + +-------------------------------------------------------------------------------- +Package: molstar +License: "MIT" + +The MIT License + + Copyright (c) 2017 - now, Mol* contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +-------------------------------------------------------------------------------- +Package: immutable +License: "MIT" + +MIT License + +Copyright (c) 2014-present, Lee Byron and other contributors. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +-------------------------------------------------------------------------------- +Package: immer +License: "MIT" + +MIT License + +Copyright (c) 2017 Michel Weststrate + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +-------------------------------------------------------------------------------- +Package: zone.js +License: "MIT" + +The MIT License + +Copyright (c) 2010-2023 Google LLC. https://angular.io/license + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +-------------------------------------------------------------------------------- diff --git a/docs/browser/assets/ngx-structure-viewer.png b/docs/browser/assets/ngx-structure-viewer.png new file mode 100644 index 0000000..af623ac Binary files /dev/null and b/docs/browser/assets/ngx-structure-viewer.png differ diff --git a/docs/browser/assets/ngx-structure-viewer.svg b/docs/browser/assets/ngx-structure-viewer.svg new file mode 100644 index 0000000..10ab1b0 --- /dev/null +++ b/docs/browser/assets/ngx-structure-viewer.svg @@ -0,0 +1,155 @@ + + + + diff --git a/docs/browser/favicon.ico b/docs/browser/favicon.ico new file mode 100644 index 0000000..57614f9 Binary files /dev/null and b/docs/browser/favicon.ico differ diff --git a/docs/browser/index.html b/docs/browser/index.html new file mode 100644 index 0000000..8897ab4 --- /dev/null +++ b/docs/browser/index.html @@ -0,0 +1,13 @@ + + +
+ +0&&Math.sqrt(N)-g[j]>S)continue;if(_)return!0;xu.add(t,l[F],N)}}}return t.count>0}var QH=y(),tp=y(),rx=new Set,KM=new Set,zxe=[.1],Hxe=[.1],jxe=[.1],N0=new I_;function qxe(e,t){var r=e.grid,n=r.min,a=r.expandedBox,i=r.boundingSphere.center,o=r.size,s=o[0],u=o[1],c=o[2],l=r.bucketOffset,f=r.bucketCounts,d=r.bucketArray,m=r.grid,h=r.data,p=h.x,v=h.y,g=h.z,b=h.indices,x=h.radius,S=r.delta,_=r.maxRadius,C=e.x,D=e.y,T=e.z,A=e.k,E=e.stopIf,I=Ee.size(b);if(xu.reset(t),I===0||A<=0)return!1;var R,B,O,z=!1,k=1,G=!0,V=0,U=zxe,Q=Hxe,W=0,X=!0,ae,q=!1,F=jxe,j=_*_;U.length=0,F.length=0,rx.clear(),N0.clear(),y.set(tp,C,D,T),gt.containsVec3(a,tp)?(R=Math.floor((C-n[0])/S[0]),B=Math.floor((D-n[1])/S[1]),O=Math.floor((T-n[2])/S[2])):(gt.nearestIntersectionWithRay(tp,a,tp,y.normalize(QH,y.sub(QH,i,tp))),R=Math.max(0,Math.min(s-1,Math.floor((tp[0]-n[0])/S[0]))),B=Math.max(0,Math.min(u-1,Math.floor((tp[1]-n[1])/S[1]))),O=Math.max(0,Math.min(c-1,Math.floor((tp[2]-n[2])/S[2]))));var Z=_!==0?Math.max(1,Math.min(s-1,Math.ceil(_/S[0]))):1,Y=_!==0?Math.max(1,Math.min(u-1,Math.ceil(_/S[1]))):1,H=_!==0?Math.max(1,Math.min(c-1,Math.ceil(_/S[2]))):1;for(U.push(R,B,O,(R*u+B)*c+O);t.count=m.length;var oe=m[ae];if(oe!==0){for(var me=W,pe=oe-1,de=l[pe],re=f[pe],te=de+re,fe=de;feW&&(W=K),N0.insert(K,ve)}me =s))for(var ke=-Y;ke<=Y;ke++){var Ne=B+ke;if(!(Ne<0||Ne>=u))for(var Ve=-H;Ve<=H;Ve++){var et=O+Ve;if(!(et<0||et>=c)&&(ae=(Ie*u+Ne)*c+et,!KM.has(ae)&&(KM.add(ae),!rx.has(ae)))){if(!G){var Re=n[0]+Ie*S[0]-C,je=n[1]+Ne*S[1]-D,tt=n[2]+et*S[2]-T,ht=Re*Re+je*je+tt*tt-j;if(ht>W){F.push(Ie,Ne,et,ae);continue}}Q.push(Ie,Ne,et,ae),V++}}}}}if(G=!1,V===0){if(A===1){var ct=N0.findMinimum();if(ct){var xt=ct,_t=xt.key,Ue=xt.value;return xu.add(t,Ue,_t),!0}}else for(;!N0.isEmpty()&&(q||N0.findMinimum().key<=W)&&t.count=A||z||t.count>=I)return t.count>0;if(G=!0,X=!0,F.length>0){for(var fe=0,ut=F.length;fe 0}function Wxe(e,t){for(var r=0,n=t*3;r this.radiusSq&&(this.radiusSq=r)},e.prototype.radiusSphereStep=function(t,r){var n=Kxe(t,this.center)+r,a=n*n;a>this.radiusSq&&(this.radiusSq=a)},e.prototype.getSphere=function(t){return t||(t=xe()),y.copy(t.center,this.center),t.radius=Math.sqrt(this.radiusSq),t},e.prototype.getCount=function(){return this.count},e}();(function(e){var t=new e,r=y(),n=y();function a(s,u){var c=s.x,l=s.y,f=s.z;t.reset();for(var d=c.length,m=0;m this.maxDist[t]&&(this.maxDist[t]=n,a7(this.extrema[t*2+1],r))},e.prototype.computeSphereExtrema=function(t,r,n){var a=this.dir[t],i=n7(a,r);i-n this.maxDist[t]&&(this.maxDist[t]=i+n,Qxe(this.extrema[t*2+1],r,a,n))},e.prototype.includeSphere=function(t){if(xe.hasExtrema(t)&&t.extrema.length>1)for(var r=0,n=t.extrema;r 1)for(var r=0,n=t.extrema;r 0?Math.ceil(e/n):0;return{width:n,height:a,length:n*a*t}}function Vn(e,t,r,n){var a=rSe(e,t),i=a.length,o=a.width,s=a.height;return n=n&&n.length>=i?n:new r(i),{array:n,width:o,height:s}}var Vc=y(),nSe=new Di("14"),aSe=new Di("98");function o7(e){return e>1e5?nSe:aSe}function Cu(e,t,r){var n=r*3,a=o7(t);a.reset();for(var i=0,o=t*3;i >2),n=t-4>>2,a=4*n,i=0;if(n<0)for(var o=0;o >16]}for(var o=a;o 0.0 && uBumpAmplitude > 0.0 && bumpiness > 0.0) { + material.rgb += fbm(vModelPosition * uBumpFrequency) * uBumpAmplitude * bumpiness; + material.rgb -= 0.5 * uBumpAmplitude * bumpiness; + } + #endif + + gl_FragColor = material; +#else + #ifdef bumpEnabled + if (uBumpFrequency > 0.0 && uBumpAmplitude > 0.0 && bumpiness > 0.0) { + normal = perturbNormal(-vViewPosition, normal, fbm(vModelPosition * uBumpFrequency), (uBumpAmplitude * bumpiness) / uBumpFrequency); + } + #endif + + vec4 color = material; + + ReflectedLight reflectedLight = ReflectedLight(vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0)); + + PhysicalMaterial physicalMaterial; + physicalMaterial.diffuseColor = color.rgb * (1.0 - metalness); + #ifdef enabledFragDepth + physicalMaterial.roughness = min(max(roughness, 0.0525), 1.0); + #else + vec3 dxy = max(abs(dFdx(normal)), abs(dFdy(normal))); + float geometryRoughness = max(max(dxy.x, dxy.y), dxy.z); + physicalMaterial.roughness = min(max(roughness, 0.0525) + geometryRoughness, 1.0); + #endif + physicalMaterial.specularColor = mix(vec3(0.04), color.rgb, metalness); + physicalMaterial.specularF90 = 1.0; + + GeometricContext geometry; + geometry.position = -vViewPosition; + geometry.normal = normal; + geometry.viewDir = normalize(vViewPosition); + + IncidentLight directLight; + #pragma unroll_loop_start + for (int i = 0; i < dLightCount; ++i) { + directLight.direction = uLightDirection[i]; + directLight.color = uLightColor[i] * PI; // * PI for punctual light + RE_Direct_Physical(directLight, geometry, physicalMaterial, reflectedLight); + } + #pragma unroll_loop_end + + vec3 irradiance = uAmbientColor * PI; // * PI for punctual light + RE_IndirectDiffuse_Physical(irradiance, geometry, physicalMaterial, reflectedLight); + + // indirect specular only metals + vec3 radiance = uAmbientColor * metalness; + vec3 iblIrradiance = uAmbientColor * metalness; + vec3 clearcoatRadiance = vec3(0.0); + RE_IndirectSpecular_Physical(radiance, iblIrradiance, clearcoatRadiance, geometry, physicalMaterial, reflectedLight); + + vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular; + outgoingLight = clamp(outgoingLight, 0.01, 0.99); // prevents black artifacts on specular highlight with transparent background + + gl_FragColor = vec4(outgoingLight, color.a); +#endif + +#if defined(dXrayShaded_on) + gl_FragColor.a *= 1.0 - pow(abs(dot(normal, vec3(0.0, 0.0, 1.0))), uXrayEdgeFalloff); +#elif defined(dXrayShaded_inverted) + gl_FragColor.a *= pow(abs(dot(normal, vec3(0.0, 0.0, 1.0))), uXrayEdgeFalloff); +#endif + +gl_FragColor.rgb *= uExposure; +`;var z7=` + +#if defined(dColorMarker) + if (marker > 0.0) { + if ((uMarkerPriority == 1 && marker != 2.0) || (uMarkerPriority != 1 && marker == 1.0)) { + gl_FragColor.rgb = mix(gl_FragColor.rgb, uHighlightColor, uHighlightStrength); + gl_FragColor.a = max(gl_FragColor.a, uHighlightStrength * 0.002); // for direct-volume rendering + } else { + gl_FragColor.rgb = mix(gl_FragColor.rgb, uSelectColor, uSelectStrength); + gl_FragColor.a = max(gl_FragColor.a, uSelectStrength * 0.002); // for direct-volume rendering + } + } else if (uMarkerAverage > 0.0) { + gl_FragColor.rgb = mix(gl_FragColor.rgb, uDimColor, uDimStrength); + gl_FragColor.a = max(gl_FragColor.a, uDimStrength * 0.002); // for direct-volume rendering + } +#endif +`;var H7=` +#if dClipObjectCount != 0 && defined(dClipping) + #if defined(dClippingType_instance) + vClipping = readFromTexture(tClipping, aInstance, uClippingTexDim).a; + #elif defined(dMarkerType_groupInstance) + vClipping = readFromTexture(tClipping, aInstance * float(uGroupCount) + group, uClippingTexDim).a; + #endif +#endif +`;var j7=` +#if defined(dRenderVariant_color) + #if defined(dColorType_attribute) + vColor.rgb = aColor; + #elif defined(dColorType_instance) + vColor.rgb = readFromTexture(tColor, aInstance, uColorTexDim).rgb; + #elif defined(dColorType_group) + vColor.rgb = readFromTexture(tColor, group, uColorTexDim).rgb; + #elif defined(dColorType_groupInstance) + vColor.rgb = readFromTexture(tColor, aInstance * float(uGroupCount) + group, uColorTexDim).rgb; + #elif defined(dColorType_vertex) + vColor.rgb = readFromTexture(tColor, VertexID, uColorTexDim).rgb; + #elif defined(dColorType_vertexInstance) + vColor.rgb = readFromTexture(tColor, int(aInstance) * uVertexCount + VertexID, uColorTexDim).rgb; + #elif defined(dColorType_volume) + vec3 cgridPos = (uColorGridTransform.w * (position - uColorGridTransform.xyz)) / uColorGridDim; + vColor.rgb = texture3dFrom2dLinear(tColorGrid, cgridPos, uColorGridDim, uColorTexDim).rgb; + #elif defined(dColorType_volumeInstance) + vec3 cgridPos = (uColorGridTransform.w * (vModelPosition - uColorGridTransform.xyz)) / uColorGridDim; + vColor.rgb = texture3dFrom2dLinear(tColorGrid, cgridPos, uColorGridDim, uColorTexDim).rgb; + #endif + + #ifdef dUsePalette + vPaletteV = ((vColor.r * 256.0 * 256.0 * 255.0 + vColor.g * 256.0 * 255.0 + vColor.b * 255.0) - 1.0) / 16777215.0; + #endif + + #ifdef dOverpaint + #if defined(dOverpaintType_instance) + vOverpaint = readFromTexture(tOverpaint, aInstance, uOverpaintTexDim); + #elif defined(dOverpaintType_groupInstance) + vOverpaint = readFromTexture(tOverpaint, aInstance * float(uGroupCount) + group, uOverpaintTexDim); + #elif defined(dOverpaintType_vertexInstance) + vOverpaint = readFromTexture(tOverpaint, int(aInstance) * uVertexCount + VertexID, uOverpaintTexDim); + #elif defined(dOverpaintType_volumeInstance) + vec3 ogridPos = (uOverpaintGridTransform.w * (vModelPosition - uOverpaintGridTransform.xyz)) / uOverpaintGridDim; + vOverpaint = texture3dFrom2dLinear(tOverpaintGrid, ogridPos, uOverpaintGridDim, uOverpaintTexDim); + #endif + + // pre-mix to avoid darkening due to empty overpaint + #ifdef dColorType_uniform + vOverpaint.rgb = mix(uColor.rgb, vOverpaint.rgb, vOverpaint.a); + #else + vOverpaint.rgb = mix(vColor.rgb, vOverpaint.rgb, vOverpaint.a); + #endif + vOverpaint *= uOverpaintStrength; + #endif + + #ifdef dSubstance + #if defined(dSubstanceType_instance) + vSubstance = readFromTexture(tSubstance, aInstance, uSubstanceTexDim); + #elif defined(dSubstanceType_groupInstance) + vSubstance = readFromTexture(tSubstance, aInstance * float(uGroupCount) + group, uSubstanceTexDim); + #elif defined(dSubstanceType_vertexInstance) + vSubstance = readFromTexture(tSubstance, int(aInstance) * uVertexCount + VertexID, uSubstanceTexDim); + #elif defined(dSubstanceType_volumeInstance) + vec3 sgridPos = (uSubstanceGridTransform.w * (vModelPosition - uSubstanceGridTransform.xyz)) / uSubstanceGridDim; + vSubstance = texture3dFrom2dLinear(tSubstanceGrid, sgridPos, uSubstanceGridDim, uSubstanceTexDim); + #endif + + // pre-mix to avoid artifacts due to empty substance + vSubstance.rgb = mix(vec3(uMetalness, uRoughness, uBumpiness), vSubstance.rgb, vSubstance.a); + vSubstance *= uSubstanceStrength; + #endif +#elif defined(dRenderVariant_pick) + #ifdef requiredDrawBuffers + vObject = vec4(packIntToRGB(float(uObjectId)), 1.0); + vInstance = vec4(packIntToRGB(aInstance), 1.0); + vGroup = vec4(packIntToRGB(group), 1.0); + #else + if (uPickType == 1) { + vColor = vec4(packIntToRGB(float(uObjectId)), 1.0); + } else if (uPickType == 2) { + vColor = vec4(packIntToRGB(aInstance), 1.0); + } else { + vColor = vec4(packIntToRGB(group), 1.0); + } + #endif +#endif + +#ifdef dTransparency + #if defined(dTransparencyType_instance) + vTransparency = readFromTexture(tTransparency, aInstance, uTransparencyTexDim).a; + #elif defined(dTransparencyType_groupInstance) + vTransparency = readFromTexture(tTransparency, aInstance * float(uGroupCount) + group, uTransparencyTexDim).a; + #elif defined(dTransparencyType_vertexInstance) + vTransparency = readFromTexture(tTransparency, int(aInstance) * uVertexCount + VertexID, uTransparencyTexDim).a; + #elif defined(dTransparencyType_volumeInstance) + vec3 tgridPos = (uTransparencyGridTransform.w * (vModelPosition - uTransparencyGridTransform.xyz)) / uTransparencyGridDim; + vTransparency = texture3dFrom2dLinear(tTransparencyGrid, tgridPos, uTransparencyGridDim, uTransparencyTexDim).a; + #endif + vTransparency *= uTransparencyStrength; +#endif +`;var q7=` +#ifdef dGeometryType_textureMesh + float group = unpackRGBToInt(readFromTexture(tGroup, VertexID, uGeoTexDim).rgb); +#else + float group = aGroup; +#endif +`;var W7=` +#if defined(dNeedsMarker) + #if defined(dMarkerType_instance) + vMarker = readFromTexture(tMarker, aInstance, uMarkerTexDim).a; + #elif defined(dMarkerType_groupInstance) + vMarker = readFromTexture(tMarker, aInstance * float(uGroupCount) + group, uMarkerTexDim).a; + #endif +#endif +`;var Y7=` +#if defined(dNeedsMarker) + float marker = uMarker; + if (uMarker == -1.0) { + marker = floor(vMarker * 255.0 + 0.5); // rounding required to work on some cards on win + } +#endif + +#if defined(dRenderVariant_color) + #if defined(dUsePalette) + vec4 material = vec4(texture2D(tPalette, vec2(vPaletteV, 0.5)).rgb, uAlpha); + #elif defined(dColorType_uniform) + vec4 material = vec4(uColor, uAlpha); + #elif defined(dColorType_varying) + vec4 material = vec4(vColor.rgb, uAlpha); + #endif + + // mix material with overpaint + #if defined(dOverpaint) + material.rgb = mix(material.rgb, vOverpaint.rgb, vOverpaint.a); + #endif + + float metalness = uMetalness; + float roughness = uRoughness; + float bumpiness = uBumpiness; + #ifdef dSubstance + metalness = mix(metalness, vSubstance.r, vSubstance.a); + roughness = mix(roughness, vSubstance.g, vSubstance.a); + bumpiness = mix(bumpiness, vSubstance.b, vSubstance.a); + #endif +#elif defined(dRenderVariant_depth) + if (fragmentDepth > getDepth(gl_FragCoord.xy / uDrawingBufferSize)) { + discard; + } + + #ifndef dXrayShaded + #if defined(dTransparency) + float dta = 1.0 - vTransparency; + if (vTransparency < 0.2) dta = 1.0; // hard cutoff looks better + + if (uRenderMask == MaskTransparent && uAlpha * dta == 1.0) { + discard; + } else if (uRenderMask == MaskOpaque && uAlpha * dta < 1.0) { + discard; + } + #else + if (uRenderMask == MaskTransparent && uAlpha == 1.0) { + discard; + } else if (uRenderMask == MaskOpaque && uAlpha < 1.0) { + discard; + } + #endif + #else + if (uRenderMask == MaskOpaque) { + discard; + } + #endif + + vec4 material = packDepthToRGBA(fragmentDepth); +#elif defined(dRenderVariant_marking) + vec4 material; + if(uMarkingType == 1) { + if (marker > 0.0) + discard; + #ifdef enabledFragDepth + material = packDepthToRGBA(gl_FragDepthEXT); + #else + material = packDepthToRGBA(gl_FragCoord.z); + #endif + } else { + if (marker == 0.0) + discard; + float depthTest = 1.0; + if (uMarkingDepthTest) { + depthTest = (fragmentDepth >= getDepthPacked(gl_FragCoord.xy / uDrawingBufferSize)) ? 1.0 : 0.0; + } + bool isHighlight = intMod(marker, 2.0) > 0.1; + float viewZ = depthToViewZ(uIsOrtho, fragmentDepth, uNear, uFar); + float fogFactor = smoothstep(uFogNear, uFogFar, abs(viewZ)); + if (fogFactor == 1.0) + discard; + material = vec4(0.0, depthTest, isHighlight ? 1.0 : 0.0, 1.0 - fogFactor); + } +#endif + +// apply per-group transparency +#if defined(dTransparency) && (defined(dRenderVariant_pick) || defined(dRenderVariant_color)) + float ta = 1.0 - vTransparency; + if (vTransparency < 0.09) ta = 1.0; // hard cutoff looks better + + #if defined(dRenderVariant_pick) + if (ta < uPickingAlphaThreshold) + discard; // ignore so the element below can be picked + #elif defined(dRenderVariant_color) + material.a *= ta; + + #if defined(dRenderVariant_colorBlended) + #if defined(dTransparentBackfaces_off) + if ((uRenderMask == MaskOpaque && material.a < 1.0) || + (uRenderMask == MaskTransparent && material.a == 1.0) || + (interior && material.a < 1.0) + ) { + discard; + } + #elif defined(dTransparentBackfaces_on) + if ((uRenderMask == MaskOpaque && material.a < 1.0) || + (uRenderMask == MaskTransparent && material.a == 1.0) + ) { + discard; + } + #elif defined(dTransparentBackfaces_opaque) + if (interior) { + material.a = 1.0; + } else if ( + (uRenderMask == MaskOpaque && material.a < 1.0) || + (uRenderMask == MaskTransparent && material.a == 1.0) + ) { + discard; + } + #endif + #endif + #endif +#endif +`;var X7=` +mat4 model = uModel * aTransform; +mat4 modelView = uView * model; +#ifdef dGeometryType_textureMesh + vec3 position = readFromTexture(tPosition, VertexID, uGeoTexDim).xyz; +#else + vec3 position = aPosition; +#endif +vec4 position4 = vec4(position, 1.0); +// for accessing tColorGrid in vert shader and for clipping in frag shader +vModelPosition = (model * position4).xyz; +vec4 mvPosition = modelView * position4; +vViewPosition = mvPosition.xyz; +gl_Position = uProjection * mvPosition; +`;var K7=` +#if defined(dSizeType_uniform) + float size = uSize; +#elif defined(dSizeType_attribute) + float size = aSize; +#elif defined(dSizeType_instance) + float size = unpackRGBToInt(readFromTexture(tSize, aInstance, uSizeTexDim).rgb); +#elif defined(dSizeType_group) + float size = unpackRGBToInt(readFromTexture(tSize, group, uSizeTexDim).rgb); +#elif defined(dSizeType_groupInstance) + float size = unpackRGBToInt(readFromTexture(tSize, aInstance * float(uGroupCount) + group, uSizeTexDim).rgb); +#endif + +#if defined(dSizeType_instance) || defined(dSizeType_group) || defined(dSizeType_groupInstance) + size /= 100.0; // NOTE factor also set in TypeScript +#endif + +size *= uSizeFactor; +`;var Z7=` +float viewZ = depthToViewZ(uIsOrtho, fragmentDepth, uNear, uFar); +float fogFactor = smoothstep(uFogNear, uFogFar, abs(viewZ)); +float alpha = (1.0 - fogFactor) * uAlpha; +// if not opaque enough ignore so the element below can be picked +if (uAlpha < uPickingAlphaThreshold || alpha < 0.1) { + #ifdef dTransparentBackfaces_opaque + if (!interior) discard; + #else + discard; + #endif +} +`;var Q7=` +#if defined(dClipVariant_instance) && dClipObjectCount != 0 + vec4 mCenter = uModel * aTransform * vec4(uInvariantBoundingSphere.xyz, 1.0); + if (clipTest(vec4(mCenter.xyz, uInvariantBoundingSphere.w))) + // move out of [ -w, +w ] to 'discard' in vert shader + gl_Position.z = 2.0 * gl_Position.w; +#endif +`;var $7=` +#if defined(dClipVariant_pixel) && dClipObjectCount != 0 + if (clipTest(vec4(vModelPosition, 0.0))) + discard; +#endif +`;var J7=` +uniform float uMetalness; +uniform float uRoughness; +uniform float uBumpiness; +#ifdef bumpEnabled + uniform float uBumpFrequency; + uniform float uBumpAmplitude; +#endif + +#if defined(dRenderVariant_color) + #if defined(dColorType_uniform) + uniform vec3 uColor; + #elif defined(dColorType_varying) + varying vec4 vColor; + #endif + + #ifdef dUsePalette + uniform sampler2D tPalette; + varying float vPaletteV; + #endif + + #ifdef dOverpaint + varying vec4 vOverpaint; + #endif + + #ifdef dSubstance + varying vec4 vSubstance; + #endif +#elif defined(dRenderVariant_pick) + #if __VERSION__ == 100 || !defined(dVaryingGroup) + #ifdef requiredDrawBuffers + varying vec4 vObject; + varying vec4 vInstance; + varying vec4 vGroup; + #else + varying vec4 vColor; + #endif + #else + #ifdef requiredDrawBuffers + flat in vec4 vObject; + flat in vec4 vInstance; + flat in vec4 vGroup; + #else + flat in vec4 vColor; + #endif + #endif +#endif + +#ifdef dTransparency + varying float vTransparency; +#endif +`;var e9=` +uniform float uMetalness; +uniform float uRoughness; +uniform float uBumpiness; + +#if defined(dRenderVariant_color) + #if defined(dColorType_uniform) + uniform vec3 uColor; + #elif defined(dColorType_attribute) + varying vec4 vColor; + attribute vec3 aColor; + #elif defined(dColorType_texture) + varying vec4 vColor; + uniform vec2 uColorTexDim; + uniform sampler2D tColor; + #elif defined(dColorType_grid) + varying vec4 vColor; + uniform vec2 uColorTexDim; + uniform vec3 uColorGridDim; + uniform vec4 uColorGridTransform; + uniform sampler2D tColorGrid; + #elif defined(dColorType_direct) + varying vec4 vColor; + #endif + + #ifdef dUsePalette + varying float vPaletteV; + #endif + + #ifdef dOverpaint + #if defined(dOverpaintType_instance) || defined(dOverpaintType_groupInstance) || defined(dOverpaintType_vertexInstance) + varying vec4 vOverpaint; + uniform vec2 uOverpaintTexDim; + uniform sampler2D tOverpaint; + #elif defined(dOverpaintType_volumeInstance) + varying vec4 vOverpaint; + uniform vec2 uOverpaintTexDim; + uniform vec3 uOverpaintGridDim; + uniform vec4 uOverpaintGridTransform; + uniform sampler2D tOverpaintGrid; + #endif + uniform float uOverpaintStrength; + #endif + + #ifdef dSubstance + #if defined(dSubstanceType_instance) || defined(dSubstanceType_groupInstance) || defined(dSubstanceType_vertexInstance) + varying vec4 vSubstance; + uniform vec2 uSubstanceTexDim; + uniform sampler2D tSubstance; + #elif defined(dSubstanceType_volumeInstance) + varying vec4 vSubstance; + uniform vec2 uSubstanceTexDim; + uniform vec3 uSubstanceGridDim; + uniform vec4 uSubstanceGridTransform; + uniform sampler2D tSubstanceGrid; + #endif + uniform float uSubstanceStrength; + #endif +#elif defined(dRenderVariant_pick) + #if __VERSION__ == 100 || !defined(dVaryingGroup) + #ifdef requiredDrawBuffers + varying vec4 vObject; + varying vec4 vInstance; + varying vec4 vGroup; + #else + varying vec4 vColor; + #endif + #else + #ifdef requiredDrawBuffers + flat out vec4 vObject; + flat out vec4 vInstance; + flat out vec4 vGroup; + #else + flat out vec4 vColor; + #endif + #endif +#endif + +#ifdef dTransparency + #if defined(dTransparencyType_instance) || defined(dTransparencyType_groupInstance) || defined(dTransparencyType_vertexInstance) + varying float vTransparency; + uniform vec2 uTransparencyTexDim; + uniform sampler2D tTransparency; + #elif defined(dTransparencyType_volumeInstance) + varying float vTransparency; + uniform vec2 uTransparencyTexDim; + uniform vec3 uTransparencyGridDim; + uniform vec4 uTransparencyGridTransform; + uniform sampler2D tTransparencyGrid; + #endif + uniform float uTransparencyStrength; +#endif +`;var t9=` +#if dClipObjectCount != 0 + vec3 quaternionTransform(const in vec4 q, const in vec3 v) { + vec3 t = 2.0 * cross(q.xyz, v); + return v + q.w * t + cross(q.xyz, t); + } + + vec4 computePlane(const in vec3 normal, const in vec3 inPoint) { + return vec4(normalize(normal), -dot(normal, inPoint)); + } + + float planeSD(const in vec4 plane, const in vec3 center) { + return -dot(plane.xyz, center - plane.xyz * -plane.w); + } + + float sphereSD(const in vec3 position, const in vec4 rotation, const in vec3 size, const in vec3 center) { + return ( + length(quaternionTransform(vec4(-rotation.x, -rotation.y, -rotation.z, rotation.w), center - position) / size) - 1.0 + ) * min(min(size.x, size.y), size.z); + } + + float cubeSD(const in vec3 position, const in vec4 rotation, const in vec3 size, const in vec3 center) { + vec3 d = abs(quaternionTransform(vec4(-rotation.x, -rotation.y, -rotation.z, rotation.w), center - position)) - size; + return min(max(d.x, max(d.y, d.z)), 0.0) + length(max(d, 0.0)); + } + + float cylinderSD(const in vec3 position, const in vec4 rotation, const in vec3 size, const in vec3 center) { + vec3 t = quaternionTransform(vec4(-rotation.x, -rotation.y, -rotation.z, rotation.w), center - position); + + vec2 d = abs(vec2(length(t.xz), t.y)) - size.xy; + return min(max(d.x, d.y), 0.0) + length(max(d, 0.0)); + } + + float infiniteConeSD(const in vec3 position, const in vec4 rotation, const in vec3 size, const in vec3 center) { + vec3 t = quaternionTransform(vec4(-rotation.x, -rotation.y, -rotation.z, rotation.w), center - position); + + float q = length(t.xy); + return dot(size.xy, vec2(q, t.z)); + } + + float getSignedDistance(const in vec3 center, const in int type, const in vec3 position, const in vec4 rotation, const in vec3 scale) { + if (type == 1) { + vec3 normal = quaternionTransform(rotation, vec3(0.0, 1.0, 0.0)); + vec4 plane = computePlane(normal, position); + return planeSD(plane, center); + } else if (type == 2) { + return sphereSD(position, rotation, scale * 0.5, center); + } else if (type == 3) { + return cubeSD(position, rotation, scale * 0.5, center); + } else if (type == 4) { + return cylinderSD(position, rotation, scale * 0.5, center); + } else if (type == 5) { + return infiniteConeSD(position, rotation, scale * 0.5, center); + } else { + return 0.1; + } + } + + #if __VERSION__ == 100 + // 8-bit + int bitwiseAnd(in int a, in int b) { + int d = 128; + int result = 0; + for (int i = 0; i < 8; ++i) { + if (d <= 0) break; + if (a >= d && b >= d) result += d; + if (a >= d) a -= d; + if (b >= d) b -= d; + d /= 2; + } + return result; + } + + bool hasBit(const in int mask, const in int bit) { + return bitwiseAnd(mask, bit) == 0; + } + #else + bool hasBit(const in int mask, const in int bit) { + return (mask & bit) == 0; + } + #endif + + bool clipTest(const in vec4 sphere) { + // flag is a bit-flag for clip-objects to ignore (note, object ids start at 1 not 0) + #if defined(dClipping) + int flag = int(floor(vClipping * 255.0 + 0.5)); + #else + int flag = 0; + #endif + + #pragma unroll_loop_start + for (int i = 0; i < dClipObjectCount; ++i) { + if (flag == 0 || hasBit(flag, UNROLLED_LOOP_INDEX + 1)) { + // TODO take sphere radius into account? + bool test = getSignedDistance(sphere.xyz, uClipObjectType[i], uClipObjectPosition[i], uClipObjectRotation[i], uClipObjectScale[i]) <= 0.0; + if ((!uClipObjectInvert[i] && test) || (uClipObjectInvert[i] && !test)) { + return true; + } + } + } + #pragma unroll_loop_end + return false; + } +#endif +`;var r9=` +uniform int uObjectId; +uniform int uInstanceCount; +uniform int uGroupCount; + +uniform int uPickType; +uniform int uMarkingType; + +#if dClipObjectCount != 0 + uniform int uClipObjectType[dClipObjectCount]; + uniform bool uClipObjectInvert[dClipObjectCount]; + uniform vec3 uClipObjectPosition[dClipObjectCount]; + uniform vec4 uClipObjectRotation[dClipObjectCount]; + uniform vec3 uClipObjectScale[dClipObjectCount]; + + #if defined(dClipping) + #if __VERSION__ == 100 || defined(dClippingType_instance) || !defined(dVaryingGroup) + varying float vClipping; + #else + flat in float vClipping; + #endif + #endif +#endif + +#if defined(dColorMarker) + uniform vec3 uHighlightColor; + uniform vec3 uSelectColor; + uniform vec3 uDimColor; + uniform float uHighlightStrength; + uniform float uSelectStrength; + uniform float uDimStrength; + uniform int uMarkerPriority; + uniform float uMarkerAverage; +#endif + +#if defined(dNeedsMarker) + uniform float uMarker; + #if __VERSION__ == 100 || defined(dMarkerType_instance) || !defined(dVaryingGroup) + varying float vMarker; + #else + flat in float vMarker; + #endif +#endif + +#if defined(dRenderVariant_colorDpoit) + #define MAX_DPOIT_DEPTH 99999.0 // NOTE constant also set in TypeScript + uniform sampler2D tDpoitDepth; + uniform sampler2D tDpoitFrontColor; +#endif + +varying vec3 vModelPosition; +varying vec3 vViewPosition; + +uniform vec2 uViewOffset; + +uniform float uNear; +uniform float uFar; +uniform float uIsOrtho; + +uniform bool uFog; +uniform float uFogNear; +uniform float uFogFar; +uniform vec3 uFogColor; + +uniform float uAlpha; +uniform float uPickingAlphaThreshold; +uniform bool uTransparentBackground; + +uniform bool uDoubleSided; +uniform float uInteriorDarkening; +uniform bool uInteriorColorFlag; +uniform vec3 uInteriorColor; +bool interior; + +uniform float uXrayEdgeFalloff; +uniform float uExposure; + +uniform mat4 uProjection; + +uniform int uRenderMask; +uniform bool uMarkingDepthTest; + +uniform sampler2D tDepth; +uniform vec2 uDrawingBufferSize; + +float getDepthPacked(const in vec2 coords) { + return unpackRGBAToDepth(texture2D(tDepth, coords)); +} + +float getDepth(const in vec2 coords) { + #ifdef depthTextureSupport + return texture2D(tDepth, coords).r; + #else + return unpackRGBAToDepth(texture2D(tDepth, coords)); + #endif +} + +float calcDepth(const in vec3 pos) { + vec2 clipZW = pos.z * uProjection[2].zw + uProjection[3].zw; + return 0.5 + 0.5 * clipZW.x / clipZW.y; +} + +// "Bump Mapping Unparametrized Surfaces on the GPU" Morten S. Mikkelsen +// https://mmikk.github.io/papers3d/mm_sfgrad_bump.pdf +vec3 perturbNormal(in vec3 position, in vec3 normal, in float height, in float scale) { + vec3 sigmaS = dFdx(position); + vec3 sigmaT = dFdy(position); + + vec3 r1 = cross(sigmaT, normal); + vec3 r2 = cross(normal, sigmaS); + float det = dot(sigmaS, r1); + + float bs = dFdx(height); + float bt = dFdy(height); + + vec3 surfGrad = sign(det) * (bs * r1 + bt * r2); + return normalize(abs(det) * normal - scale * surfGrad); +} + +float hash(in float h) { + return fract(sin(h) * 43758.5453123); +} + +float noise(in vec3 x) { + vec3 p = floor(x); + vec3 f = fract(x); + f = f * f * (3.0 - 2.0 * f); + + float n = p.x + p.y * 157.0 + 113.0 * p.z; + return mix( + mix(mix(hash(n + 0.0), hash(n + 1.0), f.x), + mix(hash(n + 157.0), hash(n + 158.0), f.x), f.y), + mix(mix(hash(n + 113.0), hash(n + 114.0), f.x), + mix(hash(n + 270.0), hash(n + 271.0), f.x), f.y), f.z); +} + +float fbm(in vec3 p) { + float f = 0.0; + f += 0.5 * noise(p); + p *= 2.01; + f += 0.25 * noise(p); + p *= 2.02; + f += 0.125 * noise(p); + + return f; +} +`;var n9=` +uniform mat4 uProjection, uModel, uView; +uniform vec3 uCameraPosition; + +uniform int uObjectId; +uniform int uVertexCount; +uniform int uInstanceCount; +uniform int uGroupCount; +uniform vec4 uInvariantBoundingSphere; + +uniform bool uDoubleSided; +uniform int uPickType; + +#if dClipObjectCount != 0 + uniform int uClipObjectType[dClipObjectCount]; + uniform bool uClipObjectInvert[dClipObjectCount]; + uniform vec3 uClipObjectPosition[dClipObjectCount]; + uniform vec4 uClipObjectRotation[dClipObjectCount]; + uniform vec3 uClipObjectScale[dClipObjectCount]; + + #if defined(dClipping) + uniform vec2 uClippingTexDim; + uniform sampler2D tClipping; + #if __VERSION__ == 100 || defined(dClippingType_instance) || !defined(dVaryingGroup) + varying float vClipping; + #else + flat out float vClipping; + #endif + #endif +#endif + +#if defined(dNeedsMarker) + uniform float uMarker; + uniform vec2 uMarkerTexDim; + uniform sampler2D tMarker; + #if __VERSION__ == 100 || defined(dMarkerType_instance) || !defined(dVaryingGroup) + varying float vMarker; + #else + flat out float vMarker; + #endif +#endif + +varying vec3 vModelPosition; +varying vec3 vViewPosition; + +#if defined(noNonInstancedActiveAttribs) + // int() is needed for some Safari versions + // see https://bugs.webkit.org/show_bug.cgi?id=244152 + #define VertexID int(gl_VertexID) +#else + attribute float aVertex; + #define VertexID int(aVertex) +#endif +`;var a9=` +// TODO find a better place for these convenience defines + +#if defined(dRenderVariant_colorBlended) || defined(dRenderVariant_colorWboit) || defined(dRenderVariant_colorDpoit) + #define dRenderVariant_color +#endif + +#if defined(dColorType_instance) || defined(dColorType_group) || defined(dColorType_groupInstance) || defined(dColorType_vertex) || defined(dColorType_vertexInstance) + #define dColorType_texture +#endif + +#if defined(dColorType_volume) || defined(dColorType_volumeInstance) + #define dColorType_grid +#endif + +#if defined(dColorType_attribute) || defined(dColorType_texture) || defined(dColorType_grid) + #define dColorType_varying +#endif + +#if (defined(dRenderVariant_color) && defined(dColorMarker)) || defined(dRenderVariant_marking) + #define dNeedsMarker +#endif + +#if defined(dXrayShaded_on) || defined(dXrayShaded_inverted) + #define dXrayShaded +#endif + +#define MaskAll 0 +#define MaskOpaque 1 +#define MaskTransparent 2 + +// + +#define PI 3.14159265 +#define RECIPROCAL_PI 0.31830988618 +#define EPSILON 1e-6 + +#define saturate(a) clamp(a, 0.0, 1.0) + +#if __VERSION__ == 100 + #define round(x) floor((x) + 0.5) +#endif + +float intDiv(const in float a, const in float b) { return float(int(a) / int(b)); } +vec2 ivec2Div(const in vec2 a, const in vec2 b) { return vec2(ivec2(a) / ivec2(b)); } +float intMod(const in float a, const in float b) { return a - b * float(int(a) / int(b)); } +int imod(const in int a, const in int b) { return a - b * (a / b); } + +float pow2(const in float x) { return x * x; } + +vec3 packIntToRGB(in float value) { + value = clamp(round(value), 0.0, 16777216.0 - 1.0) + 1.0; + vec3 c = vec3(0.0); + c.b = mod(value, 256.0); + value = floor(value / 256.0); + c.g = mod(value, 256.0); + value = floor(value / 256.0); + c.r = mod(value, 256.0); + return c / 255.0; +} +float unpackRGBToInt(const in vec3 rgb) { + return (floor(rgb.r * 255.0 + 0.5) * 256.0 * 256.0 + floor(rgb.g * 255.0 + 0.5) * 256.0 + floor(rgb.b * 255.0 + 0.5)) - 1.0; +} + +vec2 packUnitIntervalToRG(const in float v) { + vec2 enc; + enc.xy = vec2(fract(v * 256.0), v); + enc.y -= enc.x * (1.0 / 256.0); + enc.xy *= 256.0 / 255.0; + + return enc; +} + +float unpackRGToUnitInterval(const in vec2 enc) { + return dot(enc, vec2(255.0 / (256.0 * 256.0), 255.0 / 256.0)); +} + +vec3 screenSpaceToViewSpace(const in vec3 ssPos, const in mat4 invProjection) { + vec4 p = vec4(ssPos * 2.0 - 1.0, 1.0); + p = invProjection * p; + return p.xyz / p.w; +} + +const float PackUpscale = 256.0 / 255.0; // fraction -> 0..1 (including 1) +const float UnpackDownscale = 255.0 / 256.0; // 0..1 -> fraction (excluding 1) +const vec3 PackFactors = vec3(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0); +const vec4 UnpackFactors = UnpackDownscale / vec4(PackFactors, 1.0); +const float ShiftRight8 = 1.0 / 256.0; + +vec4 packDepthToRGBA(const in float v) { + vec4 r = vec4(fract(v * PackFactors), v); + r.yzw -= r.xyz * ShiftRight8; // tidy overflow + return r * PackUpscale; +} +float unpackRGBAToDepth(const in vec4 v) { + return dot(v, UnpackFactors); +} + +vec4 sRGBToLinear(const in vec4 c) { + return vec4(mix(pow(c.rgb * 0.9478672986 + vec3(0.0521327014), vec3(2.4)), c.rgb * 0.0773993808, vec3(lessThanEqual(c.rgb, vec3(0.04045)))), c.a); +} +vec4 linearTosRGB(const in vec4 c) { + return vec4(mix(pow(c.rgb, vec3(0.41666)) * 1.055 - vec3(0.055), c.rgb * 12.92, vec3(lessThanEqual(c.rgb, vec3(0.0031308)))), c.a); +} + +float linearizeDepth(const in float depth, const in float near, const in float far) { + return (2.0 * near) / (far + near - depth * (far - near)); +} + +float perspectiveDepthToViewZ(const in float invClipZ, const in float near, const in float far) { + return (near * far) / ((far - near) * invClipZ - far); +} + +float orthographicDepthToViewZ(const in float linearClipZ, const in float near, const in float far) { + return linearClipZ * (near - far) - near; +} + +float depthToViewZ(const in float isOrtho, const in float linearClipZ, const in float near, const in float far) { + return isOrtho == 1.0 ? orthographicDepthToViewZ(linearClipZ, near, far) : perspectiveDepthToViewZ(linearClipZ, near, far); +} + +#if __VERSION__ == 100 + // transpose + + float transpose(const in float m) { + return m; + } + + mat2 transpose2(const in mat2 m) { + return mat2( + m[0][0], m[1][0], + m[0][1], m[1][1] + ); + } + + mat3 transpose3(const in mat3 m) { + return mat3( + m[0][0], m[1][0], m[2][0], + m[0][1], m[1][1], m[2][1], + m[0][2], m[1][2], m[2][2] + ); + } + + mat4 transpose4(const in mat4 m) { + return mat4( + m[0][0], m[1][0], m[2][0], m[3][0], + m[0][1], m[1][1], m[2][1], m[3][1], + m[0][2], m[1][2], m[2][2], m[3][2], + m[0][3], m[1][3], m[2][3], m[3][3] + ); + } + + // inverse + + float inverse(const in float m) { + return 1.0 / m; + } + + mat2 inverse2(const in mat2 m) { + return mat2(m[1][1],-m[0][1], + -m[1][0], m[0][0]) / (m[0][0]*m[1][1] - m[0][1]*m[1][0]); + } + + mat3 inverse3(const in mat3 m) { + float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2]; + float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2]; + float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2]; + + float b01 = a22 * a11 - a12 * a21; + float b11 = -a22 * a10 + a12 * a20; + float b21 = a21 * a10 - a11 * a20; + + float det = a00 * b01 + a01 * b11 + a02 * b21; + + return mat3(b01, (-a22 * a01 + a02 * a21), (a12 * a01 - a02 * a11), + b11, (a22 * a00 - a02 * a20), (-a12 * a00 + a02 * a10), + b21, (-a21 * a00 + a01 * a20), (a11 * a00 - a01 * a10)) / det; + } + + mat4 inverse4(const in mat4 m) { + float + a00 = m[0][0], a01 = m[0][1], a02 = m[0][2], a03 = m[0][3], + a10 = m[1][0], a11 = m[1][1], a12 = m[1][2], a13 = m[1][3], + a20 = m[2][0], a21 = m[2][1], a22 = m[2][2], a23 = m[2][3], + a30 = m[3][0], a31 = m[3][1], a32 = m[3][2], a33 = m[3][3], + + b00 = a00 * a11 - a01 * a10, + b01 = a00 * a12 - a02 * a10, + b02 = a00 * a13 - a03 * a10, + b03 = a01 * a12 - a02 * a11, + b04 = a01 * a13 - a03 * a11, + b05 = a02 * a13 - a03 * a12, + b06 = a20 * a31 - a21 * a30, + b07 = a20 * a32 - a22 * a30, + b08 = a20 * a33 - a23 * a30, + b09 = a21 * a32 - a22 * a31, + b10 = a21 * a33 - a23 * a31, + b11 = a22 * a33 - a23 * a32, + + det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; + + return mat4( + a11 * b11 - a12 * b10 + a13 * b09, + a02 * b10 - a01 * b11 - a03 * b09, + a31 * b05 - a32 * b04 + a33 * b03, + a22 * b04 - a21 * b05 - a23 * b03, + a12 * b08 - a10 * b11 - a13 * b07, + a00 * b11 - a02 * b08 + a03 * b07, + a32 * b02 - a30 * b05 - a33 * b01, + a20 * b05 - a22 * b02 + a23 * b01, + a10 * b10 - a11 * b08 + a13 * b06, + a01 * b08 - a00 * b10 - a03 * b06, + a30 * b04 - a31 * b02 + a33 * b00, + a21 * b02 - a20 * b04 - a23 * b00, + a11 * b07 - a10 * b09 - a12 * b06, + a00 * b09 - a01 * b07 + a02 * b06, + a31 * b01 - a30 * b03 - a32 * b00, + a20 * b03 - a21 * b01 + a22 * b00) / det; + } + + #define isNaN(x) ((x) != (x)) + #define isInf(x) ((x) == (x) + 1.0) +#else + #define transpose2(m) transpose(m) + #define transpose3(m) transpose(m) + #define transpose4(m) transpose(m) + + #define inverse2(m) inverse(m) + #define inverse3(m) inverse(m) + #define inverse4(m) inverse(m) + + #define isNaN isnan + #define isInf isinf +#endif +`;var i9=` + // floatToRgba adapted from https://github.com/equinor/glsl-float-to-rgba + // MIT License, Copyright (c) 2020 Equinor + + float shiftRight (float v, float amt) { + v = floor(v) + 0.5; + return floor(v / exp2(amt)); + } + float shiftLeft (float v, float amt) { + return floor(v * exp2(amt) + 0.5); + } + float maskLast (float v, float bits) { + return mod(v, shiftLeft(1.0, bits)); + } + float extractBits (float num, float from, float to) { + from = floor(from + 0.5); to = floor(to + 0.5); + return maskLast(shiftRight(num, from), to - from); + } + + vec4 floatToRgba(float texelFloat, bool littleEndian) { + if (texelFloat == 0.0) return vec4(0.0, 0.0, 0.0, 0.0); + float sign = texelFloat > 0.0 ? 0.0 : 1.0; + texelFloat = abs(texelFloat); + float exponent = floor(log2(texelFloat)); + float biased_exponent = exponent + 127.0; + float fraction = ((texelFloat / exp2(exponent)) - 1.0) * 8388608.0; + float t = biased_exponent / 2.0; + float last_bit_of_biased_exponent = fract(t) * 2.0; + float remaining_bits_of_biased_exponent = floor(t); + float byte4 = extractBits(fraction, 0.0, 8.0) / 255.0; + float byte3 = extractBits(fraction, 8.0, 16.0) / 255.0; + float byte2 = (last_bit_of_biased_exponent * 128.0 + extractBits(fraction, 16.0, 23.0)) / 255.0; + float byte1 = (sign * 128.0 + remaining_bits_of_biased_exponent) / 255.0; + return ( + littleEndian + ? vec4(byte4, byte3, byte2, byte1) + : vec4(byte1, byte2, byte3, byte4) + ); + } +`;var o9=` +#if dLightCount != 0 + uniform vec3 uLightDirection[dLightCount]; + uniform vec3 uLightColor[dLightCount]; +#endif +uniform vec3 uAmbientColor; + +struct PhysicalMaterial { + vec3 diffuseColor; + float roughness; + vec3 specularColor; + float specularF90; +}; + +struct IncidentLight { + vec3 color; + vec3 direction; +}; + +struct ReflectedLight { + vec3 directDiffuse; + vec3 directSpecular; + vec3 indirectDiffuse; + vec3 indirectSpecular; +}; + +struct GeometricContext { + vec3 position; + vec3 normal; + vec3 viewDir; +}; + +vec3 BRDF_Lambert(const in vec3 diffuseColor) { + return RECIPROCAL_PI * diffuseColor; +} + +vec3 F_Schlick(const in vec3 f0, const in float f90, const in float dotVH) { + // Original approximation by Christophe Schlick '94 + // float fresnel = pow( 1.0 - dotVH, 5.0 ); + // Optimized variant (presented by Epic at SIGGRAPH '13) + // https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf + float fresnel = exp2((-5.55473 * dotVH - 6.98316) * dotVH); + return f0 * (1.0 - fresnel) + (f90 * fresnel); +} + +// Moving Frostbite to Physically Based Rendering 3.0 - page 12, listing 2 +// https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf +float V_GGX_SmithCorrelated(const in float alpha, const in float dotNL, const in float dotNV) { + float a2 = pow2(alpha); + float gv = dotNL * sqrt(a2 + (1.0 - a2) * pow2(dotNV)); + float gl = dotNV * sqrt(a2 + (1.0 - a2) * pow2(dotNL)); + return 0.5 / max(gv + gl, EPSILON); +} + +// Microfacet Models for Refraction through Rough Surfaces - equation (33) +// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html +// alpha is "roughness squared" in Disney\u2019s reparameterization +float D_GGX(const in float alpha, const in float dotNH) { + float a2 = pow2(alpha); + float denom = pow2(dotNH) * (a2 - 1.0) + 1.0; // avoid alpha = 0 with dotNH = 1 + return RECIPROCAL_PI * a2 / pow2(denom); +} + +// GGX Distribution, Schlick Fresnel, GGX_SmithCorrelated Visibility +vec3 BRDF_GGX(const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 f0, const in float f90, const in float roughness) { + float alpha = pow2(roughness); // UE4's roughness + vec3 halfDir = normalize( lightDir + viewDir); + float dotNL = saturate(dot(normal, lightDir)); + float dotNV = saturate(dot(normal, viewDir)); + float dotNH = saturate(dot(normal, halfDir)); + float dotVH = saturate(dot(viewDir, halfDir)); + vec3 F = F_Schlick(f0, f90, dotVH); + float V = V_GGX_SmithCorrelated(alpha, dotNL, dotNV); + float D = D_GGX(alpha, dotNH); + return F * (V * D); +} + +// Analytical approximation of the DFG LUT, one half of the +// split-sum approximation used in indirect specular lighting. +// via 'environmentBRDF' from "Physically Based Shading on Mobile" +// https://www.unrealengine.com/blog/physically-based-shading-on-mobile +vec2 DFGApprox(const in vec3 normal, const in vec3 viewDir, const in float roughness) { + float dotNV = saturate(dot(normal, viewDir)); + const vec4 c0 = vec4(-1, -0.0275, -0.572, 0.022); + const vec4 c1 = vec4(1, 0.0425, 1.04, -0.04); + vec4 r = roughness * c0 + c1; + float a004 = min(r.x * r.x, exp2(-9.28 * dotNV)) * r.x + r.y; + vec2 fab = vec2(-1.04, 1.04) * a004 + r.zw; + return fab; +} + +// Fdez-Ag\xFCera's "Multiple-Scattering Microfacet Model for Real-Time Image Based Lighting" +// Approximates multiscattering in order to preserve energy. +// http://www.jcgt.org/published/0008/01/03/ +void computeMultiscattering(const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter) { + vec2 fab = DFGApprox(normal, viewDir, roughness); + vec3 FssEss = specularColor * fab.x + specularF90 * fab.y; + float Ess = fab.x + fab.y; + float Ems = 1.0 - Ess; + vec3 Favg = specularColor + (1.0 - specularColor) * 0.047619; // 1/21 + vec3 Fms = FssEss * Favg / (1.0 - Ems * Favg); + singleScatter += FssEss; + multiScatter += Fms * Ems; +} + +void RE_Direct_Physical(const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) { + float dotNL = saturate(dot(geometry.normal, directLight.direction)); + vec3 irradiance = dotNL * directLight.color; + reflectedLight.directSpecular += irradiance * BRDF_GGX(directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularF90, material.roughness); + reflectedLight.directDiffuse += irradiance * BRDF_Lambert(material.diffuseColor); +} + +void RE_IndirectDiffuse_Physical(const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) { + reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert(material.diffuseColor); +} + +void RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) { + // Both indirect specular and indirect diffuse light accumulate here + vec3 singleScattering = vec3(0.0); + vec3 multiScattering = vec3(0.0); + vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI; + computeMultiscattering(geometry.normal, geometry.viewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering); + vec3 diffuse = material.diffuseColor * (1.0 - ( singleScattering + multiScattering)); + reflectedLight.indirectSpecular += radiance * singleScattering; + reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance; + reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance; +} +`;var s9=` +float matrixScale(in mat4 m){ + vec4 r = m[0]; + return sqrt(r[0] * r[0] + r[1] * r[1] + r[2] * r[2]); +} +`;var u9=` +varying vec3 vNormal; +`;var c9=` +vec4 readFromTexture(const in sampler2D tex, const in float i, const in vec2 dim) { + float x = intMod(i, dim.x); + float y = floor(intDiv(i, dim.x)); + vec2 uv = (vec2(x, y) + 0.5) / dim; + return texture2D(tex, uv); +} + +vec4 readFromTexture(const in sampler2D tex, const in int i, const in vec2 dim) { + int x = imod(i, int(dim.x)); + int y = i / int(dim.x); + vec2 uv = (vec2(x, y) + 0.5) / dim; + return texture2D(tex, uv); +} +`;var l9=` + // rgbaToFloat adapted from https://github.com/ihmeuw/glsl-rgba-to-float + // BSD 3-Clause License + // + // Copyright (c) 2019, Institute for Health Metrics and Evaluation All rights reserved. + // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + // - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + // - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + // - Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + // + // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + // IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + // OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + // OF THE POSSIBILITY OF SUCH DAMAGE. + + ivec4 floatsToBytes(vec4 inputFloats, bool littleEndian) { + ivec4 bytes = ivec4(inputFloats * 255.0); + return ( + littleEndian + ? bytes.abgr + : bytes + ); + } + + // Break the four bytes down into an array of 32 bits. + void bytesToBits(const in ivec4 bytes, out bool bits[32]) { + for (int channelIndex = 0; channelIndex < 4; ++channelIndex) { + float acc = float(bytes[channelIndex]); + for (int indexInByte = 7; indexInByte >= 0; --indexInByte) { + float powerOfTwo = exp2(float(indexInByte)); + bool bit = acc >= powerOfTwo; + bits[channelIndex * 8 + (7 - indexInByte)] = bit; + acc = mod(acc, powerOfTwo); + } + } + } + + // Compute the exponent of the 32-bit float. + float getExponent(bool bits[32]) { + const int startIndex = 1; + const int bitStringLength = 8; + const int endBeforeIndex = startIndex + bitStringLength; + float acc = 0.0; + int pow2 = bitStringLength - 1; + for (int bitIndex = startIndex; bitIndex < endBeforeIndex; ++bitIndex) { + acc += float(bits[bitIndex]) * exp2(float(pow2--)); + } + return acc; + } + + // Compute the mantissa of the 32-bit float. + float getMantissa(bool bits[32], bool subnormal) { + const int startIndex = 9; + const int bitStringLength = 23; + const int endBeforeIndex = startIndex + bitStringLength; + // Leading/implicit/hidden bit convention: + // If the number is not subnormal (with exponent 0), we add a leading 1 digit. + float acc = float(!subnormal) * exp2(float(bitStringLength)); + int pow2 = bitStringLength - 1; + for (int bitIndex = startIndex; bitIndex < endBeforeIndex; ++bitIndex) { + acc += float(bits[bitIndex]) * exp2(float(pow2--)); + } + return acc; + } + + // Parse the float from its 32 bits. + float bitsToFloat(bool bits[32]) { + float signBit = float(bits[0]) * -2.0 + 1.0; + float exponent = getExponent(bits); + bool subnormal = abs(exponent - 0.0) < 0.01; + float mantissa = getMantissa(bits, subnormal); + float exponentBias = 127.0; + return signBit * mantissa * exp2(exponent - exponentBias - 23.0); + } + + float rgbaToFloat(vec4 texelRGBA, bool littleEndian) { + ivec4 rgbaBytes = floatsToBytes(texelRGBA, littleEndian); + bool bits[32]; + bytesToBits(rgbaBytes, bits); + return bitsToFloat(bits); + } +`;var f9=` +#if defined(dSizeType_uniform) + uniform float uSize; +#elif defined(dSizeType_attribute) + attribute float aSize; +#elif defined(dSizeType_instance) || defined(dSizeType_group) || defined(dSizeType_groupInstance) + uniform vec2 uSizeTexDim; + uniform sampler2D tSize; +#endif + +uniform float uSizeFactor; +`;var d9=` +vec4 texture3dFrom1dTrilinear(const in sampler2D tex, const in vec3 pos, const in vec3 gridDim, const in vec2 texDim, const in float offset) { + float gdYZ = gridDim.z * gridDim.y; + float gdZ = gridDim.z; + vec3 p0 = floor(pos * gridDim); + vec3 p1 = ceil(pos * gridDim); + vec3 pd = (pos * gridDim - p0) / (p1 - p0); + vec4 s000 = readFromTexture(tex, offset + p0.z + p0.y * gdZ + p0.x * gdYZ, texDim); + vec4 s100 = readFromTexture(tex, offset + p0.z + p0.y * gdZ + p1.x * gdYZ, texDim); + vec4 s001 = readFromTexture(tex, offset + p1.z + p0.y * gdZ + p0.x * gdYZ, texDim); + vec4 s101 = readFromTexture(tex, offset + p1.z + p0.y * gdZ + p1.x * gdYZ, texDim); + vec4 s010 = readFromTexture(tex, offset + p0.z + p1.y * gdZ + p0.x * gdYZ, texDim); + vec4 s110 = readFromTexture(tex, offset + p0.z + p1.y * gdZ + p1.x * gdYZ, texDim); + vec4 s011 = readFromTexture(tex, offset + p1.z + p1.y * gdZ + p0.x * gdYZ, texDim); + vec4 s111 = readFromTexture(tex, offset + p1.z + p1.y * gdZ + p1.x * gdYZ, texDim); + vec4 s00 = mix(s000, s100, pd.x); + vec4 s01 = mix(s001, s101, pd.x); + vec4 s10 = mix(s010, s110, pd.x); + vec4 s11 = mix(s011, s111, pd.x); + vec4 s0 = mix(s00, s10, pd.y); + vec4 s1 = mix(s01, s11, pd.y); + return mix(s0, s1, pd.z); +} +`;var m9=` +vec4 texture3dFrom2dLinear(sampler2D tex, vec3 pos, vec3 gridDim, vec2 texDim) { + float zSlice0 = floor(pos.z * gridDim.z); + float column0 = intMod(zSlice0 * gridDim.x, texDim.x) / gridDim.x; + float row0 = floor(intDiv(zSlice0 * gridDim.x, texDim.x)); + vec2 coord0 = (vec2(column0 * gridDim.x, row0 * gridDim.y) + (pos.xy * gridDim.xy)) / texDim; + vec4 color0 = texture2D(tex, coord0); + + float zSlice1 = zSlice0 + 1.0; + float column1 = intMod(zSlice1 * gridDim.x, texDim.x) / gridDim.x; + float row1 = floor(intDiv(zSlice1 * gridDim.x, texDim.x)); + vec2 coord1 = (vec2(column1 * gridDim.x, row1 * gridDim.y) + (pos.xy * gridDim.xy)) / texDim; + vec4 color1 = texture2D(tex, coord1); + + float delta0 = abs((pos.z * gridDim.z) - zSlice0); + return mix(color0, color1, delta0); +} +`;var p9=` +vec4 texture3dFrom2dNearest(sampler2D tex, vec3 pos, vec3 gridDim, vec2 texDim) { + float zSlice = floor(pos.z * gridDim.z + 0.5); // round to nearest z-slice + float column = intMod(zSlice * gridDim.x, texDim.x) / gridDim.x; + float row = floor(intDiv(zSlice * gridDim.x, texDim.x)); + vec2 coord = (vec2(column * gridDim.x, row * gridDim.y) + (pos.xy * gridDim.xy)) / texDim; + return texture2D(tex, coord); +} +`;var h9=` +#if defined(dRenderVariant_colorWboit) + if (uRenderMask == MaskOpaque) { + if (preFogAlpha < 1.0) { + discard; + } + } else if (uRenderMask == MaskTransparent) { + if (preFogAlpha != 1.0 && fragmentDepth < getDepth(gl_FragCoord.xy / uDrawingBufferSize)) { + #ifdef dTransparentBackfaces_off + if (interior) discard; + #endif + float alpha = gl_FragColor.a; + float wboitWeight = alpha * clamp(pow(1.0 - fragmentDepth, 2.0), 0.01, 1.0); + gl_FragColor = vec4(gl_FragColor.rgb * alpha * wboitWeight, alpha); + // extra alpha is to handle pre-multiplied alpha + #ifndef dGeometryType_directVolume + gl_FragData[1] = vec4((uTransparentBackground ? alpha : 1.0) * alpha * wboitWeight); + #else + gl_FragData[1] = vec4(alpha * alpha * wboitWeight); + #endif + } else { + discard; + } + } +#endif +`;var v9=` +#if defined(dRenderVariant_colorDpoit) + if (uRenderMask == MaskOpaque) { + if (preFogAlpha < 1.0) { + discard; + } + } else if (uRenderMask == MaskTransparent) { + vec2 coords = gl_FragCoord.xy / uDrawingBufferSize; + if (preFogAlpha != 1.0 && fragmentDepth < getDepth(coords)) { + #ifdef dTransparentBackfaces_off + if (interior) discard; + #endif + + // adapted from https://github.com/tsherif/webgl2examples + // The MIT License, Copyright 2017 Tarek Sherif, Shuai Shao + + vec2 lastDepth = texture2D(tDpoitDepth, coords).rg; + vec4 lastFrontColor = texture2D(tDpoitFrontColor, coords); + + vec4 fragColor = gl_FragColor; + + // depth value always increases + // so we can use MAX blend equation + gl_FragData[2].rg = vec2(-MAX_DPOIT_DEPTH); + + // front color always increases + // so we can use MAX blend equation + gl_FragColor = lastFrontColor; + + // back color is separately blend afterwards each pass + gl_FragData[1] = vec4(0.0); + + float nearestDepth = -lastDepth.x; + float furthestDepth = lastDepth.y; + float alphaMultiplier = 1.0 - lastFrontColor.a; + + if (fragmentDepth < nearestDepth || fragmentDepth > furthestDepth) { + // Skip this depth since it's been peeled. + return; + } + + if (fragmentDepth > nearestDepth && fragmentDepth < furthestDepth) { + // This needs to be peeled. + // The ones remaining after MAX blended for + // all need-to-peel will be peeled next pass. + gl_FragData[2].rg = vec2(-fragmentDepth, fragmentDepth); + return; + } + + // write to back and front color buffer + if (fragmentDepth == nearestDepth) { + gl_FragColor.rgb += fragColor.rgb * fragColor.a * alphaMultiplier; + gl_FragColor.a = 1.0 - alphaMultiplier * (1.0 - fragColor.a); + } else { + gl_FragData[1] += fragColor; + } + + } else { + discard; + } + } +#endif +`;var g9=` +precision highp float; +precision highp int; + +#include common +#include read_from_texture +#include common_vert_params +#include color_vert_params +#include size_vert_params +#include common_clip + +uniform float uPixelRatio; +uniform vec4 uViewport; + +attribute vec3 aPosition; +attribute mat4 aTransform; +attribute float aInstance; +attribute float aGroup; + +void main(){ + #include assign_group + #include assign_color_varying + #include assign_marker_varying + #include assign_clipping_varying + #include assign_position + #include assign_size + + #ifdef dPointSizeAttenuation + gl_PointSize = size * uPixelRatio * ((uViewport.w / 2.0) / -mvPosition.z) * 5.0; + #else + gl_PointSize = size * uPixelRatio; + #endif + gl_PointSize = max(1.0, gl_PointSize); + + gl_Position = uProjection * mvPosition; + + #include clip_instance +} +`;var y9=` +precision highp float; +precision highp int; + +#include common +#include common_frag_params +#include color_frag_params +#include common_clip + +const vec2 center = vec2(0.5); +const float radius = 0.5; + +void main(){ + #include clip_pixel + + float fragmentDepth = gl_FragCoord.z; + #include assign_material_color + + #if defined(dPointStyle_circle) + float dist = distance(gl_PointCoord, center); + if (dist > radius) discard; + #elif defined(dPointStyle_fuzzy) + float dist = distance(gl_PointCoord, center); + float fuzzyAlpha = 1.0 - smoothstep(0.0, radius, dist); + if (fuzzyAlpha < 0.0001) discard; + #endif + + #if defined(dRenderVariant_pick) + #include check_picking_alpha + #ifdef requiredDrawBuffers + gl_FragColor = vObject; + gl_FragData[1] = vInstance; + gl_FragData[2] = vGroup; + gl_FragData[3] = packDepthToRGBA(fragmentDepth); + #else + gl_FragColor = vColor; + #endif + #elif defined(dRenderVariant_depth) + gl_FragColor = material; + #elif defined(dRenderVariant_marking) + gl_FragColor = material; + #elif defined(dRenderVariant_color) + gl_FragColor = material; + + #if defined(dPointStyle_fuzzy) + gl_FragColor.a *= fuzzyAlpha; + #endif + + #include apply_marker_color + #include apply_fog + #include wboit_write + #include dpoit_write + #endif +} +`;var b9=` +precision highp float; +precision highp int; + +#include common +#include read_from_texture +#include common_vert_params +#include color_vert_params +#include size_vert_params +#include common_clip + +uniform mat4 uModelView; +uniform mat4 uInvProjection; +uniform float uIsOrtho; + +uniform vec2 uTexDim; +uniform sampler2D tPositionGroup; + +attribute mat4 aTransform; +attribute float aInstance; + +varying float vRadius; +varying vec3 vPoint; +varying vec3 vPointViewPosition; + +#include matrix_scale + +/** + * Bounding rectangle of a clipped, perspective-projected 3D Sphere. + * Michael Mara, Morgan McGuire. 2013 + * + * Specialization by Arseny Kapoulkine, MIT License Copyright (c) 2018 + * https://github.com/zeux/niagara + */ +void sphereProjection(const in vec3 p, const in float r, const in vec2 mapping) { + vec3 pr = p * r; + float pzr2 = p.z * p.z - r * r; + + float vx = sqrt(p.x * p.x + pzr2); + float minx = ((vx * p.x - pr.z) / (vx * p.z + pr.x)) * uProjection[0][0]; + float maxx = ((vx * p.x + pr.z) / (vx * p.z - pr.x)) * uProjection[0][0]; + + float vy = sqrt(p.y * p.y + pzr2); + float miny = ((vy * p.y - pr.z) / (vy * p.z + pr.y)) * uProjection[1][1]; + float maxy = ((vy * p.y + pr.z) / (vy * p.z - pr.y)) * uProjection[1][1]; + + gl_Position.xy = vec2(maxx + minx, maxy + miny) * -0.5; + gl_Position.xy -= mapping * vec2(maxx - minx, maxy - miny) * 0.5; + gl_Position.xy *= gl_Position.w; +} + +void main(void){ + vec2 mapping = vec2(1.0, 1.0); // vertices 2 and 5 + #if __VERSION__ == 100 + int m = imod(VertexID, 6); + #else + int m = VertexID % 6; + #endif + if (m == 0) { + mapping = vec2(-1.0, 1.0); + } else if (m == 1 || m == 3) { + mapping = vec2(-1.0, -1.0); + } else if (m == 4) { + mapping = vec2(1.0, -1.0); + } + + vec4 positionGroup = readFromTexture(tPositionGroup, VertexID / 6, uTexDim); + vec3 position = positionGroup.rgb; + float group = positionGroup.a; + + #include assign_color_varying + #include assign_marker_varying + #include assign_clipping_varying + #include assign_size + + vRadius = size * matrixScale(uModelView); + + vec4 position4 = vec4(position, 1.0); + vec4 mvPosition = uModelView * aTransform * position4; + + #ifdef dApproximate + vec4 mvCorner = vec4(mvPosition.xyz, 1.0); + mvCorner.xy += mapping * vRadius; + gl_Position = uProjection * mvCorner; + #else + if (uIsOrtho == 1.0) { + vec4 mvCorner = vec4(mvPosition.xyz, 1.0); + mvCorner.xy += mapping * vRadius; + gl_Position = uProjection * mvCorner; + } else { + gl_Position = uProjection * vec4(mvPosition.xyz, 1.0); + sphereProjection(mvPosition.xyz, vRadius, mapping); + } + #endif + + vec4 vPoint4 = uInvProjection * gl_Position; + vPoint = vPoint4.xyz / vPoint4.w; + vPointViewPosition = -mvPosition.xyz / mvPosition.w; + + vModelPosition = (uModel * aTransform * position4).xyz; // for clipping in frag shader + + if (gl_Position.z < -gl_Position.w) { + mvPosition.z -= 2.0 * vRadius; // avoid clipping + gl_Position.z = (uProjection * vec4(mvPosition.xyz, 1.0)).z; + } + + #if defined(dClipPrimitive) && !defined(dClipVariant_instance) && dClipObjectCount != 0 + if (clipTest(vec4(vModelPosition.xyz, 0.0))) { + // move out of [ -w, +w ] to 'discard' in vert shader + gl_Position.z = 2.0 * gl_Position.w; + } + #else + #include clip_instance + #endif +} +`;var x9=` +precision highp float; +precision highp int; + +#define bumpEnabled + +#include common +#include common_frag_params +#include color_frag_params +#include light_frag_params +#include common_clip + +uniform mat4 uInvView; +uniform float uAlphaThickness; + +varying float vRadius; +varying vec3 vPoint; +varying vec3 vPointViewPosition; + +#ifdef dSolidInterior + const bool solidInterior = true; +#else + const bool solidInterior = false; +#endif + +bool SphereImpostor(out vec3 modelPos, out vec3 cameraPos, out vec3 cameraNormal, out bool interior, out float fragmentDepth){ + vec3 cameraSpherePos = -vPointViewPosition; + + vec3 rayOrigin = mix(vec3(0.0, 0.0, 0.0), vPoint, uIsOrtho); + vec3 rayDirection = mix(normalize(vPoint), vec3(0.0, 0.0, 1.0), uIsOrtho); + vec3 cameraSphereDir = mix(cameraSpherePos, rayOrigin - cameraSpherePos, uIsOrtho); + + float B = dot(rayDirection, cameraSphereDir); + float det = B * B + vRadius * vRadius - dot(cameraSphereDir, cameraSphereDir); + + if (det < 0.0) return false; + + float sqrtDet = sqrt(det); + float posT = mix(B + sqrtDet, B - sqrtDet, uIsOrtho); + float negT = mix(B - sqrtDet, B + sqrtDet, uIsOrtho); + + cameraPos = rayDirection * negT + rayOrigin; + modelPos = (uInvView * vec4(cameraPos, 1.0)).xyz; + fragmentDepth = calcDepth(cameraPos); + + bool objectClipped = false; + + #if !defined(dClipPrimitive) && defined(dClipVariant_pixel) && dClipObjectCount != 0 + if (clipTest(vec4(modelPos, 0.0))) { + objectClipped = true; + fragmentDepth = -1.0; + } + #endif + + if (fragmentDepth > 0.0) { + cameraNormal = normalize(cameraPos - cameraSpherePos); + interior = false; + return true; + } else if (uDoubleSided || solidInterior) { + cameraPos = rayDirection * posT + rayOrigin; + modelPos = (uInvView * vec4(cameraPos, 1.0)).xyz; + fragmentDepth = calcDepth(cameraPos); + cameraNormal = -normalize(cameraPos - cameraSpherePos); + interior = true; + if (fragmentDepth > 0.0) { + #ifdef dSolidInterior + if (!objectClipped) { + fragmentDepth = 0.0 + (0.0000001 / vRadius); + cameraNormal = -mix(normalize(vPoint), vec3(0.0, 0.0, 1.0), uIsOrtho); + } + #endif + return true; + } + } + + return false; +} + +void main(void){ + vec3 cameraNormal; + float fragmentDepth; + + #ifdef dApproximate + vec3 pointDir = -vPointViewPosition - vPoint; + if (dot(pointDir, pointDir) > vRadius * vRadius) discard; + vec3 vViewPosition = -vPointViewPosition; + fragmentDepth = gl_FragCoord.z; + #if !defined(dIgnoreLight) || defined(dXrayShaded) + pointDir.z -= cos(length(pointDir) / vRadius); + cameraNormal = -normalize(pointDir / vRadius); + #endif + interior = false; + #else + vec3 modelPos; + vec3 cameraPos; + bool hit = SphereImpostor(modelPos, cameraPos, cameraNormal, interior, fragmentDepth); + if (!hit) discard; + + if (fragmentDepth < 0.0) discard; + if (fragmentDepth > 1.0) discard; + + gl_FragDepthEXT = fragmentDepth; + + vec3 vModelPosition = modelPos; + vec3 vViewPosition = cameraPos; + #endif + + #if !defined(dClipPrimitive) && defined(dClipVariant_pixel) && dClipObjectCount != 0 + #include clip_pixel + #endif + #include assign_material_color + + #if defined(dRenderVariant_pick) + #include check_picking_alpha + #ifdef requiredDrawBuffers + gl_FragColor = vObject; + gl_FragData[1] = vInstance; + gl_FragData[2] = vGroup; + gl_FragData[3] = packDepthToRGBA(fragmentDepth); + #else + gl_FragColor = vColor; + #endif + #elif defined(dRenderVariant_depth) + gl_FragColor = material; + #elif defined(dRenderVariant_marking) + gl_FragColor = material; + #elif defined(dRenderVariant_color) + vec3 normal = -cameraNormal; + #include apply_light_color + + if (uRenderMask == MaskTransparent && uAlphaThickness > 0.0) { + gl_FragColor.a *= min(1.0, vRadius / uAlphaThickness); + } + + #include apply_interior_color + #include apply_marker_color + #include apply_fog + #include wboit_write + #include dpoit_write + #endif +} +`;var S9=` +precision highp float; +precision highp int; + +#include common +#include read_from_texture +#include common_vert_params +#include color_vert_params +#include size_vert_params +#include common_clip + +uniform mat4 uModelView; + +attribute mat4 aTransform; +attribute float aInstance; +attribute float aGroup; + +attribute vec3 aMapping; +attribute vec3 aStart; +attribute vec3 aEnd; +attribute float aScale; +attribute float aCap; + +varying mat4 vTransform; +varying vec3 vStart; +varying vec3 vEnd; +varying float vSize; +varying float vCap; + +uniform float uIsOrtho; +uniform vec3 uCameraDir; + +void main() { + #include assign_group + #include assign_color_varying + #include assign_marker_varying + #include assign_clipping_varying + #include assign_size + + mat4 modelTransform = uModel * aTransform; + + vTransform = aTransform; + vStart = (modelTransform * vec4(aStart, 1.0)).xyz; + vEnd = (modelTransform * vec4(aEnd, 1.0)).xyz; + vSize = size * aScale; + vCap = aCap; + + vModelPosition = (vStart + vEnd) * 0.5; + vec3 camDir = -mix(normalize(vModelPosition - uCameraPosition), uCameraDir, uIsOrtho); + vec3 dir = vEnd - vStart; + // ensure cylinder 'dir' is pointing towards the camera + if(dot(camDir, dir) < 0.0) { + dir = -dir; + } + + vec3 left = cross(camDir, dir); + vec3 up = cross(left, dir); + left = vSize * normalize(left); + up = vSize * normalize(up); + + // move vertex in object-space from center to corner + vModelPosition += aMapping.x * dir + aMapping.y * left + aMapping.z * up; + + vec4 mvPosition = uView * vec4(vModelPosition, 1.0); + vViewPosition = mvPosition.xyz; + gl_Position = uProjection * mvPosition; + + if (gl_Position.z < -gl_Position.w) { + mvPosition.z -= 2.0 * (length(vEnd - vStart) + vSize); // avoid clipping + gl_Position.z = (uProjection * mvPosition).z; + } + + #include clip_instance +} +`;var C9=` +precision highp float; +precision highp int; + +#define bumpEnabled + +uniform mat4 uView; + +varying mat4 vTransform; +varying vec3 vStart; +varying vec3 vEnd; +varying float vSize; +varying float vCap; + +uniform vec3 uCameraDir; +uniform vec3 uCameraPosition; +uniform mat4 uInvView; + +#include common +#include common_frag_params +#include color_frag_params +#include light_frag_params +#include common_clip + +#ifdef dSolidInterior + const bool solidInterior = true; +#else + const bool solidInterior = false; +#endif + +// adapted from https://www.shadertoy.com/view/4lcSRn +// The MIT License, Copyright 2016 Inigo Quilez +bool CylinderImpostor( + in vec3 rayOrigin, in vec3 rayDir, + in vec3 start, in vec3 end, in float radius, + out vec3 cameraNormal, out bool interior, + out vec3 modelPosition, out vec3 viewPosition, out float fragmentDepth +){ + vec3 ba = end - start; + vec3 oc = rayOrigin - start; + + float baba = dot(ba, ba); + float bard = dot(ba, rayDir); + float baoc = dot(ba, oc); + + float k2 = baba - bard * bard; + float k1 = baba * dot(oc, rayDir) - baoc * bard; + float k0 = baba * dot(oc, oc) - baoc * baoc - radius * radius * baba; + + float h = k1 * k1 - k2 * k0; + if (h < 0.0) return false; + + bool topCap = (vCap > 0.9 && vCap < 1.1) || vCap >= 2.9; + bool bottomCap = (vCap > 1.9 && vCap < 2.1) || vCap >= 2.9; + + #ifdef dSolidInterior + bool topInterior = !topCap; + bool bottomInterior = !bottomCap; + topCap = true; + bottomCap = true; + #else + bool topInterior = false; + bool bottomInterior = false; + #endif + + bool clipped = false; + bool objectClipped = false; + + // body outside + h = sqrt(h); + float t = (-k1 - h) / k2; + float y = baoc + t * bard; + if (y > 0.0 && y < baba) { + interior = false; + cameraNormal = (oc + t * rayDir - ba * y / baba) / radius; + modelPosition = rayOrigin + t * rayDir; + viewPosition = (uView * vec4(modelPosition, 1.0)).xyz; + fragmentDepth = calcDepth(viewPosition); + #if defined(dClipVariant_pixel) && dClipObjectCount != 0 + if (clipTest(vec4(modelPosition, 0.0))) { + objectClipped = true; + fragmentDepth = -1.0; + #ifdef dSolidInterior + topCap = !topInterior; + bottomCap = !bottomInterior; + #endif + } + #endif + if (fragmentDepth > 0.0) return true; + clipped = true; + } + + if (!clipped) { + if (topCap && y < 0.0) { + // top cap + t = -baoc / bard; + if (abs(k1 + k2 * t) < h) { + interior = topInterior; + cameraNormal = -ba / baba; + modelPosition = rayOrigin + t * rayDir; + viewPosition = (uView * vec4(modelPosition, 1.0)).xyz; + fragmentDepth = calcDepth(viewPosition); + #if defined(dClipVariant_pixel) && dClipObjectCount != 0 + if (clipTest(vec4(modelPosition, 0.0))) { + objectClipped = true; + fragmentDepth = -1.0; + #ifdef dSolidInterior + topCap = !topInterior; + bottomCap = !bottomInterior; + #endif + } + #endif + if (fragmentDepth > 0.0) { + #ifdef dSolidInterior + if (interior) cameraNormal = -rayDir; + #endif + return true; + } + } + } else if (bottomCap && y >= 0.0) { + // bottom cap + t = (baba - baoc) / bard; + if (abs(k1 + k2 * t) < h) { + interior = bottomInterior; + cameraNormal = ba / baba; + modelPosition = rayOrigin + t * rayDir; + viewPosition = (uView * vec4(modelPosition, 1.0)).xyz; + fragmentDepth = calcDepth(viewPosition); + #if defined(dClipVariant_pixel) && dClipObjectCount != 0 + if (clipTest(vec4(modelPosition, 0.0))) { + objectClipped = true; + fragmentDepth = -1.0; + #ifdef dSolidInterior + topCap = !topInterior; + bottomCap = !bottomInterior; + #endif + } + #endif + if (fragmentDepth > 0.0) { + #ifdef dSolidInterior + if (interior) cameraNormal = -rayDir; + #endif + return true; + } + } + } + } + + if (uDoubleSided || solidInterior) { + // body inside + h = -h; + t = (-k1 - h) / k2; + y = baoc + t * bard; + if (y > 0.0 && y < baba) { + interior = true; + cameraNormal = -(oc + t * rayDir - ba * y / baba) / radius; + modelPosition = rayOrigin + t * rayDir; + viewPosition = (uView * vec4(modelPosition, 1.0)).xyz; + fragmentDepth = calcDepth(viewPosition); + if (fragmentDepth > 0.0) { + #ifdef dSolidInterior + if (!objectClipped) { + fragmentDepth = 0.0 + (0.0000002 / vSize); + cameraNormal = -rayDir; + } + #endif + return true; + } + } + + if (topCap && y < 0.0) { + // top cap + t = -baoc / bard; + if (abs(k1 + k2 * t) < -h) { + interior = true; + cameraNormal = ba / baba; + modelPosition = rayOrigin + t * rayDir; + viewPosition = (uView * vec4(modelPosition, 1.0)).xyz; + fragmentDepth = calcDepth(viewPosition); + if (fragmentDepth > 0.0) { + #ifdef dSolidInterior + if (!objectClipped) { + fragmentDepth = 0.0 + (0.0000002 / vSize); + cameraNormal = -rayDir; + } + #endif + return true; + } + } + } else if (bottomCap && y >= 0.0) { + // bottom cap + t = (baba - baoc) / bard; + if (abs(k1 + k2 * t) < -h) { + interior = true; + cameraNormal = -ba / baba; + modelPosition = rayOrigin + t * rayDir; + viewPosition = (uView * vec4(modelPosition, 1.0)).xyz; + fragmentDepth = calcDepth(viewPosition); + if (fragmentDepth > 0.0) { + #ifdef dSolidInterior + if (!objectClipped) { + fragmentDepth = 0.0 + (0.0000002 / vSize); + cameraNormal = -rayDir; + } + #endif + return true; + } + } + } + } + + return false; +} + +void main() { + vec3 rayOrigin = vModelPosition; + vec3 rayDir = mix(normalize(vModelPosition - uCameraPosition), uCameraDir, uIsOrtho); + + vec3 cameraNormal; + vec3 modelPosition; + vec3 viewPosition; + float fragmentDepth; + bool hit = CylinderImpostor(rayOrigin, rayDir, vStart, vEnd, vSize, cameraNormal, interior, modelPosition, viewPosition, fragmentDepth); + if (!hit) discard; + + if (fragmentDepth < 0.0) discard; + if (fragmentDepth > 1.0) discard; + + gl_FragDepthEXT = fragmentDepth; + + vec3 vViewPosition = viewPosition; + vec3 vModelPosition = modelPosition; + + #include clip_pixel + #include assign_material_color + + #if defined(dRenderVariant_pick) + #include check_picking_alpha + #ifdef requiredDrawBuffers + gl_FragColor = vObject; + gl_FragData[1] = vInstance; + gl_FragData[2] = vGroup; + gl_FragData[3] = packDepthToRGBA(fragmentDepth); + #else + gl_FragColor = vColor; + #endif + #elif defined(dRenderVariant_depth) + gl_FragColor = material; + #elif defined(dRenderVariant_marking) + gl_FragColor = material; + #elif defined(dRenderVariant_color) + mat3 normalMatrix = transpose3(inverse3(mat3(uView))); + vec3 normal = normalize(normalMatrix * -normalize(cameraNormal)); + #include apply_light_color + + #include apply_interior_color + #include apply_marker_color + #include apply_fog + #include wboit_write + #include dpoit_write + #endif +} +`;var _9=` +precision highp float; +precision highp int; + +#include common +#include read_from_texture +#include common_vert_params +#include color_vert_params +#include size_vert_params +#include common_clip + +uniform mat4 uModelView; + +attribute vec3 aPosition; +attribute vec2 aMapping; +attribute float aDepth; +attribute vec2 aTexCoord; +attribute mat4 aTransform; +attribute float aInstance; +attribute float aGroup; + +uniform float uOffsetX; +uniform float uOffsetY; +uniform float uOffsetZ; + +uniform float uIsOrtho; +uniform float uPixelRatio; +uniform vec4 uViewport; + +varying vec2 vTexCoord; + +#include matrix_scale + +void main(void){ + #include assign_group + #include assign_color_varying + #include assign_marker_varying + #include assign_clipping_varying + #include assign_size + + vTexCoord = aTexCoord; + + float scale = matrixScale(uModelView); + + float offsetX = uOffsetX * scale; + float offsetY = uOffsetY * scale; + float offsetZ = (uOffsetZ + aDepth * 0.95) * scale; + + vec4 position4 = vec4(aPosition, 1.0); + vec4 mvPosition = uModelView * aTransform * position4; + + vModelPosition = (uModel * aTransform * position4).xyz; // for clipping in frag shader + + // TODO + // #ifdef FIXED_SIZE + // if (ortho) { + // scale /= pixelRatio * ((uViewport.w / 2.0) / -uCameraPosition.z) * 0.1; + // } else { + // scale /= pixelRatio * ((uViewport.w / 2.0) / -mvPosition.z) * 0.1; + // } + // #endif + + vec4 mvCorner = vec4(mvPosition.xyz, 1.0); + + if (vTexCoord.x == 10.0) { // indicates background plane + // move a bit to the back, taking distance to camera into account to avoid z-fighting + offsetZ -= 0.001 * distance(uCameraPosition, (uProjection * mvCorner).xyz); + } + + mvCorner.xy += aMapping * size * scale; + mvCorner.x += offsetX; + mvCorner.y += offsetY; + + if (uIsOrtho == 1.0) { + mvCorner.z += offsetZ; + } else { + mvCorner.xyz += normalize(-mvCorner.xyz) * offsetZ; + } + + gl_Position = uProjection * mvCorner; + + vViewPosition = -mvCorner.xyz; + + #include clip_instance +} +`;var w9=` +precision highp float; +precision highp int; + +#include common +#include common_frag_params +#include color_frag_params +#include common_clip + +uniform sampler2D tFont; + +uniform vec3 uBorderColor; +uniform float uBorderWidth; +uniform vec3 uBackgroundColor; +uniform float uBackgroundOpacity; + +varying vec2 vTexCoord; + +const float smoothness = 32.0; +const float gamma = 2.2; + +void main2(){ + gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); +} + +void main(){ + #include clip_pixel + + float fragmentDepth = gl_FragCoord.z; + #include assign_material_color + + if (vTexCoord.x > 1.0) { + #if defined(dRenderVariant_color) + material = vec4(uBackgroundColor, uBackgroundOpacity * material.a); + #endif + } else { + // retrieve signed distance + float sdf = texture2D(tFont, vTexCoord).a + uBorderWidth; + + // perform adaptive anti-aliasing of the edges + float w = clamp(smoothness * (abs(dFdx(vTexCoord.x)) + abs(dFdy(vTexCoord.y))), 0.0, 0.5); + float a = smoothstep(0.5 - w, 0.5 + w, sdf); + + // gamma correction for linear attenuation + a = pow(a, 1.0 / gamma); + + if (a < 0.5) discard; + + #if defined(dRenderVariant_color) + material.a *= a; + + // add border + float t = 0.5 + uBorderWidth; + if (uBorderWidth > 0.0 && sdf < t) { + material.xyz = mix(uBorderColor, material.xyz, smoothstep(t - w, t, sdf)); + } + #endif + } + + #if defined(dRenderVariant_pick) + #include check_picking_alpha + #ifdef requiredDrawBuffers + gl_FragColor = vObject; + gl_FragData[1] = vInstance; + gl_FragData[2] = vGroup; + gl_FragData[3] = packDepthToRGBA(fragmentDepth); + #else + gl_FragColor = vColor; + #endif + #elif defined(dRenderVariant_depth) + gl_FragColor = material; + #elif defined(dRenderVariant_marking) + gl_FragColor = material; + #elif defined(dRenderVariant_color) + gl_FragColor = material; + + #include apply_marker_color + #include apply_fog + #include wboit_write + #include dpoit_write + #endif +} +`;var T9=` +precision highp float; +precision highp int; + +#include common +#include read_from_texture +#include common_vert_params +#include color_vert_params +#include size_vert_params +#include common_clip + +uniform float uPixelRatio; +uniform vec4 uViewport; + +attribute mat4 aTransform; +attribute float aInstance; +attribute float aGroup; + +attribute vec2 aMapping; +attribute vec3 aStart; +attribute vec3 aEnd; + +void trimSegment(const in vec4 start, inout vec4 end) { + // trim end segment so it terminates between the camera plane and the near plane + // conservative estimate of the near plane + float a = uProjection[2][2]; // 3rd entry in 3rd column + float b = uProjection[3][2]; // 3rd entry in 4th column + float nearEstimate = -0.5 * b / a; + float alpha = (nearEstimate - start.z) / (end.z - start.z); + end.xyz = mix(start.xyz, end.xyz, alpha); +} + +void main(){ + float aspect = uViewport.z / uViewport.w; + + #include assign_group + #include assign_color_varying + #include assign_marker_varying + #include assign_clipping_varying + #include assign_size + + mat4 modelView = uView * uModel * aTransform; + + // camera space + vec4 start = modelView * vec4(aStart, 1.0); + vec4 end = modelView * vec4(aEnd, 1.0); + + // assign position + vec4 position4 = vec4((aMapping.y < 0.5) ? aStart : aEnd, 1.0); + vec4 mvPosition = modelView * position4; + vViewPosition = mvPosition.xyz; + + vModelPosition = (uModel * aTransform * position4).xyz; // for clipping in frag shader + + // special case for perspective projection, and segments that terminate either in, or behind, the camera plane + // clearly the gpu firmware has a way of addressing this issue when projecting into ndc space + // but we need to perform ndc-space calculations in the shader, so we must address this issue directly + // perhaps there is a more elegant solution -- WestLangley + bool perspective = (uProjection[2][3] == -1.0); // 4th entry in the 3rd column + if (perspective) { + if (start.z < 0.0 && end.z >= 0.0) { + trimSegment(start, end); + } else if (end.z < 0.0 && start.z >= 0.0) { + trimSegment(end, start); + } + } + + // clip space + vec4 clipStart = uProjection * start; + vec4 clipEnd = uProjection * end; + + // ndc space + vec2 ndcStart = clipStart.xy / clipStart.w; + vec2 ndcEnd = clipEnd.xy / clipEnd.w; + + // direction + vec2 dir = ndcEnd - ndcStart; + + // account for clip-space aspect ratio + dir.x *= aspect; + dir = normalize(dir); + + // perpendicular to dir + vec2 offset = vec2(dir.y, - dir.x); + + // undo aspect ratio adjustment + dir.x /= aspect; + offset.x /= aspect; + + // sign flip + if (aMapping.x < 0.0) offset *= -1.0; + + // calculate linewidth + float linewidth; + #ifdef dLineSizeAttenuation + linewidth = size * uPixelRatio * ((uViewport.w / 2.0) / -start.z) * 5.0; + #else + linewidth = size * uPixelRatio; + #endif + linewidth = max(1.0, linewidth); + + // adjust for linewidth + offset *= linewidth; + + // adjust for clip-space to screen-space conversion + offset /= uViewport.w; + + // select end + vec4 clip = (aMapping.y < 0.5) ? clipStart : clipEnd; + + // back to clip space + offset *= clip.w; + clip.xy += offset; + gl_Position = clip; + + #include clip_instance +} +`;var A9=` +precision highp float; +precision highp int; + +#include common +#include common_frag_params +#include color_frag_params +#include common_clip + +void main(){ + #include clip_pixel + + float fragmentDepth = gl_FragCoord.z; + #include assign_material_color + + #if defined(dRenderVariant_pick) + #include check_picking_alpha + #ifdef requiredDrawBuffers + gl_FragColor = vObject; + gl_FragData[1] = vInstance; + gl_FragData[2] = vGroup; + gl_FragData[3] = packDepthToRGBA(fragmentDepth); + #else + gl_FragColor = vColor; + #endif + #elif defined(dRenderVariant_depth) + gl_FragColor = material; + #elif defined(dRenderVariant_marking) + gl_FragColor = material; + #elif defined(dRenderVariant_color) + gl_FragColor = material; + + #include apply_marker_color + #include apply_fog + #include wboit_write + #include dpoit_write + #endif +} +`;var D9=` +precision highp float; +precision highp int; +precision highp sampler2D; + +#include common +#include read_from_texture +#include common_vert_params +#include color_vert_params +#include common_clip +#include texture3d_from_2d_linear + +#ifdef dGeometryType_textureMesh + uniform vec2 uGeoTexDim; + uniform sampler2D tPosition; + uniform sampler2D tGroup; + uniform sampler2D tNormal; +#else + attribute vec3 aPosition; + attribute float aGroup; + attribute vec3 aNormal; +#endif +attribute mat4 aTransform; +attribute float aInstance; + +varying vec3 vNormal; + +void main(){ + #include assign_group + #include assign_marker_varying + #include assign_clipping_varying + #include assign_position + #include assign_color_varying + #include clip_instance + + #ifdef dGeometryType_textureMesh + vec3 normal = readFromTexture(tNormal, VertexID, uGeoTexDim).xyz; + #else + vec3 normal = aNormal; + #endif + mat3 normalMatrix = transpose3(inverse3(mat3(modelView))); + vec3 transformedNormal = normalize(normalMatrix * normalize(normal)); + #if defined(dFlipSided) + if (!uDoubleSided) { // TODO checking uDoubleSided should not be required, ASR + transformedNormal = -transformedNormal; + } + #endif + vNormal = transformedNormal; +} +`;var P9=` +precision highp float; +precision highp int; + +#define bumpEnabled + +#include common +#include common_frag_params +#include color_frag_params +#include light_frag_params +#include normal_frag_params +#include common_clip + +void main() { + #include clip_pixel + + // Workaround for buggy gl_FrontFacing (e.g. on some integrated Intel GPUs) + vec3 fdx = dFdx(vViewPosition); + vec3 fdy = dFdy(vViewPosition); + vec3 faceNormal = normalize(cross(fdx,fdy)); + bool frontFacing = dot(vNormal, faceNormal) > 0.0; + + #if defined(dFlipSided) + interior = frontFacing; + #else + interior = !frontFacing; + #endif + + float fragmentDepth = gl_FragCoord.z; + #include assign_material_color + + #if defined(dRenderVariant_pick) + #include check_picking_alpha + #ifdef requiredDrawBuffers + gl_FragColor = vObject; + gl_FragData[1] = vInstance; + gl_FragData[2] = vGroup; + gl_FragData[3] = packDepthToRGBA(fragmentDepth); + #else + gl_FragColor = vColor; + #endif + #elif defined(dRenderVariant_depth) + gl_FragColor = material; + #elif defined(dRenderVariant_marking) + gl_FragColor = material; + #elif defined(dRenderVariant_color) + #if defined(dFlatShaded) + vec3 normal = -faceNormal; + #else + vec3 normal = -normalize(vNormal); + if (uDoubleSided) normal *= float(frontFacing) * 2.0 - 1.0; + #endif + #include apply_light_color + + #include apply_interior_color + #include apply_marker_color + #include apply_fog + #include wboit_write + #include dpoit_write + #endif +} +`;var E9=` +precision highp float; + +attribute vec3 aPosition; +attribute mat4 aTransform; +attribute float aInstance; + +uniform mat4 uModelView; +uniform mat4 uProjection; +uniform vec4 uInvariantBoundingSphere; + +varying vec3 vOrigPos; +varying float vInstance; +varying vec4 vBoundingSphere; +varying mat4 vTransform; + +uniform vec3 uBboxSize; +uniform vec3 uBboxMin; +uniform vec3 uBboxMax; +uniform vec3 uGridDim; +uniform mat4 uTransform; + +uniform mat4 uUnitToCartn; + +void main() { + vec4 unitCoord = vec4(aPosition + vec3(0.5), 1.0); + vec4 mvPosition = uModelView * aTransform * uUnitToCartn * unitCoord; + + vOrigPos = (aTransform * uUnitToCartn * unitCoord).xyz; + vInstance = aInstance; + vBoundingSphere = vec4( + (aTransform * vec4(uInvariantBoundingSphere.xyz, 1.0)).xyz, + uInvariantBoundingSphere.w + ); + vTransform = aTransform; + + gl_Position = uProjection * mvPosition; + + // move z position to near clip plane (but not too close to get precision issues) + gl_Position.z = gl_Position.w - 0.01; +} +`;var I9=` +precision highp float; +precision highp int; + +#include common +#include light_frag_params + +#if dClipObjectCount != 0 + uniform int uClipObjectType[dClipObjectCount]; + uniform bool uClipObjectInvert[dClipObjectCount]; + uniform vec3 uClipObjectPosition[dClipObjectCount]; + uniform vec4 uClipObjectRotation[dClipObjectCount]; + uniform vec3 uClipObjectScale[dClipObjectCount]; +#endif +#include common_clip + +#include read_from_texture +#include texture3d_from_1d_trilinear +#include texture3d_from_2d_nearest +#include texture3d_from_2d_linear + +uniform mat4 uProjection, uTransform, uModelView, uModel, uView; +uniform vec3 uCameraDir; + +uniform sampler2D tDepth; +uniform vec2 uDrawingBufferSize; + +varying vec3 vOrigPos; +varying float vInstance; +varying vec4 vBoundingSphere; +varying mat4 vTransform; + +uniform mat4 uInvView; +uniform vec3 uGridDim; +uniform vec3 uBboxSize; +uniform sampler2D tTransferTex; +uniform float uTransferScale; +uniform float uStepScale; +uniform float uJumpLength; + +uniform int uObjectId; +uniform int uVertexCount; +uniform int uInstanceCount; +uniform int uGroupCount; + +#if defined(dColorMarker) + uniform vec3 uHighlightColor; + uniform vec3 uSelectColor; + uniform vec3 uDimColor; + uniform float uHighlightStrength; + uniform float uSelectStrength; + uniform float uDimStrength; + uniform int uMarkerPriority; + uniform float uMarkerAverage; + + uniform float uMarker; + uniform vec2 uMarkerTexDim; + uniform sampler2D tMarker; +#endif + +uniform float uMetalness; +uniform float uRoughness; + +uniform bool uFog; +uniform float uFogNear; +uniform float uFogFar; +uniform vec3 uFogColor; + +uniform float uAlpha; +uniform bool uTransparentBackground; +uniform float uXrayEdgeFalloff; +uniform float uExposure; + +uniform int uRenderMask; + +uniform float uNear; +uniform float uFar; +uniform float uIsOrtho; + +uniform vec3 uCellDim; +uniform vec3 uCameraPosition; +uniform mat4 uCartnToUnit; + +#if __VERSION__ != 100 + // for webgl1 this is given as a 'define' + uniform int uMaxSteps; +#endif + +#if defined(dGridTexType_2d) + precision highp sampler2D; + uniform sampler2D tGridTex; + uniform vec3 uGridTexDim; +#elif defined(dGridTexType_3d) + precision highp sampler3D; + uniform sampler3D tGridTex; +#endif + +#if defined(dColorType_uniform) + uniform vec3 uColor; +#elif defined(dColorType_texture) + uniform vec2 uColorTexDim; + uniform sampler2D tColor; +#endif + +#ifdef dOverpaint + #if defined(dOverpaintType_groupInstance) || defined(dOverpaintType_vertexInstance) + uniform vec2 uOverpaintTexDim; + uniform sampler2D tOverpaint; + #endif +#endif + +#ifdef dUsePalette + uniform sampler2D tPalette; +#endif + +#if defined(dGridTexType_2d) + vec4 textureVal(vec3 pos) { + return texture3dFrom2dLinear(tGridTex, pos + (vec3(0.5, 0.5, 0.0) / uGridDim), uGridDim, uGridTexDim.xy); + } + vec4 textureGroup(vec3 pos) { + return texture3dFrom2dNearest(tGridTex, pos + (vec3(0.5, 0.5, 0.0) / uGridDim), uGridDim, uGridTexDim.xy); + } +#elif defined(dGridTexType_3d) + vec4 textureVal(vec3 pos) { + return texture(tGridTex, pos + (vec3(0.5) / uGridDim)); + } + vec4 textureGroup(vec3 pos) { + return texelFetch(tGridTex, ivec3(pos * uGridDim), 0); + } +#endif + +float calcDepth(const in vec3 pos) { + vec2 clipZW = pos.z * uProjection[2].zw + uProjection[3].zw; + return 0.5 + 0.5 * clipZW.x / clipZW.y; +} + +float transferFunction(float value) { + return texture2D(tTransferTex, vec2(value, 0.0)).a; +} + +float getDepth(const in vec2 coords) { + #ifdef depthTextureSupport + return texture2D(tDepth, coords).r; + #else + return unpackRGBAToDepth(texture2D(tDepth, coords)); + #endif +} + +const float gradOffset = 0.5; + +vec3 v3m4(vec3 p, mat4 m) { + return (m * vec4(p, 1.0)).xyz; +} + +float preFogAlphaBlended = 0.0; + +vec4 raymarch(vec3 startLoc, vec3 step, vec3 rayDir) { + mat3 normalMatrix = transpose3(inverse3(mat3(uModelView * vTransform))); + mat4 cartnToUnit = uCartnToUnit * inverse4(vTransform); + #if defined(dClipVariant_pixel) && dClipObjectCount != 0 + mat4 modelTransform = uModel * vTransform * uTransform; + #endif + mat4 modelViewTransform = uModelView * vTransform * uTransform; + + vec3 scaleVol = vec3(1.0) / uGridDim; + vec3 pos = startLoc; + vec4 cell; + float prevValue = -1.0; + float value = 0.0; + vec4 src = vec4(0.0); + vec4 dst = vec4(0.0); + float fragmentDepth; + + vec3 posMin = vec3(0.0); + vec3 posMax = vec3(1.0) - vec3(1.0) / uGridDim; + + vec3 unitPos; + + vec3 nextPos; + float nextValue; + + vec4 material; + vec4 overpaint; + float metalness = uMetalness; + float roughness = uRoughness; + + vec3 gradient = vec3(1.0); + vec3 dx = vec3(gradOffset * scaleVol.x, 0.0, 0.0); + vec3 dy = vec3(0.0, gradOffset * scaleVol.y, 0.0); + vec3 dz = vec3(0.0, 0.0, gradOffset * scaleVol.z); + + float maxDist = min(vBoundingSphere.w * 2.0, uFar - uNear); + float maxDistSq = maxDist * maxDist; + + for (int i = 0; i < uMaxSteps; ++i) { + // break when beyond bounding-sphere or far-plane + vec3 distVec = startLoc - pos; + if (dot(distVec, distVec) > maxDistSq) break; + + unitPos = v3m4(pos, cartnToUnit); + + // continue when outside of grid + if (unitPos.x > posMax.x || unitPos.y > posMax.y || unitPos.z > posMax.z || + unitPos.x < posMin.x || unitPos.y < posMin.y || unitPos.z < posMin.z + ) { + prevValue = value; + pos += step; + continue; + } + + cell = textureVal(unitPos); + value = cell.a; // current voxel value + + if (uJumpLength > 0.0 && value < 0.01) { + nextPos = pos + rayDir * uJumpLength; + nextValue = textureVal(v3m4(nextPos, cartnToUnit)).a; + if (nextValue < 0.01) { + prevValue = nextValue; + pos = nextPos; + continue; + } + } + + vec4 mvPosition = modelViewTransform * vec4(unitPos * uGridDim, 1.0); + if (calcDepth(mvPosition.xyz) > getDepth(gl_FragCoord.xy / uDrawingBufferSize)) + break; + + #if defined(dClipVariant_pixel) && dClipObjectCount != 0 + vec3 vModelPosition = v3m4(unitPos * uGridDim, modelTransform); + if (clipTest(vec4(vModelPosition, 0.0))) { + prevValue = value; + pos += step; + continue; + } + #endif + + vec3 vViewPosition = mvPosition.xyz; + material.a = transferFunction(value); + + #ifdef dPackedGroup + float group = unpackRGBToInt(textureGroup(floor(unitPos * uGridDim + 0.5) / uGridDim).rgb); + #else + vec3 g = floor(unitPos * uGridDim + 0.5); + // note that we swap x and z because the texture is flipped around y + #if defined(dAxisOrder_012) + float group = g.z + g.y * uGridDim.z + g.x * uGridDim.z * uGridDim.y; // 210 + #elif defined(dAxisOrder_021) + float group = g.y + g.z * uGridDim.y + g.x * uGridDim.y * uGridDim.z; // 120 + #elif defined(dAxisOrder_102) + float group = g.z + g.x * uGridDim.z + g.y * uGridDim.z * uGridDim.x; // 201 + #elif defined(dAxisOrder_120) + float group = g.x + g.z * uGridDim.x + g.y * uGridDim.x * uGridDim.z; // 021 + #elif defined(dAxisOrder_201) + float group = g.y + g.x * uGridDim.y + g.z * uGridDim.y * uGridDim.x; // 102 + #elif defined(dAxisOrder_210) + float group = g.x + g.y * uGridDim.x + g.z * uGridDim.x * uGridDim.y; // 012 + #endif + #endif + + #if defined(dColorType_direct) && defined(dUsePalette) + material.rgb = texture2D(tPalette, vec2(value, 0.0)).rgb; + #elif defined(dColorType_uniform) + material.rgb = uColor; + #elif defined(dColorType_instance) + material.rgb = readFromTexture(tColor, vInstance, uColorTexDim).rgb; + #elif defined(dColorType_group) + material.rgb = readFromTexture(tColor, group, uColorTexDim).rgb; + #elif defined(dColorType_groupInstance) + material.rgb = readFromTexture(tColor, vInstance * float(uGroupCount) + group, uColorTexDim).rgb; + #elif defined(dColorType_vertex) + material.rgb = texture3dFrom1dTrilinear(tColor, unitPos, uGridDim, uColorTexDim, 0.0).rgb; + #elif defined(dColorType_vertexInstance) + material.rgb = texture3dFrom1dTrilinear(tColor, unitPos, uGridDim, uColorTexDim, vInstance * float(uVertexCount)).rgb; + #endif + + #ifdef dOverpaint + #if defined(dOverpaintType_groupInstance) + overpaint = readFromTexture(tOverpaint, vInstance * float(uGroupCount) + group, uOverpaintTexDim); + #elif defined(dOverpaintType_vertexInstance) + overpaint = texture3dFrom1dTrilinear(tOverpaint, unitPos, uGridDim, uOverpaintTexDim, vInstance * float(uVertexCount)); + #endif + + material.rgb = mix(material.rgb, overpaint.rgb, overpaint.a); + #endif + + #ifdef dIgnoreLight + gl_FragColor.rgb = material.rgb; + #else + if (material.a >= 0.01) { + #ifdef dPackedGroup + // compute gradient by central differences + gradient.x = textureVal(unitPos - dx).a - textureVal(unitPos + dx).a; + gradient.y = textureVal(unitPos - dy).a - textureVal(unitPos + dy).a; + gradient.z = textureVal(unitPos - dz).a - textureVal(unitPos + dz).a; + #else + gradient = cell.xyz * 2.0 - 1.0; + #endif + vec3 normal = -normalize(normalMatrix * normalize(gradient)); + #include apply_light_color + } else { + gl_FragColor.rgb = material.rgb; + } + #endif + + gl_FragColor.a = material.a * uAlpha * uTransferScale; + + #if defined(dColorMarker) + float marker = uMarker; + if (uMarker == -1.0) { + marker = readFromTexture(tMarker, vInstance * float(uGroupCount) + group, uMarkerTexDim).a; + marker = floor(marker * 255.0 + 0.5); // rounding required to work on some cards on win + } + #endif + #include apply_marker_color + + preFogAlphaBlended = (1.0 - preFogAlphaBlended) * gl_FragColor.a + preFogAlphaBlended; + fragmentDepth = calcDepth(mvPosition.xyz); + #include apply_fog + + src = gl_FragColor; + + if (!uTransparentBackground) { + // done in 'apply_fog' otherwise + src.rgb *= src.a; + } + dst = (1.0 - dst.a) * src + dst; // standard blending + + // break if the color is opaque enough + if (dst.a > 0.95) + break; + + pos += step; + } + + return dst; +} + +// TODO: support float texture for higher precision values??? +// TODO: support clipping exclusion texture support + +void main() { + if (gl_FrontFacing) + discard; + + vec3 rayDir = mix(normalize(vOrigPos - uCameraPosition), uCameraDir, uIsOrtho); + vec3 step = rayDir * uStepScale; + + float boundingSphereNear = distance(vBoundingSphere.xyz, uCameraPosition) - vBoundingSphere.w; + float d = max(uNear, boundingSphereNear) - mix(0.0, distance(vOrigPos, uCameraPosition), uIsOrtho); + vec3 start = mix(uCameraPosition, vOrigPos, uIsOrtho) + (d * rayDir); + gl_FragColor = raymarch(start, step, rayDir); + + float fragmentDepth = calcDepth((uModelView * vec4(start, 1.0)).xyz); + float preFogAlpha = clamp(preFogAlphaBlended, 0.0, 1.0); + #include wboit_write +} +`;var M9=` +precision highp float; +precision highp int; + +#include common +#include common_vert_params + +attribute vec3 aPosition; +attribute vec2 aUv; +attribute mat4 aTransform; +attribute float aInstance; + +varying vec2 vUv; +varying float vInstance; + +void main() { + #include assign_position + + vUv = aUv; + vInstance = aInstance; +} +`;var R9=` +precision highp float; +precision highp int; + +#include common +#include read_from_texture +#include common_frag_params +#include common_clip + +uniform vec2 uImageTexDim; +uniform sampler2D tImageTex; +uniform sampler2D tGroupTex; + +uniform vec2 uMarkerTexDim; +uniform sampler2D tMarker; + +varying vec2 vUv; +varying float vInstance; + +#if defined(dInterpolation_catmulrom) || defined(dInterpolation_mitchell) || defined(dInterpolation_bspline) + #define dInterpolation_cubic +#endif + +#if defined(dInterpolation_cubic) + #if defined(dInterpolation_catmulrom) || defined(dInterpolation_mitchell) + #if defined(dInterpolation_catmulrom) + const float B = 0.0; + const float C = 0.5; + #elif defined(dInterpolation_mitchell) + const float B = 0.333; + const float C = 0.333; + #endif + + float cubicFilter(float x){ + float f = x; + if (f < 0.0) { + f = -f; + } + if (f < 1.0) { + return ((12.0 - 9.0 * B - 6.0 * C) * (f * f * f) + + (-18.0 + 12.0 * B + 6.0 * C) * (f * f) + + (6.0 - 2.0 * B)) / 6.0; + }else if (f >= 1.0 && f < 2.0){ + return ((-B - 6.0 * C) * ( f * f * f) + + (6.0 * B + 30.0 * C) * (f * f) + + (-(12.0 * B) - 48.0 * C) * f + + 8.0 * B + 24.0 * C) / 6.0; + }else{ + return 0.0; + } + } + #elif defined(dInterpolation_bspline) + float cubicFilter(float x) { + float f = x; + if (f < 0.0) { + f = -f; + } + if (f >= 0.0 && f <= 1.0){ + return (2.0 / 3.0) + (0.5) * (f * f * f) - (f * f); + } else if (f > 1.0 && f <= 2.0) { + return 1.0 / 6.0 * pow((2.0 - f), 3.0); + } + return 1.0; + } + #endif + + vec4 biCubic(sampler2D tex, vec2 texCoord) { + vec2 texelSize = 1.0 / uImageTexDim; + texCoord -= texelSize / 2.0; + vec4 nSum = vec4(0.0); + float nDenom = 0.0; + vec2 cell = fract(texCoord * uImageTexDim); + for (float m = -1.0; m <= 2.0; ++m) { + for (float n = -1.0; n <= 2.0; ++n) { + vec4 vecData = texture2D(tex, texCoord + texelSize * vec2(m, n)); + float c = cubicFilter(m - cell.x) * cubicFilter(-n + cell.y); + nSum += vecData * c; + nDenom += c; + } + } + return nSum / nDenom; + } +#endif + +void main() { + #include clip_pixel + + #if defined(dInterpolation_cubic) + vec4 imageData = biCubic(tImageTex, vUv); + #else + vec4 imageData = texture2D(tImageTex, vUv); + #endif + imageData.a = clamp(imageData.a, 0.0, 1.0); + if (imageData.a > 0.9) imageData.a = 1.0; + + float fragmentDepth = gl_FragCoord.z; + + #if defined(dRenderVariant_pick) + if (imageData.a < 0.3) + discard; + #ifdef requiredDrawBuffers + gl_FragColor = vec4(packIntToRGB(float(uObjectId)), 1.0); + gl_FragData[1] = vec4(packIntToRGB(vInstance), 1.0); + gl_FragData[2] = vec4(texture2D(tGroupTex, vUv).rgb, 1.0); + gl_FragData[3] = packDepthToRGBA(gl_FragCoord.z); + #else + gl_FragColor = vColor; + if (uPickType == 1) { + gl_FragColor = vec4(packIntToRGB(float(uObjectId)), 1.0); + } else if (uPickType == 2) { + gl_FragColor = vec4(packIntToRGB(vInstance), 1.0); + } else { + gl_FragColor = vec4(texture2D(tGroupTex, vUv).rgb, 1.0); + } + #endif + #elif defined(dRenderVariant_depth) + if (imageData.a < 0.05) + discard; + gl_FragColor = packDepthToRGBA(gl_FragCoord.z); + #elif defined(dRenderVariant_marking) + float marker = uMarker; + if (uMarker == -1.0) { + float group = unpackRGBToInt(texture2D(tGroupTex, vUv).rgb); + marker = readFromTexture(tMarker, vInstance * float(uGroupCount) + group, uMarkerTexDim).a; + marker = floor(marker * 255.0 + 0.5); // rounding required to work on some cards on win + } + if (uMarkingType == 1) { + if (marker > 0.0 || imageData.a < 0.05) + discard; + gl_FragColor = packDepthToRGBA(gl_FragCoord.z); + } else { + if (marker == 0.0 || imageData.a < 0.05) + discard; + float depthTest = 1.0; + if (uMarkingDepthTest) { + depthTest = (fragmentDepth >= getDepthPacked(gl_FragCoord.xy / uDrawingBufferSize)) ? 1.0 : 0.0; + } + bool isHighlight = intMod(marker, 2.0) > 0.1; + gl_FragColor = vec4(0.0, depthTest, isHighlight ? 1.0 : 0.0, 1.0); + } + #elif defined(dRenderVariant_color) + if (imageData.a < 0.05) + discard; + gl_FragColor = imageData; + gl_FragColor.a *= uAlpha; + + float marker = uMarker; + if (uMarker == -1.0) { + float group = unpackRGBToInt(texture2D(tGroupTex, vUv).rgb); + marker = readFromTexture(tMarker, vInstance * float(uGroupCount) + group, uMarkerTexDim).a; + marker = floor(marker * 255.0 + 0.5); // rounding required to work on some cards on win + } + + #include apply_marker_color + #include apply_fog + #include wboit_write + #include dpoit_write + #endif +} +`;var L9=ua(),oSe={apply_fog:U7,apply_interior_color:V7,apply_light_color:G7,apply_marker_color:z7,assign_clipping_varying:H7,assign_color_varying:j7,assign_group:q7,assign_marker_varying:W7,assign_material_color:Y7,assign_position:X7,assign_size:K7,check_picking_alpha:Z7,clip_instance:Q7,clip_pixel:$7,color_frag_params:J7,color_vert_params:e9,common_clip:t9,common_frag_params:r9,common_vert_params:n9,common:a9,float_to_rgba:i9,light_frag_params:o9,matrix_scale:s9,normal_frag_params:u9,read_from_texture:c9,rgba_to_float:l9,size_vert_params:f9,texture3d_from_1d_trilinear:d9,texture3d_from_2d_linear:m9,texture3d_from_2d_nearest:p9,wboit_write:h9,dpoit_write:v9},sSe=/^(?!\/\/)\s*#include\s+(\S+)/gm,uSe=/#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,cSe=/[ \t]*\/\/.*\n/g,lSe=/[ \t]*\/\*[\s\S]*?\*\//g,fSe=/\n{2,}/g;function B9(e){return e.replace(sSe,function(t,r){var n=oSe[r];if(!n)throw new Error("empty chunk, '".concat(r,"'"));return n}).trim().replace(cSe,` +`).replace(lSe,` +`).replace(fSe,` +`)}function dSe(e){return e.replace(uSe,mSe)}function mSe(e,t,r,n){for(var a="",i=parseInt(t);i 0?v():m=null}},stats:function(){return{gpu:l.stats(),cpu:f.stats()}},formatedStats:function(){for(var g={},b=l.stats(),x=f.stats(),S=0,_=Object.keys(b);S<_.length;S++){var C=_[S],D="".concat((b[C]/1e3/1e3).toFixed(2)),T="".concat(x[C].toFixed(2));g[C]="".concat(D," ms | CPU: ").concat(T," ms")}return g},clear:p,destroy:function(){p()}}}function tCe(e){var t="".concat((e.gpuElapsed/1e3/1e3).toFixed(2)),r="".concat((e.gpuAvg/1e3/1e3).toFixed(2)),n="".concat(e.cpuElapsed.toFixed(2)),a="".concat(e.cpuAvg.toFixed(2));return"".concat(e.label," ").concat(t," ms (avg. ").concat(r," ms) | CPU: ").concat(n," ms (avg. ").concat(a," ms)")}function nR(e){e.map(function(t){var r=tCe(t);t.children.length||t.calls?(console.groupCollapsed(r),t.calls&&console.log(t.calls),nR(t.children),console.groupEnd()):console.log(r)})}function bj(e,t){function r(a){try{return e.getContext(a,t)}catch{return null}}var n=(t?.preferWebGl1?null:r("webgl2"))||r("webgl")||r("experimental-webgl");return or&&console.log("isWebgl2: ".concat(Gt(n))),n}function iR(e,t){switch(t){case e.NO_ERROR:return"no error";case e.INVALID_ENUM:return"invalid enum";case e.INVALID_VALUE:return"invalid value";case e.INVALID_OPERATION:return"invalid operation";case e.INVALID_FRAMEBUFFER_OPERATION:return"invalid framebuffer operation";case e.OUT_OF_MEMORY:return"out of memory";case e.CONTEXT_LOST_WEBGL:return"context lost"}return"unknown error"}function oR(e){var t=e.getError();if(t!==e.NO_ERROR)throw new Error("WebGL error: '".concat(iR(e,t),"'"))}function rCe(e){for(var t=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),r=0;r = 8');var c=n.provokingVertex;c?.provokingVertex(c.FIRST_VERTEX_CONVENTION);var l=!1,f=new ha(0),d;if(Gt(e)){var m=e.createBuffer(),h=void 0,p=void 0,v=!1,g=function(){e.bindBuffer(e.PIXEL_PACK_BUFFER,m),e.getBufferSubData(e.PIXEL_PACK_BUFFER,0,h),e.bindBuffer(e.PIXEL_PACK_BUFFER,null),v=!1,p(),p=void 0,h=void 0};d=function(x,S,_,C,D){return new Promise(function(T,A){if(v){A("Can not call multiple readPixelsAsync at the same time");return}v=!0,e.bindBuffer(e.PIXEL_PACK_BUFFER,m),e.bufferData(e.PIXEL_PACK_BUFFER,_*C*4,e.STREAM_READ),e.readPixels(x,S,_,C,e.RGBA,e.UNSIGNED_BYTE,0),e.bindBuffer(e.PIXEL_PACK_BUFFER,null),p=T,h=D,Cj(e,g)})}}else d=function(x,S,_,C,D){return $(r,void 0,void 0,function(){return J(this,function(T){return aR(e,x,S,_,C,D),[2]})})};var b=new Set;return{gl:e,isWebGL2:Gt(e),get pixelRatio(){var x=typeof window<"u"&&window.devicePixelRatio||1;return x*(t.pixelScale||1)},extensions:n,state:a,stats:i,resources:o,timer:s,get maxTextureSize(){return u.maxTextureSize},get max3dTextureSize(){return u.max3dTextureSize},get maxRenderbufferSize(){return u.maxRenderbufferSize},get maxDrawBuffers(){return u.maxDrawBuffers},get maxTextureImageUnits(){return u.maxTextureImageUnits},namedComputeRenderables:Object.create(null),namedFramebuffers:Object.create(null),namedTextures:Object.create(null),get isContextLost(){return l||e.isContextLost()},contextRestored:f,setContextLost:function(){l=!0},handleContextRestored:function(x){Object.assign(n,tR(e)),a.reset(),a.currentMaterialId=-1,a.currentProgramId=-1,a.currentRenderItemId=-1,o.reset(),b.forEach(function(S){return S.reset()}),x?.(),l=!1,f.next(pn())},createRenderTarget:function(x,S,_,C,D,T){var A=pj(e,o,x,S,_,C,D,T);return b.add(A),P(P({},A),{destroy:function(){A.destroy(),b.delete(A)}})},unbindFramebuffer:function(){return N_(e)},readPixels:function(x,S,_,C,D){aR(e,x,S,_,C,D)},readPixelsAsync:d,waitForGpuCommandsComplete:function(){return nCe(e)},waitForGpuCommandsCompleteSync:function(){return _j(e)},getDrawingBufferPixelData:function(){return aCe(e,a)},clear:function(x,S,_,C){N_(e),a.enable(e.SCISSOR_TEST),a.depthMask(!0),a.colorMask(!0,!0,!0,!0),a.clearColor(x,S,_,C),a.viewport(0,0,e.drawingBufferWidth,e.drawingBufferHeight),a.scissor(0,0,e.drawingBufferWidth,e.drawingBufferHeight),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)},destroy:function(x){var S,_;o.destroy(),rCe(e),x?.doNotForceWebGLContextLoss||((S=e.getExtension("WEBGL_lose_context"))===null||S===void 0||S.loseContext(),(_=e.getExtension("STACKGL_destroy_context"))===null||_===void 0||_.destroy())}}}function Gt(e){return typeof WebGL2RenderingContext<"u"&&e instanceof WebGL2RenderingContext}function d7(e){if(Gt(e))return{drawArraysInstanced:e.drawArraysInstanced.bind(e),drawElementsInstanced:e.drawElementsInstanced.bind(e),vertexAttribDivisor:e.vertexAttribDivisor.bind(e),VERTEX_ATTRIB_ARRAY_DIVISOR:e.VERTEX_ATTRIB_ARRAY_DIVISOR};var t=e.getExtension("ANGLE_instanced_arrays");return t===null?null:{drawArraysInstanced:t.drawArraysInstancedANGLE.bind(t),drawElementsInstanced:t.drawElementsInstancedANGLE.bind(t),vertexAttribDivisor:t.vertexAttribDivisorANGLE.bind(t),VERTEX_ATTRIB_ARRAY_DIVISOR:t.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE}}function m7(e){if(Gt(e))return{FRAGMENT_SHADER_DERIVATIVE_HINT:e.FRAGMENT_SHADER_DERIVATIVE_HINT};var t=e.getExtension("OES_standard_derivatives");return t===null?null:{FRAGMENT_SHADER_DERIVATIVE_HINT:t.FRAGMENT_SHADER_DERIVATIVE_HINT_OES}}function p7(e){return Gt(e)?{}:e.getExtension("OES_element_index_uint")}function h7(e){if(Gt(e))return{VERTEX_ARRAY_BINDING:e.VERTEX_ARRAY_BINDING,bindVertexArray:e.bindVertexArray.bind(e),createVertexArray:e.createVertexArray.bind(e),deleteVertexArray:e.deleteVertexArray.bind(e),isVertexArray:e.isVertexArray.bind(e)};var t=e.getExtension("OES_vertex_array_object");return t===null?null:{VERTEX_ARRAY_BINDING:t.VERTEX_ARRAY_BINDING_OES,bindVertexArray:t.bindVertexArrayOES.bind(t),createVertexArray:t.createVertexArrayOES.bind(t),deleteVertexArray:t.deleteVertexArrayOES.bind(t),isVertexArray:t.isVertexArrayOES.bind(t)}}function v7(e){return Gt(e)?{}:e.getExtension("OES_texture_float")}function g7(e){return e.getExtension("OES_texture_float_linear")}function y7(e){if(Gt(e))return{HALF_FLOAT:e.HALF_FLOAT};var t=e.getExtension("OES_texture_half_float");return t===null?null:{HALF_FLOAT:t.HALF_FLOAT_OES}}function b7(e){return e.getExtension("OES_texture_half_float_linear")}function x7(e){if(Gt(e))return{MIN:e.MIN,MAX:e.MAX};var t=e.getExtension("EXT_blend_minmax");return t===null?null:{MIN:t.MIN_EXT,MAX:t.MAX_EXT}}function S7(e){return Gt(e)?{}:e.getExtension("EXT_frag_depth")}function C7(e){if(Gt(e))return e.getExtension("EXT_color_buffer_float")===null?null:(e.getExtension("EXT_float_blend"),{RGBA32F:e.RGBA32F});var t=e.getExtension("WEBGL_color_buffer_float");return t===null?(e.getExtension("OES_texture_float"),Tj(e,e.FLOAT)?{RGBA32F:34836}:null):(e.getExtension("EXT_float_blend"),{RGBA32F:t.RGBA32F_EXT})}function _7(e){if(Gt(e))return e.getExtension("EXT_color_buffer_half_float")===null?null:(e.getExtension("EXT_float_blend"),{RGBA16F:e.RGBA16F});var t=e.getExtension("EXT_color_buffer_half_float");return t===null?(e.getExtension("OES_texture_half_float"),Tj(e,36193)?{RGBA16F:34842}:null):(e.getExtension("EXT_float_blend"),{RGBA16F:t.RGBA16F_EXT})}function w7(e){if(Gt(e))return{drawBuffers:e.drawBuffers.bind(e),COLOR_ATTACHMENT0:e.COLOR_ATTACHMENT0,COLOR_ATTACHMENT1:e.COLOR_ATTACHMENT1,COLOR_ATTACHMENT2:e.COLOR_ATTACHMENT2,COLOR_ATTACHMENT3:e.COLOR_ATTACHMENT3,COLOR_ATTACHMENT4:e.COLOR_ATTACHMENT4,COLOR_ATTACHMENT5:e.COLOR_ATTACHMENT5,COLOR_ATTACHMENT6:e.COLOR_ATTACHMENT6,COLOR_ATTACHMENT7:e.COLOR_ATTACHMENT7,DRAW_BUFFER0:e.DRAW_BUFFER0,DRAW_BUFFER1:e.DRAW_BUFFER1,DRAW_BUFFER2:e.DRAW_BUFFER2,DRAW_BUFFER3:e.DRAW_BUFFER3,DRAW_BUFFER4:e.DRAW_BUFFER4,DRAW_BUFFER5:e.DRAW_BUFFER5,DRAW_BUFFER6:e.DRAW_BUFFER6,DRAW_BUFFER7:e.DRAW_BUFFER7,MAX_COLOR_ATTACHMENTS:e.MAX_COLOR_ATTACHMENTS,MAX_DRAW_BUFFERS:e.MAX_DRAW_BUFFERS};var t=e.getExtension("WEBGL_draw_buffers");return t===null?null:{drawBuffers:t.drawBuffersWEBGL.bind(t),COLOR_ATTACHMENT0:t.COLOR_ATTACHMENT0_WEBGL,COLOR_ATTACHMENT1:t.COLOR_ATTACHMENT1_WEBGL,COLOR_ATTACHMENT2:t.COLOR_ATTACHMENT2_WEBGL,COLOR_ATTACHMENT3:t.COLOR_ATTACHMENT3_WEBGL,COLOR_ATTACHMENT4:t.COLOR_ATTACHMENT4_WEBGL,COLOR_ATTACHMENT5:t.COLOR_ATTACHMENT5_WEBGL,COLOR_ATTACHMENT6:t.COLOR_ATTACHMENT6_WEBGL,COLOR_ATTACHMENT7:t.COLOR_ATTACHMENT7_WEBGL,DRAW_BUFFER0:t.DRAW_BUFFER0_WEBGL,DRAW_BUFFER1:t.DRAW_BUFFER1_WEBGL,DRAW_BUFFER2:t.DRAW_BUFFER2_WEBGL,DRAW_BUFFER3:t.DRAW_BUFFER3_WEBGL,DRAW_BUFFER4:t.DRAW_BUFFER4_WEBGL,DRAW_BUFFER5:t.DRAW_BUFFER5_WEBGL,DRAW_BUFFER6:t.DRAW_BUFFER6_WEBGL,DRAW_BUFFER7:t.DRAW_BUFFER7_WEBGL,MAX_COLOR_ATTACHMENTS:t.MAX_COLOR_ATTACHMENTS_WEBGL,MAX_DRAW_BUFFERS:t.MAX_DRAW_BUFFERS_WEBGL}}function T7(e){var t=e.getExtension("OES_draw_buffers_indexed");return t===null?null:{enablei:t.enableiOES.bind(t),disablei:t.disableiOES.bind(t),blendEquationi:t.blendEquationiOES.bind(t),blendEquationSeparatei:t.blendEquationSeparateiOES.bind(t),blendFunci:t.blendFunciOES.bind(t),blendFuncSeparatei:t.blendFuncSeparateiOES.bind(t),colorMaski:t.colorMaskiOES.bind(t)}}function A7(e){return Gt(e)?{}:e.getExtension("EXT_shader_texture_lod")}function D7(e){if(Gt(e))return{UNSIGNED_INT_24_8:e.UNSIGNED_INT_24_8};var t=e.getExtension("WEBGL_depth_texture");return t===null?null:{UNSIGNED_INT_24_8:t.UNSIGNED_INT_24_8_WEBGL}}function P7(e){if(Gt(e))return{FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:e.FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING,SRGB8_ALPHA8:e.SRGB8_ALPHA8,SRGB8:e.SRGB8,SRGB:e.SRGB};var t=e.getExtension("EXT_sRGB");return t===null?null:{FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING:t.FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING_EXT,SRGB8_ALPHA8:t.SRGB8_ALPHA8_EXT,SRGB8:t.SRGB_ALPHA_EXT,SRGB:t.SRGB_EXT}}function E7(e){if(Gt(e)){var t=e.getExtension("EXT_disjoint_timer_query_webgl2")||e.getExtension("EXT_disjoint_timer_query");return t===null?null:{QUERY_COUNTER_BITS:t.QUERY_COUNTER_BITS_EXT,CURRENT_QUERY:e.CURRENT_QUERY,QUERY_RESULT:e.QUERY_RESULT,QUERY_RESULT_AVAILABLE:e.QUERY_RESULT_AVAILABLE,TIME_ELAPSED:t.TIME_ELAPSED_EXT,TIMESTAMP:t.TIMESTAMP_EXT,GPU_DISJOINT:t.GPU_DISJOINT_EXT,createQuery:e.createQuery.bind(e),deleteQuery:e.deleteQuery.bind(e),isQuery:e.isQuery.bind(e),beginQuery:e.beginQuery.bind(e),endQuery:e.endQuery.bind(e),queryCounter:t.queryCounterEXT.bind(t),getQuery:e.getQuery.bind(e),getQueryParameter:e.getQueryParameter.bind(e)}}else{var t=e.getExtension("EXT_disjoint_timer_query");return t===null?null:{QUERY_COUNTER_BITS:t.QUERY_COUNTER_BITS_EXT,CURRENT_QUERY:t.CURRENT_QUERY_EXT,QUERY_RESULT:t.QUERY_RESULT_EXT,QUERY_RESULT_AVAILABLE:t.QUERY_RESULT_AVAILABLE_EXT,TIME_ELAPSED:t.TIME_ELAPSED_EXT,TIMESTAMP:t.TIMESTAMP_EXT,GPU_DISJOINT:t.GPU_DISJOINT_EXT,createQuery:t.createQueryEXT.bind(t),deleteQuery:t.deleteQueryEXT.bind(t),isQuery:t.isQueryEXT.bind(t),beginQuery:t.beginQueryEXT.bind(t),endQuery:t.endQueryEXT.bind(t),queryCounter:t.queryCounterEXT.bind(t),getQuery:t.getQueryEXT.bind(t),getQueryParameter:t.getQueryObjectEXT.bind(t)}}}function I7(e){var t=e.getExtension("KHR_parallel_shader_compile");return t===null?null:{COMPLETION_STATUS:t.COMPLETION_STATUS_KHR}}function M7(e){return Gt(e)?{}:e.getExtension("OES_fbo_render_mipmap")}function R7(e){if(Gt(e)){var t=e.getExtension("WEBGL_provoking_vertex");if(t)return{FIRST_VERTEX_CONVENTION:t.FIRST_VERTEX_CONVENTION_WEBGL,LAST_VERTEX_CONVENTION:t.LAST_VERTEX_CONVENTION_WEBGL,PROVOKING_VERTEX:t.PROVOKING_VERTEX_WEBGL,provokingVertex:t.provokingVertexWEBGL.bind(t)}}return null}function B7(e){if(Gt(e)){var t=e.getExtension("WEBGL_clip_cull_distance");if(t)return{MAX_CLIP_DISTANCES:t.MAX_CLIP_DISTANCES_WEBGL,MAX_CULL_DISTANCES:t.MAX_CULL_DISTANCES_WEBGL,MAX_COMBINED_CLIP_AND_CULL_DISTANCES:t.MAX_COMBINED_CLIP_AND_CULL_DISTANCES_WEBGL,CLIP_DISTANCE0:t.CLIP_DISTANCE0_WEBGL,CLIP_DISTANCE1:t.CLIP_DISTANCE1_WEBGL,CLIP_DISTANCE2:t.CLIP_DISTANCE2_WEBGL,CLIP_DISTANCE3:t.CLIP_DISTANCE3_WEBGL,CLIP_DISTANCE4:t.CLIP_DISTANCE4_WEBGL,CLIP_DISTANCE5:t.CLIP_DISTANCE5_WEBGL,CLIP_DISTANCE6:t.CLIP_DISTANCE6_WEBGL,CLIP_DISTANCE7:t.CLIP_DISTANCE7_WEBGL}}return null}function O7(e){if(Gt(e)){var t=e.getExtension("EXT_conservative_depth");if(t)return{}}return null}function F7(e){if(Gt(e)){var t=e.getExtension("WEBGL_stencil_texturing");if(t)return{DEPTH_STENCIL_TEXTURE_MODE:t.DEPTH_STENCIL_TEXTURE_MODE_WEBGL,STENCIL_INDEX:t.STENCIL_INDEX_WEBGL}}return null}function L7(e){var t=e.getExtension("EXT_clip_control");return t?{LOWER_LEFT:t.LOWER_LEFT_EXT,UPPER_LEFT:t.UPPER_LEFT_EXT,NEGATIVE_ONE_TO_ONE:t.NEGATIVE_ONE_TO_ONE_EXT,ZERO_TO_ONE:t.ZERO_TO_ONE_EXT,CLIP_ORIGIN:t.CLIP_ORIGIN_EXT,CLIP_DEPTH_MODE:t.CLIP_DEPTH_MODE_EXT,clipControl:t.clipControlEXT.bind(t)}:null}function k7(e){if(!Gt(e))return!1;if(typeof navigator<"u"){var t=window.navigator.userAgent.match(/Firefox\/([0-9]+)\./);if(!t)return!0;var r=parseInt(t[1]);return r>=85}return!1}var oCe=` +attribute vec4 aPosition; + +void main() { + gl_Position = aPosition; +}`,sCe=` +precision mediump float; +uniform vec4 uColor; +uniform sampler2D uTexture; + +void main() { + gl_FragColor = texture2D(uTexture, vec2(0.5, 0.5)) * uColor; +}`,uCe=new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]);function Tj(e,t){var r=ax(e,{type:"vert",source:oCe}),n=ax(e,{type:"frag",source:sCe});if(!r||!n)return!1;var a=k_(e);e.attachShader(a,r),e.attachShader(a,n),e.linkProgram(a),e.useProgram(a);var i=e.getAttribLocation(a,"aPosition"),o=e.getUniformLocation(a,"uColor");if(!o)return or&&console.log("error getting 'uColor' uniform location"),!1;var s=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,s),e.bufferData(e.ARRAY_BUFFER,uCe,e.STATIC_DRAW),e.enableVertexAttribArray(i),e.vertexAttribPointer(i,2,e.FLOAT,!1,0,0);var u=e.createTexture(),c=new Uint8Array([255,255,255,255]);e.bindTexture(e.TEXTURE_2D,u),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,1,1,0,e.RGBA,e.UNSIGNED_BYTE,c);var l=e.createTexture();e.bindTexture(e.TEXTURE_2D,l),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,1,1,0,e.RGBA,t,null),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST);var f=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,f),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,l,0);var d=e.checkFramebufferStatus(e.FRAMEBUFFER);if(d!==e.FRAMEBUFFER_COMPLETE)return or&&console.log("error creating framebuffer for '".concat(t,"'")),!1;e.bindTexture(e.TEXTURE_2D,u),e.uniform4fv(o,[0,10,20,1]),e.drawArrays(e.TRIANGLES,0,6),e.bindTexture(e.TEXTURE_2D,l),e.bindFramebuffer(e.FRAMEBUFFER,null),e.clearColor(1,0,0,1),e.clear(e.COLOR_BUFFER_BIT),e.uniform4fv(o,[0,1/10,1/20,1]),e.drawArrays(e.TRIANGLES,0,6);var m=new Uint8Array(4);if(e.readPixels(0,0,1,1,e.RGBA,e.UNSIGNED_BYTE,m),m[0]!==0||m[1]<248||m[2]<248||m[3]<254)return or&&console.log("not able to actually render to '".concat(t,"' texture")),!1;if(t===e.FLOAT){e.bindFramebuffer(e.FRAMEBUFFER,f);var h=new Float32Array(4);e.readPixels(0,0,1,1,e.RGBA,e.FLOAT,h);var p=e.getError();if(p)return or&&console.log("error reading float pixels: '".concat(iR(e,p),"'")),!1}return!0}var sR=ua();function cCe(e,t){switch(t){case"image-uint8":return e.TEXTURE_2D;case"image-float32":return e.TEXTURE_2D;case"image-float16":return e.TEXTURE_2D;case"image-depth":return e.TEXTURE_2D}if(Gt(e))switch(t){case"image-int32":return e.TEXTURE_2D;case"volume-uint8":return e.TEXTURE_3D;case"volume-float32":return e.TEXTURE_3D;case"volume-float16":return e.TEXTURE_3D}throw new Error("unknown texture kind '".concat(t,"'"))}function Ij(e,t,r){switch(t){case"alpha":return Gt(e)&&r==="float"?e.RED:Gt(e)&&r==="int"?e.RED_INTEGER:e.ALPHA;case"rgb":return Gt(e)&&r==="int"?e.RGB_INTEGER:e.RGB;case"rg":if(Gt(e)&&r==="float")return e.RG;if(Gt(e)&&r==="int")return e.RG_INTEGER;throw new Error('texture format "rg" requires webgl2 and type "float" or int"');case"rgba":return Gt(e)&&r==="int"?e.RGBA_INTEGER:e.RGBA;case"depth":return e.DEPTH_COMPONENT}}function lCe(e,t,r){if(Gt(e))switch(t){case"alpha":switch(r){case"ubyte":return e.ALPHA;case"float":return e.R32F;case"fp16":return e.R16F;case"int":return e.R32I}case"rg":switch(r){case"ubyte":return e.RG;case"float":return e.RG32F;case"fp16":return e.RG16F;case"int":return e.RG32I}case"rgb":switch(r){case"ubyte":return e.RGB;case"float":return e.RGB32F;case"fp16":return e.RGB16F;case"int":return e.RGB32I}case"rgba":switch(r){case"ubyte":return e.RGBA;case"float":return e.RGBA32F;case"fp16":return e.RGBA16F;case"int":return e.RGBA32I}case"depth":switch(r){case"ushort":return e.DEPTH_COMPONENT16;case"float":return e.DEPTH_COMPONENT32F}}return Ij(e,t,r)}function Mj(e,t,r,n,a){var i=fCe(e)*dCe(t);return i*r*n*(a||1)}function fCe(e){switch(e){case"alpha":return 1;case"rg":return 2;case"rgb":return 3;case"rgba":return 4;case"depth":return 4}}function dCe(e){switch(e){case"ubyte":return 1;case"ushort":return 2;case"float":return 4;case"fp16":return 2;case"int":return 4}}function mCe(e,t,r){switch(r){case"ubyte":return e.UNSIGNED_BYTE;case"ushort":return e.UNSIGNED_SHORT;case"float":return e.FLOAT;case"fp16":if(t.textureHalfFloat)return t.textureHalfFloat.HALF_FLOAT;throw new Error('extension "texture_half_float" unavailable');case"int":if(Gt(e))return e.INT;throw new Error('texture type "int" requires webgl2')}}function Aj(e,t){switch(t){case"nearest":return e.NEAREST;case"linear":return e.LINEAR}}function U_(e,t,r){switch(r){case"depth":return e.DEPTH_ATTACHMENT;case"stencil":return e.STENCIL_ATTACHMENT;case"color0":case 0:return e.COLOR_ATTACHMENT0}if(t.drawBuffers)switch(r){case"color1":case 1:return t.drawBuffers.COLOR_ATTACHMENT1;case"color2":case 2:return t.drawBuffers.COLOR_ATTACHMENT2;case"color3":case 3:return t.drawBuffers.COLOR_ATTACHMENT3;case"color4":case 4:return t.drawBuffers.COLOR_ATTACHMENT4;case"color5":case 5:return t.drawBuffers.COLOR_ATTACHMENT5;case"color6":case 6:return t.drawBuffers.COLOR_ATTACHMENT6;case"color7":case 7:return t.drawBuffers.COLOR_ATTACHMENT7}throw new Error("unknown texture attachment")}function Dj(e){return typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement}function pCe(e,t,r){return t===r.TEXTURE_2D}function Pj(e,t,r){return t===r.TEXTURE_3D}function Ej(e){var t=e.createTexture();if(t===null)throw new Error("Could not create WebGL texture");return t}function fj(e,t,r,n,a,i){var o=sR(),s=Ej(e);if(r.endsWith("float32")&&a!=="float"||r.endsWith("float16")&&a!=="fp16"||r.endsWith("uint8")&&a!=="ubyte"||r.endsWith("int32")&&a!=="int"||r.endsWith("depth")&&a!=="ushort"&&a!=="float")throw new Error("texture kind '".concat(r,"' and type '").concat(a,"' are incompatible"));if(!t.depthTexture&&n==="depth")throw new Error("extension 'WEBGL_depth_texture' needed for 'depth' texture format");var u=cCe(e,r),c=Aj(e,i),l=Ij(e,n,a),f=lCe(e,n,a),d=mCe(e,t,a);function m(){e.bindTexture(u,s),e.texParameteri(u,e.TEXTURE_MAG_FILTER,c),e.texParameteri(u,e.TEXTURE_MIN_FILTER,c),e.texParameteri(u,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(u,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.bindTexture(u,null)}m();var h=0,p=0,v=0,g,b=!1,x=!1;function S(T,A,E){if(T===0||A===0||Gt(e)&&u===e.TEXTURE_3D&&E===0)throw new Error("empty textures are not allowed");if(!(h===T&&p===A&&v===(E||0)))if(h=T,p=A,v=E||0,e.bindTexture(u,s),u===e.TEXTURE_2D)e.texImage2D(u,0,f,h,p,0,l,d,null);else if(Gt(e)&&u===e.TEXTURE_3D&&v!==void 0)e.texImage3D(u,0,f,h,p,v,0,l,d,null);else throw new Error("unknown texture target")}S(1,1,Gt(e)&&u===e.TEXTURE_3D?1:0);function _(T,A){if(A===void 0&&(A=!1),T.width===0||T.height===0||!Dj(T)&&Gt(e)&&Pj(T,u,e)&&T.depth===0)throw new Error("empty textures are not allowed");if(e.bindTexture(u,s),e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.NONE),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,0),Dj(T))h=T.width,p=T.height,e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),e.bindTexture(e.TEXTURE_2D,s),e.texImage2D(e.TEXTURE_2D,0,f,l,d,T);else if(pCe(T,u,e)){var E=T.filter?Aj(e,T.filter):c;e.texParameteri(u,e.TEXTURE_MAG_FILTER,E),e.texParameteri(u,e.TEXTURE_MIN_FILTER,E),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!!T.flipY),A?e.texSubImage2D(u,0,0,0,T.width,T.height,l,d,T.array):(h=T.width,p=T.height,e.texImage2D(u,0,f,h,p,0,l,d,T.array))}else if(Gt(e)&&Pj(T,u,e))e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),A?e.texSubImage3D(u,0,0,0,0,T.width,T.height,T.depth,l,d,T.array):(h=T.width,p=T.height,v=T.depth,e.texImage3D(u,0,f,h,p,v,0,l,d,T.array));else throw new Error("unknown texture target");e.bindTexture(u,null),g=T}function C(){if(u!==e.TEXTURE_2D)throw new Error("mipmap only supported for 2d textures");if(Gt(e)||Am(h)&&Am(p))e.bindTexture(u,s),e.texParameteri(u,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR),e.generateMipmap(u),e.bindTexture(u,null),b=!0;else throw new Error("mipmap unsupported for non-power-of-two textures and webgl1")}function D(T,A,E){if(T.bind(),u===e.TEXTURE_2D)e.framebufferTexture2D(e.FRAMEBUFFER,U_(e,t,A),e.TEXTURE_2D,s,0);else if(Gt(e)&&u===e.TEXTURE_3D){if(E===void 0)throw new Error("need `layer` to attach 3D texture");e.framebufferTextureLayer(e.FRAMEBUFFER,U_(e,t,A),s,0,E)}else throw new Error("unknown/unsupported texture target")}return{id:o,target:u,format:l,internalFormat:f,type:d,filter:c,getWidth:function(){return h},getHeight:function(){return p},getDepth:function(){return v},getByteCount:function(){return Mj(n,a,h,p,v)},define:S,load:_,mipmap:C,bind:function(T){e.activeTexture(e.TEXTURE0+T),e.bindTexture(u,s)},unbind:function(T){e.activeTexture(e.TEXTURE0+T),e.bindTexture(u,null)},attachFramebuffer:D,detachFramebuffer:function(T,A){if(T.bind(),u===e.TEXTURE_2D)e.framebufferTexture2D(e.FRAMEBUFFER,U_(e,t,A),e.TEXTURE_2D,null,0);else if(Gt(e)&&u===e.TEXTURE_3D)e.framebufferTextureLayer(e.FRAMEBUFFER,U_(e,t,A),null,0,0);else throw new Error("unknown texture target")},reset:function(){s=Ej(e),m();var T=[h,p,v],A=T[0],E=T[1],I=T[2];h=0,p=0,v=0,S(A,E,I),g&&_(g),b&&C()},destroy:function(){x||(e.deleteTexture(s),x=!0)}}}function uR(e,t,r){var n=e.resources,a=[];return Object.keys(t).forEach(function(i){var o=t[i];if(o.type==="texture"){var s=r[i];if(s)if(o.kind==="texture")a[a.length]=[i,s.ref.value];else{var u=n.texture(o.kind,o.format,o.dataType,o.filter);u.load(s.ref.value),a[a.length]=[i,u]}}}),a}function cR(e,t,r){var n=new Image;n.onload=function(){r.load(n),M.update(t,r)},n.src=e}function hCe(e,t){switch(t){case"nx":return e.TEXTURE_CUBE_MAP_NEGATIVE_X;case"ny":return e.TEXTURE_CUBE_MAP_NEGATIVE_Y;case"nz":return e.TEXTURE_CUBE_MAP_NEGATIVE_Z;case"px":return e.TEXTURE_CUBE_MAP_POSITIVE_X;case"py":return e.TEXTURE_CUBE_MAP_POSITIVE_Y;case"pz":return e.TEXTURE_CUBE_MAP_POSITIVE_Z}}function dj(e,t,r,n){var a=e.TEXTURE_CUBE_MAP,i=e.LINEAR,o=e.RGBA,s=e.RGBA,u=e.UNSIGNED_BYTE,c=0,l=e.createTexture();e.bindTexture(a,l);var f=0;Ua(t,function(m,h){if(m){var p=0,v=hCe(e,h),g=new Image;m instanceof File?g.src=URL.createObjectURL(m):Dm(m)?m.then(function(b){g.src=URL.createObjectURL(b)}):g.src=m,g.addEventListener("load",function(){c===0&&(c=g.width),e.texImage2D(v,p,o,c,c,0,s,u,null),e.pixelStorei(e.UNPACK_ALIGNMENT,4),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.NONE),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,0),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),e.bindTexture(a,l),e.texImage2D(v,p,o,s,u,g),f+=1,f===6&&(d||(r?(e.texParameteri(a,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR),e.generateMipmap(a)):e.texParameteri(a,e.TEXTURE_MIN_FILTER,i),e.texParameteri(a,e.TEXTURE_MAG_FILTER,i)),n?.(d))}),g.addEventListener("error",function(){n?.(!0)})}});var d=!1;return{id:sR(),target:a,format:s,internalFormat:o,type:u,filter:i,getWidth:function(){return c},getHeight:function(){return c},getDepth:function(){return 0},getByteCount:function(){return Mj("rgba","ubyte",c,c,0)*6*(r?2:1)},define:function(){},load:function(){},mipmap:function(){},bind:function(m){e.activeTexture(e.TEXTURE0+m),e.bindTexture(a,l)},unbind:function(m){e.activeTexture(e.TEXTURE0+m),e.bindTexture(a,null)},attachFramebuffer:function(){},detachFramebuffer:function(){},reset:function(){},destroy:function(){d||(e.deleteTexture(l),d=!0)}}}var Rj=-1;function Bj(e){return e.format===Rj}function Ga(e){var t,r=(t=e?.TEXTURE_2D)!==null&&t!==void 0?t:3553;return{id:sR(),target:r,format:Rj,internalFormat:0,type:0,filter:0,getWidth:function(){return 0},getHeight:function(){return 0},getDepth:function(){return 0},getByteCount:function(){return 0},define:function(){},load:function(){},mipmap:function(){},bind:function(n){e&&(e.activeTexture(e.TEXTURE0+n),e.bindTexture(r,null))},unbind:function(n){e&&(e.activeTexture(e.TEXTURE0+n),e.bindTexture(r,null))},attachFramebuffer:function(){throw new Error("cannot attach null-texture to a framebuffer")},detachFramebuffer:function(){throw new Error("cannot detach null-texture from a framebuffer")},reset:function(){},destroy:function(){}}}function Qa(e,t,r,n){var a=vCe(e,t,r,n);return r.palette?(M.updateIfChanged(a.dUsePalette,!0),gCe(r.palette,a.tPalette)):M.updateIfChanged(a.dUsePalette,!1),a}function vCe(e,t,r,n){switch(r.granularity){case"uniform":return bCe(e,r.color,n);case"instance":return e.nonInstanceable?Oj(e,r.color,n):xCe(e,r.color,n);case"group":return Oj(e,r.color,n);case"groupInstance":return SCe(e,r.color,n);case"vertex":return CCe(t,r.color,n);case"vertexInstance":return _Ce(t,r.color,n);case"volume":return Fj(r.grid,"volume",n);case"volumeInstance":return Fj(r.grid,"volumeInstance",n);case"direct":return wCe(n)}}function gCe(e,t){var r=!0,n=t.ref.value;if(e.colors.length!==n.width||n.filter!==e.filter)r=!1;else for(var a=n.array,i=0,o=0,s=e.colors;o =t*16?r.transform.ref.value:new Float32Array(t*16);a.set(e),M.update(r.transform,a),M.updateIfChanged(r.uInstanceCount,t),M.updateIfChanged(r.instanceCount,t);var i=r.aTransform.ref.value.length>=t*16?r.aTransform.ref.value:new Float32Array(t*16);M.update(r.aTransform,i);var o=r.extraTransform.ref.value.length>=t*16?r.extraTransform.ref.value:new Float32Array(t*16);M.update(r.extraTransform,U0(o,t));var s=r.aInstance.ref.value.length>=t?r.aInstance.ref.value:new Float32Array(t);M.update(r.aInstance,Qi(s,t)),M.update(r.hasReflection,n)}else r={aTransform:M.create(new Float32Array(t*16)),matrix:M.create(se.identity()),transform:M.create(new Float32Array(e)),extraTransform:M.create(U0(new Float32Array(t*16),t)),uInstanceCount:M.create(t),instanceCount:M.create(t),aInstance:M.create(Qi(new Float32Array(t))),hasReflection:M.create(n)};return fR(r),r}var lR=new Float32Array(16);se.toArray(se.identity(),lR,0);function V0(e){return ox(new Float32Array(lR),1,e)}function U0(e,t){for(var r=0;r 1.2&&(n=2)),{resolution:r,stride:n}}}var Ze;(function(e){e.MaterialCategory={category:"Material"},e.ShadingCategory={category:"Shading"},e.CustomQualityParamInfo={category:"Custom Quality",hideIf:function(o){return typeof o.quality<"u"&&o.quality!=="custom"}},e.Params={alpha:w.Numeric(1,{min:0,max:1,step:.01},{label:"Opacity",isEssential:!0,description:"How opaque/transparent the representation is rendered."}),quality:w.Select("auto",sx,{isEssential:!0,description:"Visual/rendering quality of the representation."}),material:Pi.getParam(),clip:w.Group(Ol.Params),instanceGranularity:w.Boolean(!1,{description:"Use instance granularity for marker, transparency, clipping, overpaint, substance data to save memory."})};function t(o,s,u){o===void 0&&(o=Xt.grey),s===void 0&&(s=1),u||(u=V0());var c=hr(1,u.instanceCount.ref.value,1,function(){return Gi},!1,function(){return!1}),l={color:Bl({},{value:o,lightness:0,saturation:0}),size:V_({},{value:s})};return{transform:u,locationIterator:c,theme:l}}e.createSimple=t;function r(o,s){var u=Ol.getClip(o.clip);return{alpha:M.create(o.alpha),uAlpha:M.create(o.alpha),uVertexCount:M.create(s.vertexCount),uGroupCount:M.create(s.groupCount),drawCount:M.create(s.drawCount),uMetalness:M.create(o.material.metalness),uRoughness:M.create(o.material.roughness),uBumpiness:M.create(o.material.bumpiness),dLightCount:M.create(1),dColorMarker:M.create(!0),dClipObjectCount:M.create(u.objects.count),dClipVariant:M.create(u.variant),uClipObjectType:M.create(u.objects.type),uClipObjectInvert:M.create(u.objects.invert),uClipObjectPosition:M.create(u.objects.position),uClipObjectRotation:M.create(u.objects.rotation),uClipObjectScale:M.create(u.objects.scale),instanceGranularity:M.create(o.instanceGranularity)}}e.createValues=r;function n(o,s){M.updateIfChanged(o.alpha,s.alpha),M.updateIfChanged(o.uMetalness,s.material.metalness),M.updateIfChanged(o.uRoughness,s.material.roughness),M.updateIfChanged(o.uBumpiness,s.material.bumpiness);var u=Ol.getClip(s.clip);M.updateIfChanged(o.dClipObjectCount,u.objects.count),M.updateIfChanged(o.dClipVariant,u.variant),M.update(o.uClipObjectType,u.objects.type),M.update(o.uClipObjectInvert,u.objects.invert),M.update(o.uClipObjectPosition,u.objects.position),M.update(o.uClipObjectRotation,u.objects.rotation),M.update(o.uClipObjectScale,u.objects.scale),M.updateIfChanged(o.instanceGranularity,s.instanceGranularity)}e.updateValues=n;function a(o){o===void 0&&(o={});var s=o.alpha===void 0?!0:o.alpha===1;return{disposed:!1,visible:!0,alphaFactor:1,pickable:!0,colorOnly:!1,opaque:s,writeDepth:s}}e.createRenderableState=a;function i(o,s){o.opaque=s.alpha*o.alphaFactor>=1,o.writeDepth=o.opaque}e.updateRenderableState=i})(Ze||(Ze={}));function zj(e,t,r,n){for(var a=t;a 0),M.updateIfChanged(r.dOverpaintType,t),r):{tOverpaint:M.create(n),uOverpaintTexDim:M.create(Me.create(n.width,n.height)),dOverpaint:M.create(e>0),tOverpaintGrid:M.create(Ga()),uOverpaintGridDim:M.create(y.create(1,1,1)),uOverpaintGridTransform:M.create(Wt.create(0,0,0,1)),dOverpaintType:M.create(t),uOverpaintStrength:M.create(1)}}var Gj={array:new Uint8Array(4),width:1,height:1};function Uo(e){return e?(M.update(e.tOverpaint,Gj),M.update(e.uOverpaintTexDim,Me.create(1,1)),e):{tOverpaint:M.create(Gj),uOverpaintTexDim:M.create(Me.create(1,1)),dOverpaint:M.create(!1),tOverpaintGrid:M.create(Ga()),uOverpaintGridDim:M.create(y.create(1,1,1)),uOverpaintGridTransform:M.create(Wt.create(0,0,0,1)),dOverpaintType:M.create("groupInstance"),uOverpaintStrength:M.create(1)}}function qj(e,t,r,n){for(var a=t;a 0),M.updateIfChanged(r.transparencyAverage,mR(n.array,e)),M.updateIfChanged(r.dTransparencyType,t),r):{tTransparency:M.create(n),uTransparencyTexDim:M.create(Me.create(n.width,n.height)),dTransparency:M.create(e>0),transparencyAverage:M.create(0),tTransparencyGrid:M.create(Ga()),uTransparencyGridDim:M.create(y.create(1,1,1)),uTransparencyGridTransform:M.create(Wt.create(0,0,0,1)),dTransparencyType:M.create(t),uTransparencyStrength:M.create(1)}}var jj={array:new Uint8Array(1),width:1,height:1};function Vo(e){return e?(M.update(e.tTransparency,jj),M.update(e.uTransparencyTexDim,Me.create(1,1)),e):{tTransparency:M.create(jj),uTransparencyTexDim:M.create(Me.create(1,1)),dTransparency:M.create(!1),transparencyAverage:M.create(0),tTransparencyGrid:M.create(Ga()),uTransparencyGridDim:M.create(y.create(1,1,1)),uTransparencyGridTransform:M.create(Wt.create(0,0,0,1)),dTransparencyType:M.create("groupInstance"),uTransparencyStrength:M.create(1)}}function Kj(e,t,r,n){return e.fill(n,t,r),!0}function Zj(e,t,r){e.fill(0,t,r)}function Qj(e,t,r){var n=Vn(Math.max(1,e),1,Uint8Array,r&&r.tClipping.ref.value.array);return r?(M.update(r.tClipping,n),M.update(r.uClippingTexDim,Me.create(n.width,n.height)),M.updateIfChanged(r.dClipping,e>0),M.updateIfChanged(r.dClippingType,t),r):{tClipping:M.create(n),uClippingTexDim:M.create(Me.create(n.width,n.height)),dClipping:M.create(e>0),dClippingType:M.create(t)}}var Xj={array:new Uint8Array(1),width:1,height:1};function Go(e){return e?(M.update(e.tClipping,Xj),M.update(e.uClippingTexDim,Me.create(1,1)),M.updateIfChanged(e.dClipping,!1),e):{tClipping:M.create(Xj),uClippingTexDim:M.create(Me.create(1,1)),dClipping:M.create(!1),dClippingType:M.create("groupInstance")}}function Jj(e,t,r,n){for(var a=t;a 0),M.updateIfChanged(r.dSubstanceType,t),r):{tSubstance:M.create(n),uSubstanceTexDim:M.create(Me.create(n.width,n.height)),dSubstance:M.create(e>0),tSubstanceGrid:M.create(Ga()),uSubstanceGridDim:M.create(y.create(1,1,1)),uSubstanceGridTransform:M.create(Wt.create(0,0,0,1)),dSubstanceType:M.create(t),uSubstanceStrength:M.create(1)}}var $j={array:new Uint8Array(4),width:1,height:1};function zo(e){return e?(M.update(e.tSubstance,$j),M.update(e.uSubstanceTexDim,Me.create(1,1)),e):{tSubstance:M.create($j),uSubstanceTexDim:M.create(Me.create(1,1)),dSubstance:M.create(!1),tSubstanceGrid:M.create(Ga()),uSubstanceGridDim:M.create(y.create(1,1,1)),uSubstanceGridTransform:M.create(Wt.create(0,0,0,1)),dSubstanceType:M.create("groupInstance"),uSubstanceStrength:M.create(1)}}var pt;(function(e){function t(I,R,B,O,z,k,G){return G?i(I,R,B,O,z,k,G):a(I,R,B,O,z,k)}e.create=t;function r(I){var R=I?I.vertexBuffer.ref.value:new Float32Array(0),B=I?I.indexBuffer.ref.value:new Uint32Array(0),O=I?I.normalBuffer.ref.value:new Float32Array(0),z=I?I.groupBuffer.ref.value:new Float32Array(0);return t(R,B,O,z,0,0,I)}e.createEmpty=r;function n(I){return ga([I.vertexCount,I.triangleCount,I.vertexBuffer.ref.version,I.indexBuffer.ref.version,I.normalBuffer.ref.version,I.groupBuffer.ref.version])}function a(I,R,B,O,z,k){var G=xe(),V,U=-1,Q=-1,W={kind:"mesh",vertexCount:z,triangleCount:k,vertexBuffer:M.create(I),indexBuffer:M.create(R),normalBuffer:M.create(B),groupBuffer:M.create(O),varyingGroup:M.create(!1),get boundingSphere(){var X=n(W);if(X!==U){var ae=Cu(W.vertexBuffer.ref.value,W.vertexCount,1);xe.copy(G,ae),U=X}return G},get groupMapping(){return W.groupBuffer.ref.version!==Q&&(V=Nc(W.groupBuffer.ref.value,W.vertexCount),Q=W.groupBuffer.ref.version),V},setBoundingSphere:function(X){xe.copy(G,X),U=n(W)},meta:{}};return W}function i(I,R,B,O,z,k,G){return G.vertexCount=z,G.triangleCount=k,M.update(G.vertexBuffer,I),M.update(G.indexBuffer,R),M.update(G.normalBuffer,B),M.update(G.groupBuffer,O),G}function o(I){var R=I.vertexCount,B=I.triangleCount,O=I.vertexBuffer.ref.value,z=I.indexBuffer.ref.value,k=I.normalBuffer.ref.value.length>=R*3?I.normalBuffer.ref.value:new Float32Array(R*3);k===I.normalBuffer.ref.value&&k.fill(0,0,R*3),M_(O,z,k,R,B),M.update(I.normalBuffer,k)}e.computeNormals=o;function s(I,R){R===void 0&&(R=3);for(var B=I.vertexBuffer.ref.value,O=new Map,z=function(X,ae){return"".concat(X[0].toFixed(ae),"|").concat(X[1].toFixed(ae),"|").concat(X[2].toFixed(ae))},k=0,G=y(),V=0,U=I.vertexCount;Vre)){var K=B.get(Ke);if(!(R[K[0]].includes(K[1])&&!(!((z=B.get(K[0]))===null||z===void 0)&&z.includes(K[1])))&&(y.fromArray(j,Q,Ke*3),y.fromArray(Z,Q,K[0]*3),y.fromArray(Y,Q,K[1]*3),y.sub(N,Z,j),y.sub(ee,Y,j),y.add(me,N,ee),!(y.squaredDistance(j,Z)>=O))){for(var ge=!1,Pe=0,Ie=R[Ke];Pe 0?He.add3(ae,Ke,K[0],K[1]):He.add3(ae,K[1],K[0],Ke),te.add(Ke),te.add(K[0]),te.add(K[1]),q+=1)}}}var Ne=He.compact(ae);return I.triangleCount=q,M.update(G,Ne),I}function b(I,R,B){for(var O=B.iterations,z=B.lambda,k=y(),G=y(),V=y(),U=y(),Q=-z,W=new Float32Array(I.vertexBuffer.ref.value.length),X=function(q){var F=I.vertexBuffer.ref.value;W.set(F),R.forEach(function(Z,Y){if(Z.length===2){y.fromArray(k,F,Y*3),y.fromArray(G,F,Z[0]*3),y.fromArray(V,F,Z[1]*3);var H=1/y.distance(k,G),N=1/y.distance(k,V);y.scale(G,G,H),y.scale(V,V,N),y.add(U,G,V),y.scale(U,U,1/(H+N)),y.sub(U,U,k),y.scale(U,U,q),y.add(U,k,U),y.toArray(U,W,Y*3)}});var j=I.vertexBuffer.ref.value;M.update(I.vertexBuffer,W),W=j},ae=0;ae 0&&b(!0),u&&n>0&&b(!1),{vertices:new Float32Array(d),normals:new Float32Array(m),indices:new Uint32Array(f)};function g(){for(var x=y.zero(),S=(n-r)/a,_=0;_<=o;++_){for(var C=[],D=_/o,T=D*(n-r)+r,A=0;A<=i;++A){var E=A/i,I=E*l+c,R=Math.sin(I),B=Math.cos(I);d.push(T*R,-D*a+v,T*B),y.normalize(x,y.set(x,R,S,B)),m.push.apply(m,x),C.push(h++)}p.push(C)}for(var A=0;A