@luma.gl/shadertools 9.3.6 → 9.4.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +6555 -2373
- package/dist/dist.min.js +2984 -237
- package/dist/index.cjs +4356 -268
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +13 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/preprocessor/preprocessor.d.ts +11 -1
- package/dist/lib/preprocessor/preprocessor.d.ts.map +1 -1
- package/dist/lib/preprocessor/preprocessor.js +47 -2
- package/dist/lib/preprocessor/preprocessor.js.map +1 -1
- package/dist/lib/shader-assembler.d.ts +10 -10
- package/dist/lib/shader-assembler.d.ts.map +1 -1
- package/dist/lib/shader-assembler.js +36 -20
- package/dist/lib/shader-assembler.js.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.d.ts +28 -7
- package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.js +133 -15
- package/dist/lib/shader-assembly/assemble-shaders.js.map +1 -1
- package/dist/lib/shader-assembly/platform-info.d.ts +2 -0
- package/dist/lib/shader-assembly/platform-info.d.ts.map +1 -1
- package/dist/lib/shader-assembly/shader-hooks.d.ts +1 -1
- package/dist/lib/shader-assembly/shader-hooks.d.ts.map +1 -1
- package/dist/lib/shader-assembly/shader-hooks.js +6 -3
- package/dist/lib/shader-assembly/shader-hooks.js.map +1 -1
- package/dist/lib/shader-assembly/shader-injections.d.ts +4 -1
- package/dist/lib/shader-assembly/shader-injections.d.ts.map +1 -1
- package/dist/lib/shader-assembly/shader-injections.js +68 -11
- package/dist/lib/shader-assembly/shader-injections.js.map +1 -1
- package/dist/lib/shader-assembly/shader-plugin-varyings.d.ts +15 -0
- package/dist/lib/shader-assembly/shader-plugin-varyings.d.ts.map +1 -0
- package/dist/lib/shader-assembly/shader-plugin-varyings.js +412 -0
- package/dist/lib/shader-assembly/shader-plugin-varyings.js.map +1 -0
- package/dist/lib/shader-assembly/shader-plugin-vertex-inputs.d.ts +12 -0
- package/dist/lib/shader-assembly/shader-plugin-vertex-inputs.d.ts.map +1 -0
- package/dist/lib/shader-assembly/shader-plugin-vertex-inputs.js +237 -0
- package/dist/lib/shader-assembly/shader-plugin-vertex-inputs.js.map +1 -0
- package/dist/lib/shader-module/shader-module.d.ts +3 -0
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module.js.map +1 -1
- package/dist/lib/shader-module/shader-pass-pipeline.d.ts +14 -0
- package/dist/lib/shader-module/shader-pass-pipeline.d.ts.map +1 -0
- package/dist/lib/shader-module/shader-pass-pipeline.js +5 -0
- package/dist/lib/shader-module/shader-pass-pipeline.js.map +1 -0
- package/dist/lib/shader-module/shader-pass.d.ts +21 -4
- package/dist/lib/shader-module/shader-pass.d.ts.map +1 -1
- package/dist/lib/shader-plugin.d.ts +68 -0
- package/dist/lib/shader-plugin.d.ts.map +1 -0
- package/dist/lib/shader-plugin.js +98 -0
- package/dist/lib/shader-plugin.js.map +1 -0
- package/dist/lib/utils/assert.js +1 -1
- package/dist/lib/utils/assert.js.map +1 -1
- package/dist/modules/color/float-colors.d.ts +111 -5
- package/dist/modules/color/float-colors.d.ts.map +1 -1
- package/dist/modules/color/float-colors.js +200 -34
- package/dist/modules/color/float-colors.js.map +1 -1
- package/dist/modules/engine/clip/clip.d.ts +12 -0
- package/dist/modules/engine/clip/clip.d.ts.map +1 -0
- package/dist/modules/engine/clip/clip.js +129 -0
- package/dist/modules/engine/clip/clip.js.map +1 -0
- package/dist/modules/engine/filter/filter.d.ts +12 -0
- package/dist/modules/engine/filter/filter.d.ts.map +1 -0
- package/dist/modules/engine/filter/filter.js +88 -0
- package/dist/modules/engine/filter/filter.js.map +1 -0
- package/dist/modules/geospatial/dggs/dggs-wgsl.d.ts +3 -0
- package/dist/modules/geospatial/dggs/dggs-wgsl.d.ts.map +1 -0
- package/dist/modules/geospatial/dggs/dggs-wgsl.js +1892 -0
- package/dist/modules/geospatial/dggs/dggs-wgsl.js.map +1 -0
- package/dist/modules/geospatial/dggs/dggs.d.ts +6 -0
- package/dist/modules/geospatial/dggs/dggs.d.ts.map +1 -0
- package/dist/modules/geospatial/dggs/dggs.js +10 -0
- package/dist/modules/geospatial/dggs/dggs.js.map +1 -0
- package/dist/modules/lighting/water-material/water-material.d.ts +28 -0
- package/dist/modules/lighting/water-material/water-material.d.ts.map +1 -0
- package/dist/modules/lighting/water-material/water-material.js +179 -0
- package/dist/modules/lighting/water-material/water-material.js.map +1 -0
- package/dist/modules/lighting/water-material/water-shaders-glsl.d.ts +3 -0
- package/dist/modules/lighting/water-material/water-shaders-glsl.d.ts.map +1 -0
- package/dist/modules/lighting/water-material/water-shaders-glsl.js +232 -0
- package/dist/modules/lighting/water-material/water-shaders-glsl.js.map +1 -0
- package/dist/modules/lighting/water-material/water-shaders-wgsl.d.ts +2 -0
- package/dist/modules/lighting/water-material/water-shaders-wgsl.d.ts.map +1 -0
- package/dist/modules/lighting/water-material/water-shaders-wgsl.js +230 -0
- package/dist/modules/lighting/water-material/water-shaders-wgsl.js.map +1 -0
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts +2 -1
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts.map +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js +268 -0
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +50 -3
- package/src/lib/preprocessor/preprocessor.ts +68 -3
- package/src/lib/shader-assembler.ts +49 -20
- package/src/lib/shader-assembly/assemble-shaders.ts +242 -30
- package/src/lib/shader-assembly/platform-info.ts +2 -0
- package/src/lib/shader-assembly/shader-hooks.ts +7 -3
- package/src/lib/shader-assembly/shader-injections.ts +96 -11
- package/src/lib/shader-assembly/shader-plugin-varyings.ts +524 -0
- package/src/lib/shader-assembly/shader-plugin-vertex-inputs.ts +279 -0
- package/src/lib/shader-module/shader-module.ts +3 -0
- package/src/lib/shader-module/shader-pass-pipeline.ts +19 -0
- package/src/lib/shader-module/shader-pass.ts +29 -4
- package/src/lib/shader-plugin.ts +214 -0
- package/src/lib/utils/assert.ts +1 -1
- package/src/modules/color/float-colors.ts +272 -37
- package/src/modules/engine/clip/clip.ts +149 -0
- package/src/modules/engine/filter/filter.ts +107 -0
- package/src/modules/geospatial/dggs/dggs-wgsl.ts +1892 -0
- package/src/modules/geospatial/dggs/dggs.ts +12 -0
- package/src/modules/lighting/water-material/water-material.ts +234 -0
- package/src/modules/lighting/water-material/water-shaders-glsl.ts +233 -0
- package/src/modules/lighting/water-material/water-shaders-wgsl.ts +230 -0
- package/src/modules/math/fp64/fp64-arithmetic-wgsl.ts +268 -0
package/dist/dist.min.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
5
|
else if (typeof exports === 'object') exports['luma'] = factory();
|
|
6
6
|
else root['luma'] = factory();})(globalThis, function () {
|
|
7
|
-
"use strict";var __exports__=(()=>{var
|
|
7
|
+
"use strict";var __exports__=(()=>{var Yi=Object.create;var ae=Object.defineProperty;var Xi=Object.getOwnPropertyDescriptor;var Zi=Object.getOwnPropertyNames;var Ji=Object.getPrototypeOf,Qi=Object.prototype.hasOwnProperty;var er=(e,t,n)=>t in e?ae(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var tr=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),nr=(e,t)=>{for(var n in t)ae(e,n,{get:t[n],enumerable:!0})},xe=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Zi(t))!Qi.call(e,r)&&r!==n&&ae(e,r,{get:()=>t[r],enumerable:!(i=Xi(t,r))||i.enumerable});return e},Se=(e,t,n)=>(xe(e,t,"default"),n&&xe(n,t,"default")),se=(e,t,n)=>(n=e!=null?Yi(Ji(e)):{},xe(t||!e||!e.__esModule?ae(n,"default",{value:e,enumerable:!0}):n,e)),ir=e=>xe(ae({},"__esModule",{value:!0}),e);var Ut=(e,t,n)=>(er(e,typeof t!="symbol"?t+"":t,n),n);var Z=tr((Va,Bt)=>{Bt.exports=globalThis.luma});var be={};nr(be,{STORAGE_COLOR_DEFAULT_BYTE_STRIDES:()=>Ke,STORAGE_COLOR_FORMAT:()=>D,STORAGE_COLOR_FORMAT_BYTE_LENGTHS:()=>We,ShaderAssembler:()=>de,_getDependencyGraph:()=>pe,_resolveModules:()=>Wt,assembleGLSLShaderPair:()=>Fe,capitalize:()=>K,checkShaderModuleDeprecations:()=>fe,clipShaderPlugin:()=>Ri,colors:()=>Li,combineInjects:()=>jt,convertToVec4:()=>vt,dggs:()=>di,dirlight:()=>wt,filterShaderPlugin:()=>Ei,floatColors:()=>oe,fp32:()=>ci,fp64:()=>pi,fp64LowPart:()=>_e,fp64arithmetic:()=>Rt,fp64ify:()=>ie,fp64ifyMatrix4:()=>he,fromHalfFloat:()=>ai,generateShaderForModule:()=>Nn,getGLSLUniformBlocks:()=>Ee,getPassthroughFS:()=>Rn,getQualifierDetails:()=>En,getShaderInfo:()=>ye,getShaderModuleDependencies:()=>ue,getShaderModuleSource:()=>Ge,getShaderModuleUniformBlockFields:()=>at,getShaderModuleUniformBlockName:()=>Ae,getShaderModuleUniformLayoutValidationResult:()=>st,getShaderModuleUniforms:()=>qt,gouraudMaterial:()=>Nt,ibl:()=>Ze,initializeShaderModule:()=>Le,initializeShaderModules:()=>G,lambertMaterial:()=>Tt,lighting:()=>U,mergeShaderPluginModules:()=>Jt,normalizeByteColor3:()=>me,normalizeByteColor4:()=>qe,pbrMaterial:()=>ji,pbrScene:()=>Ki,phongMaterial:()=>Pt,picking:()=>Ii,preprocess:()=>z,random:()=>li,resolveShaderPlugins:()=>Zt,resolveUseByteColors:()=>re,skin:()=>Ci,storageColors:()=>Ai,toHalfFloat:()=>oi,typeToChannelCount:()=>yn,typeToChannelSuffix:()=>Cn,validateShaderModuleUniformLayout:()=>Ie,warnIfGLSLUniformBlocksAreNotStd140:()=>Re,waterMaterial:()=>Gi});Se(be,se(Z(),1));function B(e,t){if(!e){let n=new Error(t||"shadertools: assertion failed.");throw Error.captureStackTrace?.(n,B),n}}var rt={number:{type:"number",validate(e,t){return Number.isFinite(e)&&typeof t=="object"&&(t.max===void 0||e<=t.max)&&(t.min===void 0||e>=t.min)}},array:{type:"array",validate(e,t){return Array.isArray(e)||ArrayBuffer.isView(e)}}};function Ft(e){let t={};for(let[n,i]of Object.entries(e))t[n]=rr(i);return t}function Gt(e,t,n){let i={};for(let[r,o]of Object.entries(t))e&&r in e&&!o.private?(o.validate&&B(o.validate(e[r],o),`${n}: invalid ${r}`),i[r]=e[r]):i[r]=o.value;return i}function rr(e){let t=Dt(e);if(t!=="object")return{value:e,...rt[t],type:t};if(typeof e=="object")return e?e.type!==void 0?{...e,...rt[e.type],type:e.type}:e.value===void 0?{type:"object",value:e}:(t=Dt(e.value),{...e,...rt[t],type:t}):{type:"object",value:null};throw new Error("props")}function Dt(e){return Array.isArray(e)||ArrayBuffer.isView(e)?"array":typeof e}var Vt=`#ifdef MODULE_LOGDEPTH
|
|
8
8
|
logdepth_adjustPosition(gl_Position);
|
|
9
9
|
#endif
|
|
10
|
-
`,
|
|
10
|
+
`,kt=`#ifdef MODULE_MATERIAL
|
|
11
11
|
fragColor = material_filterColor(fragColor);
|
|
12
12
|
#endif
|
|
13
13
|
|
|
@@ -27,11 +27,12 @@
|
|
|
27
27
|
#ifdef MODULE_LOGDEPTH
|
|
28
28
|
logdepth_setFragDepth();
|
|
29
29
|
#endif
|
|
30
|
-
`;var
|
|
30
|
+
`;var or={vertex:Vt,fragment:kt},zt=/void\s+main\s*\([^)]*\)\s*\{\n?/,Ht=/}\n?[^{}]*$/,ot=[],le="__LUMA_INJECT_DECLARATIONS__";function $t(e){let t={vertex:{},fragment:{}};for(let n in e){let i=e[n],r=ar(n);typeof i=="string"&&(i={order:0,injection:i}),t[r][n]=i}return t}function ar(e){let t=e.slice(0,2);switch(t){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(t)}}function ce(e,t,n,i=!1,r="glsl",o={}){let a=t==="vertex";for(let s in n){let l=n[s];l.sort((f,u)=>f.order-u.order),ot.length=l.length;for(let f=0,u=l.length;f<u;++f)ot[f]=l[f].injection;let c=`${ot.join(`
|
|
31
31
|
`)}
|
|
32
|
-
`;switch(
|
|
33
|
-
${
|
|
34
|
-
|
|
32
|
+
`;switch(s){case"vs:#decl":(r==="wgsl"||a)&&(e=e.replace(le,c));break;case"vs:#main-start":(r==="wgsl"||a)&&(e=r==="wgsl"?Me(e,"vertex",c,"start",o.vertex):e.replace(zt,f=>f+c));break;case"vs:#main-end":(r==="wgsl"||a)&&(e=r==="wgsl"?Me(e,"vertex",c,"end",o.vertex):e.replace(Ht,f=>c+f));break;case"fs:#decl":(r==="wgsl"||!a)&&(e=e.replace(le,c));break;case"fs:#main-start":(r==="wgsl"||!a)&&(e=r==="wgsl"?Me(e,"fragment",c,"start",o.fragment):e.replace(zt,f=>f+c));break;case"fs:#main-end":(r==="wgsl"||!a)&&(e=r==="wgsl"?Me(e,"fragment",c,"end",o.fragment):e.replace(Ht,f=>c+f));break;default:e=e.replace(s,f=>f+c)}}return e=e.replace(le,""),i&&(e=e.replace(/\}\s*$/,s=>s+or[t])),e}function jt(e){let t={};return B(Array.isArray(e)&&e.length>1),e.forEach(n=>{for(let i in n)t[i]=t[i]?`${t[i]}
|
|
33
|
+
${n[i]}`:n[i]}),t}function Me(e,t,n,i,r){let o=sr(e,t,r);if(!o)return e;if(i==="start"){let a=o.openBraceIndex+1;return`${e.slice(0,a)}
|
|
34
|
+
${n}${e.slice(a)}`}return`${e.slice(0,o.closeBraceIndex)}${n}${e.slice(o.closeBraceIndex)}`}function sr(e,t,n){let i=t==="vertex"?"@vertex":"@fragment",r=e.indexOf(i);if(r<0)return null;let o=n?e.search(new RegExp(`\\bfn\\s+${lr(n)}\\s*\\(`)):e.indexOf("fn",r);if(o<0)return null;let a=e.indexOf("{",o);if(a<0)return null;let s=0;for(let l=a;l<e.length;l++){let c=e[l];if(c==="{")s++;else if(c==="}"&&(s--,s===0))return{openBraceIndex:a,closeBraceIndex:l}}return null}function lr(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function G(e){e.map(t=>Le(t))}function Le(e){if(e.instance)return;G(e.dependencies||[]);let{propTypes:t={},deprecations:n=[],inject:i={}}=e,r={normalizedInjections:$t(i),parsedDeprecations:cr(n)};t&&(r.propValidators=Ft(t)),e.instance=r;let o={};t&&(o=Object.entries(t).reduce((a,[s,l])=>{let c=l?.value;return c&&(a[s]=c),a},{})),e.defaultUniforms={...e.defaultUniforms,...o}}function qt(e,t,n){Le(e);let i=n||{...e.defaultUniforms};return t&&e.getUniforms?e.getUniforms(t,i):Gt(t,e.instance?.propValidators,e.name)}function fe(e,t,n){e.deprecations?.forEach(i=>{i.regex?.test(t)&&(i.deprecated?n.deprecated(i.old,i.new)():n.removed(i.old,i.new)())})}function cr(e){return e.forEach(t=>{switch(t.type){case"function":t.regex=new RegExp(`\\b${t.old}\\(`);break;default:t.regex=new RegExp(`${t.type} ${t.old};`)}}),e}function ue(e){G(e);let t={},n={};pe({modules:e,level:0,moduleMap:t,moduleDepth:n});let i=Object.keys(n).sort((r,o)=>n[o]-n[r]).map(r=>t[r]);return G(i),i}function pe(e){let{modules:t,level:n,moduleMap:i,moduleDepth:r}=e;if(n>=5)throw new Error("Possible loop in shader dependency graph");for(let o of t)i[o.name]=o,(r[o.name]===void 0||r[o.name]<n)&&(r[o.name]=n);for(let o of t)o.dependencies&&pe({modules:o.dependencies,level:n+1,moduleMap:i,moduleDepth:r})}function fr(e){G(e);let t={},n={};return pe({modules:e,level:0,moduleMap:t,moduleDepth:n}),e=Object.keys(n).sort((i,r)=>n[r]-n[i]).map(i=>t[i]),G(e),e}function Wt(e){return fr(e)}var Xt=se(Z(),1),ur=/^(vs|fs):(?:#(?:decl|main-start|main-end)|[A-Za-z_][\w-]*)$/;function Zt(e=[],t){let n=[],i={},r={},o={},a={};for(let s of e)Kt({modules:n,defines:i,injections:r,vertexInputs:o,varyings:a},s),Kt({modules:n,defines:i,injections:r,vertexInputs:o,varyings:a},s[t]);for(let s of Object.keys(a))if(o[s])throw new Error(`ShaderPlugin name "${s}" cannot be both a vertex input and a varying`);return{modules:n,defines:i,injections:r,vertexInputs:o,varyings:a}}function Jt(e=[],t=[]){let n=[...e],i=new Set(n.map(r=>r.name));for(let r of t)i.has(r.name)||(n.push(r),i.add(r.name));return n}function Kt(e,t){if(t){t.modules?.length&&e.modules.push(...t.modules),t.defines&&Object.assign(e.defines,t.defines);for(let[n,i]of Object.entries(t.vertexInputs||{})){Yt(n,"vertex input");let r=e.vertexInputs[n];if(r&&r!==i)throw new Error(`ShaderPlugin vertex input "${n}" has conflicting types "${r}" and "${i}"`);e.vertexInputs[n]=i}for(let[n,i]of Object.entries(t.varyings||{})){Yt(n,"varying");let r=pr(n,i),o=e.varyings[n];if(o&&(o.type!==r.type||o.interpolation!==r.interpolation))throw new Error(`ShaderPlugin varying "${n}" has conflicting declarations "${o.type}/${o.interpolation}" and "${r.type}/${r.interpolation}"`);e.varyings[n]=r}for(let n of t.injections||[])gr(n.target),e.injections[n.target]||(e.injections[n.target]=[]),e.injections[n.target].push({injection:n.injection,order:n.order??0})}}function Yt(e,t){if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(e)||e.startsWith("_luma_"))throw new Error(`ShaderPlugin ${t} "${e}" must be a valid non-reserved identifier`)}function pr(e,t){let{primitiveType:n}=Xt.shaderTypeDecoder.getAttributeShaderTypeInfo(t.type),i=n==="i32"||n==="u32",r=t.interpolation||(i?"flat":"smooth");if(i&&r==="smooth")throw new Error(`ShaderPlugin integer varying "${e}" must use flat interpolation`);return{type:t.type,interpolation:r}}function gr(e){if(!ur.test(e))throw new Error(`ShaderPlugin injection target "${e}" must be a named shader anchor or hook`)}var dr=/^(?:uniform\s+)?(?:(?:lowp|mediump|highp)\s+)?[A-Za-z0-9_]+(?:<[^>]+>)?\s+([A-Za-z0-9_]+)(?:\s*\[[^\]]+\])?\s*;/,_r=/((?:layout\s*\([^)]*\)\s*)*)uniform\s+([A-Za-z_][A-Za-z0-9_]*)\s*\{([\s\S]*?)\}\s*([A-Za-z_][A-Za-z0-9_]*)?\s*;/g;function Ae(e){return`${e.name}Uniforms`}function at(e,t){let n=t==="wgsl"?e.source:t==="vertex"?e.vs:e.fs;if(!n)return null;let i=Ae(e);return hr(n,t==="wgsl"?"wgsl":"glsl",i)}function st(e,t){let n=Object.keys(e.uniformTypes||{});if(!n.length)return null;let i=at(e,t);return i?{moduleName:e.name,uniformBlockName:Ae(e),stage:t,expectedUniformNames:n,actualUniformNames:i,matches:br(n,i)}:null}function Ie(e,t,n={}){let i=st(e,t);if(!i||i.matches)return i;let r=xr(i);return n.log?.error?.(r,i)(),n.throwOnError!==!1&&B(!1,r),i}function Ee(e){let t=[],n=Sr(e);for(let i of n.matchAll(_r)){let r=i[1]?.trim()||null;t.push({blockName:i[2],body:i[3],instanceName:i[4]||null,layoutQualifier:r,hasLayoutQualifier:Boolean(r),isStd140:Boolean(r&&/\blayout\s*\([^)]*\bstd140\b[^)]*\)/.exec(r))})}return t}function Re(e,t,n,i){let r=Ee(e).filter(a=>!a.isStd140),o=new Set;for(let a of r){if(o.has(a.blockName))continue;o.add(a.blockName);let s=i?.label?`${i.label} `:"",l=a.hasLayoutQualifier?`declares ${Mr(a.layoutQualifier)} instead of layout(std140)`:"does not declare layout(std140)",c=`${s}${t} shader uniform block ${a.blockName} ${l}. luma.gl host-side shader block packing assumes explicit layout(std140) for GLSL uniform blocks. Add \`layout(std140)\` to the block declaration.`;n?.warn?.(c,a)()}return r}function hr(e,t,n){let i=t==="wgsl"?mr(e,n):vr(e,n);if(!i)return null;let r=[];for(let o of i.split(`
|
|
35
|
+
`)){let a=o.replace(/\/\/.*$/,"").trim();if(!a||a.startsWith("#"))continue;let s=t==="wgsl"?a.match(/^([A-Za-z0-9_]+)\s*:/):a.match(dr);s&&r.push(s[1])}return r}function mr(e,t){let n=new RegExp(`\\bstruct\\s+${t}\\b`,"m").exec(e);if(!n)return null;let i=e.indexOf("{",n.index);if(i<0)return null;let r=0;for(let o=i;o<e.length;o++){let a=e[o];if(a==="{"){r++;continue}if(a==="}"&&(r--,r===0))return e.slice(i+1,o)}return null}function vr(e,t){return Ee(e).find(i=>i.blockName===t)?.body||null}function br(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function xr(e){let{expectedUniformNames:t,actualUniformNames:n}=e,i=t.filter(s=>!n.includes(s)),r=n.filter(s=>!t.includes(s)),o=[`Expected ${t.length} fields, found ${n.length}.`],a=Lr(t,n);return a&&o.push(a),i.length&&o.push(`Missing from shader block (${i.length}): ${Qt(i)}.`),r.length&&o.push(`Unexpected in shader block (${r.length}): ${Qt(r)}.`),t.length<=12&&n.length<=12&&(i.length||r.length)&&(o.push(`Expected: ${t.join(", ")}.`),o.push(`Actual: ${n.join(", ")}.`)),`${e.moduleName}: ${e.stage} shader uniform block ${e.uniformBlockName} does not match module.uniformTypes. ${o.join(" ")}`}function Sr(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"")}function Mr(e){return e.replace(/\s+/g," ").trim()}function Lr(e,t){let n=Math.min(e.length,t.length);for(let i=0;i<n;i++)if(e[i]!==t[i])return`First mismatch at field ${i+1}: expected ${e[i]}, found ${t[i]}.`;return e.length>t.length?`Shader block ends after field ${t.length}; expected next field ${e[t.length]}.`:t.length>e.length?`Shader block has extra field ${t.length}: ${t[e.length]}.`:null}function Qt(e,t=8){if(e.length<=t)return e.join(", ");let n=e.length-t;return`${e.slice(0,t).join(", ")}, ... (${n} more)`}function en(e){switch(e?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
|
|
35
36
|
// Apple optimizes away the calculation necessary for emulated fp64
|
|
36
37
|
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
37
38
|
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
@@ -55,60 +56,83 @@ ${r[n]}`:r[n]}),t}function F(e){e.map(t=>he(t))}function he(e){if(e.instance)ret
|
|
|
55
56
|
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
56
57
|
// If the GPU doesn't have full 32 bits precision, will causes overflow
|
|
57
58
|
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
|
|
58
|
-
`}}function
|
|
59
|
-
`],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],
|
|
60
|
-
`,o.header&&(
|
|
61
|
-
`}o.footer&&(
|
|
62
|
-
`}return
|
|
63
|
-
`||s==="\r"?
|
|
64
|
-
`&&s!=="\r"&&(t[
|
|
65
|
-
|
|
66
|
-
${
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
`}}function nn(e,t){if(Number(e.match(/^#version[ \t]+(\d+)/m)?.[1]||100)!==300)throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");switch(t){case"vertex":return e=tn(e,Ar),e;case"fragment":return e=tn(e,Ir),e;default:throw new Error(t)}}var rn=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
|
|
60
|
+
`],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],Ar=[...rn,[lt("attribute"),"in $1"],[lt("varying"),"out $1"]],Ir=[...rn,[lt("varying"),"in $1"]];function tn(e,t){for(let[n,i]of t)e=e.replace(n,i);return e}function lt(e){return new RegExp(`\\b${e}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function Ce(e,t,n="glsl"){let i="";for(let r in e){let o=e[r];if(i+=`${n==="wgsl"?"fn":"void"} ${o.signature} {
|
|
61
|
+
`,o.header&&(i+=` ${o.header}`),t[r]){let s=t[r];s.sort((l,c)=>l.order-c.order);for(let l of s)i+=` ${l.injection}
|
|
62
|
+
`}o.footer&&(i+=` ${o.footer}`),i+=`}
|
|
63
|
+
`}return i}function ct(e){let t={vertex:{},fragment:{}};for(let n of e){let i,r;typeof n!="string"?(i=n,r=i.hook):(i={},r=n),r=r.trim();let o=r.indexOf(":"),a=r.slice(0,o),s=r.slice(o+1),l=r.replace(/\(.+/,""),c=Object.assign(i,{signature:s});switch(a){case"vs":t.vertex[l]=c;break;case"fs":t.fragment[l]=c;break;default:throw new Error(a)}}return t}function ye(e,t){return{name:Er(e,t),language:"glsl",version:Rr(e)}}function Er(e,t="unnamed"){let i=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(e);return i?i[1]:t}function Rr(e){let t=100,n=e.match(/[^\s]+/g);if(n&&n.length>=2&&n[0]==="#version"){let i=parseInt(n[1],10);Number.isFinite(i)&&(t=i)}if(t!==100&&t!==300)throw new Error(`Invalid GLSL version ${t}`);return t}var P="(?:var<\\s*(uniform|storage(?:\\s*,\\s*[A-Za-z_][A-Za-z0-9_]*)?)\\s*>|var)\\s+([A-Za-z_][A-Za-z0-9_]*)",O="\\s*",J=[new RegExp(`@binding\\(\\s*(auto|\\d+)\\s*\\)${O}@group\\(\\s*(\\d+)\\s*\\)${O}${P}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)${O}@binding\\(\\s*(auto|\\d+)\\s*\\)${O}${P}`,"g")],we=[new RegExp(`@binding\\(\\s*(auto|\\d+)\\s*\\)${O}@group\\(\\s*(\\d+)\\s*\\)${O}${P}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)${O}@binding\\(\\s*(auto|\\d+)\\s*\\)${O}${P}`,"g")],on=[new RegExp(`@binding\\(\\s*(\\d+)\\s*\\)${O}@group\\(\\s*(\\d+)\\s*\\)${O}${P}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)${O}@binding\\(\\s*(\\d+)\\s*\\)${O}${P}`,"g")],Cr=[new RegExp(`@binding\\(\\s*(auto)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${P}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto)\\s*\\)\\s*${P}`,"g"),new RegExp(`@binding\\(\\s*(auto)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)(?:[\\s\\n\\r]*@[A-Za-z_][^\\n\\r]*)*[\\s\\n\\r]*${P}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto)\\s*\\)(?:[\\s\\n\\r]*@[A-Za-z_][^\\n\\r]*)*[\\s\\n\\r]*${P}`,"g")];function Te(e){let t=e.split(""),n=0,i=0,r=!1,o=!1,a=!1;for(;n<e.length;){let s=e[n],l=e[n+1];if(o){a?a=!1:s==="\\"?a=!0:s==='"'&&(o=!1),n++;continue}if(r){s===`
|
|
64
|
+
`||s==="\r"?r=!1:t[n]=" ",n++;continue}if(i>0){if(s==="/"&&l==="*"){t[n]=" ",t[n+1]=" ",i++,n+=2;continue}if(s==="*"&&l==="/"){t[n]=" ",t[n+1]=" ",i--,n+=2;continue}s!==`
|
|
65
|
+
`&&s!=="\r"&&(t[n]=" "),n++;continue}if(s==='"'){o=!0,n++;continue}if(s==="/"&&l==="/"){t[n]=" ",t[n+1]=" ",r=!0,n+=2;continue}if(s==="/"&&l==="*"){t[n]=" ",t[n+1]=" ",i=1,n+=2;continue}n++}return t.join("")}function j(e,t){let n=Te(e),i=[];for(let r of t){r.lastIndex=0;let o;for(o=r.exec(n);o;){let a=r===t[0],s=o.index,l=o[0].length;i.push({match:e.slice(s,s+l),index:s,length:l,bindingToken:o[a?1:2],groupToken:o[a?2:1],accessDeclaration:o[3]?.trim(),name:o[4]}),o=r.exec(n)}}return i.sort((r,o)=>r.index-o.index)}function ft(e,t,n){let i=j(e,t);if(!i.length)return e;let r="",o=0;for(let a of i)r+=e.slice(o,a.index),r+=n(a),o=a.index+a.length;return r+=e.slice(o),r}function ut(e){return/@binding\(\s*auto\s*\)/.test(Te(e))}function an(e,t){return j(e,t===J||t===we?Cr:t).find(i=>i.bindingToken==="auto")}var sn=[new RegExp(`@binding\\(\\s*(\\d+)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${P}\\s*:\\s*([^;]+);`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(\\d+)\\s*\\)\\s*${P}\\s*:\\s*([^;]+);`,"g")];function Ne(e,t=[]){let n=Te(e),i=new Map;for(let o of t)i.set(ln(o.name,o.group,o.location),o.moduleName);let r=[];for(let o of sn){o.lastIndex=0;let a;for(a=o.exec(n);a;){let s=o===sn[0],l=Number(a[s?1:2]),c=Number(a[s?2:1]),f=a[3]?.trim(),u=a[4],p=a[5].trim(),g=i.get(ln(u,c,l));r.push(yr({name:u,group:c,binding:l,owner:g?"module":"application",moduleName:g,accessDeclaration:f,resourceType:p})),a=o.exec(n)}}return r.sort((o,a)=>o.group!==a.group?o.group-a.group:o.binding!==a.binding?o.binding-a.binding:o.name.localeCompare(a.name))}function yr(e){let t={name:e.name,group:e.group,binding:e.binding,owner:e.owner,kind:"unknown",moduleName:e.moduleName,resourceType:e.resourceType};if(e.accessDeclaration){let n=e.accessDeclaration.split(",").map(i=>i.trim());if(n[0]==="uniform")return{...t,kind:"uniform",access:"uniform"};if(n[0]==="storage"){let i=n[1]||"read_write";return{...t,kind:i==="read"?"read-only-storage":"storage",access:i}}}return e.resourceType==="sampler"||e.resourceType==="sampler_comparison"?{...t,kind:"sampler",samplerKind:e.resourceType==="sampler_comparison"?"comparison":"filtering"}:e.resourceType.startsWith("texture_storage_")?{...t,kind:"storage-texture",access:Tr(e.resourceType),viewDimension:cn(e.resourceType)}:e.resourceType.startsWith("texture_")?{...t,kind:"texture",viewDimension:cn(e.resourceType),sampleType:wr(e.resourceType),multisampled:e.resourceType.startsWith("texture_multisampled_")}:t}function ln(e,t,n){return`${t}:${n}:${e}`}function cn(e){if(e.includes("cube_array"))return"cube-array";if(e.includes("2d_array"))return"2d-array";if(e.includes("cube"))return"cube";if(e.includes("3d"))return"3d";if(e.includes("2d"))return"2d";if(e.includes("1d"))return"1d"}function wr(e){if(e.startsWith("texture_depth_"))return"depth";if(e.includes("<i32>"))return"sint";if(e.includes("<u32>"))return"uint";if(e.includes("<f32>"))return"float"}function Tr(e){return/,\s*([A-Za-z_][A-Za-z0-9_]*)\s*>$/.exec(e)?.[1]}var q="([a-zA-Z_][a-zA-Z0-9_]*)",Nr=/^\s*\#\s*if\s+(.+?)\s*(?:\/\/.*)?$/,Pr=new RegExp(`^\\s*\\#\\s*ifdef\\s*${q}\\s*$`),Or=new RegExp(`^\\s*\\#\\s*ifndef\\s*${q}\\s*(?:\\/\\/.*)?$`),Ur=/^\s*\#\s*else\s*(?:\/\/.*)?$/,Br=/^\s*\#\s*endif\s*$/,Dr=new RegExp(`^\\s*\\#\\s*ifdef\\s*${q}\\s*(?:\\/\\/.*)?$`),Fr=/^\s*\#\s*endif\s*(?:\/\/.*)?$/;function z(e,t){let n=e.split(`
|
|
66
|
+
`),i=[],r=[],o=!0;for(let a of n){let s=a.match(Nr),l=a.match(Dr)||a.match(Pr),c=a.match(Or),f=a.match(Ur),u=a.match(Fr)||a.match(Br);if(s){let p=Gr(s[1],t?.defines||{}),g=o&&p;r.push({parentActive:o,branchTaken:p,active:g}),o=g}else if(l||c){let p=(l||c)?.[1],g=Boolean(t?.defines?.[p]),_=l?g:!g,m=o&&_;r.push({parentActive:o,branchTaken:_,active:m}),o=m}else if(f){let p=r[r.length-1];if(!p)throw new Error("Encountered #else without matching #if, #ifdef or #ifndef");p.active=p.parentActive&&!p.branchTaken,p.branchTaken=!0,o=p.active}else u?(r.pop(),o=r.length?r[r.length-1].active:!0):o&&i.push(a)}if(r.length>0)throw new Error("Unterminated conditional block in shader source");return i.join(`
|
|
67
|
+
`)}function Gr(e,t){let n=e.trim();if(/^[+-]?\d+(?:\.\d+)?$/.test(n))return Number(n)!==0;if(n==="true")return!0;if(n==="false")return!1;let i=n.match(new RegExp(`^!\\s*${q}$`));if(i)return!Boolean(t[i[1]]);let r=n.match(new RegExp(`^${q}$`));if(r)return Boolean(t[r[1]]);let o=n.match(new RegExp(`^defined\\s*\\(\\s*${q}\\s*\\)$`));if(o)return t[o[1]]!==void 0;let a=n.match(new RegExp(`^!\\s*defined\\s*\\(\\s*${q}\\s*\\)$`));if(a)return t[a[1]]===void 0;throw new Error(`Unsupported #if expression "${e}"`)}var pn=se(Z(),1);function gn(e,t){let n=[];for(let[i,r]of Object.entries(t))Vr(e,i),n.push(`in ${Pe(r)} ${i};`);return n.join(`
|
|
68
|
+
`)}function dn(e,t,n){let i=Object.entries(n);if(i.length===0)return{source:e,declarations:"",initialization:""};let r=kr(e,t),o=e.slice(r.openParenthesis+1,r.closeParenthesis),a=zr(e,o),s=new Set(a.locations),l=[],c=[],f=[];for(let[m,b]of i){if(a.names.has(m)||jr(e,m))throw new Error(`ShaderPlugin vertex input "${m}" conflicts with an existing WGSL shader input or variable`);let x=qr(s);s.add(x);let M=`_luma_${m}`;l.push(`@location(${x}) ${M}: ${b}`),c.push(`var<private> ${m}: ${b};`),f.push(`${m} = ${M};`)}let u=o.trim()?`,
|
|
69
|
+
`:`
|
|
70
|
+
`,p=o.trim()?"":`
|
|
71
|
+
`,g=`${o}${u}${l.join(`,
|
|
72
|
+
`)}${p}`;return{source:e.slice(0,r.openParenthesis+1)+g+e.slice(r.closeParenthesis),declarations:c.join(`
|
|
73
|
+
`),initialization:f.join(`
|
|
74
|
+
`)}}function Pe(e){let{primitiveType:t,components:n}=pn.shaderTypeDecoder.getAttributeShaderTypeInfo(e),i=t==="i32"?"int":t==="u32"?"uint":"float";return n===1?i:`${i==="int"?"i":i==="uint"?"u":""}vec${n}`}function Vr(e,t){let n=Oe(t);if(new RegExp(`\\b(?:in|attribute)\\s+(?:(?:lowp|mediump|highp)\\s+)?[A-Za-z_][A-Za-z0-9_]*\\s+${n}\\s*(?:\\[|;)`).test(e))throw new Error(`ShaderPlugin vertex input "${t}" conflicts with an existing GLSL input`)}function kr(e,t){let i=new RegExp(`\\bfn\\s+${Oe(t)}\\s*\\(`,"g").exec(e);if(!i)throw new Error(`ShaderPlugin vertex inputs require WGSL vertex entry point "${t}"`);let r=e.indexOf("(",i.index),o=_n(e,r,"(",")");if(o<0)throw new Error(`Unable to parse WGSL vertex entry point "${t}" parameters`);return{openParenthesis:r,closeParenthesis:o}}function zr(e,t){let n=fn(t),i=new Set(un(t)),r=Hr(t);for(let o of r){let a=$r(e,o);if(a!==null){n.push(...fn(a));for(let s of un(a))i.add(s)}}return{locations:n,names:i}}function fn(e){let t=[],n=/@location\s*\(\s*(\d+)\s*\)/g,i=n.exec(e);for(;i;)t.push(Number(i[1])),i=n.exec(e);return t}function un(e){let t=[],n=/(?:^|,)\s*(?:@[A-Za-z_][\w]*(?:\([^)]*\))?\s*)*([A-Za-z_][\w]*)\s*:/gm,i=n.exec(e);for(;i;)t.push(i[1]),i=n.exec(e);return t}function Hr(e){let t=[],n=/:\s*([A-Za-z_][\w]*)\b/g,i=n.exec(e);for(;i;)t.push(i[1]),i=n.exec(e);return t}function $r(e,t){let i=new RegExp(`\\bstruct\\s+${Oe(t)}\\s*\\{`,"g").exec(e);if(!i)return null;let r=e.indexOf("{",i.index),o=_n(e,r,"{","}");return o<0?null:e.slice(r+1,o)}function jr(e,t){let n=Oe(t),i=new RegExp(`\\b(?:var(?:<[^>]+>)?|let|const)\\s+${n}\\b`,"g"),r=i.exec(e);for(;r;){if(Wr(e,r.index)===0)return!0;r=i.exec(e)}return!1}function qr(e){let t=0;for(;e.has(t);)t++;return t}function _n(e,t,n,i){let r=0,o=0,a=!1;for(let s=t;s<e.length;s++){let l=e[s],c=e[s+1];if(a){l===`
|
|
75
|
+
`&&(a=!1);continue}if(o>0){l==="/"&&c==="*"?(o++,s++):l==="*"&&c==="/"&&(o--,s++);continue}if(l==="/"&&c==="/"){a=!0,s++;continue}if(l==="/"&&c==="*"){o=1,s++;continue}if(l===n&&r++,l===i&&--r===0)return s}return-1}function Wr(e,t){let n=0,i=0,r=!1;for(let o=0;o<t;o++){let a=e[o],s=e[o+1];if(r){a===`
|
|
76
|
+
`&&(r=!1);continue}if(i>0){a==="/"&&s==="*"?(i++,o++):a==="*"&&s==="/"&&(i--,o++);continue}a==="/"&&s==="/"?(r=!0,o++):a==="/"&&s==="*"?(i=1,o++):a==="{"?n++:a==="}"&&n--}return n}function Oe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var gt=se(Z(),1);function mn(e,t,n){let i=[],r=[];for(let[o,a]of Object.entries(n)){ao(e,o);let s=a.interpolation==="flat"?"flat ":"",l=t==="vertex"?"out":"in";i.push(`${s}${l} ${Pe(a.type)} ${o};`),t==="vertex"&&r.push(`${o} = ${ro(a.type)};`)}return{declarations:i.join(`
|
|
77
|
+
`),initialization:r.join(`
|
|
78
|
+
`)}}function vn(e,t,n,i){let r=Object.entries(i);if(r.length===0)return{source:e,declarations:"",vertexInitialization:"",fragmentInitialization:""};let o=e,a=Ue(o,t,"vertex"),s=Kr(o,a),l=Ue(o,n,"fragment"),c=Yr(o,l),f=pt(o,s),u=pt(o,c.type),p=new Set([...Be(a.parameters),...Be(f.body),...Be(l.parameters),...Be(u.body)]),g=new Set([...hn(f.body),...hn(u.body)]),_=[],m=[],b=[],x=[];for(let[d,v]of r){if(p.has(d)||no(o,d))throw new Error(`ShaderPlugin varying "${d}" conflicts with existing WGSL stage I/O or a module variable`);let E=io(g);g.add(E);let C=v.interpolation==="flat"?" @interpolate(flat)":"";_.push(` @location(${E})${C} ${d}: ${v.type},`),m.push(`var<private> ${d}: ${v.type};`),b.push(`${d} = ${oo(v.type)};`),x.push(`${d} = ${c.name}.${d};`)}Xr(o,s,a.openBrace,a.closeBrace),o=Zr(o,s,a,r.map(([d])=>d)),a=Ue(o,t,"vertex"),o=Jr(o,a,r.map(([d])=>d));let S=(s===c.type?[s]:[s,c.type]).map(d=>pt(o,d).closeBrace).sort((d,v)=>v-d);for(let d of S)o=o.slice(0,d)+`${_.join(`
|
|
79
|
+
`)}
|
|
80
|
+
`+o.slice(d);if(l=Ue(o,n,"fragment"),!new RegExp(`\\b${W(c.name)}\\s*:`).test(l.parameters))throw new Error(`Unable to preserve WGSL fragment input "${c.name}"`);return{source:o,declarations:m.join(`
|
|
81
|
+
`),vertexInitialization:b.join(`
|
|
82
|
+
`),fragmentInitialization:x.join(`
|
|
83
|
+
`)}}function Ue(e,t,n){let r=new RegExp(`\\bfn\\s+${W(t)}\\s*\\(`,"g").exec(e);if(!r)throw new Error(`ShaderPlugin varyings require WGSL ${n} entry point "${t}"`);let o=e.indexOf("(",r.index),a=De(e,o,"(",")"),s=e.indexOf("{",a),l=De(e,s,"{","}");if(a<0||s<0||l<0)throw new Error(`Unable to parse WGSL ${n} entry point "${t}"`);return{openParenthesis:o,closeParenthesis:a,openBrace:s,closeBrace:l,parameters:e.slice(o+1,a)}}function Kr(e,t){let n=e.slice(t.closeParenthesis+1,t.openBrace),i=/->\s*([A-Za-z_][\w]*)\s*$/.exec(n.trim());if(!i||dt(e,i[1])===null)throw new Error("ShaderPlugin varyings require the WGSL vertex entry point to return a named struct");return i[1]}function Yr(e,t){let n=[];for(let i of to(t.parameters,",")){let r=/(?:@[A-Za-z_][\w]*(?:\([^)]*\))?\s*)*([A-Za-z_][\w]*)\s*:\s*([A-Za-z_][\w]*)\s*$/.exec(i.trim());r&&dt(e,r[2])&&n.push({name:r[1],type:r[2]})}if(n.length!==1)throw new Error(`ShaderPlugin varyings require exactly one named WGSL fragment input struct; found ${n.length}`);return n[0]}function pt(e,t){let n=dt(e,t);if(!n)throw new Error(`Unable to find WGSL stage I/O struct "${t}"`);return n}function dt(e,t){let i=new RegExp(`\\bstruct\\s+${W(t)}\\s*\\{`,"g").exec(e);if(!i)return null;let r=e.indexOf("{",i.index),o=De(e,r,"{","}");return o<0?null:{openBrace:r,closeBrace:o,body:e.slice(r+1,o)}}function Xr(e,t,n,i){let r=new RegExp(`\\b${W(t)}\\s*\\(`,"g"),o=r.exec(e);for(;o;){if(o.index<n||o.index>i)throw new Error(`ShaderPlugin varying output struct "${t}" is constructed outside the selected vertex entry point`);o=r.exec(e)}}function Zr(e,t,n,i){let r=new RegExp(`\\b${W(t)}\\s*\\(`,"g"),o=[],a=r.exec(e);for(;a;){if(a.index>n.openBrace&&a.index<n.closeBrace){let s=e.indexOf("(",a.index),l=De(e,s,"(",")");if(l<0||l>n.closeBrace)throw new Error(`Unable to parse WGSL output constructor "${t}"`);o.push({openParenthesis:s,closeParenthesis:l})}a=r.exec(e)}for(let s of o.sort((l,c)=>c.closeParenthesis-l.closeParenthesis)){let c=e.slice(s.openParenthesis+1,s.closeParenthesis).trim()?", ":"";e=e.slice(0,s.closeParenthesis)+c+i.join(", ")+e.slice(s.closeParenthesis)}return e}function Jr(e,t,n){let i=Qr(e,t.openBrace+1,t.closeBrace);for(let r=i.length-1;r>=0;r--){let o=i[r],a=e.slice(o.expressionStart,o.semicolon).trim();if(!a)throw new Error("ShaderPlugin varying vertex entry point cannot use an empty return");let s=`_luma_vertexOutput${r}`,l=n.map(f=>`${s}.${f} = ${f};`).join(`
|
|
84
|
+
`),c=`{
|
|
85
|
+
var ${s} = ${a};
|
|
86
|
+
${l}
|
|
87
|
+
return ${s};
|
|
88
|
+
}`;e=e.slice(0,o.start)+c+e.slice(o.semicolon+1)}return e}function Qr(e,t,n){let i=[],r=t;for(;r<n;)if(r=_t(e,r,n),e.slice(r,r+6)==="return"&&!/[A-Za-z0-9_]/.test(e[r+6]||"")){let o=r+6,a=eo(e,o,n);if(a<0)throw new Error("Unable to parse WGSL return statement in selected vertex entry point");i.push({start:r,expressionStart:o,semicolon:a}),r=a+1}else r++;return i}function eo(e,t,n){let i=0,r=0;for(let o=t;o<n;o++){let a=_t(e,o,n);if(a!==o){o=a-1;continue}let s=e[o];if(s==="("&&i++,s===")"&&i--,s==="["&&r++,s==="]"&&r--,s===";"&&i===0&&r===0)return o}return-1}function _t(e,t,n){let i=t;if(e[i]==="/"&&e[i+1]==="/"){let r=e.indexOf(`
|
|
89
|
+
`,i+2);return r<0||r>n?n:r+1}if(e[i]==="/"&&e[i+1]==="*"){let r=1;for(i+=2;i<n&&r>0;)e[i]==="/"&&e[i+1]==="*"?(r++,i+=2):e[i]==="*"&&e[i+1]==="/"?(r--,i+=2):i++}return i}function to(e,t){let n=[],i=0,r=0,o=0;for(let a=0;a<e.length;a++){let s=e[a];s==="("&&r++,s===")"&&r--,s==="<"&&o++,s===">"&&o--,s===t&&r===0&&o===0&&(n.push(e.slice(i,a)),i=a+1)}return n.push(e.slice(i)),n}function hn(e){let t=[],n=/@location\s*\(\s*(\d+)\s*\)/g,i=n.exec(e);for(;i;)t.push(Number(i[1])),i=n.exec(e);return t}function Be(e){let t=[],n=/(?:^|,)\s*(?:@[A-Za-z_][\w]*(?:\([^)]*\))?\s*)*([A-Za-z_][\w]*)\s*:/gm,i=n.exec(e);for(;i;)t.push(i[1]),i=n.exec(e);return t}function no(e,t){let n=new RegExp(`\\b(?:var(?:<[^>]+>)?|let|const)\\s+${W(t)}\\b`,"g"),i=n.exec(e);for(;i;){if(so(e,i.index)===0)return!0;i=n.exec(e)}return!1}function io(e){let t=0;for(;e.has(t);)t++;return t}function ro(e){let{primitiveType:t,components:n}=gt.shaderTypeDecoder.getAttributeShaderTypeInfo(e),i=t==="u32"?"0u":t==="i32"?"0":"0.0";return n===1?i:`${Pe(e)}(${i})`}function oo(e){let{primitiveType:t,components:n}=gt.shaderTypeDecoder.getAttributeShaderTypeInfo(e),i=`${t}(0)`;return n===1?i:`${e}(${i})`}function ao(e,t){if(new RegExp(`\\b(?:flat\\s+|smooth\\s+)?(?:in|out|varying)\\s+(?:(?:lowp|mediump|highp)\\s+)?[A-Za-z_][A-Za-z0-9_]*\\s+${W(t)}\\s*(?:\\[|;)`).test(e))throw new Error(`ShaderPlugin varying "${t}" conflicts with existing GLSL stage I/O`)}function De(e,t,n,i){let r=0,o=0,a=!1;for(let s=t;s<e.length;s++){let l=e[s],c=e[s+1];if(a){l===`
|
|
90
|
+
`&&(a=!1);continue}if(o>0){l==="/"&&c==="*"?(o++,s++):l==="*"&&c==="/"&&(o--,s++);continue}if(l==="/"&&c==="/"){a=!0,s++;continue}if(l==="/"&&c==="*"){o=1,s++;continue}if(l===n&&r++,l===i&&--r===0)return s}return-1}function so(e,t){let n=0;for(let i=0;i<t;i++){let r=_t(e,i,t);if(r!==i){i=r-1;continue}e[i]==="{"&&n++,e[i]==="}"&&n--}return n}function W(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}var ht=`
|
|
91
|
+
|
|
92
|
+
${le}
|
|
93
|
+
`,ge=100,lo=`precision highp float;
|
|
94
|
+
`;function Mn(e){let t=ue(e.modules||[]),{source:n,bindingAssignments:i}=co(e.platformInfo,{...e,source:e.source,stage:"vertex",modules:t});return{source:n,getUniforms:Ln(t),bindingAssignments:i,bindingTable:Ne(n,i)}}function Fe(e){let{vs:t,fs:n}=e,i=ue(e.modules||[]);return{vs:bn(e.platformInfo,{...e,source:t,stage:"vertex",modules:i}),fs:bn(e.platformInfo,{...e,source:n,stage:"fragment",modules:i}),getUniforms:Ln(i)}}function co(e,t){let{source:n,stage:i,modules:r,defines:o={},hookFunctions:a=[],inject:s={},pluginInjections:l={},pluginVertexInputs:c={},pluginVaryings:f={},vertexEntryPoint:u="vertexMain",fragmentEntryPoint:p="fragmentMain",log:g}=t;B(typeof n=="string","shader source must be a string");let _=z(n,{defines:o}),m=dn(_,u,c),b=vn(m.source,u,p,f),x=b.source,M="",S=ct(a),h={},d={},v={};An(l,h,d,v);for(let I in s){let R=typeof s[I]=="string"?{injection:s[I],order:0}:s[I],A=/^(v|f)s:(#)?([\w-]+)$/.exec(I);if(A){let F=A[2],V=A[3];F?V==="decl"?d[I]=[R]:v[I]=[R]:h[I]=[R]}else v[I]=[R]}fo(m.declarations,m.initialization,d,v),uo(b,d,v);let E=r,C=vo(x),w=mo(C.source),L=Mo(E,t._bindingRegistry,w,o),y=[];for(let I of E){g&&fe(I,x,g);let R=z(Ge(I,"wgsl",g),{defines:o}),A=bo(R,I,{usedBindingsByGroup:w,bindingRegistry:t._bindingRegistry,reservedBindingKeysByGroup:L});y.push(...A.bindingAssignments);let F=A.source;M+=F;let V=po(I);for(let k in V){let Ot=/^(v|f)s:#([\w-]+)$/.exec(k);if(Ot){let it=Ot[2]==="decl"?d:v;it[k]=it[k]||[],it[k].push(V[k])}else h[k]=h[k]||[],h[k].push(V[k])}}return M+=ht,M=ce(M,i,go(d),!1,"wgsl",{vertex:u,fragment:p}),M+=_o(S,h),M+=Ro(y),M+=C.source,M=ce(M,i,v,!1,"wgsl",{vertex:u,fragment:p}),Eo(M),{source:M,bindingAssignments:y}}function bn(e,t){let{source:n,stage:i,language:r="glsl",modules:o,defines:a={},hookFunctions:s=[],inject:l={},pluginInjections:c={},pluginVertexInputs:f={},pluginVaryings:u={},prologue:p=!0,log:g}=t;B(typeof n=="string","shader source must be a string");let _=r==="glsl"?ye(n).version:-1,m=e.shaderLanguageVersion,b=_===100?"#version 100":"#version 300 es",M=n.split(`
|
|
69
95
|
`).slice(1).join(`
|
|
70
|
-
`),
|
|
96
|
+
`),S={};o.forEach(L=>{Object.assign(S,L.defines)}),Object.assign(S,a);let h="";switch(r){case"wgsl":break;case"glsl":h=p?`${b}
|
|
71
97
|
|
|
72
98
|
// ----- PROLOGUE -------------------------
|
|
73
|
-
${`#define SHADER_TYPE_${
|
|
99
|
+
${`#define SHADER_TYPE_${i.toUpperCase()}`}
|
|
74
100
|
|
|
75
|
-
${
|
|
76
|
-
${
|
|
101
|
+
${en(e)}
|
|
102
|
+
${i==="fragment"?lo:""}
|
|
77
103
|
|
|
78
104
|
// ----- APPLICATION DEFINES -------------------------
|
|
79
105
|
|
|
80
|
-
${
|
|
106
|
+
${ho(S)}
|
|
81
107
|
|
|
82
|
-
`:`${
|
|
83
|
-
`;break}let
|
|
84
|
-
`)}return t}function
|
|
108
|
+
`:`${b}
|
|
109
|
+
`;break}let d=ct(s),v={},E={},C={};An(c,v,E,C);for(let L in l){let y=typeof l[L]=="string"?{injection:l[L],order:0}:l[L],I=/^(v|f)s:(#)?([\w-]+)$/.exec(L);if(I){let R=I[2],A=I[3];R?A==="decl"?E[L]=[y]:C[L]=[y]:v[L]=[y]}else C[L]=[y]}if(i==="vertex"){let L=gn(M,f);L&&(E["vs:#decl"]=E["vs:#decl"]||[],E["vs:#decl"].push({injection:L,order:Number.MIN_SAFE_INTEGER}))}let w=mn(M,i,u);if(w.declarations){let L=i==="vertex"?"vs:#decl":"fs:#decl";E[L]=E[L]||[],E[L].push({injection:w.declarations,order:Number.MIN_SAFE_INTEGER})}w.initialization&&(C["vs:#main-start"]=C["vs:#main-start"]||[],C["vs:#main-start"].push({injection:w.initialization,order:Number.MIN_SAFE_INTEGER}));for(let L of o){g&&fe(L,M,g);let y=Ge(L,i,g);h+=y;let I=L.instance?.normalizedInjections[i]||{};for(let R in I){let A=/^(v|f)s:#([\w-]+)$/.exec(R);if(A){let V=A[2]==="decl"?E:C;V[R]=V[R]||[],V[R].push(I[R])}else v[R]=v[R]||[],v[R].push(I[R])}}return h+="// ----- MAIN SHADER SOURCE -------------------------",h+=ht,h=ce(h,i,E),h+=Ce(d[i],v),h+=M,h=ce(h,i,C),r==="glsl"&&_!==m&&(h=nn(h,i)),r==="glsl"&&Re(h,i,g),h.trim()}function Ln(e){return function(n){let i={};for(let r of e){let o=r.getUniforms?.(n,i);Object.assign(i,o)}return i}}function An(e,t,n,i){for(let r in e){let o=/^(v|f)s:(#)?([\w-]+)$/.exec(r);if(o){let a=o[2],s=o[3],l=a?s==="decl"?n:i:t;l[r]=l[r]||[],l[r].push(...e[r])}else i[r]=i[r]||[],i[r].push(...e[r])}}function fo(e,t,n,i){e&&(n["vs:#decl"]=n["vs:#decl"]||[],n["vs:#decl"].push({injection:e,order:Number.MIN_SAFE_INTEGER})),t&&(i["vs:#main-start"]=i["vs:#main-start"]||[],i["vs:#main-start"].push({injection:t,order:Number.MIN_SAFE_INTEGER}))}function uo(e,t,n){e.declarations&&(t["vs:#decl"]=t["vs:#decl"]||[],t["vs:#decl"].push({injection:e.declarations,order:Number.MIN_SAFE_INTEGER})),e.vertexInitialization&&(n["vs:#main-start"]=n["vs:#main-start"]||[],n["vs:#main-start"].push({injection:e.vertexInitialization,order:Number.MIN_SAFE_INTEGER})),e.fragmentInitialization&&(n["fs:#main-start"]=n["fs:#main-start"]||[],n["fs:#main-start"].push({injection:e.fragmentInitialization,order:Number.MIN_SAFE_INTEGER}))}function po(e){return{...e.instance?.normalizedInjections.vertex||{},...e.instance?.normalizedInjections.fragment||{}}}function go(e){let t=[...e["vs:#decl"]||[],...e["fs:#decl"]||[]];return t.length?{"vs:#decl":t}:{}}function _o(e,t){return Ce(e.vertex,t,"wgsl")+Ce(e.fragment,t,"wgsl")}function ho(e={}){let t="";for(let n in e){let i=e[n];(i||Number.isFinite(i))&&(t+=`#define ${n.toUpperCase()} ${e[n]}
|
|
110
|
+
`)}return t}function Ge(e,t,n){let i;switch(t){case"vertex":i=e.vs||"";break;case"fragment":i=e.fs||"";break;case"wgsl":i=e.source||"";break;default:B(!1)}if(!e.name)throw new Error("Shader module must have a name");Ie(e,t,{log:n});let r=e.name.toUpperCase().replace(/[^0-9a-z]/gi,"_"),o=`// ----- MODULE ${e.name} ---------------
|
|
85
111
|
|
|
86
|
-
`;return t!=="wgsl"&&(
|
|
87
|
-
`),
|
|
88
|
-
`,
|
|
89
|
-
`;for(let
|
|
112
|
+
`;return t!=="wgsl"&&(o+=`#define MODULE_${r}
|
|
113
|
+
`),o+=`${i}
|
|
114
|
+
`,o}function mo(e){let t=new Map;for(let n of j(e,on)){let i=Number(n.bindingToken),r=Number(n.groupToken);mt(r,i,n.name),Q(t,r,i,`application binding "${n.name}"`)}return t}function vo(e){let t=j(e,we),n=new Map;for(let o of t){if(o.bindingToken==="auto")continue;let a=Number(o.bindingToken),s=Number(o.groupToken);mt(s,a,o.name),Q(n,s,a,`application binding "${o.name}"`)}let i={sawSupportedBindingDeclaration:t.length>0},r=ft(e,we,o=>So(o,n,i));if(ut(e)&&!i.sawSupportedBindingDeclaration)throw new Error('Unsupported @binding(auto) declaration form in application WGSL. Use adjacent "@group(N)" and "@binding(auto)" decorators followed by a bindable "var" declaration.');return{source:r}}function bo(e,t,n){let i=[],o={sawSupportedBindingDeclaration:j(e,J).length>0,nextHintedBindingLocation:typeof t.firstBindingSlot=="number"?t.firstBindingSlot:null},a=ft(e,J,s=>xo(s,{module:t,context:n,bindingAssignments:i,relocationState:o}));if(ut(e)&&!o.sawSupportedBindingDeclaration)throw new Error(`Unsupported @binding(auto) declaration form in module "${t.name}". Use adjacent "@group(N)" and "@binding(auto)" decorators followed by a bindable "var" declaration.`);return{source:a,bindingAssignments:i}}function xo(e,t){let{module:n,context:i,bindingAssignments:r,relocationState:o}=t,{match:a,bindingToken:s,groupToken:l,name:c}=e,f=Number(l);if(s==="auto"){let p=In(f,n.name,c),g=i.bindingRegistry?.get(p),_=g!==void 0?g:o.nextHintedBindingLocation===null?Sn(f,i.usedBindingsByGroup):Sn(f,i.usedBindingsByGroup,o.nextHintedBindingLocation);return xn(n.name,f,_,c),g!==void 0&&Lo(i.reservedBindingKeysByGroup,f,_,p)?(r.push({moduleName:n.name,name:c,group:f,location:_}),a.replace(/@binding\(\s*auto\s*\)/,`@binding(${_})`)):(Q(i.usedBindingsByGroup,f,_,`module "${n.name}" binding "${c}"`),i.bindingRegistry?.set(p,_),r.push({moduleName:n.name,name:c,group:f,location:_}),o.nextHintedBindingLocation!==null&&g===void 0&&(o.nextHintedBindingLocation=_+1),a.replace(/@binding\(\s*auto\s*\)/,`@binding(${_})`))}let u=Number(s);return xn(n.name,f,u,c),Q(i.usedBindingsByGroup,f,u,`module "${n.name}" binding "${c}"`),r.push({moduleName:n.name,name:c,group:f,location:u}),a}function So(e,t,n){let{match:i,bindingToken:r,groupToken:o,name:a}=e,s=Number(o);if(r==="auto"){let l=Io(s,t);return mt(s,l,a),Q(t,s,l,`application binding "${a}"`),i.replace(/@binding\(\s*auto\s*\)/,`@binding(${l})`)}return n.sawSupportedBindingDeclaration=!0,i}function Mo(e,t,n,i){let r=new Map;if(!t)return r;for(let o of e)for(let a of Ao(o,i)){let s=In(a.group,o.name,a.name),l=t.get(s);if(l!==void 0){let c=r.get(a.group)||new Map,f=c.get(l);if(f&&f!==s)throw new Error(`Duplicate WGSL binding reservation for modules "${f}" and "${s}": group ${a.group}, binding ${l}.`);Q(n,a.group,l,`registered module binding "${s}"`),c.set(l,s),r.set(a.group,c)}}return r}function Lo(e,t,n,i){let r=e.get(t);if(!r)return!1;let o=r.get(n);if(!o)return!1;if(o!==i)throw new Error(`Registered module binding "${i}" collided with "${o}": group ${t}, binding ${n}.`);return!0}function Ao(e,t){let n=[],i=z(e.source||"",{defines:t});for(let r of j(i,J))n.push({name:r.name,group:Number(r.groupToken)});return n}function mt(e,t,n){if(e===0&&t>=ge)throw new Error(`Application binding "${n}" in group 0 uses reserved binding ${t}. Application-owned explicit group-0 bindings must stay below ${ge}.`)}function xn(e,t,n,i){if(t===0&&n<ge)throw new Error(`Module "${e}" binding "${i}" in group 0 uses reserved application binding ${n}. Module-owned explicit group-0 bindings must be ${ge} or higher.`)}function Q(e,t,n,i){let r=e.get(t)||new Set;if(r.has(n))throw new Error(`Duplicate WGSL binding assignment for ${i}: group ${t}, binding ${n}.`);r.add(n),e.set(t,r)}function Sn(e,t,n){let i=t.get(e)||new Set,r=n??(e===0?ge:i.size>0?Math.max(...i)+1:0);for(;i.has(r);)r++;return r}function Io(e,t){let n=t.get(e)||new Set,i=0;for(;n.has(i);)i++;return i}function Eo(e){let t=an(e,J);if(!t)return;let n=Co(e,t.index);throw n?new Error(`Unresolved @binding(auto) for module "${n}" binding "${t.name}" remained in assembled WGSL source.`):yo(e,t.index)?new Error(`Unresolved @binding(auto) for application binding "${t.name}" remained in assembled WGSL source.`):new Error(`Unresolved @binding(auto) remained in assembled WGSL source near "${wo(t.match)}".`)}function Ro(e){if(e.length===0)return"";let t=`// ----- MODULE WGSL BINDING ASSIGNMENTS ---------------
|
|
115
|
+
`;for(let n of e)t+=`// ${n.moduleName}.${n.name} -> @group(${n.group}) @binding(${n.location})
|
|
90
116
|
`;return t+=`
|
|
91
|
-
`,t}function
|
|
92
|
-
`),n=[],o=[],i=!0;for(let a of r){let s=a.match(Kn)||a.match($n),l=a.match(Wn),c=a.match(jn),f=a.match(Yn)||a.match(qn);if(s||l){let p=(s||l)?.[1],u=Boolean(t?.defines?.[p]),h=s?u:!u,g=i&&h;o.push({parentActive:i,branchTaken:h,active:g}),i=g}else if(c){let p=o[o.length-1];if(!p)throw new Error("Encountered #else without matching #ifdef or #ifndef");p.active=p.parentActive&&!p.branchTaken,p.branchTaken=!0,i=p.active}else f?(o.pop(),i=o.length?o[o.length-1].active:!0):i&&n.push(a)}if(o.length>0)throw new Error("Unterminated conditional block in shader source");return n.join(`
|
|
93
|
-
`)}var W=class{_hookFunctions=[];_defaultModules=[];_wgslBindingRegistry=new Map;static getDefaultShaderAssembler(){return W.defaultShaderAssembler=W.defaultShaderAssembler||new W,W.defaultShaderAssembler}addDefaultModule(t){this._defaultModules.find(r=>r.name===(typeof t=="string"?t:t.name))||this._defaultModules.push(t)}removeDefaultModule(t){let r=typeof t=="string"?t:t.name;this._defaultModules=this._defaultModules.filter(n=>n.name!==r)}addShaderHook(t,r){r&&(t=Object.assign(r,{hook:t})),this._hookFunctions.push(t)}assembleWGSLShader(t){let r=this._getModuleList(t.modules),n=this._hookFunctions,{source:o,getUniforms:i,bindingAssignments:a}=kt({...t,source:t.source,_bindingRegistry:this._wgslBindingRegistry,modules:r,hookFunctions:n}),s={...r.reduce((c,f)=>(Object.assign(c,f.defines),c),{}),...t.defines},l=t.platformInfo.shaderLanguage==="wgsl"?Ae(o,{defines:s}):o;return{source:l,getUniforms:i,modules:r,bindingAssignments:a,bindingTable:xe(l,a)}}assembleGLSLShaderPair(t){let r=this._getModuleList(t.modules),n=this._hookFunctions;return{...Me({...t,vs:t.vs,fs:t.fs,modules:r,hookFunctions:n}),modules:r}}_getModuleList(t=[]){let r=new Array(this._defaultModules.length+t.length),n={},o=0;for(let i=0,a=this._defaultModules.length;i<a;++i){let s=this._defaultModules[i],l=s.name;r[o++]=s,n[l]=!0}for(let i=0,a=t.length;i<a;++i){let s=t[i],l=s.name;n[l]||(r[o++]=s,n[l]=!0)}return r.length=o,F(r),r}},ie=W;ht(ie,"defaultShaderAssembler");var Xn=`out vec4 transform_output;
|
|
117
|
+
`,t}function In(e,t,n){return`${e}:${t}:${n}`}function Co(e,t){let n=/^\/\/ ----- MODULE ([^\n]+) ---------------$/gm,i,r;for(r=n.exec(e);r&&r.index<=t;)i=r[1],r=n.exec(e);return i}function yo(e,t){let n=e.indexOf(ht);return n>=0?t>n:!0}function wo(e){return e.replace(/\s+/g," ").trim()}var ee=class{_hookFunctions=[];_defaultModules=[];_wgslBindingRegistry=new Map;static getDefaultShaderAssembler(){return ee.defaultShaderAssembler=ee.defaultShaderAssembler||new ee,ee.defaultShaderAssembler}addDefaultModule(t){this._defaultModules.find(n=>n.name===(typeof t=="string"?t:t.name))||this._defaultModules.push(t)}removeDefaultModule(t){let n=typeof t=="string"?t:t.name;this._defaultModules=this._defaultModules.filter(i=>i.name!==n)}addShaderHook(t,n){n&&(t=Object.assign(n,{hook:t})),this._hookFunctions.push(t)}assembleWGSLShader(t){let n=this._getModuleList(t.modules),i=this._hookFunctions,r=To(t,n),o=t.platformInfo.shaderLanguage==="wgsl"&&t.source?z(t.source,{defines:r}):t.source,{source:a,getUniforms:s,bindingAssignments:l}=Mn({...t,source:o,defines:r,_bindingRegistry:this._wgslBindingRegistry,modules:n,hookFunctions:i}),c=t.platformInfo.shaderLanguage==="wgsl"?z(a,{defines:r}):a;return{source:c,getUniforms:s,modules:n,bindingAssignments:l,bindingTable:Ne(c,l)}}assembleGLSLShaderPair(t){let n=this._getModuleList(t.modules),i=this._hookFunctions;return{...Fe({...t,vs:t.vs,fs:t.fs,modules:n,hookFunctions:i}),modules:n}}_getModuleList(t=[]){let n=new Array(this._defaultModules.length+t.length),i={},r=0;for(let o=0,a=this._defaultModules.length;o<a;++o){let s=this._defaultModules[o],l=s.name;n[r++]=s,i[l]=!0}for(let o=0,a=t.length;o<a;++o){let s=t[o],l=s.name;i[l]||(n[r++]=s,i[l]=!0)}return n.length=r,G(n),n}},de=ee;Ut(de,"defaultShaderAssembler");function To(e,t){return{...No(e.platformInfo),...t.reduce((n,i)=>(Object.assign(n,i.defines),n),{}),...e.defines}}function No(e){let t=e.limits||{};return{LUMA_SUPPORTS_VERTEX_STORAGE_BUFFERS:e.type==="webgpu"&&(t.maxStorageBuffersInVertexStage||0)>0}}var Po=`out vec4 transform_output;
|
|
94
118
|
void main() {
|
|
95
119
|
transform_output = vec4(0);
|
|
96
|
-
}`,
|
|
97
|
-
${
|
|
98
|
-
in ${
|
|
99
|
-
out vec4 ${
|
|
120
|
+
}`,Oo=`#version 300 es
|
|
121
|
+
${Po}`;function En(e,t){t=Array.isArray(t)?t:[t];let n=e.replace(/^\s+/,"").split(/\s+/),[i,r,o]=n;if(!t.includes(i)||!r||!o)return null;let a=o.split(";")[0];return{qualifier:i,type:r,name:a}}function Rn(e){let{input:t,inputChannels:n,output:i}=e||{};if(!t)return Oo;if(!n)throw new Error("inputChannels");let r=Uo(n),o=vt(t,n);return`#version 300 es
|
|
122
|
+
in ${r} ${t};
|
|
123
|
+
out vec4 ${i};
|
|
100
124
|
void main() {
|
|
101
|
-
${
|
|
102
|
-
}`}function
|
|
103
|
-
`)}function
|
|
104
|
-
`)}function Kt(e,t){switch(t.shaderLanguage){case"glsl":return jt(e,t);case"wgsl":return qt(e,t)}}var $i=1/Math.PI*180,Wi=1/180*Math.PI,ro={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...ro}};var y=globalThis.mathgl.config;function Qe(e,{precision:t=y.precision}={}){return e=no(e),`${parseFloat(e.toPrecision(t))}`}function j(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Je(e,t,r){return io(e,n=>Math.max(t,Math.min(r,n)))}function Re(e,t,r){let n=y.EPSILON;r&&(y.EPSILON=r);try{if(e===t)return!0;if(j(e)&&j(t)){if(e.length!==t.length)return!1;for(let o=0;o<e.length;++o)if(!Re(e[o],t[o]))return!1;return!0}return e&&e.equals?e.equals(t):t&&t.equals?t.equals(e):typeof e=="number"&&typeof t=="number"?Math.abs(e-t)<=y.EPSILON*Math.max(1,Math.abs(e),Math.abs(t)):!1}finally{y.EPSILON=n}}function no(e){return Math.round(e/y.EPSILON)*y.EPSILON}function oo(e){return e.clone?e.clone():new Array(e.length)}function io(e,t,r){if(j(e)){let n=e;r=r||oo(n);for(let o=0;o<r.length&&o<n.length;++o){let i=typeof e=="number"?e:e[o];r[o]=t(i,o,r)}return r}return t(e)}var Ee=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,r=0){for(let n=0;n<this.ELEMENTS;++n)this[n]=t[n+r];return this.check()}toArray(t=[],r=0){for(let n=0;n<this.ELEMENTS;++n)t[r+n]=this[n];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:j(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(y)}formatString(t){let r="";for(let n=0;n<this.ELEMENTS;++n)r+=(n>0?", ":"")+Qe(this[n],t);return`${t.printTypes?this.constructor.name:""}[${r}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let r=0;r<this.ELEMENTS;++r)if(!Re(this[r],t[r]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let r=0;r<this.ELEMENTS;++r)if(this[r]!==t[r])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,r,n){if(n===void 0)return this.lerp(this,t,r);for(let o=0;o<this.ELEMENTS;++o){let i=t[o],a=typeof r=="number"?r:r[o];this[o]=i+n*(a-i)}return this.check()}min(t){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(t[r],this[r]);return this.check()}max(t){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.max(t[r],this[r]);return this.check()}clamp(t,r){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t[n]),r[n]);return this.check()}add(...t){for(let r of t)for(let n=0;n<this.ELEMENTS;++n)this[n]+=r[n];return this.check()}subtract(...t){for(let r of t)for(let n=0;n<this.ELEMENTS;++n)this[n]-=r[n];return this.check()}scale(t){if(typeof t=="number")for(let r=0;r<this.ELEMENTS;++r)this[r]*=t;else for(let r=0;r<this.ELEMENTS&&r<t.length;++r)this[r]*=t[r];return this.check()}multiplyByScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]*=t;return this.check()}check(){if(y.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let r=0;r<this.ELEMENTS;++r)t=t&&Number.isFinite(this[r]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]=t;return this.check()}addScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,r){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t),r);return this.check()}get elements(){return this}};function ao(e,t){if(e.length!==t)return!1;for(let r=0;r<e.length;++r)if(!Number.isFinite(e[r]))return!1;return!0}function Yt(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function Ie(e,t,r=""){if(y.debug&&!ao(e,t))throw new Error(`math.gl: ${r} some fields set to invalid numbers'`);return e}var w=typeof Float32Array<"u"?Float32Array:Array;var Zi=Math.PI/180;function so(){let e=new w(2);return w!=Float32Array&&(e[0]=0,e[1]=0),e}function Qt(e,t,r){let n=t[0],o=t[1];return e[0]=r[0]*n+r[4]*o+r[12],e[1]=r[1]*n+r[5]*o+r[13],e}var Qi=function(){let e=so();return function(t,r,n,o,i,a){let s,l;for(r||(r=2),n||(n=0),o?l=Math.min(o*r+n,t.length):l=t.length,s=n;s<l;s+=r)e[0]=t[s],e[1]=t[s+1],i(e,e,a),t[s]=e[0],t[s+1]=e[1];return t}}();function Jt(e,t,r){let n=t[0],o=t[1],i=r[3]*n+r[7]*o||1;return e[0]=(r[0]*n+r[4]*o)/i,e[1]=(r[1]*n+r[5]*o)/i,e}function er(e,t,r){let n=t[0],o=t[1],i=t[2],a=r[3]*n+r[7]*o+r[11]*i||1;return e[0]=(r[0]*n+r[4]*o+r[8]*i)/a,e[1]=(r[1]*n+r[5]*o+r[9]*i)/a,e[2]=(r[2]*n+r[6]*o+r[10]*i)/a,e}function lo(){let e=new w(3);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function tr(e,t,r){let n=t[0],o=t[1],i=t[2],a=r[3]*n+r[7]*o+r[11]*i+r[15];return a=a||1,e[0]=(r[0]*n+r[4]*o+r[8]*i+r[12])/a,e[1]=(r[1]*n+r[5]*o+r[9]*i+r[13])/a,e[2]=(r[2]*n+r[6]*o+r[10]*i+r[14])/a,e}var ta=function(){let e=lo();return function(t,r,n,o,i,a){let s,l;for(r||(r=3),n||(n=0),o?l=Math.min(o*r+n,t.length):l=t.length,s=n;s<l;s+=r)e[0]=t[s],e[1]=t[s+1],e[2]=t[s+2],i(e,e,a),t[s]=e[0],t[s+1]=e[1],t[s+2]=e[2];return t}}();var Ce=class extends Ee{toString(){let t="[";if(y.printRowMajor){t+="row-major:";for(let r=0;r<this.RANK;++r)for(let n=0;n<this.RANK;++n)t+=` ${this[n*this.RANK+r]}`}else{t+="column-major:";for(let r=0;r<this.ELEMENTS;++r)t+=` ${this[r]}`}return t+="]",t}getElementIndex(t,r){return r*this.RANK+t}getElement(t,r){return this[r*this.RANK+t]}setElement(t,r,n){return this[r*this.RANK+t]=Yt(n),this}getColumn(t,r=new Array(this.RANK).fill(-0)){let n=t*this.RANK;for(let o=0;o<this.RANK;++o)r[o]=this[n+o];return r}setColumn(t,r){let n=t*this.RANK;for(let o=0;o<this.RANK;++o)this[n+o]=r[o];return this}};function co(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function rr(e,t){if(e===t){let r=t[1],n=t[2],o=t[3],i=t[6],a=t[7],s=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=r,e[6]=t[9],e[7]=t[13],e[8]=n,e[9]=i,e[11]=t[14],e[12]=o,e[13]=a,e[14]=s}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e}function nr(e,t){let r=t[0],n=t[1],o=t[2],i=t[3],a=t[4],s=t[5],l=t[6],c=t[7],f=t[8],p=t[9],u=t[10],h=t[11],g=t[12],S=t[13],x=t[14],_=t[15],L=r*s-n*a,d=r*l-o*a,b=r*c-i*a,v=n*l-o*s,m=n*c-i*s,M=o*c-i*l,E=f*S-p*g,A=f*x-u*g,I=f*_-h*g,P=p*x-u*S,C=p*_-h*S,O=u*_-h*x,R=L*O-d*C+b*P+v*I-m*A+M*E;return R?(R=1/R,e[0]=(s*O-l*C+c*P)*R,e[1]=(o*C-n*O-i*P)*R,e[2]=(S*M-x*m+_*v)*R,e[3]=(u*m-p*M-h*v)*R,e[4]=(l*I-a*O-c*A)*R,e[5]=(r*O-o*I+i*A)*R,e[6]=(x*b-g*M-_*d)*R,e[7]=(f*M-u*b+h*d)*R,e[8]=(a*C-s*I+c*E)*R,e[9]=(n*I-r*C-i*E)*R,e[10]=(g*m-S*b+_*L)*R,e[11]=(p*b-f*m-h*L)*R,e[12]=(s*A-a*P-l*E)*R,e[13]=(r*P-n*A+o*E)*R,e[14]=(S*d-g*v-x*L)*R,e[15]=(f*v-p*d+u*L)*R,e):null}function or(e){let t=e[0],r=e[1],n=e[2],o=e[3],i=e[4],a=e[5],s=e[6],l=e[7],c=e[8],f=e[9],p=e[10],u=e[11],h=e[12],g=e[13],S=e[14],x=e[15],_=t*a-r*i,L=t*s-n*i,d=r*s-n*a,b=c*g-f*h,v=c*S-p*h,m=f*S-p*g,M=t*m-r*v+n*b,E=i*m-a*v+s*b,A=c*d-f*L+p*_,I=h*d-g*L+S*_;return l*M-o*E+x*A-u*I}function tt(e,t,r){let n=t[0],o=t[1],i=t[2],a=t[3],s=t[4],l=t[5],c=t[6],f=t[7],p=t[8],u=t[9],h=t[10],g=t[11],S=t[12],x=t[13],_=t[14],L=t[15],d=r[0],b=r[1],v=r[2],m=r[3];return e[0]=d*n+b*s+v*p+m*S,e[1]=d*o+b*l+v*u+m*x,e[2]=d*i+b*c+v*h+m*_,e[3]=d*a+b*f+v*g+m*L,d=r[4],b=r[5],v=r[6],m=r[7],e[4]=d*n+b*s+v*p+m*S,e[5]=d*o+b*l+v*u+m*x,e[6]=d*i+b*c+v*h+m*_,e[7]=d*a+b*f+v*g+m*L,d=r[8],b=r[9],v=r[10],m=r[11],e[8]=d*n+b*s+v*p+m*S,e[9]=d*o+b*l+v*u+m*x,e[10]=d*i+b*c+v*h+m*_,e[11]=d*a+b*f+v*g+m*L,d=r[12],b=r[13],v=r[14],m=r[15],e[12]=d*n+b*s+v*p+m*S,e[13]=d*o+b*l+v*u+m*x,e[14]=d*i+b*c+v*h+m*_,e[15]=d*a+b*f+v*g+m*L,e}function ir(e,t,r){let n=r[0],o=r[1],i=r[2],a,s,l,c,f,p,u,h,g,S,x,_;return t===e?(e[12]=t[0]*n+t[4]*o+t[8]*i+t[12],e[13]=t[1]*n+t[5]*o+t[9]*i+t[13],e[14]=t[2]*n+t[6]*o+t[10]*i+t[14],e[15]=t[3]*n+t[7]*o+t[11]*i+t[15]):(a=t[0],s=t[1],l=t[2],c=t[3],f=t[4],p=t[5],u=t[6],h=t[7],g=t[8],S=t[9],x=t[10],_=t[11],e[0]=a,e[1]=s,e[2]=l,e[3]=c,e[4]=f,e[5]=p,e[6]=u,e[7]=h,e[8]=g,e[9]=S,e[10]=x,e[11]=_,e[12]=a*n+f*o+g*i+t[12],e[13]=s*n+p*o+S*i+t[13],e[14]=l*n+u*o+x*i+t[14],e[15]=c*n+h*o+_*i+t[15]),e}function ar(e,t,r){let n=r[0],o=r[1],i=r[2];return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e[4]=t[4]*o,e[5]=t[5]*o,e[6]=t[6]*o,e[7]=t[7]*o,e[8]=t[8]*i,e[9]=t[9]*i,e[10]=t[10]*i,e[11]=t[11]*i,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function sr(e,t,r,n){let o=n[0],i=n[1],a=n[2],s=Math.sqrt(o*o+i*i+a*a),l,c,f,p,u,h,g,S,x,_,L,d,b,v,m,M,E,A,I,P,C,O,R,Z;return s<1e-6?null:(s=1/s,o*=s,i*=s,a*=s,c=Math.sin(r),l=Math.cos(r),f=1-l,p=t[0],u=t[1],h=t[2],g=t[3],S=t[4],x=t[5],_=t[6],L=t[7],d=t[8],b=t[9],v=t[10],m=t[11],M=o*o*f+l,E=i*o*f+a*c,A=a*o*f-i*c,I=o*i*f-a*c,P=i*i*f+l,C=a*i*f+o*c,O=o*a*f+i*c,R=i*a*f-o*c,Z=a*a*f+l,e[0]=p*M+S*E+d*A,e[1]=u*M+x*E+b*A,e[2]=h*M+_*E+v*A,e[3]=g*M+L*E+m*A,e[4]=p*I+S*P+d*C,e[5]=u*I+x*P+b*C,e[6]=h*I+_*P+v*C,e[7]=g*I+L*P+m*C,e[8]=p*O+S*R+d*Z,e[9]=u*O+x*R+b*Z,e[10]=h*O+_*R+v*Z,e[11]=g*O+L*R+m*Z,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function lr(e,t,r){let n=Math.sin(r),o=Math.cos(r),i=t[4],a=t[5],s=t[6],l=t[7],c=t[8],f=t[9],p=t[10],u=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=i*o+c*n,e[5]=a*o+f*n,e[6]=s*o+p*n,e[7]=l*o+u*n,e[8]=c*o-i*n,e[9]=f*o-a*n,e[10]=p*o-s*n,e[11]=u*o-l*n,e}function cr(e,t,r){let n=Math.sin(r),o=Math.cos(r),i=t[0],a=t[1],s=t[2],l=t[3],c=t[8],f=t[9],p=t[10],u=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*o-c*n,e[1]=a*o-f*n,e[2]=s*o-p*n,e[3]=l*o-u*n,e[8]=i*n+c*o,e[9]=a*n+f*o,e[10]=s*n+p*o,e[11]=l*n+u*o,e}function fr(e,t,r){let n=Math.sin(r),o=Math.cos(r),i=t[0],a=t[1],s=t[2],l=t[3],c=t[4],f=t[5],p=t[6],u=t[7];return t!==e&&(e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*o+c*n,e[1]=a*o+f*n,e[2]=s*o+p*n,e[3]=l*o+u*n,e[4]=c*o-i*n,e[5]=f*o-a*n,e[6]=p*o-s*n,e[7]=u*o-l*n,e}function pr(e,t){let r=t[0],n=t[1],o=t[2],i=t[3],a=r+r,s=n+n,l=o+o,c=r*a,f=n*a,p=n*s,u=o*a,h=o*s,g=o*l,S=i*a,x=i*s,_=i*l;return e[0]=1-p-g,e[1]=f+_,e[2]=u-x,e[3]=0,e[4]=f-_,e[5]=1-c-g,e[6]=h+S,e[7]=0,e[8]=u+x,e[9]=h-S,e[10]=1-c-p,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function ur(e,t,r,n,o,i,a){let s=1/(r-t),l=1/(o-n),c=1/(i-a);return e[0]=i*2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i*2*l,e[6]=0,e[7]=0,e[8]=(r+t)*s,e[9]=(o+n)*l,e[10]=(a+i)*c,e[11]=-1,e[12]=0,e[13]=0,e[14]=a*i*2*c,e[15]=0,e}function fo(e,t,r,n,o){let i=1/Math.tan(t/2);if(e[0]=i/r,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,o!=null&&o!==1/0){let a=1/(n-o);e[10]=(o+n)*a,e[14]=2*o*n*a}else e[10]=-1,e[14]=-2*n;return e}var hr=fo;function po(e,t,r,n,o,i,a){let s=1/(t-r),l=1/(n-o),c=1/(i-a);return e[0]=-2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*l,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*c,e[11]=0,e[12]=(t+r)*s,e[13]=(o+n)*l,e[14]=(a+i)*c,e[15]=1,e}var mr=po;function gr(e,t,r,n){let o,i,a,s,l,c,f,p,u,h,g=t[0],S=t[1],x=t[2],_=n[0],L=n[1],d=n[2],b=r[0],v=r[1],m=r[2];return Math.abs(g-b)<1e-6&&Math.abs(S-v)<1e-6&&Math.abs(x-m)<1e-6?co(e):(p=g-b,u=S-v,h=x-m,o=1/Math.sqrt(p*p+u*u+h*h),p*=o,u*=o,h*=o,i=L*h-d*u,a=d*p-_*h,s=_*u-L*p,o=Math.sqrt(i*i+a*a+s*s),o?(o=1/o,i*=o,a*=o,s*=o):(i=0,a=0,s=0),l=u*s-h*a,c=h*i-p*s,f=p*a-u*i,o=Math.sqrt(l*l+c*c+f*f),o?(o=1/o,l*=o,c*=o,f*=o):(l=0,c=0,f=0),e[0]=i,e[1]=l,e[2]=p,e[3]=0,e[4]=a,e[5]=c,e[6]=u,e[7]=0,e[8]=s,e[9]=f,e[10]=h,e[11]=0,e[12]=-(i*g+a*S+s*x),e[13]=-(l*g+c*S+f*x),e[14]=-(p*g+u*S+h*x),e[15]=1,e)}function uo(){let e=new w(4);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function dr(e,t,r){let n=t[0],o=t[1],i=t[2],a=t[3];return e[0]=r[0]*n+r[4]*o+r[8]*i+r[12]*a,e[1]=r[1]*n+r[5]*o+r[9]*i+r[13]*a,e[2]=r[2]*n+r[6]*o+r[10]*i+r[14]*a,e[3]=r[3]*n+r[7]*o+r[11]*i+r[15]*a,e}var la=function(){let e=uo();return function(t,r,n,o,i,a){let s,l;for(r||(r=4),n||(n=0),o?l=Math.min(o*r+n,t.length):l=t.length,s=n;s<l;s+=r)e[0]=t[s],e[1]=t[s+1],e[2]=t[s+2],e[3]=t[s+3],i(e,e,a),t[s]=e[0],t[s+1]=e[1],t[s+2]=e[2],t[s+3]=e[3];return t}}();var ot;(function(e){e[e.COL0ROW0=0]="COL0ROW0",e[e.COL0ROW1=1]="COL0ROW1",e[e.COL0ROW2=2]="COL0ROW2",e[e.COL0ROW3=3]="COL0ROW3",e[e.COL1ROW0=4]="COL1ROW0",e[e.COL1ROW1=5]="COL1ROW1",e[e.COL1ROW2=6]="COL1ROW2",e[e.COL1ROW3=7]="COL1ROW3",e[e.COL2ROW0=8]="COL2ROW0",e[e.COL2ROW1=9]="COL2ROW1",e[e.COL2ROW2=10]="COL2ROW2",e[e.COL2ROW3=11]="COL2ROW3",e[e.COL3ROW0=12]="COL3ROW0",e[e.COL3ROW1=13]="COL3ROW1",e[e.COL3ROW2=14]="COL3ROW2",e[e.COL3ROW3=15]="COL3ROW3"})(ot||(ot={}));var ho=45*Math.PI/180,mo=1,rt=.1,nt=500,go=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),B=class extends Ce{static get IDENTITY(){return bo()}static get ZERO(){return _o()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return ot}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,r,n,o,i,a,s,l,c,f,p,u,h,g,S,x){return this[0]=t,this[1]=r,this[2]=n,this[3]=o,this[4]=i,this[5]=a,this[6]=s,this[7]=l,this[8]=c,this[9]=f,this[10]=p,this[11]=u,this[12]=h,this[13]=g,this[14]=S,this[15]=x,this.check()}setRowMajor(t,r,n,o,i,a,s,l,c,f,p,u,h,g,S,x){return this[0]=t,this[1]=i,this[2]=c,this[3]=h,this[4]=r,this[5]=a,this[6]=f,this[7]=g,this[8]=n,this[9]=s,this[10]=p,this[11]=S,this[12]=o,this[13]=l,this[14]=u,this[15]=x,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(go)}fromObject(t){return this.check()}fromQuaternion(t){return pr(this,t),this.check()}frustum(t){let{left:r,right:n,bottom:o,top:i,near:a=rt,far:s=nt}=t;return s===1/0?vo(this,r,n,o,i,a):ur(this,r,n,o,i,a,s),this.check()}lookAt(t){let{eye:r,center:n=[0,0,0],up:o=[0,1,0]}=t;return gr(this,r,n,o),this.check()}ortho(t){let{left:r,right:n,bottom:o,top:i,near:a=rt,far:s=nt}=t;return mr(this,r,n,o,i,a,s),this.check()}orthographic(t){let{fovy:r=ho,aspect:n=mo,focalDistance:o=1,near:i=rt,far:a=nt}=t;_r(r);let s=r/2,l=o*Math.tan(s),c=l*n;return this.ortho({left:-c,right:c,bottom:-l,top:l,near:i,far:a})}perspective(t){let{fovy:r=45*Math.PI/180,aspect:n=1,near:o=.1,far:i=500}=t;return _r(r),hr(this,r,n,o,i),this.check()}determinant(){return or(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,r){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],r=r||[-0,-0,-0];let n=this.getScale(r),o=1/n[0],i=1/n[1],a=1/n[2];return t[0]=this[0]*o,t[1]=this[1]*i,t[2]=this[2]*a,t[3]=0,t[4]=this[4]*o,t[5]=this[5]*i,t[6]=this[6]*a,t[7]=0,t[8]=this[8]*o,t[9]=this[9]*i,t[10]=this[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,r){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],r=r||[-0,-0,-0];let n=this.getScale(r),o=1/n[0],i=1/n[1],a=1/n[2];return t[0]=this[0]*o,t[1]=this[1]*i,t[2]=this[2]*a,t[3]=this[4]*o,t[4]=this[5]*i,t[5]=this[6]*a,t[6]=this[8]*o,t[7]=this[9]*i,t[8]=this[10]*a,t}transpose(){return rr(this,this),this.check()}invert(){return nr(this,this),this.check()}multiplyLeft(t){return tt(this,t,this),this.check()}multiplyRight(t){return tt(this,this,t),this.check()}rotateX(t){return lr(this,this,t),this.check()}rotateY(t){return cr(this,this,t),this.check()}rotateZ(t){return fr(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,r){return sr(this,this,t,r),this.check()}scale(t){return ar(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return ir(this,this,t),this.check()}transform(t,r){return t.length===4?(r=dr(r||[-0,-0,-0,-0],t,this),Ie(r,4),r):this.transformAsPoint(t,r)}transformAsPoint(t,r){let{length:n}=t,o;switch(n){case 2:o=Qt(r||[-0,-0],t,this);break;case 3:o=tr(r||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Ie(o,t.length),o}transformAsVector(t,r){let n;switch(t.length){case 2:n=Jt(r||[-0,-0],t,this);break;case 3:n=er(r||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Ie(n,t.length),n}transformPoint(t,r){return this.transformAsPoint(t,r)}transformVector(t,r){return this.transformAsPoint(t,r)}transformDirection(t,r){return this.transformAsVector(t,r)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,r,n){return this.identity().translate([t,r,n])}},ye,Ne;function _o(){return ye||(ye=new B([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(ye)),ye}function bo(){return Ne||(Ne=new B,Object.freeze(Ne)),Ne}function _r(e){if(e>Math.PI*2)throw Error("expected radians")}function vo(e,t,r,n,o,i){let a=2*i/(r-t),s=2*i/(o-n),l=(r+t)/(r-t),c=(o+n)/(o-n),f=-1,p=-1,u=-2*i;return e[0]=a,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=s,e[6]=0,e[7]=0,e[8]=l,e[9]=c,e[10]=f,e[11]=p,e[12]=0,e[13]=0,e[14]=u,e[15]=0,e}var z=null,br=new ArrayBuffer(4),vr=new Float32Array(br),Sr=new Uint32Array(br);function xr(e){z||=Lr(),e=Je(e,-65504,65504),vr[0]=e;let t=Sr[0],r=t>>23&511;return z.baseTable[r]+((t&8388607)>>z.shiftTable[r])}function Mr(e){z||=Lr();let t=e>>10;return Sr[0]=z.mantissaTable[z.offsetTable[t]+(e&1023)]+z.exponentTable[t],vr[0]}function Lr(){let e=new Uint32Array(512),t=new Uint32Array(512);for(let i=0;i<256;++i){let a=i-127;a<-27?(e[i]=0,e[i|256]=32768,t[i]=24,t[i|256]=24):a<-14?(e[i]=1024>>-a-14,e[i|256]=1024>>-a-14|32768,t[i]=-a-1,t[i|256]=-a-1):a<=15?(e[i]=a+15<<10,e[i|256]=a+15<<10|32768,t[i]=13,t[i|256]=13):a<128?(e[i]=31744,e[i|256]=64512,t[i]=24,t[i|256]=24):(e[i]=31744,e[i|256]=64512,t[i]=13,t[i|256]=13)}let r=new Uint32Array(2048),n=new Uint32Array(64),o=new Uint32Array(64);for(let i=1;i<1024;++i){let a=i<<13,s=0;for(;!(a&8388608);)a<<=1,s-=8388608;a&=-8388609,s+=947912704,r[i]=a|s}for(let i=1024;i<2048;++i)r[i]=939524096+(i-1024<<13);for(let i=1;i<31;++i)n[i]=i<<23;n[31]=1199570944,n[32]=2147483648;for(let i=33;i<63;++i)n[i]=2147483648+(i-32<<23);n[63]=3347054592;for(let i=1;i<64;++i)i!==32&&(o[i]=1024);return{baseTable:e,shiftTable:t,mantissaTable:r,exponentTable:n,offsetTable:o}}function K(e,t=[],r=0){let n=Math.fround(e),o=e-n;return t[r]=n,t[r+1]=o,t}function ae(e){return e-Math.fround(e)}function se(e){let t=new Float32Array(32);for(let r=0;r<4;++r)for(let n=0;n<4;++n){let o=r*4+n;K(e[n*4+r],t,o*2)}return t}function Y(e,t=!0){return e??t}function le(e=[0,0,0],t=!0){return t?e.map(r=>r/255):[...e]}function Pe(e,t=!0){let r=le(e.slice(0,3),t),n=Number.isFinite(e[3]),o=n?e[3]:1;return[r[0],r[1],r[2],t&&n?o/255:o]}var So=`fn random(scale: vec3f, seed: f32) -> f32 {
|
|
125
|
+
${i} = ${o};
|
|
126
|
+
}`}function Cn(e){switch(e){case"float":return"x";case"vec2":return"xy";case"vec3":return"xyz";case"vec4":return"xyzw";default:throw new Error(e)}}function yn(e){switch(e){case"float":return 1;case"vec2":return 2;case"vec3":return 3;case"vec4":return 4;default:throw new Error(e)}}function Uo(e){switch(e){case 1:return"float";case 2:return"vec2";case 3:return"vec3";case 4:return"vec4";default:throw new Error(`invalid channels: ${e}`)}}function vt(e,t){switch(t){case 1:return`vec4(${e}, 0.0, 0.0, 1.0)`;case 2:return`vec4(${e}, 0.0, 1.0)`;case 3:return`vec4(${e}, 1.0)`;case 4:return e;default:throw new Error(`invalid channels: ${t}`)}}function K(e){return typeof e=="string"?e.charAt(0).toUpperCase()+e.slice(1):e}function wn(e,t){return Bo(e,t)}function Bo(e,t){let n=[];switch(t.uniforms){case"scoped-interface-blocks":case"unscoped-interface-blocks":n.push(`layout(std140) uniform ${K(e.name)} {`);break;case"uniforms":}for(let[i,r]of Object.entries(e.uniformTypes||{})){if(typeof r!="string")throw new Error(`Composite uniform types are not supported by GLSL shader generation: ${e.name}.${i}`);let o=Do(r);switch(t.uniforms){case"scoped-interface-blocks":n.push(` ${o} ${i};`);break;case"unscoped-interface-blocks":n.push(` ${o} ${e.name}_${i};`);break;case"uniforms":n.push(`uniform ${o} ${e.name}_${i};`)}}switch(t.uniforms){case"scoped-interface-blocks":n.push(`} ${e.name};`);break;case"unscoped-interface-blocks":n.push("};");break;case"uniforms":}return n.push(""),n.join(`
|
|
127
|
+
`)}function Do(e){return{f32:"float",i32:"int",u32:"uint","vec2<f32>":"vec2","vec3<f32>":"vec3","vec4<f32>":"vec4","vec2<i32>":"ivec2","vec3<i32>":"ivec3","vec4<i32>":"ivec4","vec2<u32>":"uvec2","vec3<u32>":"uvec3","vec4<u32>":"uvec4","mat2x2<f32>":"mat2","mat2x3<f32>":"mat2x3","mat2x4<f32>":"mat2x4","mat3x2<f32>":"mat3x2","mat3x3<f32>":"mat3","mat3x4<f32>":"mat3x4","mat4x2<f32>":"mat4x2","mat4x3<f32>":"mat4x3","mat4x4<f32>":"mat4"}[e]}function Tn(e,t){return Fo(e,t)}function Fo(e,t){let n=[];n.push(`struct ${K(e.name)} {`);for(let[i,r]of Object.entries(e?.uniformTypes||{})){if(typeof r!="string")throw new Error(`Composite uniform types are not supported by WGSL shader generation: ${e.name}.${i}`);let o=r;n.push(` ${i} : ${o};`)}return n.push("};"),n.push(`var<uniform> ${e.name} : ${K(e.name)};`),n.join(`
|
|
128
|
+
`)}function Nn(e,t){switch(t.shaderLanguage){case"glsl":return wn(e,t);case"wgsl":return Tn(e,t)}}var Hs=1/Math.PI*180,$s=1/180*Math.PI,Go={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Go}};var N=globalThis.mathgl.config;function bt(e,{precision:t=N.precision}={}){return e=Vo(e),`${parseFloat(e.toPrecision(t))}`}function te(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function xt(e,t,n){return zo(e,i=>Math.max(t,Math.min(n,i)))}function Ve(e,t,n){let i=N.EPSILON;n&&(N.EPSILON=n);try{if(e===t)return!0;if(te(e)&&te(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;++r)if(!Ve(e[r],t[r]))return!1;return!0}return e&&e.equals?e.equals(t):t&&t.equals?t.equals(e):typeof e=="number"&&typeof t=="number"?Math.abs(e-t)<=N.EPSILON*Math.max(1,Math.abs(e),Math.abs(t)):!1}finally{N.EPSILON=i}}function Vo(e){return Math.round(e/N.EPSILON)*N.EPSILON}function ko(e){return e.clone?e.clone():new Array(e.length)}function zo(e,t,n){if(te(e)){let i=e;n=n||ko(i);for(let r=0;r<n.length&&r<i.length;++r){let o=typeof e=="number"?e:e[r];n[r]=t(o,r,n)}return n}return t(e)}var ke=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,n=0){for(let i=0;i<this.ELEMENTS;++i)this[i]=t[i+n];return this.check()}toArray(t=[],n=0){for(let i=0;i<this.ELEMENTS;++i)t[n+i]=this[i];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:te(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(N)}formatString(t){let n="";for(let i=0;i<this.ELEMENTS;++i)n+=(i>0?", ":"")+bt(this[i],t);return`${t.printTypes?this.constructor.name:""}[${n}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(!Ve(this[n],t[n]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(this[n]!==t[n])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,n,i){if(i===void 0)return this.lerp(this,t,n);for(let r=0;r<this.ELEMENTS;++r){let o=t[r],a=typeof n=="number"?n:n[r];this[r]=o+i*(a-o)}return this.check()}min(t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(t[n],this[n]);return this.check()}max(t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.max(t[n],this[n]);return this.check()}clamp(t,n){for(let i=0;i<this.ELEMENTS;++i)this[i]=Math.min(Math.max(this[i],t[i]),n[i]);return this.check()}add(...t){for(let n of t)for(let i=0;i<this.ELEMENTS;++i)this[i]+=n[i];return this.check()}subtract(...t){for(let n of t)for(let i=0;i<this.ELEMENTS;++i)this[i]-=n[i];return this.check()}scale(t){if(typeof t=="number")for(let n=0;n<this.ELEMENTS;++n)this[n]*=t;else for(let n=0;n<this.ELEMENTS&&n<t.length;++n)this[n]*=t[n];return this.check()}multiplyByScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]*=t;return this.check()}check(){if(N.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let n=0;n<this.ELEMENTS;++n)t=t&&Number.isFinite(this[n]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]=t;return this.check()}addScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,n){for(let i=0;i<this.ELEMENTS;++i)this[i]=Math.min(Math.max(this[i],t),n);return this.check()}get elements(){return this}};function Ho(e,t){if(e.length!==t)return!1;for(let n=0;n<e.length;++n)if(!Number.isFinite(e[n]))return!1;return!0}function Pn(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function ze(e,t,n=""){if(N.debug&&!Ho(e,t))throw new Error(`math.gl: ${n} some fields set to invalid numbers'`);return e}var H=typeof Float32Array<"u"?Float32Array:Array;var Xs=Math.PI/180;function $o(){let e=new H(2);return H!=Float32Array&&(e[0]=0,e[1]=0),e}function Bn(e,t,n){let i=t[0],r=t[1];return e[0]=n[0]*i+n[4]*r+n[12],e[1]=n[1]*i+n[5]*r+n[13],e}var Zs=function(){let e=$o();return function(t,n,i,r,o,a){let s,l;for(n||(n=2),i||(i=0),r?l=Math.min(r*n+i,t.length):l=t.length,s=i;s<l;s+=n)e[0]=t[s],e[1]=t[s+1],o(e,e,a),t[s]=e[0],t[s+1]=e[1];return t}}();function Dn(e,t,n){let i=t[0],r=t[1],o=n[3]*i+n[7]*r||1;return e[0]=(n[0]*i+n[4]*r)/o,e[1]=(n[1]*i+n[5]*r)/o,e}function Fn(e,t,n){let i=t[0],r=t[1],o=t[2],a=n[3]*i+n[7]*r+n[11]*o||1;return e[0]=(n[0]*i+n[4]*r+n[8]*o)/a,e[1]=(n[1]*i+n[5]*r+n[9]*o)/a,e[2]=(n[2]*i+n[6]*r+n[10]*o)/a,e}function jo(){let e=new H(3);return H!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function Gn(e,t,n){let i=t[0],r=t[1],o=t[2],a=n[3]*i+n[7]*r+n[11]*o+n[15];return a=a||1,e[0]=(n[0]*i+n[4]*r+n[8]*o+n[12])/a,e[1]=(n[1]*i+n[5]*r+n[9]*o+n[13])/a,e[2]=(n[2]*i+n[6]*r+n[10]*o+n[14])/a,e}var el=function(){let e=jo();return function(t,n,i,r,o,a){let s,l;for(n||(n=3),i||(i=0),r?l=Math.min(r*n+i,t.length):l=t.length,s=i;s<l;s+=n)e[0]=t[s],e[1]=t[s+1],e[2]=t[s+2],o(e,e,a),t[s]=e[0],t[s+1]=e[1],t[s+2]=e[2];return t}}();var He=class extends ke{toString(){let t="[";if(N.printRowMajor){t+="row-major:";for(let n=0;n<this.RANK;++n)for(let i=0;i<this.RANK;++i)t+=` ${this[i*this.RANK+n]}`}else{t+="column-major:";for(let n=0;n<this.ELEMENTS;++n)t+=` ${this[n]}`}return t+="]",t}getElementIndex(t,n){return n*this.RANK+t}getElement(t,n){return this[n*this.RANK+t]}setElement(t,n,i){return this[n*this.RANK+t]=Pn(i),this}getColumn(t,n=new Array(this.RANK).fill(-0)){let i=t*this.RANK;for(let r=0;r<this.RANK;++r)n[r]=this[i+r];return n}setColumn(t,n){let i=t*this.RANK;for(let r=0;r<this.RANK;++r)this[i+r]=n[r];return this}};function qo(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Vn(e,t){if(e===t){let n=t[1],i=t[2],r=t[3],o=t[6],a=t[7],s=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=n,e[6]=t[9],e[7]=t[13],e[8]=i,e[9]=o,e[11]=t[14],e[12]=r,e[13]=a,e[14]=s}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e}function kn(e,t){let n=t[0],i=t[1],r=t[2],o=t[3],a=t[4],s=t[5],l=t[6],c=t[7],f=t[8],u=t[9],p=t[10],g=t[11],_=t[12],m=t[13],b=t[14],x=t[15],M=n*s-i*a,S=n*l-r*a,h=n*c-o*a,d=i*l-r*s,v=i*c-o*s,E=r*c-o*l,C=f*m-u*_,w=f*b-p*_,L=f*x-g*_,y=u*b-p*m,I=u*x-g*m,R=p*x-g*b,A=M*R-S*I+h*y+d*L-v*w+E*C;return A?(A=1/A,e[0]=(s*R-l*I+c*y)*A,e[1]=(r*I-i*R-o*y)*A,e[2]=(m*E-b*v+x*d)*A,e[3]=(p*v-u*E-g*d)*A,e[4]=(l*L-a*R-c*w)*A,e[5]=(n*R-r*L+o*w)*A,e[6]=(b*h-_*E-x*S)*A,e[7]=(f*E-p*h+g*S)*A,e[8]=(a*I-s*L+c*C)*A,e[9]=(i*L-n*I-o*C)*A,e[10]=(_*v-m*h+x*M)*A,e[11]=(u*h-f*v-g*M)*A,e[12]=(s*w-a*y-l*C)*A,e[13]=(n*y-i*w+r*C)*A,e[14]=(m*S-_*d-b*M)*A,e[15]=(f*d-u*S+p*M)*A,e):null}function zn(e){let t=e[0],n=e[1],i=e[2],r=e[3],o=e[4],a=e[5],s=e[6],l=e[7],c=e[8],f=e[9],u=e[10],p=e[11],g=e[12],_=e[13],m=e[14],b=e[15],x=t*a-n*o,M=t*s-i*o,S=n*s-i*a,h=c*_-f*g,d=c*m-u*g,v=f*m-u*_,E=t*v-n*d+i*h,C=o*v-a*d+s*h,w=c*S-f*M+u*x,L=g*S-_*M+m*x;return l*E-r*C+b*w-p*L}function Mt(e,t,n){let i=t[0],r=t[1],o=t[2],a=t[3],s=t[4],l=t[5],c=t[6],f=t[7],u=t[8],p=t[9],g=t[10],_=t[11],m=t[12],b=t[13],x=t[14],M=t[15],S=n[0],h=n[1],d=n[2],v=n[3];return e[0]=S*i+h*s+d*u+v*m,e[1]=S*r+h*l+d*p+v*b,e[2]=S*o+h*c+d*g+v*x,e[3]=S*a+h*f+d*_+v*M,S=n[4],h=n[5],d=n[6],v=n[7],e[4]=S*i+h*s+d*u+v*m,e[5]=S*r+h*l+d*p+v*b,e[6]=S*o+h*c+d*g+v*x,e[7]=S*a+h*f+d*_+v*M,S=n[8],h=n[9],d=n[10],v=n[11],e[8]=S*i+h*s+d*u+v*m,e[9]=S*r+h*l+d*p+v*b,e[10]=S*o+h*c+d*g+v*x,e[11]=S*a+h*f+d*_+v*M,S=n[12],h=n[13],d=n[14],v=n[15],e[12]=S*i+h*s+d*u+v*m,e[13]=S*r+h*l+d*p+v*b,e[14]=S*o+h*c+d*g+v*x,e[15]=S*a+h*f+d*_+v*M,e}function Hn(e,t,n){let i=n[0],r=n[1],o=n[2],a,s,l,c,f,u,p,g,_,m,b,x;return t===e?(e[12]=t[0]*i+t[4]*r+t[8]*o+t[12],e[13]=t[1]*i+t[5]*r+t[9]*o+t[13],e[14]=t[2]*i+t[6]*r+t[10]*o+t[14],e[15]=t[3]*i+t[7]*r+t[11]*o+t[15]):(a=t[0],s=t[1],l=t[2],c=t[3],f=t[4],u=t[5],p=t[6],g=t[7],_=t[8],m=t[9],b=t[10],x=t[11],e[0]=a,e[1]=s,e[2]=l,e[3]=c,e[4]=f,e[5]=u,e[6]=p,e[7]=g,e[8]=_,e[9]=m,e[10]=b,e[11]=x,e[12]=a*i+f*r+_*o+t[12],e[13]=s*i+u*r+m*o+t[13],e[14]=l*i+p*r+b*o+t[14],e[15]=c*i+g*r+x*o+t[15]),e}function $n(e,t,n){let i=n[0],r=n[1],o=n[2];return e[0]=t[0]*i,e[1]=t[1]*i,e[2]=t[2]*i,e[3]=t[3]*i,e[4]=t[4]*r,e[5]=t[5]*r,e[6]=t[6]*r,e[7]=t[7]*r,e[8]=t[8]*o,e[9]=t[9]*o,e[10]=t[10]*o,e[11]=t[11]*o,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function jn(e,t,n,i){let r=i[0],o=i[1],a=i[2],s=Math.sqrt(r*r+o*o+a*a),l,c,f,u,p,g,_,m,b,x,M,S,h,d,v,E,C,w,L,y,I,R,A,F;return s<1e-6?null:(s=1/s,r*=s,o*=s,a*=s,c=Math.sin(n),l=Math.cos(n),f=1-l,u=t[0],p=t[1],g=t[2],_=t[3],m=t[4],b=t[5],x=t[6],M=t[7],S=t[8],h=t[9],d=t[10],v=t[11],E=r*r*f+l,C=o*r*f+a*c,w=a*r*f-o*c,L=r*o*f-a*c,y=o*o*f+l,I=a*o*f+r*c,R=r*a*f+o*c,A=o*a*f-r*c,F=a*a*f+l,e[0]=u*E+m*C+S*w,e[1]=p*E+b*C+h*w,e[2]=g*E+x*C+d*w,e[3]=_*E+M*C+v*w,e[4]=u*L+m*y+S*I,e[5]=p*L+b*y+h*I,e[6]=g*L+x*y+d*I,e[7]=_*L+M*y+v*I,e[8]=u*R+m*A+S*F,e[9]=p*R+b*A+h*F,e[10]=g*R+x*A+d*F,e[11]=_*R+M*A+v*F,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function qn(e,t,n){let i=Math.sin(n),r=Math.cos(n),o=t[4],a=t[5],s=t[6],l=t[7],c=t[8],f=t[9],u=t[10],p=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=o*r+c*i,e[5]=a*r+f*i,e[6]=s*r+u*i,e[7]=l*r+p*i,e[8]=c*r-o*i,e[9]=f*r-a*i,e[10]=u*r-s*i,e[11]=p*r-l*i,e}function Wn(e,t,n){let i=Math.sin(n),r=Math.cos(n),o=t[0],a=t[1],s=t[2],l=t[3],c=t[8],f=t[9],u=t[10],p=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=o*r-c*i,e[1]=a*r-f*i,e[2]=s*r-u*i,e[3]=l*r-p*i,e[8]=o*i+c*r,e[9]=a*i+f*r,e[10]=s*i+u*r,e[11]=l*i+p*r,e}function Kn(e,t,n){let i=Math.sin(n),r=Math.cos(n),o=t[0],a=t[1],s=t[2],l=t[3],c=t[4],f=t[5],u=t[6],p=t[7];return t!==e&&(e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=o*r+c*i,e[1]=a*r+f*i,e[2]=s*r+u*i,e[3]=l*r+p*i,e[4]=c*r-o*i,e[5]=f*r-a*i,e[6]=u*r-s*i,e[7]=p*r-l*i,e}function Yn(e,t){let n=t[0],i=t[1],r=t[2],o=t[3],a=n+n,s=i+i,l=r+r,c=n*a,f=i*a,u=i*s,p=r*a,g=r*s,_=r*l,m=o*a,b=o*s,x=o*l;return e[0]=1-u-_,e[1]=f+x,e[2]=p-b,e[3]=0,e[4]=f-x,e[5]=1-c-_,e[6]=g+m,e[7]=0,e[8]=p+b,e[9]=g-m,e[10]=1-c-u,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Xn(e,t,n,i,r,o,a){let s=1/(n-t),l=1/(r-i),c=1/(o-a);return e[0]=o*2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=o*2*l,e[6]=0,e[7]=0,e[8]=(n+t)*s,e[9]=(r+i)*l,e[10]=(a+o)*c,e[11]=-1,e[12]=0,e[13]=0,e[14]=a*o*2*c,e[15]=0,e}function Wo(e,t,n,i,r){let o=1/Math.tan(t/2);if(e[0]=o/n,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=o,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,r!=null&&r!==1/0){let a=1/(i-r);e[10]=(r+i)*a,e[14]=2*r*i*a}else e[10]=-1,e[14]=-2*i;return e}var Zn=Wo;function Ko(e,t,n,i,r,o,a){let s=1/(t-n),l=1/(i-r),c=1/(o-a);return e[0]=-2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*l,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*c,e[11]=0,e[12]=(t+n)*s,e[13]=(r+i)*l,e[14]=(a+o)*c,e[15]=1,e}var Jn=Ko;function Qn(e,t,n,i){let r,o,a,s,l,c,f,u,p,g,_=t[0],m=t[1],b=t[2],x=i[0],M=i[1],S=i[2],h=n[0],d=n[1],v=n[2];return Math.abs(_-h)<1e-6&&Math.abs(m-d)<1e-6&&Math.abs(b-v)<1e-6?qo(e):(u=_-h,p=m-d,g=b-v,r=1/Math.sqrt(u*u+p*p+g*g),u*=r,p*=r,g*=r,o=M*g-S*p,a=S*u-x*g,s=x*p-M*u,r=Math.sqrt(o*o+a*a+s*s),r?(r=1/r,o*=r,a*=r,s*=r):(o=0,a=0,s=0),l=p*s-g*a,c=g*o-u*s,f=u*a-p*o,r=Math.sqrt(l*l+c*c+f*f),r?(r=1/r,l*=r,c*=r,f*=r):(l=0,c=0,f=0),e[0]=o,e[1]=l,e[2]=u,e[3]=0,e[4]=a,e[5]=c,e[6]=p,e[7]=0,e[8]=s,e[9]=f,e[10]=g,e[11]=0,e[12]=-(o*_+a*m+s*b),e[13]=-(l*_+c*m+f*b),e[14]=-(u*_+p*m+g*b),e[15]=1,e)}function Yo(){let e=new H(4);return H!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function ei(e,t,n){let i=t[0],r=t[1],o=t[2],a=t[3];return e[0]=n[0]*i+n[4]*r+n[8]*o+n[12]*a,e[1]=n[1]*i+n[5]*r+n[9]*o+n[13]*a,e[2]=n[2]*i+n[6]*r+n[10]*o+n[14]*a,e[3]=n[3]*i+n[7]*r+n[11]*o+n[15]*a,e}var sl=function(){let e=Yo();return function(t,n,i,r,o,a){let s,l;for(n||(n=4),i||(i=0),r?l=Math.min(r*n+i,t.length):l=t.length,s=i;s<l;s+=n)e[0]=t[s],e[1]=t[s+1],e[2]=t[s+2],e[3]=t[s+3],o(e,e,a),t[s]=e[0],t[s+1]=e[1],t[s+2]=e[2],t[s+3]=e[3];return t}}();var It;(function(e){e[e.COL0ROW0=0]="COL0ROW0",e[e.COL0ROW1=1]="COL0ROW1",e[e.COL0ROW2=2]="COL0ROW2",e[e.COL0ROW3=3]="COL0ROW3",e[e.COL1ROW0=4]="COL1ROW0",e[e.COL1ROW1=5]="COL1ROW1",e[e.COL1ROW2=6]="COL1ROW2",e[e.COL1ROW3=7]="COL1ROW3",e[e.COL2ROW0=8]="COL2ROW0",e[e.COL2ROW1=9]="COL2ROW1",e[e.COL2ROW2=10]="COL2ROW2",e[e.COL2ROW3=11]="COL2ROW3",e[e.COL3ROW0=12]="COL3ROW0",e[e.COL3ROW1=13]="COL3ROW1",e[e.COL3ROW2=14]="COL3ROW2",e[e.COL3ROW3=15]="COL3ROW3"})(It||(It={}));var Xo=45*Math.PI/180,Zo=1,Lt=.1,At=500,Jo=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),$=class extends He{static get IDENTITY(){return ea()}static get ZERO(){return Qo()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return It}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,n,i,r,o,a,s,l,c,f,u,p,g,_,m,b){return this[0]=t,this[1]=n,this[2]=i,this[3]=r,this[4]=o,this[5]=a,this[6]=s,this[7]=l,this[8]=c,this[9]=f,this[10]=u,this[11]=p,this[12]=g,this[13]=_,this[14]=m,this[15]=b,this.check()}setRowMajor(t,n,i,r,o,a,s,l,c,f,u,p,g,_,m,b){return this[0]=t,this[1]=o,this[2]=c,this[3]=g,this[4]=n,this[5]=a,this[6]=f,this[7]=_,this[8]=i,this[9]=s,this[10]=u,this[11]=m,this[12]=r,this[13]=l,this[14]=p,this[15]=b,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(Jo)}fromObject(t){return this.check()}fromQuaternion(t){return Yn(this,t),this.check()}frustum(t){let{left:n,right:i,bottom:r,top:o,near:a=Lt,far:s=At}=t;return s===1/0?ta(this,n,i,r,o,a):Xn(this,n,i,r,o,a,s),this.check()}lookAt(t){let{eye:n,center:i=[0,0,0],up:r=[0,1,0]}=t;return Qn(this,n,i,r),this.check()}ortho(t){let{left:n,right:i,bottom:r,top:o,near:a=Lt,far:s=At}=t;return Jn(this,n,i,r,o,a,s),this.check()}orthographic(t){let{fovy:n=Xo,aspect:i=Zo,focalDistance:r=1,near:o=Lt,far:a=At}=t;ti(n);let s=n/2,l=r*Math.tan(s),c=l*i;return this.ortho({left:-c,right:c,bottom:-l,top:l,near:o,far:a})}perspective(t){let{fovy:n=45*Math.PI/180,aspect:i=1,near:r=.1,far:o=500}=t;return ti(n),Zn(this,n,i,r,o),this.check()}determinant(){return zn(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,n){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let i=this.getScale(n),r=1/i[0],o=1/i[1],a=1/i[2];return t[0]=this[0]*r,t[1]=this[1]*o,t[2]=this[2]*a,t[3]=0,t[4]=this[4]*r,t[5]=this[5]*o,t[6]=this[6]*a,t[7]=0,t[8]=this[8]*r,t[9]=this[9]*o,t[10]=this[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,n){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let i=this.getScale(n),r=1/i[0],o=1/i[1],a=1/i[2];return t[0]=this[0]*r,t[1]=this[1]*o,t[2]=this[2]*a,t[3]=this[4]*r,t[4]=this[5]*o,t[5]=this[6]*a,t[6]=this[8]*r,t[7]=this[9]*o,t[8]=this[10]*a,t}transpose(){return Vn(this,this),this.check()}invert(){return kn(this,this),this.check()}multiplyLeft(t){return Mt(this,t,this),this.check()}multiplyRight(t){return Mt(this,this,t),this.check()}rotateX(t){return qn(this,this,t),this.check()}rotateY(t){return Wn(this,this,t),this.check()}rotateZ(t){return Kn(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,n){return jn(this,this,t,n),this.check()}scale(t){return $n(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return Hn(this,this,t),this.check()}transform(t,n){return t.length===4?(n=ei(n||[-0,-0,-0,-0],t,this),ze(n,4),n):this.transformAsPoint(t,n)}transformAsPoint(t,n){let{length:i}=t,r;switch(i){case 2:r=Bn(n||[-0,-0],t,this);break;case 3:r=Gn(n||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return ze(r,t.length),r}transformAsVector(t,n){let i;switch(t.length){case 2:i=Dn(n||[-0,-0],t,this);break;case 3:i=Fn(n||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return ze(i,t.length),i}transformPoint(t,n){return this.transformAsPoint(t,n)}transformVector(t,n){return this.transformAsPoint(t,n)}transformDirection(t,n){return this.transformAsVector(t,n)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,n,i){return this.identity().translate([t,n,i])}},$e,je;function Qo(){return $e||($e=new $([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze($e)),$e}function ea(){return je||(je=new $,Object.freeze(je)),je}function ti(e){if(e>Math.PI*2)throw Error("expected radians")}function ta(e,t,n,i,r,o){let a=2*o/(n-t),s=2*o/(r-i),l=(n+t)/(n-t),c=(r+i)/(r-i),f=-1,u=-1,p=-2*o;return e[0]=a,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=s,e[6]=0,e[7]=0,e[8]=l,e[9]=c,e[10]=f,e[11]=u,e[12]=0,e[13]=0,e[14]=p,e[15]=0,e}var Y=null,ni=new ArrayBuffer(4),ii=new Float32Array(ni),ri=new Uint32Array(ni);function oi(e){Y||=si(),e=xt(e,-65504,65504),ii[0]=e;let t=ri[0],n=t>>23&511;return Y.baseTable[n]+((t&8388607)>>Y.shiftTable[n])}function ai(e){Y||=si();let t=e>>10;return ri[0]=Y.mantissaTable[Y.offsetTable[t]+(e&1023)]+Y.exponentTable[t],ii[0]}function si(){let e=new Uint32Array(512),t=new Uint32Array(512);for(let o=0;o<256;++o){let a=o-127;a<-27?(e[o]=0,e[o|256]=32768,t[o]=24,t[o|256]=24):a<-14?(e[o]=1024>>-a-14,e[o|256]=1024>>-a-14|32768,t[o]=-a-1,t[o|256]=-a-1):a<=15?(e[o]=a+15<<10,e[o|256]=a+15<<10|32768,t[o]=13,t[o|256]=13):a<128?(e[o]=31744,e[o|256]=64512,t[o]=24,t[o|256]=24):(e[o]=31744,e[o|256]=64512,t[o]=13,t[o|256]=13)}let n=new Uint32Array(2048),i=new Uint32Array(64),r=new Uint32Array(64);for(let o=1;o<1024;++o){let a=o<<13,s=0;for(;!(a&8388608);)a<<=1,s-=8388608;a&=-8388609,s+=947912704,n[o]=a|s}for(let o=1024;o<2048;++o)n[o]=939524096+(o-1024<<13);for(let o=1;o<31;++o)i[o]=o<<23;i[31]=1199570944,i[32]=2147483648;for(let o=33;o<63;++o)i[o]=2147483648+(o-32<<23);i[63]=3347054592;for(let o=1;o<64;++o)o!==32&&(r[o]=1024);return{baseTable:e,shiftTable:t,mantissaTable:n,exponentTable:i,offsetTable:r}}function ie(e,t=[],n=0){let i=Math.fround(e),r=e-i;return t[n]=i,t[n+1]=r,t}function _e(e){return e-Math.fround(e)}function he(e){let t=new Float32Array(32);for(let n=0;n<4;++n)for(let i=0;i<4;++i){let r=n*4+i;ie(e[i*4+n],t,r*2)}return t}function re(e,t=!0){return e??t}function me(e=[0,0,0],t=!0){return t?e.map(n=>n/255):[...e]}function qe(e,t=!0){let n=me(e.slice(0,3),t),i=Number.isFinite(e[3]),r=i?e[3]:1;return[n[0],n[1],n[2],t&&i?r/255:r]}var na=`fn random(scale: vec3f, seed: f32) -> f32 {
|
|
105
129
|
return fract(sin(dot(scale + vec3f(seed), vec3f(12.9898, 78.233, 151.7182))) * 43758.5453 + seed);
|
|
106
130
|
}
|
|
107
|
-
`,
|
|
131
|
+
`,ia=`float random(vec3 scale, float seed) {
|
|
108
132
|
/* use the fragment position for a different seed per-pixel */
|
|
109
133
|
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
|
|
110
134
|
}
|
|
111
|
-
`,
|
|
135
|
+
`,li={name:"random",source:na,fs:ia};var ra=`#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
|
|
112
136
|
|
|
113
137
|
// All these functions are for substituting tan() function from Intel GPU only
|
|
114
138
|
const float TWO_PI = 6.2831854820251465;
|
|
@@ -258,7 +282,7 @@ float tan_fp32(float a) {
|
|
|
258
282
|
return tan(a);
|
|
259
283
|
#endif
|
|
260
284
|
}
|
|
261
|
-
`,
|
|
285
|
+
`,ci={name:"fp32",vs:ra};var Et=`
|
|
262
286
|
layout(std140) uniform fp64arithmeticUniforms {
|
|
263
287
|
uniform float ONE;
|
|
264
288
|
uniform float SPLIT;
|
|
@@ -457,18 +481,285 @@ vec2 sqrt_fp64(vec2 a) {
|
|
|
457
481
|
return sum_fp64(vec2(yn, 0.0), prod);
|
|
458
482
|
#endif
|
|
459
483
|
}
|
|
460
|
-
`;var
|
|
484
|
+
`;var fi=`struct Fp64ArithmeticUniforms {
|
|
461
485
|
ONE: f32,
|
|
462
486
|
SPLIT: f32,
|
|
463
487
|
};
|
|
464
488
|
|
|
465
489
|
@group(0) @binding(auto) var<uniform> fp64arithmetic : Fp64ArithmeticUniforms;
|
|
466
490
|
|
|
491
|
+
struct Fp64Bits {
|
|
492
|
+
sign: u32,
|
|
493
|
+
exponent: i32,
|
|
494
|
+
significand: vec2u,
|
|
495
|
+
isZero: bool,
|
|
496
|
+
isInf: bool,
|
|
497
|
+
isNan: bool,
|
|
498
|
+
};
|
|
499
|
+
|
|
467
500
|
fn fp64_nan(seed: f32) -> f32 {
|
|
468
501
|
let nanBits = 0x7fc00000u | select(0u, 1u, seed < 0.0);
|
|
469
502
|
return bitcast<f32>(nanBits);
|
|
470
503
|
}
|
|
471
504
|
|
|
505
|
+
fn fp64_u64_is_zero(value: vec2u) -> bool {
|
|
506
|
+
return value.x == 0u && value.y == 0u;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
fn fp64_u64_compare(a: vec2u, b: vec2u) -> i32 {
|
|
510
|
+
if (a.x != b.x) {
|
|
511
|
+
return select(-1, 1, a.x > b.x);
|
|
512
|
+
}
|
|
513
|
+
if (a.y != b.y) {
|
|
514
|
+
return select(-1, 1, a.y > b.y);
|
|
515
|
+
}
|
|
516
|
+
return 0;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
fn fp64_u64_add(a: vec2u, b: vec2u) -> vec2u {
|
|
520
|
+
let low = a.y + b.y;
|
|
521
|
+
let carry = select(0u, 1u, low < a.y);
|
|
522
|
+
return vec2u(a.x + b.x + carry, low);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
fn fp64_u64_sub(a: vec2u, b: vec2u) -> vec2u {
|
|
526
|
+
let borrow = select(0u, 1u, a.y < b.y);
|
|
527
|
+
return vec2u(a.x - b.x - borrow, a.y - b.y);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
fn fp64_u64_shift_left(value: vec2u, shift: u32) -> vec2u {
|
|
531
|
+
if (shift == 0u) {
|
|
532
|
+
return value;
|
|
533
|
+
}
|
|
534
|
+
if (shift < 32u) {
|
|
535
|
+
return vec2u((value.x << shift) | (value.y >> (32u - shift)), value.y << shift);
|
|
536
|
+
}
|
|
537
|
+
if (shift == 32u) {
|
|
538
|
+
return vec2u(value.y, 0u);
|
|
539
|
+
}
|
|
540
|
+
if (shift < 64u) {
|
|
541
|
+
return vec2u(value.y << (shift - 32u), 0u);
|
|
542
|
+
}
|
|
543
|
+
return vec2u(0u);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
fn fp64_u64_shift_right(value: vec2u, shift: u32) -> vec2u {
|
|
547
|
+
if (shift == 0u) {
|
|
548
|
+
return value;
|
|
549
|
+
}
|
|
550
|
+
if (shift < 32u) {
|
|
551
|
+
return vec2u(value.x >> shift, (value.y >> shift) | (value.x << (32u - shift)));
|
|
552
|
+
}
|
|
553
|
+
if (shift == 32u) {
|
|
554
|
+
return vec2u(0u, value.x);
|
|
555
|
+
}
|
|
556
|
+
if (shift < 64u) {
|
|
557
|
+
return vec2u(0u, value.x >> (shift - 32u));
|
|
558
|
+
}
|
|
559
|
+
return vec2u(0u);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
fn fp64_u64_get_bit(value: vec2u, bitIndex: u32) -> bool {
|
|
563
|
+
if (bitIndex >= 64u) {
|
|
564
|
+
return false;
|
|
565
|
+
}
|
|
566
|
+
if (bitIndex >= 32u) {
|
|
567
|
+
return ((value.x >> (bitIndex - 32u)) & 1u) != 0u;
|
|
568
|
+
}
|
|
569
|
+
return ((value.y >> bitIndex) & 1u) != 0u;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
fn fp64_u64_has_bits_below(value: vec2u, bitCount: u32) -> bool {
|
|
573
|
+
if (bitCount == 0u) {
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
if (bitCount >= 64u) {
|
|
577
|
+
return !fp64_u64_is_zero(value);
|
|
578
|
+
}
|
|
579
|
+
if (bitCount > 32u) {
|
|
580
|
+
let highBitCount = bitCount - 32u;
|
|
581
|
+
let highMask = (1u << highBitCount) - 1u;
|
|
582
|
+
return value.y != 0u || (value.x & highMask) != 0u;
|
|
583
|
+
}
|
|
584
|
+
if (bitCount == 32u) {
|
|
585
|
+
return value.y != 0u;
|
|
586
|
+
}
|
|
587
|
+
let lowMask = (1u << bitCount) - 1u;
|
|
588
|
+
return (value.y & lowMask) != 0u;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
fn fp64_u64_shift_right_sticky(value: vec2u, shift: u32) -> vec2u {
|
|
592
|
+
var shifted = fp64_u64_shift_right(value, shift);
|
|
593
|
+
if (fp64_u64_has_bits_below(value, shift)) {
|
|
594
|
+
shifted.y = shifted.y | 1u;
|
|
595
|
+
}
|
|
596
|
+
return shifted;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
fn fp64_u64_count_leading_zeros(value: vec2u) -> u32 {
|
|
600
|
+
if (value.x != 0u) {
|
|
601
|
+
return countLeadingZeros(value.x);
|
|
602
|
+
}
|
|
603
|
+
return 32u + countLeadingZeros(value.y);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
fn fp64_round_shift_right_to_u32(value: vec2u, shift: u32) -> u32 {
|
|
607
|
+
if (shift == 0u) {
|
|
608
|
+
return value.y;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
let truncated = fp64_u64_shift_right(value, shift);
|
|
612
|
+
var rounded = truncated.y;
|
|
613
|
+
let guard = fp64_u64_get_bit(value, shift - 1u);
|
|
614
|
+
let hasTrailingBits = fp64_u64_has_bits_below(value, shift - 1u);
|
|
615
|
+
if (guard && (hasTrailingBits || (rounded & 1u) == 1u)) {
|
|
616
|
+
rounded = rounded + 1u;
|
|
617
|
+
}
|
|
618
|
+
return rounded;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
fn fp64_make_f32_bits_from_u64(sign: u32, significand: vec2u, baseExponent: i32) -> u32 {
|
|
622
|
+
if (fp64_u64_is_zero(significand)) {
|
|
623
|
+
return sign << 31u;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
let leadingZeros = fp64_u64_count_leading_zeros(significand);
|
|
627
|
+
let mostSignificantBit = 63u - leadingZeros;
|
|
628
|
+
var exponent = baseExponent + i32(mostSignificantBit);
|
|
629
|
+
|
|
630
|
+
if (exponent > 127) {
|
|
631
|
+
return (sign << 31u) | 0x7f800000u;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
if (exponent >= -126) {
|
|
635
|
+
let shift = i32(mostSignificantBit) - 23;
|
|
636
|
+
var significand24: u32;
|
|
637
|
+
if (shift > 0) {
|
|
638
|
+
significand24 = fp64_round_shift_right_to_u32(significand, u32(shift));
|
|
639
|
+
} else {
|
|
640
|
+
significand24 = fp64_u64_shift_left(significand, u32(-shift)).y;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
if (significand24 >= 0x1000000u) {
|
|
644
|
+
significand24 = significand24 >> 1u;
|
|
645
|
+
exponent = exponent + 1;
|
|
646
|
+
if (exponent > 127) {
|
|
647
|
+
return (sign << 31u) | 0x7f800000u;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
return (sign << 31u) | (u32(exponent + 127) << 23u) | (significand24 & 0x7fffffu);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
let scaleExponent = baseExponent + 149;
|
|
655
|
+
var mantissa: u32;
|
|
656
|
+
if (scaleExponent >= 0) {
|
|
657
|
+
mantissa = fp64_u64_shift_left(significand, u32(scaleExponent)).y;
|
|
658
|
+
} else {
|
|
659
|
+
mantissa = fp64_round_shift_right_to_u32(significand, u32(-scaleExponent));
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
if (mantissa >= 0x800000u) {
|
|
663
|
+
return (sign << 31u) | 0x00800000u;
|
|
664
|
+
}
|
|
665
|
+
return (sign << 31u) | mantissa;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
fn fp64_decode_bits(bits: vec2u) -> Fp64Bits {
|
|
669
|
+
let sign = bits.x >> 31u;
|
|
670
|
+
let exponentBits = (bits.x >> 20u) & 0x7ffu;
|
|
671
|
+
let fractionHigh = bits.x & 0xfffffu;
|
|
672
|
+
let fractionLow = bits.y;
|
|
673
|
+
let fraction = vec2u(fractionHigh, fractionLow);
|
|
674
|
+
|
|
675
|
+
if (exponentBits == 0x7ffu) {
|
|
676
|
+
let isInf = fp64_u64_is_zero(fraction);
|
|
677
|
+
return Fp64Bits(sign, 0, vec2u(0u), false, isInf, !isInf);
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
if (exponentBits == 0u) {
|
|
681
|
+
let isZero = fp64_u64_is_zero(fraction);
|
|
682
|
+
return Fp64Bits(sign, -1022, fraction, isZero, false, false);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
return Fp64Bits(sign, i32(exponentBits) - 1023, vec2u((1u << 20u) | fractionHigh, fractionLow), false, false, false);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
fn fp64_finite_magnitude_compare(a: Fp64Bits, b: Fp64Bits) -> i32 {
|
|
689
|
+
if (a.exponent != b.exponent) {
|
|
690
|
+
return select(-1, 1, a.exponent > b.exponent);
|
|
691
|
+
}
|
|
692
|
+
return fp64_u64_compare(a.significand, b.significand);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
fn fp64_add_aligned_magnitudes_to_f32_bits(sign: u32, larger: Fp64Bits, smaller: Fp64Bits) -> u32 {
|
|
696
|
+
let largeSignificand = fp64_u64_shift_left(larger.significand, 3u);
|
|
697
|
+
let smallSignificand = fp64_u64_shift_right_sticky(
|
|
698
|
+
fp64_u64_shift_left(smaller.significand, 3u),
|
|
699
|
+
u32(larger.exponent - smaller.exponent)
|
|
700
|
+
);
|
|
701
|
+
let resultSignificand = fp64_u64_add(largeSignificand, smallSignificand);
|
|
702
|
+
return fp64_make_f32_bits_from_u64(sign, resultSignificand, larger.exponent - 55);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
fn fp64_sub_aligned_magnitudes_to_f32_bits(sign: u32, larger: Fp64Bits, smaller: Fp64Bits) -> u32 {
|
|
706
|
+
let largeSignificand = fp64_u64_shift_left(larger.significand, 3u);
|
|
707
|
+
let smallSignificand = fp64_u64_shift_right_sticky(
|
|
708
|
+
fp64_u64_shift_left(smaller.significand, 3u),
|
|
709
|
+
u32(larger.exponent - smaller.exponent)
|
|
710
|
+
);
|
|
711
|
+
let resultSignificand = fp64_u64_sub(largeSignificand, smallSignificand);
|
|
712
|
+
return fp64_make_f32_bits_from_u64(sign, resultSignificand, larger.exponent - 55);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// Subtract two raw binary64 values and round the exact result once to f32.
|
|
716
|
+
// The input words are canonical high/low words: .x contains sign/exponent/high
|
|
717
|
+
// fraction bits, and .y contains the low 32 fraction bits.
|
|
718
|
+
fn sub_fp64u32_to_f32_bits(aBits: vec2u, bBits: vec2u) -> u32 {
|
|
719
|
+
let a = fp64_decode_bits(aBits);
|
|
720
|
+
let b = fp64_decode_bits(bBits);
|
|
721
|
+
let bSubtractionSign = b.sign ^ 1u;
|
|
722
|
+
|
|
723
|
+
if (a.isNan || b.isNan) {
|
|
724
|
+
return 0x7fc00000u;
|
|
725
|
+
}
|
|
726
|
+
if (a.isInf && b.isInf) {
|
|
727
|
+
if (a.sign == bSubtractionSign) {
|
|
728
|
+
return (a.sign << 31u) | 0x7f800000u;
|
|
729
|
+
}
|
|
730
|
+
return 0x7fc00000u;
|
|
731
|
+
}
|
|
732
|
+
if (a.isInf) {
|
|
733
|
+
return (a.sign << 31u) | 0x7f800000u;
|
|
734
|
+
}
|
|
735
|
+
if (b.isInf) {
|
|
736
|
+
return (bSubtractionSign << 31u) | 0x7f800000u;
|
|
737
|
+
}
|
|
738
|
+
if (a.isZero && b.isZero) {
|
|
739
|
+
return select(0u, 0x80000000u, a.sign == 1u && b.sign == 0u);
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
let magnitudeComparison = fp64_finite_magnitude_compare(a, b);
|
|
743
|
+
if (a.sign == bSubtractionSign) {
|
|
744
|
+
if (magnitudeComparison >= 0) {
|
|
745
|
+
return fp64_add_aligned_magnitudes_to_f32_bits(a.sign, a, b);
|
|
746
|
+
}
|
|
747
|
+
return fp64_add_aligned_magnitudes_to_f32_bits(a.sign, b, a);
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
if (magnitudeComparison == 0) {
|
|
751
|
+
return 0u;
|
|
752
|
+
}
|
|
753
|
+
if (magnitudeComparison > 0) {
|
|
754
|
+
return fp64_sub_aligned_magnitudes_to_f32_bits(a.sign, a, b);
|
|
755
|
+
}
|
|
756
|
+
return fp64_sub_aligned_magnitudes_to_f32_bits(bSubtractionSign, b, a);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
fn sub_fp64u32_to_f32(aBits: vec2u, bBits: vec2u) -> f32 {
|
|
760
|
+
return bitcast<f32>(sub_fp64u32_to_f32_bits(aBits, bBits));
|
|
761
|
+
}
|
|
762
|
+
|
|
472
763
|
fn fp64_runtime_zero() -> f32 {
|
|
473
764
|
return fp64arithmetic.ONE * 0.0;
|
|
474
765
|
}
|
|
@@ -663,7 +954,7 @@ fn sqrt_fp64(a: vec2f) -> vec2f {
|
|
|
663
954
|
return sum_fp64(vec2f(yn, 0.0), prod);
|
|
664
955
|
#endif
|
|
665
956
|
}
|
|
666
|
-
`;var
|
|
957
|
+
`;var ui=`const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
|
|
667
958
|
const vec2 LOG2_FP64 = vec2(0.6931471824645996e+00, -1.9046542121259336e-09);
|
|
668
959
|
const vec2 PI_FP64 = vec2(3.1415927410125732, -8.742278012618954e-8);
|
|
669
960
|
const vec2 TWO_PI_FP64 = vec2(6.2831854820251465, -1.7484556025237907e-7);
|
|
@@ -1332,246 +1623,2254 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
|
|
|
1332
1623
|
vec4_dot_fp64(a, tmp, out_val[i]);
|
|
1333
1624
|
}
|
|
1334
1625
|
}
|
|
1335
|
-
`;var
|
|
1336
|
-
|
|
1337
|
-
|
|
1626
|
+
`;var oa={ONE:1,SPLIT:4097},Rt={name:"fp64arithmetic",source:fi,fs:Et,vs:Et,defaultUniforms:oa,uniformTypes:{ONE:"f32",SPLIT:"f32"},fp64ify:ie,fp64LowPart:_e,fp64ifyMatrix4:he},pi={name:"fp64",vs:ui,dependencies:[Rt],fp64ify:ie,fp64LowPart:_e,fp64ifyMatrix4:he};var gi=`const DGGS_H3_CELL_MODE: u32 = 1u;
|
|
1627
|
+
const DGGS_H3_MAX_RESOLUTION: u32 = 15u;
|
|
1628
|
+
const DGGS_H3_MAX_BASE_CELL: u32 = 121u;
|
|
1629
|
+
const DGGS_H3_UNUSED_DIGIT: u32 = 7u;
|
|
1630
|
+
const DGGS_H3_RES0_U_GNOMONIC: f32 = 0.381966011250105;
|
|
1631
|
+
const DGGS_H3_RSQRT7: f32 = 0.3779644730092272;
|
|
1632
|
+
const DGGS_H3_ONETHIRD: f32 = 0.3333333333333333;
|
|
1633
|
+
const DGGS_H3_AP7_ROT_RADS: f32 = 0.3334731722518321;
|
|
1634
|
+
const DGGS_H3_SQRT3_2: f32 = 0.8660254037844386;
|
|
1635
|
+
const DGGS_S2_MAX_LEVEL: u32 = 30u;
|
|
1636
|
+
const DGGS_GEOHASH_MAX_LENGTH: u32 = 12u;
|
|
1637
|
+
const DGGS_GEOHASH_LENGTH_BIT_OFFSET: u32 = 60u;
|
|
1638
|
+
const DGGS_QUADKEY_MAX_LENGTH: u32 = 29u;
|
|
1639
|
+
const DGGS_QUADKEY_LENGTH_BIT_OFFSET: u32 = 58u;
|
|
1640
|
+
const DGGS_A5_FIRST_HILBERT_RESOLUTION: u32 = 2u;
|
|
1641
|
+
const DGGS_A5_MAX_RESOLUTION: u32 = 30u;
|
|
1642
|
+
const DGGS_A5_HILBERT_START_BIT: u32 = 58u;
|
|
1643
|
+
const DGGS_PI: f32 = 3.141592653589793;
|
|
1644
|
+
const DGGS_TWO_PI: f32 = 6.283185307179586;
|
|
1645
|
+
const DGGS_TWO_PI_OVER_5: f32 = 1.2566370614359172;
|
|
1646
|
+
const DGGS_PI_OVER_5: f32 = 0.6283185307179586;
|
|
1647
|
+
const DGGS_PI_OVER_2: f32 = 1.5707963267948966;
|
|
1648
|
+
const DGGS_A5_DISTANCE_TO_EDGE: f32 = 0.6180339887498949;
|
|
1649
|
+
const DGGS_A5_REFLECTED_TRIANGLE_SCALE: f32 = 3.23606797749979;
|
|
1650
|
+
const DGGS_A5_LONGITUDE_OFFSET: f32 = 93.0;
|
|
1651
|
+
const DGGS_RADIANS_TO_DEGREES: f32 = 57.29577951308232;
|
|
1652
|
+
const DGGS_DEGREES_TO_RADIANS: f32 = 0.017453292519943295;
|
|
1653
|
+
const DGGS_U64_HIGH_WORD_FLOAT_SCALE: f32 = 4294967296.0;
|
|
1338
1654
|
|
|
1339
|
-
|
|
1340
|
-
|
|
1655
|
+
// DGGS 64-bit helper functions use canonical word order vec2u(high, low).
|
|
1656
|
+
// Arrow BigInt64/BigUint64 buffers are read as little-endian vec2u(low, high),
|
|
1657
|
+
// so storage-buffer reads should pass through dggs_u64_from_little_endian_words().
|
|
1658
|
+
fn dggs_u64_make(high: u32, low: u32) -> vec2u {
|
|
1659
|
+
return vec2u(high, low);
|
|
1341
1660
|
}
|
|
1342
1661
|
|
|
1343
|
-
|
|
1344
|
-
return
|
|
1662
|
+
fn dggs_u64_from_little_endian_words(words: vec2u) -> vec2u {
|
|
1663
|
+
return words.yx;
|
|
1345
1664
|
}
|
|
1346
1665
|
|
|
1347
|
-
|
|
1348
|
-
return
|
|
1666
|
+
fn dggs_u64_to_little_endian_words(value: vec2u) -> vec2u {
|
|
1667
|
+
return value.yx;
|
|
1349
1668
|
}
|
|
1350
1669
|
|
|
1351
|
-
|
|
1352
|
-
return
|
|
1670
|
+
fn dggs_u64_high(value: vec2u) -> u32 {
|
|
1671
|
+
return value.x;
|
|
1353
1672
|
}
|
|
1354
1673
|
|
|
1355
|
-
|
|
1356
|
-
return
|
|
1674
|
+
fn dggs_u64_low(value: vec2u) -> u32 {
|
|
1675
|
+
return value.y;
|
|
1357
1676
|
}
|
|
1358
1677
|
|
|
1359
|
-
|
|
1360
|
-
return
|
|
1678
|
+
fn dggs_u64_is_zero(value: vec2u) -> bool {
|
|
1679
|
+
return value.x == 0u && value.y == 0u;
|
|
1361
1680
|
}
|
|
1362
|
-
`,Ao=`struct floatColorsUniforms {
|
|
1363
|
-
useByteColors: f32
|
|
1364
|
-
};
|
|
1365
|
-
|
|
1366
|
-
@group(0) @binding(auto) var<uniform> floatColors : floatColorsUniforms;
|
|
1367
1681
|
|
|
1368
|
-
fn
|
|
1369
|
-
return
|
|
1682
|
+
fn dggs_u64_equal(a: vec2u, b: vec2u) -> bool {
|
|
1683
|
+
return a.x == b.x && a.y == b.y;
|
|
1370
1684
|
}
|
|
1371
1685
|
|
|
1372
|
-
fn
|
|
1373
|
-
|
|
1686
|
+
fn dggs_u64_compare(a: vec2u, b: vec2u) -> i32 {
|
|
1687
|
+
if (a.x != b.x) {
|
|
1688
|
+
return select(-1, 1, a.x > b.x);
|
|
1689
|
+
}
|
|
1690
|
+
if (a.y != b.y) {
|
|
1691
|
+
return select(-1, 1, a.y > b.y);
|
|
1692
|
+
}
|
|
1693
|
+
return 0;
|
|
1374
1694
|
}
|
|
1375
1695
|
|
|
1376
|
-
fn
|
|
1377
|
-
return
|
|
1696
|
+
fn dggs_u64_less(a: vec2u, b: vec2u) -> bool {
|
|
1697
|
+
return dggs_u64_compare(a, b) < 0;
|
|
1378
1698
|
}
|
|
1379
1699
|
|
|
1380
|
-
fn
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
inputColor.a > 0.0
|
|
1385
|
-
);
|
|
1700
|
+
fn dggs_u64_add(a: vec2u, b: vec2u) -> vec2u {
|
|
1701
|
+
let low = a.y + b.y;
|
|
1702
|
+
let carry = select(0u, 1u, low < a.y);
|
|
1703
|
+
return vec2u(a.x + b.x + carry, low);
|
|
1386
1704
|
}
|
|
1387
1705
|
|
|
1388
|
-
fn
|
|
1389
|
-
|
|
1706
|
+
fn dggs_u64_subtract(a: vec2u, b: vec2u) -> vec2u {
|
|
1707
|
+
let borrow = select(0u, 1u, a.y < b.y);
|
|
1708
|
+
return vec2u(a.x - b.x - borrow, a.y - b.y);
|
|
1390
1709
|
}
|
|
1391
1710
|
|
|
1392
|
-
fn
|
|
1393
|
-
return
|
|
1711
|
+
fn dggs_u64_to_f32(value: vec2u) -> f32 {
|
|
1712
|
+
return f32(value.x) * DGGS_U64_HIGH_WORD_FLOAT_SCALE + f32(value.y);
|
|
1394
1713
|
}
|
|
1395
|
-
`,X={name:"floatColors",props:{},uniforms:{},vs:yr,fs:yr,source:Ao,uniformTypes:{useByteColors:"f32"},defaultUniforms:{useByteColors:!0}};var Ro=[0,1,1,1],Eo=`layout(std140) uniform pickingUniforms {
|
|
1396
|
-
float isActive;
|
|
1397
|
-
float isAttribute;
|
|
1398
|
-
float isHighlightActive;
|
|
1399
|
-
float useByteColors;
|
|
1400
|
-
vec3 highlightedObjectColor;
|
|
1401
|
-
vec4 highlightColor;
|
|
1402
|
-
} picking;
|
|
1403
|
-
|
|
1404
|
-
out vec4 picking_vRGBcolor_Avalid;
|
|
1405
1714
|
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
return picking.useByteColors > 0.5 ? color / 255.0 : color;
|
|
1715
|
+
fn dggs_i64_from_little_endian_words(words: vec2u) -> vec2u {
|
|
1716
|
+
return dggs_u64_from_little_endian_words(words);
|
|
1409
1717
|
}
|
|
1410
1718
|
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
return picking.useByteColors > 0.5 ? color / 255.0 : color;
|
|
1719
|
+
fn dggs_i64_to_little_endian_words(value: vec2u) -> vec2u {
|
|
1720
|
+
return dggs_u64_to_little_endian_words(value);
|
|
1414
1721
|
}
|
|
1415
1722
|
|
|
1416
|
-
|
|
1417
|
-
return
|
|
1723
|
+
fn dggs_i64_is_negative(value: vec2u) -> bool {
|
|
1724
|
+
return (value.x & 0x80000000u) != 0u;
|
|
1418
1725
|
}
|
|
1419
1726
|
|
|
1420
|
-
|
|
1421
|
-
return
|
|
1727
|
+
fn dggs_i64_negate(value: vec2u) -> vec2u {
|
|
1728
|
+
return dggs_u64_add(vec2u(~value.x, ~value.y), vec2u(0u, 1u));
|
|
1422
1729
|
}
|
|
1423
1730
|
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1731
|
+
fn dggs_i64_compare(a: vec2u, b: vec2u) -> i32 {
|
|
1732
|
+
let highA = bitcast<i32>(a.x);
|
|
1733
|
+
let highB = bitcast<i32>(b.x);
|
|
1734
|
+
if (highA != highB) {
|
|
1735
|
+
return select(-1, 1, highA > highB);
|
|
1736
|
+
}
|
|
1737
|
+
if (a.y != b.y) {
|
|
1738
|
+
return select(-1, 1, a.y > b.y);
|
|
1739
|
+
}
|
|
1740
|
+
return 0;
|
|
1429
1741
|
}
|
|
1430
1742
|
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
if (bool(picking.isActive)) {
|
|
1436
|
-
// Use alpha as the validity flag. If pickingColor is [0, 0, 0] fragment is non-pickable
|
|
1437
|
-
picking_vRGBcolor_Avalid.a = float(picking_isColorValid(pickingColor));
|
|
1743
|
+
fn dggs_i64_less(a: vec2u, b: vec2u) -> bool {
|
|
1744
|
+
return dggs_i64_compare(a, b) < 0;
|
|
1745
|
+
}
|
|
1438
1746
|
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
picking_vRGBcolor_Avalid.rgb = pickingColor;
|
|
1442
|
-
}
|
|
1443
|
-
} else {
|
|
1444
|
-
// Do the comparison with selected item color in vertex shader as it should mean fewer compares
|
|
1445
|
-
picking_vRGBcolor_Avalid.a = float(isVertexHighlighted(pickingColor));
|
|
1446
|
-
}
|
|
1747
|
+
fn dggs_i64_subtract(a: vec2u, b: vec2u) -> vec2u {
|
|
1748
|
+
return dggs_u64_subtract(a, b);
|
|
1447
1749
|
}
|
|
1448
1750
|
|
|
1449
|
-
|
|
1450
|
-
if (
|
|
1451
|
-
|
|
1751
|
+
fn dggs_i64_to_f32(value: vec2u) -> f32 {
|
|
1752
|
+
if (dggs_i64_is_negative(value)) {
|
|
1753
|
+
return -dggs_u64_to_f32(dggs_i64_negate(value));
|
|
1452
1754
|
}
|
|
1755
|
+
return dggs_u64_to_f32(value);
|
|
1453
1756
|
}
|
|
1454
1757
|
|
|
1455
|
-
|
|
1456
|
-
if (
|
|
1457
|
-
|
|
1758
|
+
fn dggs_u32_mask_low(bitCount: u32) -> u32 {
|
|
1759
|
+
if (bitCount == 0u) {
|
|
1760
|
+
return 0u;
|
|
1458
1761
|
}
|
|
1762
|
+
if (bitCount >= 32u) {
|
|
1763
|
+
return 0xffffffffu;
|
|
1764
|
+
}
|
|
1765
|
+
return (1u << bitCount) - 1u;
|
|
1459
1766
|
}
|
|
1460
1767
|
|
|
1461
|
-
|
|
1462
|
-
if (
|
|
1463
|
-
|
|
1768
|
+
fn dggs_u64_shift_left(value: vec2u, shift: u32) -> vec2u {
|
|
1769
|
+
if (shift == 0u) {
|
|
1770
|
+
return value;
|
|
1464
1771
|
}
|
|
1772
|
+
if (shift < 32u) {
|
|
1773
|
+
return vec2u((value.x << shift) | (value.y >> (32u - shift)), value.y << shift);
|
|
1774
|
+
}
|
|
1775
|
+
if (shift == 32u) {
|
|
1776
|
+
return vec2u(value.y, 0u);
|
|
1777
|
+
}
|
|
1778
|
+
if (shift < 64u) {
|
|
1779
|
+
return vec2u(value.y << (shift - 32u), 0u);
|
|
1780
|
+
}
|
|
1781
|
+
return vec2u(0u);
|
|
1465
1782
|
}
|
|
1466
|
-
`,Io=`layout(std140) uniform pickingUniforms {
|
|
1467
|
-
float isActive;
|
|
1468
|
-
float isAttribute;
|
|
1469
|
-
float isHighlightActive;
|
|
1470
|
-
float useByteColors;
|
|
1471
|
-
vec3 highlightedObjectColor;
|
|
1472
|
-
vec4 highlightColor;
|
|
1473
|
-
} picking;
|
|
1474
|
-
|
|
1475
|
-
in vec4 picking_vRGBcolor_Avalid;
|
|
1476
1783
|
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
vec4 picking_filterHighlightColor(vec4 color) {
|
|
1481
|
-
// If we are still picking, we don't highlight
|
|
1482
|
-
if (picking.isActive > 0.5) {
|
|
1483
|
-
return color;
|
|
1784
|
+
fn dggs_u64_shift_right(value: vec2u, shift: u32) -> vec2u {
|
|
1785
|
+
if (shift == 0u) {
|
|
1786
|
+
return value;
|
|
1484
1787
|
}
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
if (selected) {
|
|
1489
|
-
// Blend in highlight color based on its alpha value
|
|
1490
|
-
float highLightAlpha = picking.highlightColor.a;
|
|
1491
|
-
float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
|
|
1492
|
-
float highLightRatio = highLightAlpha / blendedAlpha;
|
|
1493
|
-
|
|
1494
|
-
vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);
|
|
1495
|
-
return vec4(blendedRGB, blendedAlpha);
|
|
1496
|
-
} else {
|
|
1497
|
-
return color;
|
|
1788
|
+
if (shift < 32u) {
|
|
1789
|
+
return vec2u(value.x >> shift, (value.y >> shift) | (value.x << (32u - shift)));
|
|
1498
1790
|
}
|
|
1791
|
+
if (shift == 32u) {
|
|
1792
|
+
return vec2u(0u, value.x);
|
|
1793
|
+
}
|
|
1794
|
+
if (shift < 64u) {
|
|
1795
|
+
return vec2u(0u, value.x >> (shift - 32u));
|
|
1796
|
+
}
|
|
1797
|
+
return vec2u(0u);
|
|
1499
1798
|
}
|
|
1500
1799
|
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
vec4 picking_filterPickingColor(vec4 color) {
|
|
1505
|
-
if (bool(picking.isActive)) {
|
|
1506
|
-
if (picking_vRGBcolor_Avalid.a == 0.0) {
|
|
1507
|
-
discard;
|
|
1508
|
-
}
|
|
1509
|
-
return picking_vRGBcolor_Avalid;
|
|
1800
|
+
fn dggs_u64_extract_bits(value: vec2u, bitOffset: u32, bitCount: u32) -> u32 {
|
|
1801
|
+
if (bitCount == 0u || bitOffset >= 64u) {
|
|
1802
|
+
return 0u;
|
|
1510
1803
|
}
|
|
1511
|
-
|
|
1804
|
+
let shifted = dggs_u64_shift_right(value, bitOffset);
|
|
1805
|
+
return shifted.y & dggs_u32_mask_low(bitCount);
|
|
1512
1806
|
}
|
|
1513
1807
|
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1808
|
+
fn dggs_u64_set_bits(value: vec2u, bitOffset: u32, bitCount: u32, bits: u32) -> vec2u {
|
|
1809
|
+
if (bitCount == 0u || bitOffset >= 64u) {
|
|
1810
|
+
return value;
|
|
1811
|
+
}
|
|
1812
|
+
let bitMask = dggs_u32_mask_low(bitCount);
|
|
1813
|
+
let fieldMask = dggs_u64_shift_left(vec2u(0u, bitMask), bitOffset);
|
|
1814
|
+
let fieldBits = dggs_u64_shift_left(vec2u(0u, bits & bitMask), bitOffset);
|
|
1815
|
+
return (value & vec2u(~fieldMask.x, ~fieldMask.y)) | fieldBits;
|
|
1521
1816
|
}
|
|
1522
|
-
`,Nr={props:{},uniforms:{},name:"picking",uniformTypes:{isActive:"f32",isAttribute:"f32",isHighlightActive:"f32",useByteColors:"f32",highlightedObjectColor:"vec3<f32>",highlightColor:"vec4<f32>"},defaultUniforms:{isActive:!1,isAttribute:!1,isHighlightActive:!1,useByteColors:!0,highlightedObjectColor:[0,0,0],highlightColor:Ro},vs:Eo,fs:Io,getUniforms:Co};function Co(e={},t){let r={},n=Y(e.useByteColors,!0);if(e.highlightedObjectColor!==void 0)if(e.highlightedObjectColor===null)r.isHighlightActive=!1;else{r.isHighlightActive=!0;let o=e.highlightedObjectColor.slice(0,3);r.highlightedObjectColor=o}return e.highlightColor&&(r.highlightColor=Pe(e.highlightColor,n)),e.isActive!==void 0&&(r.isActive=Boolean(e.isActive),r.isAttribute=Boolean(e.isAttribute)),e.useByteColors!==void 0&&(r.useByteColors=Boolean(e.useByteColors)),r}var ce=20,yo=`
|
|
1523
|
-
struct skinUniforms {
|
|
1524
|
-
jointMatrix: array<mat4x4<f32>, ${ce}>,
|
|
1525
|
-
};
|
|
1526
|
-
|
|
1527
|
-
@group(0) @binding(auto) var<uniform> skin: skinUniforms;
|
|
1528
1817
|
|
|
1529
|
-
fn
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1818
|
+
fn dggs_u64_count_trailing_zeros(value: vec2u) -> u32 {
|
|
1819
|
+
if (value.y != 0u) {
|
|
1820
|
+
return countTrailingZeros(value.y);
|
|
1821
|
+
}
|
|
1822
|
+
if (value.x != 0u) {
|
|
1823
|
+
return 32u + countTrailingZeros(value.x);
|
|
1824
|
+
}
|
|
1825
|
+
return 64u;
|
|
1534
1826
|
}
|
|
1535
|
-
`,No=`
|
|
1536
|
-
layout(std140) uniform skinUniforms {
|
|
1537
|
-
mat4 jointMatrix[SKIN_MAX_JOINTS];
|
|
1538
|
-
} skin;
|
|
1539
1827
|
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1828
|
+
struct DggsA5Cell {
|
|
1829
|
+
origin : u32,
|
|
1830
|
+
segment : u32,
|
|
1831
|
+
resolution : u32,
|
|
1832
|
+
valid : u32,
|
|
1833
|
+
quintantShift : u32,
|
|
1834
|
+
hilbertResolution : u32,
|
|
1835
|
+
};
|
|
1546
1836
|
|
|
1547
|
-
|
|
1837
|
+
struct DggsA5Anchor {
|
|
1838
|
+
q : u32,
|
|
1839
|
+
offset : vec2i,
|
|
1840
|
+
flips : vec2i,
|
|
1841
|
+
orientation : u32,
|
|
1842
|
+
quintant : u32,
|
|
1843
|
+
};
|
|
1548
1844
|
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1845
|
+
struct DggsA5FaceTriangle {
|
|
1846
|
+
a : vec2f,
|
|
1847
|
+
b : vec2f,
|
|
1848
|
+
c : vec2f,
|
|
1552
1849
|
};
|
|
1553
1850
|
|
|
1554
|
-
struct
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1851
|
+
struct DggsA5SphericalTriangle {
|
|
1852
|
+
a : vec3f,
|
|
1853
|
+
b : vec3f,
|
|
1854
|
+
c : vec3f,
|
|
1558
1855
|
};
|
|
1559
1856
|
|
|
1560
|
-
struct
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
vec3 attenuation;
|
|
1565
|
-
vec2 coneCos;
|
|
1857
|
+
struct DggsH3FaceIJK {
|
|
1858
|
+
face : u32,
|
|
1859
|
+
coord : vec3i,
|
|
1860
|
+
valid : u32,
|
|
1566
1861
|
};
|
|
1567
1862
|
|
|
1568
|
-
struct
|
|
1569
|
-
|
|
1570
|
-
|
|
1863
|
+
struct DggsH3BoundaryVertex {
|
|
1864
|
+
face : u32,
|
|
1865
|
+
coord : vec3i,
|
|
1866
|
+
resolution : u32,
|
|
1867
|
+
valid : u32,
|
|
1571
1868
|
};
|
|
1572
1869
|
|
|
1573
|
-
|
|
1574
|
-
|
|
1870
|
+
fn dggs_boundary_point_to_fp64_split(point : vec2f) -> vec4f {
|
|
1871
|
+
return vec4f(point.x, point.y, 0.0, 0.0);
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
fn dggs_a5_positive_mod_i32(value : i32, modulus : i32) -> i32 {
|
|
1875
|
+
return ((value % modulus) + modulus) % modulus;
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
fn dggs_a5_has_bit(index : vec2u, bitOffset : u32) -> bool {
|
|
1879
|
+
return dggs_u64_extract_bits(index, bitOffset, 1u) != 0u;
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
fn dggs_a5_get_resolution(index : vec2u) -> u32 {
|
|
1883
|
+
if (dggs_u64_is_zero(index)) {
|
|
1884
|
+
return 0u;
|
|
1885
|
+
}
|
|
1886
|
+
if (
|
|
1887
|
+
dggs_a5_has_bit(index, 0u) ||
|
|
1888
|
+
dggs_u64_extract_bits(index, 0u, 3u) == 4u ||
|
|
1889
|
+
dggs_u64_extract_bits(index, 0u, 5u) == 16u
|
|
1890
|
+
) {
|
|
1891
|
+
return DGGS_A5_MAX_RESOLUTION;
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
var resolution = DGGS_A5_MAX_RESOLUTION - 1u;
|
|
1895
|
+
var shifted = dggs_u64_shift_right(index, 1u);
|
|
1896
|
+
if (dggs_u64_is_zero(shifted)) {
|
|
1897
|
+
return 0u;
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
var remaining = shifted.y;
|
|
1901
|
+
if (remaining == 0u) {
|
|
1902
|
+
shifted = dggs_u64_shift_right(shifted, 32u);
|
|
1903
|
+
resolution -= 16u;
|
|
1904
|
+
remaining = shifted.y;
|
|
1905
|
+
}
|
|
1906
|
+
if ((remaining & 0xffffu) == 0u) {
|
|
1907
|
+
remaining >>= 16u;
|
|
1908
|
+
resolution -= 8u;
|
|
1909
|
+
}
|
|
1910
|
+
if (resolution >= 6u && (remaining & 0xffu) == 0u) {
|
|
1911
|
+
remaining >>= 8u;
|
|
1912
|
+
resolution -= 4u;
|
|
1913
|
+
}
|
|
1914
|
+
if (resolution >= 4u && (remaining & 0xfu) == 0u) {
|
|
1915
|
+
remaining >>= 4u;
|
|
1916
|
+
resolution -= 2u;
|
|
1917
|
+
}
|
|
1918
|
+
loop {
|
|
1919
|
+
if ((remaining & 1u) != 0u) {
|
|
1920
|
+
break;
|
|
1921
|
+
}
|
|
1922
|
+
if (resolution == 0u) {
|
|
1923
|
+
break;
|
|
1924
|
+
}
|
|
1925
|
+
resolution -= 1u;
|
|
1926
|
+
remaining >>= select(2u, 1u, resolution < DGGS_A5_FIRST_HILBERT_RESOLUTION);
|
|
1927
|
+
}
|
|
1928
|
+
return resolution;
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
fn dggs_a5_get_origin_first_quintant(origin : u32) -> u32 {
|
|
1932
|
+
let values = array<u32, 12>(
|
|
1933
|
+
4u, 2u, 3u, 0u, 2u, 4u, 2u, 2u, 3u, 0u, 3u, 0u
|
|
1934
|
+
);
|
|
1935
|
+
return values[min(origin, 11u)];
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
fn dggs_a5_get_origin_step(origin : u32) -> i32 {
|
|
1939
|
+
let values = array<i32, 12>(
|
|
1940
|
+
-1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1
|
|
1941
|
+
);
|
|
1942
|
+
return values[min(origin, 11u)];
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
fn dggs_a5_get_origin_orientation(origin : u32, faceRelativeQuintant : u32) -> u32 {
|
|
1946
|
+
// Orientation codes: uv=0, vu=1, uw=2, wu=3, vw=4, wv=5.
|
|
1947
|
+
let values = array<u32, 60>(
|
|
1948
|
+
1u, 2u, 4u, 4u, 4u,
|
|
1949
|
+
1u, 0u, 5u, 3u, 2u,
|
|
1950
|
+
3u, 0u, 5u, 3u, 2u,
|
|
1951
|
+
3u, 0u, 5u, 3u, 2u,
|
|
1952
|
+
3u, 2u, 4u, 1u, 2u,
|
|
1953
|
+
1u, 0u, 5u, 3u, 2u,
|
|
1954
|
+
3u, 2u, 4u, 1u, 2u,
|
|
1955
|
+
3u, 2u, 4u, 1u, 2u,
|
|
1956
|
+
3u, 0u, 5u, 3u, 2u,
|
|
1957
|
+
1u, 0u, 5u, 3u, 2u,
|
|
1958
|
+
1u, 0u, 5u, 3u, 2u,
|
|
1959
|
+
3u, 2u, 4u, 1u, 2u
|
|
1960
|
+
);
|
|
1961
|
+
return values[min(origin, 11u) * 5u + min(faceRelativeQuintant, 4u)];
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
fn dggs_a5_get_origin_angle(origin : u32) -> f32 {
|
|
1965
|
+
if (origin == 0u || origin == 9u) {
|
|
1966
|
+
return 0.0;
|
|
1967
|
+
}
|
|
1968
|
+
return DGGS_PI_OVER_5;
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
fn dggs_a5_get_origin_quaternion(origin : u32) -> vec4f {
|
|
1972
|
+
let values = array<vec4f, 12>(
|
|
1973
|
+
vec4f(0.0, 0.0, 0.0, 1.0),
|
|
1974
|
+
vec4f(0.0, 0.525731112119, 0.0, 0.850650808352),
|
|
1975
|
+
vec4f(-0.5, 0.688190960236, 0.0, 0.525731112119),
|
|
1976
|
+
vec4f(-0.809016994375, -0.262865556060, 0.0, 0.525731112119),
|
|
1977
|
+
vec4f(-0.5, 0.162459848116, 0.0, 0.850650808352),
|
|
1978
|
+
vec4f(-0.309016994375, -0.425325404176, 0.0, 0.850650808352),
|
|
1979
|
+
vec4f(0.309016994375, -0.425325404176, 0.0, 0.850650808352),
|
|
1980
|
+
vec4f(0.809016994375, -0.262865556060, 0.0, 0.525731112119),
|
|
1981
|
+
vec4f(0.0, -0.850650808352, 0.0, 0.525731112119),
|
|
1982
|
+
vec4f(0.0, -1.0, 0.0, 0.0),
|
|
1983
|
+
vec4f(0.5, 0.688190960236, 0.0, 0.525731112119),
|
|
1984
|
+
vec4f(0.5, 0.162459848116, 0.0, 0.850650808352)
|
|
1985
|
+
);
|
|
1986
|
+
return values[min(origin, 11u)];
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
fn dggs_a5_quaternion_rotate(point : vec3f, quaternion : vec4f) -> vec3f {
|
|
1990
|
+
let q = quaternion.xyz;
|
|
1991
|
+
let t = 2.0 * cross(q, point);
|
|
1992
|
+
return point + quaternion.w * t + cross(q, t);
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
fn dggs_a5_deserialize(index : vec2u) -> DggsA5Cell {
|
|
1996
|
+
if (dggs_u64_is_zero(index)) {
|
|
1997
|
+
return DggsA5Cell(0u, 0u, 0u, 0u, DGGS_A5_HILBERT_START_BIT, 0u);
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
let resolution = dggs_a5_get_resolution(index);
|
|
2001
|
+
var quintantShift = DGGS_A5_HILBERT_START_BIT;
|
|
2002
|
+
var quintantOffset = 0u;
|
|
2003
|
+
if (resolution == DGGS_A5_MAX_RESOLUTION) {
|
|
2004
|
+
var markerBits = 5u;
|
|
2005
|
+
if (dggs_a5_has_bit(index, 0u)) {
|
|
2006
|
+
markerBits = 1u;
|
|
2007
|
+
} else if (dggs_a5_has_bit(index, 2u)) {
|
|
2008
|
+
markerBits = 3u;
|
|
2009
|
+
}
|
|
2010
|
+
quintantShift = DGGS_A5_HILBERT_START_BIT + markerBits;
|
|
2011
|
+
quintantOffset = select(select(40u, 32u, markerBits == 3u), 0u, markerBits == 1u);
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
let topBits = dggs_u64_shift_right(index, quintantShift).y + quintantOffset;
|
|
2015
|
+
if (resolution == 0u) {
|
|
2016
|
+
if (topBits >= 12u) {
|
|
2017
|
+
return DggsA5Cell(0u, 0u, resolution, 0u, quintantShift, 0u);
|
|
2018
|
+
}
|
|
2019
|
+
return DggsA5Cell(topBits, 0u, resolution, 1u, quintantShift, 0u);
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
let origin = topBits / 5u;
|
|
2023
|
+
if (origin >= 12u) {
|
|
2024
|
+
return DggsA5Cell(0u, 0u, resolution, 0u, quintantShift, 0u);
|
|
2025
|
+
}
|
|
2026
|
+
let segment = (topBits + dggs_a5_get_origin_first_quintant(origin)) % 5u;
|
|
2027
|
+
let hilbertResolution = select(0u, resolution - 1u, resolution >= 2u);
|
|
2028
|
+
return DggsA5Cell(origin, segment, resolution, 1u, quintantShift, hilbertResolution);
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
fn dggs_a5_segment_to_anchor_info(cell : DggsA5Cell) -> DggsA5Anchor {
|
|
2032
|
+
let firstQuintant = dggs_a5_get_origin_first_quintant(cell.origin);
|
|
2033
|
+
let faceRelativeQuintant = (cell.segment + 5u - firstQuintant) % 5u;
|
|
2034
|
+
let orientation = dggs_a5_get_origin_orientation(cell.origin, faceRelativeQuintant);
|
|
2035
|
+
let step = dggs_a5_get_origin_step(cell.origin);
|
|
2036
|
+
let quintant = u32(dggs_a5_positive_mod_i32(
|
|
2037
|
+
i32(firstQuintant) + step * i32(faceRelativeQuintant),
|
|
2038
|
+
5
|
|
2039
|
+
));
|
|
2040
|
+
return DggsA5Anchor(0u, vec2i(0), vec2i(1), orientation, quintant);
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
fn dggs_a5_is_reverse_orientation(orientation : u32) -> bool {
|
|
2044
|
+
return orientation == 1u || orientation == 3u || orientation == 4u;
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
fn dggs_a5_is_invert_j_orientation(orientation : u32) -> bool {
|
|
2048
|
+
return orientation == 5u || orientation == 4u;
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
fn dggs_a5_is_flip_ij_orientation(orientation : u32) -> bool {
|
|
2052
|
+
return orientation == 3u || orientation == 2u;
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
fn dggs_a5_pattern_value(index : u32, flipIj : bool) -> u32 {
|
|
2056
|
+
let pattern = array<u32, 8>(0u, 1u, 3u, 4u, 5u, 6u, 7u, 2u);
|
|
2057
|
+
let flippedPattern = array<u32, 8>(0u, 1u, 2u, 7u, 3u, 4u, 5u, 6u);
|
|
2058
|
+
return select(pattern[min(index, 7u)], flippedPattern[min(index, 7u)], flipIj);
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
fn dggs_a5_quaternary_to_flips(digit : u32) -> vec2i {
|
|
2062
|
+
if (digit == 1u) {
|
|
2063
|
+
return vec2i(1, -1);
|
|
2064
|
+
}
|
|
2065
|
+
if (digit == 3u) {
|
|
2066
|
+
return vec2i(-1, 1);
|
|
2067
|
+
}
|
|
2068
|
+
return vec2i(1, 1);
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
fn dggs_a5_quaternary_to_kj(digit : u32, flips : vec2i) -> vec2i {
|
|
2072
|
+
var p = vec2i(0);
|
|
2073
|
+
var q = vec2i(0);
|
|
2074
|
+
if (flips.x == 1 && flips.y == 1) {
|
|
2075
|
+
p = vec2i(1, 0);
|
|
2076
|
+
q = vec2i(0, 1);
|
|
2077
|
+
} else if (flips.x == -1 && flips.y == 1) {
|
|
2078
|
+
p = vec2i(0, -1);
|
|
2079
|
+
q = vec2i(-1, 0);
|
|
2080
|
+
} else if (flips.x == 1 && flips.y == -1) {
|
|
2081
|
+
p = vec2i(0, 1);
|
|
2082
|
+
q = vec2i(1, 0);
|
|
2083
|
+
} else {
|
|
2084
|
+
p = vec2i(-1, 0);
|
|
2085
|
+
q = vec2i(0, -1);
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
if (digit == 1u) {
|
|
2089
|
+
return p;
|
|
2090
|
+
}
|
|
2091
|
+
if (digit == 2u) {
|
|
2092
|
+
return p + q;
|
|
2093
|
+
}
|
|
2094
|
+
if (digit == 3u) {
|
|
2095
|
+
return q + 2 * p;
|
|
2096
|
+
}
|
|
2097
|
+
return vec2i(0);
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
fn dggs_a5_kj_to_ij(kj : vec2i) -> vec2i {
|
|
2101
|
+
return vec2i(kj.x - kj.y, kj.y);
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
fn dggs_a5_shift_digits(
|
|
2105
|
+
digits : ptr<function, array<u32, 29>>,
|
|
2106
|
+
digitIndex : u32,
|
|
2107
|
+
flips : vec2i,
|
|
2108
|
+
invertJ : bool,
|
|
2109
|
+
flipIj : bool
|
|
2110
|
+
) {
|
|
2111
|
+
if (digitIndex == 0u) {
|
|
2112
|
+
return;
|
|
2113
|
+
}
|
|
2114
|
+
let parentK = (*digits)[digitIndex];
|
|
2115
|
+
let childK = (*digits)[digitIndex - 1u];
|
|
2116
|
+
let flipSum = flips.x + flips.y;
|
|
2117
|
+
var needsShift = true;
|
|
2118
|
+
var first = true;
|
|
2119
|
+
if (invertJ != (flipSum == 0)) {
|
|
2120
|
+
needsShift = parentK == 1u || parentK == 2u;
|
|
2121
|
+
first = parentK == 1u;
|
|
2122
|
+
} else {
|
|
2123
|
+
needsShift = parentK < 2u;
|
|
2124
|
+
first = parentK == 0u;
|
|
2125
|
+
}
|
|
2126
|
+
if (!needsShift) {
|
|
2127
|
+
return;
|
|
2128
|
+
}
|
|
2129
|
+
let source = select(childK + 4u, childK, first);
|
|
2130
|
+
let destination = dggs_a5_pattern_value(source, flipIj);
|
|
2131
|
+
(*digits)[digitIndex - 1u] = destination % 4u;
|
|
2132
|
+
(*digits)[digitIndex] = u32(dggs_a5_positive_mod_i32(
|
|
2133
|
+
i32(parentK) + 4 + i32(destination / 4u) - i32(source / 4u),
|
|
2134
|
+
4
|
|
2135
|
+
));
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
fn dggs_a5_make_anchor(index : vec2u, cell : DggsA5Cell, anchorInfo : DggsA5Anchor) -> DggsA5Anchor {
|
|
2139
|
+
if (cell.hilbertResolution == 0u) {
|
|
2140
|
+
return anchorInfo;
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
let reverse = dggs_a5_is_reverse_orientation(anchorInfo.orientation);
|
|
2144
|
+
let invertJ = dggs_a5_is_invert_j_orientation(anchorInfo.orientation);
|
|
2145
|
+
let flipIj = dggs_a5_is_flip_ij_orientation(anchorInfo.orientation);
|
|
2146
|
+
let hilbertBits = 2u * cell.hilbertResolution;
|
|
2147
|
+
let sBitOffset = cell.quintantShift - hilbertBits;
|
|
2148
|
+
var digits : array<u32, 29>;
|
|
2149
|
+
var digitIndex = 0u;
|
|
2150
|
+
loop {
|
|
2151
|
+
if (digitIndex >= cell.hilbertResolution) {
|
|
2152
|
+
break;
|
|
2153
|
+
}
|
|
2154
|
+
var digit = dggs_u64_extract_bits(index, sBitOffset + 2u * digitIndex, 2u);
|
|
2155
|
+
if (reverse) {
|
|
2156
|
+
digit = 3u - digit;
|
|
2157
|
+
}
|
|
2158
|
+
digits[digitIndex] = digit;
|
|
2159
|
+
digitIndex += 1u;
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
var flips = vec2i(1, 1);
|
|
2163
|
+
digitIndex = cell.hilbertResolution;
|
|
2164
|
+
loop {
|
|
2165
|
+
if (digitIndex == 0u) {
|
|
2166
|
+
break;
|
|
2167
|
+
}
|
|
2168
|
+
digitIndex -= 1u;
|
|
2169
|
+
dggs_a5_shift_digits(&digits, digitIndex, flips, invertJ, flipIj);
|
|
2170
|
+
flips *= dggs_a5_quaternary_to_flips(digits[digitIndex]);
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
flips = vec2i(1, 1);
|
|
2174
|
+
var offset = vec2i(0);
|
|
2175
|
+
digitIndex = cell.hilbertResolution;
|
|
2176
|
+
loop {
|
|
2177
|
+
if (digitIndex == 0u) {
|
|
2178
|
+
break;
|
|
2179
|
+
}
|
|
2180
|
+
digitIndex -= 1u;
|
|
2181
|
+
offset *= 2;
|
|
2182
|
+
offset += dggs_a5_quaternary_to_kj(digits[digitIndex], flips);
|
|
2183
|
+
flips *= dggs_a5_quaternary_to_flips(digits[digitIndex]);
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2186
|
+
var anchorOffset = dggs_a5_kj_to_ij(offset);
|
|
2187
|
+
if (flipIj) {
|
|
2188
|
+
let originalOffset = anchorOffset;
|
|
2189
|
+
anchorOffset = originalOffset.yx;
|
|
2190
|
+
if (flips.x == -1) {
|
|
2191
|
+
anchorOffset += vec2i(-1, 1);
|
|
2192
|
+
}
|
|
2193
|
+
if (flips.y == -1) {
|
|
2194
|
+
anchorOffset -= vec2i(-1, 1);
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
if (invertJ) {
|
|
2198
|
+
let i = anchorOffset.x;
|
|
2199
|
+
let j = i32(1u << cell.hilbertResolution) - (i + anchorOffset.y);
|
|
2200
|
+
flips.x = -flips.x;
|
|
2201
|
+
anchorOffset.y = j;
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2204
|
+
return DggsA5Anchor(
|
|
2205
|
+
digits[0],
|
|
2206
|
+
anchorOffset,
|
|
2207
|
+
flips,
|
|
2208
|
+
anchorInfo.orientation,
|
|
2209
|
+
anchorInfo.quintant
|
|
2210
|
+
);
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2213
|
+
fn dggs_a5_rotate_face_point(point : vec2f, quintant : u32) -> vec2f {
|
|
2214
|
+
let angle = f32(quintant) * DGGS_TWO_PI_OVER_5;
|
|
2215
|
+
let cosine = cos(angle);
|
|
2216
|
+
let sine = sin(angle);
|
|
2217
|
+
return vec2f(point.x * cosine - point.y * sine, point.x * sine + point.y * cosine);
|
|
2218
|
+
}
|
|
2219
|
+
|
|
2220
|
+
fn dggs_a5_get_base_pentagon_vertex(vertexIndex : u32) -> vec2f {
|
|
2221
|
+
let vertices = array<vec2f, 5>(
|
|
2222
|
+
vec2f(0.0, 0.0),
|
|
2223
|
+
vec2f(0.199381847431, 0.375413822391),
|
|
2224
|
+
vec2f(0.618033988750, 0.449027976580),
|
|
2225
|
+
vec2f(0.817415836181, 0.073614154188),
|
|
2226
|
+
vec2f(0.418652141319, -0.073614154188)
|
|
2227
|
+
);
|
|
2228
|
+
return vertices[min(vertexIndex, 4u)];
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
fn dggs_a5_get_base_triangle_vertex(vertexIndex : u32) -> vec2f {
|
|
2232
|
+
let vertices = array<vec2f, 3>(
|
|
2233
|
+
vec2f(0.0, 0.0),
|
|
2234
|
+
vec2f(0.618033988750, 0.449027976580),
|
|
2235
|
+
vec2f(0.618033988750, -0.449027976580)
|
|
2236
|
+
);
|
|
2237
|
+
return vertices[min(vertexIndex, 2u)];
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
fn dggs_a5_get_face_vertex(vertexIndex : u32) -> vec2f {
|
|
2241
|
+
return dggs_a5_rotate_face_point(dggs_a5_get_base_triangle_vertex(1u), 4u - min(vertexIndex, 4u));
|
|
2242
|
+
}
|
|
2243
|
+
|
|
2244
|
+
fn dggs_a5_get_triangle_vertex(quintant : u32, vertexIndex : u32) -> vec2f {
|
|
2245
|
+
return dggs_a5_rotate_face_point(dggs_a5_get_base_triangle_vertex(vertexIndex), quintant);
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
fn dggs_a5_get_pentagon_vertex(
|
|
2249
|
+
anchor : DggsA5Anchor,
|
|
2250
|
+
hilbertResolution : u32,
|
|
2251
|
+
vertexIndex : u32
|
|
2252
|
+
) -> vec2f {
|
|
2253
|
+
let flipSum = anchor.flips.x + anchor.flips.y;
|
|
2254
|
+
let reflectsY = ((flipSum == -2 || flipSum == 2) && anchor.q > 1u) ||
|
|
2255
|
+
(flipSum == 0 && (anchor.q == 0u || anchor.q == 3u));
|
|
2256
|
+
let sourceIndex = select(vertexIndex, 4u - vertexIndex, reflectsY);
|
|
2257
|
+
var point = dggs_a5_get_base_pentagon_vertex(sourceIndex);
|
|
2258
|
+
|
|
2259
|
+
if (anchor.flips.x == 1 && anchor.flips.y == -1) {
|
|
2260
|
+
point = -point;
|
|
2261
|
+
}
|
|
2262
|
+
if (reflectsY) {
|
|
2263
|
+
point.y = -point.y;
|
|
2264
|
+
}
|
|
2265
|
+
if (anchor.flips.x == -1 && anchor.flips.y == -1) {
|
|
2266
|
+
point = -point;
|
|
2267
|
+
} else if (anchor.flips.x == -1) {
|
|
2268
|
+
point += vec2f(-0.618033988750, 0.449027976580);
|
|
2269
|
+
} else if (anchor.flips.y == -1) {
|
|
2270
|
+
point += vec2f(0.618033988750, -0.449027976580);
|
|
2271
|
+
}
|
|
2272
|
+
|
|
2273
|
+
let translation = vec2f(
|
|
2274
|
+
f32(anchor.offset.x) * 0.618033988750 + f32(anchor.offset.y) * 0.618033988750,
|
|
2275
|
+
f32(anchor.offset.x) * 0.449027976580 + f32(anchor.offset.y) * -0.449027976580
|
|
2276
|
+
);
|
|
2277
|
+
point = (point + translation) / f32(1u << hilbertResolution);
|
|
2278
|
+
return dggs_a5_rotate_face_point(point, anchor.quintant);
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2281
|
+
fn dggs_a5_get_shape_vertex_count(cell : DggsA5Cell) -> u32 {
|
|
2282
|
+
return select(5u, 3u, cell.resolution == 1u);
|
|
2283
|
+
}
|
|
2284
|
+
|
|
2285
|
+
fn dggs_a5_get_reversed_shape_index(vertexIndex : u32, shapeVertexCount : u32) -> u32 {
|
|
2286
|
+
if (vertexIndex == 0u || vertexIndex >= shapeVertexCount) {
|
|
2287
|
+
return 0u;
|
|
2288
|
+
}
|
|
2289
|
+
return shapeVertexCount - vertexIndex;
|
|
2290
|
+
}
|
|
2291
|
+
|
|
2292
|
+
fn dggs_a5_get_cell_shape_face_point(index : vec2u, cell : DggsA5Cell, shapeIndex : u32) -> vec2f {
|
|
2293
|
+
let anchorInfo = dggs_a5_segment_to_anchor_info(cell);
|
|
2294
|
+
if (cell.resolution == 0u) {
|
|
2295
|
+
return dggs_a5_get_face_vertex(shapeIndex);
|
|
2296
|
+
}
|
|
2297
|
+
if (cell.resolution == 1u) {
|
|
2298
|
+
return dggs_a5_get_triangle_vertex(anchorInfo.quintant, shapeIndex);
|
|
2299
|
+
}
|
|
2300
|
+
let anchor = dggs_a5_make_anchor(index, cell, anchorInfo);
|
|
2301
|
+
return dggs_a5_get_pentagon_vertex(anchor, cell.hilbertResolution, shapeIndex);
|
|
2302
|
+
}
|
|
2303
|
+
|
|
2304
|
+
fn dggs_a5_get_cell_center_face_point(index : vec2u, cell : DggsA5Cell) -> vec2f {
|
|
2305
|
+
let shapeVertexCount = dggs_a5_get_shape_vertex_count(cell);
|
|
2306
|
+
var center = vec2f(0.0);
|
|
2307
|
+
var vertexIndex = 0u;
|
|
2308
|
+
loop {
|
|
2309
|
+
if (vertexIndex >= shapeVertexCount) {
|
|
2310
|
+
break;
|
|
2311
|
+
}
|
|
2312
|
+
center += dggs_a5_get_cell_shape_face_point(index, cell, vertexIndex);
|
|
2313
|
+
vertexIndex += 1u;
|
|
2314
|
+
}
|
|
2315
|
+
return center / f32(shapeVertexCount);
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2318
|
+
fn dggs_a5_to_polar(point : vec2f) -> vec2f {
|
|
2319
|
+
return vec2f(length(point), atan2(point.y, point.x));
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2322
|
+
fn dggs_a5_to_cartesian(thetaPhi : vec2f) -> vec3f {
|
|
2323
|
+
let sinPhi = sin(thetaPhi.y);
|
|
2324
|
+
return vec3f(sinPhi * cos(thetaPhi.x), sinPhi * sin(thetaPhi.x), cos(thetaPhi.y));
|
|
2325
|
+
}
|
|
2326
|
+
|
|
2327
|
+
fn dggs_a5_normalize_vec3(point : vec3f) -> vec3f {
|
|
2328
|
+
let magnitude = length(point);
|
|
2329
|
+
if (magnitude < 1.0e-12) {
|
|
2330
|
+
return vec3f(0.0, 0.0, 1.0);
|
|
2331
|
+
}
|
|
2332
|
+
return point / magnitude;
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
fn dggs_a5_get_face_triangle_index(polar : vec2f) -> u32 {
|
|
2336
|
+
return u32(dggs_a5_positive_mod_i32(i32(floor(polar.y / DGGS_PI_OVER_5)), 10));
|
|
2337
|
+
}
|
|
2338
|
+
|
|
2339
|
+
fn dggs_a5_normalize_gamma(gamma : f32) -> f32 {
|
|
2340
|
+
let segment = gamma / DGGS_TWO_PI_OVER_5;
|
|
2341
|
+
return (segment - round(segment)) * DGGS_TWO_PI_OVER_5;
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2344
|
+
fn dggs_a5_should_reflect(polar : vec2f) -> bool {
|
|
2345
|
+
return polar.x * cos(dggs_a5_normalize_gamma(polar.y)) > DGGS_A5_DISTANCE_TO_EDGE;
|
|
2346
|
+
}
|
|
2347
|
+
|
|
2348
|
+
fn dggs_a5_get_base_face_triangle(faceTriangleIndex : u32) -> DggsA5FaceTriangle {
|
|
2349
|
+
let quintant = ((faceTriangleIndex + 1u) / 2u) % 5u;
|
|
2350
|
+
let center = dggs_a5_get_triangle_vertex(quintant, 0u);
|
|
2351
|
+
let corner1 = dggs_a5_get_triangle_vertex(quintant, 1u);
|
|
2352
|
+
let corner2 = dggs_a5_get_triangle_vertex(quintant, 2u);
|
|
2353
|
+
let edgeMidpoint = (corner1 + corner2) * 0.5;
|
|
2354
|
+
if ((faceTriangleIndex & 1u) == 0u) {
|
|
2355
|
+
return DggsA5FaceTriangle(center, edgeMidpoint, corner1);
|
|
2356
|
+
}
|
|
2357
|
+
return DggsA5FaceTriangle(center, corner2, edgeMidpoint);
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
fn dggs_a5_get_face_triangle_vertex(triangle : DggsA5FaceTriangle, vertexIndex : u32) -> vec2f {
|
|
2361
|
+
if (vertexIndex == 0u) {
|
|
2362
|
+
return triangle.a;
|
|
2363
|
+
}
|
|
2364
|
+
if (vertexIndex == 1u) {
|
|
2365
|
+
return triangle.b;
|
|
2366
|
+
}
|
|
2367
|
+
return triangle.c;
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
fn dggs_a5_get_reflected_face_triangle(
|
|
2371
|
+
faceTriangleIndex : u32,
|
|
2372
|
+
squashed : bool
|
|
2373
|
+
) -> DggsA5FaceTriangle {
|
|
2374
|
+
let baseTriangle = dggs_a5_get_base_face_triangle(faceTriangleIndex);
|
|
2375
|
+
let even = (faceTriangleIndex & 1u) == 0u;
|
|
2376
|
+
let midpoint = select(baseTriangle.c, baseTriangle.b, even);
|
|
2377
|
+
let scale = select(2.0, DGGS_A5_REFLECTED_TRIANGLE_SCALE, squashed);
|
|
2378
|
+
let reflectedA = -baseTriangle.a + midpoint * scale;
|
|
2379
|
+
return DggsA5FaceTriangle(reflectedA, baseTriangle.c, baseTriangle.b);
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
fn dggs_a5_get_face_triangle(
|
|
2383
|
+
faceTriangleIndex : u32,
|
|
2384
|
+
reflected : bool,
|
|
2385
|
+
squashed : bool
|
|
2386
|
+
) -> DggsA5FaceTriangle {
|
|
2387
|
+
if (reflected) {
|
|
2388
|
+
return dggs_a5_get_reflected_face_triangle(faceTriangleIndex, squashed);
|
|
2389
|
+
}
|
|
2390
|
+
return dggs_a5_get_base_face_triangle(faceTriangleIndex);
|
|
2391
|
+
}
|
|
2392
|
+
|
|
2393
|
+
fn dggs_a5_face_triangle_to_spherical_triangle(
|
|
2394
|
+
faceTriangleIndex : u32,
|
|
2395
|
+
origin : u32,
|
|
2396
|
+
reflected : bool
|
|
2397
|
+
) -> DggsA5SphericalTriangle {
|
|
2398
|
+
let faceTriangle = dggs_a5_get_face_triangle(faceTriangleIndex, reflected, true);
|
|
2399
|
+
let originAngle = dggs_a5_get_origin_angle(origin);
|
|
2400
|
+
let quaternion = dggs_a5_get_origin_quaternion(origin);
|
|
2401
|
+
|
|
2402
|
+
let polarA = dggs_a5_to_polar(faceTriangle.a);
|
|
2403
|
+
let polarB = dggs_a5_to_polar(faceTriangle.b);
|
|
2404
|
+
let polarC = dggs_a5_to_polar(faceTriangle.c);
|
|
2405
|
+
let sphericalA = dggs_a5_quaternion_rotate(
|
|
2406
|
+
dggs_a5_to_cartesian(vec2f(polarA.y + originAngle, atan(polarA.x))),
|
|
2407
|
+
quaternion
|
|
2408
|
+
);
|
|
2409
|
+
let sphericalB = dggs_a5_quaternion_rotate(
|
|
2410
|
+
dggs_a5_to_cartesian(vec2f(polarB.y + originAngle, atan(polarB.x))),
|
|
2411
|
+
quaternion
|
|
2412
|
+
);
|
|
2413
|
+
let sphericalC = dggs_a5_quaternion_rotate(
|
|
2414
|
+
dggs_a5_to_cartesian(vec2f(polarC.y + originAngle, atan(polarC.x))),
|
|
2415
|
+
quaternion
|
|
2416
|
+
);
|
|
2417
|
+
return DggsA5SphericalTriangle(
|
|
2418
|
+
dggs_a5_normalize_vec3(sphericalA),
|
|
2419
|
+
dggs_a5_normalize_vec3(sphericalB),
|
|
2420
|
+
dggs_a5_normalize_vec3(sphericalC)
|
|
2421
|
+
);
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
fn dggs_a5_face_to_barycentric(point : vec2f, triangle : DggsA5FaceTriangle) -> vec3f {
|
|
2425
|
+
let d31 = triangle.a - triangle.c;
|
|
2426
|
+
let d23 = triangle.c - triangle.b;
|
|
2427
|
+
let d3p = point - triangle.c;
|
|
2428
|
+
let determinant = d23.x * d31.y - d23.y * d31.x;
|
|
2429
|
+
if (abs(determinant) < 1.0e-12) {
|
|
2430
|
+
return vec3f(1.0, 0.0, 0.0);
|
|
2431
|
+
}
|
|
2432
|
+
let b0 = (d23.x * d3p.y - d23.y * d3p.x) / determinant;
|
|
2433
|
+
let b1 = (d31.x * d3p.y - d31.y * d3p.x) / determinant;
|
|
2434
|
+
return vec3f(b0, b1, 1.0 - (b0 + b1));
|
|
2435
|
+
}
|
|
2436
|
+
|
|
2437
|
+
fn dggs_a5_triangle_area(a : vec3f, b : vec3f, c : vec3f) -> f32 {
|
|
2438
|
+
let midA = dggs_a5_normalize_vec3((b + c) * 0.5);
|
|
2439
|
+
let midB = dggs_a5_normalize_vec3((c + a) * 0.5);
|
|
2440
|
+
let midC = dggs_a5_normalize_vec3((a + b) * 0.5);
|
|
2441
|
+
let tripleProduct = dot(midA, cross(midB, midC));
|
|
2442
|
+
let clamped = clamp(tripleProduct, -1.0, 1.0);
|
|
2443
|
+
if (abs(clamped) < 1.0e-8) {
|
|
2444
|
+
return 2.0 * clamped;
|
|
2445
|
+
}
|
|
2446
|
+
return asin(clamped) * 2.0;
|
|
2447
|
+
}
|
|
2448
|
+
|
|
2449
|
+
fn dggs_a5_spherical_triangle_area(triangle : DggsA5SphericalTriangle) -> f32 {
|
|
2450
|
+
return dggs_a5_triangle_area(triangle.a, triangle.b, triangle.c);
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
fn dggs_a5_vector_difference(a : vec3f, b : vec3f) -> f32 {
|
|
2454
|
+
let midpoint = dggs_a5_normalize_vec3((a + b) * 0.5);
|
|
2455
|
+
let crossProduct = cross(a, midpoint);
|
|
2456
|
+
let distance = length(crossProduct);
|
|
2457
|
+
if (distance < 1.0e-8) {
|
|
2458
|
+
return 0.5 * length(a - b);
|
|
2459
|
+
}
|
|
2460
|
+
return distance;
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
fn dggs_a5_slerp(a : vec3f, b : vec3f, t : f32) -> vec3f {
|
|
2464
|
+
let cosineGamma = clamp(dot(a, b), -1.0, 1.0);
|
|
2465
|
+
let gamma = acos(cosineGamma);
|
|
2466
|
+
if (gamma < 1.0e-8) {
|
|
2467
|
+
return dggs_a5_normalize_vec3(mix(a, b, t));
|
|
2468
|
+
}
|
|
2469
|
+
let sinGamma = sin(gamma);
|
|
2470
|
+
if (abs(sinGamma) < 1.0e-8) {
|
|
2471
|
+
return dggs_a5_normalize_vec3(mix(a, b, t));
|
|
2472
|
+
}
|
|
2473
|
+
let weightA = sin((1.0 - t) * gamma) / sinGamma;
|
|
2474
|
+
let weightB = sin(t * gamma) / sinGamma;
|
|
2475
|
+
return dggs_a5_normalize_vec3(weightA * a + weightB * b);
|
|
2476
|
+
}
|
|
2477
|
+
|
|
2478
|
+
fn dggs_a5_safe_acos(value : f32) -> f32 {
|
|
2479
|
+
if (value < 1.0e-3) {
|
|
2480
|
+
return 2.0 * value + value * value * value / 3.0;
|
|
2481
|
+
}
|
|
2482
|
+
return acos(clamp(1.0 - 2.0 * value * value, -1.0, 1.0));
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2485
|
+
fn dggs_a5_polyhedral_inverse_edge(a : vec3f, b : vec3f, edgeHeight : f32) -> vec3f {
|
|
2486
|
+
let difference = dggs_a5_vector_difference(a, b);
|
|
2487
|
+
let denominator = max(dggs_a5_safe_acos(difference), 1.0e-8);
|
|
2488
|
+
let interpolation = dggs_a5_safe_acos(clamp(edgeHeight, 0.0, 1.0) * difference) / denominator;
|
|
2489
|
+
return dggs_a5_slerp(a, b, clamp(interpolation, 0.0, 1.0));
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
fn dggs_a5_polyhedral_inverse(
|
|
2493
|
+
facePoint : vec2f,
|
|
2494
|
+
faceTriangle : DggsA5FaceTriangle,
|
|
2495
|
+
sphericalTriangle : DggsA5SphericalTriangle
|
|
2496
|
+
) -> vec3f {
|
|
2497
|
+
let barycentric = dggs_a5_face_to_barycentric(facePoint, faceTriangle);
|
|
2498
|
+
if (barycentric.x > 0.9999999) {
|
|
2499
|
+
return sphericalTriangle.a;
|
|
2500
|
+
}
|
|
2501
|
+
if (barycentric.y > 0.9999999) {
|
|
2502
|
+
return sphericalTriangle.b;
|
|
2503
|
+
}
|
|
2504
|
+
if (barycentric.z > 0.9999999) {
|
|
2505
|
+
return sphericalTriangle.c;
|
|
2506
|
+
}
|
|
2507
|
+
if (abs(barycentric.z) < 1.0e-6) {
|
|
2508
|
+
return dggs_a5_polyhedral_inverse_edge(
|
|
2509
|
+
sphericalTriangle.a,
|
|
2510
|
+
sphericalTriangle.b,
|
|
2511
|
+
1.0 - barycentric.x
|
|
2512
|
+
);
|
|
2513
|
+
}
|
|
2514
|
+
if (abs(barycentric.y) < 1.0e-6) {
|
|
2515
|
+
return dggs_a5_polyhedral_inverse_edge(
|
|
2516
|
+
sphericalTriangle.a,
|
|
2517
|
+
sphericalTriangle.c,
|
|
2518
|
+
1.0 - barycentric.x
|
|
2519
|
+
);
|
|
2520
|
+
}
|
|
2521
|
+
|
|
2522
|
+
let crossBC = cross(sphericalTriangle.b, sphericalTriangle.c);
|
|
2523
|
+
let areaABC = dggs_a5_spherical_triangle_area(sphericalTriangle);
|
|
2524
|
+
let h = max(1.0 - barycentric.x, 1.0e-8);
|
|
2525
|
+
let areaRatio = barycentric.z / h;
|
|
2526
|
+
let alpha = areaRatio * areaABC;
|
|
2527
|
+
let sineAlpha = sin(alpha);
|
|
2528
|
+
let halfSineAlpha = sin(alpha * 0.5);
|
|
2529
|
+
let chordCoefficient = 2.0 * halfSineAlpha * halfSineAlpha;
|
|
2530
|
+
let dotAB = dot(sphericalTriangle.a, sphericalTriangle.b);
|
|
2531
|
+
let dotBC = dot(sphericalTriangle.b, sphericalTriangle.c);
|
|
2532
|
+
let dotCA = dot(sphericalTriangle.c, sphericalTriangle.a);
|
|
2533
|
+
let lengthBC = length(crossBC);
|
|
2534
|
+
let volume = dot(sphericalTriangle.a, crossBC);
|
|
2535
|
+
let f = sineAlpha * volume + chordCoefficient * (dotAB * dotBC - dotCA);
|
|
2536
|
+
let g = chordCoefficient * lengthBC * (1.0 + dotAB);
|
|
2537
|
+
let edgeAngle = max(acos(clamp(dotBC, -1.0, 1.0)), 1.0e-8);
|
|
2538
|
+
let q = 2.0 / edgeAngle * atan2(g, f);
|
|
2539
|
+
let pointOnBC = dggs_a5_slerp(sphericalTriangle.b, sphericalTriangle.c, q);
|
|
2540
|
+
let k = dggs_a5_vector_difference(sphericalTriangle.a, pointOnBC);
|
|
2541
|
+
let denominator = max(dggs_a5_safe_acos(k), 1.0e-8);
|
|
2542
|
+
let t = dggs_a5_safe_acos(h * k) / denominator;
|
|
2543
|
+
return dggs_a5_slerp(sphericalTriangle.a, pointOnBC, t);
|
|
2544
|
+
}
|
|
2545
|
+
|
|
2546
|
+
fn dggs_a5_authalic_inverse(phi : f32) -> f32 {
|
|
2547
|
+
let sinPhi = sin(phi);
|
|
2548
|
+
let cosPhi = cos(phi);
|
|
2549
|
+
let coefficientX = 2.0 * (cosPhi - sinPhi) * (cosPhi + sinPhi);
|
|
2550
|
+
var u0 = coefficientX * 4.92842354825238055e-17 + 2.19128723067677184e-14;
|
|
2551
|
+
var u1 = coefficientX * u0 + 1.02018123778161003e-11;
|
|
2552
|
+
u0 = coefficientX * u1 - u0 + 5.08622073997266026e-9;
|
|
2553
|
+
u1 = coefficientX * u0 - u1 + 0.00000288319780486075558;
|
|
2554
|
+
u0 = coefficientX * u1 - u0 + 0.00223920899635416575;
|
|
2555
|
+
return phi + 2.0 * sinPhi * cosPhi * u0;
|
|
2556
|
+
}
|
|
2557
|
+
|
|
2558
|
+
fn dggs_a5_normalize_longitude(longitude : f32) -> f32 {
|
|
2559
|
+
var result = longitude;
|
|
2560
|
+
loop {
|
|
2561
|
+
if (result < -180.0) {
|
|
2562
|
+
result += 360.0;
|
|
2563
|
+
} else {
|
|
2564
|
+
break;
|
|
2565
|
+
}
|
|
2566
|
+
}
|
|
2567
|
+
loop {
|
|
2568
|
+
if (result >= 180.0) {
|
|
2569
|
+
result -= 360.0;
|
|
2570
|
+
} else {
|
|
2571
|
+
break;
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
return result;
|
|
2575
|
+
}
|
|
2576
|
+
|
|
2577
|
+
fn dggs_a5_normalize_longitude_to_center(longitude : f32, centerLongitude : f32) -> f32 {
|
|
2578
|
+
var result = longitude;
|
|
2579
|
+
loop {
|
|
2580
|
+
if (result - centerLongitude > 180.0) {
|
|
2581
|
+
result -= 360.0;
|
|
2582
|
+
} else {
|
|
2583
|
+
break;
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
loop {
|
|
2587
|
+
if (result - centerLongitude < -180.0) {
|
|
2588
|
+
result += 360.0;
|
|
2589
|
+
} else {
|
|
2590
|
+
break;
|
|
2591
|
+
}
|
|
2592
|
+
}
|
|
2593
|
+
return result;
|
|
2594
|
+
}
|
|
2595
|
+
|
|
2596
|
+
fn dggs_a5_sphere_to_lnglat(cartesian : vec3f) -> vec2f {
|
|
2597
|
+
let point = dggs_a5_normalize_vec3(cartesian);
|
|
2598
|
+
let theta = atan2(point.y, point.x);
|
|
2599
|
+
let phi = acos(clamp(point.z, -1.0, 1.0));
|
|
2600
|
+
let longitude = dggs_a5_normalize_longitude(theta * DGGS_RADIANS_TO_DEGREES - DGGS_A5_LONGITUDE_OFFSET);
|
|
2601
|
+
let authalicLatitude = DGGS_PI_OVER_2 - phi;
|
|
2602
|
+
let latitude = dggs_a5_authalic_inverse(authalicLatitude) * DGGS_RADIANS_TO_DEGREES;
|
|
2603
|
+
return vec2f(longitude, latitude);
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
fn dggs_a5_face_to_lnglat(facePoint : vec2f, origin : u32) -> vec2f {
|
|
2607
|
+
let polar = dggs_a5_to_polar(facePoint);
|
|
2608
|
+
let faceTriangleIndex = dggs_a5_get_face_triangle_index(polar);
|
|
2609
|
+
let reflected = dggs_a5_should_reflect(polar);
|
|
2610
|
+
let faceTriangle = dggs_a5_get_face_triangle(faceTriangleIndex, reflected, false);
|
|
2611
|
+
let sphericalTriangle = dggs_a5_face_triangle_to_spherical_triangle(
|
|
2612
|
+
faceTriangleIndex,
|
|
2613
|
+
origin,
|
|
2614
|
+
reflected
|
|
2615
|
+
);
|
|
2616
|
+
return dggs_a5_sphere_to_lnglat(
|
|
2617
|
+
dggs_a5_polyhedral_inverse(facePoint, faceTriangle, sphericalTriangle)
|
|
2618
|
+
);
|
|
2619
|
+
}
|
|
2620
|
+
|
|
2621
|
+
fn dggs_a5_get_boundary_point(index : vec2u, vertexIndex : u32) -> vec2f {
|
|
2622
|
+
let cell = dggs_a5_deserialize(index);
|
|
2623
|
+
if (cell.valid == 0u || dggs_u64_is_zero(index)) {
|
|
2624
|
+
return vec2f(0.0);
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
let shapeVertexCount = dggs_a5_get_shape_vertex_count(cell);
|
|
2628
|
+
let shapeIndex = dggs_a5_get_reversed_shape_index(vertexIndex, shapeVertexCount);
|
|
2629
|
+
let facePoint = dggs_a5_get_cell_shape_face_point(index, cell, shapeIndex);
|
|
2630
|
+
let centerPoint = dggs_a5_get_cell_center_face_point(index, cell);
|
|
2631
|
+
var lngLat = dggs_a5_face_to_lnglat(facePoint, cell.origin);
|
|
2632
|
+
let centerLngLat = dggs_a5_face_to_lnglat(centerPoint, cell.origin);
|
|
2633
|
+
lngLat.x = dggs_a5_normalize_longitude_to_center(lngLat.x, centerLngLat.x);
|
|
2634
|
+
return lngLat;
|
|
2635
|
+
}
|
|
2636
|
+
|
|
2637
|
+
fn dggs_a5_get_boundary_point_fp64_split(index : vec2u, vertexIndex : u32) -> vec4f {
|
|
2638
|
+
return dggs_boundary_point_to_fp64_split(dggs_a5_get_boundary_point(index, vertexIndex));
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2641
|
+
fn dggs_h3_get_mode(index: vec2u) -> u32 {
|
|
2642
|
+
return dggs_u64_extract_bits(index, 59u, 4u);
|
|
2643
|
+
}
|
|
2644
|
+
|
|
2645
|
+
fn dggs_h3_is_cell_mode(index: vec2u) -> bool {
|
|
2646
|
+
return dggs_h3_get_mode(index) == DGGS_H3_CELL_MODE;
|
|
2647
|
+
}
|
|
2648
|
+
|
|
2649
|
+
fn dggs_h3_get_resolution(index: vec2u) -> u32 {
|
|
2650
|
+
return dggs_u64_extract_bits(index, 52u, 4u);
|
|
2651
|
+
}
|
|
2652
|
+
|
|
2653
|
+
fn dggs_h3_get_base_cell(index: vec2u) -> u32 {
|
|
2654
|
+
return dggs_u64_extract_bits(index, 45u, 7u);
|
|
2655
|
+
}
|
|
2656
|
+
|
|
2657
|
+
fn dggs_h3_digit_bit_offset(resolution: u32) -> u32 {
|
|
2658
|
+
return 3u * (DGGS_H3_MAX_RESOLUTION - resolution);
|
|
2659
|
+
}
|
|
2660
|
+
|
|
2661
|
+
fn dggs_h3_get_digit(index: vec2u, resolution: u32) -> u32 {
|
|
2662
|
+
if (resolution == 0u || resolution > DGGS_H3_MAX_RESOLUTION) {
|
|
2663
|
+
return DGGS_H3_UNUSED_DIGIT;
|
|
2664
|
+
}
|
|
2665
|
+
return dggs_u64_extract_bits(index, dggs_h3_digit_bit_offset(resolution), 3u);
|
|
2666
|
+
}
|
|
2667
|
+
|
|
2668
|
+
fn dggs_h3_is_valid_cell_id(index: vec2u) -> bool {
|
|
2669
|
+
let cellResolution = dggs_h3_get_resolution(index);
|
|
2670
|
+
if (
|
|
2671
|
+
!dggs_h3_is_cell_mode(index) ||
|
|
2672
|
+
cellResolution > DGGS_H3_MAX_RESOLUTION ||
|
|
2673
|
+
dggs_h3_get_base_cell(index) > DGGS_H3_MAX_BASE_CELL
|
|
2674
|
+
) {
|
|
2675
|
+
return false;
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
var digitResolution = 1u;
|
|
2679
|
+
loop {
|
|
2680
|
+
if (digitResolution > DGGS_H3_MAX_RESOLUTION) {
|
|
2681
|
+
break;
|
|
2682
|
+
}
|
|
2683
|
+
|
|
2684
|
+
let digit = dggs_h3_get_digit(index, digitResolution);
|
|
2685
|
+
if (digitResolution <= cellResolution) {
|
|
2686
|
+
if (digit == DGGS_H3_UNUSED_DIGIT) {
|
|
2687
|
+
return false;
|
|
2688
|
+
}
|
|
2689
|
+
} else if (digit != DGGS_H3_UNUSED_DIGIT) {
|
|
2690
|
+
return false;
|
|
2691
|
+
}
|
|
2692
|
+
digitResolution += 1u;
|
|
2693
|
+
}
|
|
2694
|
+
return true;
|
|
2695
|
+
}
|
|
2696
|
+
|
|
2697
|
+
fn dggs_h3_get_parent(index: vec2u, parentResolution: u32) -> vec2u {
|
|
2698
|
+
let currentResolution = dggs_h3_get_resolution(index);
|
|
2699
|
+
let targetResolution = min(parentResolution, currentResolution);
|
|
2700
|
+
var parent = dggs_u64_set_bits(index, 52u, 4u, targetResolution);
|
|
2701
|
+
var resolution = targetResolution + 1u;
|
|
2702
|
+
loop {
|
|
2703
|
+
if (resolution > DGGS_H3_MAX_RESOLUTION) {
|
|
2704
|
+
break;
|
|
2705
|
+
}
|
|
2706
|
+
parent = dggs_u64_set_bits(
|
|
2707
|
+
parent,
|
|
2708
|
+
dggs_h3_digit_bit_offset(resolution),
|
|
2709
|
+
3u,
|
|
2710
|
+
DGGS_H3_UNUSED_DIGIT
|
|
2711
|
+
);
|
|
2712
|
+
resolution += 1u;
|
|
2713
|
+
}
|
|
2714
|
+
return parent;
|
|
2715
|
+
}
|
|
2716
|
+
|
|
2717
|
+
fn dggs_h3_positive_angle_rads(angle: f32) -> f32 {
|
|
2718
|
+
var result = angle;
|
|
2719
|
+
if (result < 0.0) {
|
|
2720
|
+
result += DGGS_TWO_PI;
|
|
2721
|
+
}
|
|
2722
|
+
if (result >= DGGS_TWO_PI) {
|
|
2723
|
+
result -= DGGS_TWO_PI;
|
|
2724
|
+
}
|
|
2725
|
+
return result;
|
|
2726
|
+
}
|
|
2727
|
+
|
|
2728
|
+
fn dggs_h3_constrain_longitude(longitude: f32) -> f32 {
|
|
2729
|
+
var result = longitude;
|
|
2730
|
+
loop {
|
|
2731
|
+
if (result <= DGGS_PI) {
|
|
2732
|
+
break;
|
|
2733
|
+
}
|
|
2734
|
+
result -= DGGS_TWO_PI;
|
|
2735
|
+
}
|
|
2736
|
+
loop {
|
|
2737
|
+
if (result >= -DGGS_PI) {
|
|
2738
|
+
break;
|
|
2739
|
+
}
|
|
2740
|
+
result += DGGS_TWO_PI;
|
|
2741
|
+
}
|
|
2742
|
+
return result;
|
|
2743
|
+
}
|
|
2744
|
+
|
|
2745
|
+
fn dggs_h3_is_resolution_class_iii(resolution: u32) -> bool {
|
|
2746
|
+
return (resolution & 1u) != 0u;
|
|
2747
|
+
}
|
|
2748
|
+
|
|
2749
|
+
fn dggs_h3_is_base_cell_pentagon(baseCell: u32) -> bool {
|
|
2750
|
+
return baseCell == 4u ||
|
|
2751
|
+
baseCell == 14u ||
|
|
2752
|
+
baseCell == 24u ||
|
|
2753
|
+
baseCell == 38u ||
|
|
2754
|
+
baseCell == 49u ||
|
|
2755
|
+
baseCell == 58u ||
|
|
2756
|
+
baseCell == 63u ||
|
|
2757
|
+
baseCell == 72u ||
|
|
2758
|
+
baseCell == 83u ||
|
|
2759
|
+
baseCell == 97u ||
|
|
2760
|
+
baseCell == 107u ||
|
|
2761
|
+
baseCell == 117u;
|
|
2762
|
+
}
|
|
2763
|
+
|
|
2764
|
+
fn dggs_h3_get_base_cell_home(baseCell: u32) -> DggsH3FaceIJK {
|
|
2765
|
+
let values = array<vec4i, 122>(
|
|
2766
|
+
vec4i(1, 1, 0, 0),
|
|
2767
|
+
vec4i(2, 1, 1, 0),
|
|
2768
|
+
vec4i(1, 0, 0, 0),
|
|
2769
|
+
vec4i(2, 1, 0, 0),
|
|
2770
|
+
vec4i(0, 2, 0, 0),
|
|
2771
|
+
vec4i(1, 1, 1, 0),
|
|
2772
|
+
vec4i(1, 0, 0, 1),
|
|
2773
|
+
vec4i(2, 0, 0, 0),
|
|
2774
|
+
vec4i(0, 1, 0, 0),
|
|
2775
|
+
vec4i(2, 0, 1, 0),
|
|
2776
|
+
vec4i(1, 0, 1, 0),
|
|
2777
|
+
vec4i(1, 0, 1, 1),
|
|
2778
|
+
vec4i(3, 1, 0, 0),
|
|
2779
|
+
vec4i(3, 1, 1, 0),
|
|
2780
|
+
vec4i(11, 2, 0, 0),
|
|
2781
|
+
vec4i(4, 1, 0, 0),
|
|
2782
|
+
vec4i(0, 0, 0, 0),
|
|
2783
|
+
vec4i(6, 0, 1, 0),
|
|
2784
|
+
vec4i(0, 0, 0, 1),
|
|
2785
|
+
vec4i(2, 0, 1, 1),
|
|
2786
|
+
vec4i(7, 0, 0, 1),
|
|
2787
|
+
vec4i(2, 0, 0, 1),
|
|
2788
|
+
vec4i(0, 1, 1, 0),
|
|
2789
|
+
vec4i(6, 0, 0, 1),
|
|
2790
|
+
vec4i(10, 2, 0, 0),
|
|
2791
|
+
vec4i(6, 0, 0, 0),
|
|
2792
|
+
vec4i(3, 0, 0, 0),
|
|
2793
|
+
vec4i(11, 1, 0, 0),
|
|
2794
|
+
vec4i(4, 1, 1, 0),
|
|
2795
|
+
vec4i(3, 0, 1, 0),
|
|
2796
|
+
vec4i(0, 0, 1, 1),
|
|
2797
|
+
vec4i(4, 0, 0, 0),
|
|
2798
|
+
vec4i(5, 0, 1, 0),
|
|
2799
|
+
vec4i(0, 0, 1, 0),
|
|
2800
|
+
vec4i(7, 0, 1, 0),
|
|
2801
|
+
vec4i(11, 1, 1, 0),
|
|
2802
|
+
vec4i(7, 0, 0, 0),
|
|
2803
|
+
vec4i(10, 1, 0, 0),
|
|
2804
|
+
vec4i(12, 2, 0, 0),
|
|
2805
|
+
vec4i(6, 1, 0, 1),
|
|
2806
|
+
vec4i(7, 1, 0, 1),
|
|
2807
|
+
vec4i(4, 0, 0, 1),
|
|
2808
|
+
vec4i(3, 0, 0, 1),
|
|
2809
|
+
vec4i(3, 0, 1, 1),
|
|
2810
|
+
vec4i(4, 0, 1, 0),
|
|
2811
|
+
vec4i(6, 1, 0, 0),
|
|
2812
|
+
vec4i(11, 0, 0, 0),
|
|
2813
|
+
vec4i(8, 0, 0, 1),
|
|
2814
|
+
vec4i(5, 0, 0, 1),
|
|
2815
|
+
vec4i(14, 2, 0, 0),
|
|
2816
|
+
vec4i(5, 0, 0, 0),
|
|
2817
|
+
vec4i(12, 1, 0, 0),
|
|
2818
|
+
vec4i(10, 1, 1, 0),
|
|
2819
|
+
vec4i(4, 0, 1, 1),
|
|
2820
|
+
vec4i(12, 1, 1, 0),
|
|
2821
|
+
vec4i(7, 1, 0, 0),
|
|
2822
|
+
vec4i(11, 0, 1, 0),
|
|
2823
|
+
vec4i(10, 0, 0, 0),
|
|
2824
|
+
vec4i(13, 2, 0, 0),
|
|
2825
|
+
vec4i(10, 0, 0, 1),
|
|
2826
|
+
vec4i(11, 0, 0, 1),
|
|
2827
|
+
vec4i(9, 0, 1, 0),
|
|
2828
|
+
vec4i(8, 0, 1, 0),
|
|
2829
|
+
vec4i(6, 2, 0, 0),
|
|
2830
|
+
vec4i(8, 0, 0, 0),
|
|
2831
|
+
vec4i(9, 0, 0, 1),
|
|
2832
|
+
vec4i(14, 1, 0, 0),
|
|
2833
|
+
vec4i(5, 1, 0, 1),
|
|
2834
|
+
vec4i(16, 0, 1, 1),
|
|
2835
|
+
vec4i(8, 1, 0, 1),
|
|
2836
|
+
vec4i(5, 1, 0, 0),
|
|
2837
|
+
vec4i(12, 0, 0, 0),
|
|
2838
|
+
vec4i(7, 2, 0, 0),
|
|
2839
|
+
vec4i(12, 0, 1, 0),
|
|
2840
|
+
vec4i(10, 0, 1, 0),
|
|
2841
|
+
vec4i(9, 0, 0, 0),
|
|
2842
|
+
vec4i(13, 1, 0, 0),
|
|
2843
|
+
vec4i(16, 0, 0, 1),
|
|
2844
|
+
vec4i(15, 0, 1, 1),
|
|
2845
|
+
vec4i(15, 0, 1, 0),
|
|
2846
|
+
vec4i(16, 0, 1, 0),
|
|
2847
|
+
vec4i(14, 1, 1, 0),
|
|
2848
|
+
vec4i(13, 1, 1, 0),
|
|
2849
|
+
vec4i(5, 2, 0, 0),
|
|
2850
|
+
vec4i(8, 1, 0, 0),
|
|
2851
|
+
vec4i(14, 0, 0, 0),
|
|
2852
|
+
vec4i(9, 1, 0, 1),
|
|
2853
|
+
vec4i(14, 0, 0, 1),
|
|
2854
|
+
vec4i(17, 0, 0, 1),
|
|
2855
|
+
vec4i(12, 0, 0, 1),
|
|
2856
|
+
vec4i(16, 0, 0, 0),
|
|
2857
|
+
vec4i(17, 0, 1, 1),
|
|
2858
|
+
vec4i(15, 0, 0, 1),
|
|
2859
|
+
vec4i(16, 1, 0, 1),
|
|
2860
|
+
vec4i(9, 1, 0, 0),
|
|
2861
|
+
vec4i(15, 0, 0, 0),
|
|
2862
|
+
vec4i(13, 0, 0, 0),
|
|
2863
|
+
vec4i(8, 2, 0, 0),
|
|
2864
|
+
vec4i(13, 0, 1, 0),
|
|
2865
|
+
vec4i(17, 1, 0, 1),
|
|
2866
|
+
vec4i(19, 0, 1, 0),
|
|
2867
|
+
vec4i(14, 0, 1, 0),
|
|
2868
|
+
vec4i(19, 0, 1, 1),
|
|
2869
|
+
vec4i(17, 0, 1, 0),
|
|
2870
|
+
vec4i(13, 0, 0, 1),
|
|
2871
|
+
vec4i(17, 0, 0, 0),
|
|
2872
|
+
vec4i(16, 1, 0, 0),
|
|
2873
|
+
vec4i(9, 2, 0, 0),
|
|
2874
|
+
vec4i(15, 1, 0, 1),
|
|
2875
|
+
vec4i(15, 1, 0, 0),
|
|
2876
|
+
vec4i(18, 0, 1, 1),
|
|
2877
|
+
vec4i(18, 0, 0, 1),
|
|
2878
|
+
vec4i(19, 0, 0, 1),
|
|
2879
|
+
vec4i(17, 1, 0, 0),
|
|
2880
|
+
vec4i(19, 0, 0, 0),
|
|
2881
|
+
vec4i(18, 0, 1, 0),
|
|
2882
|
+
vec4i(18, 1, 0, 1),
|
|
2883
|
+
vec4i(19, 2, 0, 0),
|
|
2884
|
+
vec4i(19, 1, 0, 0),
|
|
2885
|
+
vec4i(18, 0, 0, 0),
|
|
2886
|
+
vec4i(19, 1, 0, 1),
|
|
2887
|
+
vec4i(18, 1, 0, 0)
|
|
2888
|
+
);
|
|
2889
|
+
let value = values[min(baseCell, DGGS_H3_MAX_BASE_CELL)];
|
|
2890
|
+
return DggsH3FaceIJK(
|
|
2891
|
+
u32(value.x),
|
|
2892
|
+
value.yzw,
|
|
2893
|
+
select(1u, 0u, baseCell > DGGS_H3_MAX_BASE_CELL)
|
|
2894
|
+
);
|
|
2895
|
+
}
|
|
2896
|
+
|
|
2897
|
+
fn dggs_h3_get_face_center_geo(face: u32) -> vec2f {
|
|
2898
|
+
let values = array<vec2f, 20>(
|
|
2899
|
+
vec2f(0.803582649718989942, 1.248397419617396099),
|
|
2900
|
+
vec2f(1.307747883455638156, 2.536945009877921159),
|
|
2901
|
+
vec2f(1.054751253523952054, -1.347517358900396623),
|
|
2902
|
+
vec2f(0.600191595538186799, -0.450603909469755746),
|
|
2903
|
+
vec2f(0.491715428198773866, 0.401988202911306943),
|
|
2904
|
+
vec2f(0.172745327415618701, 1.678146885280433686),
|
|
2905
|
+
vec2f(0.605929321571350690, 2.953923329812411617),
|
|
2906
|
+
vec2f(0.427370518328979641, -1.888876200336285401),
|
|
2907
|
+
vec2f(-0.079066118549212831, -0.733429513380867741),
|
|
2908
|
+
vec2f(-0.230961644455383637, 0.506495587332349035),
|
|
2909
|
+
vec2f(0.079066118549212831, 2.408163140208925497),
|
|
2910
|
+
vec2f(0.230961644455383637, -2.635097066257444203),
|
|
2911
|
+
vec2f(-0.172745327415618701, -1.463445768309359553),
|
|
2912
|
+
vec2f(-0.605929321571350690, -0.187669323777381622),
|
|
2913
|
+
vec2f(-0.427370518328979641, 1.252716453253507838),
|
|
2914
|
+
vec2f(-0.600191595538186799, 2.690988744120037492),
|
|
2915
|
+
vec2f(-0.491715428198773866, -2.739604450678486295),
|
|
2916
|
+
vec2f(-0.803582649718989942, -1.893195233972397139),
|
|
2917
|
+
vec2f(-1.307747883455638156, -0.604647643711872080),
|
|
2918
|
+
vec2f(-1.054751253523952054, 1.794075294689396615)
|
|
2919
|
+
);
|
|
2920
|
+
return values[min(face, 19u)];
|
|
2921
|
+
}
|
|
2922
|
+
|
|
2923
|
+
fn dggs_h3_get_face_axis_azimuths(face: u32) -> vec3f {
|
|
2924
|
+
let values = array<vec3f, 20>(
|
|
2925
|
+
vec3f(5.619958268523939882, 3.525563166130744542, 1.431168063737548730),
|
|
2926
|
+
vec3f(5.760339081714187279, 3.665943979320991689, 1.571548876927796127),
|
|
2927
|
+
vec3f(0.780213654393430055, 4.969003859179821079, 2.874608756786625655),
|
|
2928
|
+
vec3f(0.430469363979999913, 4.619259568766391033, 2.524864466373195467),
|
|
2929
|
+
vec3f(6.130269123335111400, 4.035874020941915804, 1.941478918548720291),
|
|
2930
|
+
vec3f(2.692877706530642877, 0.598482604137447119, 4.787272808923838195),
|
|
2931
|
+
vec3f(2.982963003477243874, 0.888567901084048369, 5.077358105870439581),
|
|
2932
|
+
vec3f(3.532912002790141181, 1.438516900396945656, 5.627307105183336758),
|
|
2933
|
+
vec3f(3.494305004259568154, 1.399909901866372864, 5.588700106652763840),
|
|
2934
|
+
vec3f(3.003214169499538391, 0.908819067106342928, 5.097609271892733906),
|
|
2935
|
+
vec3f(5.930472956509811562, 3.836077854116615875, 1.741682751723420374),
|
|
2936
|
+
vec3f(0.138378484090254847, 4.327168688876645809, 2.232773586483450311),
|
|
2937
|
+
vec3f(0.448714947059150361, 4.637505151845541521, 2.543110049452346120),
|
|
2938
|
+
vec3f(0.158629650112549365, 4.347419854898940135, 2.253024752505744869),
|
|
2939
|
+
vec3f(5.891865957979238535, 3.797470855586042958, 1.703075753192847583),
|
|
2940
|
+
vec3f(2.711123289609793325, 0.616728187216597771, 4.805518392002988683),
|
|
2941
|
+
vec3f(3.294508837434268316, 1.200113735041072948, 5.388903939827463911),
|
|
2942
|
+
vec3f(3.804819692245439833, 1.710424589852244509, 5.899214794638635174),
|
|
2943
|
+
vec3f(3.664438879055192436, 1.570043776661997111, 5.758833981448388027),
|
|
2944
|
+
vec3f(2.361378999196363184, 0.266983896803167583, 4.455774101589558636)
|
|
2945
|
+
);
|
|
2946
|
+
return values[min(face, 19u)];
|
|
2947
|
+
}
|
|
2948
|
+
|
|
2949
|
+
fn dggs_h3_get_max_dim_by_cii_resolution(resolution: u32) -> i32 {
|
|
2950
|
+
let values = array<i32, 17>(
|
|
2951
|
+
2, -1, 14, -1, 98, -1, 686, -1, 4802, -1, 33614, -1, 235298, -1, 1647086, -1, 11529602
|
|
2952
|
+
);
|
|
2953
|
+
return values[min(resolution, 16u)];
|
|
2954
|
+
}
|
|
2955
|
+
|
|
2956
|
+
fn dggs_h3_get_unit_vector(digit: u32) -> vec3i {
|
|
2957
|
+
if (digit == 1u) {
|
|
2958
|
+
return vec3i(0, 0, 1);
|
|
2959
|
+
}
|
|
2960
|
+
if (digit == 2u) {
|
|
2961
|
+
return vec3i(0, 1, 0);
|
|
2962
|
+
}
|
|
2963
|
+
if (digit == 3u) {
|
|
2964
|
+
return vec3i(0, 1, 1);
|
|
2965
|
+
}
|
|
2966
|
+
if (digit == 4u) {
|
|
2967
|
+
return vec3i(1, 0, 0);
|
|
2968
|
+
}
|
|
2969
|
+
if (digit == 5u) {
|
|
2970
|
+
return vec3i(1, 0, 1);
|
|
2971
|
+
}
|
|
2972
|
+
if (digit == 6u) {
|
|
2973
|
+
return vec3i(1, 1, 0);
|
|
2974
|
+
}
|
|
2975
|
+
return vec3i(0);
|
|
2976
|
+
}
|
|
2977
|
+
|
|
2978
|
+
fn dggs_h3_ijk_normalize(coord: vec3i) -> vec3i {
|
|
2979
|
+
var normalized = coord;
|
|
2980
|
+
if (normalized.x < 0) {
|
|
2981
|
+
normalized.y -= normalized.x;
|
|
2982
|
+
normalized.z -= normalized.x;
|
|
2983
|
+
normalized.x = 0;
|
|
2984
|
+
}
|
|
2985
|
+
if (normalized.y < 0) {
|
|
2986
|
+
normalized.x -= normalized.y;
|
|
2987
|
+
normalized.z -= normalized.y;
|
|
2988
|
+
normalized.y = 0;
|
|
2989
|
+
}
|
|
2990
|
+
if (normalized.z < 0) {
|
|
2991
|
+
normalized.x -= normalized.z;
|
|
2992
|
+
normalized.y -= normalized.z;
|
|
2993
|
+
normalized.z = 0;
|
|
2994
|
+
}
|
|
2995
|
+
|
|
2996
|
+
let minimumValue = min(normalized.x, min(normalized.y, normalized.z));
|
|
2997
|
+
if (minimumValue > 0) {
|
|
2998
|
+
normalized -= vec3i(minimumValue);
|
|
2999
|
+
}
|
|
3000
|
+
return normalized;
|
|
3001
|
+
}
|
|
3002
|
+
|
|
3003
|
+
fn dggs_h3_neighbor(coord: vec3i, digit: u32) -> vec3i {
|
|
3004
|
+
if (digit > 0u && digit < DGGS_H3_UNUSED_DIGIT) {
|
|
3005
|
+
return dggs_h3_ijk_normalize(coord + dggs_h3_get_unit_vector(digit));
|
|
3006
|
+
}
|
|
3007
|
+
return coord;
|
|
3008
|
+
}
|
|
3009
|
+
|
|
3010
|
+
fn dggs_h3_down_ap3(coord: vec3i) -> vec3i {
|
|
3011
|
+
let iVector = vec3i(2, 0, 1) * coord.x;
|
|
3012
|
+
let jVector = vec3i(1, 2, 0) * coord.y;
|
|
3013
|
+
let kVector = vec3i(0, 1, 2) * coord.z;
|
|
3014
|
+
return dggs_h3_ijk_normalize(iVector + jVector + kVector);
|
|
3015
|
+
}
|
|
3016
|
+
|
|
3017
|
+
fn dggs_h3_down_ap3r(coord: vec3i) -> vec3i {
|
|
3018
|
+
let iVector = vec3i(2, 1, 0) * coord.x;
|
|
3019
|
+
let jVector = vec3i(0, 2, 1) * coord.y;
|
|
3020
|
+
let kVector = vec3i(1, 0, 2) * coord.z;
|
|
3021
|
+
return dggs_h3_ijk_normalize(iVector + jVector + kVector);
|
|
3022
|
+
}
|
|
3023
|
+
|
|
3024
|
+
fn dggs_h3_down_ap7(coord: vec3i) -> vec3i {
|
|
3025
|
+
let iVector = vec3i(3, 0, 1) * coord.x;
|
|
3026
|
+
let jVector = vec3i(1, 3, 0) * coord.y;
|
|
3027
|
+
let kVector = vec3i(0, 1, 3) * coord.z;
|
|
3028
|
+
return dggs_h3_ijk_normalize(iVector + jVector + kVector);
|
|
3029
|
+
}
|
|
3030
|
+
|
|
3031
|
+
fn dggs_h3_down_ap7r(coord: vec3i) -> vec3i {
|
|
3032
|
+
let iVector = vec3i(3, 1, 0) * coord.x;
|
|
3033
|
+
let jVector = vec3i(0, 3, 1) * coord.y;
|
|
3034
|
+
let kVector = vec3i(1, 0, 3) * coord.z;
|
|
3035
|
+
return dggs_h3_ijk_normalize(iVector + jVector + kVector);
|
|
3036
|
+
}
|
|
3037
|
+
|
|
3038
|
+
fn dggs_h3_get_center_face_ijk(index: vec2u) -> DggsH3FaceIJK {
|
|
3039
|
+
if (!dggs_h3_is_valid_cell_id(index)) {
|
|
3040
|
+
return DggsH3FaceIJK(0u, vec3i(0), 0u);
|
|
3041
|
+
}
|
|
3042
|
+
|
|
3043
|
+
let baseCell = dggs_h3_get_base_cell(index);
|
|
3044
|
+
if (dggs_h3_is_base_cell_pentagon(baseCell)) {
|
|
3045
|
+
return DggsH3FaceIJK(0u, vec3i(0), 0u);
|
|
3046
|
+
}
|
|
3047
|
+
|
|
3048
|
+
var faceIJK = dggs_h3_get_base_cell_home(baseCell);
|
|
3049
|
+
let cellResolution = dggs_h3_get_resolution(index);
|
|
3050
|
+
var resolution = 1u;
|
|
3051
|
+
loop {
|
|
3052
|
+
if (resolution > cellResolution) {
|
|
3053
|
+
break;
|
|
3054
|
+
}
|
|
3055
|
+
|
|
3056
|
+
if (dggs_h3_is_resolution_class_iii(resolution)) {
|
|
3057
|
+
faceIJK.coord = dggs_h3_down_ap7(faceIJK.coord);
|
|
3058
|
+
} else {
|
|
3059
|
+
faceIJK.coord = dggs_h3_down_ap7r(faceIJK.coord);
|
|
3060
|
+
}
|
|
3061
|
+
faceIJK.coord = dggs_h3_neighbor(faceIJK.coord, dggs_h3_get_digit(index, resolution));
|
|
3062
|
+
resolution += 1u;
|
|
3063
|
+
}
|
|
3064
|
+
|
|
3065
|
+
return faceIJK;
|
|
3066
|
+
}
|
|
3067
|
+
|
|
3068
|
+
fn dggs_h3_get_vertex_offset(resolution: u32, vertexIndex: u32) -> vec3i {
|
|
3069
|
+
let pointIndex = vertexIndex % 6u;
|
|
3070
|
+
if (dggs_h3_is_resolution_class_iii(resolution)) {
|
|
3071
|
+
let vertices = array<vec3i, 6>(
|
|
3072
|
+
vec3i(5, 4, 0),
|
|
3073
|
+
vec3i(1, 5, 0),
|
|
3074
|
+
vec3i(0, 5, 4),
|
|
3075
|
+
vec3i(0, 1, 5),
|
|
3076
|
+
vec3i(4, 0, 5),
|
|
3077
|
+
vec3i(5, 0, 1)
|
|
3078
|
+
);
|
|
3079
|
+
return vertices[pointIndex];
|
|
3080
|
+
}
|
|
3081
|
+
|
|
3082
|
+
let vertices = array<vec3i, 6>(
|
|
3083
|
+
vec3i(2, 1, 0),
|
|
3084
|
+
vec3i(1, 2, 0),
|
|
3085
|
+
vec3i(0, 2, 1),
|
|
3086
|
+
vec3i(0, 1, 2),
|
|
3087
|
+
vec3i(1, 0, 2),
|
|
3088
|
+
vec3i(2, 0, 1)
|
|
3089
|
+
);
|
|
3090
|
+
return vertices[pointIndex];
|
|
3091
|
+
}
|
|
3092
|
+
|
|
3093
|
+
fn dggs_h3_get_boundary_vertex(index: vec2u, vertexIndex: u32) -> DggsH3BoundaryVertex {
|
|
3094
|
+
let center = dggs_h3_get_center_face_ijk(index);
|
|
3095
|
+
if (center.valid == 0u) {
|
|
3096
|
+
return DggsH3BoundaryVertex(0u, vec3i(0), 0u, 0u);
|
|
3097
|
+
}
|
|
3098
|
+
|
|
3099
|
+
let cellResolution = dggs_h3_get_resolution(index);
|
|
3100
|
+
var adjustedResolution = cellResolution;
|
|
3101
|
+
var centerCoord = dggs_h3_down_ap3r(dggs_h3_down_ap3(center.coord));
|
|
3102
|
+
if (dggs_h3_is_resolution_class_iii(cellResolution)) {
|
|
3103
|
+
centerCoord = dggs_h3_down_ap7r(centerCoord);
|
|
3104
|
+
adjustedResolution += 1u;
|
|
3105
|
+
}
|
|
3106
|
+
|
|
3107
|
+
let vertexCoord = dggs_h3_ijk_normalize(
|
|
3108
|
+
centerCoord + dggs_h3_get_vertex_offset(cellResolution, vertexIndex)
|
|
3109
|
+
);
|
|
3110
|
+
let maximumDimension = dggs_h3_get_max_dim_by_cii_resolution(adjustedResolution) * 3;
|
|
3111
|
+
let vertexDimension = vertexCoord.x + vertexCoord.y + vertexCoord.z;
|
|
3112
|
+
if (vertexDimension >= maximumDimension) {
|
|
3113
|
+
return DggsH3BoundaryVertex(center.face, vertexCoord, adjustedResolution, 0u);
|
|
3114
|
+
}
|
|
3115
|
+
|
|
3116
|
+
return DggsH3BoundaryVertex(center.face, vertexCoord, adjustedResolution, 1u);
|
|
3117
|
+
}
|
|
3118
|
+
|
|
3119
|
+
fn dggs_h3_is_single_face_boundary(index: vec2u) -> bool {
|
|
3120
|
+
var vertexIndex = 0u;
|
|
3121
|
+
loop {
|
|
3122
|
+
if (vertexIndex >= 6u) {
|
|
3123
|
+
break;
|
|
3124
|
+
}
|
|
3125
|
+
if (dggs_h3_get_boundary_vertex(index, vertexIndex).valid == 0u) {
|
|
3126
|
+
return false;
|
|
3127
|
+
}
|
|
3128
|
+
vertexIndex += 1u;
|
|
3129
|
+
}
|
|
3130
|
+
return true;
|
|
3131
|
+
}
|
|
3132
|
+
|
|
3133
|
+
fn dggs_h3_ijk_to_hex2d(coord: vec3i) -> vec2f {
|
|
3134
|
+
let i = f32(coord.x - coord.z);
|
|
3135
|
+
let j = f32(coord.y - coord.z);
|
|
3136
|
+
return vec2f(i - 0.5 * j, j * DGGS_H3_SQRT3_2);
|
|
3137
|
+
}
|
|
3138
|
+
|
|
3139
|
+
fn dggs_h3_geo_az_distance_rads(center: vec2f, azimuth: f32, distance: f32) -> vec2f {
|
|
3140
|
+
if (distance < 1.0e-7) {
|
|
3141
|
+
return center;
|
|
3142
|
+
}
|
|
3143
|
+
|
|
3144
|
+
let positiveAzimuth = dggs_h3_positive_angle_rads(azimuth);
|
|
3145
|
+
let latitude = asin(clamp(
|
|
3146
|
+
sin(center.x) * cos(distance) + cos(center.x) * sin(distance) * cos(positiveAzimuth),
|
|
3147
|
+
-1.0,
|
|
3148
|
+
1.0
|
|
3149
|
+
));
|
|
3150
|
+
var longitude = 0.0;
|
|
3151
|
+
if (abs(latitude - DGGS_PI_OVER_2) < 1.0e-7) {
|
|
3152
|
+
return vec2f(DGGS_PI_OVER_2, 0.0);
|
|
3153
|
+
}
|
|
3154
|
+
if (abs(latitude + DGGS_PI_OVER_2) < 1.0e-7) {
|
|
3155
|
+
return vec2f(-DGGS_PI_OVER_2, 0.0);
|
|
3156
|
+
}
|
|
3157
|
+
|
|
3158
|
+
let inverseCosLatitude = 1.0 / max(cos(latitude), 1.0e-8);
|
|
3159
|
+
let sinLongitude = clamp(
|
|
3160
|
+
sin(positiveAzimuth) * sin(distance) * inverseCosLatitude,
|
|
3161
|
+
-1.0,
|
|
3162
|
+
1.0
|
|
3163
|
+
);
|
|
3164
|
+
let cosLongitude = clamp(
|
|
3165
|
+
(cos(distance) - sin(center.x) * sin(latitude)) / max(cos(center.x), 1.0e-8) *
|
|
3166
|
+
inverseCosLatitude,
|
|
3167
|
+
-1.0,
|
|
3168
|
+
1.0
|
|
3169
|
+
);
|
|
3170
|
+
longitude = dggs_h3_constrain_longitude(center.y + atan2(sinLongitude, cosLongitude));
|
|
3171
|
+
return vec2f(latitude, longitude);
|
|
3172
|
+
}
|
|
3173
|
+
|
|
3174
|
+
fn dggs_h3_hex2d_to_lnglat(point: vec2f, face: u32, resolution: u32, substrate: bool) -> vec2f {
|
|
3175
|
+
var radius = length(point);
|
|
3176
|
+
let center = dggs_h3_get_face_center_geo(face);
|
|
3177
|
+
if (radius < 1.0e-7) {
|
|
3178
|
+
return vec2f(center.y * DGGS_RADIANS_TO_DEGREES, center.x * DGGS_RADIANS_TO_DEGREES);
|
|
3179
|
+
}
|
|
3180
|
+
|
|
3181
|
+
var theta = atan2(point.y, point.x);
|
|
3182
|
+
var resolutionIndex = 0u;
|
|
3183
|
+
loop {
|
|
3184
|
+
if (resolutionIndex >= resolution) {
|
|
3185
|
+
break;
|
|
3186
|
+
}
|
|
3187
|
+
radius *= DGGS_H3_RSQRT7;
|
|
3188
|
+
resolutionIndex += 1u;
|
|
3189
|
+
}
|
|
3190
|
+
|
|
3191
|
+
if (substrate) {
|
|
3192
|
+
radius *= DGGS_H3_ONETHIRD;
|
|
3193
|
+
if (dggs_h3_is_resolution_class_iii(resolution)) {
|
|
3194
|
+
radius *= DGGS_H3_RSQRT7;
|
|
3195
|
+
}
|
|
3196
|
+
} else if (dggs_h3_is_resolution_class_iii(resolution)) {
|
|
3197
|
+
theta = dggs_h3_positive_angle_rads(theta + DGGS_H3_AP7_ROT_RADS);
|
|
3198
|
+
}
|
|
3199
|
+
|
|
3200
|
+
radius = atan(radius * DGGS_H3_RES0_U_GNOMONIC);
|
|
3201
|
+
theta = dggs_h3_positive_angle_rads(dggs_h3_get_face_axis_azimuths(face).x - theta);
|
|
3202
|
+
let latitudeLongitude = dggs_h3_geo_az_distance_rads(center, theta, radius);
|
|
3203
|
+
return vec2f(
|
|
3204
|
+
latitudeLongitude.y * DGGS_RADIANS_TO_DEGREES,
|
|
3205
|
+
latitudeLongitude.x * DGGS_RADIANS_TO_DEGREES
|
|
3206
|
+
);
|
|
3207
|
+
}
|
|
3208
|
+
|
|
3209
|
+
fn dggs_h3_get_boundary_point(index: vec2u, vertexIndex: u32) -> vec2f {
|
|
3210
|
+
if (!dggs_h3_is_single_face_boundary(index)) {
|
|
3211
|
+
return vec2f(0.0);
|
|
3212
|
+
}
|
|
3213
|
+
|
|
3214
|
+
let vertex = dggs_h3_get_boundary_vertex(index, vertexIndex % 6u);
|
|
3215
|
+
let hexPoint = dggs_h3_ijk_to_hex2d(vertex.coord);
|
|
3216
|
+
return dggs_h3_hex2d_to_lnglat(hexPoint, vertex.face, vertex.resolution, true);
|
|
3217
|
+
}
|
|
3218
|
+
|
|
3219
|
+
fn dggs_h3_get_boundary_point_fp64_split(index: vec2u, vertexIndex: u32) -> vec4f {
|
|
3220
|
+
return dggs_boundary_point_to_fp64_split(dggs_h3_get_boundary_point(index, vertexIndex));
|
|
3221
|
+
}
|
|
3222
|
+
|
|
3223
|
+
fn dggs_s2_get_face(index: vec2u) -> u32 {
|
|
3224
|
+
return dggs_u64_extract_bits(index, 61u, 3u);
|
|
3225
|
+
}
|
|
3226
|
+
|
|
3227
|
+
fn dggs_s2_get_level(index: vec2u) -> u32 {
|
|
3228
|
+
let trailingZeros = dggs_u64_count_trailing_zeros(index);
|
|
3229
|
+
if (trailingZeros > 60u) {
|
|
3230
|
+
return 0u;
|
|
3231
|
+
}
|
|
3232
|
+
return DGGS_S2_MAX_LEVEL - trailingZeros / 2u;
|
|
3233
|
+
}
|
|
3234
|
+
|
|
3235
|
+
fn dggs_s2_is_valid_cell_id(index: vec2u) -> bool {
|
|
3236
|
+
let trailingZeros = dggs_u64_count_trailing_zeros(index);
|
|
3237
|
+
return !dggs_u64_is_zero(index) &&
|
|
3238
|
+
dggs_s2_get_face(index) <= 5u &&
|
|
3239
|
+
trailingZeros <= 60u &&
|
|
3240
|
+
trailingZeros % 2u == 0u;
|
|
3241
|
+
}
|
|
3242
|
+
|
|
3243
|
+
fn dggs_s2_get_child_position(index: vec2u, level: u32) -> u32 {
|
|
3244
|
+
if (level == 0u || level > DGGS_S2_MAX_LEVEL) {
|
|
3245
|
+
return 0u;
|
|
3246
|
+
}
|
|
3247
|
+
return dggs_u64_extract_bits(index, 2u * (DGGS_S2_MAX_LEVEL - level) + 1u, 2u);
|
|
3248
|
+
}
|
|
3249
|
+
|
|
3250
|
+
// Packed geohash keys store the geohash length in bits 60..63 and right-align
|
|
3251
|
+
// the base32 character codes in the lower 60 bits, first character first.
|
|
3252
|
+
fn dggs_geohash_get_length(index: vec2u) -> u32 {
|
|
3253
|
+
return min(
|
|
3254
|
+
dggs_u64_extract_bits(index, DGGS_GEOHASH_LENGTH_BIT_OFFSET, 4u),
|
|
3255
|
+
DGGS_GEOHASH_MAX_LENGTH
|
|
3256
|
+
);
|
|
3257
|
+
}
|
|
3258
|
+
|
|
3259
|
+
fn dggs_geohash_get_character(index: vec2u, characterIndex: u32) -> u32 {
|
|
3260
|
+
let length = dggs_geohash_get_length(index);
|
|
3261
|
+
if (characterIndex >= length) {
|
|
3262
|
+
return 0u;
|
|
3263
|
+
}
|
|
3264
|
+
return dggs_u64_extract_bits(index, 5u * (length - characterIndex - 1u), 5u);
|
|
3265
|
+
}
|
|
3266
|
+
|
|
3267
|
+
// Returns vec4(west, south, east, north) in longitude/latitude degrees.
|
|
3268
|
+
fn dggs_geohash_get_bounds(index: vec2u) -> vec4f {
|
|
3269
|
+
let length = dggs_geohash_get_length(index);
|
|
3270
|
+
var west = -180.0;
|
|
3271
|
+
var east = 180.0;
|
|
3272
|
+
var south = -90.0;
|
|
3273
|
+
var north = 90.0;
|
|
3274
|
+
var isLongitude = true;
|
|
3275
|
+
var characterIndex = 0u;
|
|
3276
|
+
loop {
|
|
3277
|
+
if (characterIndex >= length) {
|
|
3278
|
+
break;
|
|
3279
|
+
}
|
|
3280
|
+
|
|
3281
|
+
let character = dggs_geohash_get_character(index, characterIndex);
|
|
3282
|
+
var bitIndex = 0u;
|
|
3283
|
+
loop {
|
|
3284
|
+
if (bitIndex >= 5u) {
|
|
3285
|
+
break;
|
|
3286
|
+
}
|
|
3287
|
+
|
|
3288
|
+
let bit = (character >> (4u - bitIndex)) & 1u;
|
|
3289
|
+
if (isLongitude) {
|
|
3290
|
+
let midpoint = (west + east) * 0.5;
|
|
3291
|
+
if (bit == 0u) {
|
|
3292
|
+
east = midpoint;
|
|
3293
|
+
} else {
|
|
3294
|
+
west = midpoint;
|
|
3295
|
+
}
|
|
3296
|
+
} else {
|
|
3297
|
+
let midpoint = (south + north) * 0.5;
|
|
3298
|
+
if (bit == 0u) {
|
|
3299
|
+
north = midpoint;
|
|
3300
|
+
} else {
|
|
3301
|
+
south = midpoint;
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
isLongitude = !isLongitude;
|
|
3305
|
+
bitIndex += 1u;
|
|
3306
|
+
}
|
|
3307
|
+
characterIndex += 1u;
|
|
3308
|
+
}
|
|
3309
|
+
|
|
3310
|
+
return vec4f(west, south, east, north);
|
|
3311
|
+
}
|
|
3312
|
+
|
|
3313
|
+
fn dggs_bounds_get_boundary_point(bounds: vec4f, vertexIndex: u32) -> vec2f {
|
|
3314
|
+
let pointIndex = vertexIndex % 4u;
|
|
3315
|
+
if (pointIndex == 0u) {
|
|
3316
|
+
return vec2f(bounds.x, bounds.w);
|
|
3317
|
+
}
|
|
3318
|
+
if (pointIndex == 1u) {
|
|
3319
|
+
return vec2f(bounds.z, bounds.w);
|
|
3320
|
+
}
|
|
3321
|
+
if (pointIndex == 2u) {
|
|
3322
|
+
return vec2f(bounds.z, bounds.y);
|
|
3323
|
+
}
|
|
3324
|
+
return vec2f(bounds.x, bounds.y);
|
|
3325
|
+
}
|
|
3326
|
+
|
|
3327
|
+
fn dggs_geohash_get_boundary_point(index: vec2u, vertexIndex: u32) -> vec2f {
|
|
3328
|
+
return dggs_bounds_get_boundary_point(dggs_geohash_get_bounds(index), vertexIndex);
|
|
3329
|
+
}
|
|
3330
|
+
|
|
3331
|
+
fn dggs_geohash_get_boundary_point_fp64_split(index: vec2u, vertexIndex: u32) -> vec4f {
|
|
3332
|
+
return dggs_boundary_point_to_fp64_split(dggs_geohash_get_boundary_point(index, vertexIndex));
|
|
3333
|
+
}
|
|
3334
|
+
|
|
3335
|
+
// Packed quadkey keys store the quadkey length in bits 58..63 and right-align
|
|
3336
|
+
// the base4 digits in the lower 58 bits, first digit first.
|
|
3337
|
+
fn dggs_quadkey_get_length(index: vec2u) -> u32 {
|
|
3338
|
+
return min(
|
|
3339
|
+
dggs_u64_extract_bits(index, DGGS_QUADKEY_LENGTH_BIT_OFFSET, 6u),
|
|
3340
|
+
DGGS_QUADKEY_MAX_LENGTH
|
|
3341
|
+
);
|
|
3342
|
+
}
|
|
3343
|
+
|
|
3344
|
+
fn dggs_quadkey_get_digit(index: vec2u, digitIndex: u32) -> u32 {
|
|
3345
|
+
let length = dggs_quadkey_get_length(index);
|
|
3346
|
+
if (digitIndex >= length) {
|
|
3347
|
+
return 0u;
|
|
3348
|
+
}
|
|
3349
|
+
return dggs_u64_extract_bits(index, 2u * (length - digitIndex - 1u), 2u);
|
|
3350
|
+
}
|
|
3351
|
+
|
|
3352
|
+
fn dggs_quadkey_get_tile(index: vec2u) -> vec3u {
|
|
3353
|
+
let length = dggs_quadkey_get_length(index);
|
|
3354
|
+
var tileX = 0u;
|
|
3355
|
+
var tileY = 0u;
|
|
3356
|
+
var digitIndex = 0u;
|
|
3357
|
+
loop {
|
|
3358
|
+
if (digitIndex >= length) {
|
|
3359
|
+
break;
|
|
3360
|
+
}
|
|
3361
|
+
|
|
3362
|
+
let digit = dggs_quadkey_get_digit(index, digitIndex);
|
|
3363
|
+
let mask = 1u << (length - digitIndex - 1u);
|
|
3364
|
+
if ((digit & 1u) != 0u) {
|
|
3365
|
+
tileX |= mask;
|
|
3366
|
+
}
|
|
3367
|
+
if ((digit & 2u) != 0u) {
|
|
3368
|
+
tileY |= mask;
|
|
3369
|
+
}
|
|
3370
|
+
digitIndex += 1u;
|
|
3371
|
+
}
|
|
3372
|
+
return vec3u(tileX, tileY, length);
|
|
3373
|
+
}
|
|
3374
|
+
|
|
3375
|
+
fn dggs_web_mercator_tile_y_to_latitude(tileY: f32, tileScale: f32) -> f32 {
|
|
3376
|
+
let mercatorY = DGGS_PI * (1.0 - 2.0 * tileY / tileScale);
|
|
3377
|
+
return (2.0 * atan(exp(mercatorY)) - DGGS_PI * 0.5) * DGGS_RADIANS_TO_DEGREES;
|
|
3378
|
+
}
|
|
3379
|
+
|
|
3380
|
+
// Returns vec4(west, south, east, north) in longitude/latitude degrees.
|
|
3381
|
+
fn dggs_quadkey_get_bounds(index: vec2u) -> vec4f {
|
|
3382
|
+
let tile = dggs_quadkey_get_tile(index);
|
|
3383
|
+
let tileScale = f32(1u << tile.z);
|
|
3384
|
+
let west = f32(tile.x) / tileScale * 360.0 - 180.0;
|
|
3385
|
+
let east = f32(tile.x + 1u) / tileScale * 360.0 - 180.0;
|
|
3386
|
+
let north = dggs_web_mercator_tile_y_to_latitude(f32(tile.y), tileScale);
|
|
3387
|
+
let south = dggs_web_mercator_tile_y_to_latitude(f32(tile.y + 1u), tileScale);
|
|
3388
|
+
return vec4f(west, south, east, north);
|
|
3389
|
+
}
|
|
3390
|
+
|
|
3391
|
+
fn dggs_quadkey_get_boundary_point(index: vec2u, vertexIndex: u32) -> vec2f {
|
|
3392
|
+
return dggs_bounds_get_boundary_point(dggs_quadkey_get_bounds(index), vertexIndex);
|
|
3393
|
+
}
|
|
3394
|
+
|
|
3395
|
+
fn dggs_quadkey_get_boundary_point_fp64_split(index: vec2u, vertexIndex: u32) -> vec4f {
|
|
3396
|
+
return dggs_boundary_point_to_fp64_split(dggs_quadkey_get_boundary_point(index, vertexIndex));
|
|
3397
|
+
}
|
|
3398
|
+
|
|
3399
|
+
fn dggs_s2_digit_to_xy(digit: u32) -> vec2u {
|
|
3400
|
+
if (digit == 1u) {
|
|
3401
|
+
return vec2u(0u, 1u);
|
|
3402
|
+
}
|
|
3403
|
+
if (digit == 2u) {
|
|
3404
|
+
return vec2u(1u, 1u);
|
|
3405
|
+
}
|
|
3406
|
+
if (digit == 3u) {
|
|
3407
|
+
return vec2u(1u, 0u);
|
|
3408
|
+
}
|
|
3409
|
+
return vec2u(0u, 0u);
|
|
3410
|
+
}
|
|
3411
|
+
|
|
3412
|
+
fn dggs_s2_rotate_and_flip_quadrant(size: u32, point: vec2u, digitXY: vec2u) -> vec2u {
|
|
3413
|
+
var result = point;
|
|
3414
|
+
if (digitXY.y == 0u) {
|
|
3415
|
+
if (digitXY.x == 1u) {
|
|
3416
|
+
result = vec2u(size - 1u - result.x, size - 1u - result.y);
|
|
3417
|
+
}
|
|
3418
|
+
result = result.yx;
|
|
3419
|
+
}
|
|
3420
|
+
return result;
|
|
3421
|
+
}
|
|
3422
|
+
|
|
3423
|
+
fn dggs_s2_get_ij(index: vec2u) -> vec2u {
|
|
3424
|
+
let level = dggs_s2_get_level(index);
|
|
3425
|
+
var point = vec2u(0u);
|
|
3426
|
+
var hilbertLevel = 1u;
|
|
3427
|
+
loop {
|
|
3428
|
+
if (hilbertLevel > level) {
|
|
3429
|
+
break;
|
|
3430
|
+
}
|
|
3431
|
+
let digitLevel = level - hilbertLevel + 1u;
|
|
3432
|
+
let digitXY = dggs_s2_digit_to_xy(dggs_s2_get_child_position(index, digitLevel));
|
|
3433
|
+
let size = 1u << (hilbertLevel - 1u);
|
|
3434
|
+
point = dggs_s2_rotate_and_flip_quadrant(size, point, digitXY);
|
|
3435
|
+
point += size * digitXY;
|
|
3436
|
+
hilbertLevel += 1u;
|
|
3437
|
+
}
|
|
3438
|
+
if ((dggs_s2_get_face(index) & 1u) != 0u) {
|
|
3439
|
+
point = point.yx;
|
|
3440
|
+
}
|
|
3441
|
+
return point;
|
|
3442
|
+
}
|
|
3443
|
+
|
|
3444
|
+
fn dggs_s2_single_st_to_uv(st: f32) -> f32 {
|
|
3445
|
+
if (st >= 0.5) {
|
|
3446
|
+
return (4.0 * st * st - 1.0) / 3.0;
|
|
3447
|
+
}
|
|
3448
|
+
return (1.0 - 4.0 * (1.0 - st) * (1.0 - st)) / 3.0;
|
|
3449
|
+
}
|
|
3450
|
+
|
|
3451
|
+
fn dggs_s2_ij_to_st(ij: vec2u, level: u32, offset: vec2f) -> vec2f {
|
|
3452
|
+
let maxSize = f32(1u << level);
|
|
3453
|
+
return (vec2f(f32(ij.x), f32(ij.y)) + offset) / maxSize;
|
|
3454
|
+
}
|
|
3455
|
+
|
|
3456
|
+
fn dggs_s2_st_to_uv(st: vec2f) -> vec2f {
|
|
3457
|
+
return vec2f(dggs_s2_single_st_to_uv(st.x), dggs_s2_single_st_to_uv(st.y));
|
|
3458
|
+
}
|
|
3459
|
+
|
|
3460
|
+
fn dggs_s2_face_uv_to_xyz(face: u32, uv: vec2f) -> vec3f {
|
|
3461
|
+
if (face == 0u) {
|
|
3462
|
+
return vec3f(1.0, uv.x, uv.y);
|
|
3463
|
+
}
|
|
3464
|
+
if (face == 1u) {
|
|
3465
|
+
return vec3f(-uv.x, 1.0, uv.y);
|
|
3466
|
+
}
|
|
3467
|
+
if (face == 2u) {
|
|
3468
|
+
return vec3f(-uv.x, -uv.y, 1.0);
|
|
3469
|
+
}
|
|
3470
|
+
if (face == 3u) {
|
|
3471
|
+
return vec3f(-1.0, -uv.y, -uv.x);
|
|
3472
|
+
}
|
|
3473
|
+
if (face == 4u) {
|
|
3474
|
+
return vec3f(uv.y, -1.0, -uv.x);
|
|
3475
|
+
}
|
|
3476
|
+
return vec3f(uv.y, uv.x, -1.0);
|
|
3477
|
+
}
|
|
3478
|
+
|
|
3479
|
+
fn dggs_s2_xyz_to_lnglat(xyz: vec3f) -> vec2f {
|
|
3480
|
+
let latitude = atan2(xyz.z, length(xyz.xy)) * DGGS_RADIANS_TO_DEGREES;
|
|
3481
|
+
let longitude = atan2(xyz.y, xyz.x) * DGGS_RADIANS_TO_DEGREES;
|
|
3482
|
+
return vec2f(longitude, latitude);
|
|
3483
|
+
}
|
|
3484
|
+
|
|
3485
|
+
fn dggs_s2_get_boundary_offset(vertexIndex: u32) -> vec2f {
|
|
3486
|
+
let pointIndex = vertexIndex % 4u;
|
|
3487
|
+
if (pointIndex == 1u) {
|
|
3488
|
+
return vec2f(0.0, 1.0);
|
|
3489
|
+
}
|
|
3490
|
+
if (pointIndex == 2u) {
|
|
3491
|
+
return vec2f(1.0, 1.0);
|
|
3492
|
+
}
|
|
3493
|
+
if (pointIndex == 3u) {
|
|
3494
|
+
return vec2f(1.0, 0.0);
|
|
3495
|
+
}
|
|
3496
|
+
return vec2f(0.0, 0.0);
|
|
3497
|
+
}
|
|
3498
|
+
|
|
3499
|
+
fn dggs_s2_get_boundary_point(index: vec2u, vertexIndex: u32) -> vec2f {
|
|
3500
|
+
let level = dggs_s2_get_level(index);
|
|
3501
|
+
let ij = dggs_s2_get_ij(index);
|
|
3502
|
+
let st = dggs_s2_ij_to_st(ij, level, dggs_s2_get_boundary_offset(vertexIndex));
|
|
3503
|
+
let uv = dggs_s2_st_to_uv(st);
|
|
3504
|
+
let xyz = dggs_s2_face_uv_to_xyz(dggs_s2_get_face(index), uv);
|
|
3505
|
+
return dggs_s2_xyz_to_lnglat(xyz);
|
|
3506
|
+
}
|
|
3507
|
+
|
|
3508
|
+
fn dggs_s2_get_boundary_point_fp64_split(index: vec2u, vertexIndex: u32) -> vec4f {
|
|
3509
|
+
return dggs_boundary_point_to_fp64_split(dggs_s2_get_boundary_point(index, vertexIndex));
|
|
3510
|
+
}
|
|
3511
|
+
`;var di={name:"dggs",source:gi};var D={RGBA8UNORM:0,RGBA16FLOAT:1,RGBA32FLOAT:2},We={rgba8unorm:4,rgba16float:8,rgba32float:16},Ke={...We},Ct={rgba8unorm:D.RGBA8UNORM,rgba16float:D.RGBA16FLOAT,rgba32float:D.RGBA32FLOAT},vi={[D.RGBA8UNORM]:"rgba8unorm",[D.RGBA16FLOAT]:"rgba16float",[D.RGBA32FLOAT]:"rgba32float"},bi={useByteColors:"f32"},xi={useByteColors:!0},aa={format:"u32",wordStride:"u32",wordOffset:"u32",_padding:"u32"},sa={format:D.RGBA8UNORM,wordStride:Ke.rgba8unorm/Uint32Array.BYTES_PER_ELEMENT,wordOffset:0,_padding:0},_i=Si("colors"),hi=Si("floatColors"),la=Mi("colors"),ca=Mi("floatColors"),fa=`struct storageColorsUniforms {
|
|
3512
|
+
format: u32,
|
|
3513
|
+
wordStride: u32,
|
|
3514
|
+
wordOffset: u32,
|
|
3515
|
+
_padding: u32
|
|
3516
|
+
};
|
|
3517
|
+
|
|
3518
|
+
@group(0) @binding(auto) var<uniform> storageColors : storageColorsUniforms;
|
|
3519
|
+
@group(0) @binding(auto) var<storage, read> storageColorsBuffer : array<u32>;
|
|
3520
|
+
|
|
3521
|
+
const STORAGE_COLOR_FORMAT_RGBA8UNORM : u32 = ${D.RGBA8UNORM}u;
|
|
3522
|
+
const STORAGE_COLOR_FORMAT_RGBA16FLOAT : u32 = ${D.RGBA16FLOAT}u;
|
|
3523
|
+
|
|
3524
|
+
fn storageColors_getWordIndex(rowIndex: u32) -> u32 {
|
|
3525
|
+
return storageColors.wordOffset + rowIndex * storageColors.wordStride;
|
|
3526
|
+
}
|
|
3527
|
+
|
|
3528
|
+
fn storageColors_readRgba8UnormColor(wordIndex: u32) -> vec4<f32> {
|
|
3529
|
+
return unpack4x8unorm(storageColorsBuffer[wordIndex]);
|
|
3530
|
+
}
|
|
3531
|
+
|
|
3532
|
+
fn storageColors_readRgba16FloatColor(wordIndex: u32) -> vec4<f32> {
|
|
3533
|
+
let redGreen = unpack2x16float(storageColorsBuffer[wordIndex]);
|
|
3534
|
+
let blueAlpha = unpack2x16float(storageColorsBuffer[wordIndex + 1u]);
|
|
3535
|
+
return vec4<f32>(redGreen.x, redGreen.y, blueAlpha.x, blueAlpha.y);
|
|
3536
|
+
}
|
|
3537
|
+
|
|
3538
|
+
fn storageColors_readRgba32FloatColor(wordIndex: u32) -> vec4<f32> {
|
|
3539
|
+
return vec4<f32>(
|
|
3540
|
+
bitcast<f32>(storageColorsBuffer[wordIndex]),
|
|
3541
|
+
bitcast<f32>(storageColorsBuffer[wordIndex + 1u]),
|
|
3542
|
+
bitcast<f32>(storageColorsBuffer[wordIndex + 2u]),
|
|
3543
|
+
bitcast<f32>(storageColorsBuffer[wordIndex + 3u])
|
|
3544
|
+
);
|
|
3545
|
+
}
|
|
3546
|
+
|
|
3547
|
+
fn storageColors_readColor(rowIndex: u32) -> vec4<f32> {
|
|
3548
|
+
let wordIndex = storageColors_getWordIndex(rowIndex);
|
|
3549
|
+
if (storageColors.format == STORAGE_COLOR_FORMAT_RGBA8UNORM) {
|
|
3550
|
+
return storageColors_readRgba8UnormColor(wordIndex);
|
|
3551
|
+
}
|
|
3552
|
+
if (storageColors.format == STORAGE_COLOR_FORMAT_RGBA16FLOAT) {
|
|
3553
|
+
return storageColors_readRgba16FloatColor(wordIndex);
|
|
3554
|
+
}
|
|
3555
|
+
return storageColors_readRgba32FloatColor(wordIndex);
|
|
3556
|
+
}
|
|
3557
|
+
`;function Si(e){return`layout(std140) uniform ${e}Uniforms {
|
|
3558
|
+
float useByteColors;
|
|
3559
|
+
} ${e};
|
|
3560
|
+
|
|
3561
|
+
vec3 ${e}_normalize(vec3 inputColor) {
|
|
3562
|
+
return ${e}.useByteColors > 0.5 ? inputColor / 255.0 : inputColor;
|
|
3563
|
+
}
|
|
3564
|
+
|
|
3565
|
+
vec4 ${e}_normalize(vec4 inputColor) {
|
|
3566
|
+
return ${e}.useByteColors > 0.5 ? inputColor / 255.0 : inputColor;
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
vec4 ${e}_premultiplyAlpha(vec4 inputColor) {
|
|
3570
|
+
return vec4(inputColor.rgb * inputColor.a, inputColor.a);
|
|
3571
|
+
}
|
|
3572
|
+
|
|
3573
|
+
vec4 ${e}_unpremultiplyAlpha(vec4 inputColor) {
|
|
3574
|
+
return inputColor.a > 0.0 ? vec4(inputColor.rgb / inputColor.a, inputColor.a) : vec4(0.0);
|
|
3575
|
+
}
|
|
3576
|
+
|
|
3577
|
+
vec4 ${e}_premultiply_alpha(vec4 inputColor) {
|
|
3578
|
+
return ${e}_premultiplyAlpha(inputColor);
|
|
3579
|
+
}
|
|
3580
|
+
|
|
3581
|
+
vec4 ${e}_unpremultiply_alpha(vec4 inputColor) {
|
|
3582
|
+
return ${e}_unpremultiplyAlpha(inputColor);
|
|
3583
|
+
}
|
|
3584
|
+
`}function Mi(e){return`struct ${e}Uniforms {
|
|
3585
|
+
useByteColors: f32
|
|
3586
|
+
};
|
|
3587
|
+
|
|
3588
|
+
@group(0) @binding(auto) var<uniform> ${e} : ${e}Uniforms;
|
|
3589
|
+
|
|
3590
|
+
fn ${e}_normalize(inputColor: vec3<f32>) -> vec3<f32> {
|
|
3591
|
+
return select(inputColor, inputColor / 255.0, ${e}.useByteColors > 0.5);
|
|
3592
|
+
}
|
|
3593
|
+
|
|
3594
|
+
fn ${e}_normalize4(inputColor: vec4<f32>) -> vec4<f32> {
|
|
3595
|
+
return select(inputColor, inputColor / 255.0, ${e}.useByteColors > 0.5);
|
|
3596
|
+
}
|
|
3597
|
+
|
|
3598
|
+
fn ${e}_premultiplyAlpha(inputColor: vec4<f32>) -> vec4<f32> {
|
|
3599
|
+
return vec4<f32>(inputColor.rgb * inputColor.a, inputColor.a);
|
|
3600
|
+
}
|
|
3601
|
+
|
|
3602
|
+
fn ${e}_unpremultiplyAlpha(inputColor: vec4<f32>) -> vec4<f32> {
|
|
3603
|
+
return select(
|
|
3604
|
+
vec4<f32>(0.0),
|
|
3605
|
+
vec4<f32>(inputColor.rgb / inputColor.a, inputColor.a),
|
|
3606
|
+
inputColor.a > 0.0
|
|
3607
|
+
);
|
|
3608
|
+
}
|
|
3609
|
+
|
|
3610
|
+
fn ${e}_premultiply_alpha(inputColor: vec4<f32>) -> vec4<f32> {
|
|
3611
|
+
return ${e}_premultiplyAlpha(inputColor);
|
|
3612
|
+
}
|
|
3613
|
+
|
|
3614
|
+
fn ${e}_unpremultiply_alpha(inputColor: vec4<f32>) -> vec4<f32> {
|
|
3615
|
+
return ${e}_unpremultiplyAlpha(inputColor);
|
|
3616
|
+
}
|
|
3617
|
+
`}function ua(e={}){let t=pa(e.format),n=vi[t],i=e.byteStride??Ke[n],r=e.byteOffset??0,o=We[n];if(mi("byteStride",i),mi("byteOffset",r),i<o)throw new Error(`storageColors byteStride must be at least ${o} for ${n}`);return{format:t,wordStride:i/Uint32Array.BYTES_PER_ELEMENT,wordOffset:r/Uint32Array.BYTES_PER_ELEMENT,_padding:0}}function pa(e="rgba8unorm"){if(typeof e=="number"){if(e in vi)return e}else if(e in Ct)return Ct[e];throw new Error(`storageColors format must be one of ${Object.keys(Ct).join(", ")}`)}function mi(e,t){if(!Number.isInteger(t)||t<0||t%Uint32Array.BYTES_PER_ELEMENT!==0)throw new Error(`storageColors ${e} must be a non-negative 4-byte aligned integer`)}var Li={name:"colors",props:{},uniforms:{},vs:_i,fs:_i,source:la,uniformTypes:bi,defaultUniforms:xi},oe={name:"floatColors",props:{},uniforms:{},vs:hi,fs:hi,source:ca,uniformTypes:bi,defaultUniforms:xi},Ai={name:"storageColors",props:{},uniforms:{},bindings:{},source:fa,uniformTypes:aa,defaultUniforms:sa,bindingLayout:[{name:"storageColors",group:0},{name:"storageColorsBuffer",group:0}],getUniforms(e={}){return{...ua(e),...e.colorBuffer?{storageColorsBuffer:e.colorBuffer}:{}}}};var ga=[0,1,1,1],da=`layout(std140) uniform pickingUniforms {
|
|
3618
|
+
float isActive;
|
|
3619
|
+
float isAttribute;
|
|
3620
|
+
float isHighlightActive;
|
|
3621
|
+
float useByteColors;
|
|
3622
|
+
vec3 highlightedObjectColor;
|
|
3623
|
+
vec4 highlightColor;
|
|
3624
|
+
} picking;
|
|
3625
|
+
|
|
3626
|
+
out vec4 picking_vRGBcolor_Avalid;
|
|
3627
|
+
|
|
3628
|
+
// Normalize unsigned byte color to 0-1 range
|
|
3629
|
+
vec3 picking_normalizeColor(vec3 color) {
|
|
3630
|
+
return picking.useByteColors > 0.5 ? color / 255.0 : color;
|
|
3631
|
+
}
|
|
3632
|
+
|
|
3633
|
+
// Normalize unsigned byte color to 0-1 range
|
|
3634
|
+
vec4 picking_normalizeColor(vec4 color) {
|
|
3635
|
+
return picking.useByteColors > 0.5 ? color / 255.0 : color;
|
|
3636
|
+
}
|
|
3637
|
+
|
|
3638
|
+
bool picking_isColorZero(vec3 color) {
|
|
3639
|
+
return dot(color, vec3(1.0)) < 0.00001;
|
|
3640
|
+
}
|
|
3641
|
+
|
|
3642
|
+
bool picking_isColorValid(vec3 color) {
|
|
3643
|
+
return dot(color, vec3(1.0)) > 0.00001;
|
|
3644
|
+
}
|
|
3645
|
+
|
|
3646
|
+
// Check if this vertex is highlighted
|
|
3647
|
+
bool isVertexHighlighted(vec3 vertexColor) {
|
|
3648
|
+
vec3 highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);
|
|
3649
|
+
return
|
|
3650
|
+
bool(picking.isHighlightActive) && picking_isColorZero(abs(vertexColor - highlightedObjectColor));
|
|
3651
|
+
}
|
|
3652
|
+
|
|
3653
|
+
// Set the current picking color
|
|
3654
|
+
void picking_setPickingColor(vec3 pickingColor) {
|
|
3655
|
+
pickingColor = picking_normalizeColor(pickingColor);
|
|
3656
|
+
|
|
3657
|
+
if (bool(picking.isActive)) {
|
|
3658
|
+
// Use alpha as the validity flag. If pickingColor is [0, 0, 0] fragment is non-pickable
|
|
3659
|
+
picking_vRGBcolor_Avalid.a = float(picking_isColorValid(pickingColor));
|
|
3660
|
+
|
|
3661
|
+
if (!bool(picking.isAttribute)) {
|
|
3662
|
+
// Stores the picking color so that the fragment shader can render it during picking
|
|
3663
|
+
picking_vRGBcolor_Avalid.rgb = pickingColor;
|
|
3664
|
+
}
|
|
3665
|
+
} else {
|
|
3666
|
+
// Do the comparison with selected item color in vertex shader as it should mean fewer compares
|
|
3667
|
+
picking_vRGBcolor_Avalid.a = float(isVertexHighlighted(pickingColor));
|
|
3668
|
+
}
|
|
3669
|
+
}
|
|
3670
|
+
|
|
3671
|
+
void picking_setPickingAttribute(float value) {
|
|
3672
|
+
if (bool(picking.isAttribute)) {
|
|
3673
|
+
picking_vRGBcolor_Avalid.r = value;
|
|
3674
|
+
}
|
|
3675
|
+
}
|
|
3676
|
+
|
|
3677
|
+
void picking_setPickingAttribute(vec2 value) {
|
|
3678
|
+
if (bool(picking.isAttribute)) {
|
|
3679
|
+
picking_vRGBcolor_Avalid.rg = value;
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
|
|
3683
|
+
void picking_setPickingAttribute(vec3 value) {
|
|
3684
|
+
if (bool(picking.isAttribute)) {
|
|
3685
|
+
picking_vRGBcolor_Avalid.rgb = value;
|
|
3686
|
+
}
|
|
3687
|
+
}
|
|
3688
|
+
`,_a=`layout(std140) uniform pickingUniforms {
|
|
3689
|
+
float isActive;
|
|
3690
|
+
float isAttribute;
|
|
3691
|
+
float isHighlightActive;
|
|
3692
|
+
float useByteColors;
|
|
3693
|
+
vec3 highlightedObjectColor;
|
|
3694
|
+
vec4 highlightColor;
|
|
3695
|
+
} picking;
|
|
3696
|
+
|
|
3697
|
+
in vec4 picking_vRGBcolor_Avalid;
|
|
3698
|
+
|
|
3699
|
+
/*
|
|
3700
|
+
* Returns highlight color if this item is selected.
|
|
3701
|
+
*/
|
|
3702
|
+
vec4 picking_filterHighlightColor(vec4 color) {
|
|
3703
|
+
// If we are still picking, we don't highlight
|
|
3704
|
+
if (picking.isActive > 0.5) {
|
|
3705
|
+
return color;
|
|
3706
|
+
}
|
|
3707
|
+
|
|
3708
|
+
bool selected = bool(picking_vRGBcolor_Avalid.a);
|
|
3709
|
+
|
|
3710
|
+
if (selected) {
|
|
3711
|
+
// Blend in highlight color based on its alpha value
|
|
3712
|
+
float highLightAlpha = picking.highlightColor.a;
|
|
3713
|
+
float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
|
|
3714
|
+
float highLightRatio = highLightAlpha / blendedAlpha;
|
|
3715
|
+
|
|
3716
|
+
vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);
|
|
3717
|
+
return vec4(blendedRGB, blendedAlpha);
|
|
3718
|
+
} else {
|
|
3719
|
+
return color;
|
|
3720
|
+
}
|
|
3721
|
+
}
|
|
3722
|
+
|
|
3723
|
+
/*
|
|
3724
|
+
* Returns picking color if picking enabled else unmodified argument.
|
|
3725
|
+
*/
|
|
3726
|
+
vec4 picking_filterPickingColor(vec4 color) {
|
|
3727
|
+
if (bool(picking.isActive)) {
|
|
3728
|
+
if (picking_vRGBcolor_Avalid.a == 0.0) {
|
|
3729
|
+
discard;
|
|
3730
|
+
}
|
|
3731
|
+
return picking_vRGBcolor_Avalid;
|
|
3732
|
+
}
|
|
3733
|
+
return color;
|
|
3734
|
+
}
|
|
3735
|
+
|
|
3736
|
+
/*
|
|
3737
|
+
* Returns picking color if picking is enabled if not
|
|
3738
|
+
* highlight color if this item is selected, otherwise unmodified argument.
|
|
3739
|
+
*/
|
|
3740
|
+
vec4 picking_filterColor(vec4 color) {
|
|
3741
|
+
vec4 highlightColor = picking_filterHighlightColor(color);
|
|
3742
|
+
return picking_filterPickingColor(highlightColor);
|
|
3743
|
+
}
|
|
3744
|
+
`,Ii={props:{},uniforms:{},name:"picking",uniformTypes:{isActive:"f32",isAttribute:"f32",isHighlightActive:"f32",useByteColors:"f32",highlightedObjectColor:"vec3<f32>",highlightColor:"vec4<f32>"},defaultUniforms:{isActive:!1,isAttribute:!1,isHighlightActive:!1,useByteColors:!0,highlightedObjectColor:[0,0,0],highlightColor:ga},vs:da,fs:_a,getUniforms:ha};function ha(e={},t){let n={},i=re(e.useByteColors,!0);if(e.highlightedObjectColor!==void 0)if(e.highlightedObjectColor===null)n.isHighlightActive=!1;else{n.isHighlightActive=!0;let r=e.highlightedObjectColor.slice(0,3);n.highlightedObjectColor=r}return e.highlightColor&&(n.highlightColor=qe(e.highlightColor,i)),e.isActive!==void 0&&(n.isActive=Boolean(e.isActive),n.isAttribute=Boolean(e.isAttribute)),e.useByteColors!==void 0&&(n.useByteColors=Boolean(e.useByteColors)),n}var ma={name:"filter",props:{},uniforms:{},bindingLayout:[{name:"filter",group:2}],uniformTypes:{enabled:"i32",min:"f32",max:"f32"},defaultUniforms:{enabled:1,min:0,max:1},vs:`layout(std140) uniform filterUniforms {
|
|
3745
|
+
int enabled;
|
|
3746
|
+
float min;
|
|
3747
|
+
float max;
|
|
3748
|
+
} filterState;
|
|
3749
|
+
|
|
3750
|
+
bool filter_isVisible(float value) {
|
|
3751
|
+
return filterState.enabled == 0 || (value >= filterState.min && value <= filterState.max);
|
|
3752
|
+
}
|
|
3753
|
+
`,source:`struct FilterUniforms {
|
|
3754
|
+
enabled: i32,
|
|
3755
|
+
min: f32,
|
|
3756
|
+
max: f32,
|
|
3757
|
+
};
|
|
3758
|
+
|
|
3759
|
+
@group(2) @binding(auto) var<uniform> filterUniforms: FilterUniforms;
|
|
3760
|
+
|
|
3761
|
+
fn filter_isVisible(value: f32) -> bool {
|
|
3762
|
+
return filterUniforms.enabled == 0 ||
|
|
3763
|
+
(value >= filterUniforms.min && value <= filterUniforms.max);
|
|
3764
|
+
}
|
|
3765
|
+
`,getUniforms(e={}){let t={};return e.enabled!==void 0&&(t.enabled=Number(e.enabled)),e.min!==void 0&&(t.min=e.min),e.max!==void 0&&(t.max=e.max),t}},Ei={name:"filter",modules:[ma],vertexInputs:{filterValues:"f32"},glsl:{injections:[{target:"vs:FILTER_POSITION",injection:`if (!filter_isVisible(filterValues)) {
|
|
3766
|
+
position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
3767
|
+
}`}]},wgsl:{injections:[{target:"vs:FILTER_POSITION",injection:`if (!filter_isVisible(filterValues)) {
|
|
3768
|
+
*position = vec4<f32>(2.0, 2.0, 2.0, 1.0);
|
|
3769
|
+
}`}]}};var va={name:"clip",props:{},uniforms:{},bindingLayout:[{name:"clip",group:2}],uniformTypes:{enabled:"i32",mode:"i32",bounds:"vec4<f32>"},defaultUniforms:{enabled:1,mode:0,bounds:[0,0,1,1]},vs:`layout(std140) uniform clipUniforms {
|
|
3770
|
+
highp int enabled;
|
|
3771
|
+
highp int mode;
|
|
3772
|
+
highp vec4 bounds;
|
|
3773
|
+
} clipState;
|
|
3774
|
+
|
|
3775
|
+
bool clip_isInBounds(vec2 coordinates) {
|
|
3776
|
+
return coordinates.x >= clipState.bounds.x &&
|
|
3777
|
+
coordinates.y >= clipState.bounds.y &&
|
|
3778
|
+
coordinates.x < clipState.bounds.z &&
|
|
3779
|
+
coordinates.y < clipState.bounds.w;
|
|
3780
|
+
}
|
|
3781
|
+
`,fs:`layout(std140) uniform clipUniforms {
|
|
3782
|
+
highp int enabled;
|
|
3783
|
+
highp int mode;
|
|
3784
|
+
highp vec4 bounds;
|
|
3785
|
+
} clipState;
|
|
3786
|
+
|
|
3787
|
+
bool clip_isInBounds(vec2 coordinates) {
|
|
3788
|
+
return coordinates.x >= clipState.bounds.x &&
|
|
3789
|
+
coordinates.y >= clipState.bounds.y &&
|
|
3790
|
+
coordinates.x < clipState.bounds.z &&
|
|
3791
|
+
coordinates.y < clipState.bounds.w;
|
|
3792
|
+
}
|
|
3793
|
+
`,source:`struct ClipUniforms {
|
|
3794
|
+
enabled: i32,
|
|
3795
|
+
mode: i32,
|
|
3796
|
+
bounds: vec4<f32>,
|
|
3797
|
+
};
|
|
3798
|
+
|
|
3799
|
+
@group(2) @binding(auto) var<uniform> clipUniforms: ClipUniforms;
|
|
3800
|
+
|
|
3801
|
+
fn clip_isInBounds(coordinates: vec2<f32>) -> bool {
|
|
3802
|
+
return coordinates.x >= clipUniforms.bounds.x &&
|
|
3803
|
+
coordinates.y >= clipUniforms.bounds.y &&
|
|
3804
|
+
coordinates.x < clipUniforms.bounds.z &&
|
|
3805
|
+
coordinates.y < clipUniforms.bounds.w;
|
|
3806
|
+
}
|
|
3807
|
+
`,getUniforms(e={}){let t={};return e.enabled!==void 0&&(t.enabled=Number(e.enabled)),e.mode!==void 0&&(t.mode=e.mode==="instance"?1:0),e.bounds!==void 0&&(t.bounds=e.bounds),t}},Ri={name:"clip",modules:[va],varyings:{clipCoordinates:{type:"vec2<f32>",interpolation:"smooth"}},glsl:{injections:[{target:"vs:CLIP_POSITION",injection:`clipCoordinates = geometryCoordinates;
|
|
3808
|
+
if (clipState.enabled != 0 && clipState.mode == ${1} &&
|
|
3809
|
+
!clip_isInBounds(instanceCoordinates)) {
|
|
3810
|
+
position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
3811
|
+
}`},{target:"fs:CLIP_COLOR",injection:`if (clipState.enabled != 0 && clipState.mode == ${0} &&
|
|
3812
|
+
!clip_isInBounds(clipCoordinates)) {
|
|
3813
|
+
discard;
|
|
3814
|
+
}`}]},wgsl:{injections:[{target:"vs:CLIP_POSITION",injection:`clipCoordinates = geometryCoordinates;
|
|
3815
|
+
if (clipUniforms.enabled != 0 && clipUniforms.mode == ${1} &&
|
|
3816
|
+
!clip_isInBounds(instanceCoordinates)) {
|
|
3817
|
+
*position = vec4<f32>(2.0, 2.0, 2.0, 1.0);
|
|
3818
|
+
}`},{target:"fs:CLIP_COLOR",injection:`if (clipUniforms.enabled != 0 && clipUniforms.mode == ${0} &&
|
|
3819
|
+
!clip_isInBounds(clipCoordinates)) {
|
|
3820
|
+
discard;
|
|
3821
|
+
}`}]}};var ve=20,ba=`
|
|
3822
|
+
struct skinUniforms {
|
|
3823
|
+
jointMatrix: array<mat4x4<f32>, ${ve}>,
|
|
3824
|
+
};
|
|
3825
|
+
|
|
3826
|
+
@group(0) @binding(auto) var<uniform> skin: skinUniforms;
|
|
3827
|
+
|
|
3828
|
+
fn getSkinMatrix(weights: vec4f, joints: vec4u) -> mat4x4<f32> {
|
|
3829
|
+
return (weights.x * skin.jointMatrix[joints.x])
|
|
3830
|
+
+ (weights.y * skin.jointMatrix[joints.y])
|
|
3831
|
+
+ (weights.z * skin.jointMatrix[joints.z])
|
|
3832
|
+
+ (weights.w * skin.jointMatrix[joints.w]);
|
|
3833
|
+
}
|
|
3834
|
+
`,xa=`
|
|
3835
|
+
layout(std140) uniform skinUniforms {
|
|
3836
|
+
mat4 jointMatrix[SKIN_MAX_JOINTS];
|
|
3837
|
+
} skin;
|
|
3838
|
+
|
|
3839
|
+
mat4 getSkinMatrix(vec4 weights, uvec4 joints) {
|
|
3840
|
+
return (weights.x * skin.jointMatrix[joints.x])
|
|
3841
|
+
+ (weights.y * skin.jointMatrix[joints.y])
|
|
3842
|
+
+ (weights.z * skin.jointMatrix[joints.z])
|
|
3843
|
+
+ (weights.w * skin.jointMatrix[joints.w]);
|
|
3844
|
+
}
|
|
3845
|
+
|
|
3846
|
+
`,Sa="",Ci={props:{},uniforms:{},name:"skin",bindingLayout:[{name:"skin",group:0}],dependencies:[],source:ba,vs:xa,fs:Sa,defines:{SKIN_MAX_JOINTS:ve},getUniforms:(e={},t)=>{let{scenegraphsFromGLTF:n}=e;if(!n?.gltf?.skins?.[0])return{jointMatrix:[]};let{inverseBindMatrices:i,joints:r,skeleton:o}=n.gltf.skins[0],a=[],s=i.value.length/16;for(let u=0;u<s;u++){let p=i.value.subarray(u*16,u*16+16);a.push(new $(Array.from(p)))}let l=n.gltfNodeIndexToNodeMap.get(o),c={};l.preorderTraversal((u,{worldMatrix:p})=>{c[u.id]=p});let f=new Float32Array(ve*16);for(let u=0;u<ve;++u){let p=r[u];if(p===void 0)break;let g=c[n.gltfNodeIndexToNodeMap.get(p).id],_=a[u],m=new $().copy(g).multiplyRight(_),b=u*16;for(let x=0;x<16;x++)f[b+x]=m[x]}return{jointMatrix:f}},uniformTypes:{jointMatrix:["mat4x4<f32>",ve]}};var wi=se(Z(),1);var yt=`precision highp int;
|
|
3847
|
+
|
|
3848
|
+
// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
3849
|
+
struct AmbientLight {
|
|
3850
|
+
vec3 color;
|
|
3851
|
+
};
|
|
3852
|
+
|
|
3853
|
+
struct PointLight {
|
|
3854
|
+
vec3 color;
|
|
3855
|
+
vec3 position;
|
|
3856
|
+
vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential
|
|
3857
|
+
};
|
|
3858
|
+
|
|
3859
|
+
struct SpotLight {
|
|
3860
|
+
vec3 color;
|
|
3861
|
+
vec3 position;
|
|
3862
|
+
vec3 direction;
|
|
3863
|
+
vec3 attenuation;
|
|
3864
|
+
vec2 coneCos;
|
|
3865
|
+
};
|
|
3866
|
+
|
|
3867
|
+
struct DirectionalLight {
|
|
3868
|
+
vec3 color;
|
|
3869
|
+
vec3 direction;
|
|
3870
|
+
};
|
|
3871
|
+
|
|
3872
|
+
struct UniformLight {
|
|
3873
|
+
vec3 color;
|
|
1575
3874
|
vec3 position;
|
|
1576
3875
|
vec3 direction;
|
|
1577
3876
|
vec3 attenuation;
|
|
@@ -1624,7 +3923,7 @@ float getSpotLightAttenuation(SpotLight spotLight, vec3 positionWorldspace) {
|
|
|
1624
3923
|
}
|
|
1625
3924
|
|
|
1626
3925
|
// #endif
|
|
1627
|
-
`;var
|
|
3926
|
+
`;var yi=`// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
1628
3927
|
const MAX_LIGHTS: i32 = 5;
|
|
1629
3928
|
|
|
1630
3929
|
struct AmbientLight {
|
|
@@ -1703,7 +4002,7 @@ fn getSpotLightAttenuation(spotLight: SpotLight, positionWorldspace: vec3<f32>)
|
|
|
1703
4002
|
);
|
|
1704
4003
|
return distanceAttenuation / max(coneFactor, 0.0001);
|
|
1705
4004
|
}
|
|
1706
|
-
`;var
|
|
4005
|
+
`;var X=5,Ma={color:"vec3<f32>",position:"vec3<f32>",direction:"vec3<f32>",attenuation:"vec3<f32>",coneCos:"vec2<f32>"},U={props:{},uniforms:{},name:"lighting",defines:{},uniformTypes:{enabled:"i32",directionalLightCount:"i32",pointLightCount:"i32",spotLightCount:"i32",ambientColor:"vec3<f32>",lights:[Ma,X]},defaultUniforms:Xe(),bindingLayout:[{name:"lighting",group:2}],firstBindingSlot:0,source:yi,vs:yt,fs:yt,getUniforms:La};function La(e,t={}){if(e=e&&{...e},!e)return Xe();e.lights&&(e={...e,...Ia(e.lights),lights:void 0});let{useByteColors:n,ambientLight:i,pointLights:r,spotLights:o,directionalLights:a}=e||{};if(!(i||r&&r.length>0||o&&o.length>0||a&&a.length>0))return{...Xe(),enabled:0};let l={...Xe(),...Aa({useByteColors:n,ambientLight:i,pointLights:r,spotLights:o,directionalLights:a})};return e.enabled!==void 0&&(l.enabled=e.enabled?1:0),l}function Aa({useByteColors:e,ambientLight:t,pointLights:n=[],spotLights:i=[],directionalLights:r=[]}){let o=Ti(),a=0,s=0,l=0,c=0;for(let f of n){if(a>=X)break;o[a]={...o[a],color:Ye(f,e),position:f.position,attenuation:f.attenuation||[1,0,0]},a++,s++}for(let f of i){if(a>=X)break;o[a]={...o[a],color:Ye(f,e),position:f.position,direction:f.direction,attenuation:f.attenuation||[1,0,0],coneCos:Ra(f)},a++,l++}for(let f of r){if(a>=X)break;o[a]={...o[a],color:Ye(f,e),direction:f.direction},a++,c++}return n.length+i.length+r.length>X&&wi.log.warn(`MAX_LIGHTS exceeded, truncating to ${X}`)(),{ambientColor:Ye(t,e),directionalLightCount:c,pointLightCount:s,spotLightCount:l,lights:o}}function Ia(e){let t={pointLights:[],spotLights:[],directionalLights:[]};for(let n of e||[])switch(n.type){case"ambient":t.ambientLight=n;break;case"directional":t.directionalLights?.push(n);break;case"point":t.pointLights?.push(n);break;case"spot":t.spotLights?.push(n);break;default:}return t}function Ye(e={},t){let{color:n=[0,0,0],intensity:i=1}=e;return me(n,re(t,!0)).map(o=>o*i)}function Xe(){return{enabled:1,directionalLightCount:0,pointLightCount:0,spotLightCount:0,ambientColor:[.1,.1,.1],lights:Ti()}}function Ti(){return Array.from({length:X},()=>Ea())}function Ea(){return{color:[1,1,1],position:[1,1,2],direction:[1,1,1],attenuation:[1,0,0],coneCos:[1,0]}}function Ra(e){let t=e.innerConeAngle??0,n=e.outerConeAngle??Math.PI/4;return[Math.cos(t),Math.cos(n)]}var Ca=`#ifdef USE_IBL
|
|
1707
4006
|
@group(2) @binding(auto) var pbr_diffuseEnvSampler: texture_cube<f32>;
|
|
1708
4007
|
@group(2) @binding(auto) var pbr_diffuseEnvSamplerSampler: sampler;
|
|
1709
4008
|
@group(2) @binding(auto) var pbr_specularEnvSampler: texture_cube<f32>;
|
|
@@ -1711,12 +4010,12 @@ fn getSpotLightAttenuation(spotLight: SpotLight, positionWorldspace: vec3<f32>)
|
|
|
1711
4010
|
@group(2) @binding(auto) var pbr_brdfLUT: texture_2d<f32>;
|
|
1712
4011
|
@group(2) @binding(auto) var pbr_brdfLUTSampler: sampler;
|
|
1713
4012
|
#endif
|
|
1714
|
-
`,
|
|
4013
|
+
`,Ni=`#ifdef USE_IBL
|
|
1715
4014
|
uniform samplerCube pbr_diffuseEnvSampler;
|
|
1716
4015
|
uniform samplerCube pbr_specularEnvSampler;
|
|
1717
4016
|
uniform sampler2D pbr_brdfLUT;
|
|
1718
4017
|
#endif
|
|
1719
|
-
`,
|
|
4018
|
+
`,Ze={name:"ibl",firstBindingSlot:32,bindingLayout:[{name:"pbr_diffuseEnvSampler",group:2},{name:"pbr_specularEnvSampler",group:2},{name:"pbr_brdfLUT",group:2}],source:Ca,vs:Ni,fs:Ni};var ya=`struct dirlightUniforms {
|
|
1720
4019
|
lightDirection: vec3<f32>,
|
|
1721
4020
|
};
|
|
1722
4021
|
|
|
@@ -1741,12 +4040,12 @@ fn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {
|
|
|
1741
4040
|
let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));
|
|
1742
4041
|
return vec4<f32>(color.rgb * d, color.a);
|
|
1743
4042
|
}
|
|
1744
|
-
`,
|
|
4043
|
+
`,wa=`out vec3 dirlight_vNormal;
|
|
1745
4044
|
|
|
1746
4045
|
void dirlight_setNormal(vec3 normal) {
|
|
1747
4046
|
dirlight_vNormal = normalize(normal);
|
|
1748
4047
|
}
|
|
1749
|
-
`,
|
|
4048
|
+
`,Ta=`layout(std140) uniform dirlightUniforms {
|
|
1750
4049
|
vec3 lightDirection;
|
|
1751
4050
|
} dirlight;
|
|
1752
4051
|
|
|
@@ -1757,7 +4056,7 @@ vec4 dirlight_filterColor(vec4 color) {
|
|
|
1757
4056
|
float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
|
|
1758
4057
|
return vec4(color.rgb * d, color.a);
|
|
1759
4058
|
}
|
|
1760
|
-
`,
|
|
4059
|
+
`,wt={props:{},uniforms:{},name:"dirlight",bindingLayout:[{name:"dirlight",group:2}],firstBindingSlot:16,dependencies:[],source:ya,vs:wa,fs:Ta,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:[1,1,2]},getUniforms:Na};function Na(e=wt.defaultUniforms){let t={};return e.lightDirection&&(t.lightDirection=e.lightDirection),t}var Pi=`struct lambertMaterialUniforms {
|
|
1761
4060
|
unlit: u32,
|
|
1762
4061
|
ambient: f32,
|
|
1763
4062
|
diffuse: f32,
|
|
@@ -1824,12 +4123,12 @@ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, p
|
|
|
1824
4123
|
|
|
1825
4124
|
return lightColor;
|
|
1826
4125
|
}
|
|
1827
|
-
`;var
|
|
4126
|
+
`;var Oi=`layout(std140) uniform lambertMaterialUniforms {
|
|
1828
4127
|
uniform bool unlit;
|
|
1829
4128
|
uniform float ambient;
|
|
1830
4129
|
uniform float diffuse;
|
|
1831
4130
|
} material;
|
|
1832
|
-
`,
|
|
4131
|
+
`,Ui=`layout(std140) uniform lambertMaterialUniforms {
|
|
1833
4132
|
uniform bool unlit;
|
|
1834
4133
|
uniform float ambient;
|
|
1835
4134
|
uniform float diffuse;
|
|
@@ -1876,14 +4175,14 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
|
|
|
1876
4175
|
|
|
1877
4176
|
return lightColor;
|
|
1878
4177
|
}
|
|
1879
|
-
`;var
|
|
4178
|
+
`;var Tt={name:"lambertMaterial",firstBindingSlot:0,bindingLayout:[{name:"lambertMaterial",group:3}],dependencies:[U],source:Pi,vs:Oi,fs:Ui,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{unlit:"i32",ambient:"f32",diffuse:"f32"},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6},getUniforms(e){return{...Tt.defaultUniforms,...e}}};var Je=`layout(std140) uniform phongMaterialUniforms {
|
|
1880
4179
|
uniform bool unlit;
|
|
1881
4180
|
uniform float ambient;
|
|
1882
4181
|
uniform float diffuse;
|
|
1883
4182
|
uniform float shininess;
|
|
1884
4183
|
uniform vec3 specularColor;
|
|
1885
4184
|
} material;
|
|
1886
|
-
`,
|
|
4185
|
+
`,Qe=`layout(std140) uniform phongMaterialUniforms {
|
|
1887
4186
|
uniform bool unlit;
|
|
1888
4187
|
uniform float ambient;
|
|
1889
4188
|
uniform float diffuse;
|
|
@@ -1940,7 +4239,7 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
|
|
|
1940
4239
|
|
|
1941
4240
|
return lightColor;
|
|
1942
4241
|
}
|
|
1943
|
-
`;var
|
|
4242
|
+
`;var et=`struct phongMaterialUniforms {
|
|
1944
4243
|
unlit: u32,
|
|
1945
4244
|
ambient: f32,
|
|
1946
4245
|
diffuse: f32,
|
|
@@ -2063,7 +4362,455 @@ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace
|
|
|
2063
4362
|
}
|
|
2064
4363
|
return lightColor;
|
|
2065
4364
|
}
|
|
2066
|
-
`;var
|
|
4365
|
+
`;var Pa=[38.25,38.25,38.25],Nt={props:{},name:"gouraudMaterial",bindingLayout:[{name:"gouraudMaterial",group:3}],vs:Qe.replace("phongMaterial","gouraudMaterial"),fs:Je.replace("phongMaterial","gouraudMaterial"),source:et.replaceAll("phongMaterial","gouraudMaterial"),defines:{LIGHTING_VERTEX:!0},dependencies:[U,oe],uniformTypes:{unlit:"i32",ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6,shininess:32,specularColor:Pa},getUniforms(e){return{...Nt.defaultUniforms,...e}}};var Oa=[38.25,38.25,38.25],Pt={name:"phongMaterial",firstBindingSlot:0,bindingLayout:[{name:"phongMaterial",group:3}],dependencies:[U,oe],source:et,vs:Je,fs:Qe,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{unlit:"i32",ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6,shininess:32,specularColor:Oa},getUniforms(e){return{...Pt.defaultUniforms,...e}}};var Bi=`layout(std140) uniform waterMaterialUniforms {
|
|
4366
|
+
uniform float time;
|
|
4367
|
+
uniform vec3 baseColor;
|
|
4368
|
+
uniform float opacity;
|
|
4369
|
+
uniform vec3 fresnelColor;
|
|
4370
|
+
uniform float fresnelPower;
|
|
4371
|
+
uniform float specularIntensity;
|
|
4372
|
+
uniform float normalStrength;
|
|
4373
|
+
uniform int mappingMode;
|
|
4374
|
+
uniform vec2 coordinateScale;
|
|
4375
|
+
uniform vec2 coordinateOffset;
|
|
4376
|
+
uniform vec2 waveADirection;
|
|
4377
|
+
uniform float waveASpeed;
|
|
4378
|
+
uniform float waveAFrequency;
|
|
4379
|
+
uniform float waveAAmplitude;
|
|
4380
|
+
uniform vec2 waveBDirection;
|
|
4381
|
+
uniform float waveBSpeed;
|
|
4382
|
+
uniform float waveBFrequency;
|
|
4383
|
+
uniform float waveBAmplitude;
|
|
4384
|
+
} waterMaterial;
|
|
4385
|
+
`,Di=`layout(std140) uniform waterMaterialUniforms {
|
|
4386
|
+
uniform float time;
|
|
4387
|
+
uniform vec3 baseColor;
|
|
4388
|
+
uniform float opacity;
|
|
4389
|
+
uniform vec3 fresnelColor;
|
|
4390
|
+
uniform float fresnelPower;
|
|
4391
|
+
uniform float specularIntensity;
|
|
4392
|
+
uniform float normalStrength;
|
|
4393
|
+
uniform int mappingMode;
|
|
4394
|
+
uniform vec2 coordinateScale;
|
|
4395
|
+
uniform vec2 coordinateOffset;
|
|
4396
|
+
uniform vec2 waveADirection;
|
|
4397
|
+
uniform float waveASpeed;
|
|
4398
|
+
uniform float waveAFrequency;
|
|
4399
|
+
uniform float waveAAmplitude;
|
|
4400
|
+
uniform vec2 waveBDirection;
|
|
4401
|
+
uniform float waveBSpeed;
|
|
4402
|
+
uniform float waveBFrequency;
|
|
4403
|
+
uniform float waveBAmplitude;
|
|
4404
|
+
} waterMaterial;
|
|
4405
|
+
|
|
4406
|
+
vec2 water_getDirection(vec2 direction) {
|
|
4407
|
+
float directionLength = length(direction);
|
|
4408
|
+
return directionLength > 0.0 ? direction / directionLength : vec2(1.0, 0.0);
|
|
4409
|
+
}
|
|
4410
|
+
|
|
4411
|
+
vec2 water_getCoordinates(vec3 position_worldspace, vec3 position_objectspace, vec2 uv) {
|
|
4412
|
+
vec2 baseCoordinates = uv;
|
|
4413
|
+
if (waterMaterial.mappingMode == 1) {
|
|
4414
|
+
baseCoordinates = position_worldspace.xz;
|
|
4415
|
+
} else if (waterMaterial.mappingMode == 2) {
|
|
4416
|
+
vec3 globeDirection = normalize(position_objectspace);
|
|
4417
|
+
float longitude = atan(globeDirection.x, globeDirection.z);
|
|
4418
|
+
float latitude = asin(clamp(globeDirection.y, -1.0, 1.0));
|
|
4419
|
+
baseCoordinates = vec2(longitude, latitude);
|
|
4420
|
+
}
|
|
4421
|
+
return baseCoordinates * waterMaterial.coordinateScale + waterMaterial.coordinateOffset;
|
|
4422
|
+
}
|
|
4423
|
+
|
|
4424
|
+
vec2 water_getWaveGradient(
|
|
4425
|
+
vec2 coordinates,
|
|
4426
|
+
vec2 direction,
|
|
4427
|
+
float speed,
|
|
4428
|
+
float frequency,
|
|
4429
|
+
float amplitude
|
|
4430
|
+
) {
|
|
4431
|
+
vec2 normalizedDirection = water_getDirection(direction);
|
|
4432
|
+
float phase = dot(coordinates * frequency, normalizedDirection) + waterMaterial.time * speed;
|
|
4433
|
+
return cos(phase) * normalizedDirection * frequency * amplitude;
|
|
4434
|
+
}
|
|
4435
|
+
|
|
4436
|
+
vec3 water_getTangent(vec3 normal_worldspace) {
|
|
4437
|
+
vec3 referenceAxis = abs(normal_worldspace.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 1.0, 0.0);
|
|
4438
|
+
return normalize(cross(referenceAxis, normal_worldspace));
|
|
4439
|
+
}
|
|
4440
|
+
|
|
4441
|
+
vec3 water_getNormal(
|
|
4442
|
+
vec3 position_worldspace,
|
|
4443
|
+
vec3 position_objectspace,
|
|
4444
|
+
vec3 normal_worldspace,
|
|
4445
|
+
vec2 uv
|
|
4446
|
+
) {
|
|
4447
|
+
vec2 coordinates = water_getCoordinates(position_worldspace, position_objectspace, uv);
|
|
4448
|
+
vec2 gradient =
|
|
4449
|
+
water_getWaveGradient(
|
|
4450
|
+
coordinates,
|
|
4451
|
+
waterMaterial.waveADirection,
|
|
4452
|
+
waterMaterial.waveASpeed,
|
|
4453
|
+
waterMaterial.waveAFrequency,
|
|
4454
|
+
waterMaterial.waveAAmplitude
|
|
4455
|
+
) +
|
|
4456
|
+
water_getWaveGradient(
|
|
4457
|
+
coordinates,
|
|
4458
|
+
waterMaterial.waveBDirection,
|
|
4459
|
+
waterMaterial.waveBSpeed,
|
|
4460
|
+
waterMaterial.waveBFrequency,
|
|
4461
|
+
waterMaterial.waveBAmplitude
|
|
4462
|
+
);
|
|
4463
|
+
|
|
4464
|
+
vec3 tangent = water_getTangent(normal_worldspace);
|
|
4465
|
+
vec3 bitangent = normalize(cross(normal_worldspace, tangent));
|
|
4466
|
+
vec3 perturbation =
|
|
4467
|
+
waterMaterial.normalStrength * (gradient.x * tangent + gradient.y * bitangent);
|
|
4468
|
+
|
|
4469
|
+
return normalize(normal_worldspace + perturbation);
|
|
4470
|
+
}
|
|
4471
|
+
|
|
4472
|
+
vec3 water_getSpecularContribution(
|
|
4473
|
+
vec3 light_direction,
|
|
4474
|
+
vec3 view_direction,
|
|
4475
|
+
vec3 normal_worldspace,
|
|
4476
|
+
vec3 light_color,
|
|
4477
|
+
float fresnel
|
|
4478
|
+
) {
|
|
4479
|
+
vec3 halfway_direction = normalize(light_direction + view_direction);
|
|
4480
|
+
float specular =
|
|
4481
|
+
pow(max(dot(normal_worldspace, halfway_direction), 0.0), 72.0) *
|
|
4482
|
+
waterMaterial.specularIntensity *
|
|
4483
|
+
(0.25 + 0.75 * fresnel);
|
|
4484
|
+
|
|
4485
|
+
return waterMaterial.fresnelColor * light_color * specular;
|
|
4486
|
+
}
|
|
4487
|
+
|
|
4488
|
+
vec4 water_getColorMapped(
|
|
4489
|
+
vec3 cameraPosition,
|
|
4490
|
+
vec3 position_worldspace,
|
|
4491
|
+
vec3 position_objectspace,
|
|
4492
|
+
vec3 normal_worldspace,
|
|
4493
|
+
vec2 uv
|
|
4494
|
+
) {
|
|
4495
|
+
vec3 waterNormal = water_getNormal(
|
|
4496
|
+
position_worldspace,
|
|
4497
|
+
position_objectspace,
|
|
4498
|
+
normalize(normal_worldspace),
|
|
4499
|
+
uv
|
|
4500
|
+
);
|
|
4501
|
+
vec3 viewDirection = normalize(cameraPosition - position_worldspace);
|
|
4502
|
+
float fresnel =
|
|
4503
|
+
pow(
|
|
4504
|
+
1.0 - max(dot(viewDirection, waterNormal), 0.0),
|
|
4505
|
+
max(waterMaterial.fresnelPower, 0.0001)
|
|
4506
|
+
);
|
|
4507
|
+
vec3 surfaceColor = mix(
|
|
4508
|
+
waterMaterial.baseColor,
|
|
4509
|
+
waterMaterial.fresnelColor,
|
|
4510
|
+
clamp(fresnel * 0.6, 0.0, 1.0)
|
|
4511
|
+
);
|
|
4512
|
+
|
|
4513
|
+
if (lighting.enabled == 0) {
|
|
4514
|
+
return vec4(surfaceColor, waterMaterial.opacity);
|
|
4515
|
+
}
|
|
4516
|
+
|
|
4517
|
+
vec3 lightColor = surfaceColor * (0.15 + 0.85 * lighting.ambientColor);
|
|
4518
|
+
|
|
4519
|
+
for (int i = 0; i < lighting.pointLightCount; i++) {
|
|
4520
|
+
PointLight pointLight = lighting_getPointLight(i);
|
|
4521
|
+
vec3 lightPosition = pointLight.position;
|
|
4522
|
+
vec3 lightDirection = normalize(lightPosition - position_worldspace);
|
|
4523
|
+
float attenuation =
|
|
4524
|
+
getPointLightAttenuation(pointLight, distance(lightPosition, position_worldspace));
|
|
4525
|
+
vec3 incidentLight = pointLight.color / attenuation;
|
|
4526
|
+
float diffuse = max(dot(waterNormal, lightDirection), 0.0);
|
|
4527
|
+
|
|
4528
|
+
lightColor += surfaceColor * incidentLight * diffuse;
|
|
4529
|
+
lightColor += water_getSpecularContribution(
|
|
4530
|
+
lightDirection,
|
|
4531
|
+
viewDirection,
|
|
4532
|
+
waterNormal,
|
|
4533
|
+
incidentLight,
|
|
4534
|
+
fresnel
|
|
4535
|
+
);
|
|
4536
|
+
}
|
|
4537
|
+
|
|
4538
|
+
for (int i = 0; i < lighting.spotLightCount; i++) {
|
|
4539
|
+
SpotLight spotLight = lighting_getSpotLight(i);
|
|
4540
|
+
vec3 lightPosition = spotLight.position;
|
|
4541
|
+
vec3 lightDirection = normalize(lightPosition - position_worldspace);
|
|
4542
|
+
float attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
|
|
4543
|
+
vec3 incidentLight = spotLight.color / attenuation;
|
|
4544
|
+
float diffuse = max(dot(waterNormal, lightDirection), 0.0);
|
|
4545
|
+
|
|
4546
|
+
lightColor += surfaceColor * incidentLight * diffuse;
|
|
4547
|
+
lightColor += water_getSpecularContribution(
|
|
4548
|
+
lightDirection,
|
|
4549
|
+
viewDirection,
|
|
4550
|
+
waterNormal,
|
|
4551
|
+
incidentLight,
|
|
4552
|
+
fresnel
|
|
4553
|
+
);
|
|
4554
|
+
}
|
|
4555
|
+
|
|
4556
|
+
for (int i = 0; i < lighting.directionalLightCount; i++) {
|
|
4557
|
+
DirectionalLight directionalLight = lighting_getDirectionalLight(i);
|
|
4558
|
+
vec3 lightDirection = normalize(-directionalLight.direction);
|
|
4559
|
+
float diffuse = max(dot(waterNormal, lightDirection), 0.0);
|
|
4560
|
+
|
|
4561
|
+
lightColor += surfaceColor * directionalLight.color * diffuse;
|
|
4562
|
+
lightColor += water_getSpecularContribution(
|
|
4563
|
+
lightDirection,
|
|
4564
|
+
viewDirection,
|
|
4565
|
+
waterNormal,
|
|
4566
|
+
directionalLight.color,
|
|
4567
|
+
fresnel
|
|
4568
|
+
);
|
|
4569
|
+
}
|
|
4570
|
+
|
|
4571
|
+
lightColor = mix(lightColor, waterMaterial.fresnelColor, clamp(fresnel, 0.0, 1.0) * 0.35);
|
|
4572
|
+
return vec4(lightColor, waterMaterial.opacity);
|
|
4573
|
+
}
|
|
4574
|
+
|
|
4575
|
+
vec4 water_getColor(
|
|
4576
|
+
vec3 cameraPosition,
|
|
4577
|
+
vec3 position_worldspace,
|
|
4578
|
+
vec3 normal_worldspace,
|
|
4579
|
+
vec2 uv
|
|
4580
|
+
) {
|
|
4581
|
+
return water_getColorMapped(
|
|
4582
|
+
cameraPosition,
|
|
4583
|
+
position_worldspace,
|
|
4584
|
+
position_worldspace,
|
|
4585
|
+
normal_worldspace,
|
|
4586
|
+
uv
|
|
4587
|
+
);
|
|
4588
|
+
}
|
|
4589
|
+
`;var Fi=`struct waterMaterialUniforms {
|
|
4590
|
+
time: f32,
|
|
4591
|
+
baseColor: vec3<f32>,
|
|
4592
|
+
opacity: f32,
|
|
4593
|
+
fresnelColor: vec3<f32>,
|
|
4594
|
+
fresnelPower: f32,
|
|
4595
|
+
specularIntensity: f32,
|
|
4596
|
+
normalStrength: f32,
|
|
4597
|
+
mappingMode: i32,
|
|
4598
|
+
coordinateScale: vec2<f32>,
|
|
4599
|
+
coordinateOffset: vec2<f32>,
|
|
4600
|
+
waveADirection: vec2<f32>,
|
|
4601
|
+
waveASpeed: f32,
|
|
4602
|
+
waveAFrequency: f32,
|
|
4603
|
+
waveAAmplitude: f32,
|
|
4604
|
+
waveBDirection: vec2<f32>,
|
|
4605
|
+
waveBSpeed: f32,
|
|
4606
|
+
waveBFrequency: f32,
|
|
4607
|
+
waveBAmplitude: f32,
|
|
4608
|
+
};
|
|
4609
|
+
|
|
4610
|
+
@group(3) @binding(auto) var<uniform> waterMaterial : waterMaterialUniforms;
|
|
4611
|
+
|
|
4612
|
+
fn water_getDirection(direction: vec2<f32>) -> vec2<f32> {
|
|
4613
|
+
let directionLength = length(direction);
|
|
4614
|
+
if (directionLength > 0.0) {
|
|
4615
|
+
return direction / directionLength;
|
|
4616
|
+
}
|
|
4617
|
+
|
|
4618
|
+
return vec2<f32>(1.0, 0.0);
|
|
4619
|
+
}
|
|
4620
|
+
|
|
4621
|
+
fn water_getCoordinates(
|
|
4622
|
+
position_worldspace: vec3<f32>,
|
|
4623
|
+
position_objectspace: vec3<f32>,
|
|
4624
|
+
uv: vec2<f32>
|
|
4625
|
+
) -> vec2<f32> {
|
|
4626
|
+
var baseCoordinates = uv;
|
|
4627
|
+
if (waterMaterial.mappingMode == 1) {
|
|
4628
|
+
baseCoordinates = position_worldspace.xz;
|
|
4629
|
+
} else if (waterMaterial.mappingMode == 2) {
|
|
4630
|
+
let globeDirection = normalize(position_objectspace);
|
|
4631
|
+
let longitude = atan2(globeDirection.x, globeDirection.z);
|
|
4632
|
+
let latitude = asin(clamp(globeDirection.y, -1.0, 1.0));
|
|
4633
|
+
baseCoordinates = vec2<f32>(longitude, latitude);
|
|
4634
|
+
}
|
|
4635
|
+
|
|
4636
|
+
return baseCoordinates * waterMaterial.coordinateScale + waterMaterial.coordinateOffset;
|
|
4637
|
+
}
|
|
4638
|
+
|
|
4639
|
+
fn water_getWaveGradient(
|
|
4640
|
+
coordinates: vec2<f32>,
|
|
4641
|
+
direction: vec2<f32>,
|
|
4642
|
+
speed: f32,
|
|
4643
|
+
frequency: f32,
|
|
4644
|
+
amplitude: f32
|
|
4645
|
+
) -> vec2<f32> {
|
|
4646
|
+
let normalizedDirection = water_getDirection(direction);
|
|
4647
|
+
let phase = dot(coordinates * frequency, normalizedDirection) + waterMaterial.time * speed;
|
|
4648
|
+
return cos(phase) * normalizedDirection * frequency * amplitude;
|
|
4649
|
+
}
|
|
4650
|
+
|
|
4651
|
+
fn water_getTangent(normal_worldspace: vec3<f32>) -> vec3<f32> {
|
|
4652
|
+
var referenceAxis = vec3<f32>(0.0, 0.0, 1.0);
|
|
4653
|
+
if (abs(normal_worldspace.z) >= 0.999) {
|
|
4654
|
+
referenceAxis = vec3<f32>(0.0, 1.0, 0.0);
|
|
4655
|
+
}
|
|
4656
|
+
|
|
4657
|
+
return normalize(cross(referenceAxis, normal_worldspace));
|
|
4658
|
+
}
|
|
4659
|
+
|
|
4660
|
+
fn water_getNormal(
|
|
4661
|
+
position_worldspace: vec3<f32>,
|
|
4662
|
+
position_objectspace: vec3<f32>,
|
|
4663
|
+
normal_worldspace: vec3<f32>,
|
|
4664
|
+
uv: vec2<f32>
|
|
4665
|
+
) -> vec3<f32> {
|
|
4666
|
+
let coordinates = water_getCoordinates(position_worldspace, position_objectspace, uv);
|
|
4667
|
+
let gradient =
|
|
4668
|
+
water_getWaveGradient(
|
|
4669
|
+
coordinates,
|
|
4670
|
+
waterMaterial.waveADirection,
|
|
4671
|
+
waterMaterial.waveASpeed,
|
|
4672
|
+
waterMaterial.waveAFrequency,
|
|
4673
|
+
waterMaterial.waveAAmplitude
|
|
4674
|
+
) +
|
|
4675
|
+
water_getWaveGradient(
|
|
4676
|
+
coordinates,
|
|
4677
|
+
waterMaterial.waveBDirection,
|
|
4678
|
+
waterMaterial.waveBSpeed,
|
|
4679
|
+
waterMaterial.waveBFrequency,
|
|
4680
|
+
waterMaterial.waveBAmplitude
|
|
4681
|
+
);
|
|
4682
|
+
let tangent = water_getTangent(normal_worldspace);
|
|
4683
|
+
let bitangent = normalize(cross(normal_worldspace, tangent));
|
|
4684
|
+
let perturbation =
|
|
4685
|
+
waterMaterial.normalStrength * (gradient.x * tangent + gradient.y * bitangent);
|
|
4686
|
+
|
|
4687
|
+
return normalize(normal_worldspace + perturbation);
|
|
4688
|
+
}
|
|
4689
|
+
|
|
4690
|
+
fn water_getSpecularContribution(
|
|
4691
|
+
light_direction: vec3<f32>,
|
|
4692
|
+
view_direction: vec3<f32>,
|
|
4693
|
+
normal_worldspace: vec3<f32>,
|
|
4694
|
+
light_color: vec3<f32>,
|
|
4695
|
+
fresnel: f32
|
|
4696
|
+
) -> vec3<f32> {
|
|
4697
|
+
let halfwayDirection = normalize(light_direction + view_direction);
|
|
4698
|
+
let specular =
|
|
4699
|
+
pow(max(dot(normal_worldspace, halfwayDirection), 0.0), 72.0) *
|
|
4700
|
+
waterMaterial.specularIntensity *
|
|
4701
|
+
(0.25 + 0.75 * fresnel);
|
|
4702
|
+
|
|
4703
|
+
return waterMaterial.fresnelColor * light_color * specular;
|
|
4704
|
+
}
|
|
4705
|
+
|
|
4706
|
+
fn water_getColorMapped(
|
|
4707
|
+
cameraPosition: vec3<f32>,
|
|
4708
|
+
position_worldspace: vec3<f32>,
|
|
4709
|
+
position_objectspace: vec3<f32>,
|
|
4710
|
+
normal_worldspace: vec3<f32>,
|
|
4711
|
+
uv: vec2<f32>
|
|
4712
|
+
) -> vec4<f32> {
|
|
4713
|
+
let waterNormal = water_getNormal(
|
|
4714
|
+
position_worldspace,
|
|
4715
|
+
position_objectspace,
|
|
4716
|
+
normalize(normal_worldspace),
|
|
4717
|
+
uv
|
|
4718
|
+
);
|
|
4719
|
+
let viewDirection = normalize(cameraPosition - position_worldspace);
|
|
4720
|
+
let fresnel =
|
|
4721
|
+
pow(
|
|
4722
|
+
1.0 - max(dot(viewDirection, waterNormal), 0.0),
|
|
4723
|
+
max(waterMaterial.fresnelPower, 0.0001)
|
|
4724
|
+
);
|
|
4725
|
+
let surfaceColor = mix(
|
|
4726
|
+
waterMaterial.baseColor,
|
|
4727
|
+
waterMaterial.fresnelColor,
|
|
4728
|
+
clamp(fresnel * 0.6, 0.0, 1.0)
|
|
4729
|
+
);
|
|
4730
|
+
|
|
4731
|
+
if (lighting.enabled == 0) {
|
|
4732
|
+
return vec4<f32>(surfaceColor, waterMaterial.opacity);
|
|
4733
|
+
}
|
|
4734
|
+
|
|
4735
|
+
var lightColor = surfaceColor * (0.15 + 0.85 * lighting.ambientColor);
|
|
4736
|
+
|
|
4737
|
+
for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
|
|
4738
|
+
let pointLight = lighting_getPointLight(i);
|
|
4739
|
+
let lightPosition = pointLight.position;
|
|
4740
|
+
let lightDirection = normalize(lightPosition - position_worldspace);
|
|
4741
|
+
let attenuation = getPointLightAttenuation(
|
|
4742
|
+
pointLight,
|
|
4743
|
+
distance(lightPosition, position_worldspace)
|
|
4744
|
+
);
|
|
4745
|
+
let incidentLight = pointLight.color / attenuation;
|
|
4746
|
+
let diffuse = max(dot(waterNormal, lightDirection), 0.0);
|
|
4747
|
+
|
|
4748
|
+
lightColor += surfaceColor * incidentLight * diffuse;
|
|
4749
|
+
lightColor += water_getSpecularContribution(
|
|
4750
|
+
lightDirection,
|
|
4751
|
+
viewDirection,
|
|
4752
|
+
waterNormal,
|
|
4753
|
+
incidentLight,
|
|
4754
|
+
fresnel
|
|
4755
|
+
);
|
|
4756
|
+
}
|
|
4757
|
+
|
|
4758
|
+
for (var i: i32 = 0; i < lighting.spotLightCount; i++) {
|
|
4759
|
+
let spotLight = lighting_getSpotLight(i);
|
|
4760
|
+
let lightPosition = spotLight.position;
|
|
4761
|
+
let lightDirection = normalize(lightPosition - position_worldspace);
|
|
4762
|
+
let attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
|
|
4763
|
+
let incidentLight = spotLight.color / attenuation;
|
|
4764
|
+
let diffuse = max(dot(waterNormal, lightDirection), 0.0);
|
|
4765
|
+
|
|
4766
|
+
lightColor += surfaceColor * incidentLight * diffuse;
|
|
4767
|
+
lightColor += water_getSpecularContribution(
|
|
4768
|
+
lightDirection,
|
|
4769
|
+
viewDirection,
|
|
4770
|
+
waterNormal,
|
|
4771
|
+
incidentLight,
|
|
4772
|
+
fresnel
|
|
4773
|
+
);
|
|
4774
|
+
}
|
|
4775
|
+
|
|
4776
|
+
for (var i: i32 = 0; i < lighting.directionalLightCount; i++) {
|
|
4777
|
+
let directionalLight = lighting_getDirectionalLight(i);
|
|
4778
|
+
let lightDirection = normalize(-directionalLight.direction);
|
|
4779
|
+
let diffuse = max(dot(waterNormal, lightDirection), 0.0);
|
|
4780
|
+
|
|
4781
|
+
lightColor += surfaceColor * directionalLight.color * diffuse;
|
|
4782
|
+
lightColor += water_getSpecularContribution(
|
|
4783
|
+
lightDirection,
|
|
4784
|
+
viewDirection,
|
|
4785
|
+
waterNormal,
|
|
4786
|
+
directionalLight.color,
|
|
4787
|
+
fresnel
|
|
4788
|
+
);
|
|
4789
|
+
}
|
|
4790
|
+
|
|
4791
|
+
lightColor = mix(
|
|
4792
|
+
lightColor,
|
|
4793
|
+
waterMaterial.fresnelColor,
|
|
4794
|
+
clamp(fresnel, 0.0, 1.0) * 0.35
|
|
4795
|
+
);
|
|
4796
|
+
return vec4<f32>(lightColor, waterMaterial.opacity);
|
|
4797
|
+
}
|
|
4798
|
+
|
|
4799
|
+
fn water_getColor(
|
|
4800
|
+
cameraPosition: vec3<f32>,
|
|
4801
|
+
position_worldspace: vec3<f32>,
|
|
4802
|
+
normal_worldspace: vec3<f32>,
|
|
4803
|
+
uv: vec2<f32>
|
|
4804
|
+
) -> vec4<f32> {
|
|
4805
|
+
return water_getColorMapped(
|
|
4806
|
+
cameraPosition,
|
|
4807
|
+
position_worldspace,
|
|
4808
|
+
position_worldspace,
|
|
4809
|
+
normal_worldspace,
|
|
4810
|
+
uv
|
|
4811
|
+
);
|
|
4812
|
+
}
|
|
4813
|
+
`;var T={time:0,baseColor:[.04,.18,.31],opacity:.82,fresnelColor:[.86,.95,1],fresnelPower:5,specularIntensity:1.4,normalStrength:.35,mappingMode:0,coordinateScale:[1,1],coordinateOffset:[0,0],waveADirection:[.9805806756909201,.19611613513818402],waveASpeed:.6,waveAFrequency:4,waveAAmplitude:.08,waveBDirection:[.09950371902099893,.9950371902099893],waveBSpeed:-.45,waveBFrequency:7,waveBAmplitude:.04},Gi={name:"waterMaterial",firstBindingSlot:0,bindingLayout:[{name:"waterMaterial",group:3}],dependencies:[U],source:Fi,vs:Bi,fs:Di,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{time:"f32",baseColor:"vec3<f32>",opacity:"f32",fresnelColor:"vec3<f32>",fresnelPower:"f32",specularIntensity:"f32",normalStrength:"f32",mappingMode:"i32",coordinateScale:"vec2<f32>",coordinateOffset:"vec2<f32>",waveADirection:"vec2<f32>",waveASpeed:"f32",waveAFrequency:"f32",waveAAmplitude:"f32",waveBDirection:"vec2<f32>",waveBSpeed:"f32",waveBFrequency:"f32",waveBAmplitude:"f32"},defaultUniforms:T,getUniforms(e,t=T){let{mapping:n,...i}=e||{},r=Ua(t);return i.time!==void 0&&(r.time=i.time),i.opacity!==void 0&&(r.opacity=i.opacity),i.fresnelPower!==void 0&&(r.fresnelPower=i.fresnelPower),i.specularIntensity!==void 0&&(r.specularIntensity=i.specularIntensity),i.normalStrength!==void 0&&(r.normalStrength=i.normalStrength),i.coordinateScale!==void 0&&(r.coordinateScale=[Number(i.coordinateScale[0]),Number(i.coordinateScale[1])]),i.coordinateOffset!==void 0&&(r.coordinateOffset=[Number(i.coordinateOffset[0]),Number(i.coordinateOffset[1])]),i.waveASpeed!==void 0&&(r.waveASpeed=i.waveASpeed),i.waveAFrequency!==void 0&&(r.waveAFrequency=i.waveAFrequency),i.waveAAmplitude!==void 0&&(r.waveAAmplitude=i.waveAAmplitude),i.waveBSpeed!==void 0&&(r.waveBSpeed=i.waveBSpeed),i.waveBFrequency!==void 0&&(r.waveBFrequency=i.waveBFrequency),i.waveBAmplitude!==void 0&&(r.waveBAmplitude=i.waveBAmplitude),i.baseColor&&(r.baseColor=tt(i.baseColor)),i.fresnelColor&&(r.fresnelColor=tt(i.fresnelColor)),i.waveADirection&&(r.waveADirection=nt(i.waveADirection)),i.waveBDirection&&(r.waveBDirection=nt(i.waveBDirection)),n!==void 0&&(r.mappingMode=n==="world"?1:n==="object"?2:0),r}};function Ua(e){return{time:e.time??T.time,baseColor:e.baseColor?tt(e.baseColor):T.baseColor,opacity:e.opacity??T.opacity,fresnelColor:e.fresnelColor?tt(e.fresnelColor):T.fresnelColor,fresnelPower:e.fresnelPower??T.fresnelPower,specularIntensity:e.specularIntensity??T.specularIntensity,normalStrength:e.normalStrength??T.normalStrength,mappingMode:e.mappingMode??T.mappingMode,coordinateScale:e.coordinateScale?[Number(e.coordinateScale[0]),Number(e.coordinateScale[1])]:T.coordinateScale,coordinateOffset:e.coordinateOffset?[Number(e.coordinateOffset[0]),Number(e.coordinateOffset[1])]:T.coordinateOffset,waveADirection:e.waveADirection?nt(e.waveADirection):T.waveADirection,waveASpeed:e.waveASpeed??T.waveASpeed,waveAFrequency:e.waveAFrequency??T.waveAFrequency,waveAAmplitude:e.waveAAmplitude??T.waveAAmplitude,waveBDirection:e.waveBDirection?nt(e.waveBDirection):T.waveBDirection,waveBSpeed:e.waveBSpeed??T.waveBSpeed,waveBFrequency:e.waveBFrequency??T.waveBFrequency,waveBAmplitude:e.waveBAmplitude??T.waveBAmplitude}}function tt(e){let t=[Number(e[0]),Number(e[1]),Number(e[2])];return Math.max(...t.map(i=>Math.abs(i)))>1&&(t[0]/=255,t[1]/=255,t[2]/=255),t}function nt(e){let t=Number(e[0]),n=Number(e[1]),i=Math.hypot(t,n);return i===0?[1,0]:[t/i,n/i]}var Vi=`out vec3 pbr_vPosition;
|
|
2067
4814
|
out vec2 pbr_vUV0;
|
|
2068
4815
|
out vec2 pbr_vUV1;
|
|
2069
4816
|
|
|
@@ -2105,7 +4852,7 @@ void pbr_setPositionNormalTangentUV(
|
|
|
2105
4852
|
|
|
2106
4853
|
pbr_vUV1 = uv1;
|
|
2107
4854
|
}
|
|
2108
|
-
`,
|
|
4855
|
+
`,ki=`precision highp float;
|
|
2109
4856
|
|
|
2110
4857
|
layout(std140) uniform pbrMaterialUniforms {
|
|
2111
4858
|
// Material is unlit
|
|
@@ -3153,7 +5900,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
3153
5900
|
float alpha = clamp(baseColor.a * (1.0 - transmission), 0.0, 1.0);
|
|
3154
5901
|
return vec4(pow(color,vec3(1.0/2.2)), alpha);
|
|
3155
5902
|
}
|
|
3156
|
-
`;var
|
|
5903
|
+
`;var zi=`struct PBRFragmentInputs {
|
|
3157
5904
|
pbr_vPosition: vec3f,
|
|
3158
5905
|
pbr_vUV0: vec2f,
|
|
3159
5906
|
pbr_vUV1: vec2f,
|
|
@@ -4341,13 +7088,13 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
4341
7088
|
let alpha = clamp(baseColor.a * (1.0 - transmission), 0.0, 1.0);
|
|
4342
7089
|
return vec4<f32>(pow(color, vec3<f32>(1.0 / 2.2)), alpha);
|
|
4343
7090
|
}
|
|
4344
|
-
`;var
|
|
7091
|
+
`;var Hi=`layout(std140) uniform pbrProjectionUniforms {
|
|
4345
7092
|
mat4 modelViewProjectionMatrix;
|
|
4346
7093
|
mat4 modelMatrix;
|
|
4347
7094
|
mat4 normalMatrix;
|
|
4348
7095
|
vec3 camera;
|
|
4349
7096
|
} pbrProjection;
|
|
4350
|
-
`,
|
|
7097
|
+
`,Ba=`struct pbrProjectionUniforms {
|
|
4351
7098
|
modelViewProjectionMatrix: mat4x4<f32>,
|
|
4352
7099
|
modelMatrix: mat4x4<f32>,
|
|
4353
7100
|
normalMatrix: mat4x4<f32>,
|
|
@@ -4355,7 +7102,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
4355
7102
|
};
|
|
4356
7103
|
|
|
4357
7104
|
@group(0) @binding(auto) var<uniform> pbrProjection: pbrProjectionUniforms;
|
|
4358
|
-
|
|
7105
|
+
`,$i={name:"pbrProjection",bindingLayout:[{name:"pbrProjection",group:0}],source:Ba,vs:Hi,fs:Hi,getUniforms:e=>e,uniformTypes:{modelViewProjectionMatrix:"mat4x4<f32>",modelMatrix:"mat4x4<f32>",normalMatrix:"mat4x4<f32>",camera:"vec3<f32>"}};var ji={props:{},uniforms:{},defaultUniforms:{unlit:!1,baseColorMapEnabled:!1,baseColorFactor:[1,1,1,1],normalMapEnabled:!1,normalScale:1,emissiveMapEnabled:!1,emissiveFactor:[0,0,0],metallicRoughnessValues:[1,1],metallicRoughnessMapEnabled:!1,occlusionMapEnabled:!1,occlusionStrength:1,alphaCutoffEnabled:!1,alphaCutoff:.5,IBLenabled:!1,scaleIBLAmbient:[1,1],scaleDiffBaseMR:[0,0,0,0],scaleFGDSpec:[0,0,0,0],specularColorFactor:[1,1,1],specularIntensityFactor:1,specularColorMapEnabled:!1,specularIntensityMapEnabled:!1,ior:1.5,transmissionFactor:0,transmissionMapEnabled:!1,thicknessFactor:0,attenuationDistance:1e9,attenuationColor:[1,1,1],clearcoatFactor:0,clearcoatRoughnessFactor:0,clearcoatMapEnabled:!1,clearcoatRoughnessMapEnabled:!1,sheenColorFactor:[0,0,0],sheenRoughnessFactor:0,sheenColorMapEnabled:!1,sheenRoughnessMapEnabled:!1,iridescenceFactor:0,iridescenceIor:1.3,iridescenceThicknessRange:[100,400],iridescenceMapEnabled:!1,anisotropyStrength:0,anisotropyRotation:0,anisotropyDirection:[1,0],anisotropyMapEnabled:!1,emissiveStrength:1,baseColorUVSet:0,baseColorUVTransform:[1,0,0,0,1,0,0,0,1],metallicRoughnessUVSet:0,metallicRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],normalUVSet:0,normalUVTransform:[1,0,0,0,1,0,0,0,1],occlusionUVSet:0,occlusionUVTransform:[1,0,0,0,1,0,0,0,1],emissiveUVSet:0,emissiveUVTransform:[1,0,0,0,1,0,0,0,1],specularColorUVSet:0,specularColorUVTransform:[1,0,0,0,1,0,0,0,1],specularIntensityUVSet:0,specularIntensityUVTransform:[1,0,0,0,1,0,0,0,1],transmissionUVSet:0,transmissionUVTransform:[1,0,0,0,1,0,0,0,1],thicknessUVSet:0,thicknessUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatUVSet:0,clearcoatUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatRoughnessUVSet:0,clearcoatRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatNormalUVSet:0,clearcoatNormalUVTransform:[1,0,0,0,1,0,0,0,1],sheenColorUVSet:0,sheenColorUVTransform:[1,0,0,0,1,0,0,0,1],sheenRoughnessUVSet:0,sheenRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],iridescenceUVSet:0,iridescenceUVTransform:[1,0,0,0,1,0,0,0,1],iridescenceThicknessUVSet:0,iridescenceThicknessUVTransform:[1,0,0,0,1,0,0,0,1],anisotropyUVSet:0,anisotropyUVTransform:[1,0,0,0,1,0,0,0,1]},name:"pbrMaterial",firstBindingSlot:0,bindingLayout:[{name:"pbrMaterial",group:3},{name:"pbr_baseColorSampler",group:3},{name:"pbr_normalSampler",group:3},{name:"pbr_emissiveSampler",group:3},{name:"pbr_metallicRoughnessSampler",group:3},{name:"pbr_occlusionSampler",group:3},{name:"pbr_specularColorSampler",group:3},{name:"pbr_specularIntensitySampler",group:3},{name:"pbr_transmissionSampler",group:3},{name:"pbr_thicknessSampler",group:3},{name:"pbr_clearcoatSampler",group:3},{name:"pbr_clearcoatRoughnessSampler",group:3},{name:"pbr_clearcoatNormalSampler",group:3},{name:"pbr_sheenColorSampler",group:3},{name:"pbr_sheenRoughnessSampler",group:3},{name:"pbr_iridescenceSampler",group:3},{name:"pbr_iridescenceThicknessSampler",group:3},{name:"pbr_anisotropySampler",group:3}],dependencies:[U,Ze,$i],source:zi,vs:Vi,fs:ki,defines:{LIGHTING_FRAGMENT:!0,HAS_NORMALMAP:!1,HAS_EMISSIVEMAP:!1,HAS_OCCLUSIONMAP:!1,HAS_BASECOLORMAP:!1,HAS_METALROUGHNESSMAP:!1,HAS_SPECULARCOLORMAP:!1,HAS_SPECULARINTENSITYMAP:!1,HAS_TRANSMISSIONMAP:!1,HAS_THICKNESSMAP:!1,HAS_CLEARCOATMAP:!1,HAS_CLEARCOATROUGHNESSMAP:!1,HAS_CLEARCOATNORMALMAP:!1,HAS_SHEENCOLORMAP:!1,HAS_SHEENROUGHNESSMAP:!1,HAS_IRIDESCENCEMAP:!1,HAS_IRIDESCENCETHICKNESSMAP:!1,HAS_ANISOTROPYMAP:!1,USE_MATERIAL_EXTENSIONS:!1,ALPHA_CUTOFF:!1,USE_IBL:!1,PBR_DEBUG:!1},getUniforms:e=>e,uniformTypes:{unlit:"i32",baseColorMapEnabled:"i32",baseColorFactor:"vec4<f32>",normalMapEnabled:"i32",normalScale:"f32",emissiveMapEnabled:"i32",emissiveFactor:"vec3<f32>",metallicRoughnessValues:"vec2<f32>",metallicRoughnessMapEnabled:"i32",occlusionMapEnabled:"i32",occlusionStrength:"f32",alphaCutoffEnabled:"i32",alphaCutoff:"f32",specularColorFactor:"vec3<f32>",specularIntensityFactor:"f32",specularColorMapEnabled:"i32",specularIntensityMapEnabled:"i32",ior:"f32",transmissionFactor:"f32",transmissionMapEnabled:"i32",thicknessFactor:"f32",attenuationDistance:"f32",attenuationColor:"vec3<f32>",clearcoatFactor:"f32",clearcoatRoughnessFactor:"f32",clearcoatMapEnabled:"i32",clearcoatRoughnessMapEnabled:"i32",sheenColorFactor:"vec3<f32>",sheenRoughnessFactor:"f32",sheenColorMapEnabled:"i32",sheenRoughnessMapEnabled:"i32",iridescenceFactor:"f32",iridescenceIor:"f32",iridescenceThicknessRange:"vec2<f32>",iridescenceMapEnabled:"i32",anisotropyStrength:"f32",anisotropyRotation:"f32",anisotropyDirection:"vec2<f32>",anisotropyMapEnabled:"i32",emissiveStrength:"f32",IBLenabled:"i32",scaleIBLAmbient:"vec2<f32>",scaleDiffBaseMR:"vec4<f32>",scaleFGDSpec:"vec4<f32>",baseColorUVSet:"i32",baseColorUVTransform:"mat3x3<f32>",metallicRoughnessUVSet:"i32",metallicRoughnessUVTransform:"mat3x3<f32>",normalUVSet:"i32",normalUVTransform:"mat3x3<f32>",occlusionUVSet:"i32",occlusionUVTransform:"mat3x3<f32>",emissiveUVSet:"i32",emissiveUVTransform:"mat3x3<f32>",specularColorUVSet:"i32",specularColorUVTransform:"mat3x3<f32>",specularIntensityUVSet:"i32",specularIntensityUVTransform:"mat3x3<f32>",transmissionUVSet:"i32",transmissionUVTransform:"mat3x3<f32>",thicknessUVSet:"i32",thicknessUVTransform:"mat3x3<f32>",clearcoatUVSet:"i32",clearcoatUVTransform:"mat3x3<f32>",clearcoatRoughnessUVSet:"i32",clearcoatRoughnessUVTransform:"mat3x3<f32>",clearcoatNormalUVSet:"i32",clearcoatNormalUVTransform:"mat3x3<f32>",sheenColorUVSet:"i32",sheenColorUVTransform:"mat3x3<f32>",sheenRoughnessUVSet:"i32",sheenRoughnessUVTransform:"mat3x3<f32>",iridescenceUVSet:"i32",iridescenceUVTransform:"mat3x3<f32>",iridescenceThicknessUVSet:"i32",iridescenceThicknessUVTransform:"mat3x3<f32>",anisotropyUVSet:"i32",anisotropyUVTransform:"mat3x3<f32>"}};var qi=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],Wi=`layout(std140) uniform pbrSceneUniforms {
|
|
4359
7106
|
float exposure;
|
|
4360
7107
|
int toneMapMode;
|
|
4361
7108
|
float environmentIntensity;
|
|
@@ -4368,7 +7115,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
4368
7115
|
#ifdef USE_TRANSMISSION_FRAMEBUFFER
|
|
4369
7116
|
uniform sampler2D pbr_transmissionFramebufferSampler;
|
|
4370
7117
|
#endif
|
|
4371
|
-
`,
|
|
7118
|
+
`,Da=`struct pbrSceneUniforms {
|
|
4372
7119
|
exposure: f32,
|
|
4373
7120
|
toneMapMode: i32,
|
|
4374
7121
|
environmentIntensity: f32,
|
|
@@ -4384,6 +7131,6 @@ uniform sampler2D pbr_transmissionFramebufferSampler;
|
|
|
4384
7131
|
@group(1) @binding(auto) var pbr_transmissionFramebufferSampler: texture_2d<f32>;
|
|
4385
7132
|
@group(1) @binding(auto) var pbr_transmissionFramebufferSamplerSampler: sampler;
|
|
4386
7133
|
#endif
|
|
4387
|
-
`,
|
|
7134
|
+
`,Ki={name:"pbrScene",bindingLayout:[{name:"pbrScene",group:1},{name:"pbr_transmissionFramebufferSampler",group:1}],source:Da,vs:Wi,fs:Wi,getUniforms:e=>e,uniformTypes:{exposure:"f32",toneMapMode:"i32",environmentIntensity:"f32",environmentRotation:"f32",framebufferSize:"vec2<f32>",viewMatrix:"mat4x4<f32>",projectionMatrix:"mat4x4<f32>"},defaultUniforms:{exposure:1,toneMapMode:2,environmentIntensity:1,environmentRotation:Math.PI*.5,framebufferSize:[1,1],viewMatrix:qi,projectionMatrix:qi}};return ir(be);})();
|
|
4388
7135
|
return __exports__;
|
|
4389
7136
|
});
|