@luma.gl/shaders 10.0.0-alpha.10 → 10.0.0-alpha.12
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 +1923 -60
- package/dist/dist.min.js +1499 -148
- package/dist/glsl.cjs.map +1 -1
- package/dist/index.cjs +41 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.cjs +40 -0
- package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.d.ts +6 -0
- package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.d.ts.map +1 -0
- package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.js +15 -0
- package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.js.map +1 -0
- package/dist/modules/lighting/contact-shadow/contact-shadow.cjs +348 -0
- package/dist/modules/lighting/contact-shadow/contact-shadow.d.ts +188 -0
- package/dist/modules/lighting/contact-shadow/contact-shadow.d.ts.map +1 -0
- package/dist/modules/lighting/contact-shadow/contact-shadow.js +307 -0
- package/dist/modules/lighting/contact-shadow/contact-shadow.js.map +1 -0
- package/dist/modules/lighting/lightmap/lightmap-filter.cjs +93 -0
- package/dist/modules/lighting/lightmap/lightmap-filter.d.ts +35 -0
- package/dist/modules/lighting/lightmap/lightmap-filter.d.ts.map +1 -0
- package/dist/modules/lighting/lightmap/lightmap-filter.js +71 -0
- package/dist/modules/lighting/lightmap/lightmap-filter.js.map +1 -0
- package/dist/modules/lighting/lightmap/lightmap.cjs +89 -0
- package/dist/modules/lighting/lightmap/lightmap.d.ts +405 -0
- package/dist/modules/lighting/lightmap/lightmap.d.ts.map +1 -0
- package/dist/modules/lighting/lightmap/lightmap.js +67 -0
- package/dist/modules/lighting/lightmap/lightmap.js.map +1 -0
- package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.cjs +87 -0
- package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.d.ts +21 -0
- package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.js +61 -0
- package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.js.map +1 -0
- package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.cjs +87 -0
- package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.d.ts +21 -0
- package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.js +61 -0
- package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.js.map +1 -0
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.cjs +33 -11
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +2 -2
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +33 -11
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.cjs +33 -11
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +33 -11
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +3 -3
- package/dist/modules/lighting/pbr-shadow/pbr-shadow.cjs +97 -0
- package/dist/modules/lighting/pbr-shadow/pbr-shadow.d.ts +15 -0
- package/dist/modules/lighting/pbr-shadow/pbr-shadow.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-shadow/pbr-shadow.js +69 -0
- package/dist/modules/lighting/pbr-shadow/pbr-shadow.js.map +1 -0
- package/dist/modules/lighting/pbr-surface/pbr-surface.cjs +114 -0
- package/dist/modules/lighting/pbr-surface/pbr-surface.d.ts +15 -0
- package/dist/modules/lighting/pbr-surface/pbr-surface.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-surface/pbr-surface.js +88 -0
- package/dist/modules/lighting/pbr-surface/pbr-surface.js.map +1 -0
- package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.cjs +379 -0
- package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.d.ts +41 -0
- package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.d.ts.map +1 -0
- package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.js +345 -0
- package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.js.map +1 -0
- package/dist/modules/lighting/shadow/shadow-glsl.cjs +228 -0
- package/dist/modules/lighting/shadow/shadow-glsl.d.ts +3 -0
- package/dist/modules/lighting/shadow/shadow-glsl.d.ts.map +1 -0
- package/dist/modules/lighting/shadow/shadow-glsl.js +204 -0
- package/dist/modules/lighting/shadow/shadow-glsl.js.map +1 -0
- package/dist/modules/lighting/shadow/shadow-types.cjs +15 -0
- package/dist/modules/lighting/shadow/shadow-types.d.ts +63 -0
- package/dist/modules/lighting/shadow/shadow-types.d.ts.map +1 -0
- package/dist/modules/lighting/shadow/shadow-types.js +5 -0
- package/dist/modules/lighting/shadow/shadow-types.js.map +1 -0
- package/dist/modules/lighting/shadow/shadow.cjs +458 -0
- package/dist/modules/lighting/shadow/shadow.d.ts +117 -0
- package/dist/modules/lighting/shadow/shadow.d.ts.map +1 -0
- package/dist/modules/lighting/shadow/shadow.js +450 -0
- package/dist/modules/lighting/shadow/shadow.js.map +1 -0
- package/dist/modules/lighting/unlit-material/unlit-material.cjs +60 -0
- package/dist/modules/lighting/unlit-material/unlit-material.d.ts +9 -0
- package/dist/modules/lighting/unlit-material/unlit-material.d.ts.map +1 -0
- package/dist/modules/lighting/unlit-material/unlit-material.js +40 -0
- package/dist/modules/lighting/unlit-material/unlit-material.js.map +1 -0
- package/dist/types/shader-type-decoder.cjs +12 -2
- package/dist/types/shader-type-decoder.d.ts +7 -7
- package/dist/types/shader-type-decoder.d.ts.map +1 -1
- package/dist/types/shader-type-decoder.js +13 -2
- package/dist/types/shader-type-decoder.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/wgsl.cjs.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +52 -0
- package/src/modules/lighting/clustered-light-grid/clustered-light-grid.ts +17 -0
- package/src/modules/lighting/contact-shadow/contact-shadow.ts +365 -0
- package/src/modules/lighting/lightmap/lightmap-filter.ts +73 -0
- package/src/modules/lighting/lightmap/lightmap.ts +76 -0
- package/src/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.ts +78 -0
- package/src/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.ts +78 -0
- package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +33 -11
- package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +33 -11
- package/src/modules/lighting/pbr-shadow/pbr-shadow.ts +85 -0
- package/src/modules/lighting/pbr-surface/pbr-surface.ts +103 -0
- package/src/modules/lighting/prefiltered-environment/prefiltered-environment.ts +370 -0
- package/src/modules/lighting/shadow/shadow-glsl.ts +204 -0
- package/src/modules/lighting/shadow/shadow-types.ts +68 -0
- package/src/modules/lighting/shadow/shadow.ts +536 -0
- package/src/modules/lighting/unlit-material/unlit-material.ts +44 -0
- package/src/types/shader-type-decoder.ts +22 -9
package/dist/dist.min.js
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
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 xt=Object.defineProperty;var xo=Object.getOwnPropertyDescriptor;var So=Object.getOwnPropertyNames;var yo=Object.prototype.hasOwnProperty;var Co=(e,t)=>{for(var i in t)xt(e,i,{get:t[i],enumerable:!0})},Io=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of So(t))!yo.call(e,r)&&r!==i&&xt(e,r,{get:()=>t[r],enumerable:!(n=xo(t,r))||n.enumerable});return e};var wo=e=>Io(xt({},"__esModule",{value:!0}),e);var Dl={};Co(Dl,{GLSLShaderAssembler:()=>ye,PBR_ENVIRONMENT_FRAGMENT_GLSL:()=>to,PBR_ENVIRONMENT_FRAGMENT_WGSL:()=>io,PBR_TONE_MAP_MODE:()=>li,SKIN_MAX_JOINTS:()=>$,STORAGE_COLOR_DEFAULT_BYTE_STRIDES:()=>rt,STORAGE_COLOR_FORMAT:()=>k,STORAGE_COLOR_FORMAT_BYTE_LENGTHS:()=>nt,ShaderAssembler:()=>H,WGSLShaderAssembler:()=>Ce,_resolveModules:()=>Mi,areaLighting:()=>mt,assembleGLSLShaderPair:()=>Se,atmosphere:()=>Yr,capitalize:()=>ee,checkShaderModuleDeprecations:()=>se,clipShaderPlugin:()=>vr,clouds:()=>_t,clusteredLightGrid:()=>go,colors:()=>pr,combineInjects:()=>Pi,contactShadowBilateralBlur:()=>fo,contactShadowComposite:()=>uo,contactShadowTrace:()=>co,convertToVec4:()=>zt,dggs:()=>rr,dirlight:()=>ii,filterShaderPlugin:()=>hr,firefly:()=>Jr,floatColors:()=>me,fp32:()=>Xn,fp64:()=>ir,fp64LowPart:()=>Ie,fp64arithmetic:()=>Jt,fp64ify:()=>ge,fp64ifyMatrix4:()=>we,fromHalfFloat:()=>Gn,generateShaderForModule:()=>hn,getGLSLUniformBlocks:()=>Be,getPassthroughFS:()=>un,getQualifierDetails:()=>fn,getShaderInfo:()=>Ye,getShaderModuleDependencies:()=>V,getShaderModuleSource:()=>J,getShaderModuleUniformBlockFields:()=>Et,getShaderModuleUniformBlockName:()=>Ne,getShaderModuleUniformLayoutValidationResult:()=>Pt,getShaderModuleUniforms:()=>Li,globeClouds:()=>Qr,gouraudMaterial:()=>ri,gpuAnimation:()=>br,heightFog:()=>Hr,heightFogFunctions:()=>vt,ibl:()=>lt,initializeShaderModule:()=>Ee,initializeShaderModules:()=>Z,integrateSurfaceWeather:()=>Xr,lambertMaterial:()=>ni,lighting:()=>F,lightmapBake:()=>ho,lightmapFilter:()=>vo,mergeShaderPluginModules:()=>Gi,normalizeByteColor3:()=>ne,normalizeByteColor4:()=>it,pathDash:()=>$n,patternFill:()=>qr,pbrAmbientOcclusion:()=>mo,pbrContactShadow:()=>po,pbrEnvironmentFilter:()=>eo,pbrMaterial:()=>U,pbrScene:()=>ht,pbrShadow:()=>ao,pbrSurface:()=>so,phongMaterial:()=>oi,picking:()=>mr,pointGlow:()=>$r,precipitation:()=>Kr,preprocess:()=>q,random:()=>Kn,resolveShaderPlugins:()=>Vi,resolveUseByteColors:()=>ie,riverWaterMaterial:()=>Dr,scanWGSLInterface:()=>Re,shadow:()=>bt,sketchStroke:()=>qn,skin:()=>_r,storageColors:()=>gr,surfaceWeather:()=>Zr,toHalfFloat:()=>Vn,typeToChannelCount:()=>pn,typeToChannelSuffix:()=>dn,unlitMaterial:()=>Ir,validateShaderModuleUniformLayout:()=>Fe,valueNoise:()=>Y,volumeRaymarch:()=>Yn,warnIfGLSLUniformBlocksAreNotStd140:()=>Oe,waterMaterial:()=>gt});var B="(?:var<\\s*(uniform|storage(?:\\s*,\\s*[A-Za-z_][A-Za-z0-9_]*)?)\\s*>|var)\\s+([A-Za-z_][A-Za-z0-9_]*)";var ae=[new RegExp(`@binding\\(\\s*(auto|\\d+)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${B}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto|\\d+)\\s*\\)\\s*${B}`,"g")],Me=[new RegExp(`@binding\\(\\s*(auto|\\d+)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${B}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto|\\d+)\\s*\\)\\s*${B}`,"g")],hi=[new RegExp(`@binding\\(\\s*(\\d+)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${B}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(\\d+)\\s*\\)\\s*${B}`,"g")],Lo=[new RegExp(`@binding\\(\\s*(auto)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${B}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto)\\s*\\)\\s*${B}`,"g"),new RegExp(`@binding\\(\\s*(auto)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)(?:[\\s\\n\\r]*@[A-Za-z_][^\\n\\r]*)*[\\s\\n\\r]*${B}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto)\\s*\\)(?:[\\s\\n\\r]*@[A-Za-z_][^\\n\\r]*)*[\\s\\n\\r]*${B}`,"g")];function O(e){let t=e.split(""),i=0,n=0,r=!1,o=!1,a=!1;for(;i<e.length;){let s=e[i],l=e[i+1];if(o){a?a=!1:s==="\\"?a=!0:s==='"'&&(o=!1),i++;continue}if(r){s===`
|
|
8
8
|
`||s==="\r"?r=!1:t[i]=" ",i++;continue}if(n>0){if(s==="/"&&l==="*"){t[i]=" ",t[i+1]=" ",n++,i+=2;continue}if(s==="*"&&l==="/"){t[i]=" ",t[i+1]=" ",n--,i+=2;continue}s!==`
|
|
9
|
-
`&&s!=="\r"&&(t[i]=" "),i++;continue}if(s==='"'){o=!0,i++;continue}if(s==="/"&&l==="/"){t[i]=" ",t[i+1]=" ",r=!0,i+=2;continue}if(s==="/"&&l==="*"){t[i]=" ",t[i+1]=" ",n=1,i+=2;continue}i++}return t.join("")}function Y(e,t){let i=B(e),n=[];for(let r of t){r.lastIndex=0;let o;for(o=r.exec(i);o;){let a=r===t[0],s=o.index,l=o[0].length;n.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(i)}}return n.sort((r,o)=>r.index-o.index)}function bt(e,t,i){let n=Y(e,t);if(!n.length)return e;let r="",o=0;for(let a of n)r+=e.slice(o,a.index),r+=i(a),o=a.index+a.length;return r+=e.slice(o),r}function xt(e){return/@binding\(\s*auto\s*\)/.test(B(e))}function di(e,t){return Y(e,t===oe||t===Ae?to:t).find(n=>n.bindingToken==="auto")}function Re(e,t={}){let i=gi(e),n=io(i);if(!n)return null;let r=no(i,n);if(!r)return null;let o=oo(i,n,r);if(!o)return null;if(t.scanVertexAttributes===!1)return{attributes:[],bindings:o};let a=ro(i,n);if(!a)return null;let s=fo(i,n,r,a,t.vertexEntryPoint);return s?{attributes:s,bindings:o}:null}function gi(e){let t=B(e),i=/[A-Za-z_][A-Za-z0-9_]*|(?:0[xX][0-9A-Fa-f]+|\d+)|[@(){}<>\[\]:,;=]/g,n=[],r=i.exec(t);for(;r;)n.push({value:r[0],index:r.index}),r=i.exec(t);return n}function io(e){let t=[],i=0;for(let n of e){if(n.value==="}"&&i===0)return null;t.push(i),n.value==="{"?i++:n.value==="}"&&i--}return i===0?t:null}function no(e,t){let i=new Map;for(let n=0;n<e.length;n++){if(t[n]!==0||e[n].value!=="alias")continue;let r=e[n+1]?.value;if(!me(r)||e[n+2]?.value!=="="||i.has(r))return null;let o=_i(e,t,n+3,";");if(o<0||o===n+3)return null;i.set(r,Me(e.slice(n+3,o))),n=o}return i}function ro(e,t){let i=new Map;for(let n=0;n<e.length;n++){if(t[n]!==0||e[n].value!=="struct")continue;let r=e[n+1]?.value,o=n+2;if(!me(r)||i.has(r)||e[o]?.value!=="{")return null;let a=Ct(e,o,"{","}");if(a<0)return null;i.set(r,e.slice(o+1,a)),n=a}return i}function oo(e,t,i){let n=[],r=new Set,o=new Set;for(let a=0;a<e.length;a++){if(t[a]!==0||e[a].value!=="var")continue;let s=vi(e,t,a),l=e.slice(s,a),c=St(l,"group"),f=St(l,"binding");if(c===null||f===null||c===void 0!=(f===void 0))return null;if(c===void 0||f===void 0)continue;let p=a+1,u=[];if(e[p]?.value==="<"){let S=Ct(e,p,"<",">");if(S<0)return null;let x=Ee(e.slice(p+1,S),",");if(!x)return null;u=x.map(Me),p=S+1}let d=e[p]?.value;if(!me(d)||e[p+1]?.value!==":")return null;let g=_i(e,t,p+2,";");if(g<0||g===p+2)return null;let m=yt(Me(e.slice(p+2,g)),i);if(!m)return null;let b=ao({name:d,group:c,location:f,addressSpace:u,resourceType:m}),I=`${c}:${f}`;if(!b||r.has(I)||o.has(d))return null;n.push(b),r.add(I),o.add(d),a=g}return co(n),n.sort((a,s)=>a.group-s.group||a.location-s.location||a.name.localeCompare(s.name))}function ao(e){let{name:t,group:i,location:n,addressSpace:r,resourceType:o}=e,a={name:t,group:i,location:n};if(r[0]==="uniform"&&r.length===1)return{...a,type:"uniform"};if(r[0]==="storage"&&r.length<=2){let s=r[1]||"read";return s==="read"?{...a,type:"read-only-storage"}:s==="read_write"?{...a,type:"storage"}:null}return r.length>0?null:o==="sampler"||o==="sampler_comparison"?{...a,type:"sampler",...o==="sampler_comparison"?{samplerType:"comparison"}:{}}:o==="texture_external"?{...a,type:"external-texture"}:so(a,o)||lo(a,o)}function so(e,t){let i=/^texture_storage_(1d|2d|2d_array|3d)<([A-Za-z0-9_]+),(read|write|read_write)>$/.exec(t);if(!i)return null;let n={read:"read-only",write:"write-only",read_write:"read-write"}[i[3]];return{...e,type:"storage",format:i[2],access:n,viewDimension:It(i[1])}}function lo(e,t){let i=/^texture_(multisampled_)?(1d|2d|2d_array|cube|cube_array|3d)<(f32|i32|u32)>$/.exec(t);if(i){if(i[1]&&i[2]!=="2d")return null;let r={f32:"float",i32:"sint",u32:"uint"}[i[3]];return{...e,type:"texture",viewDimension:It(i[2]),sampleType:r,multisampled:!!i[1]}}let n=/^texture_depth_(multisampled_)?(2d|2d_array|cube|cube_array)$/.exec(t);return!n||n[1]&&n[2]!=="2d"?null:{...e,type:"texture",viewDimension:It(n[2]),sampleType:"depth",multisampled:!!n[1]}}function co(e){for(let t of e){if(t.type!=="sampler"||t.samplerType||!t.name.endsWith("Sampler"))continue;let i=t.name.slice(0,-7);e.find(r=>r.type==="texture"&&r.name===i&&r.group===t.group)?.sampleType==="depth"&&(t.samplerType="non-filtering")}}function fo(e,t,i,n,r){let o=uo(e,t);if(!o)return null;let a=o.filter(d=>d.vertex),s=r?a.find(d=>d.name===r):a.length===1?a[0]:void 0;if(!s)return a.length===0&&!r?[]:null;let l=Ee(s.parameters,",");if(!l)return null;let c=[],f=new Set,p=new Set,u=new Set;for(let d of l)if(d.length>0&&!mi({declaration:d,aliases:i,structures:n,attributes:c,attributeLocations:f,attributeNames:p,visitedStructures:u}))return null;return c.sort((d,g)=>d.location-g.location||d.name.localeCompare(g.name))}function uo(e,t){let i=[],n=new Set;for(let r=0;r<e.length;r++){if(t[r]!==0||e[r].value!=="fn")continue;let o=e[r+1]?.value,a=r+2;if(!me(o)||n.has(o)||e[a]?.value!=="(")return null;let s=Ct(e,a,"(",")");if(s<0)return null;let l=vi(e,t,r);i.push({name:o,vertex:hi(e.slice(l,r),"vertex"),parameters:e.slice(a+1,s)}),n.add(o),r=s}return i}function mi(e){let{declaration:t,aliases:i,structures:n,attributes:r,attributeLocations:o,attributeNames:a,visitedStructures:s}=e,l=mo(t,":");if(l<1||l===t.length-1)return!1;let c=ho(t.slice(0,l)),f=St(t.slice(0,l),"location"),p=hi(t.slice(0,l),"builtin"),u=yt(Me(t.slice(l+1)),i);if(!c||f===null||!u||f!==void 0&&p)return!1;if(f!==void 0){let m=go(u);return!m||o.has(f)||a.has(c)?!1:(r.push({name:c,location:f,type:m}),o.add(f),a.add(c),!0)}if(p)return!0;let d=n.get(u);if(!d||s.has(u))return!1;let g=Ee(d,",");if(!g)return!1;s.add(u);for(let m of g)if(m.length>0&&!mi({...e,declaration:m}))return!1;return s.delete(u),!0}function yt(e,t,i=new Set){let n=gi(e),r="";for(let o of n){let a=t.get(o.value);if(!a){r+=po(o.value);continue}if(i.has(o.value))return null;let s=new Set(i);s.add(o.value);let l=yt(a,t,s);if(!l)return null;r+=l}return r}function po(e){let t=/^(vec[234]|mat[234]x[234])([fiuh])$/.exec(e);if(!t)return e;let i={f:"f32",i:"i32",u:"u32",h:"f16"}[t[2]];return`${t[1]}<${i}>`}function go(e){return/^(?:i32|u32|f32|f16|vec[234]<(?:i32|u32|f32|f16)>)$/.test(e)?e:null}function St(e,t){let i;for(let n=0;n<e.length;n++)if(!(e[n].value!=="@"||e[n+1]?.value!==t)){if(i!==void 0||e[n+2]?.value!=="("||!/^\d+$/.test(e[n+3]?.value||"")||e[n+4]?.value!==")")return null;i=Number(e[n+3].value)}return i}function hi(e,t){return e.some((i,n)=>i.value==="@"&&e[n+1]?.value===t)}function It(e){return e.replace("_","-")}function Ct(e,t,i,n){let r=0;for(let o=t;o<e.length;o++)if(e[o].value===i)r++;else if(e[o].value===n&&--r===0)return o;return-1}function Ee(e,t){let i=[],n=0,r={"(":0,"<":0,"[":0,"{":0},o=Object.keys(r),a={")":"(",">":"<","]":"[","}":"{"};for(let s=0;s<e.length;s++){let l=e[s].value;if(l===t&&o.every(c=>r[c]===0)){i.push(e.slice(n,s)),n=s+1;continue}if(l in r)r[l]++;else if(l in a){let c=a[l];if(r[c]--,r[c]<0)return null}}return o.every(s=>r[s]===0)?(i.push(e.slice(n)),i):null}function mo(e,t){let i=Ee(e,t);return i&&i.length===2?i[0].length:-1}function _i(e,t,i,n){for(let r=i;r<e.length;r++)if(t[r]===0&&e[r].value===n)return r;return-1}function vi(e,t,i){for(let n=i-1;n>=0;n--)if(e[n].value===";"&&t[n]===0||e[n].value==="}"&&t[n]===1)return n+1;return 0}function ho(e){for(let t=e.length-1;t>=0;t--)if(me(e[t].value))return e[t].value;return null}function Me(e){return e.map(t=>t.value).join("")}function me(e){return!!(e&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(e))}function T(e,t){if(!e){let i=new Error(t||"shaders: assertion failed.");throw Error.captureStackTrace?.(i,T),i}}var Lt={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 xi(e){let t={};for(let[i,n]of Object.entries(e))t[i]=_o(n);return t}function Si(e,t,i){let n={};for(let[r,o]of Object.entries(t))e&&r in e&&!o.private?(o.validate&&T(o.validate(e[r],o),`${i}: invalid ${r}`),n[r]=e[r]):n[r]=o.value;return n}function _o(e){let t=bi(e);if(t!=="object")return{value:e,...Lt[t],type:t};if(typeof e=="object")return e?e.type!==void 0?{...e,...Lt[e.type],type:e.type}:e.value===void 0?{type:"object",value:e}:(t=bi(e.value),{...e,...Lt[t],type:t}):{type:"object",value:null};throw new Error("props")}function bi(e){return Array.isArray(e)||ArrayBuffer.isView(e)?"array":typeof e}function Z(e){e.map(t=>we(t))}function we(e){if(e.instance)return;Z(e.dependencies||[]);let{propTypes:t={},deprecations:i=[]}=e,n={parsedDeprecations:vo(i),normalizedInjections:{vertex:{},fragment:{}}};t&&(n.propValidators=xi(t)),e.instance=n;let r={};t&&(r=Object.entries(t).reduce((o,[a,s])=>{let l=s?.value;return l&&(o[a]=l),o},{})),e.defaultUniforms={...e.defaultUniforms,...r}}function Ii(e,t,i){we(e);let n=i||{...e.defaultUniforms};return t&&e.getUniforms?e.getUniforms(t,n):Si(t,e.instance?.propValidators,e.name)}function ae(e,t,i){e.deprecations?.forEach(n=>{n.regex?.test(t)&&(n.deprecated?i.deprecated(n.old,n.new)():i.removed(n.old,n.new)())})}function vo(e){return e.forEach(t=>{t.type==="function"?t.regex=new RegExp(`\\b${t.old}\\(`):t.regex=new RegExp(`${t.type} ${t.old};`)}),e}function G(e){let t=new Set,i=new Set,n=[],r=new Map;function o(l){let c=r.get(l.name);if(c&&c!==l)throw new Error(`Shader module name collision: Multiple different module objects share the name "${l.name}". Each module object must have a unique name.`);r.set(l.name,l)}function a(l,c){if(i.has(l)){let p=[...c,l.name].join(" -> ");throw new Error(`Shader module dependency cycle detected: ${p}`)}if(t.has(l))return;o(l),i.add(l);let f=[...c,l.name];if(l.dependencies)for(let p of l.dependencies)a(p,f);i.delete(l),t.add(l),n.push(l)}for(let l of e)a(l,[]);let s=new Set;for(let l of n)l.implements!==void 0&&(T(!s.has(l.implements)),s.add(l.implements));return Z(n),n}function bo(e){return G(e)}function yi(e){return bo(e)}var Ci=`#ifdef MODULE_LOGDEPTH
|
|
9
|
+
`&&s!=="\r"&&(t[i]=" "),i++;continue}if(s==='"'){o=!0,i++;continue}if(s==="/"&&l==="/"){t[i]=" ",t[i+1]=" ",r=!0,i+=2;continue}if(s==="/"&&l==="*"){t[i]=" ",t[i+1]=" ",n=1,i+=2;continue}i++}return t.join("")}function X(e,t){let i=O(e),n=[];for(let r of t){r.lastIndex=0;let o;for(o=r.exec(i);o;){let a=r===t[0],s=o.index,l=o[0].length;n.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(i)}}return n.sort((r,o)=>r.index-o.index)}function St(e,t,i){let n=X(e,t);if(!n.length)return e;let r="",o=0;for(let a of n)r+=e.slice(o,a.index),r+=i(a),o=a.index+a.length;return r+=e.slice(o),r}function yt(e){return/@binding\(\s*auto\s*\)/.test(O(e))}function vi(e,t){return X(e,t===ae||t===Me?Lo:t).find(n=>n.bindingToken==="auto")}function Re(e,t={}){let i=_i(e),n=Mo(i);if(!n)return null;let r=Ao(i,n);if(!r)return null;let o=To(i,n,r);if(!o)return null;if(t.scanVertexAttributes===!1)return{attributes:[],bindings:o};let a=Ro(i,n);if(!a)return null;let s=Fo(i,n,r,a,t.vertexEntryPoint);return s?{attributes:s,bindings:o}:null}function _i(e){let t=O(e),i=/[A-Za-z_][A-Za-z0-9_]*|(?:0[xX][0-9A-Fa-f]+|\d+)|[@(){}<>\[\]:,;=]/g,n=[],r=i.exec(t);for(;r;)n.push({value:r[0],index:r.index}),r=i.exec(t);return n}function Mo(e){let t=[],i=0;for(let n of e){if(n.value==="}"&&i===0)return null;t.push(i),n.value==="{"?i++:n.value==="}"&&i--}return i===0?t:null}function Ao(e,t){let i=new Map;for(let n=0;n<e.length;n++){if(t[n]!==0||e[n].value!=="alias")continue;let r=e[n+1]?.value;if(!he(r)||e[n+2]?.value!=="="||i.has(r))return null;let o=Si(e,t,n+3,";");if(o<0||o===n+3)return null;i.set(r,Ae(e.slice(n+3,o))),n=o}return i}function Ro(e,t){let i=new Map;for(let n=0;n<e.length;n++){if(t[n]!==0||e[n].value!=="struct")continue;let r=e[n+1]?.value,o=n+2;if(!he(r)||i.has(r)||e[o]?.value!=="{")return null;let a=Lt(e,o,"{","}");if(a<0)return null;i.set(r,e.slice(o+1,a)),n=a}return i}function To(e,t,i){let n=[],r=new Set,o=new Set;for(let a=0;a<e.length;a++){if(t[a]!==0||e[a].value!=="var")continue;let s=yi(e,t,a),l=e.slice(s,a),c=Ct(l,"group"),f=Ct(l,"binding");if(c===null||f===null||c===void 0!=(f===void 0))return null;if(c===void 0||f===void 0)continue;let d=a+1,u=[];if(e[d]?.value==="<"){let S=Lt(e,d,"<",">");if(S<0)return null;let x=Te(e.slice(d+1,S),",");if(!x)return null;u=x.map(Ae),d=S+1}let p=e[d]?.value;if(!he(p)||e[d+1]?.value!==":")return null;let g=Si(e,t,d+2,";");if(g<0||g===d+2)return null;let m=wt(Ae(e.slice(d+2,g)),i);if(!m)return null;let b=Eo({name:p,group:c,location:f,addressSpace:u,resourceType:m}),y=`${c}:${f}`;if(!b||r.has(y)||o.has(p))return null;n.push(b),r.add(y),o.add(p),a=g}return No(n),n.sort((a,s)=>a.group-s.group||a.location-s.location||a.name.localeCompare(s.name))}function Eo(e){let{name:t,group:i,location:n,addressSpace:r,resourceType:o}=e,a={name:t,group:i,location:n};if(r[0]==="uniform"&&r.length===1)return{...a,type:"uniform"};if(r[0]==="storage"&&r.length<=2){let s=r[1]||"read";return s==="read"?{...a,type:"read-only-storage"}:s==="read_write"?{...a,type:"storage"}:null}return r.length>0?null:o==="sampler"||o==="sampler_comparison"?{...a,type:"sampler",...o==="sampler_comparison"?{samplerType:"comparison"}:{}}:o==="texture_external"?{...a,type:"external-texture"}:Po(a,o)||Do(a,o)}function Po(e,t){let i=/^texture_storage_(1d|2d|2d_array|3d)<([A-Za-z0-9_]+),(read|write|read_write)>$/.exec(t);if(!i)return null;let n={read:"read-only",write:"write-only",read_write:"read-write"}[i[3]];return{...e,type:"storage",format:i[2],access:n,viewDimension:It(i[1])}}function Do(e,t){let i=/^texture_(multisampled_)?(1d|2d|2d_array|cube|cube_array|3d)<(f32|i32|u32)>$/.exec(t);if(i){if(i[1]&&i[2]!=="2d")return null;let r={f32:"float",i32:"sint",u32:"uint"}[i[3]];return{...e,type:"texture",viewDimension:It(i[2]),sampleType:r,multisampled:!!i[1]}}let n=/^texture_depth_(multisampled_)?(2d|2d_array|cube|cube_array)$/.exec(t);return!n||n[1]&&n[2]!=="2d"?null:{...e,type:"texture",viewDimension:It(n[2]),sampleType:"depth",multisampled:!!n[1]}}function No(e){for(let t of e){if(t.type!=="sampler"||t.samplerType||!t.name.endsWith("Sampler"))continue;let i=t.name.slice(0,-7);e.find(r=>r.type==="texture"&&r.name===i&&r.group===t.group)?.sampleType==="depth"&&(t.samplerType="non-filtering")}}function Fo(e,t,i,n,r){let o=Bo(e,t);if(!o)return null;let a=o.filter(p=>p.vertex),s=r?a.find(p=>p.name===r):a.length===1?a[0]:void 0;if(!s)return a.length===0&&!r?[]:null;let l=Te(s.parameters,",");if(!l)return null;let c=[],f=new Set,d=new Set,u=new Set;for(let p of l)if(p.length>0&&!bi({declaration:p,aliases:i,structures:n,attributes:c,attributeLocations:f,attributeNames:d,visitedStructures:u}))return null;return c.sort((p,g)=>p.location-g.location||p.name.localeCompare(g.name))}function Bo(e,t){let i=[],n=new Set;for(let r=0;r<e.length;r++){if(t[r]!==0||e[r].value!=="fn")continue;let o=e[r+1]?.value,a=r+2;if(!he(o)||n.has(o)||e[a]?.value!=="(")return null;let s=Lt(e,a,"(",")");if(s<0)return null;let l=yi(e,t,r);i.push({name:o,vertex:xi(e.slice(l,r),"vertex"),parameters:e.slice(a+1,s)}),n.add(o),r=s}return i}function bi(e){let{declaration:t,aliases:i,structures:n,attributes:r,attributeLocations:o,attributeNames:a,visitedStructures:s}=e,l=ko(t,":");if(l<1||l===t.length-1)return!1;let c=zo(t.slice(0,l)),f=Ct(t.slice(0,l),"location"),d=xi(t.slice(0,l),"builtin"),u=wt(Ae(t.slice(l+1)),i);if(!c||f===null||!u||f!==void 0&&d)return!1;if(f!==void 0){let m=Uo(u);return!m||o.has(f)||a.has(c)?!1:(r.push({name:c,location:f,type:m}),o.add(f),a.add(c),!0)}if(d)return!0;let p=n.get(u);if(!p||s.has(u))return!1;let g=Te(p,",");if(!g)return!1;s.add(u);for(let m of g)if(m.length>0&&!bi({...e,declaration:m}))return!1;return s.delete(u),!0}function wt(e,t,i=new Set){let n=_i(e),r="";for(let o of n){let a=t.get(o.value);if(!a){r+=Oo(o.value);continue}if(i.has(o.value))return null;let s=new Set(i);s.add(o.value);let l=wt(a,t,s);if(!l)return null;r+=l}return r}function Oo(e){let t=/^(vec[234]|mat[234]x[234])([fiuh])$/.exec(e);if(!t)return e;let i={f:"f32",i:"i32",u:"u32",h:"f16"}[t[2]];return`${t[1]}<${i}>`}function Uo(e){return/^(?:i32|u32|f32|f16|vec[234]<(?:i32|u32|f32|f16)>)$/.test(e)?e:null}function Ct(e,t){let i;for(let n=0;n<e.length;n++)if(!(e[n].value!=="@"||e[n+1]?.value!==t)){if(i!==void 0||e[n+2]?.value!=="("||!/^\d+$/.test(e[n+3]?.value||"")||e[n+4]?.value!==")")return null;i=Number(e[n+3].value)}return i}function xi(e,t){return e.some((i,n)=>i.value==="@"&&e[n+1]?.value===t)}function It(e){return e.replace("_","-")}function Lt(e,t,i,n){let r=0;for(let o=t;o<e.length;o++)if(e[o].value===i)r++;else if(e[o].value===n&&--r===0)return o;return-1}function Te(e,t){let i=[],n=0,r={"(":0,"<":0,"[":0,"{":0},o=Object.keys(r),a={")":"(",">":"<","]":"[","}":"{"};for(let s=0;s<e.length;s++){let l=e[s].value;if(l===t&&o.every(c=>r[c]===0)){i.push(e.slice(n,s)),n=s+1;continue}if(l in r)r[l]++;else if(l in a){let c=a[l];if(r[c]--,r[c]<0)return null}}return o.every(s=>r[s]===0)?(i.push(e.slice(n)),i):null}function ko(e,t){let i=Te(e,t);return i&&i.length===2?i[0].length:-1}function Si(e,t,i,n){for(let r=i;r<e.length;r++)if(t[r]===0&&e[r].value===n)return r;return-1}function yi(e,t,i){for(let n=i-1;n>=0;n--)if(e[n].value===";"&&t[n]===0||e[n].value==="}"&&t[n]===1)return n+1;return 0}function zo(e){for(let t=e.length-1;t>=0;t--)if(he(e[t].value))return e[t].value;return null}function Ae(e){return e.map(t=>t.value).join("")}function he(e){return!!(e&&/^[A-Za-z_][A-Za-z0-9_]*$/.test(e))}function E(e,t){if(!e){let i=new Error(t||"shaders: assertion failed.");throw Error.captureStackTrace?.(i,E),i}}var Mt={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 Ii(e){let t={};for(let[i,n]of Object.entries(e))t[i]=Vo(n);return t}function wi(e,t,i){let n={};for(let[r,o]of Object.entries(t))e&&r in e&&!o.private?(o.validate&&E(o.validate(e[r],o),`${i}: invalid ${r}`),n[r]=e[r]):n[r]=o.value;return n}function Vo(e){let t=Ci(e);if(t!=="object")return{value:e,...Mt[t],type:t};if(typeof e=="object")return e?e.type!==void 0?{...e,...Mt[e.type],type:e.type}:e.value===void 0?{type:"object",value:e}:(t=Ci(e.value),{...e,...Mt[t],type:t}):{type:"object",value:null};throw new Error("props")}function Ci(e){return Array.isArray(e)||ArrayBuffer.isView(e)?"array":typeof e}function Z(e){e.map(t=>Ee(t))}function Ee(e){if(e.instance)return;Z(e.dependencies||[]);let{propTypes:t={},deprecations:i=[]}=e,n={parsedDeprecations:Go(i),normalizedInjections:{vertex:{},fragment:{}}};t&&(n.propValidators=Ii(t)),e.instance=n;let r={};t&&(r=Object.entries(t).reduce((o,[a,s])=>{let l=s?.value;return l&&(o[a]=l),o},{})),e.defaultUniforms={...e.defaultUniforms,...r}}function Li(e,t,i){Ee(e);let n=i||{...e.defaultUniforms};return t&&e.getUniforms?e.getUniforms(t,n):wi(t,e.instance?.propValidators,e.name)}function se(e,t,i){e.deprecations?.forEach(n=>{n.regex?.test(t)&&(n.deprecated?i.deprecated(n.old,n.new)():i.removed(n.old,n.new)())})}function Go(e){return e.forEach(t=>{t.type==="function"?t.regex=new RegExp(`\\b${t.old}\\(`):t.regex=new RegExp(`${t.type} ${t.old};`)}),e}function V(e){let t=new Set,i=new Set,n=[],r=new Map;function o(l){let c=r.get(l.name);if(c&&c!==l)throw new Error(`Shader module name collision: Multiple different module objects share the name "${l.name}". Each module object must have a unique name.`);r.set(l.name,l)}function a(l,c){if(i.has(l)){let d=[...c,l.name].join(" -> ");throw new Error(`Shader module dependency cycle detected: ${d}`)}if(t.has(l))return;o(l),i.add(l);let f=[...c,l.name];if(l.dependencies)for(let d of l.dependencies)a(d,f);i.delete(l),t.add(l),n.push(l)}for(let l of e)a(l,[]);let s=new Set;for(let l of n)l.implements!==void 0&&(E(!s.has(l.implements)),s.add(l.implements));return Z(n),n}function Ho(e){return V(e)}function Mi(e){return Ho(e)}var Ai=`#ifdef MODULE_LOGDEPTH
|
|
10
10
|
logdepth_adjustPosition(gl_Position);
|
|
11
11
|
#endif
|
|
12
|
-
`,
|
|
12
|
+
`,Ri=`#ifdef MODULE_MATERIAL
|
|
13
13
|
fragColor = material_filterColor(fragColor);
|
|
14
14
|
#endif
|
|
15
15
|
|
|
@@ -29,60 +29,60 @@
|
|
|
29
29
|
#ifdef MODULE_LOGDEPTH
|
|
30
30
|
logdepth_setFragDepth();
|
|
31
31
|
#endif
|
|
32
|
-
`;var
|
|
32
|
+
`;var Wo={vertex:Ai,fragment:Ri},Ti=/void\s+main\s*\([^)]*\)\s*\{\n?/,Ei=/}\n?[^{}]*$/,At=[],ve="__LUMA_INJECT_DECLARATIONS__";function le(e,t,i){let n={};for(let r of e){let o=r[t];if(o===void 0)continue;if(r.stage!=="vertex"&&r.stage!=="fragment"||r.target.includes(":"))throw new Error("Shader injection targets require an explicit stage and unqualified target");let a=`${r.stage==="vertex"?"vs":"fs"}:${r.target}`;if(!/^(vs|fs):(?:#(?:decl|main-start|main-end)|[A-Za-z_][A-Za-z0-9_]*)$/.test(a))throw new Error(`Shader injection target "${a}" must be a named shader injection target`);n[a]||=[],n[a].push({injection:o,order:r.order??0,...i?{pluginName:i}:{}})}return n}function ce(e,t,i,n=!1,r="glsl",o={}){let a=t==="vertex";for(let s in i){let l=i[s];l.sort((f,d)=>f.order-d.order),At.length=l.length;for(let f=0,d=l.length;f<d;++f)At[f]=l[f].injection;let c=`${At.join(`
|
|
33
33
|
`)}
|
|
34
|
-
`;switch(s){case"vs:#decl":(r==="wgsl"||a)&&(e=e.replace(
|
|
35
|
-
${i[n]}`:i[n]}),t}function
|
|
36
|
-
${i}${e.slice(a)}`}return`${e.slice(0,o.closeBraceIndex)}${i}${e.slice(o.closeBraceIndex)}`}function
|
|
37
|
-
`)){let a=o.replace(/\/\/.*$/,"").trim();if(!a||a.startsWith("#"))continue;let s=t==="wgsl"?a.match(/^([A-Za-z0-9_]+)\s*:/):a.match(
|
|
34
|
+
`;switch(s){case"vs:#decl":(r==="wgsl"||a)&&(e=e.replace(ve,c));break;case"vs:#main-start":(r==="wgsl"||a)&&(e=r==="wgsl"?Pe(e,"vertex",c,"start",o.vertex):e.replace(Ti,f=>f+c));break;case"vs:#main-end":(r==="wgsl"||a)&&(e=r==="wgsl"?Pe(e,"vertex",c,"end",o.vertex):e.replace(Ei,f=>c+f));break;case"fs:#decl":(r==="wgsl"||!a)&&(e=e.replace(ve,c));break;case"fs:#main-start":(r==="wgsl"||!a)&&(e=r==="wgsl"?Pe(e,"fragment",c,"start",o.fragment):e.replace(Ti,f=>f+c));break;case"fs:#main-end":(r==="wgsl"||!a)&&(e=r==="wgsl"?Pe(e,"fragment",c,"end",o.fragment):e.replace(Ei,f=>c+f));break;default:e=e.replace(s,f=>f+c)}}return e=e.replace(ve,""),n&&(e=e.replace(/\}\s*$/,s=>s+Wo[t])),e}function Pi(e){let t={};return E(Array.isArray(e)&&e.length>1),e.forEach(i=>{for(let n in i)t[n]=t[n]?`${t[n]}
|
|
35
|
+
${i[n]}`:i[n]}),t}function Pe(e,t,i,n,r){let o=jo(e,t,r);if(!o)return e;if(n==="start"){let a=o.openBraceIndex+1;return`${e.slice(0,a)}
|
|
36
|
+
${i}${e.slice(a)}`}return`${e.slice(0,o.closeBraceIndex)}${i}${e.slice(o.closeBraceIndex)}`}function jo(e,t,i){let n=t==="vertex"?"@vertex":"@fragment",r=e.indexOf(n);if(r<0)return null;let o=i?e.search(new RegExp(`\\bfn\\s+${qo(i)}\\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 qo(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ni(e){let t=Tt(e),i=Oi[t];if(!i)throw new Error(`Unsupported variable shader type: ${e}`);return i}var Di=new Map;function Fi(e){let t=Rt(e),i=Di.get(t);if(i)return i;let n=Ko[t];if(!n)throw new Error(`Unsupported attribute shader type: ${e}`);let[r,o]=n,a=r==="i32"||r==="u32",s=r!=="u32",l=$o[r]*o,c=Object.freeze({primitiveType:r,components:o,byteLength:l,integer:a,signed:s});return Di.set(t,c),c}var De=class{getVariableShaderTypeInfo(t){return Ni(t)}getAttributeShaderTypeInfo(t){return Fi(t)}makeShaderAttributeType(t,i){return Bi(t,i)}resolveAttributeShaderTypeAlias(t){return Rt(t)}resolveVariableShaderTypeAlias(t){return Tt(t)}};function Bi(e,t){return t===1?e:`vec${t}<${e}>`}function Rt(e){return Ui[e]||e}function Tt(e){return ki[e]||e}var j=new De,$o={f32:4,f16:2,i32:4,u32:4},Ko={f32:["f32",1],"vec2<f32>":["f32",2],"vec3<f32>":["f32",3],"vec4<f32>":["f32",4],f16:["f16",1],"vec2<f16>":["f16",2],"vec3<f16>":["f16",3],"vec4<f16>":["f16",4],i32:["i32",1],"vec2<i32>":["i32",2],"vec3<i32>":["i32",3],"vec4<i32>":["i32",4],u32:["u32",1],"vec2<u32>":["u32",2],"vec3<u32>":["u32",3],"vec4<u32>":["u32",4]},Oi={f32:{type:"f32",components:1},f16:{type:"f16",components:1},i32:{type:"i32",components:1},u32:{type:"u32",components:1},"vec2<f32>":{type:"f32",components:2},"vec3<f32>":{type:"f32",components:3},"vec4<f32>":{type:"f32",components:4},"vec2<f16>":{type:"f16",components:2},"vec3<f16>":{type:"f16",components:3},"vec4<f16>":{type:"f16",components:4},"vec2<i32>":{type:"i32",components:2},"vec3<i32>":{type:"i32",components:3},"vec4<i32>":{type:"i32",components:4},"vec2<u32>":{type:"u32",components:2},"vec3<u32>":{type:"u32",components:3},"vec4<u32>":{type:"u32",components:4},"mat2x2<f32>":{type:"f32",components:4},"mat2x3<f32>":{type:"f32",components:6},"mat2x4<f32>":{type:"f32",components:8},"mat3x2<f32>":{type:"f32",components:6},"mat3x3<f32>":{type:"f32",components:9},"mat3x4<f32>":{type:"f32",components:12},"mat4x2<f32>":{type:"f32",components:8},"mat4x3<f32>":{type:"f32",components:12},"mat4x4<f32>":{type:"f32",components:16},"mat2x2<f16>":{type:"f16",components:4},"mat2x3<f16>":{type:"f16",components:6},"mat2x4<f16>":{type:"f16",components:8},"mat3x2<f16>":{type:"f16",components:6},"mat3x3<f16>":{type:"f16",components:9},"mat3x4<f16>":{type:"f16",components:12},"mat4x2<f16>":{type:"f16",components:8},"mat4x3<f16>":{type:"f16",components:12},"mat4x4<f16>":{type:"f16",components:16},"mat2x2<i32>":{type:"i32",components:4},"mat2x3<i32>":{type:"i32",components:6},"mat2x4<i32>":{type:"i32",components:8},"mat3x2<i32>":{type:"i32",components:6},"mat3x3<i32>":{type:"i32",components:9},"mat3x4<i32>":{type:"i32",components:12},"mat4x2<i32>":{type:"i32",components:8},"mat4x3<i32>":{type:"i32",components:12},"mat4x4<i32>":{type:"i32",components:16},"mat2x2<u32>":{type:"u32",components:4},"mat2x3<u32>":{type:"u32",components:6},"mat2x4<u32>":{type:"u32",components:8},"mat3x2<u32>":{type:"u32",components:6},"mat3x3<u32>":{type:"u32",components:9},"mat3x4<u32>":{type:"u32",components:12},"mat4x2<u32>":{type:"u32",components:8},"mat4x3<u32>":{type:"u32",components:12},"mat4x4<u32>":{type:"u32",components:16}};for(let e of Object.values(Oi))Object.freeze(e);var Ui={vec2i:"vec2<i32>",vec3i:"vec3<i32>",vec4i:"vec4<i32>",vec2u:"vec2<u32>",vec3u:"vec3<u32>",vec4u:"vec4<u32>",vec2f:"vec2<f32>",vec3f:"vec3<f32>",vec4f:"vec4<f32>",vec2h:"vec2<f16>",vec3h:"vec3<f16>",vec4h:"vec4<f16>"},ki={vec2i:"vec2<i32>",vec3i:"vec3<i32>",vec4i:"vec4<i32>",vec2u:"vec2<u32>",vec3u:"vec3<u32>",vec4u:"vec4<u32>",vec2f:"vec2<f32>",vec3f:"vec3<f32>",vec4f:"vec4<f32>",vec2h:"vec2<f16>",vec3h:"vec3<f16>",vec4h:"vec4<f16>",mat2x2f:"mat2x2<f32>",mat2x3f:"mat2x3<f32>",mat2x4f:"mat2x4<f32>",mat3x2f:"mat3x2<f32>",mat3x3f:"mat3x3<f32>",mat3x4f:"mat3x4<f32>",mat4x2f:"mat4x2<f32>",mat4x3f:"mat4x3<f32>",mat4x4f:"mat4x4<f32>",mat2x2i:"mat2x2<i32>",mat2x3i:"mat2x3<i32>",mat2x4i:"mat2x4<i32>",mat3x2i:"mat3x2<i32>",mat3x3i:"mat3x3<i32>",mat3x4i:"mat3x4<i32>",mat4x2i:"mat4x2<i32>",mat4x3i:"mat4x3<i32>",mat4x4i:"mat4x4<i32>",mat2x2u:"mat2x2<u32>",mat2x3u:"mat2x3<u32>",mat2x4u:"mat2x4<u32>",mat3x2u:"mat3x2<u32>",mat3x3u:"mat3x3<u32>",mat3x4u:"mat3x4<u32>",mat4x2u:"mat4x2<u32>",mat4x3u:"mat4x3<u32>",mat4x4u:"mat4x4<u32>",mat2x2h:"mat2x2<f16>",mat2x3h:"mat2x3<f16>",mat2x4h:"mat2x4<f16>",mat3x2h:"mat3x2<f16>",mat3x3h:"mat3x3<f16>",mat3x4h:"mat3x4<f16>",mat4x2h:"mat4x2<f16>",mat4x3h:"mat4x3<f16>",mat4x4h:"mat4x4<f16>"};function Vi(e=[],t){let i={modules:[],injectionTargets:[],defines:{},injections:{},vertexInputs:{},interStageVariables:{}};for(let o of e)Yo(i,o,t);let{vertexInputs:n,interStageVariables:r}=i;for(let o of Object.keys(r))if(n[o])throw new Error(`ShaderPlugin name "${o}" cannot be both a vertex input and a varying`);return i}function Gi(e=[],t=[],i={}){let n=[...e],r=new Map;for(let o of n){let a=r.get(o.name);a&&a!==o&&i.onConflict?.(o.name,a,o),a||r.set(o.name,o)}for(let o of t){let a=r.get(o.name);a&&a!==o&&i.onConflict?.(o.name,a,o),a||(n.push(o),r.set(o.name,o))}return n}function Yo(e,t,i){t.module&&e.modules.push(t.module),t.defines&&Object.assign(e.defines,t.defines);for(let[o,a]of Object.entries(t.vertexInputs||{})){zi(o,"vertex input");let s=e.vertexInputs[o];if(s&&s!==a)throw new Error(`ShaderPlugin vertex input "${o}" has conflicting types "${s}" and "${a}"`);e.vertexInputs[o]=a}for(let[o,a]of Object.entries(t.interStageVariables||{})){zi(o,"varying");let s=Xo(o,a),l=e.interStageVariables[o];if(l&&(l.type!==s.type||l.interpolation!==s.interpolation))throw new Error(`ShaderPlugin varying "${o}" has conflicting declarations "${l.type}/${l.interpolation}" and "${s.type}/${s.interpolation}"`);e.interStageVariables[o]=s}for(let o of t.injectionTargets||[]){let a=o[i];if(!a)continue;let s=`${o.stage==="vertex"?"vs":"fs"}:${o.name}`;if(!/^(vs|fs):[A-Za-z_][A-Za-z0-9_]*$/.test(s))throw new Error(`Invalid ShaderPlugin injection target ${s}`);let l=e.injectionTargets.find(f=>f.stage===o.stage&&f.name===o.name),c=l?.[i];if(c&&(c.parameters!==a.parameters||(c.returnType||"void")!==(a.returnType||"void")||c.header!==a.header||c.footer!==a.footer))throw new Error(`Conflicting ShaderPlugin injection target ${s}`);l||e.injectionTargets.push({name:o.name,stage:o.stage,[i]:a})}let n=Array.isArray(t.injections)?t.injections:Object.entries(t.injections||{}).flatMap(([o,a])=>{let s=Zo(o,i);if(s===void 0)return[];let[l,...c]=s.split(":");if(l!=="vs"&&l!=="fs")throw new Error(`Invalid ShaderPlugin injection ${o}`);return[{stage:l==="vs"?"vertex":"fragment",target:c.join(":"),[i]:a}]}),r=le(n,i,t.name);for(let[o,a]of Object.entries(r))e.injections[o]||=[],e.injections[o].push(...a)}function zi(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 Xo(e,t){let{primitiveType:i}=j.getAttributeShaderTypeInfo(t.type),n=i==="i32"||i==="u32",r=t.interpolation||(n?"flat":"smooth");if(n&&r==="smooth")throw new Error(`ShaderPlugin integer varying "${e}" must use flat interpolation`);return{type:t.type,interpolation:r}}function Zo(e,t){let i=/^(glsl|wgsl):([\s\S]+)$/.exec(e);return i?i[1]===t?i[2]:void 0:e}var Jo=/^(?:uniform\s+)?(?:(?:lowp|mediump|highp)\s+)?[A-Za-z0-9_]+(?:<[^>]+>)?\s+([A-Za-z0-9_]+)(?:\s*\[[^\]]+\])?\s*;/,Qo=/((?: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 Ne(e){return`${e.name}Uniforms`}function Et(e,t){let i=t==="wgsl"?e.source:t==="vertex"?e.vs:e.fs;if(!i)return null;let n=Ne(e);return ea(i,t==="wgsl"?"wgsl":"glsl",n)}function Pt(e,t){let i=Object.keys(e.uniformTypes||{});if(!i.length)return null;let n=Et(e,t);return n?{moduleName:e.name,uniformBlockName:Ne(e),stage:t,expectedUniformNames:i,actualUniformNames:n,matches:na(i,n)}:null}function Fe(e,t,i={}){let n=Pt(e,t);if(!n||n.matches)return n;let r=ra(n);return i.log?.error?.(r,n)(),i.throwOnError!==!1&&E(!1,r),n}function Be(e){let t=[],i=oa(e);for(let n of i.matchAll(Qo)){let r=n[1]?.trim()||null;t.push({blockName:n[2],body:n[3],instanceName:n[4]||null,layoutQualifier:r,hasLayoutQualifier:!!r,isStd140:!!(r&&/\blayout\s*\([^)]*\bstd140\b[^)]*\)/.exec(r))})}return t}function Oe(e,t,i,n){let r=Be(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=n?.label?`${n.label} `:"",l=a.hasLayoutQualifier?`declares ${aa(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.`;i?.warn?.(c,a)()}return r}function ea(e,t,i){let n=t==="wgsl"?ta(e,i):ia(e,i);if(!n)return null;let r=[];for(let o of n.split(`
|
|
37
|
+
`)){let a=o.replace(/\/\/.*$/,"").trim();if(!a||a.startsWith("#"))continue;let s=t==="wgsl"?a.match(/^([A-Za-z0-9_]+)\s*:/):a.match(Jo);s&&r.push(s[1])}return r}function ta(e,t){let i=new RegExp(`\\bstruct\\s+${t}\\b`,"m").exec(e);if(!i)return null;let n=e.indexOf("{",i.index);if(n<0)return null;let r=0;for(let o=n;o<e.length;o++){let a=e[o];if(a==="{"){r++;continue}if(a==="}"&&(r--,r===0))return e.slice(n+1,o)}return null}function ia(e,t){return Be(e).find(n=>n.blockName===t)?.body||null}function na(e,t){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(e[i]!==t[i])return!1;return!0}function ra(e){let{expectedUniformNames:t,actualUniformNames:i}=e,n=t.filter(s=>!i.includes(s)),r=i.filter(s=>!t.includes(s)),o=[`Expected ${t.length} fields, found ${i.length}.`],a=sa(t,i);return a&&o.push(a),n.length&&o.push(`Missing from shader block (${n.length}): ${Hi(n)}.`),r.length&&o.push(`Unexpected in shader block (${r.length}): ${Hi(r)}.`),t.length<=12&&i.length<=12&&(n.length||r.length)&&(o.push(`Expected: ${t.join(", ")}.`),o.push(`Actual: ${i.join(", ")}.`)),`${e.moduleName}: ${e.stage} shader uniform block ${e.uniformBlockName} does not match module.uniformTypes. ${o.join(" ")}`}function oa(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"")}function aa(e){return e.replace(/\s+/g," ").trim()}function sa(e,t){let i=Math.min(e.length,t.length);for(let n=0;n<i;n++)if(e[n]!==t[n])return`First mismatch at field ${n+1}: expected ${e[n]}, found ${t[n]}.`;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 Hi(e,t=8){if(e.length<=t)return e.join(", ");let i=e.length-t;return`${e.slice(0,t).join(", ")}, ... (${i} more)`}var Wi=[new RegExp(`@binding\\(\\s*(\\d+)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${B}\\s*:\\s*([^;]+);`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(\\d+)\\s*\\)\\s*${B}\\s*:\\s*([^;]+);`,"g")];function $i(e,t=[]){let i=O(e),n=new Map;for(let o of t)n.set(ji(o.name,o.group,o.location),o.moduleName);let r=[];for(let o of Wi){o.lastIndex=0;let a;for(a=o.exec(i);a;){let s=o===Wi[0],l=Number(a[s?1:2]),c=Number(a[s?2:1]),f=a[3]?.trim(),d=a[4],u=a[5].trim(),p=n.get(ji(d,c,l));r.push(la({name:d,group:c,binding:l,owner:p?"module":"application",moduleName:p,accessDeclaration:f,resourceType:u})),a=o.exec(i)}}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 la(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 i=e.accessDeclaration.split(",").map(n=>n.trim());if(i[0]==="uniform")return{...t,kind:"uniform",access:"uniform"};if(i[0]==="storage"){let n=i[1]||"read_write";return{...t,kind:n==="read"?"read-only-storage":"storage",access:n}}}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:fa(e.resourceType),viewDimension:qi(e.resourceType)}:e.resourceType.startsWith("texture_")?{...t,kind:"texture",viewDimension:qi(e.resourceType),sampleType:ca(e.resourceType),multisampled:e.resourceType.startsWith("texture_multisampled_")}:t}function ji(e,t,i){return`${t}:${i}:${e}`}function qi(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 ca(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 fa(e){return/,\s*([A-Za-z_][A-Za-z0-9_]*)\s*>$/.exec(e)?.[1]}function ke(e,t=""){let i=new Map,n=Object.values(e).flatMap(o=>Object.entries(o).map(([a,s])=>`${a.slice(3)}
|
|
38
38
|
${s.signature}
|
|
39
39
|
${s.header||""}
|
|
40
|
-
${s.footer||""}`)),r=new Set(
|
|
40
|
+
${s.footer||""}`)),r=new Set(O(`${t}
|
|
41
41
|
${n.join(`
|
|
42
|
-
`)}`).match(/[_\p{XID_Start}][\p{XID_Continue}]*/gu));for(let o of Object.keys(e.vertex)){let a=o.slice(3);e.fragment[`fs:${a}`]&&i.set(a,{vertex:
|
|
43
|
-
`)+e.slice(u.end)}return e}function
|
|
42
|
+
`)}`).match(/[_\p{XID_Start}][\p{XID_Continue}]*/gu));for(let o of Object.keys(e.vertex)){let a=o.slice(3);e.fragment[`fs:${a}`]&&i.set(a,{vertex:Ue(`_luma_vertex_target_${a}`,r),fragment:Ue(`_luma_fragment_target_${a}`,r)})}return i}function Ki(e,t,i=ke(t)){if(!i.size)return e;let n=O(e),r=new Map,o=/((?:@\w+(?:\([^)]*\))?\s*)*)\bfn\s+([_\p{XID_Start}][\p{XID_Continue}]*)\s*\(/gu;for(let u=o.exec(n);u;u=o.exec(n)){let p=n.indexOf("{",o.lastIndex),g=p+1,m=1;for(;g<n.length&&m;g++)n[g]==="{"&&m++,n[g]==="}"&&m--;E(p>=0&&m===0);let b=u[2],y=u.index+u[0].lastIndexOf(b),S=Array.from(n.slice(p+1,g-1).matchAll(/([_\p{XID_Start}][\p{XID_Continue}]*)\s*\(/gu),x=>x[1]);r.set(b,{name:b,start:u.index,end:g,nameStart:y,bodyStart:p,calls:S,stages:new Set,entryStage:/@vertex\b/.test(u[1])?"vertex":/@fragment\b/.test(u[1])?"fragment":void 0}),o.lastIndex=g}function a(u,p){let g=r.get(u);if(!(!g||g.stages.has(p))){g.stages.add(p);for(let m of g.calls)a(i.get(m)?.[p]||m,p)}}for(let u of r.values())u.entryStage&&a(u.name,u.entryStage);for(let u of["vertex","fragment"])for(let p of Object.keys(t[u])){let g=p.slice(3);a(i.get(g)?.[u]||g,u)}let s=new Set,l=!0;for(;l;){l=!1;for(let u of r.values())!s.has(u.name)&&u.calls.some(p=>i.has(p)||s.has(p))&&(s.add(u.name),l=!0)}let c=new Map,f=new Set(n.match(/[_\p{XID_Start}][\p{XID_Continue}]*/gu));for(let u of s)r.get(u)?.stages.size===2&&c.set(u,{vertex:Ue(`_luma_vertex_helper_${u}`,f),fragment:Ue(`_luma_fragment_helper_${u}`,f)});function d(u,p){let g=i.get(u)?.[p];return g||c.get(u)?.[p]||u}for(let u of[...r.values()].reverse()){if(!s.has(u.name))continue;if(!u.stages.size)throw new Error(`Cannot infer WGSL target stage in ${u.name}`);let p=[],g=u.start;for(let m of u.stages){let b=e.slice(g,u.end),S=[...n.slice(u.bodyStart+1,u.end-1).matchAll(/([_\p{XID_Start}][\p{XID_Continue}]*)\s*\(/gu)];for(let v of S.reverse()){let h=u.bodyStart+1+v.index-g,_=d(v[1],m);b=b.slice(0,h)+_+b.slice(h+v[1].length)}let x=u.nameStart-g;b=b.slice(0,x)+d(u.name,m)+b.slice(x+u.name.length),p.push(b)}e=e.slice(0,g)+p.join(`
|
|
43
|
+
`)+e.slice(u.end)}return e}function Ue(e,t){let i=e,n=0;for(;t.has(i);)i=`${e}_${++n}`;return t.add(i),i}var _e=`
|
|
44
44
|
|
|
45
|
-
${
|
|
46
|
-
`;function
|
|
45
|
+
${ve}
|
|
46
|
+
`;function ze(e){return function(i){let n={};for(let r of e){let o=r.getUniforms?.(i,n);Object.assign(n,o)}return n}}function fe(e,t,i,n){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"?i:n:t;l[r]=l[r]||[],l[r].push(...e[r])}else n[r]=n[r]||[],n[r].push(...e[r])}}function J(e,t,i){let n;switch(t){case"vertex":n=e.vs||"";break;case"fragment":n=e.fs||"";break;case"wgsl":n=e.source||"";break;default:E(!1)}if(!e.name)throw new Error("Shader module must have a name");Fe(e,t,{log:i});let r=e.name.toUpperCase().replace(/[^0-9a-z]/gi,"_"),o=`// ----- MODULE ${e.name} ---------------
|
|
47
47
|
|
|
48
48
|
`;return t!=="wgsl"&&(o+=`#define MODULE_${r}
|
|
49
49
|
`),o+=`${n}
|
|
50
|
-
`,o}var
|
|
51
|
-
`),n=[],r=[],o=!0;for(let a of i){let s=a.match(
|
|
52
|
-
`)}function
|
|
53
|
-
`)}function
|
|
50
|
+
`,o}var Q="([a-zA-Z_][a-zA-Z0-9_]*)",ua=/^\s*\#\s*if\s+(.+?)\s*(?:\/\/.*)?$/,da=new RegExp(`^\\s*\\#\\s*ifdef\\s*${Q}\\s*$`),pa=new RegExp(`^\\s*\\#\\s*ifndef\\s*${Q}\\s*(?:\\/\\/.*)?$`),ga=/^\s*\#\s*else\s*(?:\/\/.*)?$/,ma=/^\s*\#\s*endif\s*$/,ha=new RegExp(`^\\s*\\#\\s*ifdef\\s*${Q}\\s*(?:\\/\\/.*)?$`),va=/^\s*\#\s*endif\s*(?:\/\/.*)?$/;function q(e,t){let i=e.split(`
|
|
51
|
+
`),n=[],r=[],o=!0;for(let a of i){let s=a.match(ua),l=a.match(ha)||a.match(da),c=a.match(pa),f=a.match(ga),d=a.match(va)||a.match(ma);if(s){let u=_a(s[1],t?.defines||{}),p=o&&u;r.push({parentActive:o,branchTaken:u,active:p}),o=p}else if(l||c){let u=(l||c)?.[1],p=!!t?.defines?.[u],g=l?p:!p,m=o&&g;r.push({parentActive:o,branchTaken:g,active:m}),o=m}else if(f){let u=r[r.length-1];if(!u)throw new Error("Encountered #else without matching #if, #ifdef or #ifndef");u.active=u.parentActive&&!u.branchTaken,u.branchTaken=!0,o=u.active}else d?(r.pop(),o=r.length?r[r.length-1].active:!0):o&&n.push(a)}if(r.length>0)throw new Error("Unterminated conditional block in shader source");return n.join(`
|
|
52
|
+
`)}function _a(e,t){let i=e.trim();if(/^[+-]?\d+(?:\.\d+)?$/.test(i))return Number(i)!==0;if(i==="true")return!0;if(i==="false")return!1;let n="(?:[A-Za-z_][A-Za-z0-9_]*|[+-]?\\d+(?:\\.\\d+)?)",r=i.match(new RegExp(`^(${n})\\s*(==|!=|<=|>=|<|>)\\s*(${n})$`));if(r){let c=u=>/^[A-Za-z_]/.test(u)?Number(t[u]??0):Number(u),f=c(r[1]),d=c(r[3]);switch(r[2]){case"==":return f===d;case"!=":return f!==d;case"<=":return f<=d;case">=":return f>=d;case"<":return f<d;case">":return f>d}}let o=i.match(new RegExp(`^!\\s*${Q}$`));if(o)return!t[o[1]];let a=i.match(new RegExp(`^${Q}$`));if(a)return!!t[a[1]];let s=i.match(new RegExp(`^defined\\s*\\(\\s*${Q}\\s*\\)$`));if(s)return t[s[1]]!==void 0;let l=i.match(new RegExp(`^!\\s*defined\\s*\\(\\s*${Q}\\s*\\)$`));if(l)return t[l[1]]===void 0;throw new Error(`Unsupported #if expression "${e}"`)}function Zi(e,t){let i=[];for(let[n,r]of Object.entries(t))ba(e,n),i.push(`in ${Ve(r)} ${n};`);return i.join(`
|
|
53
|
+
`)}function Ji(e,t,i){let n=Object.entries(i);if(n.length===0)return{source:e,declarations:"",initialization:""};let r=xa(e,t),o=e.slice(r.openParenthesis+1,r.closeParenthesis),a=Sa(e,o),s=new Set(a.locations),l=[],c=[],f=[];for(let[m,b]of n){if(a.names.has(m)||Ia(e,m))throw new Error(`ShaderPlugin vertex input "${m}" conflicts with an existing WGSL shader input or variable`);let y=wa(s);s.add(y);let S=`_luma_${m}`;l.push(`@location(${y}) ${S}: ${b}`),c.push(`var<private> ${m}: ${b};`),f.push(`${m} = ${S};`)}let d=o.trim()?`,
|
|
54
54
|
`:`
|
|
55
55
|
`,u=o.trim()?"":`
|
|
56
|
-
`,
|
|
57
|
-
`)}${u}`;return{source:e.slice(0,r.openParenthesis+1)+
|
|
56
|
+
`,p=`${o}${d}${l.join(`,
|
|
57
|
+
`)}${u}`;return{source:e.slice(0,r.openParenthesis+1)+p+e.slice(r.closeParenthesis),declarations:c.join(`
|
|
58
58
|
`),initialization:f.join(`
|
|
59
|
-
`)}}function
|
|
60
|
-
`&&(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===i&&r++,l===n&&--r===0)return s}return-1}function
|
|
61
|
-
`&&(r=!1);continue}if(n>0){a==="/"&&s==="*"?(n++,o++):a==="*"&&s==="/"&&(n--,o++);continue}a==="/"&&s==="/"?(r=!0,o++):a==="/"&&s==="*"?(n=1,o++):a==="{"?i++:a==="}"&&i--}return i}function
|
|
59
|
+
`)}}function Ve(e){let{primitiveType:t,components:i}=j.getAttributeShaderTypeInfo(e),n=t==="i32"?"int":t==="u32"?"uint":"float";return i===1?n:`${n==="int"?"i":n==="uint"?"u":""}vec${i}`}function ba(e,t){let i=Ge(t);if(new RegExp(`\\b(?:in|attribute)\\s+(?:(?:lowp|mediump|highp)\\s+)?[A-Za-z_][A-Za-z0-9_]*\\s+${i}\\s*(?:\\[|;)`).test(e))throw new Error(`ShaderPlugin vertex input "${t}" conflicts with an existing GLSL input`)}function xa(e,t){let n=new RegExp(`\\bfn\\s+${Ge(t)}\\s*\\(`,"g").exec(e);if(!n)throw new Error(`ShaderPlugin vertex inputs require WGSL vertex entry point "${t}"`);let r=e.indexOf("(",n.index),o=Qi(e,r,"(",")");if(o<0)throw new Error(`Unable to parse WGSL vertex entry point "${t}" parameters`);return{openParenthesis:r,closeParenthesis:o}}function Sa(e,t){let i=Yi(t),n=new Set(Xi(t)),r=ya(t);for(let o of r){let a=Ca(e,o);if(a!==null){i.push(...Yi(a));for(let s of Xi(a))n.add(s)}}return{locations:i,names:n}}function Yi(e){let t=[],i=/@location\s*\(\s*(\d+)\s*\)/g,n=i.exec(e);for(;n;)t.push(Number(n[1])),n=i.exec(e);return t}function Xi(e){let t=[],i=/(?:^|,)\s*(?:@[A-Za-z_][\w]*(?:\([^)]*\))?\s*)*([A-Za-z_][\w]*)\s*:/gm,n=i.exec(e);for(;n;)t.push(n[1]),n=i.exec(e);return t}function ya(e){let t=[],i=/:\s*([A-Za-z_][\w]*)\b/g,n=i.exec(e);for(;n;)t.push(n[1]),n=i.exec(e);return t}function Ca(e,t){let n=new RegExp(`\\bstruct\\s+${Ge(t)}\\s*\\{`,"g").exec(e);if(!n)return null;let r=e.indexOf("{",n.index),o=Qi(e,r,"{","}");return o<0?null:e.slice(r+1,o)}function Ia(e,t){let i=Ge(t),n=new RegExp(`\\b(?:var(?:<[^>]+>)?|let|const)\\s+${i}\\b`,"g"),r=n.exec(e);for(;r;){if(La(e,r.index)===0)return!0;r=n.exec(e)}return!1}function wa(e){let t=0;for(;e.has(t);)t++;return t}function Qi(e,t,i,n){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===`
|
|
60
|
+
`&&(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===i&&r++,l===n&&--r===0)return s}return-1}function La(e,t){let i=0,n=0,r=!1;for(let o=0;o<t;o++){let a=e[o],s=e[o+1];if(r){a===`
|
|
61
|
+
`&&(r=!1);continue}if(n>0){a==="/"&&s==="*"?(n++,o++):a==="*"&&s==="/"&&(n--,o++);continue}a==="/"&&s==="/"?(r=!0,o++):a==="/"&&s==="*"?(n=1,o++):a==="{"?i++:a==="}"&&i--}return i}function Ge(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function en(e,t,i){let n=[],r=[];for(let[o,a]of Object.entries(i)){ka(e,o);let s=a.interpolation==="flat"?"flat ":"",l=t==="vertex"?"out":"in";n.push(`${s}${l} ${Ve(a.type)} ${o};`),t==="vertex"&&r.push(`${o} = ${Oa(a.type)};`)}return{declarations:n.join(`
|
|
62
62
|
`),initialization:r.join(`
|
|
63
|
-
`)}}function
|
|
63
|
+
`)}}function tn(e,t,i,n){let r=Object.entries(n);if(r.length===0)return{source:e,declarations:"",vertexInitialization:"",fragmentInitialization:""};let o=e,a=He(o,t,"vertex"),s=Ma(o,a),l=He(o,i,"fragment"),c=Aa(o,l),f=Dt(o,s),d=c?Dt(o,c.type):null,u=new Set([...We(a.parameters),...We(f.body),...We(l.parameters),...We(d?.body||"")]),p=new Set([...Nt(f.body),...Nt(d?.body||""),...Nt(l.parameters)]),g=[],m=[],b=[],y=[],S=[];for(let[h,_]of r){if(u.has(h)||Fa(o,h))throw new Error(`ShaderPlugin varying "${h}" conflicts with existing WGSL stage I/O or a module variable`);let L=Ba(p);p.add(L);let I=_.interpolation==="flat"?" @interpolate(flat)":"";if(g.push(` @location(${L})${I} ${h}: ${_.type},`),b.push(`var<private> ${h}: ${_.type};`),y.push(`${h} = ${Ua(_.type)};`),c)S.push(`${h} = ${c.name}.${h};`);else{let A=`_luma_${h}`;if(u.has(A))throw new Error(`ShaderPlugin varying "${h}" conflicts with a generated fragment parameter`);m.push(`@location(${L})${I} ${A}: ${_.type}`),S.push(`${h} = ${A};`)}}Ra(o,s,a.openBrace,a.closeBrace),o=Ta(o,s,a,r.map(([h])=>h)),a=He(o,t,"vertex"),o=Ea(o,a,r.map(([h])=>h));let v=(!c||s===c.type?[s]:[s,c.type]).map(h=>Dt(o,h).closeBrace).sort((h,_)=>_-h);for(let h of v)o=o.slice(0,h)+`${g.join(`
|
|
64
64
|
`)}
|
|
65
|
-
`+o.slice(h);if(l=
|
|
65
|
+
`+o.slice(h);if(l=He(o,i,"fragment"),m.length){let h=l.parameters,_=O(h).trimEnd();if(_.trim()&&!_.endsWith(",")){let L=_.length;h=`${h.slice(0,L)},${h.slice(L)}`}o=o.slice(0,l.openParenthesis+1)+h+`
|
|
66
66
|
`+m.join(`,
|
|
67
67
|
`)+`
|
|
68
68
|
`+o.slice(l.closeParenthesis)}return{source:o,declarations:b.join(`
|
|
69
|
-
`),vertexInitialization:
|
|
69
|
+
`),vertexInitialization:y.join(`
|
|
70
70
|
`),fragmentInitialization:S.join(`
|
|
71
|
-
`)}}function
|
|
71
|
+
`)}}function He(e,t,i){let r=new RegExp(`\\bfn\\s+${ue(t)}\\s*\\(`,"g").exec(e);if(!r)throw new Error(`ShaderPlugin interStageVariables require WGSL ${i} entry point "${t}"`);let o=e.indexOf("(",r.index),a=je(e,o,"(",")"),s=e.indexOf("{",a),l=je(e,s,"{","}");if(a<0||s<0||l<0)throw new Error(`Unable to parse WGSL ${i} entry point "${t}"`);return{openParenthesis:o,closeParenthesis:a,openBrace:s,closeBrace:l,parameters:e.slice(o+1,a)}}function Ma(e,t){let i=e.slice(t.closeParenthesis+1,t.openBrace),n=/->\s*([A-Za-z_][\w]*)\s*$/.exec(i.trim());if(!n||Ft(e,n[1])===null)throw new Error("ShaderPlugin interStageVariables require the WGSL vertex entry point to return a named struct");return n[1]}function Aa(e,t){let i=[];for(let n of Na(O(t.parameters),",")){let r=/(?:@[A-Za-z_][\w]*(?:\([^)]*\))?\s*)*([A-Za-z_][\w]*)\s*:\s*([A-Za-z_][\w]*)\s*$/.exec(n.trim());r&&Ft(e,r[2])&&i.push({name:r[1],type:r[2]})}if(i.length>1)throw new Error(`ShaderPlugin interStageVariables require exactly one named WGSL fragment input struct; found ${i.length}`);return i[0]||null}function Dt(e,t){let i=Ft(e,t);if(!i)throw new Error(`Unable to find WGSL stage I/O struct "${t}"`);return i}function Ft(e,t){let n=new RegExp(`\\bstruct\\s+${ue(t)}\\s*\\{`,"g").exec(e);if(!n)return null;let r=e.indexOf("{",n.index),o=je(e,r,"{","}");return o<0?null:{openBrace:r,closeBrace:o,body:e.slice(r+1,o)}}function Ra(e,t,i,n){let r=new RegExp(`\\b${ue(t)}\\s*\\(`,"g"),o=r.exec(e);for(;o;){if(o.index<i||o.index>n)throw new Error(`ShaderPlugin varying output struct "${t}" is constructed outside the selected vertex entry point`);o=r.exec(e)}}function Ta(e,t,i,n){let r=new RegExp(`\\b${ue(t)}\\s*\\(`,"g"),o=[],a=r.exec(e);for(;a;){if(a.index>i.openBrace&&a.index<i.closeBrace){let s=e.indexOf("(",a.index),l=je(e,s,"(",")");if(l<0||l>i.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+n.join(", ")+e.slice(s.closeParenthesis)}return e}function Ea(e,t,i){let n=Pa(e,t.openBrace+1,t.closeBrace);for(let r=n.length-1;r>=0;r--){let o=n[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=i.map(f=>`${s}.${f} = ${f};`).join(`
|
|
72
72
|
`),c=`{
|
|
73
73
|
var ${s} = ${a};
|
|
74
74
|
${l}
|
|
75
75
|
return ${s};
|
|
76
|
-
}`;e=e.slice(0,o.start)+c+e.slice(o.semicolon+1)}return e}function
|
|
77
|
-
`,n+2);return r<0||r>i?i:r+1}if(e[n]==="/"&&e[n+1]==="*"){let r=1;for(n+=2;n<i&&r>0;)e[n]==="/"&&e[n+1]==="*"?(r++,n+=2):e[n]==="*"&&e[n+1]==="/"?(r--,n+=2):n++}return n}function
|
|
78
|
-
`&&(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===i&&r++,l===n&&--r===0)return s}return-1}function
|
|
79
|
-
`,o.header&&(n+=` ${o.header}`),t[r]){let c=t[r];c.sort((f,
|
|
76
|
+
}`;e=e.slice(0,o.start)+c+e.slice(o.semicolon+1)}return e}function Pa(e,t,i){let n=[],r=t;for(;r<i;)if(r=Bt(e,r,i),e.slice(r,r+6)==="return"&&!/[A-Za-z0-9_]/.test(e[r+6]||"")){let o=r+6,a=Da(e,o,i);if(a<0)throw new Error("Unable to parse WGSL return statement in selected vertex entry point");n.push({start:r,expressionStart:o,semicolon:a}),r=a+1}else r++;return n}function Da(e,t,i){let n=0,r=0;for(let o=t;o<i;o++){let a=Bt(e,o,i);if(a!==o){o=a-1;continue}let s=e[o];if(s==="("&&n++,s===")"&&n--,s==="["&&r++,s==="]"&&r--,s===";"&&n===0&&r===0)return o}return-1}function Bt(e,t,i){let n=t;if(e[n]==="/"&&e[n+1]==="/"){let r=e.indexOf(`
|
|
77
|
+
`,n+2);return r<0||r>i?i:r+1}if(e[n]==="/"&&e[n+1]==="*"){let r=1;for(n+=2;n<i&&r>0;)e[n]==="/"&&e[n+1]==="*"?(r++,n+=2):e[n]==="*"&&e[n+1]==="/"?(r--,n+=2):n++}return n}function Na(e,t){let i=[],n=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&&(i.push(e.slice(n,a)),n=a+1)}return i.push(e.slice(n)),i}function Nt(e){let t=[],i=/@location\s*\(\s*(\d+)\s*\)/g,n=i.exec(e);for(;n;)t.push(Number(n[1])),n=i.exec(e);return t}function We(e){let t=[],i=/(?:^|,)\s*(?:@[A-Za-z_][\w]*(?:\([^)]*\))?\s*)*([A-Za-z_][\w]*)\s*:/gm,n=i.exec(e);for(;n;)t.push(n[1]),n=i.exec(e);return t}function Fa(e,t){let i=new RegExp(`\\b(?:var(?:<[^>]+>)?|let|const)\\s+${ue(t)}\\b`,"g"),n=i.exec(e);for(;n;){if(za(e,n.index)===0)return!0;n=i.exec(e)}return!1}function Ba(e){let t=0;for(;e.has(t);)t++;return t}function Oa(e){let{primitiveType:t,components:i}=j.getAttributeShaderTypeInfo(e),n=t==="u32"?"0u":t==="i32"?"0":"0.0";return i===1?n:`${Ve(e)}(${n})`}function Ua(e){let{primitiveType:t,components:i}=j.getAttributeShaderTypeInfo(e),n=`${t}(0)`;return i===1?n:`${e}(${n})`}function ka(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+${ue(t)}\\s*(?:\\[|;)`).test(e))throw new Error(`ShaderPlugin varying "${t}" conflicts with existing GLSL stage I/O`)}function je(e,t,i,n){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===`
|
|
78
|
+
`&&(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===i&&r++,l===n&&--r===0)return s}return-1}function za(e,t){let i=0;for(let n=0;n<t;n++){let r=Bt(e,n,t);if(r!==n){n=r-1;continue}e[n]==="{"&&i++,e[n]==="}"&&i--}return i}function ue(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function qe(e,t,i="glsl"){let n="";for(let r in e){let o=e[r],a=o.returnType||"void",s=i==="wgsl"?"fn":a,l=i==="wgsl"&&a!=="void"?` -> ${a}`:"";if(n+=`${s} ${o.signature}${l} {
|
|
79
|
+
`,o.header&&(n+=` ${o.header}`),t[r]){let c=t[r];c.sort((f,d)=>f.order-d.order);for(let f of c)n+=` ${f.injection}
|
|
80
80
|
`}o.footer&&(n+=` ${o.footer}`),n+=`}
|
|
81
|
-
`}return n}function
|
|
82
|
-
`));return S+=
|
|
81
|
+
`}return n}function be(e,t=[],i="glsl"){let n={vertex:{},fragment:{}};for(let r of e){let o=r[i];if(o){let a=r.stage==="vertex"?"vs":"fs";n[r.stage][`${a}:${r.name}`]={...o,signature:`${r.name}(${o.parameters})`}}}for(let r of t){let o=be([r],[],i);for(let a of["vertex","fragment"])for(let[s,l]of Object.entries(o[a])){let c=n[a][s];if(c&&(c.signature!==l.signature||(c.returnType||"void")!==(l.returnType||"void")))throw new Error(`Conflicting ShaderPlugin injection target ${s}`);n[a][s]=c||l}}return n}function Va(e,t){return!!(t.startsWith("vs:")?e.vertex:e.fragment)[t]}function $e(e,t,i){let n=i==="vertex"?"vs:":i==="fragment"?"fs:":null;for(let r in t)if(!(n&&!r.startsWith(n))&&!Va(e,r)){let o=[...new Set(t[r].map(a=>a.pluginName).filter(Boolean))];throw new Error(`Unknown shader injection target ${r}${o.length?` (plugins: ${o.join(", ")})`:""}`)}}var xe=100;function rn(e){let t=V(e.modules||[]),{source:i,bindingAssignments:n}=Ga(e.platformInfo,{...e,source:e.source,stage:"vertex",modules:t});return{source:i,getUniforms:ze(t),bindingAssignments:n}}function Ga(e,t){let{source:i,stage:n,modules:r,defines:o={},injectionTargets:a=[],inject:s={},pluginInjections:l={},pluginVertexInputs:c={},pluginInterStageVariables:f={},vertexEntryPoint:d="vertexMain",fragmentEntryPoint:u="fragmentMain",log:p}=t;E(typeof i=="string","shader source must be a string");let g=q(i,{defines:o}),m=Ji(g,d,c),b=tn(m.source,d,u,f),y=b.source,S="",x=be(a,t.pluginInjectionTargets,"wgsl"),v={},h={},_={};fe(l,v,h,_);let L=Array.isArray(s)?le(s,"wgsl"):{};fe(L,v,h,_);let I=Array.isArray(s)?{}:s;for(let M in I){let W=typeof I[M]=="string"?{injection:I[M],order:0}:I[M],oe=/^(v|f)s:(#)?([\w-]+)$/.exec(M);if(oe){let _o=oe[2],bo=oe[3];_o?bo==="decl"?h[M]=[...h[M]||[],W]:_[M]=[..._[M]||[],W]:v[M]=[...v[M]||[],W]}else _[M]=[..._[M]||[],W]}Ha(m.declarations,m.initialization,h,_),Wa(b,h,_),$e(x,v);let A=r.map(M=>({module:M,source:q(J(M,"wgsl",p),{defines:o})})),R=Ka(y),D=$a(R.source),C=Ja(A,t._bindingRegistry,D),T=[],w=A.map(({module:M,source:W})=>{let oe=Ya(W,M,{usedBindingsByGroup:D,bindingRegistry:t._bindingRegistry,reservedBindingKeysByGroup:C});return T.push(...oe.bindingAssignments),{module:M,source:oe.source}});for(let{module:M,source:W}of w)p&&se(M,y,p),S+=W;S+=_e,S=ce(S,n,ja(h),!1,"wgsl",{vertex:d,fragment:u});let z=ke(x,[S,R.source,...Object.values(v).flat().map(M=>M.injection),...Object.values(_).flat().map(M=>M.injection)].join(`
|
|
82
|
+
`));return S+=qa(x,v,z),S+=is(T),S+=R.source,S=ce(S,n,_,!1,"wgsl",{vertex:d,fragment:u}),S=Ki(S,x,z),ts(S),{source:S,bindingAssignments:T}}function Ha(e,t,i,n){e&&(i["vs:#decl"]=i["vs:#decl"]||[],i["vs:#decl"].push({injection:e,order:Number.MIN_SAFE_INTEGER})),t&&(n["vs:#main-start"]=n["vs:#main-start"]||[],n["vs:#main-start"].push({injection:t,order:Number.MIN_SAFE_INTEGER}))}function Wa(e,t,i){e.declarations&&(t["vs:#decl"]=t["vs:#decl"]||[],t["vs:#decl"].push({injection:e.declarations,order:Number.MIN_SAFE_INTEGER})),e.vertexInitialization&&(i["vs:#main-start"]=i["vs:#main-start"]||[],i["vs:#main-start"].push({injection:e.vertexInitialization,order:Number.MIN_SAFE_INTEGER})),e.fragmentInitialization&&(i["fs:#main-start"]=i["fs:#main-start"]||[],i["fs:#main-start"].push({injection:e.fragmentInitialization,order:Number.MIN_SAFE_INTEGER}))}function ja(e){let t=[...e["vs:#decl"]||[],...e["fs:#decl"]||[]];return t.length?{"vs:#decl":t}:{}}function qa(e,t,i=ke(e)){return["vertex","fragment"].map(n=>{let r=Object.fromEntries(Object.entries(e[n]).map(([o,a])=>{let s=o.slice(3),l=i.get(s)?.[n]||s;return[o,{...a,signature:l+a.signature.slice(s.length)}]}));return qe(r,t,"wgsl")}).join("")}function $a(e){let t=new Map;for(let i of X(e,hi)){let n=Number(i.bindingToken),r=Number(i.groupToken);Ut(r,n,i.name),de(t,r,n,`application binding "${i.name}"`)}return t}function Ka(e){let t=X(e,Me),i=new Map;for(let o of t){if(o.bindingToken==="auto")continue;let a=Number(o.bindingToken),s=Number(o.groupToken);Ut(s,a,o.name),de(i,s,a,`application binding "${o.name}"`)}let n={sawSupportedBindingDeclaration:t.length>0},r=St(e,Me,o=>Za(o,i,n));if(yt(e)&&!n.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 Ya(e,t,i){let n=[],o={sawSupportedBindingDeclaration:X(e,ae).length>0,nextHintedBindingLocation:typeof t.firstBindingSlot=="number"?t.firstBindingSlot:null},a=St(e,ae,s=>Xa(s,{module:t,context:i,bindingAssignments:n,relocationState:o}));if(yt(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:n}}function Xa(e,t){let{module:i,context:n,bindingAssignments:r,relocationState:o}=t,{match:a,bindingToken:s,groupToken:l,name:c}=e,f=Number(l);if(s==="auto"){let p=Ke(f,i.name,c),g=n.bindingRegistry?.get(p),m=g!==void 0?g:Qa(f,n.usedBindingsByGroup,i.name,o.nextHintedBindingLocation??void 0,n.bindingRegistry);return Ot(i.name,f,m,c),g!==void 0&&nn(n.reservedBindingKeysByGroup,f,m,p)?(r.push({moduleName:i.name,name:c,group:f,location:m}),a.replace(/@binding\(\s*auto\s*\)/,`@binding(${m})`)):(de(n.usedBindingsByGroup,f,m,`module "${i.name}" binding "${c}"`),n.bindingRegistry?.set(p,m),r.push({moduleName:i.name,name:c,group:f,location:m}),o.nextHintedBindingLocation!==null&&g===void 0&&(o.nextHintedBindingLocation=m+1),a.replace(/@binding\(\s*auto\s*\)/,`@binding(${m})`))}let d=Number(s);Ot(i.name,f,d,c);let u=Ke(f,i.name,c);return nn(n.reservedBindingKeysByGroup,f,d,u)||de(n.usedBindingsByGroup,f,d,`module "${i.name}" binding "${c}"`),r.push({moduleName:i.name,name:c,group:f,location:d}),a}function Za(e,t,i){let{match:n,bindingToken:r,groupToken:o,name:a}=e,s=Number(o);if(r==="auto"){let l=es(s,t);return Ut(s,l,a),de(t,s,l,`application binding "${a}"`),n.replace(/@binding\(\s*auto\s*\)/,`@binding(${l})`)}return i.sawSupportedBindingDeclaration=!0,n}function Ja(e,t,i){let n=new Map,r=[];function o(a,s,l,c){de(i,a,s,c);let f=n.get(a)||new Map;f.set(s,l),n.set(a,f)}for(let{module:a,source:s}of e)for(let l of X(s,ae)){let c=Number(l.groupToken);if(l.bindingToken==="auto"){r.push({module:a,name:l.name,group:c});continue}let f=Number(l.bindingToken);Ot(a.name,c,f,l.name),o(c,f,Ke(c,a.name,l.name),`module "${a.name}" binding "${l.name}"`)}for(let{module:a,name:s,group:l}of r){let c=Ke(l,a.name,s),f=t?.get(c);f!==void 0&&o(l,f,c,`registered module binding "${c}"`)}return n}function nn(e,t,i,n){let r=e.get(t);if(!r)return!1;let o=r.get(i);if(!o)return!1;if(o!==n)throw new Error(`Registered module binding "${n}" collided with "${o}": group ${t}, binding ${i}.`);return r.delete(i),!0}function Ut(e,t,i){if(e===0&&t>=xe)throw new Error(`Application binding "${i}" in group 0 uses reserved binding ${t}. Application-owned explicit group-0 bindings must stay below ${xe}.`)}function Ot(e,t,i,n){if(t===0&&i<xe)throw new Error(`Module "${e}" binding "${n}" in group 0 uses reserved application binding ${i}. Module-owned explicit group-0 bindings must be ${xe} or higher.`)}function de(e,t,i,n){let r=e.get(t)||new Set;if(r.has(i))throw new Error(`Duplicate WGSL binding assignment for ${n}: group ${t}, binding ${i}.`);r.add(i),e.set(t,r)}function Qa(e,t,i,n,r){let o=t.get(e)||new Set,a=new Set,s=`${e}:`,l=`${s}${i}:`;for(let[f,d]of r||[])f.startsWith(l)&&a.add(d);let c=n??(e===0?xe:o.size>0?Math.max(...o)+1:0);for(;o.has(c)||a.has(c);)c++;for(let[f,d]of r||[])d===c&&f.startsWith(s)&&r?.delete(f);return c}function es(e,t){let i=t.get(e)||new Set,n=0;for(;i.has(n);)n++;return n}function ts(e){let t=vi(e,ae);if(!t)return;let i=ns(e,t.index);throw i?new Error(`Unresolved @binding(auto) for module "${i}" binding "${t.name}" remained in assembled WGSL source.`):rs(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 "${os(t.match)}".`)}function is(e){if(e.length===0)return"";let t=`// ----- MODULE WGSL BINDING ASSIGNMENTS ---------------
|
|
83
83
|
`;for(let i of e)t+=`// ${i.moduleName}.${i.name} -> @group(${i.group}) @binding(${i.location})
|
|
84
84
|
`;return t+=`
|
|
85
|
-
`,t}function
|
|
85
|
+
`,t}function Ke(e,t,i){return`${e}:${t}:${i}`}function ns(e,t){let i=/^\/\/ ----- MODULE ([^\n]+) ---------------$/gm,n,r;for(r=i.exec(e);r&&r.index<=t;)n=r[1],r=i.exec(e);return n}function rs(e,t){let i=e.indexOf(_e);return i>=0?t>i:!0}function os(e){return e.replace(/\s+/g," ").trim()}function Ye(e,t){return{name:as(e,t),language:"glsl",version:ss(e)}}function as(e,t="unnamed"){let n=/#define[^\S\r\n]*SHADER_NAME[^\S\r\n]*([A-Za-z0-9_-]+)\s*/.exec(e);return n?n[1]:t}function ss(e){let t=100,i=e.match(/[^\s]+/g);if(i&&i.length>=2&&i[0]==="#version"){let n=parseInt(i[1],10);Number.isFinite(n)&&(t=n)}if(t!==100&&t!==300)throw new Error(`Invalid GLSL version ${t}`);return t}function on(e){switch(e?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
|
|
86
86
|
// Apple optimizes away the calculation necessary for emulated fp64
|
|
87
87
|
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
88
88
|
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
@@ -106,40 +106,40 @@ return ${s};
|
|
|
106
106
|
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
107
107
|
// If the GPU doesn't have full 32 bits precision, will causes overflow
|
|
108
108
|
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
|
|
109
|
-
`}}function
|
|
110
|
-
`],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],
|
|
111
|
-
`;function
|
|
109
|
+
`}}function sn(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=an(e,ls),e;case"fragment":return e=an(e,cs),e;default:throw new Error(t)}}var ln=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
|
|
110
|
+
`],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],ls=[...ln,[kt("attribute"),"in $1"],[kt("varying"),"out $1"]],cs=[...ln,[kt("varying"),"in $1"]];function an(e,t){for(let[i,n]of t)e=e.replace(i,n);return e}function kt(e){return new RegExp(`\\b${e}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}var fs=`precision highp float;
|
|
111
|
+
`;function Se(e){let{vs:t,fs:i}=e,n=V(e.modules||[]);return{vs:cn(e.platformInfo,{...e,source:t,stage:"vertex",modules:n}),fs:cn(e.platformInfo,{...e,source:i,stage:"fragment",modules:n}),getUniforms:ze(n)}}function cn(e,t){let{source:i,stage:n,language:r="glsl",modules:o,defines:a={},injectionTargets:s=[],inject:l={},pluginInjections:c={},pluginVertexInputs:f={},pluginInterStageVariables:d={},prologue:u=!0,log:p}=t;E(typeof i=="string","shader source must be a string");let g=r==="glsl"?Ye(i).version:-1,m=e.shaderLanguageVersion,b=g===100?"#version 100":"#version 300 es",S=i.split(`
|
|
112
112
|
`).slice(1).join(`
|
|
113
|
-
`),x={};o.forEach(
|
|
113
|
+
`),x={};o.forEach(C=>{Object.assign(x,C.defines)}),Object.assign(x,a);let v="";switch(r){case"wgsl":break;case"glsl":v=u?`${b}
|
|
114
114
|
|
|
115
115
|
// ----- PROLOGUE -------------------------
|
|
116
116
|
${`#define SHADER_TYPE_${n.toUpperCase()}`}
|
|
117
117
|
|
|
118
|
-
${
|
|
119
|
-
${n==="fragment"?
|
|
118
|
+
${on(e)}
|
|
119
|
+
${n==="fragment"?fs:""}
|
|
120
120
|
|
|
121
121
|
// ----- APPLICATION DEFINES -------------------------
|
|
122
122
|
|
|
123
|
-
${
|
|
123
|
+
${us(x)}
|
|
124
124
|
|
|
125
125
|
`:`${b}
|
|
126
|
-
`;break}let h=
|
|
127
|
-
`)}let
|
|
128
|
-
`),
|
|
129
|
-
`)}return t}var
|
|
126
|
+
`;break}let h=be(s,t.pluginInjectionTargets,"glsl"),_={},L={},I={};fe(c,_,L,I);let A=Array.isArray(l)?le(l,"glsl"):{};fe(A,_,L,I);let R=Array.isArray(l)?{}:l;for(let C in R){let T=typeof R[C]=="string"?{injection:R[C],order:0}:R[C],w=/^(v|f)s:(#)?([\w-]+)$/.exec(C);if(w){let z=w[2],M=w[3];z?M==="decl"?L[C]=[...L[C]||[],T]:I[C]=[...I[C]||[],T]:_[C]=[..._[C]||[],T]}else I[C]=[...I[C]||[],T]}if(n==="vertex"){let C=Zi(S,f);C&&(v+=`${C}
|
|
127
|
+
`)}let D=en(S,n,d);D.declarations&&(v+=`${D.declarations}
|
|
128
|
+
`),D.initialization&&(I["vs:#main-start"]=I["vs:#main-start"]||[],I["vs:#main-start"].push({injection:D.initialization,order:Number.MIN_SAFE_INTEGER}));for(let C of o){p&&se(C,S,p);let T=J(C,n,p);v+=T}return $e(h,_,n),v+="// ----- MAIN SHADER SOURCE -------------------------",v+=_e,v=ce(v,n,L),v+=qe(h[n],_),v+=S,v=ce(v,n,I),r==="glsl"&&g!==m&&(v=sn(v,n)),r==="glsl"&&Oe(v,n,p),v.trim()}function us(e={}){let t="";for(let i in e){let n=e[i];(n||Number.isFinite(n))&&(t+=`#define ${i.toUpperCase()} ${e[i]}
|
|
129
|
+
`)}return t}var H=class{_shaderTranspilers=new Map;_injectionTargets=[];_defaultModules=[];addShaderTranspiler(t){this._shaderTranspilers.set(t.sourceLanguage,t)}removeShaderTranspiler(t){this._shaderTranspilers.delete(t)}_transpileShader(t,i,n,r){let o=t.sourceLanguage||this.shaderLanguage;if(o===this.shaderLanguage)return E(!V(i).some(u=>u.sourceLanguage&&u.sourceLanguage!==this.shaderLanguage)),{code:n||"",modules:i};let a=this._shaderTranspilers.get(o);E(a);let s=V(i);E(!s.some(u=>u.sourceLanguage&&u.sourceLanguage!==o&&u.sourceLanguage!==this.shaderLanguage));let l=s.filter(u=>u.sourceLanguage===o).map(u=>u.source||"").join(`
|
|
130
130
|
`),c={vertex:t.vertexEntryPoint,fragment:t.fragmentEntryPoint,compute:t.computeEntryPoint},f=n==null?{code:""}:a.transpile({source:[l,n].filter(Boolean).join(`
|
|
131
|
-
`),target:this.shaderLanguage,stage:r,entryPoints:c,platformInfo:t.platformInfo}),
|
|
131
|
+
`),target:this.shaderLanguage,stage:r,entryPoints:c,platformInfo:t.platformInfo}),d=s.map(u=>({...u,dependencies:void 0,...u.sourceLanguage===o?{source:void 0,vs:void 0,fs:void 0}:{}}));return{...f,modules:d}}addDefaultModule(t){this._defaultModules.find(i=>i.name===(typeof t=="string"?t:t.name))||this._defaultModules.push(t)}removeDefaultModule(t){let i=typeof t=="string"?t:t.name;this._defaultModules=this._defaultModules.filter(n=>n.name!==i)}addShaderInjectionTarget(t){this._injectionTargets.push(t)}resetShaderInjectionTargets(){this._injectionTargets.length=0}_getModuleList(t=[]){let i=new Array(this._defaultModules.length+t.length),n={},r=0;for(let o=0,a=this._defaultModules.length;o<a;++o){let s=this._defaultModules[o],l=s.name;i[r++]=s,n[l]=!0}for(let o=0,a=t.length;o<a;++o){let s=t[o],l=s.name;n[l]||(i[r++]=s,n[l]=!0)}return i.length=r,Z(i),i}};var ye=class extends H{shaderLanguage="glsl";assembleGLSLShaderPair(t){let i=this._getModuleList(t.modules),n=[...this._injectionTargets,...t.injectionTargets||[]],r=this._transpileShader(t,i,t.vs,"vertex"),o=this._transpileShader(t,i,t.fs,"fragment");return{...Se({...t,vs:r.code,fs:t.fs==null?void 0:o.code,modules:r.modules,injectionTargets:n}),modules:i}}};var Ce=class e extends H{shaderLanguage="wgsl";_wgslBindingRegistry=new Map;assembleWGSLShader(t){let i=this._getModuleList(t.modules),n=[...this._injectionTargets,...t.injectionTargets||[]],r=this._transpileShader(t,i,t.source,t.shaderStage??(t.computeEntryPoint?"compute":void 0)),o={vertex:r.entryPoints?.vertex??t.vertexEntryPoint,fragment:r.entryPoints?.fragment??t.fragmentEntryPoint,compute:r.entryPoints?.compute??t.computeEntryPoint},a=e.getShaderPreprocessorDefines(t,i),s=t.platformInfo.shaderLanguage==="wgsl"&&r.code?q(r.code,{defines:a}):r.code,{source:l,getUniforms:c,bindingAssignments:f}=rn({...t,source:s,vertexEntryPoint:o.vertex,fragmentEntryPoint:o.fragment,defines:a,_bindingRegistry:this._wgslBindingRegistry,modules:r.modules,injectionTargets:n}),d=t.platformInfo.shaderLanguage==="wgsl"?q(l,{defines:a}):l;return{source:d,entryPoints:o,getUniforms:c,modules:i,bindingAssignments:f,bindingTable:$i(d,f),shaderLayout:Re(d,{vertexEntryPoint:o.vertex,scanVertexAttributes:t.scanVertexAttributes})}}static getShaderPreprocessorDefines(t,i){return{...e.getPlatformPreprocessorDefines(t.platformInfo),...i.reduce((n,r)=>(Object.assign(n,r.defines),n),{}),...t.defines}}static getPlatformPreprocessorDefines(t){let i=t.limits||{};return{LUMA_SUPPORTS_VERTEX_STORAGE_BUFFERS:t.type==="webgpu"&&(i.maxStorageBuffersInVertexStage||0)>0,LUMA_FP32_TAN_PRECISION_WORKAROUND:t.type==="webgpu"&&t.gpu.toLowerCase()!=="nvidia"&&t.gpu.toLowerCase()!=="amd",LUMA_FP64_INTEGER_ARITHMETIC:t.type==="webgpu"&&t.gpu.toLowerCase()==="apple"}}};var ds=`out vec4 transform_output;
|
|
132
132
|
void main() {
|
|
133
133
|
transform_output = vec4(0);
|
|
134
|
-
}`,
|
|
135
|
-
${
|
|
134
|
+
}`,ps=`#version 300 es
|
|
135
|
+
${ds}`;function fn(e,t){t=Array.isArray(t)?t:[t];let i=e.replace(/^\s+/,"").split(/\s+/),[n,r,o]=i;if(!t.includes(n)||!r||!o)return null;let a=o.split(";")[0];return{qualifier:n,type:r,name:a}}function un(e){let{input:t,inputChannels:i,output:n}=e||{};if(!t)return ps;if(!i)throw new Error("inputChannels");let r=gs(i),o=zt(t,i);return`#version 300 es
|
|
136
136
|
in ${r} ${t};
|
|
137
137
|
out vec4 ${n};
|
|
138
138
|
void main() {
|
|
139
139
|
${n} = ${o};
|
|
140
|
-
}`}function
|
|
141
|
-
`)}function
|
|
142
|
-
`)}function fn(e,t){switch(t.shaderLanguage){case"glsl":return ln(e,t);case"wgsl":return cn(e,t)}}var Hc=1/Math.PI*180,Wc=1/180*Math.PI,Ya={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Ya}};var D=globalThis.mathgl.config;function kt(e,{precision:t=D.precision}={}){return e=Za(e),`${parseFloat(e.toPrecision(t))}`}function pe(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Gt(e,t,i){return Ja(e,n=>Math.max(t,Math.min(i,n)))}function Ye(e,t,i){let n=D.EPSILON;i&&(D.EPSILON=i);try{if(e===t)return!0;if(pe(e)&&pe(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;++r)if(!Ye(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)<=D.EPSILON*Math.max(1,Math.abs(e),Math.abs(t)):!1}finally{D.EPSILON=n}}function Za(e){return Math.round(e/D.EPSILON)*D.EPSILON}function Xa(e){return e.clone?e.clone():new Array(e.length)}function Ja(e,t,i){if(pe(e)){let n=e;i=i||Xa(n);for(let r=0;r<i.length&&r<n.length;++r){let o=typeof e=="number"?e:e[r];i[r]=t(o,r,i)}return i}return t(e)}var Ze=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,i=0){for(let n=0;n<this.ELEMENTS;++n)this[n]=t[n+i];return this.check()}toArray(t=[],i=0){for(let n=0;n<this.ELEMENTS;++n)t[i+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:pe(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toString(){return this.formatString(D)}formatString(t){let i="";for(let n=0;n<this.ELEMENTS;++n)i+=(n>0?", ":"")+kt(this[n],t);return`${t.printTypes?this.constructor.name:""}[${i}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let i=0;i<this.ELEMENTS;++i)if(!Ye(this[i],t[i]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let i=0;i<this.ELEMENTS;++i)if(this[i]!==t[i])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,i,n){if(n===void 0)return this.lerp(this,t,i);for(let r=0;r<this.ELEMENTS;++r){let o=t[r],a=typeof i=="number"?i:i[r];this[r]=o+n*(a-o)}return this.check()}min(t){for(let i=0;i<this.ELEMENTS;++i)this[i]=Math.min(t[i],this[i]);return this.check()}max(t){for(let i=0;i<this.ELEMENTS;++i)this[i]=Math.max(t[i],this[i]);return this.check()}clamp(t,i){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t[n]),i[n]);return this.check()}add(...t){for(let i of t)for(let n=0;n<this.ELEMENTS;++n)this[n]+=i[n];return this.check()}subtract(...t){for(let i of t)for(let n=0;n<this.ELEMENTS;++n)this[n]-=i[n];return this.check()}scale(t){if(typeof t=="number")for(let i=0;i<this.ELEMENTS;++i)this[i]*=t;else for(let i=0;i<this.ELEMENTS&&i<t.length;++i)this[i]*=t[i];return this.check()}multiplyByScalar(t){for(let i=0;i<this.ELEMENTS;++i)this[i]*=t;return this.check()}check(){if(D.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 i=0;i<this.ELEMENTS;++i)t=t&&Number.isFinite(this[i]);return t}};function Qa(e,t){if(e.length!==t)return!1;for(let i=0;i<e.length;++i)if(!Number.isFinite(e[i]))return!1;return!0}function un(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function Xe(e,t,i=""){if(D.debug&&!Qa(e,t))throw new Error(`math.gl: ${i} some fields set to invalid numbers'`);return e}var Je=class extends Ze{toString(){let t="[";if(D.printRowMajor){t+="row-major:";for(let i=0;i<this.RANK;++i)for(let n=0;n<this.RANK;++n)t+=` ${this[n*this.RANK+i]}`}else{t+="column-major:";for(let i=0;i<this.ELEMENTS;++i)t+=` ${this[i]}`}return t+="]",t}getElementIndex(t,i){return i*this.RANK+t}getElement(t,i){return this[i*this.RANK+t]}setElement(t,i,n){return this[i*this.RANK+t]=un(n),this}getColumn(t,i=new Array(this.RANK).fill(-0)){let n=t*this.RANK;for(let r=0;r<this.RANK;++r)i[r]=this[n+r];return i}setColumn(t,i){let n=t*this.RANK;for(let r=0;r<this.RANK;++r)this[n+r]=i[r];return this}};function pn(e,t,i){let n=t[0],r=t[1];return e[0]=i[0]*n+i[4]*r+i[12],e[1]=i[1]*n+i[5]*r+i[13],e}function dn(e,t,i){let n=t[0],r=t[1],o=i[3]*n+i[7]*r||1;return e[0]=(i[0]*n+i[4]*r)/o,e[1]=(i[1]*n+i[5]*r)/o,e}function gn(e,t,i){let n=t[0],r=t[1],o=t[2],a=i[3]*n+i[7]*r+i[11]*o||1;return e[0]=(i[0]*n+i[4]*r+i[8]*o)/a,e[1]=(i[1]*n+i[5]*r+i[9]*o)/a,e[2]=(i[2]*n+i[6]*r+i[10]*o)/a,e}function mn(e,t,i){let n=t[0],r=t[1],o=t[2],a=i[3]*n+i[7]*r+i[11]*o+i[15];return a=a||1,e[0]=(i[0]*n+i[4]*r+i[8]*o+i[12])/a,e[1]=(i[1]*n+i[5]*r+i[9]*o+i[13])/a,e[2]=(i[2]*n+i[6]*r+i[10]*o+i[14])/a,e}function es(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 hn(e,t){if(e===t){let i=t[1],n=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]=i,e[6]=t[9],e[7]=t[13],e[8]=n,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 _n(e,t){let i=t[0],n=t[1],r=t[2],o=t[3],a=t[4],s=t[5],l=t[6],c=t[7],f=t[8],p=t[9],u=t[10],d=t[11],g=t[12],m=t[13],b=t[14],I=t[15],S=i*s-n*a,x=i*l-r*a,_=i*c-o*a,h=n*l-r*s,v=n*c-o*s,A=r*c-o*l,C=f*m-p*g,R=f*b-u*g,E=f*I-d*g,N=p*b-u*m,y=p*I-d*m,w=u*I-d*b,L=S*w-x*y+_*N+h*E-v*R+A*C;return L?(L=1/L,e[0]=(s*w-l*y+c*N)*L,e[1]=(r*y-n*w-o*N)*L,e[2]=(m*A-b*v+I*h)*L,e[3]=(u*v-p*A-d*h)*L,e[4]=(l*E-a*w-c*R)*L,e[5]=(i*w-r*E+o*R)*L,e[6]=(b*_-g*A-I*x)*L,e[7]=(f*A-u*_+d*x)*L,e[8]=(a*y-s*E+c*C)*L,e[9]=(n*E-i*y-o*C)*L,e[10]=(g*v-m*_+I*S)*L,e[11]=(p*_-f*v-d*S)*L,e[12]=(s*R-a*N-l*C)*L,e[13]=(i*N-n*R+r*C)*L,e[14]=(m*x-g*h-b*S)*L,e[15]=(f*h-p*x+u*S)*L,e):null}function vn(e){let t=e[0],i=e[1],n=e[2],r=e[3],o=e[4],a=e[5],s=e[6],l=e[7],c=e[8],f=e[9],p=e[10],u=e[11],d=e[12],g=e[13],m=e[14],b=e[15],I=t*a-i*o,S=t*s-n*o,x=i*s-n*a,_=c*g-f*d,h=c*m-p*d,v=f*m-p*g,A=t*v-i*h+n*_,C=o*v-a*h+s*_,R=c*x-f*S+p*I,E=d*x-g*S+m*I;return l*A-r*C+b*R-u*E}function Vt(e,t,i){let n=t[0],r=t[1],o=t[2],a=t[3],s=t[4],l=t[5],c=t[6],f=t[7],p=t[8],u=t[9],d=t[10],g=t[11],m=t[12],b=t[13],I=t[14],S=t[15],x=i[0],_=i[1],h=i[2],v=i[3];return e[0]=x*n+_*s+h*p+v*m,e[1]=x*r+_*l+h*u+v*b,e[2]=x*o+_*c+h*d+v*I,e[3]=x*a+_*f+h*g+v*S,x=i[4],_=i[5],h=i[6],v=i[7],e[4]=x*n+_*s+h*p+v*m,e[5]=x*r+_*l+h*u+v*b,e[6]=x*o+_*c+h*d+v*I,e[7]=x*a+_*f+h*g+v*S,x=i[8],_=i[9],h=i[10],v=i[11],e[8]=x*n+_*s+h*p+v*m,e[9]=x*r+_*l+h*u+v*b,e[10]=x*o+_*c+h*d+v*I,e[11]=x*a+_*f+h*g+v*S,x=i[12],_=i[13],h=i[14],v=i[15],e[12]=x*n+_*s+h*p+v*m,e[13]=x*r+_*l+h*u+v*b,e[14]=x*o+_*c+h*d+v*I,e[15]=x*a+_*f+h*g+v*S,e}function bn(e,t,i){let n=i[0],r=i[1],o=i[2],a,s,l,c,f,p,u,d,g,m,b,I;return t===e?(e[12]=t[0]*n+t[4]*r+t[8]*o+t[12],e[13]=t[1]*n+t[5]*r+t[9]*o+t[13],e[14]=t[2]*n+t[6]*r+t[10]*o+t[14],e[15]=t[3]*n+t[7]*r+t[11]*o+t[15]):(a=t[0],s=t[1],l=t[2],c=t[3],f=t[4],p=t[5],u=t[6],d=t[7],g=t[8],m=t[9],b=t[10],I=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]=d,e[8]=g,e[9]=m,e[10]=b,e[11]=I,e[12]=a*n+f*r+g*o+t[12],e[13]=s*n+p*r+m*o+t[13],e[14]=l*n+u*r+b*o+t[14],e[15]=c*n+d*r+I*o+t[15]),e}function xn(e,t,i){let n=i[0],r=i[1],o=i[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]*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 Sn(e,t,i,n){let r=n[0],o=n[1],a=n[2],s=Math.sqrt(r*r+o*o+a*a),l,c,f,p,u,d,g,m,b,I,S,x,_,h,v,A,C,R,E,N,y,w,L,k;return s<1e-6?null:(s=1/s,r*=s,o*=s,a*=s,c=Math.sin(i),l=Math.cos(i),f=1-l,p=t[0],u=t[1],d=t[2],g=t[3],m=t[4],b=t[5],I=t[6],S=t[7],x=t[8],_=t[9],h=t[10],v=t[11],A=r*r*f+l,C=o*r*f+a*c,R=a*r*f-o*c,E=r*o*f-a*c,N=o*o*f+l,y=a*o*f+r*c,w=r*a*f+o*c,L=o*a*f-r*c,k=a*a*f+l,e[0]=p*A+m*C+x*R,e[1]=u*A+b*C+_*R,e[2]=d*A+I*C+h*R,e[3]=g*A+S*C+v*R,e[4]=p*E+m*N+x*y,e[5]=u*E+b*N+_*y,e[6]=d*E+I*N+h*y,e[7]=g*E+S*N+v*y,e[8]=p*w+m*L+x*k,e[9]=u*w+b*L+_*k,e[10]=d*w+I*L+h*k,e[11]=g*w+S*L+v*k,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function In(e,t,i){let n=Math.sin(i),r=Math.cos(i),o=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]=o*r+c*n,e[5]=a*r+f*n,e[6]=s*r+p*n,e[7]=l*r+u*n,e[8]=c*r-o*n,e[9]=f*r-a*n,e[10]=p*r-s*n,e[11]=u*r-l*n,e}function yn(e,t,i){let n=Math.sin(i),r=Math.cos(i),o=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]=o*r-c*n,e[1]=a*r-f*n,e[2]=s*r-p*n,e[3]=l*r-u*n,e[8]=o*n+c*r,e[9]=a*n+f*r,e[10]=s*n+p*r,e[11]=l*n+u*r,e}function Cn(e,t,i){let n=Math.sin(i),r=Math.cos(i),o=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]=o*r+c*n,e[1]=a*r+f*n,e[2]=s*r+p*n,e[3]=l*r+u*n,e[4]=c*r-o*n,e[5]=f*r-a*n,e[6]=p*r-s*n,e[7]=u*r-l*n,e}function Ln(e,t){let i=t[0],n=t[1],r=t[2],o=t[3],a=i+i,s=n+n,l=r+r,c=i*a,f=n*a,p=n*s,u=r*a,d=r*s,g=r*l,m=o*a,b=o*s,I=o*l;return e[0]=1-p-g,e[1]=f+I,e[2]=u-b,e[3]=0,e[4]=f-I,e[5]=1-c-g,e[6]=d+m,e[7]=0,e[8]=u+b,e[9]=d-m,e[10]=1-c-p,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function An(e,t,i,n,r,o,a){let s=1/(i-t),l=1/(r-n),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]=(i+t)*s,e[9]=(r+n)*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 ts(e,t,i,n,r){let o=1/Math.tan(t/2);if(e[0]=o/i,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/(n-r);e[10]=(r+n)*a,e[14]=2*r*n*a}else e[10]=-1,e[14]=-2*n;return e}var Mn=ts;function is(e,t,i,n,r,o,a){let s=1/(t-i),l=1/(n-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+i)*s,e[13]=(r+n)*l,e[14]=(a+o)*c,e[15]=1,e}var Rn=is;function En(e,t,i,n){let r,o,a,s,l,c,f,p,u,d,g=t[0],m=t[1],b=t[2],I=n[0],S=n[1],x=n[2],_=i[0],h=i[1],v=i[2];return Math.abs(g-_)<1e-6&&Math.abs(m-h)<1e-6&&Math.abs(b-v)<1e-6?es(e):(p=g-_,u=m-h,d=b-v,r=1/Math.sqrt(p*p+u*u+d*d),p*=r,u*=r,d*=r,o=S*d-x*u,a=x*p-I*d,s=I*u-S*p,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=u*s-d*a,c=d*o-p*s,f=p*a-u*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]=p,e[3]=0,e[4]=a,e[5]=c,e[6]=u,e[7]=0,e[8]=s,e[9]=f,e[10]=d,e[11]=0,e[12]=-(o*g+a*m+s*b),e[13]=-(l*g+c*m+f*b),e[14]=-(p*g+u*m+d*b),e[15]=1,e)}function wn(e,t,i){let n=t[0],r=t[1],o=t[2],a=t[3];return e[0]=i[0]*n+i[4]*r+i[8]*o+i[12]*a,e[1]=i[1]*n+i[5]*r+i[9]*o+i[13]*a,e[2]=i[2]*n+i[6]*r+i[10]*o+i[14]*a,e[3]=i[3]*n+i[7]*r+i[11]*o+i[15]*a,e}var qt;(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"})(qt||(qt={}));var ns=45*Math.PI/180,rs=1,Ht=.1,Wt=500,os=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),z=class extends Je{static get IDENTITY(){return ss()}static get ZERO(){return as()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return qt}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,i,n,r,o,a,s,l,c,f,p,u,d,g,m,b){return this[0]=t,this[1]=i,this[2]=n,this[3]=r,this[4]=o,this[5]=a,this[6]=s,this[7]=l,this[8]=c,this[9]=f,this[10]=p,this[11]=u,this[12]=d,this[13]=g,this[14]=m,this[15]=b,this.check()}setRowMajor(t,i,n,r,o,a,s,l,c,f,p,u,d,g,m,b){return this[0]=t,this[1]=o,this[2]=c,this[3]=d,this[4]=i,this[5]=a,this[6]=f,this[7]=g,this[8]=n,this[9]=s,this[10]=p,this[11]=m,this[12]=r,this[13]=l,this[14]=u,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(os)}fromObject(t){return this.check()}fromQuaternion(t){return Ln(this,t),this.check()}fromMatrix3(t){return this.set(t[0],t[1],t[2],0,t[3],t[4],t[5],0,t[6],t[7],t[8],0,0,0,0,1)}frustum(t){let{left:i,right:n,bottom:r,top:o,near:a=Ht,far:s=Wt}=t;return s===1/0?ls(this,i,n,r,o,a):An(this,i,n,r,o,a,s),this.check()}lookAt(t){let{eye:i,center:n=[0,0,0],up:r=[0,1,0]}=t;return En(this,i,n,r),this.check()}ortho(t){let{left:i,right:n,bottom:r,top:o,near:a=Ht,far:s=Wt}=t;return Rn(this,i,n,r,o,a,s),this.check()}orthographic(t){let{fovy:i=ns,aspect:n=rs,focalDistance:r=1,near:o=Ht,far:a=Wt}=t;Tn(i);let s=i/2,l=r*Math.tan(s),c=l*n;return this.ortho({left:-c,right:c,bottom:-l,top:l,near:o,far:a})}perspective(t){let{fovy:i=45*Math.PI/180,aspect:n=1,near:r=.1,far:o=500}=t;return Tn(i),Mn(this,i,n,r,o),this.check()}determinant(){return vn(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,i){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],i=i||[-0,-0,-0];let n=this.getScale(i),r=1/n[0],o=1/n[1],a=1/n[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,i){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],i=i||[-0,-0,-0];let n=this.getScale(i),r=1/n[0],o=1/n[1],a=1/n[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 hn(this,this),this.check()}invert(){return _n(this,this),this.check()}multiplyLeft(t){return Vt(this,t,this),this.check()}multiplyRight(t){return Vt(this,this,t),this.check()}rotateX(t){return In(this,this,t),this.check()}rotateY(t){return yn(this,this,t),this.check()}rotateZ(t){return Cn(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,i){return Sn(this,this,t,i),this.check()}scale(t){return xn(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return bn(this,this,t),this.check()}transform(t,i){return t.length===4?(i=wn(i||[-0,-0,-0,-0],t,this),Xe(i,4),i):this.transformAsPoint(t,i)}transformAsPoint(t,i){let{length:n}=t,r;switch(n){case 2:r=pn(i||[-0,-0],t,this);break;case 3:r=mn(i||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Xe(r,t.length),r}transformAsVector(t,i){let n;switch(t.length){case 2:n=dn(i||[-0,-0],t,this);break;case 3:n=gn(i||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Xe(n,t.length),n}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,i,n){return this.identity().translate([t,i,n])}},Qe,et;function as(){return Qe||(Qe=new z([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Qe)),Qe}function ss(){return et||(et=new z,Object.freeze(et)),et}function Tn(e){if(e>Math.PI*2)throw Error("expected radians")}function ls(e,t,i,n,r,o){let a=2*o/(i-t),s=2*o/(r-n),l=(i+t)/(i-t),c=(r+n)/(r-n),f=-1,p=-1,u=-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]=p,e[12]=0,e[13]=0,e[14]=u,e[15]=0,e}var ee=null,Pn=new ArrayBuffer(4),Nn=new Float32Array(Pn),Dn=new Uint32Array(Pn);function Fn(e){ee||=Bn(),e=Gt(e,-65504,65504),Nn[0]=e;let t=Dn[0],i=t>>23&511;return ee.baseTable[i]+((t&8388607)>>ee.shiftTable[i])}function On(e){ee||=Bn();let t=e>>10;return Dn[0]=ee.mantissaTable[ee.offsetTable[t]+(e&1023)]+ee.exponentTable[t],Nn[0]}function Bn(){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 i=new Uint32Array(2048),n=new Uint32Array(64),r=new Uint32Array(64);for(let o=1;o<1024;++o){let a=o<<13,s=0;for(;(a&8388608)===0;)a<<=1,s-=8388608;a&=-8388609,s+=947912704,i[o]=a|s}for(let o=1024;o<2048;++o)i[o]=939524096+(o-1024<<13);for(let o=1;o<31;++o)n[o]=o<<23;n[31]=1199570944,n[32]=2147483648;for(let o=33;o<63;++o)n[o]=2147483648+(o-32<<23);n[63]=3347054592;for(let o=1;o<64;++o)o!==32&&(r[o]=1024);return{baseTable:e,shiftTable:t,mantissaTable:i,exponentTable:n,offsetTable:r}}function de(e,t=[],i=0){let n=Math.fround(e),r=e-n;return t[i]=n,t[i+1]=r,t}function ye(e){return e-Math.fround(e)}function Ce(e){let t=new Float32Array(32);for(let i=0;i<4;++i)for(let n=0;n<4;++n){let r=i*4+n;de(e[n*4+i],t,r*2)}return t}function te(e,t=!0){return e??t}function ie(e=[0,0,0],t=!0){return t?e.map(i=>i/255):[...e]}function tt(e,t=!0){let i=ie(e.slice(0,3),t),n=Number.isFinite(e[3]),r=n?e[3]:1;return[i[0],i[1],i[2],t&&n?r/255:r]}var Un={width:2,jitter:.7,variation:.35,grain:.45,offset:0,extension:3,sketch:1,minimumAntialias:.7},kn=`
|
|
140
|
+
}`}function dn(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 pn(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 gs(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 zt(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 ee(e){return typeof e=="string"?e.charAt(0).toUpperCase()+e.slice(1):e}function gn(e,t){return ms(e,t)}function ms(e,t){let i=[];switch(t.uniforms){case"scoped-interface-blocks":case"unscoped-interface-blocks":i.push(`layout(std140) uniform ${ee(e.name)} {`);break;case"uniforms":}for(let[n,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}.${n}`);let o=hs(r);switch(t.uniforms){case"scoped-interface-blocks":i.push(` ${o} ${n};`);break;case"unscoped-interface-blocks":i.push(` ${o} ${e.name}_${n};`);break;case"uniforms":i.push(`uniform ${o} ${e.name}_${n};`)}}switch(t.uniforms){case"scoped-interface-blocks":i.push(`} ${e.name};`);break;case"unscoped-interface-blocks":i.push("};");break;case"uniforms":}return i.push(""),i.join(`
|
|
141
|
+
`)}function hs(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 mn(e,t){return vs(e,t)}function vs(e,t){let i=[];i.push(`struct ${ee(e.name)} {`);for(let[n,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}.${n}`);let o=r;i.push(` ${n} : ${o};`)}return i.push("};"),i.push(`var<uniform> ${e.name} : ${ee(e.name)};`),i.join(`
|
|
142
|
+
`)}function hn(e,t){switch(t.shaderLanguage){case"glsl":return gn(e,t);case"wgsl":return mn(e,t)}}var wf=1/Math.PI*180,Lf=1/180*Math.PI,_s={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{..._s}};var N=globalThis.mathgl.config;function Vt(e,{precision:t=N.precision}={}){return e=bs(e),`${parseFloat(e.toPrecision(t))}`}function pe(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Gt(e,t,i){return Ss(e,n=>Math.max(t,Math.min(i,n)))}function Xe(e,t,i){let n=N.EPSILON;i&&(N.EPSILON=i);try{if(e===t)return!0;if(pe(e)&&pe(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;++r)if(!Xe(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=n}}function bs(e){return Math.round(e/N.EPSILON)*N.EPSILON}function xs(e){return e.clone?e.clone():new Array(e.length)}function Ss(e,t,i){if(pe(e)){let n=e;i=i||xs(n);for(let r=0;r<i.length&&r<n.length;++r){let o=typeof e=="number"?e:e[r];i[r]=t(o,r,i)}return i}return t(e)}var Ze=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,i=0){for(let n=0;n<this.ELEMENTS;++n)this[n]=t[n+i];return this.check()}toArray(t=[],i=0){for(let n=0;n<this.ELEMENTS;++n)t[i+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:pe(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toString(){return this.formatString(N)}formatString(t){let i="";for(let n=0;n<this.ELEMENTS;++n)i+=(n>0?", ":"")+Vt(this[n],t);return`${t.printTypes?this.constructor.name:""}[${i}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let i=0;i<this.ELEMENTS;++i)if(!Xe(this[i],t[i]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let i=0;i<this.ELEMENTS;++i)if(this[i]!==t[i])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,i,n){if(n===void 0)return this.lerp(this,t,i);for(let r=0;r<this.ELEMENTS;++r){let o=t[r],a=typeof i=="number"?i:i[r];this[r]=o+n*(a-o)}return this.check()}min(t){for(let i=0;i<this.ELEMENTS;++i)this[i]=Math.min(t[i],this[i]);return this.check()}max(t){for(let i=0;i<this.ELEMENTS;++i)this[i]=Math.max(t[i],this[i]);return this.check()}clamp(t,i){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t[n]),i[n]);return this.check()}add(...t){for(let i of t)for(let n=0;n<this.ELEMENTS;++n)this[n]+=i[n];return this.check()}subtract(...t){for(let i of t)for(let n=0;n<this.ELEMENTS;++n)this[n]-=i[n];return this.check()}scale(t){if(typeof t=="number")for(let i=0;i<this.ELEMENTS;++i)this[i]*=t;else for(let i=0;i<this.ELEMENTS&&i<t.length;++i)this[i]*=t[i];return this.check()}multiplyByScalar(t){for(let i=0;i<this.ELEMENTS;++i)this[i]*=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 i=0;i<this.ELEMENTS;++i)t=t&&Number.isFinite(this[i]);return t}};function ys(e,t){if(e.length!==t)return!1;for(let i=0;i<e.length;++i)if(!Number.isFinite(e[i]))return!1;return!0}function vn(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function Je(e,t,i=""){if(N.debug&&!ys(e,t))throw new Error(`math.gl: ${i} some fields set to invalid numbers'`);return e}var Qe=class extends Ze{toString(){let t="[";if(N.printRowMajor){t+="row-major:";for(let i=0;i<this.RANK;++i)for(let n=0;n<this.RANK;++n)t+=` ${this[n*this.RANK+i]}`}else{t+="column-major:";for(let i=0;i<this.ELEMENTS;++i)t+=` ${this[i]}`}return t+="]",t}getElementIndex(t,i){return i*this.RANK+t}getElement(t,i){return this[i*this.RANK+t]}setElement(t,i,n){return this[i*this.RANK+t]=vn(n),this}getColumn(t,i=new Array(this.RANK).fill(-0)){let n=t*this.RANK;for(let r=0;r<this.RANK;++r)i[r]=this[n+r];return i}setColumn(t,i){let n=t*this.RANK;for(let r=0;r<this.RANK;++r)this[n+r]=i[r];return this}};function _n(e,t,i){let n=t[0],r=t[1];return e[0]=i[0]*n+i[4]*r+i[12],e[1]=i[1]*n+i[5]*r+i[13],e}function bn(e,t,i){let n=t[0],r=t[1],o=i[3]*n+i[7]*r||1;return e[0]=(i[0]*n+i[4]*r)/o,e[1]=(i[1]*n+i[5]*r)/o,e}function xn(e,t,i){let n=t[0],r=t[1],o=t[2],a=i[3]*n+i[7]*r+i[11]*o||1;return e[0]=(i[0]*n+i[4]*r+i[8]*o)/a,e[1]=(i[1]*n+i[5]*r+i[9]*o)/a,e[2]=(i[2]*n+i[6]*r+i[10]*o)/a,e}function Sn(e,t,i){let n=t[0],r=t[1],o=t[2],a=i[3]*n+i[7]*r+i[11]*o+i[15];return a=a||1,e[0]=(i[0]*n+i[4]*r+i[8]*o+i[12])/a,e[1]=(i[1]*n+i[5]*r+i[9]*o+i[13])/a,e[2]=(i[2]*n+i[6]*r+i[10]*o+i[14])/a,e}function Cs(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 yn(e,t){if(e===t){let i=t[1],n=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]=i,e[6]=t[9],e[7]=t[13],e[8]=n,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 Cn(e,t){let i=t[0],n=t[1],r=t[2],o=t[3],a=t[4],s=t[5],l=t[6],c=t[7],f=t[8],d=t[9],u=t[10],p=t[11],g=t[12],m=t[13],b=t[14],y=t[15],S=i*s-n*a,x=i*l-r*a,v=i*c-o*a,h=n*l-r*s,_=n*c-o*s,L=r*c-o*l,I=f*m-d*g,A=f*b-u*g,R=f*y-p*g,D=d*b-u*m,C=d*y-p*m,T=u*y-p*b,w=S*T-x*C+v*D+h*R-_*A+L*I;return w?(w=1/w,e[0]=(s*T-l*C+c*D)*w,e[1]=(r*C-n*T-o*D)*w,e[2]=(m*L-b*_+y*h)*w,e[3]=(u*_-d*L-p*h)*w,e[4]=(l*R-a*T-c*A)*w,e[5]=(i*T-r*R+o*A)*w,e[6]=(b*v-g*L-y*x)*w,e[7]=(f*L-u*v+p*x)*w,e[8]=(a*C-s*R+c*I)*w,e[9]=(n*R-i*C-o*I)*w,e[10]=(g*_-m*v+y*S)*w,e[11]=(d*v-f*_-p*S)*w,e[12]=(s*A-a*D-l*I)*w,e[13]=(i*D-n*A+r*I)*w,e[14]=(m*x-g*h-b*S)*w,e[15]=(f*h-d*x+u*S)*w,e):null}function In(e){let t=e[0],i=e[1],n=e[2],r=e[3],o=e[4],a=e[5],s=e[6],l=e[7],c=e[8],f=e[9],d=e[10],u=e[11],p=e[12],g=e[13],m=e[14],b=e[15],y=t*a-i*o,S=t*s-n*o,x=i*s-n*a,v=c*g-f*p,h=c*m-d*p,_=f*m-d*g,L=t*_-i*h+n*v,I=o*_-a*h+s*v,A=c*x-f*S+d*y,R=p*x-g*S+m*y;return l*L-r*I+b*A-u*R}function Wt(e,t,i){let n=t[0],r=t[1],o=t[2],a=t[3],s=t[4],l=t[5],c=t[6],f=t[7],d=t[8],u=t[9],p=t[10],g=t[11],m=t[12],b=t[13],y=t[14],S=t[15],x=i[0],v=i[1],h=i[2],_=i[3];return e[0]=x*n+v*s+h*d+_*m,e[1]=x*r+v*l+h*u+_*b,e[2]=x*o+v*c+h*p+_*y,e[3]=x*a+v*f+h*g+_*S,x=i[4],v=i[5],h=i[6],_=i[7],e[4]=x*n+v*s+h*d+_*m,e[5]=x*r+v*l+h*u+_*b,e[6]=x*o+v*c+h*p+_*y,e[7]=x*a+v*f+h*g+_*S,x=i[8],v=i[9],h=i[10],_=i[11],e[8]=x*n+v*s+h*d+_*m,e[9]=x*r+v*l+h*u+_*b,e[10]=x*o+v*c+h*p+_*y,e[11]=x*a+v*f+h*g+_*S,x=i[12],v=i[13],h=i[14],_=i[15],e[12]=x*n+v*s+h*d+_*m,e[13]=x*r+v*l+h*u+_*b,e[14]=x*o+v*c+h*p+_*y,e[15]=x*a+v*f+h*g+_*S,e}function wn(e,t,i){let n=i[0],r=i[1],o=i[2],a,s,l,c,f,d,u,p,g,m,b,y;return t===e?(e[12]=t[0]*n+t[4]*r+t[8]*o+t[12],e[13]=t[1]*n+t[5]*r+t[9]*o+t[13],e[14]=t[2]*n+t[6]*r+t[10]*o+t[14],e[15]=t[3]*n+t[7]*r+t[11]*o+t[15]):(a=t[0],s=t[1],l=t[2],c=t[3],f=t[4],d=t[5],u=t[6],p=t[7],g=t[8],m=t[9],b=t[10],y=t[11],e[0]=a,e[1]=s,e[2]=l,e[3]=c,e[4]=f,e[5]=d,e[6]=u,e[7]=p,e[8]=g,e[9]=m,e[10]=b,e[11]=y,e[12]=a*n+f*r+g*o+t[12],e[13]=s*n+d*r+m*o+t[13],e[14]=l*n+u*r+b*o+t[14],e[15]=c*n+p*r+y*o+t[15]),e}function Ln(e,t,i){let n=i[0],r=i[1],o=i[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]*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 Mn(e,t,i,n){let r=n[0],o=n[1],a=n[2],s=Math.sqrt(r*r+o*o+a*a),l,c,f,d,u,p,g,m,b,y,S,x,v,h,_,L,I,A,R,D,C,T,w,z;return s<1e-6?null:(s=1/s,r*=s,o*=s,a*=s,c=Math.sin(i),l=Math.cos(i),f=1-l,d=t[0],u=t[1],p=t[2],g=t[3],m=t[4],b=t[5],y=t[6],S=t[7],x=t[8],v=t[9],h=t[10],_=t[11],L=r*r*f+l,I=o*r*f+a*c,A=a*r*f-o*c,R=r*o*f-a*c,D=o*o*f+l,C=a*o*f+r*c,T=r*a*f+o*c,w=o*a*f-r*c,z=a*a*f+l,e[0]=d*L+m*I+x*A,e[1]=u*L+b*I+v*A,e[2]=p*L+y*I+h*A,e[3]=g*L+S*I+_*A,e[4]=d*R+m*D+x*C,e[5]=u*R+b*D+v*C,e[6]=p*R+y*D+h*C,e[7]=g*R+S*D+_*C,e[8]=d*T+m*w+x*z,e[9]=u*T+b*w+v*z,e[10]=p*T+y*w+h*z,e[11]=g*T+S*w+_*z,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function An(e,t,i){let n=Math.sin(i),r=Math.cos(i),o=t[4],a=t[5],s=t[6],l=t[7],c=t[8],f=t[9],d=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]=o*r+c*n,e[5]=a*r+f*n,e[6]=s*r+d*n,e[7]=l*r+u*n,e[8]=c*r-o*n,e[9]=f*r-a*n,e[10]=d*r-s*n,e[11]=u*r-l*n,e}function Rn(e,t,i){let n=Math.sin(i),r=Math.cos(i),o=t[0],a=t[1],s=t[2],l=t[3],c=t[8],f=t[9],d=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]=o*r-c*n,e[1]=a*r-f*n,e[2]=s*r-d*n,e[3]=l*r-u*n,e[8]=o*n+c*r,e[9]=a*n+f*r,e[10]=s*n+d*r,e[11]=l*n+u*r,e}function Tn(e,t,i){let n=Math.sin(i),r=Math.cos(i),o=t[0],a=t[1],s=t[2],l=t[3],c=t[4],f=t[5],d=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]=o*r+c*n,e[1]=a*r+f*n,e[2]=s*r+d*n,e[3]=l*r+u*n,e[4]=c*r-o*n,e[5]=f*r-a*n,e[6]=d*r-s*n,e[7]=u*r-l*n,e}function En(e,t){let i=t[0],n=t[1],r=t[2],o=t[3],a=i+i,s=n+n,l=r+r,c=i*a,f=n*a,d=n*s,u=r*a,p=r*s,g=r*l,m=o*a,b=o*s,y=o*l;return e[0]=1-d-g,e[1]=f+y,e[2]=u-b,e[3]=0,e[4]=f-y,e[5]=1-c-g,e[6]=p+m,e[7]=0,e[8]=u+b,e[9]=p-m,e[10]=1-c-d,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Pn(e,t,i,n,r,o,a){let s=1/(i-t),l=1/(r-n),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]=(i+t)*s,e[9]=(r+n)*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 Is(e,t,i,n,r){let o=1/Math.tan(t/2);if(e[0]=o/i,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/(n-r);e[10]=(r+n)*a,e[14]=2*r*n*a}else e[10]=-1,e[14]=-2*n;return e}var Dn=Is;function ws(e,t,i,n,r,o,a){let s=1/(t-i),l=1/(n-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+i)*s,e[13]=(r+n)*l,e[14]=(a+o)*c,e[15]=1,e}var Nn=ws;function Fn(e,t,i,n){let r,o,a,s,l,c,f,d,u,p,g=t[0],m=t[1],b=t[2],y=n[0],S=n[1],x=n[2],v=i[0],h=i[1],_=i[2];return Math.abs(g-v)<1e-6&&Math.abs(m-h)<1e-6&&Math.abs(b-_)<1e-6?Cs(e):(d=g-v,u=m-h,p=b-_,r=1/Math.sqrt(d*d+u*u+p*p),d*=r,u*=r,p*=r,o=S*p-x*u,a=x*d-y*p,s=y*u-S*d,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=u*s-p*a,c=p*o-d*s,f=d*a-u*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]=d,e[3]=0,e[4]=a,e[5]=c,e[6]=u,e[7]=0,e[8]=s,e[9]=f,e[10]=p,e[11]=0,e[12]=-(o*g+a*m+s*b),e[13]=-(l*g+c*m+f*b),e[14]=-(d*g+u*m+p*b),e[15]=1,e)}function jt(e){if(e.length!==16||Array.from(e).some(r=>!Number.isFinite(r))||e[3]!==0||e[7]!==0||e[11]!==0||e[15]!==1)throw new RangeError("Expected a finite affine matrix");let t=[Math.hypot(e[0],e[1],e[2]),Math.hypot(e[4],e[5],e[6]),Math.hypot(e[8],e[9],e[10])];if(t.some(r=>r===0||!Number.isFinite(r)))throw new RangeError("Singular transform");let i=Array.from({length:9},(r,o)=>e[Math.floor(o/3)*4+o%3]/t[Math.floor(o/3)]);for(let[r,o]of[[0,3],[0,6],[3,6]])if(Math.abs(i[r]*i[o]+i[r+1]*i[o+1]+i[r+2]*i[o+2])>1e-7)throw new RangeError("Sheared transforms do not have a TRS decomposition");if(i[0]*(i[4]*i[8]-i[5]*i[7])-i[3]*(i[1]*i[8]-i[2]*i[7])+i[6]*(i[1]*i[5]-i[2]*i[4])<0){t[0]=-t[0];for(let r=0;r<3;r++)i[r]=-i[r]}return{rotation:i,scale:t,translation:[e[12],e[13],e[14]]}}function Bn(e,t,i){let n=t[0],r=t[1],o=t[2],a=t[3];return e[0]=i[0]*n+i[4]*r+i[8]*o+i[12]*a,e[1]=i[1]*n+i[5]*r+i[9]*o+i[13]*a,e[2]=i[2]*n+i[6]*r+i[10]*o+i[14]*a,e[3]=i[3]*n+i[7]*r+i[11]*o+i[15]*a,e}var Kt;(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"})(Kt||(Kt={}));var Ls=45*Math.PI/180,Ms=1,qt=.1,$t=500,As=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),G=class extends Qe{static get IDENTITY(){return Ts()}static get ZERO(){return Rs()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Kt}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,i,n,r,o,a,s,l,c,f,d,u,p,g,m,b){return this[0]=t,this[1]=i,this[2]=n,this[3]=r,this[4]=o,this[5]=a,this[6]=s,this[7]=l,this[8]=c,this[9]=f,this[10]=d,this[11]=u,this[12]=p,this[13]=g,this[14]=m,this[15]=b,this.check()}setRowMajor(t,i,n,r,o,a,s,l,c,f,d,u,p,g,m,b){return this[0]=t,this[1]=o,this[2]=c,this[3]=p,this[4]=i,this[5]=a,this[6]=f,this[7]=g,this[8]=n,this[9]=s,this[10]=d,this[11]=m,this[12]=r,this[13]=l,this[14]=u,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(As)}fromObject(t){return this.check()}fromQuaternion(t){return En(this,t),this.check()}fromMatrix3(t){return this.set(t[0],t[1],t[2],0,t[3],t[4],t[5],0,t[6],t[7],t[8],0,0,0,0,1)}frustum(t){let{left:i,right:n,bottom:r,top:o,near:a=qt,far:s=$t}=t;return s===1/0?Es(this,i,n,r,o,a):Pn(this,i,n,r,o,a,s),this.check()}lookAt(t){let{eye:i,center:n=[0,0,0],up:r=[0,1,0]}=t;return Fn(this,i,n,r),this.check()}ortho(t){let{left:i,right:n,bottom:r,top:o,near:a=qt,far:s=$t}=t;return Nn(this,i,n,r,o,a,s),this.check()}orthographic(t){let{fovy:i=Ls,aspect:n=Ms,focalDistance:r=1,near:o=qt,far:a=$t}=t;On(i);let s=i/2,l=r*Math.tan(s),c=l*n;return this.ortho({left:-c,right:c,bottom:-l,top:l,near:o,far:a})}perspective(t){let{fovy:i=45*Math.PI/180,aspect:n=1,near:r=.1,far:o=500}=t;return On(i),Dn(this,i,n,r,o),this.check()}determinant(){return In(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,i){let{rotation:n,scale:r}=jt(this);if(t=t||new Array(16),i)for(let o=0;o<3;o++)i[o]=r[o];for(let o=0;o<16;o++)t[o]=0;for(let o=0;o<9;o++)t[Math.floor(o/3)*4+o%3]=n[o];return t[15]=1,t}getRotationMatrix3(t,i){let{rotation:n,scale:r}=jt(this);if(t=t||new Array(9),i)for(let o=0;o<3;o++)i[o]=r[o];for(let o=0;o<9;o++)t[o]=n[o];return t}transpose(){return yn(this,this),this.check()}invert(){return Cn(this,this),this.check()}multiplyLeft(t){return Wt(this,t,this),this.check()}multiplyRight(t){return Wt(this,this,t),this.check()}rotateX(t){return An(this,this,t),this.check()}rotateY(t){return Rn(this,this,t),this.check()}rotateZ(t){return Tn(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,i){return Mn(this,this,t,i),this.check()}scale(t){return Ln(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return wn(this,this,t),this.check()}transform(t,i){return t.length===4?(i=Bn(i||[-0,-0,-0,-0],t,this),Je(i,4),i):this.transformAsPoint(t,i)}transformAsPoint(t,i){let{length:n}=t,r;switch(n){case 2:r=_n(i||[-0,-0],t,this);break;case 3:r=Sn(i||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Je(r,t.length),r}transformAsVector(t,i){let n;switch(t.length){case 2:n=bn(i||[-0,-0],t,this);break;case 3:n=xn(i||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Je(n,t.length),n}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,i,n){return this.identity().translate([t,i,n])}},et,tt;function Rs(){return et||(et=new G([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(et)),et}function Ts(){return tt||(tt=new G,Object.freeze(tt)),tt}function On(e){if(e>Math.PI*2)throw Error("expected radians")}function Es(e,t,i,n,r,o){let a=2*o/(i-t),s=2*o/(r-n),l=(i+t)/(i-t),c=(r+n)/(r-n),f=-1,d=-1,u=-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]=d,e[12]=0,e[13]=0,e[14]=u,e[15]=0,e}var te=null,Un=new ArrayBuffer(4),kn=new Float32Array(Un),zn=new Uint32Array(Un);function Vn(e){te||=Hn(),e=Gt(e,-65504,65504),kn[0]=e;let t=zn[0],i=t>>23&511;return te.baseTable[i]+((t&8388607)>>te.shiftTable[i])}function Gn(e){te||=Hn();let t=e>>10;return zn[0]=te.mantissaTable[te.offsetTable[t]+(e&1023)]+te.exponentTable[t],kn[0]}function Hn(){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 i=new Uint32Array(2048),n=new Uint32Array(64),r=new Uint32Array(64);for(let o=1;o<1024;++o){let a=o<<13,s=0;for(;(a&8388608)===0;)a<<=1,s-=8388608;a&=-8388609,s+=947912704,i[o]=a|s}for(let o=1024;o<2048;++o)i[o]=939524096+(o-1024<<13);for(let o=1;o<31;++o)n[o]=o<<23;n[31]=1199570944,n[32]=2147483648;for(let o=33;o<63;++o)n[o]=2147483648+(o-32<<23);n[63]=3347054592;for(let o=1;o<64;++o)o!==32&&(r[o]=1024);return{baseTable:e,shiftTable:t,mantissaTable:i,exponentTable:n,offsetTable:r}}function ge(e,t=[],i=0){let n=Math.fround(e),r=e-n;return t[i]=n,t[i+1]=r,t}function Ie(e){return e-Math.fround(e)}function we(e){let t=new Float32Array(32);for(let i=0;i<4;++i)for(let n=0;n<4;++n){let r=i*4+n;ge(e[n*4+i],t,r*2)}return t}function ie(e,t=!0){return e??t}function ne(e=[0,0,0],t=!0){return t?e.map(i=>i/255):[...e]}function it(e,t=!0){let i=ne(e.slice(0,3),t),n=Number.isFinite(e[3]),r=n?e[3]:1;return[i[0],i[1],i[2],t&&n?r/255:r]}var Wn={width:2,jitter:.7,variation:.35,grain:.45,offset:0,extension:3,sketch:1,minimumAntialias:.7},jn=`
|
|
143
143
|
layout(std140) uniform sketchStrokeUniforms {
|
|
144
144
|
float width;
|
|
145
145
|
float jitter;
|
|
@@ -150,7 +150,7 @@ layout(std140) uniform sketchStrokeUniforms {
|
|
|
150
150
|
float sketch;
|
|
151
151
|
float minimumAntialias;
|
|
152
152
|
} sketchStroke;
|
|
153
|
-
`,
|
|
153
|
+
`,Ps=`
|
|
154
154
|
float sketchStroke_noise(float coordinate) {
|
|
155
155
|
float cell = floor(coordinate);
|
|
156
156
|
float fraction = fract(coordinate);
|
|
@@ -189,7 +189,7 @@ float sketchStroke_getCoverage(vec2 coordinates, float strokeLength, float seed)
|
|
|
189
189
|
// Keep the pigment opaque; grain changes the stroke edge so the paper does not show through as white flecks.
|
|
190
190
|
return coverage;
|
|
191
191
|
}
|
|
192
|
-
`,
|
|
192
|
+
`,Ds=`
|
|
193
193
|
struct sketchStrokeUniforms {
|
|
194
194
|
width: f32,
|
|
195
195
|
jitter: f32,
|
|
@@ -237,7 +237,7 @@ fn sketchStroke_getCoverage(coordinates: vec2<f32>, strokeLength: f32, seed: f32
|
|
|
237
237
|
// Keep the pigment opaque; grain changes the stroke edge so the paper does not show through as white flecks.
|
|
238
238
|
return coverage;
|
|
239
239
|
}
|
|
240
|
-
`,
|
|
240
|
+
`,qn={name:"sketchStroke",bindingLayout:[{name:"sketchStroke",group:3}],source:Ds,vs:jn,fs:jn+Ps,uniformTypes:{width:"f32",jitter:"f32",variation:"f32",grain:"f32",offset:"f32",extension:"f32",sketch:"f32",minimumAntialias:"f32"},defaultUniforms:Wn,getUniforms(e={}){return{...Wn,...e}}};var Yt={dashLength:12,gapLength:8,offset:0},$n={name:"pathDash",bindingLayout:[{name:"pathDash",group:3}],firstBindingSlot:0,uniformTypes:{dashLength:"f32",gapLength:"f32",offset:"f32"},defaultUniforms:Yt,getUniforms(e={},t=Yt){let i={...Yt,...t};return e.dashLength!==void 0&&(i.dashLength=Math.max(0,e.dashLength)),e.gapLength!==void 0&&(i.gapLength=Math.max(0,e.gapLength)),e.offset!==void 0&&(i.offset=e.offset),i},fs:`
|
|
241
241
|
layout(std140) uniform pathDashUniforms {
|
|
242
242
|
float dashLength;
|
|
243
243
|
float gapLength;
|
|
@@ -278,14 +278,14 @@ fn pathDash_getCoverage(distanceAlongPath: f32) -> f32 {
|
|
|
278
278
|
if (pathDash.dashLength <= 0.0) { return 0.0; }
|
|
279
279
|
return clamp(coverage, 0.0, 1.0);
|
|
280
280
|
}
|
|
281
|
-
`};var
|
|
281
|
+
`};var Ns=`fn random(scale: vec3f, seed: f32) -> f32 {
|
|
282
282
|
return fract(sin(dot(scale + vec3f(seed), vec3f(12.9898, 78.233, 151.7182))) * 43758.5453 + seed);
|
|
283
283
|
}
|
|
284
|
-
`,
|
|
284
|
+
`,Fs=`float random(vec3 scale, float seed) {
|
|
285
285
|
/* use the fragment position for a different seed per-pixel */
|
|
286
286
|
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
|
|
287
287
|
}
|
|
288
|
-
`,
|
|
288
|
+
`,Kn={name:"random",source:Ns,fs:Fs};var Bs=`fn volumeRaymarch_intersectBox(origin: vec3f, direction: vec3f, minimum: vec3f, maximum: vec3f) -> vec2f {
|
|
289
289
|
let safeDirection = select(vec3f(0.000001), direction, abs(direction) > vec3f(0.000001));
|
|
290
290
|
let first = (minimum - origin) / safeDirection;
|
|
291
291
|
let second = (maximum - origin) / safeDirection;
|
|
@@ -358,7 +358,7 @@ fn volumeRaymarch_composite(accumulated: vec4f, color: vec3f, alpha: f32) -> vec
|
|
|
358
358
|
let contribution = (1.0 - accumulated.a) * clamp(alpha, 0.0, 1.0);
|
|
359
359
|
return vec4f(accumulated.rgb + color * contribution, accumulated.a + contribution);
|
|
360
360
|
}
|
|
361
|
-
`,
|
|
361
|
+
`,Yn={name:"volumeRaymarch",source:Bs};var Os=`#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
|
|
362
362
|
|
|
363
363
|
// All these functions are for substituting tan() function from Intel GPU only
|
|
364
364
|
const float TWO_PI = 6.2831854820251465;
|
|
@@ -508,7 +508,7 @@ float tan_fp32(float a) {
|
|
|
508
508
|
return tan(a);
|
|
509
509
|
#endif
|
|
510
510
|
}
|
|
511
|
-
`,
|
|
511
|
+
`,Us=`#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
|
|
512
512
|
const FP32_TWO_PI: f32 = 6.2831854820251465;
|
|
513
513
|
const FP32_PI_2: f32 = 1.5707963705062866;
|
|
514
514
|
const FP32_PI_16: f32 = 0.1963495463132858;
|
|
@@ -629,7 +629,7 @@ fn tan_fp32(a: f32) -> f32 {
|
|
|
629
629
|
return tan(a);
|
|
630
630
|
}
|
|
631
631
|
#endif
|
|
632
|
-
`,
|
|
632
|
+
`,Xn={name:"fp32",source:Us,vs:Os};var Xt=`
|
|
633
633
|
layout(std140) uniform fp64arithmeticUniforms {
|
|
634
634
|
uniform float ONE;
|
|
635
635
|
uniform float SPLIT;
|
|
@@ -828,7 +828,7 @@ vec2 sqrt_fp64(vec2 a) {
|
|
|
828
828
|
return sum_fp64(vec2(yn, 0.0), prod);
|
|
829
829
|
#endif
|
|
830
830
|
}
|
|
831
|
-
`;var
|
|
831
|
+
`;var Zt=`struct Fp64F32Bits {
|
|
832
832
|
sign: u32,
|
|
833
833
|
baseExponent: i32,
|
|
834
834
|
significand: u32,
|
|
@@ -1107,7 +1107,7 @@ fn fp64_divide_f32_integer(aValue: f32, bValue: f32) -> f32 {
|
|
|
1107
1107
|
}
|
|
1108
1108
|
#endif
|
|
1109
1109
|
|
|
1110
|
-
`,
|
|
1110
|
+
`,Zn=`${Zt}
|
|
1111
1111
|
|
|
1112
1112
|
#ifndef LUMA_FP64_PREDICATE_ONLY
|
|
1113
1113
|
fn split(a: f32) -> vec2f {
|
|
@@ -1375,7 +1375,7 @@ fn sqrt_fp64(a: vec2f) -> vec2f {
|
|
|
1375
1375
|
return fp64_scale_fp64_integer(normalizedRoot, evenExponent / 2);
|
|
1376
1376
|
}
|
|
1377
1377
|
#endif
|
|
1378
|
-
`;var
|
|
1378
|
+
`;var Jn=`${Zt}
|
|
1379
1379
|
|
|
1380
1380
|
#ifndef LUMA_FP64_PREDICATE_ONLY
|
|
1381
1381
|
fn split(a: f32) -> vec2f {
|
|
@@ -1488,7 +1488,7 @@ fn sqrt_fp64(a: vec2f) -> vec2f {
|
|
|
1488
1488
|
return sum_fp64(vec2f(estimate, 0.0), correction);
|
|
1489
1489
|
}
|
|
1490
1490
|
#endif
|
|
1491
|
-
`;var
|
|
1491
|
+
`;var Qn=`struct Fp64ArithmeticUniforms {
|
|
1492
1492
|
ONE: f32,
|
|
1493
1493
|
SPLIT: f32,
|
|
1494
1494
|
};
|
|
@@ -2121,10 +2121,10 @@ fn prevent_fp64_optimization(value: f32) -> f32 {
|
|
|
2121
2121
|
#endif
|
|
2122
2122
|
|
|
2123
2123
|
#ifdef LUMA_FP64_INTEGER_ARITHMETIC
|
|
2124
|
-
${
|
|
2124
|
+
${Zn}
|
|
2125
2125
|
#else
|
|
2126
2126
|
#ifdef LUMA_FP64_HYBRID_ARITHMETIC
|
|
2127
|
-
${
|
|
2127
|
+
${Jn}
|
|
2128
2128
|
#else
|
|
2129
2129
|
fn split(a: f32) -> vec2f {
|
|
2130
2130
|
let splitValue = prevent_fp64_optimization(fp64arithmetic.SPLIT + fp64_runtime_zero());
|
|
@@ -2402,7 +2402,7 @@ fn fp64_scale_fp64(value: vec2f, exponent: i32) -> vec2f {
|
|
|
2402
2402
|
#endif
|
|
2403
2403
|
}
|
|
2404
2404
|
#endif
|
|
2405
|
-
`;var
|
|
2405
|
+
`;var er=`const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
|
|
2406
2406
|
const vec2 LOG2_FP64 = vec2(0.6931471824645996e+00, -1.9046542121259336e-09);
|
|
2407
2407
|
const vec2 PI_FP64 = vec2(3.1415927410125732, -8.742278012618954e-8);
|
|
2408
2408
|
const vec2 TWO_PI_FP64 = vec2(6.2831854820251465, -1.7484556025237907e-7);
|
|
@@ -3071,7 +3071,7 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
|
|
|
3071
3071
|
vec4_dot_fp64(a, tmp, out_val[i]);
|
|
3072
3072
|
}
|
|
3073
3073
|
}
|
|
3074
|
-
`;var
|
|
3074
|
+
`;var tr=`const E_FP64 = vec2f(2.7182817459106445, 8.254840366817007e-8);
|
|
3075
3075
|
const LOG2_FP64 = vec2f(0.6931471824645996, -1.9046542121259336e-9);
|
|
3076
3076
|
const PI_FP64 = vec2f(3.1415927410125732, -8.742278012618954e-8);
|
|
3077
3077
|
const TWO_PI_FP64 = vec2f(6.2831854820251465, -1.7484556025237907e-7);
|
|
@@ -3221,7 +3221,7 @@ fn mat4_vec4_mul_fp64(matrix: array<vec2f, 16>, a: array<vec2f, 4>) -> array<vec
|
|
|
3221
3221
|
}
|
|
3222
3222
|
return result;
|
|
3223
3223
|
}
|
|
3224
|
-
`;var
|
|
3224
|
+
`;var ks={ONE:1,SPLIT:4097},Jt={name:"fp64arithmetic",source:Qn,fs:Xt,vs:Xt,defaultUniforms:ks,uniformTypes:{ONE:"f32",SPLIT:"f32"},fp64ify:ge,fp64LowPart:Ie,fp64ifyMatrix4:we},ir={name:"fp64",source:tr,vs:er,dependencies:[Jt],fp64ify:ge,fp64LowPart:Ie,fp64ifyMatrix4:we};var nr=`const DGGS_H3_CELL_MODE: u32 = 1u;
|
|
3225
3225
|
const DGGS_H3_MAX_RESOLUTION: u32 = 15u;
|
|
3226
3226
|
const DGGS_H3_MAX_BASE_CELL: u32 = 121u;
|
|
3227
3227
|
const DGGS_H3_UNUSED_DIGIT: u32 = 7u;
|
|
@@ -5495,7 +5495,7 @@ fn dggs_s2_get_boundary_point(index: vec2u, vertexIndex: u32) -> vec2f {
|
|
|
5495
5495
|
fn dggs_s2_get_boundary_point_fp64_split(index: vec2u, vertexIndex: u32) -> vec4f {
|
|
5496
5496
|
return dggs_boundary_point_to_fp64_split(dggs_s2_get_boundary_point(index, vertexIndex));
|
|
5497
5497
|
}
|
|
5498
|
-
`;var
|
|
5498
|
+
`;var rr={name:"dggs",source:nr};var k={RGBA8UNORM:0,RGBA16FLOAT:1,RGBA32FLOAT:2},nt={rgba8unorm:4,rgba16float:8,rgba32float:16},rt={...nt},Qt={rgba8unorm:k.RGBA8UNORM,rgba16float:k.RGBA16FLOAT,rgba32float:k.RGBA32FLOAT},lr={[k.RGBA8UNORM]:"rgba8unorm",[k.RGBA16FLOAT]:"rgba16float",[k.RGBA32FLOAT]:"rgba32float"},cr={useByteColors:"f32"},fr={useByteColors:!0},zs={format:"u32",wordStride:"u32",wordOffset:"u32",_padding:"u32"},Vs={format:k.RGBA8UNORM,wordStride:rt.rgba8unorm/Uint32Array.BYTES_PER_ELEMENT,wordOffset:0,_padding:0},or=ur("colors"),ar=ur("floatColors"),Gs=dr("colors"),Hs=dr("floatColors"),Ws=`struct storageColorsUniforms {
|
|
5499
5499
|
format: u32,
|
|
5500
5500
|
wordStride: u32,
|
|
5501
5501
|
wordOffset: u32,
|
|
@@ -5505,8 +5505,8 @@ fn dggs_s2_get_boundary_point_fp64_split(index: vec2u, vertexIndex: u32) -> vec4
|
|
|
5505
5505
|
@group(0) @binding(auto) var<uniform> storageColors : storageColorsUniforms;
|
|
5506
5506
|
@group(0) @binding(auto) var<storage, read> storageColorsBuffer : array<u32>;
|
|
5507
5507
|
|
|
5508
|
-
const STORAGE_COLOR_FORMAT_RGBA8UNORM : u32 = ${
|
|
5509
|
-
const STORAGE_COLOR_FORMAT_RGBA16FLOAT : u32 = ${
|
|
5508
|
+
const STORAGE_COLOR_FORMAT_RGBA8UNORM : u32 = ${k.RGBA8UNORM}u;
|
|
5509
|
+
const STORAGE_COLOR_FORMAT_RGBA16FLOAT : u32 = ${k.RGBA16FLOAT}u;
|
|
5510
5510
|
|
|
5511
5511
|
fn storageColors_getWordIndex(rowIndex: u32) -> u32 {
|
|
5512
5512
|
return storageColors.wordOffset + rowIndex * storageColors.wordStride;
|
|
@@ -5541,7 +5541,7 @@ fn storageColors_readColor(rowIndex: u32) -> vec4<f32> {
|
|
|
5541
5541
|
}
|
|
5542
5542
|
return storageColors_readRgba32FloatColor(wordIndex);
|
|
5543
5543
|
}
|
|
5544
|
-
`;function
|
|
5544
|
+
`;function ur(e){return`layout(std140) uniform ${e}Uniforms {
|
|
5545
5545
|
float useByteColors;
|
|
5546
5546
|
} ${e};
|
|
5547
5547
|
|
|
@@ -5568,7 +5568,7 @@ vec4 ${e}_premultiply_alpha(vec4 inputColor) {
|
|
|
5568
5568
|
vec4 ${e}_unpremultiply_alpha(vec4 inputColor) {
|
|
5569
5569
|
return ${e}_unpremultiplyAlpha(inputColor);
|
|
5570
5570
|
}
|
|
5571
|
-
`}function
|
|
5571
|
+
`}function dr(e){return`struct ${e}Uniforms {
|
|
5572
5572
|
useByteColors: f32
|
|
5573
5573
|
};
|
|
5574
5574
|
|
|
@@ -5601,7 +5601,7 @@ fn ${e}_premultiply_alpha(inputColor: vec4<f32>) -> vec4<f32> {
|
|
|
5601
5601
|
fn ${e}_unpremultiply_alpha(inputColor: vec4<f32>) -> vec4<f32> {
|
|
5602
5602
|
return ${e}_unpremultiplyAlpha(inputColor);
|
|
5603
5603
|
}
|
|
5604
|
-
`}function
|
|
5604
|
+
`}function js(e={}){let t=qs(e.format),i=lr[t],n=e.byteStride??rt[i],r=e.byteOffset??0,o=nt[i];if(sr("byteStride",n),sr("byteOffset",r),n<o)throw new Error(`storageColors byteStride must be at least ${o} for ${i}`);return{format:t,wordStride:n/Uint32Array.BYTES_PER_ELEMENT,wordOffset:r/Uint32Array.BYTES_PER_ELEMENT,_padding:0}}function qs(e="rgba8unorm"){if(typeof e=="number"){if(e in lr)return e}else if(e in Qt)return Qt[e];throw new Error(`storageColors format must be one of ${Object.keys(Qt).join(", ")}`)}function sr(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 pr={name:"colors",props:{},uniforms:{},vs:or,fs:or,source:Gs,uniformTypes:cr,defaultUniforms:fr},me={name:"floatColors",props:{},uniforms:{},vs:ar,fs:ar,source:Hs,uniformTypes:cr,defaultUniforms:fr},gr={name:"storageColors",props:{},uniforms:{},bindings:{},source:Ws,uniformTypes:zs,defaultUniforms:Vs,bindingLayout:[{name:"storageColors",group:0},{name:"storageColorsBuffer",group:0}],getUniforms(e={}){return{...js(e),...e.colorBuffer?{storageColorsBuffer:e.colorBuffer}:{}}}};var $s=[0,1,1,1],Ks=`layout(std140) uniform pickingUniforms {
|
|
5605
5605
|
float isActive;
|
|
5606
5606
|
float isAttribute;
|
|
5607
5607
|
float isHighlightActive;
|
|
@@ -5672,7 +5672,7 @@ void picking_setPickingAttribute(vec3 value) {
|
|
|
5672
5672
|
picking_vRGBcolor_Avalid.rgb = value;
|
|
5673
5673
|
}
|
|
5674
5674
|
}
|
|
5675
|
-
`,
|
|
5675
|
+
`,Ys=`layout(std140) uniform pickingUniforms {
|
|
5676
5676
|
float isActive;
|
|
5677
5677
|
float isAttribute;
|
|
5678
5678
|
float isHighlightActive;
|
|
@@ -5728,7 +5728,7 @@ vec4 picking_filterColor(vec4 color) {
|
|
|
5728
5728
|
vec4 highlightColor = picking_filterHighlightColor(color);
|
|
5729
5729
|
return picking_filterPickingColor(highlightColor);
|
|
5730
5730
|
}
|
|
5731
|
-
`,
|
|
5731
|
+
`,mr={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:$s},vs:Ks,fs:Ys,getUniforms:Xs};function Xs(e={},t){let i={},n=ie(e.useByteColors,!0);if(e.highlightedObjectColor!==void 0)if(e.highlightedObjectColor===null)i.isHighlightActive=!1;else{i.isHighlightActive=!0;let r=e.highlightedObjectColor.slice(0,3);i.highlightedObjectColor=r}return e.highlightColor&&(i.highlightColor=it(e.highlightColor,n)),e.isActive!==void 0&&(i.isActive=!!e.isActive,i.isAttribute=!!e.isAttribute),e.useByteColors!==void 0&&(i.useByteColors=!!e.useByteColors),i}var Zs={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 {
|
|
5732
5732
|
int enabled;
|
|
5733
5733
|
float min;
|
|
5734
5734
|
float max;
|
|
@@ -5749,11 +5749,11 @@ fn filter_isVisible(value: f32) -> bool {
|
|
|
5749
5749
|
return filterUniforms.enabled == 0 ||
|
|
5750
5750
|
(value >= filterUniforms.min && value <= filterUniforms.max);
|
|
5751
5751
|
}
|
|
5752
|
-
`,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}},
|
|
5752
|
+
`,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}},hr={name:"filter",module:Zs,vertexInputs:{filterValues:"f32"},injections:[{stage:"vertex",target:"FILTER_POSITION",glsl:`if (!filter_isVisible(filterValues)) {
|
|
5753
5753
|
position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
5754
5754
|
}`,wgsl:`if (!filter_isVisible(filterValues)) {
|
|
5755
5755
|
*position = vec4<f32>(2.0, 2.0, 2.0, 1.0);
|
|
5756
|
-
}`}]};var
|
|
5756
|
+
}`}]};var Js={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 {
|
|
5757
5757
|
highp int enabled;
|
|
5758
5758
|
highp int mode;
|
|
5759
5759
|
highp vec4 bounds;
|
|
@@ -5791,7 +5791,7 @@ fn clip_isInBounds(coordinates: vec2<f32>) -> bool {
|
|
|
5791
5791
|
coordinates.x < clipUniforms.bounds.z &&
|
|
5792
5792
|
coordinates.y < clipUniforms.bounds.w;
|
|
5793
5793
|
}
|
|
5794
|
-
`,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}},
|
|
5794
|
+
`,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}},vr={name:"clip",module:Js,interStageVariables:{clipCoordinates:{type:"vec2<f32>",interpolation:"smooth"}},injections:[{stage:"vertex",target:"CLIP_POSITION",glsl:`clipCoordinates = geometryCoordinates;
|
|
5795
5795
|
if (clipState.enabled != 0 && clipState.mode == 1 &&
|
|
5796
5796
|
!clip_isInBounds(instanceCoordinates)) {
|
|
5797
5797
|
position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
@@ -5805,9 +5805,9 @@ if (clipUniforms.enabled != 0 && clipUniforms.mode == 1 &&
|
|
|
5805
5805
|
}`,wgsl:`if (clipUniforms.enabled != 0 && clipUniforms.mode == 0 &&
|
|
5806
5806
|
!clip_isInBounds(clipCoordinates)) {
|
|
5807
5807
|
discard;
|
|
5808
|
-
}`}]};var
|
|
5808
|
+
}`}]};var $=64,Qs=`
|
|
5809
5809
|
struct skinUniforms {
|
|
5810
|
-
jointMatrix: array<mat4x4<f32>, ${
|
|
5810
|
+
jointMatrix: array<mat4x4<f32>, ${$}>,
|
|
5811
5811
|
};
|
|
5812
5812
|
|
|
5813
5813
|
@group(0) @binding(auto) var<uniform> skin: skinUniforms;
|
|
@@ -5846,7 +5846,7 @@ fn getSkinMatrix(weights: vec4f, joints: vec4u) -> mat4x4<f32> {
|
|
|
5846
5846
|
+ (weights.w * skin.jointMatrix[joints.w]);
|
|
5847
5847
|
#endif
|
|
5848
5848
|
}
|
|
5849
|
-
`,
|
|
5849
|
+
`,el=`
|
|
5850
5850
|
layout(std140) uniform skinUniforms {
|
|
5851
5851
|
mat4 jointMatrix[SKIN_MAX_JOINTS];
|
|
5852
5852
|
} skin;
|
|
@@ -5906,7 +5906,7 @@ mat4 getSkinMatrix(vec4 weights, uvec4 joints) {
|
|
|
5906
5906
|
#endif
|
|
5907
5907
|
}
|
|
5908
5908
|
|
|
5909
|
-
`,
|
|
5909
|
+
`,tl="",_r={props:{},uniforms:{},bindings:{},name:"skin",bindingLayout:[{name:"skin",group:0},{name:"skinJointMatrices",group:0,visibility:1}],dependencies:[],source:Qs,vs:el,fs:tl,defines:{SKIN_MAX_JOINTS:$},getUniforms:(e={},t)=>{let{jointMatrices:i,skinJointMatrices:n,scenegraphsFromGLTF:r,skinIndex:o=0,meshWorldMatrix:a}=e,s=n?{skinJointMatrices:n}:{};if(i)return{jointMatrix:il(i),...s};let l=r?.gltf?.skins?.[o];if(!l)return{jointMatrix:[],...s};let{inverseBindMatrices:c,joints:f,skeleton:d}=l,u=r.gltfNodeIndexToNodeMap,p=new Map,g=d===void 0?void 0:u?.get(d),m=g?[g]:r.scenes||[];for(let x of m)x.preorderTraversal((v,{worldMatrix:h})=>{p.set(v.id,h)});let b=a?new G(a).invert():null,y=new Float32Array($*16),S=c?.value;for(let x=0;x<Math.min(f.length,$);x++){let v=u?.get(f[x]);if(!v)continue;let h=p.get(v.id)||v.matrix,_=b?new G(b).multiplyRight(h):new G(h);S&&S.length>=(x+1)*16&&_.multiplyRight(new G(Array.from(S.slice(x*16,(x+1)*16)))),y.set(_,x*16)}return{jointMatrix:y,...s}},uniformTypes:{jointMatrix:["mat4x4<f32>",$]}};function il(e){let t=new Float32Array($*16);return t.set(e instanceof Float32Array?e.subarray(0,t.length):e.slice(0,t.length)),t}var nl=`
|
|
5910
5910
|
#ifdef HAS_GPU_CROWD_ANIMATION
|
|
5911
5911
|
@group(0) @binding(auto) var<storage, read> gpuAnimationFrames: array<vec4f>;
|
|
5912
5912
|
|
|
@@ -6018,7 +6018,7 @@ fn getGPUCrowdMorphDelta(
|
|
|
6018
6018
|
return result;
|
|
6019
6019
|
}
|
|
6020
6020
|
#endif
|
|
6021
|
-
`,
|
|
6021
|
+
`,rl=`
|
|
6022
6022
|
#ifdef HAS_GPU_CROWD_ANIMATION
|
|
6023
6023
|
uniform highp sampler2D gpuAnimationFrames;
|
|
6024
6024
|
|
|
@@ -6110,7 +6110,7 @@ vec3 getGPUCrowdMorphDelta(
|
|
|
6110
6110
|
return result;
|
|
6111
6111
|
}
|
|
6112
6112
|
#endif
|
|
6113
|
-
`,
|
|
6113
|
+
`,br={name:"gpuAnimation",props:{},uniforms:{},bindings:{},source:nl,vs:rl,fs:"",bindingLayout:[{name:"gpuAnimationFrames",group:0,visibility:1},{name:"gpuMorphTargets",group:0,visibility:1},{name:"gpuMorphWeights",group:0,visibility:1}],getUniforms(e={}){return e}};var K=4;function ei(){return{color:[0,0,0],position:[0,0,0],halfAxisX:[0,0,0],halfAxisY:[0,0,0],normal:[0,0,-1],disk:0}}var ot={color:"vec3<f32>",position:"vec3<f32>",halfAxisX:"vec3<f32>",halfAxisY:"vec3<f32>",normal:"vec3<f32>",disk:"i32"};function Le(e,t=!1){return Array.from({length:K},(i,n)=>{let r=e[n];if(!r)return ei();let o=ne(r.color||(t?[255,255,255]:[1,1,1]),t);return{position:r.position,halfAxisX:r.halfAxisX,halfAxisY:r.halfAxisY,normal:r.normal,disk:r.type==="disk"?1:0,color:o.map(a=>a*(r.intensity??1e3))}})}var ti=`precision highp int;
|
|
6114
6114
|
|
|
6115
6115
|
// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
6116
6116
|
struct AmbientLight {
|
|
@@ -6196,7 +6196,7 @@ float getSpotLightAttenuation(SpotLight spotLight, vec3 positionWorldspace) {
|
|
|
6196
6196
|
}
|
|
6197
6197
|
|
|
6198
6198
|
// #endif
|
|
6199
|
-
`;var
|
|
6199
|
+
`;var xr=`// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
6200
6200
|
const MAX_LIGHTS: i32 = 5;
|
|
6201
6201
|
|
|
6202
6202
|
struct AmbientLight {
|
|
@@ -6281,7 +6281,7 @@ fn getSpotLightAttenuation(spotLight: SpotLight, positionWorldspace: vec3<f32>)
|
|
|
6281
6281
|
);
|
|
6282
6282
|
return distanceAttenuation / max(coneFactor, 0.0001);
|
|
6283
6283
|
}
|
|
6284
|
-
`;var
|
|
6284
|
+
`;var re=5,ol={color:"vec3<f32>",position:"vec3<f32>",direction:"vec3<f32>",attenuation:"vec3<f32>",coneCos:"vec2<f32>"},F={props:{},uniforms:{},name:"lighting",defines:{},uniformTypes:{enabled:"i32",directionalLightCount:"i32",pointLightCount:"i32",spotLightCount:"i32",ambientColor:"vec3<f32>",lights:[ol,re],areaLightCount:"i32",areaLights:[ot,K]},defaultUniforms:st(),bindingLayout:[{name:"lighting",group:2}],firstBindingSlot:0,source:xr,vs:ti,fs:ti,getUniforms:al};function al(e,t={}){e=e&&{...e};let i=(e?.lights||[]).filter(f=>f.type==="rect"||f.type==="disk");if(!e)return st();e.lights&&(e={...e,...ll(e.lights),lights:void 0});let{useByteColors:n,ambientLight:r,pointLights:o,spotLights:a,directionalLights:s}=e||{};if(!(r||o&&o.length>0||a&&a.length>0||s&&s.length>0)&&i.length===0)return{...st(),enabled:0};let c={...st(),...sl({useByteColors:n,ambientLight:r,pointLights:o,spotLights:a,directionalLights:s})};return c.areaLightCount=Math.min(i.length,K),c.areaLights=Le(i,ie(e.useByteColors,!0)),e.enabled!==void 0&&(c.enabled=e.enabled?1:0),c}function sl({useByteColors:e,ambientLight:t,pointLights:i=[],spotLights:n=[],directionalLights:r=[]}){let o=Sr(),a=0,s=0,l=0,c=0;for(let f of i){if(a>=re)break;o[a]={...o[a],color:at(f,e),position:f.position,attenuation:f.attenuation||[1,0,0]},a++,s++}for(let f of n){if(a>=re)break;o[a]={...o[a],color:at(f,e),position:f.position,direction:f.direction,attenuation:f.attenuation||[1,0,0],coneCos:fl(f)},a++,l++}for(let f of r){if(a>=re)break;o[a]={...o[a],color:at(f,e),direction:f.direction},a++,c++}return i.length+n.length+r.length>re&&console.warn(`MAX_LIGHTS exceeded, truncating to ${re}`),{ambientColor:at(t,e),directionalLightCount:c,pointLightCount:s,spotLightCount:l,lights:o}}function ll(e){let t={pointLights:[],spotLights:[],directionalLights:[]};for(let i of e||[])switch(i.type){case"ambient":t.ambientLight=i;break;case"directional":t.directionalLights?.push(i);break;case"point":t.pointLights?.push(i);break;case"spot":t.spotLights?.push(i);break;default:}return t}function at(e={},t){let{color:i=[0,0,0],intensity:n=1}=e;return ne(i,ie(t,!0)).map(o=>o*n)}function st(){return{enabled:1,directionalLightCount:0,pointLightCount:0,spotLightCount:0,ambientColor:[.1,.1,.1],lights:Sr(),areaLightCount:0,areaLights:Le([])}}function Sr(){return Array.from({length:re},()=>cl())}function cl(){return{color:[1,1,1],position:[1,1,2],direction:[1,1,1],attenuation:[1,0,0],coneCos:[1,0]}}function fl(e){let t=e.innerConeAngle??0,i=e.outerConeAngle??Math.PI/4;return[Math.cos(t),Math.cos(i)]}var ul=`#ifdef USE_IBL
|
|
6285
6285
|
@group(2) @binding(auto) var pbr_diffuseEnvSampler: texture_cube<f32>;
|
|
6286
6286
|
@group(2) @binding(auto) var pbr_diffuseEnvSamplerSampler: sampler;
|
|
6287
6287
|
@group(2) @binding(auto) var pbr_specularEnvSampler: texture_cube<f32>;
|
|
@@ -6289,12 +6289,12 @@ fn getSpotLightAttenuation(spotLight: SpotLight, positionWorldspace: vec3<f32>)
|
|
|
6289
6289
|
@group(2) @binding(auto) var pbr_brdfLUT: texture_2d<f32>;
|
|
6290
6290
|
@group(2) @binding(auto) var pbr_brdfLUTSampler: sampler;
|
|
6291
6291
|
#endif
|
|
6292
|
-
`,
|
|
6292
|
+
`,yr=`#ifdef USE_IBL
|
|
6293
6293
|
uniform samplerCube pbr_diffuseEnvSampler;
|
|
6294
6294
|
uniform samplerCube pbr_specularEnvSampler;
|
|
6295
6295
|
uniform sampler2D pbr_brdfLUT;
|
|
6296
6296
|
#endif
|
|
6297
|
-
`,
|
|
6297
|
+
`,lt={name:"ibl",firstBindingSlot:32,bindingLayout:[{name:"pbr_diffuseEnvSampler",group:2},{name:"pbr_specularEnvSampler",group:2},{name:"pbr_brdfLUT",group:2}],source:ul,vs:yr,fs:yr};var dl=`struct dirlightUniforms {
|
|
6298
6298
|
lightDirection: vec3<f32>,
|
|
6299
6299
|
};
|
|
6300
6300
|
|
|
@@ -6319,12 +6319,12 @@ fn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {
|
|
|
6319
6319
|
let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));
|
|
6320
6320
|
return vec4<f32>(color.rgb * d, color.a);
|
|
6321
6321
|
}
|
|
6322
|
-
`,
|
|
6322
|
+
`,pl=`out vec3 dirlight_vNormal;
|
|
6323
6323
|
|
|
6324
6324
|
void dirlight_setNormal(vec3 normal) {
|
|
6325
6325
|
dirlight_vNormal = normalize(normal);
|
|
6326
6326
|
}
|
|
6327
|
-
`,
|
|
6327
|
+
`,gl=`layout(std140) uniform dirlightUniforms {
|
|
6328
6328
|
vec3 lightDirection;
|
|
6329
6329
|
} dirlight;
|
|
6330
6330
|
|
|
@@ -6335,7 +6335,23 @@ vec4 dirlight_filterColor(vec4 color) {
|
|
|
6335
6335
|
float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
|
|
6336
6336
|
return vec4(color.rgb * d, color.a);
|
|
6337
6337
|
}
|
|
6338
|
-
`,
|
|
6338
|
+
`,ii={props:{},uniforms:{},name:"dirlight",bindingLayout:[{name:"dirlight",group:2}],firstBindingSlot:16,dependencies:[],source:dl,vs:pl,fs:gl,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:[1,1,2]},getUniforms:ml};function ml(e=ii.defaultUniforms){let t={};return e.lightDirection&&(t.lightDirection=e.lightDirection),t}var hl=`fn unlitMaterial_getColor(surfaceColor: vec4<f32>) -> vec4<f32> {
|
|
6339
|
+
return surfaceColor;
|
|
6340
|
+
}
|
|
6341
|
+
|
|
6342
|
+
// Compatibility with the aggregate Phong/Gouraud material evaluation function.
|
|
6343
|
+
fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, positionWorldspace: vec3<f32>, normalWorldspace: vec3<f32>) -> vec3<f32> {
|
|
6344
|
+
return surfaceColor;
|
|
6345
|
+
}
|
|
6346
|
+
`,Cr=`vec4 unlitMaterial_getColor(vec4 surfaceColor) {
|
|
6347
|
+
return surfaceColor;
|
|
6348
|
+
}
|
|
6349
|
+
|
|
6350
|
+
// Compatibility with the aggregate Phong/Gouraud material evaluation function.
|
|
6351
|
+
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positionWorldspace, vec3 normalWorldspace) {
|
|
6352
|
+
return surfaceColor;
|
|
6353
|
+
}
|
|
6354
|
+
`,Ir={name:"unlitMaterial",source:hl,vs:Cr,fs:Cr,dependencies:[],bindingLayout:[],uniformTypes:{},defaultUniforms:{}};var wr=`struct lambertMaterialUniforms {
|
|
6339
6355
|
unlit: u32,
|
|
6340
6356
|
ambient: f32,
|
|
6341
6357
|
diffuse: f32,
|
|
@@ -6402,12 +6418,12 @@ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, p
|
|
|
6402
6418
|
|
|
6403
6419
|
return lightColor;
|
|
6404
6420
|
}
|
|
6405
|
-
`;var
|
|
6421
|
+
`;var Lr=`layout(std140) uniform lambertMaterialUniforms {
|
|
6406
6422
|
uniform bool unlit;
|
|
6407
6423
|
uniform float ambient;
|
|
6408
6424
|
uniform float diffuse;
|
|
6409
6425
|
} material;
|
|
6410
|
-
`,
|
|
6426
|
+
`,Mr=`layout(std140) uniform lambertMaterialUniforms {
|
|
6411
6427
|
uniform bool unlit;
|
|
6412
6428
|
uniform float ambient;
|
|
6413
6429
|
uniform float diffuse;
|
|
@@ -6454,14 +6470,14 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
|
|
|
6454
6470
|
|
|
6455
6471
|
return lightColor;
|
|
6456
6472
|
}
|
|
6457
|
-
`;var
|
|
6473
|
+
`;var ni={name:"lambertMaterial",firstBindingSlot:0,bindingLayout:[{name:"lambertMaterial",group:3}],dependencies:[F],source:wr,vs:Lr,fs:Mr,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{unlit:"i32",ambient:"f32",diffuse:"f32"},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6},getUniforms(e){return{...ni.defaultUniforms,...e}}};var ct=`layout(std140) uniform phongMaterialUniforms {
|
|
6458
6474
|
uniform bool unlit;
|
|
6459
6475
|
uniform float ambient;
|
|
6460
6476
|
uniform float diffuse;
|
|
6461
6477
|
uniform float shininess;
|
|
6462
6478
|
uniform vec3 specularColor;
|
|
6463
6479
|
} material;
|
|
6464
|
-
`,
|
|
6480
|
+
`,ft=`layout(std140) uniform phongMaterialUniforms {
|
|
6465
6481
|
uniform bool unlit;
|
|
6466
6482
|
uniform float ambient;
|
|
6467
6483
|
uniform float diffuse;
|
|
@@ -6518,7 +6534,7 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
|
|
|
6518
6534
|
|
|
6519
6535
|
return lightColor;
|
|
6520
6536
|
}
|
|
6521
|
-
`;var
|
|
6537
|
+
`;var ut=`struct phongMaterialUniforms {
|
|
6522
6538
|
unlit: u32,
|
|
6523
6539
|
ambient: f32,
|
|
6524
6540
|
diffuse: f32,
|
|
@@ -6641,7 +6657,7 @@ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace
|
|
|
6641
6657
|
}
|
|
6642
6658
|
return lightColor;
|
|
6643
6659
|
}
|
|
6644
|
-
`;var
|
|
6660
|
+
`;var vl=[38.25,38.25,38.25],ri={props:{},name:"gouraudMaterial",bindingLayout:[{name:"gouraudMaterial",group:3}],vs:ft.replace("phongMaterial","gouraudMaterial"),fs:ct.replace("phongMaterial","gouraudMaterial"),source:ut.replaceAll("phongMaterial","gouraudMaterial"),defines:{LIGHTING_VERTEX:!0},dependencies:[F,me],uniformTypes:{unlit:"i32",ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>"},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6,shininess:32,specularColor:vl},getUniforms(e){return{...ri.defaultUniforms,...e}}};var _l=[38.25,38.25,38.25],oi={name:"phongMaterial",firstBindingSlot:0,bindingLayout:[{name:"phongMaterial",group:3}],dependencies:[F,me],source:ut,vs:ct,fs:ft,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:_l},getUniforms(e){return{...oi.defaultUniforms,...e}}};var Ar=`layout(std140) uniform waterMaterialUniforms {
|
|
6645
6661
|
uniform float time;
|
|
6646
6662
|
uniform vec3 baseColor;
|
|
6647
6663
|
uniform float opacity;
|
|
@@ -6661,7 +6677,7 @@ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace
|
|
|
6661
6677
|
uniform float waveBFrequency;
|
|
6662
6678
|
uniform float waveBAmplitude;
|
|
6663
6679
|
} waterMaterial;
|
|
6664
|
-
`,
|
|
6680
|
+
`,Rr=`layout(std140) uniform waterMaterialUniforms {
|
|
6665
6681
|
uniform float time;
|
|
6666
6682
|
uniform vec3 baseColor;
|
|
6667
6683
|
uniform float opacity;
|
|
@@ -6865,7 +6881,7 @@ vec4 water_getColor(
|
|
|
6865
6881
|
uv
|
|
6866
6882
|
);
|
|
6867
6883
|
}
|
|
6868
|
-
`;var
|
|
6884
|
+
`;var Tr=`struct waterMaterialUniforms {
|
|
6869
6885
|
time: f32,
|
|
6870
6886
|
baseColor: vec3<f32>,
|
|
6871
6887
|
opacity: f32,
|
|
@@ -7089,7 +7105,7 @@ fn water_getColor(
|
|
|
7089
7105
|
uv
|
|
7090
7106
|
);
|
|
7091
7107
|
}
|
|
7092
|
-
`;var P={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},
|
|
7108
|
+
`;var P={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},gt={name:"waterMaterial",firstBindingSlot:0,bindingLayout:[{name:"waterMaterial",group:3}],dependencies:[F],source:Tr,vs:Ar,fs:Rr,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:P,getUniforms(e,t=P){let{mapping:i,...n}=e||{},r=bl(t);return n.time!==void 0&&(r.time=n.time),n.opacity!==void 0&&(r.opacity=n.opacity),n.fresnelPower!==void 0&&(r.fresnelPower=n.fresnelPower),n.specularIntensity!==void 0&&(r.specularIntensity=n.specularIntensity),n.normalStrength!==void 0&&(r.normalStrength=n.normalStrength),n.coordinateScale!==void 0&&(r.coordinateScale=[Number(n.coordinateScale[0]),Number(n.coordinateScale[1])]),n.coordinateOffset!==void 0&&(r.coordinateOffset=[Number(n.coordinateOffset[0]),Number(n.coordinateOffset[1])]),n.waveASpeed!==void 0&&(r.waveASpeed=n.waveASpeed),n.waveAFrequency!==void 0&&(r.waveAFrequency=n.waveAFrequency),n.waveAAmplitude!==void 0&&(r.waveAAmplitude=n.waveAAmplitude),n.waveBSpeed!==void 0&&(r.waveBSpeed=n.waveBSpeed),n.waveBFrequency!==void 0&&(r.waveBFrequency=n.waveBFrequency),n.waveBAmplitude!==void 0&&(r.waveBAmplitude=n.waveBAmplitude),n.baseColor&&(r.baseColor=dt(n.baseColor)),n.fresnelColor&&(r.fresnelColor=dt(n.fresnelColor)),n.waveADirection&&(r.waveADirection=pt(n.waveADirection)),n.waveBDirection&&(r.waveBDirection=pt(n.waveBDirection)),i!==void 0&&(r.mappingMode=i==="world"?1:i==="object"?2:0),r}};function bl(e){return{time:e.time??P.time,baseColor:e.baseColor?dt(e.baseColor):P.baseColor,opacity:e.opacity??P.opacity,fresnelColor:e.fresnelColor?dt(e.fresnelColor):P.fresnelColor,fresnelPower:e.fresnelPower??P.fresnelPower,specularIntensity:e.specularIntensity??P.specularIntensity,normalStrength:e.normalStrength??P.normalStrength,mappingMode:e.mappingMode??P.mappingMode,coordinateScale:e.coordinateScale?[Number(e.coordinateScale[0]),Number(e.coordinateScale[1])]:P.coordinateScale,coordinateOffset:e.coordinateOffset?[Number(e.coordinateOffset[0]),Number(e.coordinateOffset[1])]:P.coordinateOffset,waveADirection:e.waveADirection?pt(e.waveADirection):P.waveADirection,waveASpeed:e.waveASpeed??P.waveASpeed,waveAFrequency:e.waveAFrequency??P.waveAFrequency,waveAAmplitude:e.waveAAmplitude??P.waveAAmplitude,waveBDirection:e.waveBDirection?pt(e.waveBDirection):P.waveBDirection,waveBSpeed:e.waveBSpeed??P.waveBSpeed,waveBFrequency:e.waveBFrequency??P.waveBFrequency,waveBAmplitude:e.waveBAmplitude??P.waveBAmplitude}}function dt(e){let t=[Number(e[0]),Number(e[1]),Number(e[2])];return Math.max(...t.map(n=>Math.abs(n)))>1&&(t[0]/=255,t[1]/=255,t[2]/=255),t}function pt(e){let t=Number(e[0]),i=Number(e[1]),n=Math.hypot(t,i);return n===0?[1,0]:[t/n,i/n]}var Er=`struct riverWaterMaterialUniforms {
|
|
7093
7109
|
enabled: i32,
|
|
7094
7110
|
flowDirection: vec2<f32>,
|
|
7095
7111
|
skyZenithColor: vec3<f32>,
|
|
@@ -7205,7 +7221,7 @@ fn riverWater_getColorMapped(
|
|
|
7205
7221
|
color = mix(color, reflectedColor, clamp(fresnel * 0.3, 0.0, 0.3));
|
|
7206
7222
|
return vec4<f32>(color, waterMaterial.opacity);
|
|
7207
7223
|
}
|
|
7208
|
-
`,
|
|
7224
|
+
`,Pr=`layout(std140) uniform riverWaterMaterialUniforms {
|
|
7209
7225
|
uniform int enabled;
|
|
7210
7226
|
uniform vec2 flowDirection;
|
|
7211
7227
|
uniform vec3 skyZenithColor;
|
|
@@ -7314,7 +7330,7 @@ vec4 riverWater_getColorMapped(
|
|
|
7314
7330
|
color = mix(color, reflectedColor, clamp(fresnel * 0.3, 0.0, 0.3));
|
|
7315
7331
|
return vec4(color, waterMaterial.opacity);
|
|
7316
7332
|
}
|
|
7317
|
-
`;var
|
|
7333
|
+
`;var Dr={name:"riverWaterMaterial",firstBindingSlot:1,bindingLayout:[{name:"riverWaterMaterial",group:3}],dependencies:[gt],source:Er,fs:Pr,uniformTypes:{enabled:"i32",flowDirection:"vec2<f32>",skyZenithColor:"vec3<f32>",skyUpDirection:"vec3<f32>"},defaultUniforms:{enabled:0,flowDirection:[0,1],skyZenithColor:[.22,.48,.57],skyUpDirection:[0,0,1]},getUniforms(e={},t={}){return{enabled:e.enabled??t.enabled??0,flowDirection:e.flowDirection??t.flowDirection??[0,1],skyZenithColor:e.skyZenithColor??t.skyZenithColor??[.22,.48,.57],skyUpDirection:e.skyUpDirection??t.skyUpDirection??[0,0,1]}}};var ai=`
|
|
7318
7334
|
#ifdef USE_AREA_LIGHT_LTC
|
|
7319
7335
|
uniform sampler2D areaLTCMatrix;
|
|
7320
7336
|
uniform sampler2D areaLTCAmplitude;
|
|
@@ -7394,7 +7410,7 @@ vec3 areaLTC_evaluate(int index, vec3 receiver, vec3 normal, vec3 view, float ro
|
|
|
7394
7410
|
areaLTC_specular(light, receiver, normal, view, roughness, reflectance0, reflectance90);
|
|
7395
7411
|
}
|
|
7396
7412
|
#endif
|
|
7397
|
-
`,
|
|
7413
|
+
`,Nr=`
|
|
7398
7414
|
#ifdef USE_AREA_LIGHT_LTC
|
|
7399
7415
|
@group(2) @binding(auto) var areaLTCMatrix: texture_2d<f32>;
|
|
7400
7416
|
@group(2) @binding(auto) var areaLTCAmplitude: texture_2d<f32>;
|
|
@@ -7470,7 +7486,7 @@ fn areaLTC_evaluate(index: i32, receiver: vec3f, normal: vec3f, view: vec3f, rou
|
|
|
7470
7486
|
areaLTC_specular(light, receiver, normal, view, roughness, reflectance0, reflectance90);
|
|
7471
7487
|
}
|
|
7472
7488
|
#endif
|
|
7473
|
-
`;var
|
|
7489
|
+
`;var si=`
|
|
7474
7490
|
layout(std140) uniform areaLightingUniforms {
|
|
7475
7491
|
int lightCount;
|
|
7476
7492
|
int sampleCount;
|
|
@@ -7502,7 +7518,7 @@ PointLight areaLighting_getSample(int lightIndex, int sampleIndex, vec3 receiver
|
|
|
7502
7518
|
float emissionCosine = max(dot(light.normal, displacement * inversesqrt(distanceSquared)), 0.0);
|
|
7503
7519
|
return PointLight(light.color * (area * emissionCosine / (float(areaLighting.sampleCount) * distanceSquared)), position, vec3(1.0, 0.0, 0.0));
|
|
7504
7520
|
}
|
|
7505
|
-
`,
|
|
7521
|
+
`,Fr=`
|
|
7506
7522
|
struct AreaLightingUniforms {
|
|
7507
7523
|
lightCount: i32,
|
|
7508
7524
|
sampleCount: i32,
|
|
@@ -7535,7 +7551,7 @@ fn areaLighting_getSample(lightIndex: i32, sampleIndex: i32, receiver: vec3f) ->
|
|
|
7535
7551
|
let emissionCosine = max(dot(light.normal, displacement * inverseSqrt(distanceSquared)), 0.0);
|
|
7536
7552
|
return PointLight(light.color * (area * emissionCosine / (f32(areaLighting.sampleCount) * distanceSquared)), position, vec3f(1.0, 0.0, 0.0));
|
|
7537
7553
|
}
|
|
7538
|
-
`;var
|
|
7554
|
+
`;var mt={name:"areaLighting",props:{},uniforms:{},dependencies:[F],defaultUniforms:{lightCount:0,sampleCount:64,lights:Array.from({length:K},ei)},uniformTypes:{lightCount:"i32",sampleCount:"i32",lights:[ot,K]},bindingLayout:[{name:"areaLighting",group:2},{name:"areaLTCMatrix",group:2},{name:"areaLTCAmplitude",group:2}],source:Fr+Nr,vs:si+ai,fs:si+ai,getUniforms(e={}){let t=e.lights||[];return{lightCount:Math.min(t.length,K),sampleCount:e.sampleCount||64,lights:Le(t,e.useByteColors)}}};var Br=`out vec3 pbr_vPosition;
|
|
7539
7555
|
out vec2 pbr_vUV0;
|
|
7540
7556
|
out vec2 pbr_vUV1;
|
|
7541
7557
|
|
|
@@ -7565,7 +7581,7 @@ void pbr_setPositionNormalTangentUV(
|
|
|
7565
7581
|
vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
|
|
7566
7582
|
pbr_vTBN = mat3(tangentW, bitangentW, normalW);
|
|
7567
7583
|
#else // HAS_TANGENTS != 1
|
|
7568
|
-
pbr_vNormal = normalize(vec3(pbrProjection.
|
|
7584
|
+
pbr_vNormal = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
|
|
7569
7585
|
#endif
|
|
7570
7586
|
#endif
|
|
7571
7587
|
|
|
@@ -7577,7 +7593,7 @@ void pbr_setPositionNormalTangentUV(
|
|
|
7577
7593
|
|
|
7578
7594
|
pbr_vUV1 = uv1;
|
|
7579
7595
|
}
|
|
7580
|
-
`,
|
|
7596
|
+
`,Or=`precision highp float;
|
|
7581
7597
|
|
|
7582
7598
|
layout(std140) uniform pbrMaterialUniforms {
|
|
7583
7599
|
// Material is unlit
|
|
@@ -8568,7 +8584,9 @@ vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {
|
|
|
8568
8584
|
}
|
|
8569
8585
|
|
|
8570
8586
|
// Visibility for the first four spotlights; environment and other lights are unaffected.
|
|
8571
|
-
|
|
8587
|
+
float pbr_ambientVisibility = 1.0;
|
|
8588
|
+
|
|
8589
|
+
vec4 pbr_filterColorWithShadows(vec4 vertexColor, float directionalVisibility, vec4 pointVisibility, vec4 spotVisibility)
|
|
8572
8590
|
{
|
|
8573
8591
|
vec2 baseColorUV = getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform);
|
|
8574
8592
|
vec2 metallicRoughnessUV = getMaterialUV(
|
|
@@ -8664,7 +8682,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
8664
8682
|
color.rgb = baseColor.rgb;
|
|
8665
8683
|
#ifdef HAS_LIGHTMAP
|
|
8666
8684
|
if (pbrMaterial.lightmapMapEnabled) {
|
|
8667
|
-
color *= lightmapIrradiance / M_PI;
|
|
8685
|
+
color *= lightmapIrradiance / M_PI * pbr_ambientVisibility;
|
|
8668
8686
|
#ifdef HAS_OCCLUSIONMAP
|
|
8669
8687
|
if (pbrMaterial.occlusionMapEnabled) {
|
|
8670
8688
|
float ao = texture(pbr_occlusionSampler, occlusionUV).r;
|
|
@@ -8766,12 +8784,12 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
8766
8784
|
|
|
8767
8785
|
#ifdef USE_LIGHTS
|
|
8768
8786
|
PBRInfo_setAmbientLight(pbrInfo);
|
|
8769
|
-
color += calculateFinalColor(pbrInfo, lighting.ambientColor);
|
|
8787
|
+
color += calculateFinalColor(pbrInfo, lighting.ambientColor * pbr_ambientVisibility);
|
|
8770
8788
|
|
|
8771
8789
|
for(int i = 0; i < lighting.directionalLightCount; i++) {
|
|
8772
8790
|
if (i < lighting.directionalLightCount) {
|
|
8773
8791
|
PBRInfo_setDirectionalLight(pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
8774
|
-
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
|
|
8792
|
+
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color * (i == 0 ? clamp(directionalVisibility, 0.0, 1.0) : 1.0));
|
|
8775
8793
|
}
|
|
8776
8794
|
}
|
|
8777
8795
|
|
|
@@ -8779,7 +8797,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
8779
8797
|
if (i < lighting.pointLightCount) {
|
|
8780
8798
|
PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
|
|
8781
8799
|
float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
|
|
8782
|
-
color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
|
|
8800
|
+
color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color * (i < 4 ? clamp(pointVisibility[min(i, 3)], 0.0, 1.0) : 1.0) / attenuation);
|
|
8783
8801
|
}
|
|
8784
8802
|
}
|
|
8785
8803
|
|
|
@@ -8805,6 +8823,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
8805
8823
|
}
|
|
8806
8824
|
#endif
|
|
8807
8825
|
|
|
8826
|
+
vec3 indirectBaseColor = color;
|
|
8808
8827
|
#ifdef USE_IBL
|
|
8809
8828
|
if (pbrMaterial.IBLenabled) {
|
|
8810
8829
|
color += getIBLContribution(pbrInfo, n, reflection);
|
|
@@ -8813,6 +8832,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
8813
8832
|
|
|
8814
8833
|
// The pinned KHR_lightmap draft explicitly defines c_diff = (1 - metallic) * baseColor.
|
|
8815
8834
|
color += baseColor.rgb * (1.0 - metallic) * lightmapIrradiance / M_PI;
|
|
8835
|
+
color = indirectBaseColor + (color - indirectBaseColor) * pbr_ambientVisibility;
|
|
8816
8836
|
|
|
8817
8837
|
#ifdef HAS_OCCLUSIONMAP
|
|
8818
8838
|
if (pbrMaterial.occlusionMapEnabled) {
|
|
@@ -9045,7 +9065,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
9045
9065
|
PBRInfo_setAmbientLight(pbrInfo);
|
|
9046
9066
|
color += calculateMaterialLightColor(
|
|
9047
9067
|
pbrInfo,
|
|
9048
|
-
lighting.ambientColor,
|
|
9068
|
+
lighting.ambientColor * pbr_ambientVisibility,
|
|
9049
9069
|
clearcoatNormal,
|
|
9050
9070
|
clearcoatFactor,
|
|
9051
9071
|
clearcoatRoughness,
|
|
@@ -9061,7 +9081,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
9061
9081
|
PBRInfo_setDirectionalLight(pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
9062
9082
|
color += calculateMaterialLightColor(
|
|
9063
9083
|
pbrInfo,
|
|
9064
|
-
lighting_getDirectionalLight(i).color,
|
|
9084
|
+
lighting_getDirectionalLight(i).color * (i == 0 ? clamp(directionalVisibility, 0.0, 1.0) : 1.0),
|
|
9065
9085
|
clearcoatNormal,
|
|
9066
9086
|
clearcoatFactor,
|
|
9067
9087
|
clearcoatRoughness,
|
|
@@ -9072,7 +9092,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
9072
9092
|
);
|
|
9073
9093
|
color += calculateDiffuseTransmissionLight(
|
|
9074
9094
|
pbrInfo,
|
|
9075
|
-
lighting_getDirectionalLight(i).color,
|
|
9095
|
+
lighting_getDirectionalLight(i).color * (i == 0 ? clamp(directionalVisibility, 0.0, 1.0) : 1.0),
|
|
9076
9096
|
diffuseTransmissionColor,
|
|
9077
9097
|
diffuseTransmission,
|
|
9078
9098
|
multiscatterColor,
|
|
@@ -9088,7 +9108,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
9088
9108
|
float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
|
|
9089
9109
|
color += calculateMaterialLightColor(
|
|
9090
9110
|
pbrInfo,
|
|
9091
|
-
lighting_getPointLight(i).color / attenuation,
|
|
9111
|
+
lighting_getPointLight(i).color * (i < 4 ? clamp(pointVisibility[min(i, 3)], 0.0, 1.0) : 1.0) / attenuation,
|
|
9092
9112
|
clearcoatNormal,
|
|
9093
9113
|
clearcoatFactor,
|
|
9094
9114
|
clearcoatRoughness,
|
|
@@ -9099,7 +9119,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
9099
9119
|
);
|
|
9100
9120
|
color += calculateDiffuseTransmissionLight(
|
|
9101
9121
|
pbrInfo,
|
|
9102
|
-
lighting_getPointLight(i).color / attenuation,
|
|
9122
|
+
lighting_getPointLight(i).color * (i < 4 ? clamp(pointVisibility[min(i, 3)], 0.0, 1.0) : 1.0) / attenuation,
|
|
9103
9123
|
diffuseTransmissionColor,
|
|
9104
9124
|
diffuseTransmission,
|
|
9105
9125
|
multiscatterColor,
|
|
@@ -9168,6 +9188,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
9168
9188
|
}
|
|
9169
9189
|
#endif
|
|
9170
9190
|
|
|
9191
|
+
vec3 indirectBaseColor = color;
|
|
9171
9192
|
// Calculate lighting contribution from image based lighting source (IBL)
|
|
9172
9193
|
#ifdef USE_IBL
|
|
9173
9194
|
if (pbrMaterial.IBLenabled) {
|
|
@@ -9202,6 +9223,8 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
9202
9223
|
(1.0 - diffuseTransmission) * baseLayerEnergy * lightmapIrradiance / M_PI;
|
|
9203
9224
|
#endif
|
|
9204
9225
|
|
|
9226
|
+
color = indirectBaseColor + (color - indirectBaseColor) * pbr_ambientVisibility;
|
|
9227
|
+
|
|
9205
9228
|
// Apply optional PBR terms for additional (optional) shading
|
|
9206
9229
|
#ifdef HAS_OCCLUSIONMAP
|
|
9207
9230
|
if (pbrMaterial.occlusionMapEnabled) {
|
|
@@ -9263,10 +9286,25 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
9263
9286
|
return vec4(applySceneColorManagement(color), alpha);
|
|
9264
9287
|
}
|
|
9265
9288
|
|
|
9289
|
+
// Depth-only passes use the same base-color alpha, vertex color and UV transform.
|
|
9290
|
+
void pbr_discardMaskedFragment(vec4 vertexColor) {
|
|
9291
|
+
#ifdef ALPHA_CUTOFF
|
|
9292
|
+
float alpha = pbrMaterial.baseColorFactor.a * vertexColor.a;
|
|
9293
|
+
#ifdef HAS_BASECOLORMAP
|
|
9294
|
+
alpha *= texture(pbr_baseColorSampler, getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform)).a;
|
|
9295
|
+
#endif
|
|
9296
|
+
if (alpha < pbrMaterial.alphaCutoff) {discard;}
|
|
9297
|
+
#endif
|
|
9298
|
+
}
|
|
9299
|
+
|
|
9300
|
+
vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility) {
|
|
9301
|
+
return pbr_filterColorWithShadows(vertexColor, 1.0, vec4(1.0), spotVisibility);
|
|
9302
|
+
}
|
|
9303
|
+
|
|
9266
9304
|
vec4 pbr_filterColor(vec4 vertexColor) {
|
|
9267
9305
|
return pbr_filterColorWithSpotShadows(vertexColor, vec4(1.0));
|
|
9268
9306
|
}
|
|
9269
|
-
`;var
|
|
9307
|
+
`;var Ur=`#ifdef DOUBLE_SIDED
|
|
9270
9308
|
var<private> pbr_frontFacing: bool = true;
|
|
9271
9309
|
#endif
|
|
9272
9310
|
struct PBRFragmentInputs {
|
|
@@ -10381,7 +10419,9 @@ fn calculateFinalColor(pbrInfo: PBRInfo, lightColor: vec3<f32>) -> vec3<f32> {
|
|
|
10381
10419
|
}
|
|
10382
10420
|
|
|
10383
10421
|
// Visibility for the first four spotlights; environment and other lights are unaffected.
|
|
10384
|
-
|
|
10422
|
+
var<private> pbr_ambientVisibility: f32 = 1.0;
|
|
10423
|
+
|
|
10424
|
+
fn pbr_filterColorWithShadows(vertexColor: vec4<f32>, directionalVisibility: f32, pointVisibility: vec4f, spotVisibility: vec4f) -> vec4<f32> {
|
|
10385
10425
|
let baseColorUV = getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform);
|
|
10386
10426
|
let metallicRoughnessUV = getMaterialUV(
|
|
10387
10427
|
pbrMaterial.metallicRoughnessUVSet,
|
|
@@ -10474,7 +10514,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
10474
10514
|
color = baseColor.rgb;
|
|
10475
10515
|
#ifdef HAS_LIGHTMAP
|
|
10476
10516
|
if (pbrMaterial.lightmapMapEnabled != 0u) {
|
|
10477
|
-
color *= lightmapIrradiance / M_PI;
|
|
10517
|
+
color *= lightmapIrradiance / M_PI * pbr_ambientVisibility;
|
|
10478
10518
|
#ifdef HAS_OCCLUSIONMAP
|
|
10479
10519
|
if (pbrMaterial.occlusionMapEnabled != 0) {
|
|
10480
10520
|
let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, occlusionUV).r;
|
|
@@ -10577,12 +10617,12 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
10577
10617
|
|
|
10578
10618
|
#ifdef USE_LIGHTS
|
|
10579
10619
|
PBRInfo_setAmbientLight(&pbrInfo);
|
|
10580
|
-
color += calculateFinalColor(pbrInfo, lighting.ambientColor);
|
|
10620
|
+
color += calculateFinalColor(pbrInfo, lighting.ambientColor * pbr_ambientVisibility);
|
|
10581
10621
|
|
|
10582
10622
|
for (var i = 0; i < lighting.directionalLightCount; i++) {
|
|
10583
10623
|
if (i < lighting.directionalLightCount) {
|
|
10584
10624
|
PBRInfo_setDirectionalLight(&pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
10585
|
-
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
|
|
10625
|
+
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color * select(1.0, clamp(directionalVisibility, 0.0, 1.0), i == 0));
|
|
10586
10626
|
}
|
|
10587
10627
|
}
|
|
10588
10628
|
|
|
@@ -10593,7 +10633,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
10593
10633
|
lighting_getPointLight(i),
|
|
10594
10634
|
distance(lighting_getPointLight(i).position, fragmentInputs.pbr_vPosition)
|
|
10595
10635
|
);
|
|
10596
|
-
color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
|
|
10636
|
+
color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color * select(1.0, clamp(pointVisibility[min(i, 3)], 0.0, 1.0), i < 4) / attenuation);
|
|
10597
10637
|
}
|
|
10598
10638
|
}
|
|
10599
10639
|
|
|
@@ -10622,7 +10662,8 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
10622
10662
|
}
|
|
10623
10663
|
#endif
|
|
10624
10664
|
|
|
10625
|
-
|
|
10665
|
+
let indirectBaseColor = color;
|
|
10666
|
+
#ifdef USE_IBL
|
|
10626
10667
|
if (pbrMaterial.IBLenabled != 0) {
|
|
10627
10668
|
color += getIBLContribution(pbrInfo, n, reflection);
|
|
10628
10669
|
}
|
|
@@ -10630,6 +10671,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
10630
10671
|
|
|
10631
10672
|
// The pinned KHR_lightmap draft explicitly defines c_diff = (1 - metallic) * baseColor.
|
|
10632
10673
|
color += baseColor.rgb * (1.0 - metallic) * lightmapIrradiance / M_PI;
|
|
10674
|
+
color = indirectBaseColor + (color - indirectBaseColor) * pbr_ambientVisibility;
|
|
10633
10675
|
|
|
10634
10676
|
#ifdef HAS_OCCLUSIONMAP
|
|
10635
10677
|
if (pbrMaterial.occlusionMapEnabled != 0) {
|
|
@@ -10928,7 +10970,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
10928
10970
|
PBRInfo_setAmbientLight(&pbrInfo);
|
|
10929
10971
|
color += calculateMaterialLightColor(
|
|
10930
10972
|
pbrInfo,
|
|
10931
|
-
lighting.ambientColor,
|
|
10973
|
+
lighting.ambientColor * pbr_ambientVisibility,
|
|
10932
10974
|
clearcoatNormal,
|
|
10933
10975
|
clearcoatFactor,
|
|
10934
10976
|
clearcoatRoughness,
|
|
@@ -10944,7 +10986,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
10944
10986
|
PBRInfo_setDirectionalLight(&pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
10945
10987
|
color += calculateMaterialLightColor(
|
|
10946
10988
|
pbrInfo,
|
|
10947
|
-
lighting_getDirectionalLight(i).color,
|
|
10989
|
+
lighting_getDirectionalLight(i).color * select(1.0, clamp(directionalVisibility, 0.0, 1.0), i == 0),
|
|
10948
10990
|
clearcoatNormal,
|
|
10949
10991
|
clearcoatFactor,
|
|
10950
10992
|
clearcoatRoughness,
|
|
@@ -10955,7 +10997,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
10955
10997
|
);
|
|
10956
10998
|
color += calculateDiffuseTransmissionLight(
|
|
10957
10999
|
pbrInfo,
|
|
10958
|
-
lighting_getDirectionalLight(i).color,
|
|
11000
|
+
lighting_getDirectionalLight(i).color * select(1.0, clamp(directionalVisibility, 0.0, 1.0), i == 0),
|
|
10959
11001
|
diffuseTransmissionColor,
|
|
10960
11002
|
diffuseTransmission,
|
|
10961
11003
|
multiscatterColor,
|
|
@@ -10974,7 +11016,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
10974
11016
|
);
|
|
10975
11017
|
color += calculateMaterialLightColor(
|
|
10976
11018
|
pbrInfo,
|
|
10977
|
-
lighting_getPointLight(i).color / attenuation,
|
|
11019
|
+
lighting_getPointLight(i).color * select(1.0, clamp(pointVisibility[min(i, 3)], 0.0, 1.0), i < 4) / attenuation,
|
|
10978
11020
|
clearcoatNormal,
|
|
10979
11021
|
clearcoatFactor,
|
|
10980
11022
|
clearcoatRoughness,
|
|
@@ -10985,7 +11027,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
10985
11027
|
);
|
|
10986
11028
|
color += calculateDiffuseTransmissionLight(
|
|
10987
11029
|
pbrInfo,
|
|
10988
|
-
lighting_getPointLight(i).color / attenuation,
|
|
11030
|
+
lighting_getPointLight(i).color * select(1.0, clamp(pointVisibility[min(i, 3)], 0.0, 1.0), i < 4) / attenuation,
|
|
10989
11031
|
diffuseTransmissionColor,
|
|
10990
11032
|
diffuseTransmission,
|
|
10991
11033
|
multiscatterColor,
|
|
@@ -11054,6 +11096,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
11054
11096
|
}
|
|
11055
11097
|
#endif
|
|
11056
11098
|
|
|
11099
|
+
let indirectBaseColor = color;
|
|
11057
11100
|
// Calculate lighting contribution from image based lighting source (IBL)
|
|
11058
11101
|
#ifdef USE_IBL
|
|
11059
11102
|
if (pbrMaterial.IBLenabled != 0) {
|
|
@@ -11088,6 +11131,8 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
11088
11131
|
(1.0 - diffuseTransmission) * baseLayerEnergy * lightmapIrradiance / M_PI;
|
|
11089
11132
|
#endif
|
|
11090
11133
|
|
|
11134
|
+
color = indirectBaseColor + (color - indirectBaseColor) * pbr_ambientVisibility;
|
|
11135
|
+
|
|
11091
11136
|
// Apply optional PBR terms for additional (optional) shading
|
|
11092
11137
|
#ifdef HAS_OCCLUSIONMAP
|
|
11093
11138
|
if (pbrMaterial.occlusionMapEnabled != 0) {
|
|
@@ -11150,16 +11195,31 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
11150
11195
|
return vec4<f32>(applySceneColorManagement(color), alpha);
|
|
11151
11196
|
}
|
|
11152
11197
|
|
|
11198
|
+
// Depth-only passes use the same base-color alpha, vertex color and UV transform.
|
|
11199
|
+
fn pbr_discardMaskedFragment(vertexColor: vec4f) {
|
|
11200
|
+
#ifdef ALPHA_CUTOFF
|
|
11201
|
+
var alpha = pbrMaterial.baseColorFactor.a * vertexColor.a;
|
|
11202
|
+
#ifdef HAS_BASECOLORMAP
|
|
11203
|
+
alpha *= textureSample(pbr_baseColorSampler, pbr_baseColorSamplerSampler, getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform)).a;
|
|
11204
|
+
#endif
|
|
11205
|
+
if (alpha < pbrMaterial.alphaCutoff) {discard;}
|
|
11206
|
+
#endif
|
|
11207
|
+
}
|
|
11208
|
+
|
|
11209
|
+
fn pbr_filterColorWithSpotShadows(vertexColor: vec4f, spotVisibility: vec4f) -> vec4f {
|
|
11210
|
+
return pbr_filterColorWithShadows(vertexColor, 1.0, vec4f(1.0), spotVisibility);
|
|
11211
|
+
}
|
|
11212
|
+
|
|
11153
11213
|
fn pbr_filterColor(vertexColor: vec4<f32>) -> vec4<f32> {
|
|
11154
11214
|
return pbr_filterColorWithSpotShadows(vertexColor, vec4f(1.0));
|
|
11155
11215
|
}
|
|
11156
|
-
`;var
|
|
11216
|
+
`;var kr=`layout(std140) uniform pbrProjectionUniforms {
|
|
11157
11217
|
mat4 modelViewProjectionMatrix;
|
|
11158
11218
|
mat4 modelMatrix;
|
|
11159
11219
|
mat4 normalMatrix;
|
|
11160
11220
|
vec3 camera;
|
|
11161
11221
|
} pbrProjection;
|
|
11162
|
-
`,
|
|
11222
|
+
`,xl=`struct pbrProjectionUniforms {
|
|
11163
11223
|
modelViewProjectionMatrix: mat4x4<f32>,
|
|
11164
11224
|
modelMatrix: mat4x4<f32>,
|
|
11165
11225
|
normalMatrix: mat4x4<f32>,
|
|
@@ -11167,7 +11227,7 @@ fn pbr_filterColor(vertexColor: vec4<f32>) -> vec4<f32> {
|
|
|
11167
11227
|
};
|
|
11168
11228
|
|
|
11169
11229
|
@group(0) @binding(auto) var<uniform> pbrProjection: pbrProjectionUniforms;
|
|
11170
|
-
`,
|
|
11230
|
+
`,zr={name:"pbrProjection",bindingLayout:[{name:"pbrProjection",group:0}],source:xl,vs:kr,fs:kr,getUniforms:e=>e,uniformTypes:{modelViewProjectionMatrix:"mat4x4<f32>",modelMatrix:"mat4x4<f32>",normalMatrix:"mat4x4<f32>",camera:"vec3<f32>"}};var li={NONE:0,REINHARD:1,KHRONOS_PBR_NEUTRAL:2,ACES:3},Vr=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],Gr=`layout(std140) uniform pbrSceneUniforms {
|
|
11171
11231
|
float exposure;
|
|
11172
11232
|
highp int toneMapMode;
|
|
11173
11233
|
float environmentIntensity;
|
|
@@ -11182,7 +11242,7 @@ fn pbr_filterColor(vertexColor: vec4<f32>) -> vec4<f32> {
|
|
|
11182
11242
|
#ifdef USE_TRANSMISSION_FRAMEBUFFER
|
|
11183
11243
|
uniform sampler2D pbr_transmissionFramebufferSampler;
|
|
11184
11244
|
#endif
|
|
11185
|
-
`,
|
|
11245
|
+
`,Sl=`struct pbrSceneUniforms {
|
|
11186
11246
|
exposure: f32,
|
|
11187
11247
|
toneMapMode: i32,
|
|
11188
11248
|
environmentIntensity: f32,
|
|
@@ -11200,7 +11260,7 @@ uniform sampler2D pbr_transmissionFramebufferSampler;
|
|
|
11200
11260
|
@group(1) @binding(auto) var pbr_transmissionFramebufferSampler: texture_2d<f32>;
|
|
11201
11261
|
@group(1) @binding(auto) var pbr_transmissionFramebufferSamplerSampler: sampler;
|
|
11202
11262
|
#endif
|
|
11203
|
-
`,
|
|
11263
|
+
`,ht={name:"pbrScene",bindingLayout:[{name:"pbrScene",group:1},{name:"pbr_transmissionFramebufferSampler",group:1}],source:Sl,vs:Gr,fs:Gr,getUniforms:e=>e,uniformTypes:{exposure:"f32",toneMapMode:"i32",environmentIntensity:"f32",environmentRotation:"f32",environmentMipCount:"f32",outputEncoding:"i32",framebufferSize:"vec2<f32>",viewMatrix:"mat4x4<f32>",projectionMatrix:"mat4x4<f32>"},defaultUniforms:{exposure:1,toneMapMode:li.KHRONOS_PBR_NEUTRAL,environmentIntensity:1,environmentRotation:Math.PI*.5,environmentMipCount:1,outputEncoding:1,framebufferSize:[1,1],viewMatrix:Vr,projectionMatrix:Vr}};var U={props:{},uniforms:{},defaultUniforms:{unlit:!1,baseColorMapEnabled:!1,baseColorFactor:[1,1,1,1],normalMapEnabled:!1,normalScale:1,emissiveMapEnabled:!1,lightmapMapEnabled:!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,lightmapIntensity:1,scatterStrengthFactor:0,dispersion:0,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,lightmapUVSet:0,emissiveUVTransform:[1,0,0,0,1,0,0,0,1],lightmapUVTransform:[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],bumpFactor:1,bumpMapEnabled:!1,diffuseTransmissionFactor:0,diffuseTransmissionMapEnabled:!1,diffuseTransmissionColorFactor:[1,1,1],diffuseTransmissionColorMapEnabled:!1,multiscatterColorFactor:[0,0,0],multiscatterColorMapEnabled:!1,scatterAnisotropy:0,bumpUVSet:0,bumpUVTransform:[1,0,0,0,1,0,0,0,1],diffuseTransmissionUVSet:0,diffuseTransmissionUVTransform:[1,0,0,0,1,0,0,0,1],diffuseTransmissionColorUVSet:0,diffuseTransmissionColorUVTransform:[1,0,0,0,1,0,0,0,1],multiscatterColorUVSet:0,multiscatterColorUVTransform:[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_lightmapSampler",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},{name:"pbr_bumpSampler",group:3},{name:"pbr_diffuseTransmissionSampler",group:3},{name:"pbr_diffuseTransmissionColorSampler",group:3},{name:"pbr_multiscatterColorSampler",group:3}],dependencies:[F,mt,lt,zr,ht],source:Ur,vs:Br,fs:Or,defines:{LIGHTING_FRAGMENT:!0,HAS_NORMALMAP:!1,HAS_EMISSIVEMAP:!1,HAS_LIGHTMAP:!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,HAS_BUMPMAP:!1,HAS_DIFFUSETRANSMISSIONMAP:!1,HAS_DIFFUSETRANSMISSIONCOLORMAP:!1,HAS_MULTISCATTERCOLORMAP:!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",dispersion:"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>",bumpFactor:"f32",bumpMapEnabled:"i32",diffuseTransmissionFactor:"f32",diffuseTransmissionMapEnabled:"i32",diffuseTransmissionColorFactor:"vec3<f32>",diffuseTransmissionColorMapEnabled:"i32",multiscatterColorFactor:"vec3<f32>",multiscatterColorMapEnabled:"i32",scatterAnisotropy:"f32",bumpUVSet:"i32",bumpUVTransform:"mat3x3<f32>",diffuseTransmissionUVSet:"i32",diffuseTransmissionUVTransform:"mat3x3<f32>",diffuseTransmissionColorUVSet:"i32",diffuseTransmissionColorUVTransform:"mat3x3<f32>",multiscatterColorUVSet:"i32",multiscatterColorUVTransform:"mat3x3<f32>",lightmapMapEnabled:"i32",lightmapIntensity:"f32",lightmapUVSet:"i32",lightmapUVTransform:"mat3x3<f32>",scatterStrengthFactor:"f32"}};var Y={name:"valueNoise",fs:`
|
|
11204
11264
|
float valueNoise_hash(vec2 cell) {
|
|
11205
11265
|
vec3 value = fract(vec3(cell.x, cell.y, cell.x) * 0.1031);
|
|
11206
11266
|
value += dot(value, value.yzx + 33.33);
|
|
@@ -11258,7 +11318,7 @@ fn valueNoise_noise3(position: vec3f) -> f32 {
|
|
|
11258
11318
|
mix(valueNoise_hash3(cell + vec3f(0.0, 1.0, 1.0)), valueNoise_hash3(cell + vec3f(1.0)), blend.x), blend.y);
|
|
11259
11319
|
return mix(bottom, top, blend.z);
|
|
11260
11320
|
}
|
|
11261
|
-
`};var
|
|
11321
|
+
`};var vt={name:"heightFogFunctions",dependencies:[Y],fs:`
|
|
11262
11322
|
float heightFog_getRayTransmittance(float rayLength, float cameraHeight, float fragmentHeight, float density, float baseHeight, float heightFalloff) {
|
|
11263
11323
|
float startHeight = (cameraHeight - baseHeight) * max(heightFalloff, 0.0);
|
|
11264
11324
|
float endHeight = (fragmentHeight - baseHeight) * max(heightFalloff, 0.0);
|
|
@@ -11358,7 +11418,7 @@ fn heightFog_getSpatialTransmittance(camera: vec3f, position: vec3f, upDirection
|
|
|
11358
11418
|
return transmittance;
|
|
11359
11419
|
}
|
|
11360
11420
|
|
|
11361
|
-
`};var
|
|
11421
|
+
`};var Hr={name:"heightFog",dependencies:[vt],bindingLayout:[{name:"heightFog",group:3}],uniformTypes:{color:"vec3<f32>",density:"f32",baseHeight:"f32",heightFalloff:"f32",variation:"f32",wispScale:"f32",velocity:"vec3<f32>",time:"f32",evolutionSpeed:"f32"},defaultUniforms:{color:[.65,.72,.78],density:0,baseHeight:0,heightFalloff:.01,variation:0,wispScale:160,velocity:[0,0,0],time:0,evolutionSpeed:0},getUniforms(e={}){return e},fs:`
|
|
11362
11422
|
layout(std140) uniform heightFogUniforms {
|
|
11363
11423
|
vec3 color;
|
|
11364
11424
|
float density;
|
|
@@ -11397,7 +11457,7 @@ fn heightFog_getTransmittance(position: vec3<f32>, cameraPosition: vec3<f32>) ->
|
|
|
11397
11457
|
fn heightFog_getColor(color: vec4<f32>, position: vec3<f32>, cameraPosition: vec3<f32>) -> vec4<f32> {
|
|
11398
11458
|
return vec4<f32>(mix(heightFog.color, color.rgb, heightFog_getTransmittance(position, cameraPosition)), color.a);
|
|
11399
11459
|
}
|
|
11400
|
-
`};var
|
|
11460
|
+
`};var Wr=`
|
|
11401
11461
|
layout(std140) uniform patternFillUniforms {
|
|
11402
11462
|
int patternType;
|
|
11403
11463
|
float spacing;
|
|
@@ -11438,7 +11498,7 @@ float patternFill_getCoverage(vec2 coordinates) {
|
|
|
11438
11498
|
if (patternFill.patternType == 1) return first + second - first * second;
|
|
11439
11499
|
return first;
|
|
11440
11500
|
}
|
|
11441
|
-
`,
|
|
11501
|
+
`,jr=`
|
|
11442
11502
|
struct patternFillUniforms {
|
|
11443
11503
|
patternType: i32,
|
|
11444
11504
|
spacing: f32,
|
|
@@ -11478,7 +11538,7 @@ fn patternFill_getCoverage(coordinates: vec2<f32>) -> f32 {
|
|
|
11478
11538
|
if (patternFill.patternType == 1) { return first + second - first * second; }
|
|
11479
11539
|
return first;
|
|
11480
11540
|
}
|
|
11481
|
-
`;var
|
|
11541
|
+
`;var ci={patternType:0,spacing:8,width:.12,angle:Math.PI/4,offset:[0,0]},qr={name:"patternFill",firstBindingSlot:0,bindingLayout:[{name:"patternFill",group:3}],source:jr,fs:Wr,uniformTypes:{patternType:"i32",spacing:"f32",width:"f32",angle:"f32",offset:"vec2<f32>"},defaultUniforms:ci,getUniforms(e={},t=ci){let i={...ci,...t};return e.pattern!==void 0&&(i.patternType={hatch:0,crosshatch:1,dots:2}[e.pattern]),e.spacing!==void 0&&(i.spacing=Math.max(e.spacing,1e-4)),e.width!==void 0&&(i.width=Math.min(1,Math.max(0,e.width))),e.angle!==void 0&&(i.angle=e.angle),e.offset!==void 0&&(i.offset=e.offset),i}};var fi={coreRadius:.12,coreIntensity:1,haloIntensity:.6,falloff:5},$r={name:"pointGlow",firstBindingSlot:0,bindingLayout:[{name:"pointGlow",group:3}],uniformTypes:{coreRadius:"f32",coreIntensity:"f32",haloIntensity:"f32",falloff:"f32"},defaultUniforms:fi,getUniforms(e={},t=fi){let i={...fi,...t};return e.coreRadius!==void 0&&(i.coreRadius=Math.min(1,Math.max(0,e.coreRadius))),e.coreIntensity!==void 0&&(i.coreIntensity=Math.max(0,e.coreIntensity)),e.haloIntensity!==void 0&&(i.haloIntensity=Math.max(0,e.haloIntensity)),e.falloff!==void 0&&(i.falloff=Math.max(.01,e.falloff)),i},fs:`
|
|
11482
11542
|
layout(std140) uniform pointGlowUniforms {
|
|
11483
11543
|
float coreRadius;
|
|
11484
11544
|
float coreIntensity;
|
|
@@ -11518,7 +11578,7 @@ fn pointGlow_getColor(coordinates: vec2<f32>, tint: vec3<f32>) -> vec3<f32> {
|
|
|
11518
11578
|
let halo = max(0.0, (exp(-pointGlow.falloff * radius * radius) - outer) / (1.0 - outer));
|
|
11519
11579
|
return (vec3<f32>(core * pointGlow.coreIntensity) + tint * halo * pointGlow.haloIntensity) * envelope;
|
|
11520
11580
|
}
|
|
11521
|
-
`};var
|
|
11581
|
+
`};var Kr={name:"precipitation",bindingLayout:[{name:"precipitation",group:3}],uniformTypes:{time:"f32",fallSpeed:"f32",turbulence:"f32",seed:"f32",volumeCenter:"vec3<f32>",volumeSize:"vec3<f32>",wind:"vec2<f32>"},defaultUniforms:{time:0,fallSpeed:20,turbulence:0,seed:29,volumeCenter:[0,0,150],volumeSize:[1200,1600,300],wind:[2,0]},getUniforms(e={}){return e},vs:`
|
|
11522
11582
|
layout(std140) uniform precipitationUniforms {
|
|
11523
11583
|
float time;
|
|
11524
11584
|
float fallSpeed;
|
|
@@ -11581,7 +11641,7 @@ fn precipitation_getFade(position: vec3<f32>) -> f32 {
|
|
|
11581
11641
|
let edge = 0.5 - abs((position - precipitation.volumeCenter) / max(precipitation.volumeSize, vec3<f32>(0.001)));
|
|
11582
11642
|
return smoothstep(0.0, 0.08, min(edge.x, min(edge.y, edge.z)));
|
|
11583
11643
|
}
|
|
11584
|
-
`};var
|
|
11644
|
+
`};var ui={cover:.45,altitude:1e3,thickness:1200,scale:1400,density:.005,time:0,velocity:[14,4],sunDirection:[0,.8,.6],sunColor:[1,.95,.85]},_t={name:"clouds",dependencies:[Y],uniformTypes:{cover:"f32",altitude:"f32",thickness:"f32",scale:"f32",density:"f32",time:"f32",velocity:"vec2<f32>",sunDirection:"vec3<f32>",sunColor:"vec3<f32>"},defaultUniforms:ui,getUniforms(e={},t=ui){return{...ui,...t,...e}},fs:`
|
|
11585
11645
|
layout(std140) uniform cloudsUniforms {
|
|
11586
11646
|
float cover;
|
|
11587
11647
|
float altitude;
|
|
@@ -11732,7 +11792,7 @@ fn clouds_getColor(camera: vec3f, rayDirection: vec3f) -> vec4f {
|
|
|
11732
11792
|
let distanceFade = 1.0 - smoothstep(10000.0, 20000.0, start);
|
|
11733
11793
|
return vec4f(radiance, 1.0 - transmittance) * distanceFade;
|
|
11734
11794
|
}
|
|
11735
|
-
`};var
|
|
11795
|
+
`};var di={enabled:1,sunDirection:[0,.8,.6],sunIntensity:20,haze:1,rayleigh:1,planetRadius:6371e3,exposure:1,groundColor:[.18,.17,.14]},Yr={name:"atmosphere",uniformTypes:{enabled:"f32",sunDirection:"vec3<f32>",sunIntensity:"f32",haze:"f32",rayleigh:"f32",planetRadius:"f32",exposure:"f32",groundColor:"vec3<f32>"},defaultUniforms:di,getUniforms(e={},t=di){return{...di,...t,...e}},fs:`
|
|
11736
11796
|
layout(std140) uniform atmosphereUniforms {
|
|
11737
11797
|
float enabled;
|
|
11738
11798
|
vec3 sunDirection;
|
|
@@ -11924,7 +11984,7 @@ fn atmosphere_getColor(color: vec4f,
|
|
|
11924
11984
|
var scattering: vec3f = vec3f(1.0) - exp(-scatteringSample.radiance * atmosphere.exposure);
|
|
11925
11985
|
return vec4f(color.rgb * scatteringSample.transmittance + scattering, color.a);
|
|
11926
11986
|
}
|
|
11927
|
-
`};function
|
|
11987
|
+
`};function Xr(e,t,i){function n(r,o,a){let s=Math.max(o,0)+Math.max(a,0),l=Math.min(1,Math.max(0,r));if(s===0||i<=0)return l;let c=Math.max(o,0)/s;return c+(l-c)*Math.exp(-s*Math.max(i,0))}return{wetness:n(e.wetness,t.rainfall,t.evaporation),snow:n(e.snow,t.snowfall,t.snowmelt)}}var pi={wetness:0,snow:0,puddles:.8,scale:20,snowColor:[.9,.94,.98],skyColor:[.48,.6,.72]},Zr={name:"surfaceWeather",dependencies:[Y],uniformTypes:{wetness:"f32",snow:"f32",puddles:"f32",scale:"f32",snowColor:"vec3<f32>",skyColor:"vec3<f32>"},defaultUniforms:pi,getUniforms(e={},t=pi){return{...pi,...t,...e}},fs:`
|
|
11928
11988
|
layout(std140) uniform surfaceWeatherUniforms {
|
|
11929
11989
|
float wetness;
|
|
11930
11990
|
float snow;
|
|
@@ -12048,7 +12108,7 @@ fn surfaceWeather_getReflection(position: vec3f,
|
|
|
12048
12108
|
var highlight: f32 = pow(max(dot(surfaceNormal, halfway), 0.0), mix(36.0, 160.0, puddle)) * max(dot(surfaceNormal, normalize(lightDirection)), 0.0);
|
|
12049
12109
|
return wetness * (surfaceWeather.skyColor * fresnel * (0.15 + puddle * 0.85) + lightColor * highlight * 0.6);
|
|
12050
12110
|
}
|
|
12051
|
-
`};var
|
|
12111
|
+
`};var gi={enabled:0,time:0,radius:8,speed:.6,pulse:.85},Jr={name:"firefly",uniformTypes:{enabled:"f32",time:"f32",radius:"f32",speed:"f32",pulse:"f32"},defaultUniforms:gi,getUniforms(e={},t=gi){return{...gi,...t,...e}},source:`struct FireflyUniforms {enabled: f32, time: f32, radius: f32, speed: f32, pulse: f32};
|
|
12052
12112
|
@group(3) @binding(auto) var<uniform> firefly: FireflyUniforms;
|
|
12053
12113
|
fn firefly_getPosition(position: vec3f, seed: f32, time: f32) -> vec3f {
|
|
12054
12114
|
if (firefly.enabled <= 0.0) { return position; }
|
|
@@ -12085,7 +12145,7 @@ fn surfaceWeather_getReflection(position: vec3f,
|
|
|
12085
12145
|
float phase = seed * 2.399963;
|
|
12086
12146
|
float pulse = pow(0.5 + 0.5 * sin(time * firefly.speed * (1.6 + fract(seed * 0.37)) + phase), 3.0);
|
|
12087
12147
|
return mix(1.0, mix(0.08, 1.0, pulse), firefly.pulse * firefly.enabled);
|
|
12088
|
-
}`};var
|
|
12148
|
+
}`};var Qr={name:"globeClouds",dependencies:[_t],uniformTypes:{planetRadius:"f32"},defaultUniforms:{planetRadius:6370972},fs:`
|
|
12089
12149
|
layout(std140) uniform globeCloudsUniforms { float planetRadius; } globeClouds;
|
|
12090
12150
|
vec2 globeClouds_intersectSphere(vec3 camera, vec3 direction, float radius) {
|
|
12091
12151
|
float projected = dot(camera, direction);
|
|
@@ -12187,6 +12247,1297 @@ fn globeClouds_getColor(camera: vec3f, direction: vec3f) -> vec4f {
|
|
|
12187
12247
|
}
|
|
12188
12248
|
return vec4f(radiance, 1.0 - transmittance);
|
|
12189
12249
|
}
|
|
12190
|
-
`};
|
|
12250
|
+
`};var yl=`layout(std140) uniform pbrEnvironmentFilterUniforms {
|
|
12251
|
+
int face;
|
|
12252
|
+
float roughness;
|
|
12253
|
+
int mode;
|
|
12254
|
+
int sampleCount;
|
|
12255
|
+
int sourceEncoding;
|
|
12256
|
+
} pbrEnvironmentFilter;
|
|
12257
|
+
|
|
12258
|
+
uniform sampler2D pbrEnvironmentSource;
|
|
12259
|
+
`,Cl=`struct PBREnvironmentFilterUniforms {
|
|
12260
|
+
face: i32,
|
|
12261
|
+
roughness: f32,
|
|
12262
|
+
mode: i32,
|
|
12263
|
+
sampleCount: i32,
|
|
12264
|
+
sourceEncoding: i32,
|
|
12265
|
+
};
|
|
12266
|
+
|
|
12267
|
+
@group(0) @binding(auto) var<uniform> pbrEnvironmentFilter: PBREnvironmentFilterUniforms;
|
|
12268
|
+
@group(0) @binding(auto) var pbrEnvironmentSource: texture_2d<f32>;
|
|
12269
|
+
@group(0) @binding(auto) var pbrEnvironmentSourceSampler: sampler;
|
|
12270
|
+
`,eo={name:"pbrEnvironmentFilter",bindingLayout:[{name:"pbrEnvironmentFilter",group:0},{name:"pbrEnvironmentSource",group:0}],fs:yl,source:Cl,getUniforms:e=>e,uniformTypes:{face:"i32",roughness:"f32",mode:"i32",sampleCount:"i32",sourceEncoding:"i32"},defaultUniforms:{face:0,roughness:0,mode:0,sampleCount:64,sourceEncoding:0}},to=`#version 300 es
|
|
12271
|
+
precision highp float;
|
|
12272
|
+
precision highp int;
|
|
12273
|
+
|
|
12274
|
+
in vec2 uv;
|
|
12275
|
+
out vec4 fragmentColor;
|
|
12276
|
+
|
|
12277
|
+
const float ENVIRONMENT_PI = 3.141592653589793;
|
|
12278
|
+
|
|
12279
|
+
vec2 getEnvironmentHammersley(uint index, uint sampleCount)
|
|
12280
|
+
{
|
|
12281
|
+
uint reversedBits = (index << 16u) | (index >> 16u);
|
|
12282
|
+
reversedBits = ((reversedBits & 0x55555555u) << 1u) |
|
|
12283
|
+
((reversedBits & 0xAAAAAAAAu) >> 1u);
|
|
12284
|
+
reversedBits = ((reversedBits & 0x33333333u) << 2u) |
|
|
12285
|
+
((reversedBits & 0xCCCCCCCCu) >> 2u);
|
|
12286
|
+
reversedBits = ((reversedBits & 0x0F0F0F0Fu) << 4u) |
|
|
12287
|
+
((reversedBits & 0xF0F0F0F0u) >> 4u);
|
|
12288
|
+
reversedBits = ((reversedBits & 0x00FF00FFu) << 8u) |
|
|
12289
|
+
((reversedBits & 0xFF00FF00u) >> 8u);
|
|
12290
|
+
return vec2(
|
|
12291
|
+
float(index) / float(sampleCount),
|
|
12292
|
+
float(reversedBits) * 2.3283064365386963e-10
|
|
12293
|
+
);
|
|
12294
|
+
}
|
|
12295
|
+
|
|
12296
|
+
vec3 getEnvironmentFaceDirection(int face, vec2 textureCoordinate)
|
|
12297
|
+
{
|
|
12298
|
+
vec2 coordinate = textureCoordinate * 2.0 - 1.0;
|
|
12299
|
+
if (face == 0) return normalize(vec3(1.0, -coordinate.y, -coordinate.x));
|
|
12300
|
+
if (face == 1) return normalize(vec3(-1.0, -coordinate.y, coordinate.x));
|
|
12301
|
+
if (face == 2) return normalize(vec3(coordinate.x, 1.0, coordinate.y));
|
|
12302
|
+
if (face == 3) return normalize(vec3(coordinate.x, -1.0, -coordinate.y));
|
|
12303
|
+
if (face == 4) return normalize(vec3(coordinate.x, -coordinate.y, 1.0));
|
|
12304
|
+
return normalize(vec3(-coordinate.x, -coordinate.y, -1.0));
|
|
12305
|
+
}
|
|
12306
|
+
|
|
12307
|
+
mat3 getEnvironmentTangentBasis(vec3 normal)
|
|
12308
|
+
{
|
|
12309
|
+
vec3 up = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
|
|
12310
|
+
vec3 tangent = normalize(cross(up, normal));
|
|
12311
|
+
return mat3(tangent, cross(normal, tangent), normal);
|
|
12312
|
+
}
|
|
12313
|
+
|
|
12314
|
+
vec3 sampleEnvironmentDirection(vec3 direction)
|
|
12315
|
+
{
|
|
12316
|
+
vec3 normalizedDirection = normalize(direction);
|
|
12317
|
+
vec2 textureCoordinate = vec2(
|
|
12318
|
+
atan(normalizedDirection.z, normalizedDirection.x) / (2.0 * ENVIRONMENT_PI) + 0.5,
|
|
12319
|
+
acos(clamp(normalizedDirection.y, -1.0, 1.0)) / ENVIRONMENT_PI
|
|
12320
|
+
);
|
|
12321
|
+
vec3 color = texture(pbrEnvironmentSource, textureCoordinate).rgb;
|
|
12322
|
+
if (pbrEnvironmentFilter.sourceEncoding == 1) {
|
|
12323
|
+
vec3 lower = color / 12.92;
|
|
12324
|
+
vec3 upper = pow((color + 0.055) / 1.055, vec3(2.4));
|
|
12325
|
+
color = mix(lower, upper, step(vec3(0.04045), color));
|
|
12326
|
+
}
|
|
12327
|
+
return color;
|
|
12328
|
+
}
|
|
12329
|
+
|
|
12330
|
+
vec3 importanceSampleEnvironment(vec2 sequence, vec3 normal, float roughness)
|
|
12331
|
+
{
|
|
12332
|
+
float alpha = max(roughness * roughness, 0.0001);
|
|
12333
|
+
float azimuth = 2.0 * ENVIRONMENT_PI * sequence.x;
|
|
12334
|
+
float cosine = sqrt(
|
|
12335
|
+
(1.0 - sequence.y) / max(1.0 + (alpha * alpha - 1.0) * sequence.y, 0.0001)
|
|
12336
|
+
);
|
|
12337
|
+
float sine = sqrt(max(1.0 - cosine * cosine, 0.0));
|
|
12338
|
+
vec3 halfVector = vec3(cos(azimuth) * sine, sin(azimuth) * sine, cosine);
|
|
12339
|
+
return normalize(getEnvironmentTangentBasis(normal) * halfVector);
|
|
12340
|
+
}
|
|
12341
|
+
|
|
12342
|
+
float getEnvironmentGeometry(float normalDotDirection, float roughness)
|
|
12343
|
+
{
|
|
12344
|
+
float alpha = roughness * roughness;
|
|
12345
|
+
float factor = alpha * 0.5;
|
|
12346
|
+
return normalDotDirection / max(normalDotDirection * (1.0 - factor) + factor, 0.0001);
|
|
12347
|
+
}
|
|
12348
|
+
|
|
12349
|
+
vec2 integrateEnvironmentBRDF(vec2 textureCoordinate, int sampleCount)
|
|
12350
|
+
{
|
|
12351
|
+
float normalDotView = max(textureCoordinate.x, 0.001);
|
|
12352
|
+
float roughness = 1.0 - textureCoordinate.y;
|
|
12353
|
+
vec3 viewDirection = vec3(sqrt(max(1.0 - normalDotView * normalDotView, 0.0)), 0.0, normalDotView);
|
|
12354
|
+
vec2 integration = vec2(0.0);
|
|
12355
|
+
|
|
12356
|
+
for (int sampleIndex = 0; sampleIndex < 1024; sampleIndex++) {
|
|
12357
|
+
if (sampleIndex >= sampleCount) break;
|
|
12358
|
+
vec3 halfVector = importanceSampleEnvironment(
|
|
12359
|
+
getEnvironmentHammersley(uint(sampleIndex), uint(sampleCount)),
|
|
12360
|
+
vec3(0.0, 0.0, 1.0),
|
|
12361
|
+
roughness
|
|
12362
|
+
);
|
|
12363
|
+
vec3 lightDirection = normalize(2.0 * dot(viewDirection, halfVector) * halfVector - viewDirection);
|
|
12364
|
+
float normalDotLight = max(lightDirection.z, 0.0);
|
|
12365
|
+
float normalDotHalf = max(halfVector.z, 0.0);
|
|
12366
|
+
float viewDotHalf = max(dot(viewDirection, halfVector), 0.0);
|
|
12367
|
+
if (normalDotLight > 0.0) {
|
|
12368
|
+
float visibility = getEnvironmentGeometry(normalDotView, roughness) *
|
|
12369
|
+
getEnvironmentGeometry(normalDotLight, roughness) * viewDotHalf /
|
|
12370
|
+
max(normalDotHalf * normalDotView, 0.0001);
|
|
12371
|
+
float fresnel = pow(1.0 - viewDotHalf, 5.0);
|
|
12372
|
+
integration += vec2(1.0 - fresnel, fresnel) * visibility;
|
|
12373
|
+
}
|
|
12374
|
+
}
|
|
12375
|
+
return integration / float(sampleCount);
|
|
12376
|
+
}
|
|
12377
|
+
|
|
12378
|
+
vec3 integrateEnvironmentDirection(vec3 normal, int sampleCount)
|
|
12379
|
+
{
|
|
12380
|
+
vec3 accumulatedColor = vec3(0.0);
|
|
12381
|
+
float accumulatedWeight = 0.0;
|
|
12382
|
+
|
|
12383
|
+
for (int sampleIndex = 0; sampleIndex < 1024; sampleIndex++) {
|
|
12384
|
+
if (sampleIndex >= sampleCount) break;
|
|
12385
|
+
vec2 sequence = getEnvironmentHammersley(uint(sampleIndex), uint(sampleCount));
|
|
12386
|
+
vec3 direction;
|
|
12387
|
+
float sampleWeight;
|
|
12388
|
+
|
|
12389
|
+
if (pbrEnvironmentFilter.mode == 1) {
|
|
12390
|
+
float azimuth = 2.0 * ENVIRONMENT_PI * sequence.x;
|
|
12391
|
+
float cosine = sqrt(1.0 - sequence.y);
|
|
12392
|
+
float sine = sqrt(sequence.y);
|
|
12393
|
+
direction = normalize(
|
|
12394
|
+
getEnvironmentTangentBasis(normal) *
|
|
12395
|
+
vec3(cos(azimuth) * sine, sin(azimuth) * sine, cosine)
|
|
12396
|
+
);
|
|
12397
|
+
sampleWeight = 1.0;
|
|
12398
|
+
} else {
|
|
12399
|
+
vec3 halfVector = importanceSampleEnvironment(sequence, normal, pbrEnvironmentFilter.roughness);
|
|
12400
|
+
direction = normalize(2.0 * dot(normal, halfVector) * halfVector - normal);
|
|
12401
|
+
sampleWeight = max(dot(normal, direction), 0.0);
|
|
12402
|
+
}
|
|
12403
|
+
|
|
12404
|
+
accumulatedColor += sampleEnvironmentDirection(direction) * sampleWeight;
|
|
12405
|
+
accumulatedWeight += sampleWeight;
|
|
12406
|
+
}
|
|
12407
|
+
|
|
12408
|
+
return accumulatedColor / max(accumulatedWeight, 0.0001);
|
|
12409
|
+
}
|
|
12410
|
+
|
|
12411
|
+
void main(void)
|
|
12412
|
+
{
|
|
12413
|
+
int sampleCount = max(pbrEnvironmentFilter.sampleCount, 1);
|
|
12414
|
+
if (pbrEnvironmentFilter.mode == 2) {
|
|
12415
|
+
fragmentColor = vec4(integrateEnvironmentBRDF(uv, sampleCount), 0.0, 1.0);
|
|
12416
|
+
return;
|
|
12417
|
+
}
|
|
12418
|
+
|
|
12419
|
+
vec3 direction = getEnvironmentFaceDirection(pbrEnvironmentFilter.face, uv);
|
|
12420
|
+
fragmentColor = vec4(integrateEnvironmentDirection(direction, sampleCount), 1.0);
|
|
12421
|
+
}
|
|
12422
|
+
`,io=`const ENVIRONMENT_PI: f32 = 3.141592653589793;
|
|
12423
|
+
|
|
12424
|
+
fn getEnvironmentHammersley(index: u32, sampleCount: u32) -> vec2f {
|
|
12425
|
+
return vec2f(f32(index) / f32(sampleCount), f32(reverseBits(index)) * 2.3283064365386963e-10);
|
|
12426
|
+
}
|
|
12427
|
+
|
|
12428
|
+
fn getEnvironmentFaceDirection(face: i32, textureCoordinate: vec2f) -> vec3f {
|
|
12429
|
+
let coordinate = textureCoordinate * 2.0 - 1.0;
|
|
12430
|
+
if (face == 0) { return normalize(vec3f(1.0, -coordinate.y, -coordinate.x)); }
|
|
12431
|
+
if (face == 1) { return normalize(vec3f(-1.0, -coordinate.y, coordinate.x)); }
|
|
12432
|
+
if (face == 2) { return normalize(vec3f(coordinate.x, 1.0, coordinate.y)); }
|
|
12433
|
+
if (face == 3) { return normalize(vec3f(coordinate.x, -1.0, -coordinate.y)); }
|
|
12434
|
+
if (face == 4) { return normalize(vec3f(coordinate.x, -coordinate.y, 1.0)); }
|
|
12435
|
+
return normalize(vec3f(-coordinate.x, -coordinate.y, -1.0));
|
|
12436
|
+
}
|
|
12437
|
+
|
|
12438
|
+
fn getEnvironmentTangentBasis(normal: vec3f) -> mat3x3f {
|
|
12439
|
+
var up = vec3f(1.0, 0.0, 0.0);
|
|
12440
|
+
if (abs(normal.z) < 0.999) {
|
|
12441
|
+
up = vec3f(0.0, 0.0, 1.0);
|
|
12442
|
+
}
|
|
12443
|
+
let tangent = normalize(cross(up, normal));
|
|
12444
|
+
return mat3x3f(tangent, cross(normal, tangent), normal);
|
|
12445
|
+
}
|
|
12446
|
+
|
|
12447
|
+
fn sampleEnvironmentDirection(direction: vec3f) -> vec3f {
|
|
12448
|
+
let normalizedDirection = normalize(direction);
|
|
12449
|
+
let textureCoordinate = vec2f(
|
|
12450
|
+
atan2(normalizedDirection.z, normalizedDirection.x) / (2.0 * ENVIRONMENT_PI) + 0.5,
|
|
12451
|
+
acos(clamp(normalizedDirection.y, -1.0, 1.0)) / ENVIRONMENT_PI
|
|
12452
|
+
);
|
|
12453
|
+
var color = textureSampleLevel(
|
|
12454
|
+
pbrEnvironmentSource,
|
|
12455
|
+
pbrEnvironmentSourceSampler,
|
|
12456
|
+
textureCoordinate,
|
|
12457
|
+
0.0
|
|
12458
|
+
).rgb;
|
|
12459
|
+
if (pbrEnvironmentFilter.sourceEncoding == 1) {
|
|
12460
|
+
let lower = color / 12.92;
|
|
12461
|
+
let upper = pow((color + 0.055) / 1.055, vec3f(2.4));
|
|
12462
|
+
color = mix(lower, upper, step(vec3f(0.04045), color));
|
|
12463
|
+
}
|
|
12464
|
+
return color;
|
|
12465
|
+
}
|
|
12466
|
+
|
|
12467
|
+
fn importanceSampleEnvironment(sequence: vec2f, normal: vec3f, roughness: f32) -> vec3f {
|
|
12468
|
+
let alpha = max(roughness * roughness, 0.0001);
|
|
12469
|
+
let azimuth = 2.0 * ENVIRONMENT_PI * sequence.x;
|
|
12470
|
+
let cosine = sqrt(
|
|
12471
|
+
(1.0 - sequence.y) / max(1.0 + (alpha * alpha - 1.0) * sequence.y, 0.0001)
|
|
12472
|
+
);
|
|
12473
|
+
let sine = sqrt(max(1.0 - cosine * cosine, 0.0));
|
|
12474
|
+
let halfVector = vec3f(cos(azimuth) * sine, sin(azimuth) * sine, cosine);
|
|
12475
|
+
return normalize(getEnvironmentTangentBasis(normal) * halfVector);
|
|
12476
|
+
}
|
|
12477
|
+
|
|
12478
|
+
fn getEnvironmentGeometry(normalDotDirection: f32, roughness: f32) -> f32 {
|
|
12479
|
+
let alpha = roughness * roughness;
|
|
12480
|
+
let factor = alpha * 0.5;
|
|
12481
|
+
return normalDotDirection / max(normalDotDirection * (1.0 - factor) + factor, 0.0001);
|
|
12482
|
+
}
|
|
12483
|
+
|
|
12484
|
+
fn integrateEnvironmentBRDF(textureCoordinate: vec2f, sampleCount: u32) -> vec2f {
|
|
12485
|
+
let normalDotView = max(textureCoordinate.x, 0.001);
|
|
12486
|
+
let roughness = 1.0 - textureCoordinate.y;
|
|
12487
|
+
let viewDirection = vec3f(
|
|
12488
|
+
sqrt(max(1.0 - normalDotView * normalDotView, 0.0)),
|
|
12489
|
+
0.0,
|
|
12490
|
+
normalDotView
|
|
12491
|
+
);
|
|
12492
|
+
var integration = vec2f(0.0);
|
|
12493
|
+
|
|
12494
|
+
for (var sampleIndex = 0u; sampleIndex < sampleCount; sampleIndex++) {
|
|
12495
|
+
let halfVector = importanceSampleEnvironment(
|
|
12496
|
+
getEnvironmentHammersley(sampleIndex, sampleCount),
|
|
12497
|
+
vec3f(0.0, 0.0, 1.0),
|
|
12498
|
+
roughness
|
|
12499
|
+
);
|
|
12500
|
+
let lightDirection = normalize(
|
|
12501
|
+
2.0 * dot(viewDirection, halfVector) * halfVector - viewDirection
|
|
12502
|
+
);
|
|
12503
|
+
let normalDotLight = max(lightDirection.z, 0.0);
|
|
12504
|
+
let normalDotHalf = max(halfVector.z, 0.0);
|
|
12505
|
+
let viewDotHalf = max(dot(viewDirection, halfVector), 0.0);
|
|
12506
|
+
if (normalDotLight > 0.0) {
|
|
12507
|
+
let visibility = getEnvironmentGeometry(normalDotView, roughness) *
|
|
12508
|
+
getEnvironmentGeometry(normalDotLight, roughness) * viewDotHalf /
|
|
12509
|
+
max(normalDotHalf * normalDotView, 0.0001);
|
|
12510
|
+
let fresnel = pow(1.0 - viewDotHalf, 5.0);
|
|
12511
|
+
integration += vec2f(1.0 - fresnel, fresnel) * visibility;
|
|
12512
|
+
}
|
|
12513
|
+
}
|
|
12514
|
+
return integration / f32(sampleCount);
|
|
12515
|
+
}
|
|
12516
|
+
|
|
12517
|
+
fn integrateEnvironmentDirection(normal: vec3f, sampleCount: u32) -> vec3f {
|
|
12518
|
+
var accumulatedColor = vec3f(0.0);
|
|
12519
|
+
var accumulatedWeight = 0.0;
|
|
12520
|
+
|
|
12521
|
+
for (var sampleIndex = 0u; sampleIndex < sampleCount; sampleIndex++) {
|
|
12522
|
+
let sequence = getEnvironmentHammersley(sampleIndex, sampleCount);
|
|
12523
|
+
var direction: vec3f;
|
|
12524
|
+
var sampleWeight: f32;
|
|
12525
|
+
|
|
12526
|
+
if (pbrEnvironmentFilter.mode == 1) {
|
|
12527
|
+
let azimuth = 2.0 * ENVIRONMENT_PI * sequence.x;
|
|
12528
|
+
let cosine = sqrt(1.0 - sequence.y);
|
|
12529
|
+
let sine = sqrt(sequence.y);
|
|
12530
|
+
direction = normalize(
|
|
12531
|
+
getEnvironmentTangentBasis(normal) *
|
|
12532
|
+
vec3f(cos(azimuth) * sine, sin(azimuth) * sine, cosine)
|
|
12533
|
+
);
|
|
12534
|
+
sampleWeight = 1.0;
|
|
12535
|
+
} else {
|
|
12536
|
+
let halfVector = importanceSampleEnvironment(sequence, normal, pbrEnvironmentFilter.roughness);
|
|
12537
|
+
direction = normalize(2.0 * dot(normal, halfVector) * halfVector - normal);
|
|
12538
|
+
sampleWeight = max(dot(normal, direction), 0.0);
|
|
12539
|
+
}
|
|
12540
|
+
|
|
12541
|
+
accumulatedColor += sampleEnvironmentDirection(direction) * sampleWeight;
|
|
12542
|
+
accumulatedWeight += sampleWeight;
|
|
12543
|
+
}
|
|
12544
|
+
return accumulatedColor / max(accumulatedWeight, 0.0001);
|
|
12545
|
+
}
|
|
12546
|
+
|
|
12547
|
+
@fragment
|
|
12548
|
+
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
|
|
12549
|
+
// ClipSpace UVs increase upward; WebGPU texture rows increase downward.
|
|
12550
|
+
let textureCoordinate = vec2f(inputs.uv.x, 1.0 - inputs.uv.y);
|
|
12551
|
+
let sampleCount = u32(max(pbrEnvironmentFilter.sampleCount, 1));
|
|
12552
|
+
if (pbrEnvironmentFilter.mode == 2) {
|
|
12553
|
+
return vec4f(integrateEnvironmentBRDF(textureCoordinate, sampleCount), 0.0, 1.0);
|
|
12554
|
+
}
|
|
12555
|
+
|
|
12556
|
+
let direction = getEnvironmentFaceDirection(pbrEnvironmentFilter.face, textureCoordinate);
|
|
12557
|
+
return vec4f(integrateEnvironmentDirection(direction, sampleCount), 1.0);
|
|
12558
|
+
}
|
|
12559
|
+
`;var no=`
|
|
12560
|
+
precision highp sampler2DArray;
|
|
12561
|
+
struct DirectionalShadowLightUniform {
|
|
12562
|
+
vec3 direction;
|
|
12563
|
+
float strength;
|
|
12564
|
+
float normalBias;
|
|
12565
|
+
float sourceAngularRadius;
|
|
12566
|
+
float cascadeBlendFraction;
|
|
12567
|
+
float farFadeFraction;
|
|
12568
|
+
float shadowDistance;
|
|
12569
|
+
};
|
|
12570
|
+
struct SpotShadowLightUniform {
|
|
12571
|
+
vec3 position;
|
|
12572
|
+
float range;
|
|
12573
|
+
vec3 direction;
|
|
12574
|
+
float outerConeCos;
|
|
12575
|
+
float sourceRadius;
|
|
12576
|
+
float normalBias;
|
|
12577
|
+
float strength;
|
|
12578
|
+
float nearPlane;
|
|
12579
|
+
};
|
|
12580
|
+
struct PointShadowLightUniform {
|
|
12581
|
+
vec3 position;
|
|
12582
|
+
float range;
|
|
12583
|
+
float sourceRadius;
|
|
12584
|
+
float normalBias;
|
|
12585
|
+
float strength;
|
|
12586
|
+
float nearPlane;
|
|
12587
|
+
};
|
|
12588
|
+
layout(std140) uniform shadowUniforms {
|
|
12589
|
+
int directionalLightCount;
|
|
12590
|
+
int spotLightCount;
|
|
12591
|
+
int pointLightCount;
|
|
12592
|
+
int cascadeCount;
|
|
12593
|
+
int blockerSampleCount;
|
|
12594
|
+
int filterSampleCount;
|
|
12595
|
+
vec4 cascadeSplits;
|
|
12596
|
+
mat4 directionalViewProjectionMatrices[4];
|
|
12597
|
+
mat4 spotViewProjectionMatrices[4];
|
|
12598
|
+
mat4 pointViewProjectionMatrices[24];
|
|
12599
|
+
DirectionalShadowLightUniform directionalLights[1];
|
|
12600
|
+
SpotShadowLightUniform spotLights[4];
|
|
12601
|
+
PointShadowLightUniform pointLights[4];
|
|
12602
|
+
} shadow;
|
|
12603
|
+
uniform sampler2DArray directionalShadowTexture;
|
|
12604
|
+
uniform sampler2DArray spotShadowTexture;
|
|
12605
|
+
uniform sampler2DArray pointShadowTexture;
|
|
12606
|
+
const float SHADOW_PI = 3.141592653589793;
|
|
12607
|
+
float shadow_hash(vec3 position) {
|
|
12608
|
+
return fract(sin(dot(position, vec3(12.9898, 78.233, 37.719))) * 43758.5453);
|
|
12609
|
+
}
|
|
12610
|
+
vec2 shadow_diskSample(int index, int count, float rotation) {
|
|
12611
|
+
float fraction = (float(index) + 0.5) / max(float(count), 1.0);
|
|
12612
|
+
float angle = float(index) * 2.39996323 + rotation;
|
|
12613
|
+
return sqrt(fraction) * vec2(cos(angle), sin(angle));
|
|
12614
|
+
}
|
|
12615
|
+
vec3 shadow_project(mat4 matrix, vec3 worldPosition) {
|
|
12616
|
+
vec4 clip = matrix * vec4(worldPosition, 1.0);
|
|
12617
|
+
vec3 projected = clip.xyz / max(abs(clip.w), 0.00001);
|
|
12618
|
+
// Shared matrices retain [0,1] depth; WebGL texture rows start at the bottom.
|
|
12619
|
+
return vec3(projected.xy * 0.5 + 0.5, projected.z);
|
|
12620
|
+
}
|
|
12621
|
+
bool shadow_validProjection(vec3 projected) {
|
|
12622
|
+
return all(greaterThanEqual(projected, vec3(0.0))) && all(lessThanEqual(projected, vec3(1.0)));
|
|
12623
|
+
}
|
|
12624
|
+
// Bilinear interpolation of four depth comparisons matches a hardware 2x2 PCF lookup.
|
|
12625
|
+
float shadow_compare(sampler2DArray shadowMap, vec2 coordinate, int layer, float reference) {
|
|
12626
|
+
ivec2 dimensions = textureSize(shadowMap, 0).xy;
|
|
12627
|
+
vec2 position = coordinate * vec2(dimensions) - 0.5;
|
|
12628
|
+
ivec2 base = ivec2(floor(position));
|
|
12629
|
+
vec2 fraction = fract(position);
|
|
12630
|
+
ivec2 maximum = dimensions - 1;
|
|
12631
|
+
float lowerLeft = step(reference, texelFetch(shadowMap, ivec3(clamp(base, ivec2(0), maximum), layer), 0).r);
|
|
12632
|
+
float lowerRight = step(reference, texelFetch(shadowMap, ivec3(clamp(base + ivec2(1,0), ivec2(0), maximum), layer), 0).r);
|
|
12633
|
+
float upperLeft = step(reference, texelFetch(shadowMap, ivec3(clamp(base + ivec2(0,1), ivec2(0), maximum), layer), 0).r);
|
|
12634
|
+
float upperRight = step(reference, texelFetch(shadowMap, ivec3(clamp(base + ivec2(1,1), ivec2(0), maximum), layer), 0).r);
|
|
12635
|
+
return mix(mix(lowerLeft, lowerRight, fraction.x), mix(upperLeft, upperRight, fraction.x), fraction.y);
|
|
12636
|
+
}
|
|
12637
|
+
float shadow_arrayPCSS(sampler2DArray shadowMap, int layer, vec3 projected, float searchRadius, float rotation, float penumbraScale) {
|
|
12638
|
+
if (!shadow_validProjection(projected)) return 1.0;
|
|
12639
|
+
float texel = 1.0 / float(textureSize(shadowMap, 0).x);
|
|
12640
|
+
searchRadius = max(texel, searchRadius);
|
|
12641
|
+
float blockerDepth = 0.0;
|
|
12642
|
+
float blockerCount = 0.0;
|
|
12643
|
+
for (int index = 0; index < 24; index++) {
|
|
12644
|
+
if (index >= shadow.blockerSampleCount) break;
|
|
12645
|
+
vec2 coordinate = clamp(projected.xy + shadow_diskSample(index, shadow.blockerSampleCount, rotation) * searchRadius, vec2(0.0), vec2(1.0));
|
|
12646
|
+
float depth = textureLod(shadowMap, vec3(coordinate, float(layer)), 0.0).r;
|
|
12647
|
+
if (depth < projected.z) { blockerDepth += depth; blockerCount += 1.0; }
|
|
12648
|
+
}
|
|
12649
|
+
if (blockerCount == 0.0) return 1.0;
|
|
12650
|
+
float averageBlocker = blockerDepth / blockerCount;
|
|
12651
|
+
float penumbra = clamp((projected.z - averageBlocker) / max(abs(averageBlocker), 0.001), 0.0, 1.0);
|
|
12652
|
+
float radius = max(texel, searchRadius * (1.0 + penumbra * penumbraScale));
|
|
12653
|
+
float visibility = 0.0;
|
|
12654
|
+
for (int index = 0; index < 48; index++) {
|
|
12655
|
+
if (index >= shadow.filterSampleCount) break;
|
|
12656
|
+
vec2 coordinate = clamp(projected.xy + shadow_diskSample(index, shadow.filterSampleCount, rotation) * radius, vec2(0.0), vec2(1.0));
|
|
12657
|
+
visibility += shadow_compare(shadowMap, coordinate, layer, projected.z);
|
|
12658
|
+
}
|
|
12659
|
+
return visibility / max(float(shadow.filterSampleCount), 1.0);
|
|
12660
|
+
}
|
|
12661
|
+
int shadow_directionalCascadeIndex(float viewDepth) {
|
|
12662
|
+
int cascadeIndex = 0;
|
|
12663
|
+
for (int index = 0; index < 4; index++) {
|
|
12664
|
+
if (index >= shadow.cascadeCount) break;
|
|
12665
|
+
cascadeIndex = index;
|
|
12666
|
+
if (viewDepth <= shadow.cascadeSplits[index]) break;
|
|
12667
|
+
}
|
|
12668
|
+
return cascadeIndex;
|
|
12669
|
+
}
|
|
12670
|
+
int shadow_getDirectionalCascadeIndex(float viewDepth) {
|
|
12671
|
+
return shadow.directionalLightCount == 0 ? -1 : shadow_directionalCascadeIndex(viewDepth);
|
|
12672
|
+
}
|
|
12673
|
+
float shadow_directionalPCSS(int cascadeIndex, vec3 worldPosition, float viewDepth) {
|
|
12674
|
+
DirectionalShadowLightUniform light = shadow.directionalLights[0];
|
|
12675
|
+
return shadow_arrayPCSS(directionalShadowTexture, cascadeIndex,
|
|
12676
|
+
shadow_project(shadow.directionalViewProjectionMatrices[cascadeIndex], worldPosition),
|
|
12677
|
+
light.sourceAngularRadius * viewDepth / max(light.shadowDistance, 0.001),
|
|
12678
|
+
shadow_hash(worldPosition) * 2.0 * SHADOW_PI, 18.0);
|
|
12679
|
+
}
|
|
12680
|
+
float shadow_getDirectionalFactor(vec3 worldPosition, vec3 worldNormal, float viewDepth) {
|
|
12681
|
+
if (shadow.directionalLightCount == 0 || viewDepth <= 0.0) return 1.0;
|
|
12682
|
+
DirectionalShadowLightUniform light = shadow.directionalLights[0];
|
|
12683
|
+
if (viewDepth >= light.shadowDistance) return 1.0;
|
|
12684
|
+
vec3 position = worldPosition + normalize(worldNormal) * light.normalBias;
|
|
12685
|
+
int cascadeIndex = shadow_directionalCascadeIndex(viewDepth);
|
|
12686
|
+
float visibility = shadow_directionalPCSS(cascadeIndex, position, viewDepth);
|
|
12687
|
+
if (cascadeIndex + 1 < shadow.cascadeCount) {
|
|
12688
|
+
float cascadeStart = cascadeIndex > 0 ? shadow.cascadeSplits[cascadeIndex - 1] : 0.0;
|
|
12689
|
+
float cascadeEnd = shadow.cascadeSplits[cascadeIndex];
|
|
12690
|
+
float blendWidth = max((cascadeEnd - cascadeStart) * light.cascadeBlendFraction, 0.0001);
|
|
12691
|
+
float blend = smoothstep(cascadeEnd - blendWidth, cascadeEnd, viewDepth);
|
|
12692
|
+
if (blend > 0.0) visibility = mix(visibility, shadow_directionalPCSS(cascadeIndex + 1, position, viewDepth), blend);
|
|
12693
|
+
}
|
|
12694
|
+
float fadeWidth = max(light.shadowDistance * light.farFadeFraction, 0.0001);
|
|
12695
|
+
visibility = mix(visibility, 1.0, smoothstep(light.shadowDistance - fadeWidth, light.shadowDistance, viewDepth));
|
|
12696
|
+
return mix(1.0, visibility, light.strength);
|
|
12697
|
+
}
|
|
12698
|
+
float shadow_getSpotFactor(int lightIndex, vec3 worldPosition, vec3 worldNormal) {
|
|
12699
|
+
if (lightIndex < 0 || lightIndex >= shadow.spotLightCount) return 1.0;
|
|
12700
|
+
SpotShadowLightUniform light = shadow.spotLights[lightIndex];
|
|
12701
|
+
vec3 fromLight = worldPosition - light.position;
|
|
12702
|
+
float distanceToLight = length(fromLight);
|
|
12703
|
+
if (distanceToLight >= light.range || dot(normalize(fromLight), normalize(light.direction)) < light.outerConeCos) return 1.0;
|
|
12704
|
+
vec3 position = worldPosition + normalize(worldNormal) * light.normalBias;
|
|
12705
|
+
float visibility = shadow_arrayPCSS(spotShadowTexture, lightIndex,
|
|
12706
|
+
shadow_project(shadow.spotViewProjectionMatrices[lightIndex], position),
|
|
12707
|
+
light.sourceRadius / max(distanceToLight, 0.001) * 0.5,
|
|
12708
|
+
shadow_hash(worldPosition) * 2.0 * SHADOW_PI, 16.0);
|
|
12709
|
+
return mix(1.0, visibility, light.strength);
|
|
12710
|
+
}
|
|
12711
|
+
float shadow_pointReferenceDepth(float majorDistance, float nearPlane, float farPlane) {
|
|
12712
|
+
return farPlane / (farPlane - nearPlane) - (farPlane * nearPlane) / ((farPlane - nearPlane) * majorDistance);
|
|
12713
|
+
}
|
|
12714
|
+
vec3 shadow_pointCoordinate(int lightIndex, vec3 direction) {
|
|
12715
|
+
vec3 magnitude = abs(direction);
|
|
12716
|
+
int face = magnitude.x >= magnitude.y && magnitude.x >= magnitude.z ? (direction.x >= 0.0 ? 0 : 1)
|
|
12717
|
+
: magnitude.y >= magnitude.z ? (direction.y >= 0.0 ? 2 : 3) : (direction.z >= 0.0 ? 4 : 5);
|
|
12718
|
+
PointShadowLightUniform light = shadow.pointLights[lightIndex];
|
|
12719
|
+
vec3 projected = shadow_project(shadow.pointViewProjectionMatrices[lightIndex * 6 + face], light.position + direction * light.range * 0.5);
|
|
12720
|
+
return vec3(projected.xy, float(lightIndex * 6 + face));
|
|
12721
|
+
}
|
|
12722
|
+
float shadow_getPointFactor(int lightIndex, vec3 worldPosition, vec3 worldNormal) {
|
|
12723
|
+
if (lightIndex < 0 || lightIndex >= shadow.pointLightCount) return 1.0;
|
|
12724
|
+
PointShadowLightUniform light = shadow.pointLights[lightIndex];
|
|
12725
|
+
vec3 fromLight = worldPosition + normalize(worldNormal) * light.normalBias - light.position;
|
|
12726
|
+
float distanceToLight = length(fromLight);
|
|
12727
|
+
if (distanceToLight >= light.range || distanceToLight <= light.nearPlane) return 1.0;
|
|
12728
|
+
vec3 direction = normalize(fromLight);
|
|
12729
|
+
float referenceDepth = shadow_pointReferenceDepth(max(max(abs(fromLight.x), abs(fromLight.y)), abs(fromLight.z)), light.nearPlane, light.range);
|
|
12730
|
+
vec3 reference = abs(direction.y) > 0.99 ? vec3(0,0,1) : vec3(0,1,0);
|
|
12731
|
+
vec3 tangent = normalize(cross(direction, reference));
|
|
12732
|
+
vec3 bitangent = normalize(cross(direction, tangent));
|
|
12733
|
+
float searchRadius = light.sourceRadius / max(distanceToLight, 0.001);
|
|
12734
|
+
float rotation = shadow_hash(worldPosition) * 2.0 * SHADOW_PI;
|
|
12735
|
+
float blockerDepth = 0.0;
|
|
12736
|
+
float blockerCount = 0.0;
|
|
12737
|
+
for (int index = 0; index < 24; index++) {
|
|
12738
|
+
if (index >= shadow.blockerSampleCount) break;
|
|
12739
|
+
vec2 disk = shadow_diskSample(index, shadow.blockerSampleCount, rotation) * searchRadius;
|
|
12740
|
+
vec3 coordinate = shadow_pointCoordinate(lightIndex, normalize(direction + tangent * disk.x + bitangent * disk.y));
|
|
12741
|
+
float depth = textureLod(pointShadowTexture, coordinate, 0.0).r;
|
|
12742
|
+
if (depth < referenceDepth) { blockerDepth += depth; blockerCount += 1.0; }
|
|
12743
|
+
}
|
|
12744
|
+
if (blockerCount == 0.0) return 1.0;
|
|
12745
|
+
float averageBlocker = blockerDepth / blockerCount;
|
|
12746
|
+
float penumbra = clamp((referenceDepth - averageBlocker) / max(abs(averageBlocker), 0.001), 0.0, 1.0);
|
|
12747
|
+
float radius = searchRadius * (1.0 + penumbra * 12.0);
|
|
12748
|
+
float visibility = 0.0;
|
|
12749
|
+
for (int index = 0; index < 48; index++) {
|
|
12750
|
+
if (index >= shadow.filterSampleCount) break;
|
|
12751
|
+
vec2 disk = shadow_diskSample(index, shadow.filterSampleCount, rotation) * radius;
|
|
12752
|
+
vec3 coordinate = shadow_pointCoordinate(lightIndex, normalize(direction + tangent * disk.x + bitangent * disk.y));
|
|
12753
|
+
visibility += shadow_compare(pointShadowTexture, coordinate.xy, int(coordinate.z), referenceDepth);
|
|
12754
|
+
}
|
|
12755
|
+
return mix(1.0, visibility / max(float(shadow.filterSampleCount), 1.0), light.strength);
|
|
12756
|
+
}
|
|
12757
|
+
`;var Il=4,mi=4,ro=4,wl=24,Ll={direction:"vec3<f32>",strength:"f32",normalBias:"f32",sourceAngularRadius:"f32",cascadeBlendFraction:"f32",farFadeFraction:"f32",shadowDistance:"f32"},Ml={position:"vec3<f32>",range:"f32",direction:"vec3<f32>",outerConeCos:"f32",sourceRadius:"f32",normalBias:"f32",strength:"f32",nearPlane:"f32"},Al={position:"vec3<f32>",range:"f32",sourceRadius:"f32",normalBias:"f32",strength:"f32",nearPlane:"f32"},Rl=`const SHADOW_PI: f32 = 3.141592653589793;
|
|
12758
|
+
|
|
12759
|
+
struct DirectionalShadowLightUniform {
|
|
12760
|
+
direction: vec3f,
|
|
12761
|
+
strength: f32,
|
|
12762
|
+
normalBias: f32,
|
|
12763
|
+
sourceAngularRadius: f32,
|
|
12764
|
+
cascadeBlendFraction: f32,
|
|
12765
|
+
farFadeFraction: f32,
|
|
12766
|
+
shadowDistance: f32,
|
|
12767
|
+
};
|
|
12768
|
+
|
|
12769
|
+
struct SpotShadowLightUniform {
|
|
12770
|
+
position: vec3f,
|
|
12771
|
+
range: f32,
|
|
12772
|
+
direction: vec3f,
|
|
12773
|
+
outerConeCos: f32,
|
|
12774
|
+
sourceRadius: f32,
|
|
12775
|
+
normalBias: f32,
|
|
12776
|
+
strength: f32,
|
|
12777
|
+
nearPlane: f32,
|
|
12778
|
+
};
|
|
12779
|
+
|
|
12780
|
+
struct PointShadowLightUniform {
|
|
12781
|
+
position: vec3f,
|
|
12782
|
+
range: f32,
|
|
12783
|
+
sourceRadius: f32,
|
|
12784
|
+
normalBias: f32,
|
|
12785
|
+
strength: f32,
|
|
12786
|
+
nearPlane: f32,
|
|
12787
|
+
};
|
|
12788
|
+
|
|
12789
|
+
struct ShadowUniforms {
|
|
12790
|
+
directionalLightCount: i32,
|
|
12791
|
+
spotLightCount: i32,
|
|
12792
|
+
pointLightCount: i32,
|
|
12793
|
+
cascadeCount: i32,
|
|
12794
|
+
blockerSampleCount: i32,
|
|
12795
|
+
filterSampleCount: i32,
|
|
12796
|
+
cascadeSplits: vec4f,
|
|
12797
|
+
directionalViewProjectionMatrices: array<mat4x4f, 4>,
|
|
12798
|
+
spotViewProjectionMatrices: array<mat4x4f, 4>,
|
|
12799
|
+
pointViewProjectionMatrices: array<mat4x4f, 24>,
|
|
12800
|
+
directionalLights: array<DirectionalShadowLightUniform, 1>,
|
|
12801
|
+
spotLights: array<SpotShadowLightUniform, 4>,
|
|
12802
|
+
pointLights: array<PointShadowLightUniform, 4>,
|
|
12803
|
+
};
|
|
12804
|
+
|
|
12805
|
+
@group(2) @binding(auto) var<uniform> shadow: ShadowUniforms;
|
|
12806
|
+
@group(2) @binding(auto) var directionalShadowTexture: texture_depth_2d_array;
|
|
12807
|
+
@group(2) @binding(auto) var spotShadowTexture: texture_depth_2d_array;
|
|
12808
|
+
@group(2) @binding(auto) var pointShadowTexture: texture_depth_cube_array;
|
|
12809
|
+
@group(2) @binding(auto) var directionalShadowTextureSampler: sampler;
|
|
12810
|
+
@group(2) @binding(auto) var shadowComparisonSampler: sampler_comparison;
|
|
12811
|
+
|
|
12812
|
+
fn shadow_hash(position: vec3f) -> f32 {
|
|
12813
|
+
return fract(sin(dot(position, vec3f(12.9898, 78.233, 37.719))) * 43758.5453);
|
|
12814
|
+
}
|
|
12815
|
+
|
|
12816
|
+
fn shadow_diskSample(index: i32, count: i32, rotation: f32) -> vec2f {
|
|
12817
|
+
let fraction = (f32(index) + 0.5) / max(f32(count), 1.0);
|
|
12818
|
+
let angle = f32(index) * 2.39996323 + rotation;
|
|
12819
|
+
return sqrt(fraction) * vec2f(cos(angle), sin(angle));
|
|
12820
|
+
}
|
|
12821
|
+
|
|
12822
|
+
fn shadow_project(matrix: mat4x4f, worldPosition: vec3f) -> vec3f {
|
|
12823
|
+
let clip = matrix * vec4f(worldPosition, 1.0);
|
|
12824
|
+
let ndc = clip.xyz / max(abs(clip.w), 0.00001);
|
|
12825
|
+
return vec3f(ndc.x * 0.5 + 0.5, 0.5 - ndc.y * 0.5, ndc.z);
|
|
12826
|
+
}
|
|
12827
|
+
|
|
12828
|
+
fn shadow_validProjection(projected: vec3f) -> bool {
|
|
12829
|
+
return all(projected.xy >= vec2f(0.0)) && all(projected.xy <= vec2f(1.0)) &&
|
|
12830
|
+
projected.z >= 0.0 && projected.z <= 1.0;
|
|
12831
|
+
}
|
|
12832
|
+
|
|
12833
|
+
fn shadow_directionalCascadeIndex(viewDepth: f32) -> i32 {
|
|
12834
|
+
var cascadeIndex = 0;
|
|
12835
|
+
for (var index: i32 = 0; index < 4; index++) {
|
|
12836
|
+
if (index >= shadow.cascadeCount) { break; }
|
|
12837
|
+
cascadeIndex = index;
|
|
12838
|
+
if (viewDepth <= shadow.cascadeSplits[index]) { break; }
|
|
12839
|
+
}
|
|
12840
|
+
return cascadeIndex;
|
|
12841
|
+
}
|
|
12842
|
+
|
|
12843
|
+
fn shadow_getDirectionalCascadeIndex(viewDepth: f32) -> i32 {
|
|
12844
|
+
if (shadow.directionalLightCount == 0) { return -1; }
|
|
12845
|
+
return shadow_directionalCascadeIndex(viewDepth);
|
|
12846
|
+
}
|
|
12847
|
+
|
|
12848
|
+
fn shadow_directionalPCSS(cascadeIndex: i32, worldPosition: vec3f, viewDepth: f32) -> f32 {
|
|
12849
|
+
let projected = shadow_project(shadow.directionalViewProjectionMatrices[cascadeIndex], worldPosition);
|
|
12850
|
+
if (!shadow_validProjection(projected)) { return 1.0; }
|
|
12851
|
+
let dimensions = vec2f(textureDimensions(directionalShadowTexture));
|
|
12852
|
+
let texel = 1.0 / dimensions;
|
|
12853
|
+
let light = shadow.directionalLights[0];
|
|
12854
|
+
let rotation = shadow_hash(worldPosition) * 2.0 * SHADOW_PI;
|
|
12855
|
+
let searchRadius = max(texel.x, light.sourceAngularRadius * viewDepth / max(light.shadowDistance, 0.001));
|
|
12856
|
+
var blockerDepth = 0.0;
|
|
12857
|
+
var blockerCount = 0.0;
|
|
12858
|
+
for (var index: i32 = 0; index < 24; index++) {
|
|
12859
|
+
if (index >= shadow.blockerSampleCount) { break; }
|
|
12860
|
+
let offset = shadow_diskSample(index, shadow.blockerSampleCount, rotation) * searchRadius;
|
|
12861
|
+
let sampleDepth = textureSampleLevel(
|
|
12862
|
+
directionalShadowTexture,
|
|
12863
|
+
directionalShadowTextureSampler,
|
|
12864
|
+
clamp(projected.xy + offset, vec2f(0.0), vec2f(1.0)),
|
|
12865
|
+
cascadeIndex,
|
|
12866
|
+
0
|
|
12867
|
+
);
|
|
12868
|
+
if (sampleDepth < projected.z) {
|
|
12869
|
+
blockerDepth += sampleDepth;
|
|
12870
|
+
blockerCount += 1.0;
|
|
12871
|
+
}
|
|
12872
|
+
}
|
|
12873
|
+
if (blockerCount == 0.0) { return 1.0; }
|
|
12874
|
+
let averageBlocker = blockerDepth / blockerCount;
|
|
12875
|
+
let penumbra = clamp((projected.z - averageBlocker) / max(abs(averageBlocker), 0.001), 0.0, 1.0);
|
|
12876
|
+
let filterRadius = max(texel.x, searchRadius * (1.0 + penumbra * 18.0));
|
|
12877
|
+
var visibility = 0.0;
|
|
12878
|
+
for (var index: i32 = 0; index < 48; index++) {
|
|
12879
|
+
if (index >= shadow.filterSampleCount) { break; }
|
|
12880
|
+
let offset = shadow_diskSample(index, shadow.filterSampleCount, rotation) * filterRadius;
|
|
12881
|
+
visibility += textureSampleCompareLevel(
|
|
12882
|
+
directionalShadowTexture,
|
|
12883
|
+
shadowComparisonSampler,
|
|
12884
|
+
clamp(projected.xy + offset, vec2f(0.0), vec2f(1.0)),
|
|
12885
|
+
cascadeIndex,
|
|
12886
|
+
projected.z
|
|
12887
|
+
);
|
|
12888
|
+
}
|
|
12889
|
+
return visibility / max(f32(shadow.filterSampleCount), 1.0);
|
|
12890
|
+
}
|
|
12891
|
+
|
|
12892
|
+
fn shadow_getDirectionalFactor(worldPosition: vec3f, worldNormal: vec3f, viewDepth: f32) -> f32 {
|
|
12893
|
+
if (shadow.directionalLightCount == 0 || viewDepth <= 0.0) { return 1.0; }
|
|
12894
|
+
let light = shadow.directionalLights[0];
|
|
12895
|
+
if (viewDepth >= light.shadowDistance) { return 1.0; }
|
|
12896
|
+
let biasedPosition = worldPosition + normalize(worldNormal) * light.normalBias;
|
|
12897
|
+
let cascadeIndex = shadow_directionalCascadeIndex(viewDepth);
|
|
12898
|
+
var visibility = shadow_directionalPCSS(cascadeIndex, biasedPosition, viewDepth);
|
|
12899
|
+
if (cascadeIndex + 1 < shadow.cascadeCount) {
|
|
12900
|
+
var cascadeStart = 0.0;
|
|
12901
|
+
if (cascadeIndex > 0) { cascadeStart = shadow.cascadeSplits[cascadeIndex - 1]; }
|
|
12902
|
+
let cascadeEnd = shadow.cascadeSplits[cascadeIndex];
|
|
12903
|
+
let blendWidth = max((cascadeEnd - cascadeStart) * light.cascadeBlendFraction, 0.0001);
|
|
12904
|
+
let blend = smoothstep(cascadeEnd - blendWidth, cascadeEnd, viewDepth);
|
|
12905
|
+
if (blend > 0.0) {
|
|
12906
|
+
visibility = mix(
|
|
12907
|
+
visibility,
|
|
12908
|
+
shadow_directionalPCSS(cascadeIndex + 1, biasedPosition, viewDepth),
|
|
12909
|
+
blend
|
|
12910
|
+
);
|
|
12911
|
+
}
|
|
12912
|
+
}
|
|
12913
|
+
let fadeWidth = max(light.shadowDistance * light.farFadeFraction, 0.0001);
|
|
12914
|
+
let farFade = smoothstep(light.shadowDistance - fadeWidth, light.shadowDistance, viewDepth);
|
|
12915
|
+
visibility = mix(visibility, 1.0, farFade);
|
|
12916
|
+
return mix(1.0, visibility, light.strength);
|
|
12917
|
+
}
|
|
12918
|
+
|
|
12919
|
+
fn shadow_spotPCSS(lightIndex: i32, worldPosition: vec3f) -> f32 {
|
|
12920
|
+
let projected = shadow_project(shadow.spotViewProjectionMatrices[lightIndex], worldPosition);
|
|
12921
|
+
if (!shadow_validProjection(projected)) { return 1.0; }
|
|
12922
|
+
let light = shadow.spotLights[lightIndex];
|
|
12923
|
+
let dimensions = vec2f(textureDimensions(spotShadowTexture));
|
|
12924
|
+
let texel = 1.0 / dimensions;
|
|
12925
|
+
let distanceToLight = length(worldPosition - light.position);
|
|
12926
|
+
let searchRadius = max(texel.x, light.sourceRadius / max(distanceToLight, 0.001) * 0.5);
|
|
12927
|
+
let rotation = shadow_hash(worldPosition) * 2.0 * SHADOW_PI;
|
|
12928
|
+
var blockerDepth = 0.0;
|
|
12929
|
+
var blockerCount = 0.0;
|
|
12930
|
+
for (var index: i32 = 0; index < 24; index++) {
|
|
12931
|
+
if (index >= shadow.blockerSampleCount) { break; }
|
|
12932
|
+
let offset = shadow_diskSample(index, shadow.blockerSampleCount, rotation) * searchRadius;
|
|
12933
|
+
let sampleDepth = textureSampleLevel(
|
|
12934
|
+
spotShadowTexture,
|
|
12935
|
+
directionalShadowTextureSampler,
|
|
12936
|
+
clamp(projected.xy + offset, vec2f(0.0), vec2f(1.0)),
|
|
12937
|
+
lightIndex,
|
|
12938
|
+
0
|
|
12939
|
+
);
|
|
12940
|
+
if (sampleDepth < projected.z) { blockerDepth += sampleDepth; blockerCount += 1.0; }
|
|
12941
|
+
}
|
|
12942
|
+
if (blockerCount == 0.0) { return 1.0; }
|
|
12943
|
+
let averageBlocker = blockerDepth / blockerCount;
|
|
12944
|
+
let penumbra = clamp((projected.z - averageBlocker) / max(abs(averageBlocker), 0.001), 0.0, 1.0);
|
|
12945
|
+
let filterRadius = max(texel.x, searchRadius * (1.0 + penumbra * 16.0));
|
|
12946
|
+
var visibility = 0.0;
|
|
12947
|
+
for (var index: i32 = 0; index < 48; index++) {
|
|
12948
|
+
if (index >= shadow.filterSampleCount) { break; }
|
|
12949
|
+
let offset = shadow_diskSample(index, shadow.filterSampleCount, rotation) * filterRadius;
|
|
12950
|
+
visibility += textureSampleCompareLevel(
|
|
12951
|
+
spotShadowTexture,
|
|
12952
|
+
shadowComparisonSampler,
|
|
12953
|
+
clamp(projected.xy + offset, vec2f(0.0), vec2f(1.0)),
|
|
12954
|
+
lightIndex,
|
|
12955
|
+
projected.z
|
|
12956
|
+
);
|
|
12957
|
+
}
|
|
12958
|
+
return visibility / max(f32(shadow.filterSampleCount), 1.0);
|
|
12959
|
+
}
|
|
12960
|
+
|
|
12961
|
+
fn shadow_getSpotFactor(lightIndex: i32, worldPosition: vec3f, worldNormal: vec3f) -> f32 {
|
|
12962
|
+
if (lightIndex < 0 || lightIndex >= shadow.spotLightCount) { return 1.0; }
|
|
12963
|
+
let light = shadow.spotLights[lightIndex];
|
|
12964
|
+
let fromLight = worldPosition - light.position;
|
|
12965
|
+
let distanceToLight = length(fromLight);
|
|
12966
|
+
let coneCos = dot(normalize(fromLight), normalize(light.direction));
|
|
12967
|
+
if (distanceToLight >= light.range || coneCos < light.outerConeCos) { return 1.0; }
|
|
12968
|
+
let biasedPosition = worldPosition + normalize(worldNormal) * light.normalBias;
|
|
12969
|
+
return mix(1.0, shadow_spotPCSS(lightIndex, biasedPosition), light.strength);
|
|
12970
|
+
}
|
|
12971
|
+
|
|
12972
|
+
fn shadow_pointReferenceDepth(majorDistance: f32, nearPlane: f32, farPlane: f32) -> f32 {
|
|
12973
|
+
// Match the cube-face projection and stored WebGPU depth in [0, 1].
|
|
12974
|
+
return farPlane / (farPlane - nearPlane) -
|
|
12975
|
+
(farPlane * nearPlane) / ((farPlane - nearPlane) * majorDistance);
|
|
12976
|
+
}
|
|
12977
|
+
|
|
12978
|
+
fn shadow_pointBasis(direction: vec3f) -> mat2x3f {
|
|
12979
|
+
let reference = select(vec3f(0.0, 1.0, 0.0), vec3f(0.0, 0.0, 1.0), abs(direction.y) > 0.99);
|
|
12980
|
+
let tangent = normalize(cross(direction, reference));
|
|
12981
|
+
return mat2x3f(tangent, normalize(cross(direction, tangent)));
|
|
12982
|
+
}
|
|
12983
|
+
|
|
12984
|
+
fn shadow_getPointFactor(lightIndex: i32, worldPosition: vec3f, worldNormal: vec3f) -> f32 {
|
|
12985
|
+
if (lightIndex < 0 || lightIndex >= shadow.pointLightCount) { return 1.0; }
|
|
12986
|
+
let light = shadow.pointLights[lightIndex];
|
|
12987
|
+
let biasedPosition = worldPosition + normalize(worldNormal) * light.normalBias;
|
|
12988
|
+
let fromLight = biasedPosition - light.position;
|
|
12989
|
+
let distanceToLight = length(fromLight);
|
|
12990
|
+
if (distanceToLight >= light.range || distanceToLight <= light.nearPlane) { return 1.0; }
|
|
12991
|
+
let direction = normalize(fromLight);
|
|
12992
|
+
let majorDistance = max(max(abs(fromLight.x), abs(fromLight.y)), abs(fromLight.z));
|
|
12993
|
+
let referenceDepth = shadow_pointReferenceDepth(majorDistance, light.nearPlane, light.range);
|
|
12994
|
+
let searchRadius = light.sourceRadius / max(distanceToLight, 0.001);
|
|
12995
|
+
let rotation = shadow_hash(worldPosition) * 2.0 * SHADOW_PI;
|
|
12996
|
+
let basis = shadow_pointBasis(direction);
|
|
12997
|
+
var blockerDepth = 0.0;
|
|
12998
|
+
var blockerCount = 0.0;
|
|
12999
|
+
for (var index: i32 = 0; index < 24; index++) {
|
|
13000
|
+
if (index >= shadow.blockerSampleCount) { break; }
|
|
13001
|
+
let disk = shadow_diskSample(index, shadow.blockerSampleCount, rotation) * searchRadius;
|
|
13002
|
+
let sampleDirection = normalize(direction + basis[0] * disk.x + basis[1] * disk.y);
|
|
13003
|
+
let sampleDepth = textureSampleLevel(
|
|
13004
|
+
pointShadowTexture,
|
|
13005
|
+
directionalShadowTextureSampler,
|
|
13006
|
+
sampleDirection,
|
|
13007
|
+
lightIndex,
|
|
13008
|
+
0
|
|
13009
|
+
);
|
|
13010
|
+
if (sampleDepth < referenceDepth) { blockerDepth += sampleDepth; blockerCount += 1.0; }
|
|
13011
|
+
}
|
|
13012
|
+
if (blockerCount == 0.0) { return 1.0; }
|
|
13013
|
+
let averageBlocker = blockerDepth / blockerCount;
|
|
13014
|
+
let penumbra = clamp((referenceDepth - averageBlocker) / max(abs(averageBlocker), 0.001), 0.0, 1.0);
|
|
13015
|
+
let filterRadius = searchRadius * (1.0 + penumbra * 12.0);
|
|
13016
|
+
var visibility = 0.0;
|
|
13017
|
+
for (var index: i32 = 0; index < 48; index++) {
|
|
13018
|
+
if (index >= shadow.filterSampleCount) { break; }
|
|
13019
|
+
let disk = shadow_diskSample(index, shadow.filterSampleCount, rotation) * filterRadius;
|
|
13020
|
+
let sampleDirection = normalize(direction + basis[0] * disk.x + basis[1] * disk.y);
|
|
13021
|
+
visibility += textureSampleCompareLevel(
|
|
13022
|
+
pointShadowTexture,
|
|
13023
|
+
shadowComparisonSampler,
|
|
13024
|
+
sampleDirection,
|
|
13025
|
+
lightIndex,
|
|
13026
|
+
referenceDepth
|
|
13027
|
+
);
|
|
13028
|
+
}
|
|
13029
|
+
visibility /= max(f32(shadow.filterSampleCount), 1.0);
|
|
13030
|
+
return mix(1.0, visibility, light.strength);
|
|
13031
|
+
}
|
|
13032
|
+
`,bt={name:"shadow",source:Rl,fs:no,props:{},uniforms:{},bindings:{},uniformTypes:{directionalLightCount:"i32",spotLightCount:"i32",pointLightCount:"i32",cascadeCount:"i32",blockerSampleCount:"i32",filterSampleCount:"i32",cascadeSplits:"vec4<f32>",directionalViewProjectionMatrices:["mat4x4<f32>",Il],spotViewProjectionMatrices:["mat4x4<f32>",mi],pointViewProjectionMatrices:["mat4x4<f32>",wl],directionalLights:[Ll,1],spotLights:[Ml,mi],pointLights:[Al,ro]},bindingLayout:[{name:"shadow",group:2},{name:"directionalShadowTexture",group:2},{name:"spotShadowTexture",group:2},{name:"pointShadowTexture",group:2},{name:"shadowComparisonSampler",group:2}],getUniforms(e){return!e.directionalLights||!e.spotLights||!e.pointLights||!e.cascadeSplits||!e.directionalViewProjectionMatrices||!e.spotViewProjectionMatrices||!e.pointViewProjectionMatrices||!e.directionalShadowTexture||!e.spotShadowTexture||!e.pointShadowTexture||!e.nonFilteringSampler||!e.comparisonSampler?{}:{directionalLightCount:e.directionalLights.length,spotLightCount:e.spotLights.length,pointLightCount:e.pointLights.length,cascadeCount:e.cascadeCount,blockerSampleCount:e.blockerSampleCount,filterSampleCount:e.filterSampleCount,cascadeSplits:e.cascadeSplits,directionalViewProjectionMatrices:e.directionalViewProjectionMatrices,spotViewProjectionMatrices:e.spotViewProjectionMatrices,pointViewProjectionMatrices:e.pointViewProjectionMatrices,directionalLights:Tl(e.directionalLights),spotLights:El(e.spotLights),pointLights:Pl(e.pointLights),directionalShadowTexture:e.directionalShadowTexture,spotShadowTexture:e.spotShadowTexture,pointShadowTexture:e.pointShadowTexture,...e.directionalShadowTexture.device.type==="webgpu"?{shadowComparisonSampler:e.comparisonSampler}:{}}}};function Tl(e){let t=e[0];return[t?{direction:t.direction,strength:t.strength??1,normalBias:t.normalBias??.04,sourceAngularRadius:t.sourceAngularRadius??.00465,cascadeBlendFraction:t.cascadeBlendFraction??.1,farFadeFraction:t.farFadeFraction??.1,shadowDistance:t.shadowDistance??1}:{direction:[0,1,0],strength:0,normalBias:0,sourceAngularRadius:0,cascadeBlendFraction:0,farFadeFraction:0,shadowDistance:1}]}function El(e){return oo(e.map(t=>({position:t.position,range:t.range,direction:t.direction,outerConeCos:Math.cos(t.outerConeAngle),sourceRadius:t.sourceRadius??.2,normalBias:t.normalBias??.025,strength:t.strength??1,nearPlane:t.nearPlane??.1})),mi,{position:[0,0,0],range:1,direction:[0,-1,0],outerConeCos:1,sourceRadius:0,normalBias:0,strength:0,nearPlane:.1})}function Pl(e){return oo(e.map(t=>({position:t.position,range:t.range,sourceRadius:t.sourceRadius??.2,normalBias:t.normalBias??.025,strength:t.strength??1,nearPlane:t.nearPlane??.1})),ro,{position:[0,0,0],range:1,sourceRadius:0,normalBias:0,strength:0,nearPlane:.1})}function oo(e,t,i){let n=e.slice(0,t);for(;n.length<t;)n.push(i);return n}var ao={name:"pbrShadow",dependencies:[U,bt],bindingLayout:[{name:"pbrShadow",group:0}],uniformTypes:{viewMatrix:"mat4x4<f32>",enabled:"i32"},defaultUniforms:{viewMatrix:[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],enabled:1},getUniforms(e={}){return{...e.viewMatrix?{viewMatrix:e.viewMatrix}:{},...e.enabled===void 0?{}:{enabled:Number(e.enabled)}}},source:`
|
|
13033
|
+
struct PBRShadowUniforms {
|
|
13034
|
+
viewMatrix: mat4x4f,
|
|
13035
|
+
enabled: i32,
|
|
13036
|
+
};
|
|
13037
|
+
@group(0) @binding(auto) var<uniform> pbrShadow: PBRShadowUniforms;
|
|
13038
|
+
fn pbrShadow_filterColorWithDirectionalContact(vertexColor: vec4f, worldPosition: vec3f, worldNormal: vec3f, contactVisibility: f32) -> vec4f {
|
|
13039
|
+
var directionalVisibility = 1.0;
|
|
13040
|
+
var pointVisibility = vec4f(1.0);
|
|
13041
|
+
var spotVisibility = vec4f(1.0);
|
|
13042
|
+
if (pbrShadow.enabled != 0) {
|
|
13043
|
+
let normal = normalize(worldNormal);
|
|
13044
|
+
let viewDepth = -(pbrShadow.viewMatrix * vec4f(worldPosition, 1.0)).z;
|
|
13045
|
+
directionalVisibility = shadow_getDirectionalFactor(worldPosition, normal, viewDepth);
|
|
13046
|
+
for (var index = 0; index < 4; index++) {
|
|
13047
|
+
pointVisibility[index] = shadow_getPointFactor(index, worldPosition, normal);
|
|
13048
|
+
spotVisibility[index] = shadow_getSpotFactor(index, worldPosition, normal);
|
|
13049
|
+
}
|
|
13050
|
+
}
|
|
13051
|
+
return pbr_filterColorWithShadows(vertexColor, min(directionalVisibility, contactVisibility), pointVisibility, spotVisibility);
|
|
13052
|
+
}
|
|
13053
|
+
fn pbrShadow_filterColor(vertexColor: vec4f, worldPosition: vec3f, worldNormal: vec3f) -> vec4f {
|
|
13054
|
+
return pbrShadow_filterColorWithDirectionalContact(vertexColor, worldPosition, worldNormal, 1.0);
|
|
13055
|
+
}`,fs:`
|
|
13056
|
+
layout(std140) uniform pbrShadowUniforms {
|
|
13057
|
+
mat4 viewMatrix;
|
|
13058
|
+
int enabled;
|
|
13059
|
+
} pbrShadow;
|
|
13060
|
+
vec4 pbrShadow_filterColorWithDirectionalContact(vec4 vertexColor, vec3 worldPosition, vec3 worldNormal, float contactVisibility) {
|
|
13061
|
+
float directionalVisibility = 1.0;
|
|
13062
|
+
vec4 pointVisibility = vec4(1.0);
|
|
13063
|
+
vec4 spotVisibility = vec4(1.0);
|
|
13064
|
+
if (pbrShadow.enabled != 0) {
|
|
13065
|
+
vec3 normal = normalize(worldNormal);
|
|
13066
|
+
float viewDepth = -(pbrShadow.viewMatrix * vec4(worldPosition, 1.0)).z;
|
|
13067
|
+
directionalVisibility = shadow_getDirectionalFactor(worldPosition, normal, viewDepth);
|
|
13068
|
+
for (int index = 0; index < 4; index++) {
|
|
13069
|
+
pointVisibility[index] = shadow_getPointFactor(index, worldPosition, normal);
|
|
13070
|
+
spotVisibility[index] = shadow_getSpotFactor(index, worldPosition, normal);
|
|
13071
|
+
}
|
|
13072
|
+
}
|
|
13073
|
+
return pbr_filterColorWithShadows(vertexColor, min(directionalVisibility, contactVisibility), pointVisibility, spotVisibility);
|
|
13074
|
+
}
|
|
13075
|
+
vec4 pbrShadow_filterColor(vec4 vertexColor, vec3 worldPosition, vec3 worldNormal) {
|
|
13076
|
+
return pbrShadow_filterColorWithDirectionalContact(vertexColor, worldPosition, worldNormal, 1.0);
|
|
13077
|
+
}`};var so={name:"pbrSurface",dependencies:[U],bindingLayout:[{name:"pbrSurface",group:0}],uniformTypes:{viewMatrix:"mat4x4<f32>",useMaterialNormals:"i32"},defaultUniforms:{viewMatrix:[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],useMaterialNormals:0},getUniforms(e={}){return{...e.viewMatrix?{viewMatrix:e.viewMatrix}:{},...e.useMaterialNormals===void 0?{}:{useMaterialNormals:Number(e.useMaterialNormals)}}},source:`
|
|
13078
|
+
struct PBRSurfaceUniforms {
|
|
13079
|
+
viewMatrix: mat4x4f,
|
|
13080
|
+
useMaterialNormals: i32,
|
|
13081
|
+
};
|
|
13082
|
+
@group(0) @binding(auto) var<uniform> pbrSurface: PBRSurfaceUniforms;
|
|
13083
|
+
fn pbrSurface_getColor() -> vec4f {
|
|
13084
|
+
#ifdef HAS_NORMALS
|
|
13085
|
+
var normal = normalize(fragmentInputs.pbr_vNormal);
|
|
13086
|
+
#ifdef DOUBLE_SIDED
|
|
13087
|
+
if (!pbr_frontFacing) {normal = -normal;}
|
|
13088
|
+
#endif
|
|
13089
|
+
#else
|
|
13090
|
+
var normal = normalize(cross(dpdy(fragmentInputs.pbr_vPosition), dpdx(fragmentInputs.pbr_vPosition)));
|
|
13091
|
+
#endif
|
|
13092
|
+
#ifdef HAS_NORMALMAP
|
|
13093
|
+
if (pbrSurface.useMaterialNormals != 0) {
|
|
13094
|
+
let coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
|
|
13095
|
+
normal = getNormal(getTBN(coordinates), coordinates);
|
|
13096
|
+
}
|
|
13097
|
+
#else
|
|
13098
|
+
#ifdef HAS_BUMPMAP
|
|
13099
|
+
if (pbrSurface.useMaterialNormals != 0) {
|
|
13100
|
+
let coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
|
|
13101
|
+
normal = getNormal(getTBN(coordinates), coordinates);
|
|
13102
|
+
}
|
|
13103
|
+
#endif
|
|
13104
|
+
#endif
|
|
13105
|
+
let viewNormal = normalize((pbrSurface.viewMatrix * vec4f(normal, 0.0)).xyz);
|
|
13106
|
+
return vec4f(viewNormal * 0.5 + vec3f(0.5), 1.0);
|
|
13107
|
+
}`,fs:`
|
|
13108
|
+
layout(std140) uniform pbrSurfaceUniforms {
|
|
13109
|
+
mat4 viewMatrix;
|
|
13110
|
+
int useMaterialNormals;
|
|
13111
|
+
} pbrSurface;
|
|
13112
|
+
vec4 pbrSurface_getColor() {
|
|
13113
|
+
#ifdef HAS_NORMALS
|
|
13114
|
+
#ifdef HAS_TANGENTS
|
|
13115
|
+
vec3 normal = normalize(pbr_vTBN[2]);
|
|
13116
|
+
#else
|
|
13117
|
+
vec3 normal = normalize(pbr_vNormal);
|
|
13118
|
+
#endif
|
|
13119
|
+
#ifdef DOUBLE_SIDED
|
|
13120
|
+
if (!gl_FrontFacing) normal = -normal;
|
|
13121
|
+
#endif
|
|
13122
|
+
#else
|
|
13123
|
+
vec3 normal = normalize(cross(dFdx(pbr_vPosition), dFdy(pbr_vPosition)));
|
|
13124
|
+
#endif
|
|
13125
|
+
#ifdef HAS_NORMALMAP
|
|
13126
|
+
if (pbrSurface.useMaterialNormals != 0) {
|
|
13127
|
+
vec2 coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
|
|
13128
|
+
normal = getNormal(getTBN(coordinates), coordinates);
|
|
13129
|
+
}
|
|
13130
|
+
#else
|
|
13131
|
+
#ifdef HAS_BUMPMAP
|
|
13132
|
+
if (pbrSurface.useMaterialNormals != 0) {
|
|
13133
|
+
vec2 coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
|
|
13134
|
+
normal = getNormal(getTBN(coordinates), coordinates);
|
|
13135
|
+
}
|
|
13136
|
+
#endif
|
|
13137
|
+
#endif
|
|
13138
|
+
vec3 viewNormal = normalize((pbrSurface.viewMatrix * vec4(normal, 0.0)).xyz);
|
|
13139
|
+
return vec4(viewNormal * 0.5 + 0.5, 1.0);
|
|
13140
|
+
}`};var lo=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],co={name:"contactShadowTrace",source:`struct contactShadowTraceUniforms {
|
|
13141
|
+
projectionMatrix: mat4x4f,
|
|
13142
|
+
inverseProjectionMatrix: mat4x4f,
|
|
13143
|
+
lightDirectionView: vec3f,
|
|
13144
|
+
maxDistance: f32,
|
|
13145
|
+
thickness: f32,
|
|
13146
|
+
stepCount: f32,
|
|
13147
|
+
frameIndex: f32,
|
|
13148
|
+
normalBias: f32,
|
|
13149
|
+
};
|
|
13150
|
+
@group(0) @binding(auto) var<uniform> contactShadowTrace: contactShadowTraceUniforms;
|
|
13151
|
+
@group(0) @binding(auto) var depthTexture: texture_depth_2d;
|
|
13152
|
+
@group(0) @binding(auto) var depthTextureSampler: sampler;
|
|
13153
|
+
@group(0) @binding(auto) var normalTexture: texture_2d<f32>;
|
|
13154
|
+
@group(0) @binding(auto) var normalTextureSampler: sampler;
|
|
13155
|
+
|
|
13156
|
+
fn contactShadow_reconstructViewPosition(uv: vec2f, depth: f32) -> vec3f {
|
|
13157
|
+
let clip = vec4f(uv.x * 2.0 - 1.0, 1.0 - uv.y * 2.0, depth, 1.0);
|
|
13158
|
+
let view = contactShadowTrace.inverseProjectionMatrix * clip;
|
|
13159
|
+
return view.xyz / max(abs(view.w), 0.00001);
|
|
13160
|
+
}
|
|
13161
|
+
|
|
13162
|
+
fn contactShadow_projectViewPosition(position: vec3f) -> vec2f {
|
|
13163
|
+
let clip = contactShadowTrace.projectionMatrix * vec4f(position, 1.0);
|
|
13164
|
+
let ndc = clip.xy / max(abs(clip.w), 0.00001);
|
|
13165
|
+
return vec2f(ndc.x * 0.5 + 0.5, 0.5 - ndc.y * 0.5);
|
|
13166
|
+
}
|
|
13167
|
+
|
|
13168
|
+
fn contactShadowTrace_sampleColor(
|
|
13169
|
+
sourceTexture: texture_2d<f32>, sourceTextureSampler: sampler, texSize: vec2f, texCoord: vec2f
|
|
13170
|
+
) -> vec4f {
|
|
13171
|
+
let centerDepth = textureSampleLevel(depthTexture, depthTextureSampler, texCoord, 0);
|
|
13172
|
+
if (centerDepth >= 0.99999) { return vec4f(1.0); }
|
|
13173
|
+
let centerNormal = normalize(textureSampleLevel(normalTexture, normalTextureSampler, texCoord, 0.0).xyz * 2.0 - 1.0);
|
|
13174
|
+
let centerPosition = contactShadow_reconstructViewPosition(texCoord, centerDepth) + centerNormal * contactShadowTrace.normalBias;
|
|
13175
|
+
let rayDirection = normalize(contactShadowTrace.lightDirectionView);
|
|
13176
|
+
let noise = fract(sin(dot(texCoord * texSize + contactShadowTrace.frameIndex, vec2f(12.9898, 78.233))) * 43758.5453);
|
|
13177
|
+
for (var index: i32 = 0; index < 40; index++) {
|
|
13178
|
+
if (f32(index) >= contactShadowTrace.stepCount) { break; }
|
|
13179
|
+
let fraction = (f32(index) + 0.35 + noise * 0.5) / max(contactShadowTrace.stepCount, 1.0);
|
|
13180
|
+
let travel = contactShadowTrace.maxDistance * fraction * fraction;
|
|
13181
|
+
let rayPosition = centerPosition + rayDirection * travel;
|
|
13182
|
+
let sampleUv = contactShadow_projectViewPosition(rayPosition);
|
|
13183
|
+
if (any(sampleUv <= vec2f(0.0)) || any(sampleUv >= vec2f(1.0))) { break; }
|
|
13184
|
+
let sampleDepth = textureSampleLevel(depthTexture, depthTextureSampler, sampleUv, 0);
|
|
13185
|
+
if (sampleDepth >= 0.99999) { continue; }
|
|
13186
|
+
let scenePosition = contactShadow_reconstructViewPosition(sampleUv, sampleDepth);
|
|
13187
|
+
let depthDelta = (-rayPosition.z) - (-scenePosition.z);
|
|
13188
|
+
let hitThickness = contactShadowTrace.thickness + travel * 0.02;
|
|
13189
|
+
if (depthDelta >= 0.0 && depthDelta <= hitThickness) {
|
|
13190
|
+
let distanceFade = 1.0 - clamp(travel / contactShadowTrace.maxDistance, 0.0, 1.0);
|
|
13191
|
+
return vec4f(vec3f(1.0 - distanceFade), 1.0);
|
|
13192
|
+
}
|
|
13193
|
+
if (depthDelta > hitThickness * 8.0) { break; }
|
|
13194
|
+
}
|
|
13195
|
+
return vec4f(1.0);
|
|
13196
|
+
}`,fs:`
|
|
13197
|
+
layout(std140) uniform contactShadowTraceUniforms {
|
|
13198
|
+
mat4 projectionMatrix;
|
|
13199
|
+
mat4 inverseProjectionMatrix;
|
|
13200
|
+
vec3 lightDirectionView;
|
|
13201
|
+
float maxDistance;
|
|
13202
|
+
float thickness;
|
|
13203
|
+
float stepCount;
|
|
13204
|
+
float frameIndex;
|
|
13205
|
+
float normalBias;
|
|
13206
|
+
} contactShadowTrace;
|
|
13207
|
+
uniform sampler2D depthTexture;
|
|
13208
|
+
uniform sampler2D normalTexture;
|
|
13209
|
+
vec3 contactShadow_reconstructViewPosition(vec2 uv, float depth) {
|
|
13210
|
+
vec4 view = contactShadowTrace.inverseProjectionMatrix * vec4(uv * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
|
|
13211
|
+
return view.xyz / max(abs(view.w), 0.00001);
|
|
13212
|
+
}
|
|
13213
|
+
vec2 contactShadow_projectViewPosition(vec3 position) {
|
|
13214
|
+
vec4 clip = contactShadowTrace.projectionMatrix * vec4(position,1.0);
|
|
13215
|
+
return clip.xy / max(abs(clip.w),0.00001) * 0.5 + 0.5;
|
|
13216
|
+
}
|
|
13217
|
+
vec4 contactShadowTrace_sampleColor(sampler2D sourceTexture,vec2 texSize,vec2 texCoord) {
|
|
13218
|
+
float centerDepth = texture(depthTexture,texCoord).r;
|
|
13219
|
+
if(centerDepth >= 0.99999) return vec4(1.0);
|
|
13220
|
+
vec3 centerNormal = normalize(texture(normalTexture,texCoord).xyz * 2.0 - 1.0);
|
|
13221
|
+
vec3 centerPosition = contactShadow_reconstructViewPosition(texCoord,centerDepth) + centerNormal * contactShadowTrace.normalBias;
|
|
13222
|
+
vec3 rayDirection = normalize(contactShadowTrace.lightDirectionView);
|
|
13223
|
+
float noise = fract(sin(dot(texCoord * texSize + contactShadowTrace.frameIndex,vec2(12.9898,78.233))) * 43758.5453);
|
|
13224
|
+
for(int index=0;index<40;index++) {
|
|
13225
|
+
if(float(index)>=contactShadowTrace.stepCount) break;
|
|
13226
|
+
float fraction=(float(index)+0.35+noise*0.5)/max(contactShadowTrace.stepCount,1.0);
|
|
13227
|
+
float travel=contactShadowTrace.maxDistance*fraction*fraction;
|
|
13228
|
+
vec3 rayPosition=centerPosition+rayDirection*travel;
|
|
13229
|
+
vec2 sampleUv=contactShadow_projectViewPosition(rayPosition);
|
|
13230
|
+
if(any(lessThanEqual(sampleUv,vec2(0.0)))||any(greaterThanEqual(sampleUv,vec2(1.0))))break;
|
|
13231
|
+
float sampleDepth=texture(depthTexture,sampleUv).r;
|
|
13232
|
+
if(sampleDepth>=0.99999)continue;
|
|
13233
|
+
vec3 scenePosition=contactShadow_reconstructViewPosition(sampleUv,sampleDepth);
|
|
13234
|
+
float depthDelta=(-rayPosition.z)-(-scenePosition.z);
|
|
13235
|
+
float hitThickness=contactShadowTrace.thickness+travel*0.02;
|
|
13236
|
+
if(depthDelta>=0.0&&depthDelta<=hitThickness) {
|
|
13237
|
+
float distanceFade=1.0-clamp(travel/contactShadowTrace.maxDistance,0.0,1.0);
|
|
13238
|
+
return vec4(vec3(1.0-distanceFade),1.0);
|
|
13239
|
+
}
|
|
13240
|
+
if(depthDelta>hitThickness*8.0)break;
|
|
13241
|
+
}
|
|
13242
|
+
return vec4(1.0);
|
|
13243
|
+
}
|
|
13244
|
+
`,bindingLayout:[{name:"depthTexture",group:0},{name:"normalTexture",group:0}],props:{},uniforms:{},bindings:{},uniformTypes:{projectionMatrix:"mat4x4<f32>",inverseProjectionMatrix:"mat4x4<f32>",lightDirectionView:"vec3<f32>",maxDistance:"f32",thickness:"f32",stepCount:"f32",frameIndex:"f32",normalBias:"f32"},propTypes:{projectionMatrix:{value:lo,private:!0},inverseProjectionMatrix:{value:lo,private:!0},lightDirectionView:{value:[0,1,0],private:!0},maxDistance:{value:4,min:.1,softMax:16},thickness:{value:.12,min:.005,softMax:1},stepCount:{value:24,min:1,max:40},frameIndex:{value:0,private:!0},normalBias:{value:.035,min:0,softMax:.2}},passes:[{sampler:!0}]},fo={name:"contactShadowBilateralBlur",source:`struct contactShadowBilateralBlurUniforms {
|
|
13245
|
+
direction: vec2f,
|
|
13246
|
+
radius: f32,
|
|
13247
|
+
depthSigma: f32,
|
|
13248
|
+
normalPower: f32,
|
|
13249
|
+
};
|
|
13250
|
+
@group(0) @binding(auto) var<uniform> contactShadowBilateralBlur: contactShadowBilateralBlurUniforms;
|
|
13251
|
+
@group(0) @binding(auto) var depthTexture: texture_depth_2d;
|
|
13252
|
+
@group(0) @binding(auto) var depthTextureSampler: sampler;
|
|
13253
|
+
@group(0) @binding(auto) var normalTexture: texture_2d<f32>;
|
|
13254
|
+
@group(0) @binding(auto) var normalTextureSampler: sampler;
|
|
13255
|
+
|
|
13256
|
+
fn contactShadowBilateralBlur_sampleColor(
|
|
13257
|
+
sourceTexture: texture_2d<f32>, sourceTextureSampler: sampler, texSize: vec2f, texCoord: vec2f
|
|
13258
|
+
) -> vec4f {
|
|
13259
|
+
let sourceDimensions = vec2f(textureDimensions(sourceTexture));
|
|
13260
|
+
let texel = contactShadowBilateralBlur.direction / sourceDimensions;
|
|
13261
|
+
let centerDepth = textureSampleLevel(depthTexture, depthTextureSampler, texCoord, 0);
|
|
13262
|
+
let centerNormal = normalize(textureSampleLevel(normalTexture, normalTextureSampler, texCoord, 0.0).xyz * 2.0 - 1.0);
|
|
13263
|
+
var result = textureSampleLevel(sourceTexture, sourceTextureSampler, texCoord, 0.0).r;
|
|
13264
|
+
var totalWeight = 1.0;
|
|
13265
|
+
for (var index: i32 = 1; index <= 6; index++) {
|
|
13266
|
+
if (f32(index) > contactShadowBilateralBlur.radius) { break; }
|
|
13267
|
+
for (var side: i32 = -1; side <= 1; side += 2) {
|
|
13268
|
+
let sampleUv = clamp(texCoord + texel * f32(index * side), vec2f(0.0), vec2f(1.0));
|
|
13269
|
+
let sampleDepth = textureSampleLevel(depthTexture, depthTextureSampler, sampleUv, 0);
|
|
13270
|
+
let sampleNormal = normalize(textureSampleLevel(normalTexture, normalTextureSampler, sampleUv, 0.0).xyz * 2.0 - 1.0);
|
|
13271
|
+
let depthDelta = abs(sampleDepth - centerDepth);
|
|
13272
|
+
let depthWeight = exp(-(depthDelta * depthDelta) / max(2.0 * contactShadowBilateralBlur.depthSigma * contactShadowBilateralBlur.depthSigma, 0.000001));
|
|
13273
|
+
let normalWeight = pow(max(dot(centerNormal, sampleNormal), 0.0), contactShadowBilateralBlur.normalPower);
|
|
13274
|
+
let spatialWeight = exp(-f32(index * index) / 8.0);
|
|
13275
|
+
let weight = depthWeight * normalWeight * spatialWeight;
|
|
13276
|
+
result += textureSampleLevel(sourceTexture, sourceTextureSampler, sampleUv, 0.0).r * weight;
|
|
13277
|
+
totalWeight += weight;
|
|
13278
|
+
}
|
|
13279
|
+
}
|
|
13280
|
+
let visibility = result / totalWeight;
|
|
13281
|
+
return vec4f(vec3f(visibility), 1.0);
|
|
13282
|
+
}`,fs:`
|
|
13283
|
+
layout(std140) uniform contactShadowBilateralBlurUniforms {
|
|
13284
|
+
vec2 direction;
|
|
13285
|
+
float radius;
|
|
13286
|
+
float depthSigma;
|
|
13287
|
+
float normalPower;
|
|
13288
|
+
} contactShadowBilateralBlur;
|
|
13289
|
+
uniform sampler2D depthTexture;
|
|
13290
|
+
uniform sampler2D normalTexture;
|
|
13291
|
+
vec4 contactShadowBilateralBlur_sampleColor(sampler2D sourceTexture,vec2 texSize,vec2 texCoord) {
|
|
13292
|
+
vec2 texel=contactShadowBilateralBlur.direction/vec2(textureSize(sourceTexture,0));
|
|
13293
|
+
float centerDepth=texture(depthTexture,texCoord).r;
|
|
13294
|
+
vec3 centerNormal=normalize(texture(normalTexture,texCoord).xyz*2.0-1.0);
|
|
13295
|
+
float result=texture(sourceTexture,texCoord).r;
|
|
13296
|
+
float totalWeight=1.0;
|
|
13297
|
+
for(int index=1;index<=6;index++) {
|
|
13298
|
+
if(float(index)>contactShadowBilateralBlur.radius)break;
|
|
13299
|
+
for(int side=-1;side<=1;side+=2) {
|
|
13300
|
+
vec2 sampleUv=clamp(texCoord+texel*float(index*side),vec2(0.0),vec2(1.0));
|
|
13301
|
+
float sampleDepth=texture(depthTexture,sampleUv).r;
|
|
13302
|
+
vec3 sampleNormal=normalize(texture(normalTexture,sampleUv).xyz*2.0-1.0);
|
|
13303
|
+
float depthDelta=abs(sampleDepth-centerDepth);
|
|
13304
|
+
float depthWeight=exp(-(depthDelta*depthDelta)/max(2.0*contactShadowBilateralBlur.depthSigma*contactShadowBilateralBlur.depthSigma,0.000001));
|
|
13305
|
+
float normalWeight=pow(max(dot(centerNormal,sampleNormal),0.0),contactShadowBilateralBlur.normalPower);
|
|
13306
|
+
float spatialWeight=exp(-float(index*index)/8.0);
|
|
13307
|
+
float weight=depthWeight*normalWeight*spatialWeight;
|
|
13308
|
+
result+=texture(sourceTexture,sampleUv).r*weight;totalWeight+=weight;
|
|
13309
|
+
}
|
|
13310
|
+
}
|
|
13311
|
+
return vec4(vec3(result/totalWeight),1.0);
|
|
13312
|
+
}
|
|
13313
|
+
`,bindingLayout:[{name:"depthTexture",group:0},{name:"normalTexture",group:0}],props:{},uniforms:{},bindings:{},uniformTypes:{direction:"vec2<f32>",radius:"f32",depthSigma:"f32",normalPower:"f32"},propTypes:{direction:{value:[1,0],private:!0},radius:{value:4,min:1,max:6},depthSigma:{value:.006,min:1e-4,softMax:.05},normalPower:{value:24,min:1,softMax:64}},passes:[{sampler:!0}]},uo={name:"contactShadowComposite",source:`struct contactShadowCompositeUniforms {
|
|
13314
|
+
strength: f32,
|
|
13315
|
+
debugMode: f32,
|
|
13316
|
+
};
|
|
13317
|
+
@group(0) @binding(auto) var<uniform> contactShadowComposite: contactShadowCompositeUniforms;
|
|
13318
|
+
@group(0) @binding(auto) var contactShadowTexture: texture_2d<f32>;
|
|
13319
|
+
@group(0) @binding(auto) var contactShadowTextureSampler: sampler;
|
|
13320
|
+
@group(0) @binding(auto) var directionalDirectTexture: texture_2d<f32>;
|
|
13321
|
+
@group(0) @binding(auto) var directionalDirectTextureSampler: sampler;
|
|
13322
|
+
@group(0) @binding(auto) var shadowDebugTexture: texture_2d<f32>;
|
|
13323
|
+
@group(0) @binding(auto) var shadowDebugTextureSampler: sampler;
|
|
13324
|
+
|
|
13325
|
+
fn contactShadowComposite_sampleColor(
|
|
13326
|
+
sourceTexture: texture_2d<f32>, sourceTextureSampler: sampler, texSize: vec2f, texCoord: vec2f
|
|
13327
|
+
) -> vec4f {
|
|
13328
|
+
let color = textureSampleLevel(sourceTexture, sourceTextureSampler, texCoord, 0.0);
|
|
13329
|
+
let contact = textureSampleLevel(contactShadowTexture, contactShadowTextureSampler, texCoord, 0.0).r;
|
|
13330
|
+
let appliedContact = mix(1.0, contact, contactShadowComposite.strength);
|
|
13331
|
+
if (contactShadowComposite.debugMode > 0.5 && contactShadowComposite.debugMode < 1.5) {
|
|
13332
|
+
return vec4f(vec3f(contact), 1.0);
|
|
13333
|
+
}
|
|
13334
|
+
if (contactShadowComposite.debugMode >= 1.5) {
|
|
13335
|
+
let factors = textureSampleLevel(shadowDebugTexture, shadowDebugTextureSampler, texCoord, 0.0).rgb;
|
|
13336
|
+
return vec4f(vec3f(factors.x * factors.y * factors.z * contact), 1.0);
|
|
13337
|
+
}
|
|
13338
|
+
let directionalDirect = textureSampleLevel(
|
|
13339
|
+
directionalDirectTexture,
|
|
13340
|
+
directionalDirectTextureSampler,
|
|
13341
|
+
texCoord,
|
|
13342
|
+
0.0
|
|
13343
|
+
).rgb;
|
|
13344
|
+
return vec4f(max(color.rgb - directionalDirect * (1.0 - appliedContact), vec3f(0.0)), color.a);
|
|
13345
|
+
}`,fs:`
|
|
13346
|
+
layout(std140) uniform contactShadowCompositeUniforms {
|
|
13347
|
+
float strength;
|
|
13348
|
+
float debugMode;
|
|
13349
|
+
} contactShadowComposite;
|
|
13350
|
+
uniform sampler2D contactShadowTexture;
|
|
13351
|
+
uniform sampler2D directionalDirectTexture;
|
|
13352
|
+
uniform sampler2D shadowDebugTexture;
|
|
13353
|
+
vec4 contactShadowComposite_sampleColor(sampler2D sourceTexture,vec2 texSize,vec2 texCoord) {
|
|
13354
|
+
vec4 color=texture(sourceTexture,texCoord);
|
|
13355
|
+
float contact=texture(contactShadowTexture,texCoord).r;
|
|
13356
|
+
float appliedContact=mix(1.0,contact,contactShadowComposite.strength);
|
|
13357
|
+
if(contactShadowComposite.debugMode>0.5&&contactShadowComposite.debugMode<1.5)return vec4(vec3(contact),1.0);
|
|
13358
|
+
if(contactShadowComposite.debugMode>=1.5){vec3 factors=texture(shadowDebugTexture,texCoord).rgb;return vec4(vec3(factors.x*factors.y*factors.z*contact),1.0);}
|
|
13359
|
+
vec3 directionalDirect=texture(directionalDirectTexture,texCoord).rgb;
|
|
13360
|
+
return vec4(max(color.rgb-directionalDirect*(1.0-appliedContact),vec3(0.0)),color.a);
|
|
13361
|
+
}
|
|
13362
|
+
`,bindingLayout:[{name:"contactShadowTexture",group:0},{name:"directionalDirectTexture",group:0},{name:"shadowDebugTexture",group:0}],props:{},uniforms:{},bindings:{},uniformTypes:{strength:"f32",debugMode:"f32"},propTypes:{strength:{value:1,min:0,max:1},debugMode:{value:0,min:0,max:2,private:!0}},passes:[{sampler:!0}]};var po={name:"pbrContactShadow",dependencies:[U],bindingLayout:[{name:"pbrContactShadow",group:0},{name:"contactShadowTexture",group:2}],uniformTypes:{viewport:"vec4<f32>",strength:"f32",enabled:"i32"},defaultUniforms:{viewport:[0,0,1,1],strength:1,enabled:1},getUniforms(e={}){return{...e.viewport?{viewport:e.viewport}:{},...e.strength===void 0?{}:{strength:e.strength},...e.enabled===void 0?{}:{enabled:Number(e.enabled)},...e.contactShadowTexture?{contactShadowTexture:e.contactShadowTexture}:{}}},source:`
|
|
13363
|
+
struct PBRContactShadowUniforms {
|
|
13364
|
+
viewport: vec4f,
|
|
13365
|
+
strength: f32,
|
|
13366
|
+
enabled: i32,
|
|
13367
|
+
};
|
|
13368
|
+
@group(0) @binding(auto) var<uniform> pbrContactShadow: PBRContactShadowUniforms;
|
|
13369
|
+
@group(2) @binding(auto) var contactShadowTexture: texture_2d<f32>;
|
|
13370
|
+
@group(2) @binding(auto) var contactShadowTextureSampler: sampler;
|
|
13371
|
+
fn pbrContactShadow_getFactor(pixelPosition:vec2f)->f32 {
|
|
13372
|
+
if(pbrContactShadow.enabled==0){return 1.0;}
|
|
13373
|
+
let coordinates=(pixelPosition-pbrContactShadow.viewport.xy)/pbrContactShadow.viewport.zw;
|
|
13374
|
+
if(any(coordinates<vec2f(0.0))||any(coordinates>vec2f(1.0))){return 1.0;}
|
|
13375
|
+
let visibility=textureSampleLevel(contactShadowTexture,contactShadowTextureSampler,coordinates,0.0).r;
|
|
13376
|
+
return mix(1.0,clamp(visibility,0.0,1.0),clamp(pbrContactShadow.strength,0.0,1.0));
|
|
13377
|
+
}
|
|
13378
|
+
fn pbrContactShadow_filterColor(vertexColor:vec4f,pixelPosition:vec2f)->vec4f {
|
|
13379
|
+
return pbr_filterColorWithShadows(vertexColor,pbrContactShadow_getFactor(pixelPosition),vec4f(1.0),vec4f(1.0));
|
|
13380
|
+
}`,fs:`
|
|
13381
|
+
layout(std140) uniform pbrContactShadowUniforms {
|
|
13382
|
+
vec4 viewport;
|
|
13383
|
+
float strength;
|
|
13384
|
+
int enabled;
|
|
13385
|
+
} pbrContactShadow;
|
|
13386
|
+
uniform sampler2D contactShadowTexture;
|
|
13387
|
+
float pbrContactShadow_getFactor(vec2 pixelPosition) {
|
|
13388
|
+
if(pbrContactShadow.enabled==0)return 1.0;
|
|
13389
|
+
vec2 coordinates=(pixelPosition-pbrContactShadow.viewport.xy)/pbrContactShadow.viewport.zw;
|
|
13390
|
+
if(any(lessThan(coordinates,vec2(0.0)))||any(greaterThan(coordinates,vec2(1.0))))return 1.0;
|
|
13391
|
+
float visibility=texture(contactShadowTexture,coordinates).r;
|
|
13392
|
+
return mix(1.0,clamp(visibility,0.0,1.0),clamp(pbrContactShadow.strength,0.0,1.0));
|
|
13393
|
+
}
|
|
13394
|
+
vec4 pbrContactShadow_filterColor(vec4 vertexColor,vec2 pixelPosition) {
|
|
13395
|
+
return pbr_filterColorWithShadows(vertexColor,pbrContactShadow_getFactor(pixelPosition),vec4(1.0),vec4(1.0));
|
|
13396
|
+
}`};var go={name:"clusteredLightGrid",source:`
|
|
13397
|
+
fn clusteredLightGrid_getIndex(coordinates: vec2f, viewDepth: f32, dimensions: vec3u, nearPlane: f32, farPlane: f32) -> u32 {
|
|
13398
|
+
let tile = min(vec2u(clamp(coordinates, vec2f(0.0), vec2f(0.999999)) * vec2f(dimensions.xy)), dimensions.xy - vec2u(1));
|
|
13399
|
+
let normalizedDepth = clamp(log(clamp(viewDepth, nearPlane, farPlane) / nearPlane) / log(farPlane / nearPlane), 0.0, 0.999999);
|
|
13400
|
+
let depthSlice = min(u32(normalizedDepth * f32(dimensions.z)), dimensions.z - 1u);
|
|
13401
|
+
return (depthSlice * dimensions.y + tile.y) * dimensions.x + tile.x;
|
|
13402
|
+
}
|
|
13403
|
+
`};var mo={name:"pbrAmbientOcclusion",dependencies:[U],bindingLayout:[{name:"pbrAmbientOcclusion",group:0},{name:"ambientOcclusionTexture",group:2}],uniformTypes:{viewport:"vec4<f32>",strength:"f32",enabled:"i32"},defaultUniforms:{viewport:[0,0,1,1],strength:1,enabled:1},getUniforms(e={}){return{...e.viewport?{viewport:e.viewport}:{},...e.strength===void 0?{}:{strength:e.strength},...e.enabled===void 0?{}:{enabled:Number(e.enabled)},...e.ambientOcclusionTexture?{ambientOcclusionTexture:e.ambientOcclusionTexture}:{}}},source:`
|
|
13404
|
+
struct PBRAmbientOcclusionUniforms {
|
|
13405
|
+
viewport: vec4f,
|
|
13406
|
+
strength: f32,
|
|
13407
|
+
enabled: i32,
|
|
13408
|
+
};
|
|
13409
|
+
@group(0) @binding(auto) var<uniform> pbrAmbientOcclusion: PBRAmbientOcclusionUniforms;
|
|
13410
|
+
@group(2) @binding(auto) var ambientOcclusionTexture: texture_2d<f32>;
|
|
13411
|
+
@group(2) @binding(auto) var ambientOcclusionTextureSampler: sampler;
|
|
13412
|
+
fn pbrAmbientOcclusion_getFactor(pixelPosition:vec2f)->f32 {
|
|
13413
|
+
if(pbrAmbientOcclusion.enabled==0){return 1.0;}
|
|
13414
|
+
let coordinates=(pixelPosition-pbrAmbientOcclusion.viewport.xy)/pbrAmbientOcclusion.viewport.zw;
|
|
13415
|
+
if(any(coordinates<vec2f(0.0))||any(coordinates>vec2f(1.0))){return 1.0;}
|
|
13416
|
+
let visibility=textureSampleLevel(ambientOcclusionTexture,ambientOcclusionTextureSampler,coordinates,0.0).r;
|
|
13417
|
+
return mix(1.0,clamp(visibility,0.0,1.0),clamp(pbrAmbientOcclusion.strength,0.0,1.0));
|
|
13418
|
+
}
|
|
13419
|
+
fn pbrAmbientOcclusion_setFactor(pixelPosition:vec2f) {
|
|
13420
|
+
pbr_ambientVisibility = pbrAmbientOcclusion_getFactor(pixelPosition);
|
|
13421
|
+
}`,fs:`
|
|
13422
|
+
layout(std140) uniform pbrAmbientOcclusionUniforms {
|
|
13423
|
+
vec4 viewport;
|
|
13424
|
+
float strength;
|
|
13425
|
+
int enabled;
|
|
13426
|
+
} pbrAmbientOcclusion;
|
|
13427
|
+
uniform sampler2D ambientOcclusionTexture;
|
|
13428
|
+
float pbrAmbientOcclusion_getFactor(vec2 pixelPosition) {
|
|
13429
|
+
if(pbrAmbientOcclusion.enabled==0)return 1.0;
|
|
13430
|
+
vec2 coordinates=(pixelPosition-pbrAmbientOcclusion.viewport.xy)/pbrAmbientOcclusion.viewport.zw;
|
|
13431
|
+
if(any(lessThan(coordinates,vec2(0.0)))||any(greaterThan(coordinates,vec2(1.0))))return 1.0;
|
|
13432
|
+
float visibility=texture(ambientOcclusionTexture,coordinates).r;
|
|
13433
|
+
return mix(1.0,clamp(visibility,0.0,1.0),clamp(pbrAmbientOcclusion.strength,0.0,1.0));
|
|
13434
|
+
}
|
|
13435
|
+
void pbrAmbientOcclusion_setFactor(vec2 pixelPosition) {
|
|
13436
|
+
pbr_ambientVisibility = pbrAmbientOcclusion_getFactor(pixelPosition);
|
|
13437
|
+
}`};var ho={name:"lightmapBake",dependencies:[U],bindingLayout:[{name:"lightmapBake",group:0}],uniformTypes:{uvSet:"i32",uvTransform:"mat3x3<f32>",chartId:"f32"},defaultUniforms:{uvSet:1,uvTransform:[1,0,0,0,1,0,0,0,1],chartId:1},getUniforms:e=>e,source:`
|
|
13438
|
+
struct LightmapBakeUniforms {uvSet: i32, uvTransform: mat3x3f, chartId: f32};
|
|
13439
|
+
@group(0) @binding(auto) var<uniform> lightmapBake: LightmapBakeUniforms;
|
|
13440
|
+
|
|
13441
|
+
fn lightmap_getIrradiance(position: vec3f, normal: vec3f, directionalVisibility: f32, pointVisibility: vec4f, spotVisibility: vec4f) -> vec3f {
|
|
13442
|
+
if (lighting.enabled == 0) {return vec3f(0.0);}
|
|
13443
|
+
var irradiance = lighting.ambientColor;
|
|
13444
|
+
for (var index = 0; index < lighting.directionalLightCount; index++) {
|
|
13445
|
+
let light = lighting_getDirectionalLight(index);
|
|
13446
|
+
irradiance += light.color * max(dot(normal, -normalize(light.direction)), 0.0) * select(1.0, directionalVisibility, index == 0);
|
|
13447
|
+
}
|
|
13448
|
+
for (var index = 0; index < lighting.pointLightCount; index++) {
|
|
13449
|
+
let light = lighting_getPointLight(index);
|
|
13450
|
+
let offset = light.position - position;
|
|
13451
|
+
let visibility = select(1.0, pointVisibility[min(index, 3)], index < 4);
|
|
13452
|
+
irradiance += light.color * max(dot(normal, normalize(offset)), 0.0) * visibility / max(getPointLightAttenuation(light, length(offset)), 0.0001);
|
|
13453
|
+
}
|
|
13454
|
+
for (var index = 0; index < lighting.spotLightCount; index++) {
|
|
13455
|
+
let light = lighting_getSpotLight(index);
|
|
13456
|
+
irradiance += light.color * max(dot(normal, normalize(light.position - position)), 0.0) * select(1.0, spotVisibility[min(index, 3)], index < 4) / max(getSpotLightAttenuation(light, position), 0.0001);
|
|
13457
|
+
}
|
|
13458
|
+
return irradiance;
|
|
13459
|
+
}
|
|
13460
|
+
`,vs:`layout(std140) uniform lightmapBakeUniforms {
|
|
13461
|
+
int uvSet;
|
|
13462
|
+
mat3 uvTransform;
|
|
13463
|
+
float chartId;
|
|
13464
|
+
} lightmapBake;`,fs:`layout(std140) uniform lightmapBakeUniforms {
|
|
13465
|
+
int uvSet;
|
|
13466
|
+
mat3 uvTransform;
|
|
13467
|
+
float chartId;
|
|
13468
|
+
} lightmapBake;
|
|
13469
|
+
|
|
13470
|
+
vec3 lightmap_getIrradiance(vec3 position, vec3 normal, float directionalVisibility, vec4 pointVisibility, vec4 spotVisibility) {
|
|
13471
|
+
if (lighting.enabled == 0) {return vec3(0.0);}
|
|
13472
|
+
vec3 irradiance = lighting.ambientColor;
|
|
13473
|
+
for (int index = 0; index < lighting.directionalLightCount; index++) {
|
|
13474
|
+
DirectionalLight light = lighting_getDirectionalLight(index);
|
|
13475
|
+
irradiance += light.color * max(dot(normal, -normalize(light.direction)), 0.0) * (index == 0 ? directionalVisibility : 1.0);
|
|
13476
|
+
}
|
|
13477
|
+
for (int index = 0; index < lighting.pointLightCount; index++) {
|
|
13478
|
+
PointLight light = lighting_getPointLight(index);
|
|
13479
|
+
vec3 offset = light.position - position;
|
|
13480
|
+
irradiance += light.color * max(dot(normal, normalize(offset)), 0.0) * (index < 4 ? pointVisibility[index] : 1.0) / max(getPointLightAttenuation(light, length(offset)), 0.0001);
|
|
13481
|
+
}
|
|
13482
|
+
for (int index = 0; index < lighting.spotLightCount; index++) {
|
|
13483
|
+
SpotLight light = lighting_getSpotLight(index);
|
|
13484
|
+
irradiance += light.color * max(dot(normal, normalize(light.position - position)), 0.0) * (index < 4 ? spotVisibility[index] : 1.0) / max(getSpotLightAttenuation(light, position), 0.0001);
|
|
13485
|
+
}
|
|
13486
|
+
return irradiance;
|
|
13487
|
+
}
|
|
13488
|
+
`};var vo={name:"lightmapFilter",bindingLayout:[{name:"lightmapFilter",group:0},{name:"currentTexture",group:0},{name:"previousTexture",group:0},{name:"chartTexture",group:0}],uniformTypes:{weight:"f32",mode:"i32"},defaultUniforms:{weight:1,mode:0},getUniforms:e=>e,source:`
|
|
13489
|
+
struct LightmapFilterUniforms {weight: f32, mode: i32};
|
|
13490
|
+
@group(0) @binding(auto) var<uniform> lightmapFilter: LightmapFilterUniforms;
|
|
13491
|
+
@group(0) @binding(auto) var currentTexture: texture_2d<f32>;
|
|
13492
|
+
@group(0) @binding(auto) var previousTexture: texture_2d<f32>;
|
|
13493
|
+
@group(0) @binding(auto) var chartTexture: texture_2d<f32>;
|
|
13494
|
+
fn lightmapFilter_getColor(coordinates: vec2i) -> vec4f {
|
|
13495
|
+
let current = textureLoad(currentTexture, coordinates, 0);
|
|
13496
|
+
if (lightmapFilter.mode == 0) {
|
|
13497
|
+
let previous = textureLoad(previousTexture, coordinates, 0);
|
|
13498
|
+
return vec4f(mix(previous.rgb, current.rgb, lightmapFilter.weight), current.a);
|
|
13499
|
+
}
|
|
13500
|
+
if (lightmapFilter.mode == 2 || current.a > 0.0) {return current;}
|
|
13501
|
+
let chart = textureLoad(chartTexture, coordinates, 0).r;
|
|
13502
|
+
if (chart <= 0.0) {return current;}
|
|
13503
|
+
let size = vec2i(textureDimensions(currentTexture));
|
|
13504
|
+
for (var y = -1; y <= 1; y++) {
|
|
13505
|
+
for (var x = -1; x <= 1; x++) {
|
|
13506
|
+
let neighbor = coordinates + vec2i(x, y);
|
|
13507
|
+
if (all(neighbor >= vec2i(0)) && all(neighbor < size)) {
|
|
13508
|
+
let candidate = textureLoad(currentTexture, neighbor, 0);
|
|
13509
|
+
if (candidate.a == chart) {return candidate;}
|
|
13510
|
+
}
|
|
13511
|
+
}
|
|
13512
|
+
}
|
|
13513
|
+
return current;
|
|
13514
|
+
}`,fs:`
|
|
13515
|
+
layout(std140) uniform lightmapFilterUniforms {
|
|
13516
|
+
float weight;
|
|
13517
|
+
int mode;
|
|
13518
|
+
} lightmapFilter;
|
|
13519
|
+
uniform sampler2D currentTexture;
|
|
13520
|
+
uniform sampler2D previousTexture;
|
|
13521
|
+
uniform sampler2D chartTexture;
|
|
13522
|
+
vec4 lightmapFilter_getColor(ivec2 coordinates) {
|
|
13523
|
+
vec4 current = texelFetch(currentTexture, coordinates, 0);
|
|
13524
|
+
if (lightmapFilter.mode == 0) {
|
|
13525
|
+
return vec4(mix(texelFetch(previousTexture, coordinates, 0).rgb, current.rgb, lightmapFilter.weight), current.a);
|
|
13526
|
+
}
|
|
13527
|
+
if (lightmapFilter.mode == 2 || current.a > 0.0) {return current;}
|
|
13528
|
+
float chart = texelFetch(chartTexture, coordinates, 0).r;
|
|
13529
|
+
ivec2 size = textureSize(currentTexture, 0);
|
|
13530
|
+
if (chart <= 0.0) return current;
|
|
13531
|
+
for (int y = -1; y <= 1; y++) {
|
|
13532
|
+
for (int x = -1; x <= 1; x++) {
|
|
13533
|
+
ivec2 neighbor = coordinates + ivec2(x,y);
|
|
13534
|
+
if (all(greaterThanEqual(neighbor, ivec2(0))) && all(lessThan(neighbor,size))) {
|
|
13535
|
+
vec4 candidate = texelFetch(currentTexture, neighbor, 0);
|
|
13536
|
+
if (candidate.a == chart) {return candidate;}
|
|
13537
|
+
}
|
|
13538
|
+
}
|
|
13539
|
+
}
|
|
13540
|
+
return current;
|
|
13541
|
+
}`};return wo(Dl);})();
|
|
12191
13542
|
return __exports__;
|
|
12192
13543
|
});
|