@luma.gl/shadertools 9.3.0-alpha.8 → 9.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +1020 -191
- package/dist/dist.min.js +440 -145
- package/dist/index.cjs +915 -173
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/color/normalize-byte-colors.d.ts +23 -0
- package/dist/lib/color/normalize-byte-colors.d.ts.map +1 -0
- package/dist/lib/color/normalize-byte-colors.js +42 -0
- package/dist/lib/color/normalize-byte-colors.js.map +1 -0
- package/dist/lib/glsl-utils/shader-utils.js +4 -4
- package/dist/lib/glsl-utils/shader-utils.js.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.js +102 -49
- package/dist/lib/shader-assembly/assemble-shaders.js.map +1 -1
- package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts.map +1 -1
- package/dist/lib/shader-assembly/wgsl-binding-debug.js +7 -3
- package/dist/lib/shader-assembly/wgsl-binding-debug.js.map +1 -1
- package/dist/lib/shader-assembly/wgsl-binding-scan.d.ts +19 -0
- package/dist/lib/shader-assembly/wgsl-binding-scan.d.ts.map +1 -0
- package/dist/lib/shader-assembly/wgsl-binding-scan.js +151 -0
- package/dist/lib/shader-assembly/wgsl-binding-scan.js.map +1 -0
- package/dist/lib/shader-generator/glsl/generate-glsl.js +4 -4
- package/dist/lib/shader-generator/glsl/generate-glsl.js.map +1 -1
- package/dist/lib/shader-module/shader-module-uniform-layout.d.ts +69 -0
- package/dist/lib/shader-module/shader-module-uniform-layout.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module-uniform-layout.js +145 -4
- package/dist/lib/shader-module/shader-module-uniform-layout.js.map +1 -1
- package/dist/modules/color/float-colors.d.ts +26 -0
- package/dist/modules/color/float-colors.d.ts.map +1 -0
- package/dist/modules/color/float-colors.js +82 -0
- package/dist/modules/color/float-colors.js.map +1 -0
- package/dist/modules/engine/picking/picking.d.ts +8 -8
- package/dist/modules/engine/picking/picking.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.js +13 -15
- package/dist/modules/engine/picking/picking.js.map +1 -1
- package/dist/modules/engine/project/project.d.ts +1 -1
- package/dist/modules/engine/project/project.js +1 -1
- package/dist/modules/engine/skin/skin.d.ts +2 -2
- package/dist/modules/engine/skin/skin.d.ts.map +1 -1
- package/dist/modules/engine/skin/skin.js +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +1 -0
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +6 -3
- package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts +2 -2
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js +2 -2
- package/dist/modules/lighting/lights/lighting-glsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-glsl.js +1 -1
- package/dist/modules/lighting/lights/lighting.d.ts +4 -2
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +17 -11
- package/dist/modules/lighting/lights/lighting.js.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.d.ts +3 -3
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +2 -2
- 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 +138 -35
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
- 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 +139 -35
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +74 -6
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +70 -2
- package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.js +1 -1
- package/dist/modules/lighting/pbr-material/pbr-scene.d.ts +40 -0
- package/dist/modules/lighting/pbr-material/pbr-scene.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-material/pbr-scene.js +67 -0
- package/dist/modules/lighting/pbr-material/pbr-scene.js.map +1 -0
- package/dist/modules/lighting/phong-material/phong-material.d.ts +1 -0
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +6 -3
- package/dist/modules/lighting/phong-material/phong-material.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +2 -2
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.js +1 -1
- package/package.json +2 -2
- package/src/index.ts +17 -1
- package/src/lib/color/normalize-byte-colors.ts +57 -0
- package/src/lib/glsl-utils/shader-utils.ts +4 -4
- package/src/lib/shader-assembly/assemble-shaders.ts +197 -69
- package/src/lib/shader-assembly/wgsl-binding-debug.ts +14 -3
- package/src/lib/shader-assembly/wgsl-binding-scan.ts +228 -0
- package/src/lib/shader-generator/glsl/generate-glsl.ts +4 -4
- package/src/lib/shader-module/shader-module-uniform-layout.ts +236 -10
- package/src/modules/color/float-colors.ts +99 -0
- package/src/modules/engine/picking/picking.ts +17 -19
- package/src/modules/engine/project/project.ts +1 -1
- package/src/modules/engine/skin/skin.ts +1 -1
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +10 -3
- package/src/modules/lighting/lambert-material/lambert-shaders-glsl.ts +2 -2
- package/src/modules/lighting/lights/lighting-glsl.ts +1 -1
- package/src/modules/lighting/lights/lighting.ts +20 -11
- package/src/modules/lighting/no-material/dirlight.ts +2 -2
- package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +138 -35
- package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +139 -35
- package/src/modules/lighting/pbr-material/pbr-material.ts +110 -3
- package/src/modules/lighting/pbr-material/pbr-projection.ts +1 -1
- package/src/modules/lighting/pbr-material/pbr-scene.ts +91 -0
- package/src/modules/lighting/phong-material/phong-material.ts +10 -3
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +2 -2
- package/src/modules/math/fp64/fp64-arithmetic-glsl.ts +1 -1
package/dist/dist.min.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
5
|
else if (typeof exports === 'object') exports['luma'] = factory();
|
|
6
6
|
else root['luma'] = factory();})(globalThis, function () {
|
|
7
|
-
"use strict";var __exports__=(()=>{var
|
|
7
|
+
"use strict";var __exports__=(()=>{var Kr=Object.create;var Q=Object.defineProperty;var Yr=Object.getOwnPropertyDescriptor;var Xr=Object.getOwnPropertyNames;var Zr=Object.getPrototypeOf,Qr=Object.prototype.hasOwnProperty;var Jr=(e,t,r)=>t in e?Q(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var en=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),tn=(e,t)=>{for(var r in t)Q(e,r,{get:t[r],enumerable:!0})},fe=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Xr(t))!Qr.call(e,o)&&o!==r&&Q(e,o,{get:()=>t[o],enumerable:!(n=Yr(t,o))||n.enumerable});return e},pe=(e,t,r)=>(fe(e,t,"default"),r&&fe(r,t,"default")),pt=(e,t,r)=>(r=e!=null?Kr(Zr(e)):{},fe(t||!e||!e.__esModule?Q(r,"default",{value:e,enumerable:!0}):r,e)),rn=e=>fe(Q({},"__esModule",{value:!0}),e);var ut=(e,t,r)=>(Jr(e,typeof t!="symbol"?t+"":t,r),r);var Be=en((jo,ht)=>{ht.exports=globalThis.luma});var ce={};tn(ce,{ShaderAssembler:()=>ie,_getDependencyGraph:()=>ne,_resolveModules:()=>At,assembleGLSLShaderPair:()=>xe,capitalize:()=>G,checkShaderModuleDeprecations:()=>te,combineInjects:()=>Mt,convertToVec4:()=>Xe,dirlight:()=>st,floatColors:()=>yr,fp32:()=>Ar,fp64:()=>Cr,fp64LowPart:()=>ae,fp64arithmetic:()=>it,fp64ify:()=>X,fp64ifyMatrix4:()=>se,fromHalfFloat:()=>xr,generateShaderForModule:()=>qt,getGLSLUniformBlocks:()=>ge,getPassthroughFS:()=>Gt,getQualifierDetails:()=>zt,getShaderInfo:()=>_e,getShaderModuleDependencies:()=>re,getShaderModuleSource:()=>Me,getShaderModuleUniformBlockFields:()=>De,getShaderModuleUniformBlockName:()=>he,getShaderModuleUniformLayoutValidationResult:()=>ze,getShaderModuleUniforms:()=>Lt,gouraudMaterial:()=>ct,ibl:()=>Oe,initializeShaderModule:()=>ue,initializeShaderModules:()=>F,lambertMaterial:()=>lt,lighting:()=>B,normalizeByteColor3:()=>k,normalizeByteColor4:()=>Ne,pbrMaterial:()=>$r,pbrScene:()=>qr,phongMaterial:()=>ft,picking:()=>Nr,preprocess:()=>Le,random:()=>Lr,resolveUseByteColors:()=>V,skin:()=>Pr,toHalfFloat:()=>Sr,typeToChannelCount:()=>$t,typeToChannelSuffix:()=>Ht,validateShaderModuleUniformLayout:()=>me,warnIfGLSLUniformBlocksAreNotStd140:()=>de});pe(ce,pt(Be(),1));function U(e,t){if(!e){let r=new Error(t||"shadertools: assertion failed.");throw Error.captureStackTrace?.(r,U),r}}var we={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 gt(e){let t={};for(let[r,n]of Object.entries(e))t[r]=nn(n);return t}function dt(e,t,r){let n={};for(let[o,i]of Object.entries(t))e&&o in e&&!i.private?(i.validate&&U(i.validate(e[o],i),`${r}: invalid ${o}`),n[o]=e[o]):n[o]=i.value;return n}function nn(e){let t=mt(e);if(t!=="object")return{value:e,...we[t],type:t};if(typeof e=="object")return e?e.type!==void 0?{...e,...we[e.type],type:e.type}:e.value===void 0?{type:"object",value:e}:(t=mt(e.value),{...e,...we[t],type:t}):{type:"object",value:null};throw new Error("props")}function mt(e){return Array.isArray(e)||ArrayBuffer.isView(e)?"array":typeof e}var _t=`#ifdef MODULE_LOGDEPTH
|
|
8
8
|
logdepth_adjustPosition(gl_Position);
|
|
9
9
|
#endif
|
|
10
|
-
`,
|
|
10
|
+
`,bt=`#ifdef MODULE_MATERIAL
|
|
11
11
|
fragColor = material_filterColor(fragColor);
|
|
12
12
|
#endif
|
|
13
13
|
|
|
@@ -27,13 +27,11 @@
|
|
|
27
27
|
#ifdef MODULE_LOGDEPTH
|
|
28
28
|
logdepth_setFragDepth();
|
|
29
29
|
#endif
|
|
30
|
-
`;var
|
|
30
|
+
`;var on={vertex:_t,fragment:bt},vt=/void\s+main\s*\([^)]*\)\s*\{\n?/,St=/}\n?[^{}]*$/,ke=[],J="__LUMA_INJECT_DECLARATIONS__";function xt(e){let t={vertex:{},fragment:{}};for(let r in e){let n=e[r],o=an(r);typeof n=="string"&&(n={order:0,injection:n}),t[o][r]=n}return t}function an(e){let t=e.slice(0,2);switch(t){case"vs":return"vertex";case"fs":return"fragment";default:throw new Error(t)}}function ee(e,t,r,n=!1){let o=t==="vertex";for(let i in r){let a=r[i];a.sort((l,c)=>l.order-c.order),ke.length=a.length;for(let l=0,c=a.length;l<c;++l)ke[l]=a[l].injection;let s=`${ke.join(`
|
|
31
31
|
`)}
|
|
32
|
-
`;switch(i){case"vs:#decl":o&&(e=e.replace(
|
|
33
|
-
${n
|
|
34
|
-
`)){let a=i.replace(/\/\/.*$/,"").trim();if(!a||a.startsWith("#"))continue;let s=t==="wgsl"?a.match(/^([A-Za-z0-9_]+)\s*:/):a.match(
|
|
35
|
-
Expected: ${e.expectedUniformNames.join(", ")}
|
|
36
|
-
Actual: ${e.actualUniformNames.join(", ")}`}function pt(e){switch(e?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
|
|
32
|
+
`;switch(i){case"vs:#decl":o&&(e=e.replace(J,s));break;case"vs:#main-start":o&&(e=e.replace(vt,l=>l+s));break;case"vs:#main-end":o&&(e=e.replace(St,l=>s+l));break;case"fs:#decl":o||(e=e.replace(J,s));break;case"fs:#main-start":o||(e=e.replace(vt,l=>l+s));break;case"fs:#main-end":o||(e=e.replace(St,l=>s+l));break;default:e=e.replace(i,l=>l+s)}}return e=e.replace(J,""),n&&(e=e.replace(/\}\s*$/,i=>i+on[t])),e}function Mt(e){let t={};return U(Array.isArray(e)&&e.length>1),e.forEach(r=>{for(let n in r)t[n]=t[n]?`${t[n]}
|
|
33
|
+
${r[n]}`:r[n]}),t}function F(e){e.map(t=>ue(t))}function ue(e){if(e.instance)return;F(e.dependencies||[]);let{propTypes:t={},deprecations:r=[],inject:n={}}=e,o={normalizedInjections:xt(n),parsedDeprecations:sn(r)};t&&(o.propValidators=gt(t)),e.instance=o;let i={};t&&(i=Object.entries(t).reduce((a,[s,l])=>{let c=l?.value;return c&&(a[s]=c),a},{})),e.defaultUniforms={...e.defaultUniforms,...i}}function Lt(e,t,r){ue(e);let n=r||{...e.defaultUniforms};return t&&e.getUniforms?e.getUniforms(t,n):dt(t,e.instance?.propValidators,e.name)}function te(e,t,r){e.deprecations?.forEach(n=>{n.regex?.test(t)&&(n.deprecated?r.deprecated(n.old,n.new)():r.removed(n.old,n.new)())})}function sn(e){return e.forEach(t=>{switch(t.type){case"function":t.regex=new RegExp(`\\b${t.old}\\(`);break;default:t.regex=new RegExp(`${t.type} ${t.old};`)}}),e}function re(e){F(e);let t={},r={};ne({modules:e,level:0,moduleMap:t,moduleDepth:r});let n=Object.keys(r).sort((o,i)=>r[i]-r[o]).map(o=>t[o]);return F(n),n}function ne(e){let{modules:t,level:r,moduleMap:n,moduleDepth:o}=e;if(r>=5)throw new Error("Possible loop in shader dependency graph");for(let i of t)n[i.name]=i,(o[i.name]===void 0||o[i.name]<r)&&(o[i.name]=r);for(let i of t)i.dependencies&&ne({modules:i.dependencies,level:r+1,moduleMap:n,moduleDepth:o})}function ln(e){F(e);let t={},r={};return ne({modules:e,level:0,moduleMap:t,moduleDepth:r}),e=Object.keys(r).sort((n,o)=>r[o]-r[n]).map(n=>t[n]),F(e),e}function At(e){return ln(e)}var cn=/^(?:uniform\s+)?(?:(?:lowp|mediump|highp)\s+)?[A-Za-z0-9_]+(?:<[^>]+>)?\s+([A-Za-z0-9_]+)(?:\s*\[[^\]]+\])?\s*;/,fn=/((?: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 he(e){return`${e.name}Uniforms`}function De(e,t){let r=t==="wgsl"?e.source:t==="vertex"?e.vs:e.fs;if(!r)return null;let n=he(e);return pn(r,t==="wgsl"?"wgsl":"glsl",n)}function ze(e,t){let r=Object.keys(e.uniformTypes||{});if(!r.length)return null;let n=De(e,t);return n?{moduleName:e.name,uniformBlockName:he(e),stage:t,expectedUniformNames:r,actualUniformNames:n,matches:mn(r,n)}:null}function me(e,t,r={}){let n=ze(e,t);if(!n||n.matches)return n;let o=gn(n);return r.log?.error?.(o,n)(),r.throwOnError!==!1&&U(!1,o),n}function ge(e){let t=[],r=dn(e);for(let n of r.matchAll(fn)){let o=n[1]?.trim()||null;t.push({blockName:n[2],body:n[3],instanceName:n[4]||null,layoutQualifier:o,hasLayoutQualifier:Boolean(o),isStd140:Boolean(o&&/\blayout\s*\([^)]*\bstd140\b[^)]*\)/.exec(o))})}return t}function de(e,t,r,n){let o=ge(e).filter(a=>!a.isStd140),i=new Set;for(let a of o){if(i.has(a.blockName))continue;i.add(a.blockName);let s=n?.label?`${n.label} `:"",l=a.hasLayoutQualifier?`declares ${_n(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.`;r?.warn?.(c,a)()}return o}function pn(e,t,r){let n=t==="wgsl"?un(e,r):hn(e,r);if(!n)return null;let o=[];for(let i of n.split(`
|
|
34
|
+
`)){let a=i.replace(/\/\/.*$/,"").trim();if(!a||a.startsWith("#"))continue;let s=t==="wgsl"?a.match(/^([A-Za-z0-9_]+)\s*:/):a.match(cn);s&&o.push(s[1])}return o}function un(e,t){let r=new RegExp(`\\bstruct\\s+${t}\\b`,"m").exec(e);if(!r)return null;let n=e.indexOf("{",r.index);if(n<0)return null;let o=0;for(let i=n;i<e.length;i++){let a=e[i];if(a==="{"){o++;continue}if(a==="}"&&(o--,o===0))return e.slice(n+1,i)}return null}function hn(e,t){return ge(e).find(n=>n.blockName===t)?.body||null}function mn(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}function gn(e){let{expectedUniformNames:t,actualUniformNames:r}=e,n=t.filter(s=>!r.includes(s)),o=r.filter(s=>!t.includes(s)),i=[`Expected ${t.length} fields, found ${r.length}.`],a=bn(t,r);return a&&i.push(a),n.length&&i.push(`Missing from shader block (${n.length}): ${Rt(n)}.`),o.length&&i.push(`Unexpected in shader block (${o.length}): ${Rt(o)}.`),t.length<=12&&r.length<=12&&(n.length||o.length)&&(i.push(`Expected: ${t.join(", ")}.`),i.push(`Actual: ${r.join(", ")}.`)),`${e.moduleName}: ${e.stage} shader uniform block ${e.uniformBlockName} does not match module.uniformTypes. ${i.join(" ")}`}function dn(e){return e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"")}function _n(e){return e.replace(/\s+/g," ").trim()}function bn(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;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 Rt(e,t=8){if(e.length<=t)return e.join(", ");let r=e.length-t;return`${e.slice(0,t).join(", ")}, ... (${r} more)`}function Et(e){switch(e?.gpu.toLowerCase()){case"apple":return`#define APPLE_GPU
|
|
37
35
|
// Apple optimizes away the calculation necessary for emulated fp64
|
|
38
36
|
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
39
37
|
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
@@ -57,58 +55,60 @@ Actual: ${e.actualUniformNames.join(", ")}`}function pt(e){switch(e?.gpu.toLower
|
|
|
57
55
|
#define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
|
|
58
56
|
// If the GPU doesn't have full 32 bits precision, will causes overflow
|
|
59
57
|
#define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
|
|
60
|
-
`}}function
|
|
61
|
-
`],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],
|
|
62
|
-
`,o.header&&(
|
|
63
|
-
`}o.footer&&(
|
|
64
|
-
`}return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
`}}function It(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=Ct(e,vn),e;case"fragment":return e=Ct(e,Sn),e;default:throw new Error(t)}}var yt=[[/^(#version[ \t]+(100|300[ \t]+es))?[ \t]*\n/,`#version 300 es
|
|
59
|
+
`],[/\btexture(2D|2DProj|Cube)Lod(EXT)?\(/g,"textureLod("],[/\btexture(2D|2DProj|Cube)(EXT)?\(/g,"texture("]],vn=[...yt,[Ge("attribute"),"in $1"],[Ge("varying"),"out $1"]],Sn=[...yt,[Ge("varying"),"in $1"]];function Ct(e,t){for(let[r,n]of t)e=e.replace(r,n);return e}function Ge(e){return new RegExp(`\\b${e}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`,"g")}function He(e,t){let r="";for(let n in e){let o=e[n];if(r+=`void ${o.signature} {
|
|
60
|
+
`,o.header&&(r+=` ${o.header}`),t[n]){let i=t[n];i.sort((a,s)=>a.order-s.order);for(let a of i)r+=` ${a.injection}
|
|
61
|
+
`}o.footer&&(r+=` ${o.footer}`),r+=`}
|
|
62
|
+
`}return r}function $e(e){let t={vertex:{},fragment:{}};for(let r of e){let n,o;typeof r!="string"?(n=r,o=n.hook):(n={},o=r),o=o.trim();let[i,a]=o.split(":"),s=o.replace(/\(.+/,""),l=Object.assign(n,{signature:a});switch(i){case"vs":t.vertex[s]=l;break;case"fs":t.fragment[s]=l;break;default:throw new Error(i)}}return t}function _e(e,t){return{name:xn(e,t),language:"glsl",version:Mn(e)}}function xn(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 Mn(e){let t=100,r=e.match(/[^\s]+/g);if(r&&r.length>=2&&r[0]==="#version"){let n=parseInt(r[1],10);Number.isFinite(n)&&(t=n)}if(t!==100&&t!==300)throw new Error(`Invalid GLSL version ${t}`);return t}var N="(?:var<\\s*(uniform|storage(?:\\s*,\\s*[A-Za-z_][A-Za-z0-9_]*)?)\\s*>|var)\\s+([A-Za-z_][A-Za-z0-9_]*)",T="\\s*",W=[new RegExp(`@binding\\(\\s*(auto|\\d+)\\s*\\)${T}@group\\(\\s*(\\d+)\\s*\\)${T}${N}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)${T}@binding\\(\\s*(auto|\\d+)\\s*\\)${T}${N}`,"g")],be=[new RegExp(`@binding\\(\\s*(auto|\\d+)\\s*\\)${T}@group\\(\\s*(\\d+)\\s*\\)${T}${N}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)${T}@binding\\(\\s*(auto|\\d+)\\s*\\)${T}${N}`,"g")],Nt=[new RegExp(`@binding\\(\\s*(\\d+)\\s*\\)${T}@group\\(\\s*(\\d+)\\s*\\)${T}${N}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)${T}@binding\\(\\s*(\\d+)\\s*\\)${T}${N}`,"g")],Ln=[new RegExp(`@binding\\(\\s*(auto)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${N}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto)\\s*\\)\\s*${N}`,"g"),new RegExp(`@binding\\(\\s*(auto)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)(?:[\\s\\n\\r]*@[A-Za-z_][^\\n\\r]*)*[\\s\\n\\r]*${N}`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(auto)\\s*\\)(?:[\\s\\n\\r]*@[A-Za-z_][^\\n\\r]*)*[\\s\\n\\r]*${N}`,"g")];function ve(e){let t=e.split(""),r=0,n=0,o=!1,i=!1,a=!1;for(;r<e.length;){let s=e[r],l=e[r+1];if(i){a?a=!1:s==="\\"?a=!0:s==='"'&&(i=!1),r++;continue}if(o){s===`
|
|
63
|
+
`||s==="\r"?o=!1:t[r]=" ",r++;continue}if(n>0){if(s==="/"&&l==="*"){t[r]=" ",t[r+1]=" ",n++,r+=2;continue}if(s==="*"&&l==="/"){t[r]=" ",t[r+1]=" ",n--,r+=2;continue}s!==`
|
|
64
|
+
`&&s!=="\r"&&(t[r]=" "),r++;continue}if(s==='"'){i=!0,r++;continue}if(s==="/"&&l==="/"){t[r]=" ",t[r+1]=" ",o=!0,r+=2;continue}if(s==="/"&&l==="*"){t[r]=" ",t[r+1]=" ",n=1,r+=2;continue}r++}return t.join("")}function z(e,t){let r=ve(e),n=[];for(let o of t){o.lastIndex=0;let i;for(i=o.exec(r);i;){let a=o===t[0],s=i.index,l=i[0].length;n.push({match:e.slice(s,s+l),index:s,length:l,bindingToken:i[a?1:2],groupToken:i[a?2:1],accessDeclaration:i[3]?.trim(),name:i[4]}),i=o.exec(r)}}return n.sort((o,i)=>o.index-i.index)}function We(e,t,r){let n=z(e,t);if(!n.length)return e;let o="",i=0;for(let a of n)o+=e.slice(i,a.index),o+=r(a),i=a.index+a.length;return o+=e.slice(i),o}function je(e){return/@binding\(\s*auto\s*\)/.test(ve(e))}function Pt(e,t){return z(e,t===W||t===be?Ln:t).find(n=>n.bindingToken==="auto")}var Tt=[new RegExp(`@binding\\(\\s*(\\d+)\\s*\\)\\s*@group\\(\\s*(\\d+)\\s*\\)\\s*${N}\\s*:\\s*([^;]+);`,"g"),new RegExp(`@group\\(\\s*(\\d+)\\s*\\)\\s*@binding\\(\\s*(\\d+)\\s*\\)\\s*${N}\\s*:\\s*([^;]+);`,"g")];function Se(e,t=[]){let r=ve(e),n=new Map;for(let i of t)n.set(Ot(i.name,i.group,i.location),i.moduleName);let o=[];for(let i of Tt){i.lastIndex=0;let a;for(a=i.exec(r);a;){let s=i===Tt[0],l=Number(a[s?1:2]),c=Number(a[s?2:1]),f=a[3]?.trim(),p=a[4],u=a[5].trim(),h=n.get(Ot(p,c,l));o.push(An({name:p,group:c,binding:l,owner:h?"module":"application",moduleName:h,accessDeclaration:f,resourceType:u})),a=i.exec(r)}}return o.sort((i,a)=>i.group!==a.group?i.group-a.group:i.binding!==a.binding?i.binding-a.binding:i.name.localeCompare(a.name))}function An(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 r=e.accessDeclaration.split(",").map(n=>n.trim());if(r[0]==="uniform")return{...t,kind:"uniform",access:"uniform"};if(r[0]==="storage"){let n=r[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:En(e.resourceType),viewDimension:Ut(e.resourceType)}:e.resourceType.startsWith("texture_")?{...t,kind:"texture",viewDimension:Ut(e.resourceType),sampleType:Rn(e.resourceType),multisampled:e.resourceType.startsWith("texture_multisampled_")}:t}function Ot(e,t,r){return`${t}:${r}:${e}`}function Ut(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 Rn(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 En(e){return/,\s*([A-Za-z_][A-Za-z0-9_]*)\s*>$/.exec(e)?.[1]}var qe=`
|
|
65
|
+
|
|
66
|
+
${J}
|
|
67
|
+
`,oe=100,Cn=`precision highp float;
|
|
68
|
+
`;function wt(e){let t=re(e.modules||[]),{source:r,bindingAssignments:n}=In(e.platformInfo,{...e,source:e.source,stage:"vertex",modules:t});return{source:r,getUniforms:kt(t),bindingAssignments:n,bindingTable:Se(r,n)}}function xe(e){let{vs:t,fs:r}=e,n=re(e.modules||[]);return{vs:Ft(e.platformInfo,{...e,source:t,stage:"vertex",modules:n}),fs:Ft(e.platformInfo,{...e,source:r,stage:"fragment",modules:n}),getUniforms:kt(n)}}function In(e,t){let{source:r,stage:n,modules:o,hookFunctions:i=[],inject:a={},log:s}=t;U(typeof r=="string","shader source must be a string");let l=r,c="",f=$e(i),p={},u={},h={};for(let d in a){let b=typeof a[d]=="string"?{injection:a[d],order:0}:a[d],v=/^(v|f)s:(#)?([\w-]+)$/.exec(d);if(v){let m=v[2],M=v[3];m?M==="decl"?u[d]=[b]:h[d]=[b]:p[d]=[b]}else h[d]=[b]}let g=o,S=Pn(l),x=Nn(S.source),_=Fn(g,t._bindingRegistry,x),L=[];for(let d of g){s&&te(d,l,s);let b=Tn(Me(d,"wgsl",s),d,{usedBindingsByGroup:x,bindingRegistry:t._bindingRegistry,reservedBindingKeysByGroup:_});L.push(...b.bindingAssignments);let v=b.source;c+=v;let m=d.injections?.[n]||{};for(let M in m){let E=/^(v|f)s:#([\w-]+)$/.exec(M);if(E){let C=E[2]==="decl"?u:h;C[M]=C[M]||[],C[M].push(m[M])}else p[M]=p[M]||[],p[M].push(m[M])}}return c+=qe,c=ee(c,n,u),c+=He(f[n],p),c+=Dn(L),c+=S.source,c=ee(c,n,h),kn(c),{source:c,bindingAssignments:L}}function Ft(e,t){let{source:r,stage:n,language:o="glsl",modules:i,defines:a={},hookFunctions:s=[],inject:l={},prologue:c=!0,log:f}=t;U(typeof r=="string","shader source must be a string");let p=o==="glsl"?_e(r).version:-1,u=e.shaderLanguageVersion,h=p===100?"#version 100":"#version 300 es",S=r.split(`
|
|
69
69
|
`).slice(1).join(`
|
|
70
|
-
`),x={};i.forEach(
|
|
70
|
+
`),x={};i.forEach(m=>{Object.assign(x,m.defines)}),Object.assign(x,a);let _="";switch(o){case"wgsl":break;case"glsl":_=c?`${h}
|
|
71
71
|
|
|
72
72
|
// ----- PROLOGUE -------------------------
|
|
73
|
-
${`#define SHADER_TYPE_${
|
|
73
|
+
${`#define SHADER_TYPE_${n.toUpperCase()}`}
|
|
74
74
|
|
|
75
|
-
${
|
|
76
|
-
${
|
|
75
|
+
${Et(e)}
|
|
76
|
+
${n==="fragment"?Cn:""}
|
|
77
77
|
|
|
78
78
|
// ----- APPLICATION DEFINES -------------------------
|
|
79
79
|
|
|
80
|
-
${
|
|
80
|
+
${yn(x)}
|
|
81
81
|
|
|
82
|
-
`:`${
|
|
83
|
-
`;break}let
|
|
84
|
-
`)}return t}function
|
|
82
|
+
`:`${h}
|
|
83
|
+
`;break}let L=$e(s),d={},b={},v={};for(let m in l){let M=typeof l[m]=="string"?{injection:l[m],order:0}:l[m],E=/^(v|f)s:(#)?([\w-]+)$/.exec(m);if(E){let A=E[2],C=E[3];A?C==="decl"?b[m]=[M]:v[m]=[M]:d[m]=[M]}else v[m]=[M]}for(let m of i){f&&te(m,S,f);let M=Me(m,n,f);_+=M;let E=m.instance?.normalizedInjections[n]||{};for(let A in E){let C=/^(v|f)s:#([\w-]+)$/.exec(A);if(C){let I=C[2]==="decl"?b:v;I[A]=I[A]||[],I[A].push(E[A])}else d[A]=d[A]||[],d[A].push(E[A])}}return _+="// ----- MAIN SHADER SOURCE -------------------------",_+=qe,_=ee(_,n,b),_+=He(L[n],d),_+=S,_=ee(_,n,v),o==="glsl"&&p!==u&&(_=It(_,n)),o==="glsl"&&de(_,n,f),_.trim()}function kt(e){return function(r){let n={};for(let o of e){let i=o.getUniforms?.(r,n);Object.assign(n,i)}return n}}function yn(e={}){let t="";for(let r in e){let n=e[r];(n||Number.isFinite(n))&&(t+=`#define ${r.toUpperCase()} ${e[r]}
|
|
84
|
+
`)}return t}function Me(e,t,r){let n;switch(t){case"vertex":n=e.vs||"";break;case"fragment":n=e.fs||"";break;case"wgsl":n=e.source||"";break;default:U(!1)}if(!e.name)throw new Error("Shader module must have a name");me(e,t,{log:r});let o=e.name.toUpperCase().replace(/[^0-9a-z]/gi,"_"),i=`// ----- MODULE ${e.name} ---------------
|
|
85
85
|
|
|
86
86
|
`;return t!=="wgsl"&&(i+=`#define MODULE_${o}
|
|
87
|
-
`),i+=`${
|
|
88
|
-
`,i}function
|
|
89
|
-
`;for(let
|
|
87
|
+
`),i+=`${n}
|
|
88
|
+
`,i}function Nn(e){let t=new Map;for(let r of z(e,Nt)){let n=Number(r.bindingToken),o=Number(r.groupToken);Ke(o,n,r.name),j(t,o,n,`application binding "${r.name}"`)}return t}function Pn(e){let t=z(e,be),r=new Map;for(let i of t){if(i.bindingToken==="auto")continue;let a=Number(i.bindingToken),s=Number(i.groupToken);Ke(s,a,i.name),j(r,s,a,`application binding "${i.name}"`)}let n={sawSupportedBindingDeclaration:t.length>0},o=We(e,be,i=>Un(i,r,n));if(je(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:o}}function Tn(e,t,r){let n=[],i={sawSupportedBindingDeclaration:z(e,W).length>0,nextHintedBindingLocation:typeof t.firstBindingSlot=="number"?t.firstBindingSlot:null},a=We(e,W,s=>On(s,{module:t,context:r,bindingAssignments:n,relocationState:i}));if(je(e)&&!i.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 On(e,t){let{module:r,context:n,bindingAssignments:o,relocationState:i}=t,{match:a,bindingToken:s,groupToken:l,name:c}=e,f=Number(l);if(s==="auto"){let u=Dt(f,r.name,c),h=n.bindingRegistry?.get(u),g=h!==void 0?h:i.nextHintedBindingLocation===null?Bt(f,n.usedBindingsByGroup):Bt(f,n.usedBindingsByGroup,i.nextHintedBindingLocation);return Vt(r.name,f,g,c),h!==void 0&&Vn(n.reservedBindingKeysByGroup,f,g,u)?(o.push({moduleName:r.name,name:c,group:f,location:g}),a.replace(/@binding\(\s*auto\s*\)/,`@binding(${g})`)):(j(n.usedBindingsByGroup,f,g,`module "${r.name}" binding "${c}"`),n.bindingRegistry?.set(u,g),o.push({moduleName:r.name,name:c,group:f,location:g}),i.nextHintedBindingLocation!==null&&h===void 0&&(i.nextHintedBindingLocation=g+1),a.replace(/@binding\(\s*auto\s*\)/,`@binding(${g})`))}let p=Number(s);return Vt(r.name,f,p,c),j(n.usedBindingsByGroup,f,p,`module "${r.name}" binding "${c}"`),o.push({moduleName:r.name,name:c,group:f,location:p}),a}function Un(e,t,r){let{match:n,bindingToken:o,groupToken:i,name:a}=e,s=Number(i);if(o==="auto"){let l=wn(s,t);return Ke(s,l,a),j(t,s,l,`application binding "${a}"`),n.replace(/@binding\(\s*auto\s*\)/,`@binding(${l})`)}return r.sawSupportedBindingDeclaration=!0,n}function Fn(e,t,r){let n=new Map;if(!t)return n;for(let o of e)for(let i of Bn(o)){let a=Dt(i.group,o.name,i.name),s=t.get(a);if(s!==void 0){let l=n.get(i.group)||new Map,c=l.get(s);if(c&&c!==a)throw new Error(`Duplicate WGSL binding reservation for modules "${c}" and "${a}": group ${i.group}, binding ${s}.`);j(r,i.group,s,`registered module binding "${a}"`),l.set(s,a),n.set(i.group,l)}}return n}function Vn(e,t,r,n){let o=e.get(t);if(!o)return!1;let i=o.get(r);if(!i)return!1;if(i!==n)throw new Error(`Registered module binding "${n}" collided with "${i}": group ${t}, binding ${r}.`);return!0}function Bn(e){let t=[],r=e.source||"";for(let n of z(r,W))t.push({name:n.name,group:Number(n.groupToken)});return t}function Ke(e,t,r){if(e===0&&t>=oe)throw new Error(`Application binding "${r}" in group 0 uses reserved binding ${t}. Application-owned explicit group-0 bindings must stay below ${oe}.`)}function Vt(e,t,r,n){if(t===0&&r<oe)throw new Error(`Module "${e}" binding "${n}" in group 0 uses reserved application binding ${r}. Module-owned explicit group-0 bindings must be ${oe} or higher.`)}function j(e,t,r,n){let o=e.get(t)||new Set;if(o.has(r))throw new Error(`Duplicate WGSL binding assignment for ${n}: group ${t}, binding ${r}.`);o.add(r),e.set(t,o)}function Bt(e,t,r){let n=t.get(e)||new Set,o=r??(e===0?oe:n.size>0?Math.max(...n)+1:0);for(;n.has(o);)o++;return o}function wn(e,t){let r=t.get(e)||new Set,n=0;for(;r.has(n);)n++;return n}function kn(e){let t=Pt(e,W);if(!t)return;let r=zn(e,t.index);throw r?new Error(`Unresolved @binding(auto) for module "${r}" binding "${t.name}" remained in assembled WGSL source.`):Gn(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 "${Hn(t.match)}".`)}function Dn(e){if(e.length===0)return"";let t=`// ----- MODULE WGSL BINDING ASSIGNMENTS ---------------
|
|
89
|
+
`;for(let r of e)t+=`// ${r.moduleName}.${r.name} -> @group(${r.group}) @binding(${r.location})
|
|
90
90
|
`;return t+=`
|
|
91
|
-
`,t}function
|
|
92
|
-
`),
|
|
93
|
-
`)}var
|
|
91
|
+
`,t}function Dt(e,t,r){return`${e}:${t}:${r}`}function zn(e,t){let r=/^\/\/ ----- MODULE ([^\n]+) ---------------$/gm,n,o;for(o=r.exec(e);o&&o.index<=t;)n=o[1],o=r.exec(e);return n}function Gn(e,t){let r=e.indexOf(qe);return r>=0?t>r:!0}function Hn(e){return e.replace(/\s+/g," ").trim()}var Ye="([a-zA-Z_][a-zA-Z0-9_]*)",$n=new RegExp(`^\\s*\\#\\s*ifdef\\s*${Ye}\\s*$`),Wn=new RegExp(`^\\s*\\#\\s*ifndef\\s*${Ye}\\s*(?:\\/\\/.*)?$`),jn=/^\s*\#\s*else\s*(?:\/\/.*)?$/,qn=/^\s*\#\s*endif\s*$/,Kn=new RegExp(`^\\s*\\#\\s*ifdef\\s*${Ye}\\s*(?:\\/\\/.*)?$`),Yn=/^\s*\#\s*endif\s*(?:\/\/.*)?$/;function Le(e,t){let r=e.split(`
|
|
92
|
+
`),n=[],o=[],i=!0;for(let a of r){let s=a.match(Kn)||a.match($n),l=a.match(Wn),c=a.match(jn),f=a.match(Yn)||a.match(qn);if(s||l){let p=(s||l)?.[1],u=Boolean(t?.defines?.[p]),h=s?u:!u,g=i&&h;o.push({parentActive:i,branchTaken:h,active:g}),i=g}else if(c){let p=o[o.length-1];if(!p)throw new Error("Encountered #else without matching #ifdef or #ifndef");p.active=p.parentActive&&!p.branchTaken,p.branchTaken=!0,i=p.active}else f?(o.pop(),i=o.length?o[o.length-1].active:!0):i&&n.push(a)}if(o.length>0)throw new Error("Unterminated conditional block in shader source");return n.join(`
|
|
93
|
+
`)}var q=class{_hookFunctions=[];_defaultModules=[];_wgslBindingRegistry=new Map;static getDefaultShaderAssembler(){return q.defaultShaderAssembler=q.defaultShaderAssembler||new q,q.defaultShaderAssembler}addDefaultModule(t){this._defaultModules.find(r=>r.name===(typeof t=="string"?t:t.name))||this._defaultModules.push(t)}removeDefaultModule(t){let r=typeof t=="string"?t:t.name;this._defaultModules=this._defaultModules.filter(n=>n.name!==r)}addShaderHook(t,r){r&&(t=Object.assign(r,{hook:t})),this._hookFunctions.push(t)}assembleWGSLShader(t){let r=this._getModuleList(t.modules),n=this._hookFunctions,{source:o,getUniforms:i,bindingAssignments:a}=wt({...t,source:t.source,_bindingRegistry:this._wgslBindingRegistry,modules:r,hookFunctions:n}),s={...r.reduce((c,f)=>(Object.assign(c,f.defines),c),{}),...t.defines},l=t.platformInfo.shaderLanguage==="wgsl"?Le(o,{defines:s}):o;return{source:l,getUniforms:i,modules:r,bindingAssignments:a,bindingTable:Se(l,a)}}assembleGLSLShaderPair(t){let r=this._getModuleList(t.modules),n=this._hookFunctions;return{...xe({...t,vs:t.vs,fs:t.fs,modules:r,hookFunctions:n}),modules:r}}_getModuleList(t=[]){let r=new Array(this._defaultModules.length+t.length),n={},o=0;for(let i=0,a=this._defaultModules.length;i<a;++i){let s=this._defaultModules[i],l=s.name;r[o++]=s,n[l]=!0}for(let i=0,a=t.length;i<a;++i){let s=t[i],l=s.name;n[l]||(r[o++]=s,n[l]=!0)}return r.length=o,F(r),r}},ie=q;ut(ie,"defaultShaderAssembler");var Xn=`out vec4 transform_output;
|
|
94
94
|
void main() {
|
|
95
95
|
transform_output = vec4(0);
|
|
96
|
-
}`,
|
|
97
|
-
${
|
|
96
|
+
}`,Zn=`#version 300 es
|
|
97
|
+
${Xn}`;function zt(e,t){t=Array.isArray(t)?t:[t];let r=e.replace(/^\s+/,"").split(/\s+/),[n,o,i]=r;if(!t.includes(n)||!o||!i)return null;let a=i.split(";")[0];return{qualifier:n,type:o,name:a}}function Gt(e){let{input:t,inputChannels:r,output:n}=e||{};if(!t)return Zn;if(!r)throw new Error("inputChannels");let o=Qn(r),i=Xe(t,r);return`#version 300 es
|
|
98
98
|
in ${o} ${t};
|
|
99
|
-
out vec4 ${
|
|
99
|
+
out vec4 ${n};
|
|
100
100
|
void main() {
|
|
101
|
-
${
|
|
102
|
-
}`}function
|
|
103
|
-
`)}function
|
|
104
|
-
`)}function Tt(e,t){switch(t.shaderLanguage){case"glsl":return yt(e,t);case"wgsl":return Ot(e,t)}}var ci=1/Math.PI*180,li=1/180*Math.PI,Rr={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Rr}};var P=globalThis.mathgl.config;function ke(e,{precision:t=P.precision}={}){return e=Ir(e),`${parseFloat(e.toPrecision(t))}`}function H(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function De(e,t,n){return Pr(e,r=>Math.max(t,Math.min(n,r)))}function me(e,t,n){let r=P.EPSILON;n&&(P.EPSILON=n);try{if(e===t)return!0;if(H(e)&&H(t)){if(e.length!==t.length)return!1;for(let o=0;o<e.length;++o)if(!me(e[o],t[o]))return!1;return!0}return e&&e.equals?e.equals(t):t&&t.equals?t.equals(e):typeof e=="number"&&typeof t=="number"?Math.abs(e-t)<=P.EPSILON*Math.max(1,Math.abs(e),Math.abs(t)):!1}finally{P.EPSILON=r}}function Ir(e){return Math.round(e/P.EPSILON)*P.EPSILON}function Cr(e){return e.clone?e.clone():new Array(e.length)}function Pr(e,t,n){if(H(e)){let r=e;n=n||Cr(r);for(let o=0;o<n.length&&o<r.length;++o){let i=typeof e=="number"?e:e[o];n[o]=t(i,o,n)}return n}return t(e)}var de=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,n=0){for(let r=0;r<this.ELEMENTS;++r)this[r]=t[r+n];return this.check()}toArray(t=[],n=0){for(let r=0;r<this.ELEMENTS;++r)t[n+r]=this[r];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:H(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(P)}formatString(t){let n="";for(let r=0;r<this.ELEMENTS;++r)n+=(r>0?", ":"")+ke(this[r],t);return`${t.printTypes?this.constructor.name:""}[${n}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(!me(this[n],t[n]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let n=0;n<this.ELEMENTS;++n)if(this[n]!==t[n])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,n,r){if(r===void 0)return this.lerp(this,t,n);for(let o=0;o<this.ELEMENTS;++o){let i=t[o],a=typeof n=="number"?n:n[o];this[o]=i+r*(a-i)}return this.check()}min(t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(t[n],this[n]);return this.check()}max(t){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.max(t[n],this[n]);return this.check()}clamp(t,n){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],t[r]),n[r]);return this.check()}add(...t){for(let n of t)for(let r=0;r<this.ELEMENTS;++r)this[r]+=n[r];return this.check()}subtract(...t){for(let n of t)for(let r=0;r<this.ELEMENTS;++r)this[r]-=n[r];return this.check()}scale(t){if(typeof t=="number")for(let n=0;n<this.ELEMENTS;++n)this[n]*=t;else for(let n=0;n<this.ELEMENTS&&n<t.length;++n)this[n]*=t[n];return this.check()}multiplyByScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]*=t;return this.check()}check(){if(P.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let n=0;n<this.ELEMENTS;++n)t=t&&Number.isFinite(this[n]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]=t;return this.check()}addScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let n=0;n<this.ELEMENTS;++n)this[n]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,n){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(Math.max(this[r],t),n);return this.check()}get elements(){return this}};function Nr(e,t){if(e.length!==t)return!1;for(let n=0;n<e.length;++n)if(!Number.isFinite(e[n]))return!1;return!0}function Ft(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function _e(e,t,n=""){if(P.debug&&!Nr(e,t))throw new Error(`math.gl: ${n} some fields set to invalid numbers'`);return e}var w=typeof Float32Array<"u"?Float32Array:Array;var mi=Math.PI/180;function yr(){let e=new w(2);return w!=Float32Array&&(e[0]=0,e[1]=0),e}function kt(e,t,n){let r=t[0],o=t[1];return e[0]=n[0]*r+n[4]*o+n[12],e[1]=n[1]*r+n[5]*o+n[13],e}var di=function(){let e=yr();return function(t,n,r,o,i,a){let s,c;for(n||(n=2),r||(r=0),o?c=Math.min(o*n+r,t.length):c=t.length,s=r;s<c;s+=n)e[0]=t[s],e[1]=t[s+1],i(e,e,a),t[s]=e[0],t[s+1]=e[1];return t}}();function Dt(e,t,n){let r=t[0],o=t[1],i=n[3]*r+n[7]*o||1;return e[0]=(n[0]*r+n[4]*o)/i,e[1]=(n[1]*r+n[5]*o)/i,e}function Ut(e,t,n){let r=t[0],o=t[1],i=t[2],a=n[3]*r+n[7]*o+n[11]*i||1;return e[0]=(n[0]*r+n[4]*o+n[8]*i)/a,e[1]=(n[1]*r+n[5]*o+n[9]*i)/a,e[2]=(n[2]*r+n[6]*o+n[10]*i)/a,e}function Or(){let e=new w(3);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function zt(e,t,n){let r=t[0],o=t[1],i=t[2],a=n[3]*r+n[7]*o+n[11]*i+n[15];return a=a||1,e[0]=(n[0]*r+n[4]*o+n[8]*i+n[12])/a,e[1]=(n[1]*r+n[5]*o+n[9]*i+n[13])/a,e[2]=(n[2]*r+n[6]*o+n[10]*i+n[14])/a,e}var vi=function(){let e=Or();return function(t,n,r,o,i,a){let s,c;for(n||(n=3),r||(r=0),o?c=Math.min(o*n+r,t.length):c=t.length,s=r;s<c;s+=n)e[0]=t[s],e[1]=t[s+1],e[2]=t[s+2],i(e,e,a),t[s]=e[0],t[s+1]=e[1],t[s+2]=e[2];return t}}();var be=class extends de{toString(){let t="[";if(P.printRowMajor){t+="row-major:";for(let n=0;n<this.RANK;++n)for(let r=0;r<this.RANK;++r)t+=` ${this[r*this.RANK+n]}`}else{t+="column-major:";for(let n=0;n<this.ELEMENTS;++n)t+=` ${this[n]}`}return t+="]",t}getElementIndex(t,n){return n*this.RANK+t}getElement(t,n){return this[n*this.RANK+t]}setElement(t,n,r){return this[n*this.RANK+t]=Ft(r),this}getColumn(t,n=new Array(this.RANK).fill(-0)){let r=t*this.RANK;for(let o=0;o<this.RANK;++o)n[o]=this[r+o];return n}setColumn(t,n){let r=t*this.RANK;for(let o=0;o<this.RANK;++o)this[r+o]=n[o];return this}};function Tr(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 Ht(e,t){if(e===t){let n=t[1],r=t[2],o=t[3],i=t[6],a=t[7],s=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=n,e[6]=t[9],e[7]=t[13],e[8]=r,e[9]=i,e[11]=t[14],e[12]=o,e[13]=a,e[14]=s}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e}function Gt(e,t){let n=t[0],r=t[1],o=t[2],i=t[3],a=t[4],s=t[5],c=t[6],l=t[7],p=t[8],f=t[9],h=t[10],g=t[11],_=t[12],m=t[13],x=t[14],d=t[15],M=n*s-r*a,b=n*c-o*a,S=n*l-i*a,v=r*c-o*s,u=r*l-i*s,E=o*l-i*c,R=p*m-f*_,L=p*x-h*_,I=p*d-g*_,N=f*x-h*m,C=f*d-g*m,y=h*d-g*x,A=M*y-b*C+S*N+v*I-u*L+E*R;return A?(A=1/A,e[0]=(s*y-c*C+l*N)*A,e[1]=(o*C-r*y-i*N)*A,e[2]=(m*E-x*u+d*v)*A,e[3]=(h*u-f*E-g*v)*A,e[4]=(c*I-a*y-l*L)*A,e[5]=(n*y-o*I+i*L)*A,e[6]=(x*S-_*E-d*b)*A,e[7]=(p*E-h*S+g*b)*A,e[8]=(a*C-s*I+l*R)*A,e[9]=(r*I-n*C-i*R)*A,e[10]=(_*u-m*S+d*M)*A,e[11]=(f*S-p*u-g*M)*A,e[12]=(s*L-a*N-c*R)*A,e[13]=(n*N-r*L+o*R)*A,e[14]=(m*b-_*v-x*M)*A,e[15]=(p*v-f*b+h*M)*A,e):null}function Vt(e){let t=e[0],n=e[1],r=e[2],o=e[3],i=e[4],a=e[5],s=e[6],c=e[7],l=e[8],p=e[9],f=e[10],h=e[11],g=e[12],_=e[13],m=e[14],x=e[15],d=t*a-n*i,M=t*s-r*i,b=n*s-r*a,S=l*_-p*g,v=l*m-f*g,u=p*m-f*_,E=t*u-n*v+r*S,R=i*u-a*v+s*S,L=l*b-p*M+f*d,I=g*b-_*M+m*d;return c*E-o*R+x*L-h*I}function ze(e,t,n){let r=t[0],o=t[1],i=t[2],a=t[3],s=t[4],c=t[5],l=t[6],p=t[7],f=t[8],h=t[9],g=t[10],_=t[11],m=t[12],x=t[13],d=t[14],M=t[15],b=n[0],S=n[1],v=n[2],u=n[3];return e[0]=b*r+S*s+v*f+u*m,e[1]=b*o+S*c+v*h+u*x,e[2]=b*i+S*l+v*g+u*d,e[3]=b*a+S*p+v*_+u*M,b=n[4],S=n[5],v=n[6],u=n[7],e[4]=b*r+S*s+v*f+u*m,e[5]=b*o+S*c+v*h+u*x,e[6]=b*i+S*l+v*g+u*d,e[7]=b*a+S*p+v*_+u*M,b=n[8],S=n[9],v=n[10],u=n[11],e[8]=b*r+S*s+v*f+u*m,e[9]=b*o+S*c+v*h+u*x,e[10]=b*i+S*l+v*g+u*d,e[11]=b*a+S*p+v*_+u*M,b=n[12],S=n[13],v=n[14],u=n[15],e[12]=b*r+S*s+v*f+u*m,e[13]=b*o+S*c+v*h+u*x,e[14]=b*i+S*l+v*g+u*d,e[15]=b*a+S*p+v*_+u*M,e}function Wt(e,t,n){let r=n[0],o=n[1],i=n[2],a,s,c,l,p,f,h,g,_,m,x,d;return t===e?(e[12]=t[0]*r+t[4]*o+t[8]*i+t[12],e[13]=t[1]*r+t[5]*o+t[9]*i+t[13],e[14]=t[2]*r+t[6]*o+t[10]*i+t[14],e[15]=t[3]*r+t[7]*o+t[11]*i+t[15]):(a=t[0],s=t[1],c=t[2],l=t[3],p=t[4],f=t[5],h=t[6],g=t[7],_=t[8],m=t[9],x=t[10],d=t[11],e[0]=a,e[1]=s,e[2]=c,e[3]=l,e[4]=p,e[5]=f,e[6]=h,e[7]=g,e[8]=_,e[9]=m,e[10]=x,e[11]=d,e[12]=a*r+p*o+_*i+t[12],e[13]=s*r+f*o+m*i+t[13],e[14]=c*r+h*o+x*i+t[14],e[15]=l*r+g*o+d*i+t[15]),e}function jt(e,t,n){let r=n[0],o=n[1],i=n[2];return e[0]=t[0]*r,e[1]=t[1]*r,e[2]=t[2]*r,e[3]=t[3]*r,e[4]=t[4]*o,e[5]=t[5]*o,e[6]=t[6]*o,e[7]=t[7]*o,e[8]=t[8]*i,e[9]=t[9]*i,e[10]=t[10]*i,e[11]=t[11]*i,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function $t(e,t,n,r){let o=r[0],i=r[1],a=r[2],s=Math.sqrt(o*o+i*i+a*a),c,l,p,f,h,g,_,m,x,d,M,b,S,v,u,E,R,L,I,N,C,y,A,W;return s<1e-6?null:(s=1/s,o*=s,i*=s,a*=s,l=Math.sin(n),c=Math.cos(n),p=1-c,f=t[0],h=t[1],g=t[2],_=t[3],m=t[4],x=t[5],d=t[6],M=t[7],b=t[8],S=t[9],v=t[10],u=t[11],E=o*o*p+c,R=i*o*p+a*l,L=a*o*p-i*l,I=o*i*p-a*l,N=i*i*p+c,C=a*i*p+o*l,y=o*a*p+i*l,A=i*a*p-o*l,W=a*a*p+c,e[0]=f*E+m*R+b*L,e[1]=h*E+x*R+S*L,e[2]=g*E+d*R+v*L,e[3]=_*E+M*R+u*L,e[4]=f*I+m*N+b*C,e[5]=h*I+x*N+S*C,e[6]=g*I+d*N+v*C,e[7]=_*I+M*N+u*C,e[8]=f*y+m*A+b*W,e[9]=h*y+x*A+S*W,e[10]=g*y+d*A+v*W,e[11]=_*y+M*A+u*W,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function qt(e,t,n){let r=Math.sin(n),o=Math.cos(n),i=t[4],a=t[5],s=t[6],c=t[7],l=t[8],p=t[9],f=t[10],h=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=i*o+l*r,e[5]=a*o+p*r,e[6]=s*o+f*r,e[7]=c*o+h*r,e[8]=l*o-i*r,e[9]=p*o-a*r,e[10]=f*o-s*r,e[11]=h*o-c*r,e}function Kt(e,t,n){let r=Math.sin(n),o=Math.cos(n),i=t[0],a=t[1],s=t[2],c=t[3],l=t[8],p=t[9],f=t[10],h=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*o-l*r,e[1]=a*o-p*r,e[2]=s*o-f*r,e[3]=c*o-h*r,e[8]=i*r+l*o,e[9]=a*r+p*o,e[10]=s*r+f*o,e[11]=c*r+h*o,e}function Yt(e,t,n){let r=Math.sin(n),o=Math.cos(n),i=t[0],a=t[1],s=t[2],c=t[3],l=t[4],p=t[5],f=t[6],h=t[7];return t!==e&&(e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*o+l*r,e[1]=a*o+p*r,e[2]=s*o+f*r,e[3]=c*o+h*r,e[4]=l*o-i*r,e[5]=p*o-a*r,e[6]=f*o-s*r,e[7]=h*o-c*r,e}function Xt(e,t){let n=t[0],r=t[1],o=t[2],i=t[3],a=n+n,s=r+r,c=o+o,l=n*a,p=r*a,f=r*s,h=o*a,g=o*s,_=o*c,m=i*a,x=i*s,d=i*c;return e[0]=1-f-_,e[1]=p+d,e[2]=h-x,e[3]=0,e[4]=p-d,e[5]=1-l-_,e[6]=g+m,e[7]=0,e[8]=h+x,e[9]=g-m,e[10]=1-l-f,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function Zt(e,t,n,r,o,i,a){let s=1/(n-t),c=1/(o-r),l=1/(i-a);return e[0]=i*2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i*2*c,e[6]=0,e[7]=0,e[8]=(n+t)*s,e[9]=(o+r)*c,e[10]=(a+i)*l,e[11]=-1,e[12]=0,e[13]=0,e[14]=a*i*2*l,e[15]=0,e}function Fr(e,t,n,r,o){let i=1/Math.tan(t/2);if(e[0]=i/n,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,o!=null&&o!==1/0){let a=1/(r-o);e[10]=(o+r)*a,e[14]=2*o*r*a}else e[10]=-1,e[14]=-2*r;return e}var Jt=Fr;function wr(e,t,n,r,o,i,a){let s=1/(t-n),c=1/(r-o),l=1/(i-a);return e[0]=-2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*c,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*l,e[11]=0,e[12]=(t+n)*s,e[13]=(o+r)*c,e[14]=(a+i)*l,e[15]=1,e}var Qt=wr;function en(e,t,n,r){let o,i,a,s,c,l,p,f,h,g,_=t[0],m=t[1],x=t[2],d=r[0],M=r[1],b=r[2],S=n[0],v=n[1],u=n[2];return Math.abs(_-S)<1e-6&&Math.abs(m-v)<1e-6&&Math.abs(x-u)<1e-6?Tr(e):(f=_-S,h=m-v,g=x-u,o=1/Math.sqrt(f*f+h*h+g*g),f*=o,h*=o,g*=o,i=M*g-b*h,a=b*f-d*g,s=d*h-M*f,o=Math.sqrt(i*i+a*a+s*s),o?(o=1/o,i*=o,a*=o,s*=o):(i=0,a=0,s=0),c=h*s-g*a,l=g*i-f*s,p=f*a-h*i,o=Math.sqrt(c*c+l*l+p*p),o?(o=1/o,c*=o,l*=o,p*=o):(c=0,l=0,p=0),e[0]=i,e[1]=c,e[2]=f,e[3]=0,e[4]=a,e[5]=l,e[6]=h,e[7]=0,e[8]=s,e[9]=p,e[10]=g,e[11]=0,e[12]=-(i*_+a*m+s*x),e[13]=-(c*_+l*m+p*x),e[14]=-(f*_+h*m+g*x),e[15]=1,e)}function Br(){let e=new w(4);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function tn(e,t,n){let r=t[0],o=t[1],i=t[2],a=t[3];return e[0]=n[0]*r+n[4]*o+n[8]*i+n[12]*a,e[1]=n[1]*r+n[5]*o+n[9]*i+n[13]*a,e[2]=n[2]*r+n[6]*o+n[10]*i+n[14]*a,e[3]=n[3]*r+n[7]*o+n[11]*i+n[15]*a,e}var Ri=function(){let e=Br();return function(t,n,r,o,i,a){let s,c;for(n||(n=4),r||(r=0),o?c=Math.min(o*n+r,t.length):c=t.length,s=r;s<c;s+=n)e[0]=t[s],e[1]=t[s+1],e[2]=t[s+2],e[3]=t[s+3],i(e,e,a),t[s]=e[0],t[s+1]=e[1],t[s+2]=e[2],t[s+3]=e[3];return t}}();var Ve;(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"})(Ve||(Ve={}));var kr=45*Math.PI/180,Dr=1,He=.1,Ge=500,Ur=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),B=class extends be{static get IDENTITY(){return Hr()}static get ZERO(){return zr()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Ve}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,n,r,o,i,a,s,c,l,p,f,h,g,_,m,x){return this[0]=t,this[1]=n,this[2]=r,this[3]=o,this[4]=i,this[5]=a,this[6]=s,this[7]=c,this[8]=l,this[9]=p,this[10]=f,this[11]=h,this[12]=g,this[13]=_,this[14]=m,this[15]=x,this.check()}setRowMajor(t,n,r,o,i,a,s,c,l,p,f,h,g,_,m,x){return this[0]=t,this[1]=i,this[2]=l,this[3]=g,this[4]=n,this[5]=a,this[6]=p,this[7]=_,this[8]=r,this[9]=s,this[10]=f,this[11]=m,this[12]=o,this[13]=c,this[14]=h,this[15]=x,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(Ur)}fromObject(t){return this.check()}fromQuaternion(t){return Xt(this,t),this.check()}frustum(t){let{left:n,right:r,bottom:o,top:i,near:a=He,far:s=Ge}=t;return s===1/0?Gr(this,n,r,o,i,a):Zt(this,n,r,o,i,a,s),this.check()}lookAt(t){let{eye:n,center:r=[0,0,0],up:o=[0,1,0]}=t;return en(this,n,r,o),this.check()}ortho(t){let{left:n,right:r,bottom:o,top:i,near:a=He,far:s=Ge}=t;return Qt(this,n,r,o,i,a,s),this.check()}orthographic(t){let{fovy:n=kr,aspect:r=Dr,focalDistance:o=1,near:i=He,far:a=Ge}=t;nn(n);let s=n/2,c=o*Math.tan(s),l=c*r;return this.ortho({left:-l,right:l,bottom:-c,top:c,near:i,far:a})}perspective(t){let{fovy:n=45*Math.PI/180,aspect:r=1,near:o=.1,far:i=500}=t;return nn(n),Jt(this,n,r,o,i),this.check()}determinant(){return Vt(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,n){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let r=this.getScale(n),o=1/r[0],i=1/r[1],a=1/r[2];return t[0]=this[0]*o,t[1]=this[1]*i,t[2]=this[2]*a,t[3]=0,t[4]=this[4]*o,t[5]=this[5]*i,t[6]=this[6]*a,t[7]=0,t[8]=this[8]*o,t[9]=this[9]*i,t[10]=this[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,n){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],n=n||[-0,-0,-0];let r=this.getScale(n),o=1/r[0],i=1/r[1],a=1/r[2];return t[0]=this[0]*o,t[1]=this[1]*i,t[2]=this[2]*a,t[3]=this[4]*o,t[4]=this[5]*i,t[5]=this[6]*a,t[6]=this[8]*o,t[7]=this[9]*i,t[8]=this[10]*a,t}transpose(){return Ht(this,this),this.check()}invert(){return Gt(this,this),this.check()}multiplyLeft(t){return ze(this,t,this),this.check()}multiplyRight(t){return ze(this,this,t),this.check()}rotateX(t){return qt(this,this,t),this.check()}rotateY(t){return Kt(this,this,t),this.check()}rotateZ(t){return Yt(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,n){return $t(this,this,t,n),this.check()}scale(t){return jt(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return Wt(this,this,t),this.check()}transform(t,n){return t.length===4?(n=tn(n||[-0,-0,-0,-0],t,this),_e(n,4),n):this.transformAsPoint(t,n)}transformAsPoint(t,n){let{length:r}=t,o;switch(r){case 2:o=kt(n||[-0,-0],t,this);break;case 3:o=zt(n||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return _e(o,t.length),o}transformAsVector(t,n){let r;switch(t.length){case 2:r=Dt(n||[-0,-0],t,this);break;case 3:r=Ut(n||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return _e(r,t.length),r}transformPoint(t,n){return this.transformAsPoint(t,n)}transformVector(t,n){return this.transformAsPoint(t,n)}transformDirection(t,n){return this.transformAsVector(t,n)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,n,r){return this.identity().translate([t,n,r])}},ve,Se;function zr(){return ve||(ve=new B([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(ve)),ve}function Hr(){return Se||(Se=new B,Object.freeze(Se)),Se}function nn(e){if(e>Math.PI*2)throw Error("expected radians")}function Gr(e,t,n,r,o,i){let a=2*i/(n-t),s=2*i/(o-r),c=(n+t)/(n-t),l=(o+r)/(o-r),p=-1,f=-1,h=-2*i;return e[0]=a,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=s,e[6]=0,e[7]=0,e[8]=c,e[9]=l,e[10]=p,e[11]=f,e[12]=0,e[13]=0,e[14]=h,e[15]=0,e}var D=null,rn=new ArrayBuffer(4),on=new Float32Array(rn),an=new Uint32Array(rn);function sn(e){D||=ln(),e=De(e,-65504,65504),on[0]=e;let t=an[0],n=t>>23&511;return D.baseTable[n]+((t&8388607)>>D.shiftTable[n])}function cn(e){D||=ln();let t=e>>10;return an[0]=D.mantissaTable[D.offsetTable[t]+(e&1023)]+D.exponentTable[t],on[0]}function ln(){let e=new Uint32Array(512),t=new Uint32Array(512);for(let i=0;i<256;++i){let a=i-127;a<-27?(e[i]=0,e[i|256]=32768,t[i]=24,t[i|256]=24):a<-14?(e[i]=1024>>-a-14,e[i|256]=1024>>-a-14|32768,t[i]=-a-1,t[i|256]=-a-1):a<=15?(e[i]=a+15<<10,e[i|256]=a+15<<10|32768,t[i]=13,t[i|256]=13):a<128?(e[i]=31744,e[i|256]=64512,t[i]=24,t[i|256]=24):(e[i]=31744,e[i|256]=64512,t[i]=13,t[i|256]=13)}let n=new Uint32Array(2048),r=new Uint32Array(64),o=new Uint32Array(64);for(let i=1;i<1024;++i){let a=i<<13,s=0;for(;!(a&8388608);)a<<=1,s-=8388608;a&=-8388609,s+=947912704,n[i]=a|s}for(let i=1024;i<2048;++i)n[i]=939524096+(i-1024<<13);for(let i=1;i<31;++i)r[i]=i<<23;r[31]=1199570944,r[32]=2147483648;for(let i=33;i<63;++i)r[i]=2147483648+(i-32<<23);r[63]=3347054592;for(let i=1;i<64;++i)i!==32&&(o[i]=1024);return{baseTable:e,shiftTable:t,mantissaTable:n,exponentTable:r,offsetTable:o}}function V(e,t=[],n=0){let r=Math.fround(e),o=e-r;return t[n]=r,t[n+1]=o,t}function Q(e){return e-Math.fround(e)}function ee(e){let t=new Float32Array(32);for(let n=0;n<4;++n)for(let r=0;r<4;++r){let o=n*4+r;V(e[r*4+n],t,o*2)}return t}var Vr=`fn random(scale: vec3f, seed: f32) -> f32 {
|
|
101
|
+
${n} = ${i};
|
|
102
|
+
}`}function Ht(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 $t(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 Qn(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 Xe(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 G(e){return typeof e=="string"?e.charAt(0).toUpperCase()+e.slice(1):e}function Wt(e,t){return Jn(e,t)}function Jn(e,t){let r=[];switch(t.uniforms){case"scoped-interface-blocks":case"unscoped-interface-blocks":r.push(`layout(std140) uniform ${G(e.name)} {`);break;case"uniforms":}for(let[n,o]of Object.entries(e.uniformTypes||{})){if(typeof o!="string")throw new Error(`Composite uniform types are not supported by GLSL shader generation: ${e.name}.${n}`);let i=eo(o);switch(t.uniforms){case"scoped-interface-blocks":r.push(` ${i} ${n};`);break;case"unscoped-interface-blocks":r.push(` ${i} ${e.name}_${n};`);break;case"uniforms":r.push(`uniform ${i} ${e.name}_${n};`)}}switch(t.uniforms){case"scoped-interface-blocks":r.push(`} ${e.name};`);break;case"unscoped-interface-blocks":r.push("};");break;case"uniforms":}return r.push(""),r.join(`
|
|
103
|
+
`)}function eo(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 jt(e,t){return to(e,t)}function to(e,t){let r=[];r.push(`struct ${G(e.name)} {`);for(let[n,o]of Object.entries(e?.uniformTypes||{})){if(typeof o!="string")throw new Error(`Composite uniform types are not supported by WGSL shader generation: ${e.name}.${n}`);let i=o;r.push(` ${n} : ${i};`)}return r.push("};"),r.push(`var<uniform> ${e.name} : ${G(e.name)};`),r.join(`
|
|
104
|
+
`)}function qt(e,t){switch(t.shaderLanguage){case"glsl":return Wt(e,t);case"wgsl":return jt(e,t)}}var Gi=1/Math.PI*180,Hi=1/180*Math.PI,ro={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...ro}};var y=globalThis.mathgl.config;function Ze(e,{precision:t=y.precision}={}){return e=no(e),`${parseFloat(e.toPrecision(t))}`}function K(e){return Array.isArray(e)||ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Qe(e,t,r){return io(e,n=>Math.max(t,Math.min(r,n)))}function Ae(e,t,r){let n=y.EPSILON;r&&(y.EPSILON=r);try{if(e===t)return!0;if(K(e)&&K(t)){if(e.length!==t.length)return!1;for(let o=0;o<e.length;++o)if(!Ae(e[o],t[o]))return!1;return!0}return e&&e.equals?e.equals(t):t&&t.equals?t.equals(e):typeof e=="number"&&typeof t=="number"?Math.abs(e-t)<=y.EPSILON*Math.max(1,Math.abs(e),Math.abs(t)):!1}finally{y.EPSILON=n}}function no(e){return Math.round(e/y.EPSILON)*y.EPSILON}function oo(e){return e.clone?e.clone():new Array(e.length)}function io(e,t,r){if(K(e)){let n=e;r=r||oo(n);for(let o=0;o<r.length&&o<n.length;++o){let i=typeof e=="number"?e:e[o];r[o]=t(i,o,r)}return r}return t(e)}var Re=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,r=0){for(let n=0;n<this.ELEMENTS;++n)this[n]=t[n+r];return this.check()}toArray(t=[],r=0){for(let n=0;n<this.ELEMENTS;++n)t[r+n]=this[n];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:K(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(y)}formatString(t){let r="";for(let n=0;n<this.ELEMENTS;++n)r+=(n>0?", ":"")+Ze(this[n],t);return`${t.printTypes?this.constructor.name:""}[${r}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let r=0;r<this.ELEMENTS;++r)if(!Ae(this[r],t[r]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let r=0;r<this.ELEMENTS;++r)if(this[r]!==t[r])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,r,n){if(n===void 0)return this.lerp(this,t,r);for(let o=0;o<this.ELEMENTS;++o){let i=t[o],a=typeof r=="number"?r:r[o];this[o]=i+n*(a-i)}return this.check()}min(t){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.min(t[r],this[r]);return this.check()}max(t){for(let r=0;r<this.ELEMENTS;++r)this[r]=Math.max(t[r],this[r]);return this.check()}clamp(t,r){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t[n]),r[n]);return this.check()}add(...t){for(let r of t)for(let n=0;n<this.ELEMENTS;++n)this[n]+=r[n];return this.check()}subtract(...t){for(let r of t)for(let n=0;n<this.ELEMENTS;++n)this[n]-=r[n];return this.check()}scale(t){if(typeof t=="number")for(let r=0;r<this.ELEMENTS;++r)this[r]*=t;else for(let r=0;r<this.ELEMENTS&&r<t.length;++r)this[r]*=t[r];return this.check()}multiplyByScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]*=t;return this.check()}check(){if(y.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let r=0;r<this.ELEMENTS;++r)t=t&&Number.isFinite(this[r]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]=t;return this.check()}addScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let r=0;r<this.ELEMENTS;++r)this[r]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,r){for(let n=0;n<this.ELEMENTS;++n)this[n]=Math.min(Math.max(this[n],t),r);return this.check()}get elements(){return this}};function ao(e,t){if(e.length!==t)return!1;for(let r=0;r<e.length;++r)if(!Number.isFinite(e[r]))return!1;return!0}function Kt(e){if(!Number.isFinite(e))throw new Error(`Invalid number ${JSON.stringify(e)}`);return e}function Ee(e,t,r=""){if(y.debug&&!ao(e,t))throw new Error(`math.gl: ${r} some fields set to invalid numbers'`);return e}var w=typeof Float32Array<"u"?Float32Array:Array;var Yi=Math.PI/180;function so(){let e=new w(2);return w!=Float32Array&&(e[0]=0,e[1]=0),e}function Zt(e,t,r){let n=t[0],o=t[1];return e[0]=r[0]*n+r[4]*o+r[12],e[1]=r[1]*n+r[5]*o+r[13],e}var Xi=function(){let e=so();return function(t,r,n,o,i,a){let s,l;for(r||(r=2),n||(n=0),o?l=Math.min(o*r+n,t.length):l=t.length,s=n;s<l;s+=r)e[0]=t[s],e[1]=t[s+1],i(e,e,a),t[s]=e[0],t[s+1]=e[1];return t}}();function Qt(e,t,r){let n=t[0],o=t[1],i=r[3]*n+r[7]*o||1;return e[0]=(r[0]*n+r[4]*o)/i,e[1]=(r[1]*n+r[5]*o)/i,e}function Jt(e,t,r){let n=t[0],o=t[1],i=t[2],a=r[3]*n+r[7]*o+r[11]*i||1;return e[0]=(r[0]*n+r[4]*o+r[8]*i)/a,e[1]=(r[1]*n+r[5]*o+r[9]*i)/a,e[2]=(r[2]*n+r[6]*o+r[10]*i)/a,e}function lo(){let e=new w(3);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0),e}function er(e,t,r){let n=t[0],o=t[1],i=t[2],a=r[3]*n+r[7]*o+r[11]*i+r[15];return a=a||1,e[0]=(r[0]*n+r[4]*o+r[8]*i+r[12])/a,e[1]=(r[1]*n+r[5]*o+r[9]*i+r[13])/a,e[2]=(r[2]*n+r[6]*o+r[10]*i+r[14])/a,e}var Ji=function(){let e=lo();return function(t,r,n,o,i,a){let s,l;for(r||(r=3),n||(n=0),o?l=Math.min(o*r+n,t.length):l=t.length,s=n;s<l;s+=r)e[0]=t[s],e[1]=t[s+1],e[2]=t[s+2],i(e,e,a),t[s]=e[0],t[s+1]=e[1],t[s+2]=e[2];return t}}();var Ce=class extends Re{toString(){let t="[";if(y.printRowMajor){t+="row-major:";for(let r=0;r<this.RANK;++r)for(let n=0;n<this.RANK;++n)t+=` ${this[n*this.RANK+r]}`}else{t+="column-major:";for(let r=0;r<this.ELEMENTS;++r)t+=` ${this[r]}`}return t+="]",t}getElementIndex(t,r){return r*this.RANK+t}getElement(t,r){return this[r*this.RANK+t]}setElement(t,r,n){return this[r*this.RANK+t]=Kt(n),this}getColumn(t,r=new Array(this.RANK).fill(-0)){let n=t*this.RANK;for(let o=0;o<this.RANK;++o)r[o]=this[n+o];return r}setColumn(t,r){let n=t*this.RANK;for(let o=0;o<this.RANK;++o)this[n+o]=r[o];return this}};function co(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function tr(e,t){if(e===t){let r=t[1],n=t[2],o=t[3],i=t[6],a=t[7],s=t[11];e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=r,e[6]=t[9],e[7]=t[13],e[8]=n,e[9]=i,e[11]=t[14],e[12]=o,e[13]=a,e[14]=s}else e[0]=t[0],e[1]=t[4],e[2]=t[8],e[3]=t[12],e[4]=t[1],e[5]=t[5],e[6]=t[9],e[7]=t[13],e[8]=t[2],e[9]=t[6],e[10]=t[10],e[11]=t[14],e[12]=t[3],e[13]=t[7],e[14]=t[11],e[15]=t[15];return e}function rr(e,t){let r=t[0],n=t[1],o=t[2],i=t[3],a=t[4],s=t[5],l=t[6],c=t[7],f=t[8],p=t[9],u=t[10],h=t[11],g=t[12],S=t[13],x=t[14],_=t[15],L=r*s-n*a,d=r*l-o*a,b=r*c-i*a,v=n*l-o*s,m=n*c-i*s,M=o*c-i*l,E=f*S-p*g,A=f*x-u*g,C=f*_-h*g,P=p*x-u*S,I=p*_-h*S,O=u*_-h*x,R=L*O-d*I+b*P+v*C-m*A+M*E;return R?(R=1/R,e[0]=(s*O-l*I+c*P)*R,e[1]=(o*I-n*O-i*P)*R,e[2]=(S*M-x*m+_*v)*R,e[3]=(u*m-p*M-h*v)*R,e[4]=(l*C-a*O-c*A)*R,e[5]=(r*O-o*C+i*A)*R,e[6]=(x*b-g*M-_*d)*R,e[7]=(f*M-u*b+h*d)*R,e[8]=(a*I-s*C+c*E)*R,e[9]=(n*C-r*I-i*E)*R,e[10]=(g*m-S*b+_*L)*R,e[11]=(p*b-f*m-h*L)*R,e[12]=(s*A-a*P-l*E)*R,e[13]=(r*P-n*A+o*E)*R,e[14]=(S*d-g*v-x*L)*R,e[15]=(f*v-p*d+u*L)*R,e):null}function nr(e){let t=e[0],r=e[1],n=e[2],o=e[3],i=e[4],a=e[5],s=e[6],l=e[7],c=e[8],f=e[9],p=e[10],u=e[11],h=e[12],g=e[13],S=e[14],x=e[15],_=t*a-r*i,L=t*s-n*i,d=r*s-n*a,b=c*g-f*h,v=c*S-p*h,m=f*S-p*g,M=t*m-r*v+n*b,E=i*m-a*v+s*b,A=c*d-f*L+p*_,C=h*d-g*L+S*_;return l*M-o*E+x*A-u*C}function et(e,t,r){let n=t[0],o=t[1],i=t[2],a=t[3],s=t[4],l=t[5],c=t[6],f=t[7],p=t[8],u=t[9],h=t[10],g=t[11],S=t[12],x=t[13],_=t[14],L=t[15],d=r[0],b=r[1],v=r[2],m=r[3];return e[0]=d*n+b*s+v*p+m*S,e[1]=d*o+b*l+v*u+m*x,e[2]=d*i+b*c+v*h+m*_,e[3]=d*a+b*f+v*g+m*L,d=r[4],b=r[5],v=r[6],m=r[7],e[4]=d*n+b*s+v*p+m*S,e[5]=d*o+b*l+v*u+m*x,e[6]=d*i+b*c+v*h+m*_,e[7]=d*a+b*f+v*g+m*L,d=r[8],b=r[9],v=r[10],m=r[11],e[8]=d*n+b*s+v*p+m*S,e[9]=d*o+b*l+v*u+m*x,e[10]=d*i+b*c+v*h+m*_,e[11]=d*a+b*f+v*g+m*L,d=r[12],b=r[13],v=r[14],m=r[15],e[12]=d*n+b*s+v*p+m*S,e[13]=d*o+b*l+v*u+m*x,e[14]=d*i+b*c+v*h+m*_,e[15]=d*a+b*f+v*g+m*L,e}function or(e,t,r){let n=r[0],o=r[1],i=r[2],a,s,l,c,f,p,u,h,g,S,x,_;return t===e?(e[12]=t[0]*n+t[4]*o+t[8]*i+t[12],e[13]=t[1]*n+t[5]*o+t[9]*i+t[13],e[14]=t[2]*n+t[6]*o+t[10]*i+t[14],e[15]=t[3]*n+t[7]*o+t[11]*i+t[15]):(a=t[0],s=t[1],l=t[2],c=t[3],f=t[4],p=t[5],u=t[6],h=t[7],g=t[8],S=t[9],x=t[10],_=t[11],e[0]=a,e[1]=s,e[2]=l,e[3]=c,e[4]=f,e[5]=p,e[6]=u,e[7]=h,e[8]=g,e[9]=S,e[10]=x,e[11]=_,e[12]=a*n+f*o+g*i+t[12],e[13]=s*n+p*o+S*i+t[13],e[14]=l*n+u*o+x*i+t[14],e[15]=c*n+h*o+_*i+t[15]),e}function ir(e,t,r){let n=r[0],o=r[1],i=r[2];return e[0]=t[0]*n,e[1]=t[1]*n,e[2]=t[2]*n,e[3]=t[3]*n,e[4]=t[4]*o,e[5]=t[5]*o,e[6]=t[6]*o,e[7]=t[7]*o,e[8]=t[8]*i,e[9]=t[9]*i,e[10]=t[10]*i,e[11]=t[11]*i,e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15],e}function ar(e,t,r,n){let o=n[0],i=n[1],a=n[2],s=Math.sqrt(o*o+i*i+a*a),l,c,f,p,u,h,g,S,x,_,L,d,b,v,m,M,E,A,C,P,I,O,R,Z;return s<1e-6?null:(s=1/s,o*=s,i*=s,a*=s,c=Math.sin(r),l=Math.cos(r),f=1-l,p=t[0],u=t[1],h=t[2],g=t[3],S=t[4],x=t[5],_=t[6],L=t[7],d=t[8],b=t[9],v=t[10],m=t[11],M=o*o*f+l,E=i*o*f+a*c,A=a*o*f-i*c,C=o*i*f-a*c,P=i*i*f+l,I=a*i*f+o*c,O=o*a*f+i*c,R=i*a*f-o*c,Z=a*a*f+l,e[0]=p*M+S*E+d*A,e[1]=u*M+x*E+b*A,e[2]=h*M+_*E+v*A,e[3]=g*M+L*E+m*A,e[4]=p*C+S*P+d*I,e[5]=u*C+x*P+b*I,e[6]=h*C+_*P+v*I,e[7]=g*C+L*P+m*I,e[8]=p*O+S*R+d*Z,e[9]=u*O+x*R+b*Z,e[10]=h*O+_*R+v*Z,e[11]=g*O+L*R+m*Z,t!==e&&(e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e)}function sr(e,t,r){let n=Math.sin(r),o=Math.cos(r),i=t[4],a=t[5],s=t[6],l=t[7],c=t[8],f=t[9],p=t[10],u=t[11];return t!==e&&(e[0]=t[0],e[1]=t[1],e[2]=t[2],e[3]=t[3],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[4]=i*o+c*n,e[5]=a*o+f*n,e[6]=s*o+p*n,e[7]=l*o+u*n,e[8]=c*o-i*n,e[9]=f*o-a*n,e[10]=p*o-s*n,e[11]=u*o-l*n,e}function lr(e,t,r){let n=Math.sin(r),o=Math.cos(r),i=t[0],a=t[1],s=t[2],l=t[3],c=t[8],f=t[9],p=t[10],u=t[11];return t!==e&&(e[4]=t[4],e[5]=t[5],e[6]=t[6],e[7]=t[7],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*o-c*n,e[1]=a*o-f*n,e[2]=s*o-p*n,e[3]=l*o-u*n,e[8]=i*n+c*o,e[9]=a*n+f*o,e[10]=s*n+p*o,e[11]=l*n+u*o,e}function cr(e,t,r){let n=Math.sin(r),o=Math.cos(r),i=t[0],a=t[1],s=t[2],l=t[3],c=t[4],f=t[5],p=t[6],u=t[7];return t!==e&&(e[8]=t[8],e[9]=t[9],e[10]=t[10],e[11]=t[11],e[12]=t[12],e[13]=t[13],e[14]=t[14],e[15]=t[15]),e[0]=i*o+c*n,e[1]=a*o+f*n,e[2]=s*o+p*n,e[3]=l*o+u*n,e[4]=c*o-i*n,e[5]=f*o-a*n,e[6]=p*o-s*n,e[7]=u*o-l*n,e}function fr(e,t){let r=t[0],n=t[1],o=t[2],i=t[3],a=r+r,s=n+n,l=o+o,c=r*a,f=n*a,p=n*s,u=o*a,h=o*s,g=o*l,S=i*a,x=i*s,_=i*l;return e[0]=1-p-g,e[1]=f+_,e[2]=u-x,e[3]=0,e[4]=f-_,e[5]=1-c-g,e[6]=h+S,e[7]=0,e[8]=u+x,e[9]=h-S,e[10]=1-c-p,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}function pr(e,t,r,n,o,i,a){let s=1/(r-t),l=1/(o-n),c=1/(i-a);return e[0]=i*2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i*2*l,e[6]=0,e[7]=0,e[8]=(r+t)*s,e[9]=(o+n)*l,e[10]=(a+i)*c,e[11]=-1,e[12]=0,e[13]=0,e[14]=a*i*2*c,e[15]=0,e}function fo(e,t,r,n,o){let i=1/Math.tan(t/2);if(e[0]=i/r,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[11]=-1,e[12]=0,e[13]=0,e[15]=0,o!=null&&o!==1/0){let a=1/(n-o);e[10]=(o+n)*a,e[14]=2*o*n*a}else e[10]=-1,e[14]=-2*n;return e}var ur=fo;function po(e,t,r,n,o,i,a){let s=1/(t-r),l=1/(n-o),c=1/(i-a);return e[0]=-2*s,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=-2*l,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=2*c,e[11]=0,e[12]=(t+r)*s,e[13]=(o+n)*l,e[14]=(a+i)*c,e[15]=1,e}var hr=po;function mr(e,t,r,n){let o,i,a,s,l,c,f,p,u,h,g=t[0],S=t[1],x=t[2],_=n[0],L=n[1],d=n[2],b=r[0],v=r[1],m=r[2];return Math.abs(g-b)<1e-6&&Math.abs(S-v)<1e-6&&Math.abs(x-m)<1e-6?co(e):(p=g-b,u=S-v,h=x-m,o=1/Math.sqrt(p*p+u*u+h*h),p*=o,u*=o,h*=o,i=L*h-d*u,a=d*p-_*h,s=_*u-L*p,o=Math.sqrt(i*i+a*a+s*s),o?(o=1/o,i*=o,a*=o,s*=o):(i=0,a=0,s=0),l=u*s-h*a,c=h*i-p*s,f=p*a-u*i,o=Math.sqrt(l*l+c*c+f*f),o?(o=1/o,l*=o,c*=o,f*=o):(l=0,c=0,f=0),e[0]=i,e[1]=l,e[2]=p,e[3]=0,e[4]=a,e[5]=c,e[6]=u,e[7]=0,e[8]=s,e[9]=f,e[10]=h,e[11]=0,e[12]=-(i*g+a*S+s*x),e[13]=-(l*g+c*S+f*x),e[14]=-(p*g+u*S+h*x),e[15]=1,e)}function uo(){let e=new w(4);return w!=Float32Array&&(e[0]=0,e[1]=0,e[2]=0,e[3]=0),e}function gr(e,t,r){let n=t[0],o=t[1],i=t[2],a=t[3];return e[0]=r[0]*n+r[4]*o+r[8]*i+r[12]*a,e[1]=r[1]*n+r[5]*o+r[9]*i+r[13]*a,e[2]=r[2]*n+r[6]*o+r[10]*i+r[14]*a,e[3]=r[3]*n+r[7]*o+r[11]*i+r[15]*a,e}var aa=function(){let e=uo();return function(t,r,n,o,i,a){let s,l;for(r||(r=4),n||(n=0),o?l=Math.min(o*r+n,t.length):l=t.length,s=n;s<l;s+=r)e[0]=t[s],e[1]=t[s+1],e[2]=t[s+2],e[3]=t[s+3],i(e,e,a),t[s]=e[0],t[s+1]=e[1],t[s+2]=e[2],t[s+3]=e[3];return t}}();var nt;(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"})(nt||(nt={}));var ho=45*Math.PI/180,mo=1,tt=.1,rt=500,go=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),D=class extends Ce{static get IDENTITY(){return bo()}static get ZERO(){return _o()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return nt}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,r,n,o,i,a,s,l,c,f,p,u,h,g,S,x){return this[0]=t,this[1]=r,this[2]=n,this[3]=o,this[4]=i,this[5]=a,this[6]=s,this[7]=l,this[8]=c,this[9]=f,this[10]=p,this[11]=u,this[12]=h,this[13]=g,this[14]=S,this[15]=x,this.check()}setRowMajor(t,r,n,o,i,a,s,l,c,f,p,u,h,g,S,x){return this[0]=t,this[1]=i,this[2]=c,this[3]=h,this[4]=r,this[5]=a,this[6]=f,this[7]=g,this[8]=n,this[9]=s,this[10]=p,this[11]=S,this[12]=o,this[13]=l,this[14]=u,this[15]=x,this.check()}toRowMajor(t){return t[0]=this[0],t[1]=this[4],t[2]=this[8],t[3]=this[12],t[4]=this[1],t[5]=this[5],t[6]=this[9],t[7]=this[13],t[8]=this[2],t[9]=this[6],t[10]=this[10],t[11]=this[14],t[12]=this[3],t[13]=this[7],t[14]=this[11],t[15]=this[15],t}identity(){return this.copy(go)}fromObject(t){return this.check()}fromQuaternion(t){return fr(this,t),this.check()}frustum(t){let{left:r,right:n,bottom:o,top:i,near:a=tt,far:s=rt}=t;return s===1/0?vo(this,r,n,o,i,a):pr(this,r,n,o,i,a,s),this.check()}lookAt(t){let{eye:r,center:n=[0,0,0],up:o=[0,1,0]}=t;return mr(this,r,n,o),this.check()}ortho(t){let{left:r,right:n,bottom:o,top:i,near:a=tt,far:s=rt}=t;return hr(this,r,n,o,i,a,s),this.check()}orthographic(t){let{fovy:r=ho,aspect:n=mo,focalDistance:o=1,near:i=tt,far:a=rt}=t;dr(r);let s=r/2,l=o*Math.tan(s),c=l*n;return this.ortho({left:-c,right:c,bottom:-l,top:l,near:i,far:a})}perspective(t){let{fovy:r=45*Math.PI/180,aspect:n=1,near:o=.1,far:i=500}=t;return dr(r),ur(this,r,n,o,i),this.check()}determinant(){return nr(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,r){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],r=r||[-0,-0,-0];let n=this.getScale(r),o=1/n[0],i=1/n[1],a=1/n[2];return t[0]=this[0]*o,t[1]=this[1]*i,t[2]=this[2]*a,t[3]=0,t[4]=this[4]*o,t[5]=this[5]*i,t[6]=this[6]*a,t[7]=0,t[8]=this[8]*o,t[9]=this[9]*i,t[10]=this[10]*a,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,r){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],r=r||[-0,-0,-0];let n=this.getScale(r),o=1/n[0],i=1/n[1],a=1/n[2];return t[0]=this[0]*o,t[1]=this[1]*i,t[2]=this[2]*a,t[3]=this[4]*o,t[4]=this[5]*i,t[5]=this[6]*a,t[6]=this[8]*o,t[7]=this[9]*i,t[8]=this[10]*a,t}transpose(){return tr(this,this),this.check()}invert(){return rr(this,this),this.check()}multiplyLeft(t){return et(this,t,this),this.check()}multiplyRight(t){return et(this,this,t),this.check()}rotateX(t){return sr(this,this,t),this.check()}rotateY(t){return lr(this,this,t),this.check()}rotateZ(t){return cr(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,r){return ar(this,this,t,r),this.check()}scale(t){return ir(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return or(this,this,t),this.check()}transform(t,r){return t.length===4?(r=gr(r||[-0,-0,-0,-0],t,this),Ee(r,4),r):this.transformAsPoint(t,r)}transformAsPoint(t,r){let{length:n}=t,o;switch(n){case 2:o=Zt(r||[-0,-0],t,this);break;case 3:o=er(r||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Ee(o,t.length),o}transformAsVector(t,r){let n;switch(t.length){case 2:n=Qt(r||[-0,-0],t,this);break;case 3:n=Jt(r||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Ee(n,t.length),n}transformPoint(t,r){return this.transformAsPoint(t,r)}transformVector(t,r){return this.transformAsPoint(t,r)}transformDirection(t,r){return this.transformAsVector(t,r)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,r,n){return this.identity().translate([t,r,n])}},Ie,ye;function _o(){return Ie||(Ie=new D([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(Ie)),Ie}function bo(){return ye||(ye=new D,Object.freeze(ye)),ye}function dr(e){if(e>Math.PI*2)throw Error("expected radians")}function vo(e,t,r,n,o,i){let a=2*i/(r-t),s=2*i/(o-n),l=(r+t)/(r-t),c=(o+n)/(o-n),f=-1,p=-1,u=-2*i;return e[0]=a,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=s,e[6]=0,e[7]=0,e[8]=l,e[9]=c,e[10]=f,e[11]=p,e[12]=0,e[13]=0,e[14]=u,e[15]=0,e}var H=null,_r=new ArrayBuffer(4),br=new Float32Array(_r),vr=new Uint32Array(_r);function Sr(e){H||=Mr(),e=Qe(e,-65504,65504),br[0]=e;let t=vr[0],r=t>>23&511;return H.baseTable[r]+((t&8388607)>>H.shiftTable[r])}function xr(e){H||=Mr();let t=e>>10;return vr[0]=H.mantissaTable[H.offsetTable[t]+(e&1023)]+H.exponentTable[t],br[0]}function Mr(){let e=new Uint32Array(512),t=new Uint32Array(512);for(let i=0;i<256;++i){let a=i-127;a<-27?(e[i]=0,e[i|256]=32768,t[i]=24,t[i|256]=24):a<-14?(e[i]=1024>>-a-14,e[i|256]=1024>>-a-14|32768,t[i]=-a-1,t[i|256]=-a-1):a<=15?(e[i]=a+15<<10,e[i|256]=a+15<<10|32768,t[i]=13,t[i|256]=13):a<128?(e[i]=31744,e[i|256]=64512,t[i]=24,t[i|256]=24):(e[i]=31744,e[i|256]=64512,t[i]=13,t[i|256]=13)}let r=new Uint32Array(2048),n=new Uint32Array(64),o=new Uint32Array(64);for(let i=1;i<1024;++i){let a=i<<13,s=0;for(;!(a&8388608);)a<<=1,s-=8388608;a&=-8388609,s+=947912704,r[i]=a|s}for(let i=1024;i<2048;++i)r[i]=939524096+(i-1024<<13);for(let i=1;i<31;++i)n[i]=i<<23;n[31]=1199570944,n[32]=2147483648;for(let i=33;i<63;++i)n[i]=2147483648+(i-32<<23);n[63]=3347054592;for(let i=1;i<64;++i)i!==32&&(o[i]=1024);return{baseTable:e,shiftTable:t,mantissaTable:r,exponentTable:n,offsetTable:o}}function X(e,t=[],r=0){let n=Math.fround(e),o=e-n;return t[r]=n,t[r+1]=o,t}function ae(e){return e-Math.fround(e)}function se(e){let t=new Float32Array(32);for(let r=0;r<4;++r)for(let n=0;n<4;++n){let o=r*4+n;X(e[n*4+r],t,o*2)}return t}function V(e,t=!0){return e??t}function k(e=[0,0,0],t=!0){return t?e.map(r=>r/255):[...e]}function Ne(e,t=!0){let r=k(e.slice(0,3),t),n=Number.isFinite(e[3]),o=n?e[3]:1;return[r[0],r[1],r[2],t&&n?o/255:o]}var So=`fn random(scale: vec3f, seed: f32) -> f32 {
|
|
105
105
|
return fract(sin(dot(scale + vec3f(seed), vec3f(12.9898, 78.233, 151.7182))) * 43758.5453 + seed);
|
|
106
106
|
}
|
|
107
|
-
`,
|
|
107
|
+
`,xo=`float random(vec3 scale, float seed) {
|
|
108
108
|
/* use the fragment position for a different seed per-pixel */
|
|
109
109
|
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
|
|
110
110
|
}
|
|
111
|
-
`,
|
|
111
|
+
`,Lr={name:"random",source:So,fs:xo};var Mo=`#ifdef LUMA_FP32_TAN_PRECISION_WORKAROUND
|
|
112
112
|
|
|
113
113
|
// All these functions are for substituting tan() function from Intel GPU only
|
|
114
114
|
const float TWO_PI = 6.2831854820251465;
|
|
@@ -258,8 +258,8 @@ float tan_fp32(float a) {
|
|
|
258
258
|
return tan(a);
|
|
259
259
|
#endif
|
|
260
260
|
}
|
|
261
|
-
`,
|
|
262
|
-
uniform fp64arithmeticUniforms {
|
|
261
|
+
`,Ar={name:"fp32",vs:Mo};var ot=`
|
|
262
|
+
layout(std140) uniform fp64arithmeticUniforms {
|
|
263
263
|
uniform float ONE;
|
|
264
264
|
uniform float SPLIT;
|
|
265
265
|
} fp64;
|
|
@@ -457,7 +457,7 @@ vec2 sqrt_fp64(vec2 a) {
|
|
|
457
457
|
return sum_fp64(vec2(yn, 0.0), prod);
|
|
458
458
|
#endif
|
|
459
459
|
}
|
|
460
|
-
`;var
|
|
460
|
+
`;var Rr=`struct Fp64ArithmeticUniforms {
|
|
461
461
|
ONE: f32,
|
|
462
462
|
SPLIT: f32,
|
|
463
463
|
};
|
|
@@ -663,7 +663,7 @@ fn sqrt_fp64(a: vec2f) -> vec2f {
|
|
|
663
663
|
return sum_fp64(vec2f(yn, 0.0), prod);
|
|
664
664
|
#endif
|
|
665
665
|
}
|
|
666
|
-
`;var
|
|
666
|
+
`;var Er=`const vec2 E_FP64 = vec2(2.7182817459106445e+00, 8.254840366817007e-08);
|
|
667
667
|
const vec2 LOG2_FP64 = vec2(0.6931471824645996e+00, -1.9046542121259336e-09);
|
|
668
668
|
const vec2 PI_FP64 = vec2(3.1415927410125732, -8.742278012618954e-8);
|
|
669
669
|
const vec2 TWO_PI_FP64 = vec2(6.2831854820251465, -1.7484556025237907e-7);
|
|
@@ -1332,11 +1332,71 @@ void mat4_vec4_mul_fp64(vec2 b[16], vec2 a[4], out vec2 out_val[4]) {
|
|
|
1332
1332
|
vec4_dot_fp64(a, tmp, out_val[i]);
|
|
1333
1333
|
}
|
|
1334
1334
|
}
|
|
1335
|
-
`;var
|
|
1335
|
+
`;var Lo={ONE:1,SPLIT:4097},it={name:"fp64arithmetic",source:Rr,fs:ot,vs:ot,defaultUniforms:Lo,uniformTypes:{ONE:"f32",SPLIT:"f32"},fp64ify:X,fp64LowPart:ae,fp64ifyMatrix4:se},Cr={name:"fp64",vs:Er,dependencies:[it],fp64ify:X,fp64LowPart:ae,fp64ifyMatrix4:se};var Ir=`layout(std140) uniform floatColorsUniforms {
|
|
1336
|
+
float useByteColors;
|
|
1337
|
+
} floatColors;
|
|
1338
|
+
|
|
1339
|
+
vec3 floatColors_normalize(vec3 inputColor) {
|
|
1340
|
+
return floatColors.useByteColors > 0.5 ? inputColor / 255.0 : inputColor;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
vec4 floatColors_normalize(vec4 inputColor) {
|
|
1344
|
+
return floatColors.useByteColors > 0.5 ? inputColor / 255.0 : inputColor;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
vec4 floatColors_premultiplyAlpha(vec4 inputColor) {
|
|
1348
|
+
return vec4(inputColor.rgb * inputColor.a, inputColor.a);
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
vec4 floatColors_unpremultiplyAlpha(vec4 inputColor) {
|
|
1352
|
+
return inputColor.a > 0.0 ? vec4(inputColor.rgb / inputColor.a, inputColor.a) : vec4(0.0);
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
vec4 floatColors_premultiply_alpha(vec4 inputColor) {
|
|
1356
|
+
return floatColors_premultiplyAlpha(inputColor);
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
vec4 floatColors_unpremultiply_alpha(vec4 inputColor) {
|
|
1360
|
+
return floatColors_unpremultiplyAlpha(inputColor);
|
|
1361
|
+
}
|
|
1362
|
+
`,Ao=`struct floatColorsUniforms {
|
|
1363
|
+
useByteColors: f32
|
|
1364
|
+
};
|
|
1365
|
+
|
|
1366
|
+
@group(0) @binding(auto) var<uniform> floatColors : floatColorsUniforms;
|
|
1367
|
+
|
|
1368
|
+
fn floatColors_normalize(inputColor: vec3<f32>) -> vec3<f32> {
|
|
1369
|
+
return select(inputColor, inputColor / 255.0, floatColors.useByteColors > 0.5);
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
fn floatColors_normalize4(inputColor: vec4<f32>) -> vec4<f32> {
|
|
1373
|
+
return select(inputColor, inputColor / 255.0, floatColors.useByteColors > 0.5);
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
fn floatColors_premultiplyAlpha(inputColor: vec4<f32>) -> vec4<f32> {
|
|
1377
|
+
return vec4<f32>(inputColor.rgb * inputColor.a, inputColor.a);
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
fn floatColors_unpremultiplyAlpha(inputColor: vec4<f32>) -> vec4<f32> {
|
|
1381
|
+
return select(
|
|
1382
|
+
vec4<f32>(0.0),
|
|
1383
|
+
vec4<f32>(inputColor.rgb / inputColor.a, inputColor.a),
|
|
1384
|
+
inputColor.a > 0.0
|
|
1385
|
+
);
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
fn floatColors_premultiply_alpha(inputColor: vec4<f32>) -> vec4<f32> {
|
|
1389
|
+
return floatColors_premultiplyAlpha(inputColor);
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
fn floatColors_unpremultiply_alpha(inputColor: vec4<f32>) -> vec4<f32> {
|
|
1393
|
+
return floatColors_unpremultiplyAlpha(inputColor);
|
|
1394
|
+
}
|
|
1395
|
+
`,yr={name:"floatColors",props:{},uniforms:{},vs:Ir,fs:Ir,source:Ao,uniformTypes:{useByteColors:"f32"},defaultUniforms:{useByteColors:!0}};var Ro=[0,1,1,1],Eo=`layout(std140) uniform pickingUniforms {
|
|
1336
1396
|
float isActive;
|
|
1337
1397
|
float isAttribute;
|
|
1338
1398
|
float isHighlightActive;
|
|
1339
|
-
float
|
|
1399
|
+
float useByteColors;
|
|
1340
1400
|
vec3 highlightedObjectColor;
|
|
1341
1401
|
vec4 highlightColor;
|
|
1342
1402
|
} picking;
|
|
@@ -1345,12 +1405,12 @@ out vec4 picking_vRGBcolor_Avalid;
|
|
|
1345
1405
|
|
|
1346
1406
|
// Normalize unsigned byte color to 0-1 range
|
|
1347
1407
|
vec3 picking_normalizeColor(vec3 color) {
|
|
1348
|
-
return picking.
|
|
1408
|
+
return picking.useByteColors > 0.5 ? color / 255.0 : color;
|
|
1349
1409
|
}
|
|
1350
1410
|
|
|
1351
1411
|
// Normalize unsigned byte color to 0-1 range
|
|
1352
1412
|
vec4 picking_normalizeColor(vec4 color) {
|
|
1353
|
-
return picking.
|
|
1413
|
+
return picking.useByteColors > 0.5 ? color / 255.0 : color;
|
|
1354
1414
|
}
|
|
1355
1415
|
|
|
1356
1416
|
bool picking_isColorZero(vec3 color) {
|
|
@@ -1403,11 +1463,11 @@ void picking_setPickingAttribute(vec3 value) {
|
|
|
1403
1463
|
picking_vRGBcolor_Avalid.rgb = value;
|
|
1404
1464
|
}
|
|
1405
1465
|
}
|
|
1406
|
-
`,
|
|
1466
|
+
`,Co=`layout(std140) uniform pickingUniforms {
|
|
1407
1467
|
float isActive;
|
|
1408
1468
|
float isAttribute;
|
|
1409
1469
|
float isHighlightActive;
|
|
1410
|
-
float
|
|
1470
|
+
float useByteColors;
|
|
1411
1471
|
vec3 highlightedObjectColor;
|
|
1412
1472
|
vec4 highlightColor;
|
|
1413
1473
|
} picking;
|
|
@@ -1459,9 +1519,9 @@ vec4 picking_filterColor(vec4 color) {
|
|
|
1459
1519
|
vec4 highlightColor = picking_filterHighlightColor(color);
|
|
1460
1520
|
return picking_filterPickingColor(highlightColor);
|
|
1461
1521
|
}
|
|
1462
|
-
`,
|
|
1522
|
+
`,Nr={props:{},uniforms:{},name:"picking",uniformTypes:{isActive:"f32",isAttribute:"f32",isHighlightActive:"f32",useByteColors:"f32",highlightedObjectColor:"vec3<f32>",highlightColor:"vec4<f32>"},defaultUniforms:{isActive:!1,isAttribute:!1,isHighlightActive:!1,useByteColors:!0,highlightedObjectColor:[0,0,0],highlightColor:Ro},vs:Eo,fs:Co,getUniforms:Io};function Io(e={},t){let r={},n=V(e.useByteColors,!0);if(e.highlightedObjectColor!==void 0)if(e.highlightedObjectColor===null)r.isHighlightActive=!1;else{r.isHighlightActive=!0;let o=e.highlightedObjectColor.slice(0,3);r.highlightedObjectColor=o}return e.highlightColor&&(r.highlightColor=Ne(e.highlightColor,n)),e.isActive!==void 0&&(r.isActive=Boolean(e.isActive),r.isAttribute=Boolean(e.isAttribute)),e.useByteColors!==void 0&&(r.useByteColors=Boolean(e.useByteColors)),r}var le=20,yo=`
|
|
1463
1523
|
struct skinUniforms {
|
|
1464
|
-
jointMatrix: array<mat4x4<f32>, ${
|
|
1524
|
+
jointMatrix: array<mat4x4<f32>, ${le}>,
|
|
1465
1525
|
};
|
|
1466
1526
|
|
|
1467
1527
|
@group(0) @binding(auto) var<uniform> skin: skinUniforms;
|
|
@@ -1472,8 +1532,8 @@ fn getSkinMatrix(weights: vec4f, joints: vec4u) -> mat4x4<f32> {
|
|
|
1472
1532
|
+ (weights.z * skin.jointMatrix[joints.z])
|
|
1473
1533
|
+ (weights.w * skin.jointMatrix[joints.w]);
|
|
1474
1534
|
}
|
|
1475
|
-
`,
|
|
1476
|
-
uniform skinUniforms {
|
|
1535
|
+
`,No=`
|
|
1536
|
+
layout(std140) uniform skinUniforms {
|
|
1477
1537
|
mat4 jointMatrix[SKIN_MAX_JOINTS];
|
|
1478
1538
|
} skin;
|
|
1479
1539
|
|
|
@@ -1484,7 +1544,7 @@ mat4 getSkinMatrix(vec4 weights, uvec4 joints) {
|
|
|
1484
1544
|
+ (weights.w * skin.jointMatrix[joints.w]);
|
|
1485
1545
|
}
|
|
1486
1546
|
|
|
1487
|
-
`,
|
|
1547
|
+
`,Po="",Pr={props:{},uniforms:{},name:"skin",bindingLayout:[{name:"skin",group:0}],dependencies:[],source:yo,vs:No,fs:Po,defines:{SKIN_MAX_JOINTS:le},getUniforms:(e={},t)=>{let{scenegraphsFromGLTF:r}=e;if(!r?.gltf?.skins?.[0])return{jointMatrix:[]};let{inverseBindMatrices:n,joints:o,skeleton:i}=r.gltf.skins[0],a=[],s=n.value.length/16;for(let p=0;p<s;p++){let u=n.value.subarray(p*16,p*16+16);a.push(new D(Array.from(u)))}let l=r.gltfNodeIndexToNodeMap.get(i),c={};l.preorderTraversal((p,{worldMatrix:u})=>{c[p.id]=u});let f=new Float32Array(le*16);for(let p=0;p<le;++p){let u=o[p];if(u===void 0)break;let h=c[r.gltfNodeIndexToNodeMap.get(u).id],g=a[p],S=new D().copy(h).multiplyRight(g),x=p*16;for(let _=0;_<16;_++)f[x+_]=S[_]}return{jointMatrix:f}},uniformTypes:{jointMatrix:["mat4x4<f32>",le]}};var Or=pt(Be(),1);var at=`precision highp int;
|
|
1488
1548
|
|
|
1489
1549
|
// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
1490
1550
|
struct AmbientLight {
|
|
@@ -1518,7 +1578,7 @@ struct UniformLight {
|
|
|
1518
1578
|
vec2 coneCos;
|
|
1519
1579
|
};
|
|
1520
1580
|
|
|
1521
|
-
uniform lightingUniforms {
|
|
1581
|
+
layout(std140) uniform lightingUniforms {
|
|
1522
1582
|
int enabled;
|
|
1523
1583
|
int directionalLightCount;
|
|
1524
1584
|
int pointLightCount;
|
|
@@ -1564,7 +1624,7 @@ float getSpotLightAttenuation(SpotLight spotLight, vec3 positionWorldspace) {
|
|
|
1564
1624
|
}
|
|
1565
1625
|
|
|
1566
1626
|
// #endif
|
|
1567
|
-
`;var
|
|
1627
|
+
`;var Tr=`// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
1568
1628
|
const MAX_LIGHTS: i32 = 5;
|
|
1569
1629
|
|
|
1570
1630
|
struct AmbientLight {
|
|
@@ -1643,7 +1703,7 @@ fn getSpotLightAttenuation(spotLight: SpotLight, positionWorldspace: vec3<f32>)
|
|
|
1643
1703
|
);
|
|
1644
1704
|
return distanceAttenuation / max(coneFactor, 0.0001);
|
|
1645
1705
|
}
|
|
1646
|
-
`;var
|
|
1706
|
+
`;var $=5,To={color:"vec3<f32>",position:"vec3<f32>",direction:"vec3<f32>",attenuation:"vec3<f32>",coneCos:"vec2<f32>"},B={props:{},uniforms:{},name:"lighting",defines:{},uniformTypes:{enabled:"i32",directionalLightCount:"i32",pointLightCount:"i32",spotLightCount:"i32",ambientColor:"vec3<f32>",lights:[To,$]},defaultUniforms:Te(),bindingLayout:[{name:"lighting",group:2}],firstBindingSlot:0,source:Tr,vs:at,fs:at,getUniforms:Oo};function Oo(e,t={}){if(e=e&&{...e},!e)return Te();e.lights&&(e={...e,...Fo(e.lights),lights:void 0});let{useByteColors:r,ambientLight:n,pointLights:o,spotLights:i,directionalLights:a}=e||{};if(!(n||o&&o.length>0||i&&i.length>0||a&&a.length>0))return{...Te(),enabled:0};let l={...Te(),...Uo({useByteColors:r,ambientLight:n,pointLights:o,spotLights:i,directionalLights:a})};return e.enabled!==void 0&&(l.enabled=e.enabled?1:0),l}function Uo({useByteColors:e,ambientLight:t,pointLights:r=[],spotLights:n=[],directionalLights:o=[]}){let i=Ur(),a=0,s=0,l=0,c=0;for(let f of r){if(a>=$)break;i[a]={...i[a],color:Pe(f,e),position:f.position,attenuation:f.attenuation||[1,0,0]},a++,s++}for(let f of n){if(a>=$)break;i[a]={...i[a],color:Pe(f,e),position:f.position,direction:f.direction,attenuation:f.attenuation||[1,0,0],coneCos:Bo(f)},a++,l++}for(let f of o){if(a>=$)break;i[a]={...i[a],color:Pe(f,e),direction:f.direction},a++,c++}return r.length+n.length+o.length>$&&Or.log.warn(`MAX_LIGHTS exceeded, truncating to ${$}`)(),{ambientColor:Pe(t,e),directionalLightCount:c,pointLightCount:s,spotLightCount:l,lights:i}}function Fo(e){let t={pointLights:[],spotLights:[],directionalLights:[]};for(let r of e||[])switch(r.type){case"ambient":t.ambientLight=r;break;case"directional":t.directionalLights?.push(r);break;case"point":t.pointLights?.push(r);break;case"spot":t.spotLights?.push(r);break;default:}return t}function Pe(e={},t){let{color:r=[0,0,0],intensity:n=1}=e;return k(r,V(t,!0)).map(i=>i*n)}function Te(){return{enabled:1,directionalLightCount:0,pointLightCount:0,spotLightCount:0,ambientColor:[.1,.1,.1],lights:Ur()}}function Ur(){return Array.from({length:$},()=>Vo())}function Vo(){return{color:[1,1,1],position:[1,1,2],direction:[1,1,1],attenuation:[1,0,0],coneCos:[1,0]}}function Bo(e){let t=e.innerConeAngle??0,r=e.outerConeAngle??Math.PI/4;return[Math.cos(t),Math.cos(r)]}var wo=`#ifdef USE_IBL
|
|
1647
1707
|
@group(2) @binding(auto) var pbr_diffuseEnvSampler: texture_cube<f32>;
|
|
1648
1708
|
@group(2) @binding(auto) var pbr_diffuseEnvSamplerSampler: sampler;
|
|
1649
1709
|
@group(2) @binding(auto) var pbr_specularEnvSampler: texture_cube<f32>;
|
|
@@ -1651,13 +1711,12 @@ fn getSpotLightAttenuation(spotLight: SpotLight, positionWorldspace: vec3<f32>)
|
|
|
1651
1711
|
@group(2) @binding(auto) var pbr_brdfLUT: texture_2d<f32>;
|
|
1652
1712
|
@group(2) @binding(auto) var pbr_brdfLUTSampler: sampler;
|
|
1653
1713
|
#endif
|
|
1654
|
-
`,
|
|
1714
|
+
`,Fr=`#ifdef USE_IBL
|
|
1655
1715
|
uniform samplerCube pbr_diffuseEnvSampler;
|
|
1656
1716
|
uniform samplerCube pbr_specularEnvSampler;
|
|
1657
1717
|
uniform sampler2D pbr_brdfLUT;
|
|
1658
1718
|
#endif
|
|
1659
|
-
`,
|
|
1660
|
-
struct dirlightUniforms {
|
|
1719
|
+
`,Oe={name:"ibl",firstBindingSlot:32,bindingLayout:[{name:"pbr_diffuseEnvSampler",group:2},{name:"pbr_specularEnvSampler",group:2},{name:"pbr_brdfLUT",group:2}],source:wo,vs:Fr,fs:Fr};var ko=`struct dirlightUniforms {
|
|
1661
1720
|
lightDirection: vec3<f32>,
|
|
1662
1721
|
};
|
|
1663
1722
|
|
|
@@ -1682,12 +1741,12 @@ fn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {
|
|
|
1682
1741
|
let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));
|
|
1683
1742
|
return vec4<f32>(color.rgb * d, color.a);
|
|
1684
1743
|
}
|
|
1685
|
-
`,
|
|
1744
|
+
`,Do=`out vec3 dirlight_vNormal;
|
|
1686
1745
|
|
|
1687
1746
|
void dirlight_setNormal(vec3 normal) {
|
|
1688
1747
|
dirlight_vNormal = normalize(normal);
|
|
1689
1748
|
}
|
|
1690
|
-
`,
|
|
1749
|
+
`,zo=`layout(std140) uniform dirlightUniforms {
|
|
1691
1750
|
vec3 lightDirection;
|
|
1692
1751
|
} dirlight;
|
|
1693
1752
|
|
|
@@ -1698,7 +1757,7 @@ vec4 dirlight_filterColor(vec4 color) {
|
|
|
1698
1757
|
float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
|
|
1699
1758
|
return vec4(color.rgb * d, color.a);
|
|
1700
1759
|
}
|
|
1701
|
-
`,
|
|
1760
|
+
`,st={props:{},uniforms:{},name:"dirlight",bindingLayout:[{name:"dirlight",group:2}],firstBindingSlot:16,dependencies:[],source:ko,vs:Do,fs:zo,uniformTypes:{lightDirection:"vec3<f32>"},defaultUniforms:{lightDirection:[1,1,2]},getUniforms:Go};function Go(e=st.defaultUniforms){let t={};return e.lightDirection&&(t.lightDirection=e.lightDirection),t}var Vr=`struct lambertMaterialUniforms {
|
|
1702
1761
|
unlit: u32,
|
|
1703
1762
|
ambient: f32,
|
|
1704
1763
|
diffuse: f32,
|
|
@@ -1765,12 +1824,12 @@ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, p
|
|
|
1765
1824
|
|
|
1766
1825
|
return lightColor;
|
|
1767
1826
|
}
|
|
1768
|
-
`;var
|
|
1827
|
+
`;var Br=`layout(std140) uniform lambertMaterialUniforms {
|
|
1769
1828
|
uniform bool unlit;
|
|
1770
1829
|
uniform float ambient;
|
|
1771
1830
|
uniform float diffuse;
|
|
1772
1831
|
} material;
|
|
1773
|
-
`,
|
|
1832
|
+
`,wr=`layout(std140) uniform lambertMaterialUniforms {
|
|
1774
1833
|
uniform bool unlit;
|
|
1775
1834
|
uniform float ambient;
|
|
1776
1835
|
uniform float diffuse;
|
|
@@ -1817,14 +1876,14 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
|
|
|
1817
1876
|
|
|
1818
1877
|
return lightColor;
|
|
1819
1878
|
}
|
|
1820
|
-
`;var
|
|
1879
|
+
`;var lt={name:"lambertMaterial",firstBindingSlot:0,bindingLayout:[{name:"lambertMaterial",group:3}],dependencies:[B],source:Vr,vs:Br,fs:wr,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{unlit:"i32",ambient:"f32",diffuse:"f32"},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6},getUniforms(e){return{...lt.defaultUniforms,...e}}};var Ue=`layout(std140) uniform phongMaterialUniforms {
|
|
1821
1880
|
uniform bool unlit;
|
|
1822
1881
|
uniform float ambient;
|
|
1823
1882
|
uniform float diffuse;
|
|
1824
1883
|
uniform float shininess;
|
|
1825
1884
|
uniform vec3 specularColor;
|
|
1826
1885
|
} material;
|
|
1827
|
-
`,
|
|
1886
|
+
`,Fe=`layout(std140) uniform phongMaterialUniforms {
|
|
1828
1887
|
uniform bool unlit;
|
|
1829
1888
|
uniform float ambient;
|
|
1830
1889
|
uniform float diffuse;
|
|
@@ -1881,7 +1940,7 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
|
|
|
1881
1940
|
|
|
1882
1941
|
return lightColor;
|
|
1883
1942
|
}
|
|
1884
|
-
`;var
|
|
1943
|
+
`;var Ve=`struct phongMaterialUniforms {
|
|
1885
1944
|
unlit: u32,
|
|
1886
1945
|
ambient: f32,
|
|
1887
1946
|
diffuse: f32,
|
|
@@ -2001,8 +2060,9 @@ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace
|
|
|
2001
2060
|
}
|
|
2002
2061
|
return lightColor;
|
|
2003
2062
|
}
|
|
2004
|
-
`;var
|
|
2005
|
-
out vec2
|
|
2063
|
+
`;var ct={props:{},name:"gouraudMaterial",bindingLayout:[{name:"gouraudMaterial",group:3}],vs:Fe.replace("phongMaterial","gouraudMaterial"),fs:Ue.replace("phongMaterial","gouraudMaterial"),source:Ve.replaceAll("phongMaterial","gouraudMaterial"),defines:{LIGHTING_VERTEX:!0},dependencies:[B],uniformTypes:{unlit:"i32",ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>",useByteColors:"i32"},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15],useByteColors:!0},getUniforms(e){let t={...e};return t.specularColor&&(t.specularColor=k(t.specularColor,V(t.useByteColors,!0))),{...ct.defaultUniforms,...t}}};var ft={name:"phongMaterial",firstBindingSlot:0,bindingLayout:[{name:"phongMaterial",group:3}],dependencies:[B],source:Ve,vs:Ue,fs:Fe,defines:{LIGHTING_FRAGMENT:!0},uniformTypes:{unlit:"i32",ambient:"f32",diffuse:"f32",shininess:"f32",specularColor:"vec3<f32>",useByteColors:"i32"},defaultUniforms:{unlit:!1,ambient:.35,diffuse:.6,shininess:32,specularColor:[.15,.15,.15],useByteColors:!0},getUniforms(e){let t={...e};return t.specularColor&&(t.specularColor=k(t.specularColor,V(t.useByteColors,!0))),{...ft.defaultUniforms,...t}}};var kr=`out vec3 pbr_vPosition;
|
|
2064
|
+
out vec2 pbr_vUV0;
|
|
2065
|
+
out vec2 pbr_vUV1;
|
|
2006
2066
|
|
|
2007
2067
|
#ifdef HAS_NORMALS
|
|
2008
2068
|
# ifdef HAS_TANGENTS
|
|
@@ -2012,7 +2072,13 @@ out vec3 pbr_vNormal;
|
|
|
2012
2072
|
# endif
|
|
2013
2073
|
#endif
|
|
2014
2074
|
|
|
2015
|
-
void pbr_setPositionNormalTangentUV(
|
|
2075
|
+
void pbr_setPositionNormalTangentUV(
|
|
2076
|
+
vec4 position,
|
|
2077
|
+
vec4 normal,
|
|
2078
|
+
vec4 tangent,
|
|
2079
|
+
vec2 uv0,
|
|
2080
|
+
vec2 uv1
|
|
2081
|
+
)
|
|
2016
2082
|
{
|
|
2017
2083
|
vec4 pos = pbrProjection.modelMatrix * position;
|
|
2018
2084
|
pbr_vPosition = vec3(pos.xyz) / pos.w;
|
|
@@ -2029,14 +2095,16 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
|
|
|
2029
2095
|
#endif
|
|
2030
2096
|
|
|
2031
2097
|
#ifdef HAS_UV
|
|
2032
|
-
|
|
2098
|
+
pbr_vUV0 = uv0;
|
|
2033
2099
|
#else
|
|
2034
|
-
|
|
2100
|
+
pbr_vUV0 = vec2(0.,0.);
|
|
2035
2101
|
#endif
|
|
2102
|
+
|
|
2103
|
+
pbr_vUV1 = uv1;
|
|
2036
2104
|
}
|
|
2037
|
-
`,
|
|
2105
|
+
`,Dr=`precision highp float;
|
|
2038
2106
|
|
|
2039
|
-
uniform pbrMaterialUniforms {
|
|
2107
|
+
layout(std140) uniform pbrMaterialUniforms {
|
|
2040
2108
|
// Material is unlit
|
|
2041
2109
|
bool unlit;
|
|
2042
2110
|
|
|
@@ -2104,6 +2172,41 @@ uniform pbrMaterialUniforms {
|
|
|
2104
2172
|
vec4 scaleDiffBaseMR;
|
|
2105
2173
|
vec4 scaleFGDSpec;
|
|
2106
2174
|
// #endif
|
|
2175
|
+
|
|
2176
|
+
int baseColorUVSet;
|
|
2177
|
+
mat3 baseColorUVTransform;
|
|
2178
|
+
int metallicRoughnessUVSet;
|
|
2179
|
+
mat3 metallicRoughnessUVTransform;
|
|
2180
|
+
int normalUVSet;
|
|
2181
|
+
mat3 normalUVTransform;
|
|
2182
|
+
int occlusionUVSet;
|
|
2183
|
+
mat3 occlusionUVTransform;
|
|
2184
|
+
int emissiveUVSet;
|
|
2185
|
+
mat3 emissiveUVTransform;
|
|
2186
|
+
int specularColorUVSet;
|
|
2187
|
+
mat3 specularColorUVTransform;
|
|
2188
|
+
int specularIntensityUVSet;
|
|
2189
|
+
mat3 specularIntensityUVTransform;
|
|
2190
|
+
int transmissionUVSet;
|
|
2191
|
+
mat3 transmissionUVTransform;
|
|
2192
|
+
int thicknessUVSet;
|
|
2193
|
+
mat3 thicknessUVTransform;
|
|
2194
|
+
int clearcoatUVSet;
|
|
2195
|
+
mat3 clearcoatUVTransform;
|
|
2196
|
+
int clearcoatRoughnessUVSet;
|
|
2197
|
+
mat3 clearcoatRoughnessUVTransform;
|
|
2198
|
+
int clearcoatNormalUVSet;
|
|
2199
|
+
mat3 clearcoatNormalUVTransform;
|
|
2200
|
+
int sheenColorUVSet;
|
|
2201
|
+
mat3 sheenColorUVTransform;
|
|
2202
|
+
int sheenRoughnessUVSet;
|
|
2203
|
+
mat3 sheenRoughnessUVTransform;
|
|
2204
|
+
int iridescenceUVSet;
|
|
2205
|
+
mat3 iridescenceUVTransform;
|
|
2206
|
+
int iridescenceThicknessUVSet;
|
|
2207
|
+
mat3 iridescenceThicknessUVTransform;
|
|
2208
|
+
int anisotropyUVSet;
|
|
2209
|
+
mat3 anisotropyUVTransform;
|
|
2107
2210
|
} pbrMaterial;
|
|
2108
2211
|
|
|
2109
2212
|
// Samplers
|
|
@@ -2161,7 +2264,8 @@ uniform sampler2D pbr_anisotropySampler;
|
|
|
2161
2264
|
// Inputs from vertex shader
|
|
2162
2265
|
|
|
2163
2266
|
in vec3 pbr_vPosition;
|
|
2164
|
-
in vec2
|
|
2267
|
+
in vec2 pbr_vUV0;
|
|
2268
|
+
in vec2 pbr_vUV1;
|
|
2165
2269
|
|
|
2166
2270
|
#ifdef HAS_NORMALS
|
|
2167
2271
|
#ifdef HAS_TANGENTS
|
|
@@ -2211,14 +2315,20 @@ vec4 SRGBtoLINEAR(vec4 srgbIn)
|
|
|
2211
2315
|
#endif //MANUAL_SRGB
|
|
2212
2316
|
}
|
|
2213
2317
|
|
|
2318
|
+
vec2 getMaterialUV(int uvSet, mat3 uvTransform)
|
|
2319
|
+
{
|
|
2320
|
+
vec2 baseUV = uvSet == 1 ? pbr_vUV1 : pbr_vUV0;
|
|
2321
|
+
return (uvTransform * vec3(baseUV, 1.0)).xy;
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2214
2324
|
// Build the tangent basis from interpolated attributes or screen-space derivatives.
|
|
2215
|
-
mat3 getTBN()
|
|
2325
|
+
mat3 getTBN(vec2 uv)
|
|
2216
2326
|
{
|
|
2217
2327
|
#ifndef HAS_TANGENTS
|
|
2218
2328
|
vec3 pos_dx = dFdx(pbr_vPosition);
|
|
2219
2329
|
vec3 pos_dy = dFdy(pbr_vPosition);
|
|
2220
|
-
vec3 tex_dx = dFdx(vec3(
|
|
2221
|
-
vec3 tex_dy = dFdy(vec3(
|
|
2330
|
+
vec3 tex_dx = dFdx(vec3(uv, 0.0));
|
|
2331
|
+
vec3 tex_dy = dFdy(vec3(uv, 0.0));
|
|
2222
2332
|
vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
|
|
2223
2333
|
|
|
2224
2334
|
#ifdef HAS_NORMALS
|
|
@@ -2239,16 +2349,16 @@ mat3 getTBN()
|
|
|
2239
2349
|
|
|
2240
2350
|
// Find the normal for this fragment, pulling either from a predefined normal map
|
|
2241
2351
|
// or from the interpolated mesh normal and tangent attributes.
|
|
2242
|
-
vec3 getMappedNormal(sampler2D normalSampler, mat3 tbn, float normalScale)
|
|
2352
|
+
vec3 getMappedNormal(sampler2D normalSampler, mat3 tbn, float normalScale, vec2 uv)
|
|
2243
2353
|
{
|
|
2244
|
-
vec3 n = texture(normalSampler,
|
|
2354
|
+
vec3 n = texture(normalSampler, uv).rgb;
|
|
2245
2355
|
return normalize(tbn * ((2.0 * n - 1.0) * vec3(normalScale, normalScale, 1.0)));
|
|
2246
2356
|
}
|
|
2247
2357
|
|
|
2248
|
-
vec3 getNormal(mat3 tbn)
|
|
2358
|
+
vec3 getNormal(mat3 tbn, vec2 uv)
|
|
2249
2359
|
{
|
|
2250
2360
|
#ifdef HAS_NORMALMAP
|
|
2251
|
-
vec3 n = getMappedNormal(pbr_normalSampler, tbn, pbrMaterial.normalScale);
|
|
2361
|
+
vec3 n = getMappedNormal(pbr_normalSampler, tbn, pbrMaterial.normalScale, uv);
|
|
2252
2362
|
#else
|
|
2253
2363
|
// The tbn matrix is linearly interpolated, so we need to re-normalize
|
|
2254
2364
|
vec3 n = normalize(tbn[2].xyz);
|
|
@@ -2257,10 +2367,10 @@ vec3 getNormal(mat3 tbn)
|
|
|
2257
2367
|
return n;
|
|
2258
2368
|
}
|
|
2259
2369
|
|
|
2260
|
-
vec3 getClearcoatNormal(mat3 tbn, vec3 baseNormal)
|
|
2370
|
+
vec3 getClearcoatNormal(mat3 tbn, vec3 baseNormal, vec2 uv)
|
|
2261
2371
|
{
|
|
2262
2372
|
#ifdef HAS_CLEARCOATNORMALMAP
|
|
2263
|
-
return getMappedNormal(pbr_clearcoatNormalSampler, tbn, 1.0);
|
|
2373
|
+
return getMappedNormal(pbr_clearcoatNormalSampler, tbn, 1.0, uv);
|
|
2264
2374
|
#else
|
|
2265
2375
|
return baseNormal;
|
|
2266
2376
|
#endif
|
|
@@ -2548,9 +2658,61 @@ vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {
|
|
|
2548
2658
|
|
|
2549
2659
|
vec4 pbr_filterColor(vec4 colorUnused)
|
|
2550
2660
|
{
|
|
2661
|
+
vec2 baseColorUV = getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform);
|
|
2662
|
+
vec2 metallicRoughnessUV = getMaterialUV(
|
|
2663
|
+
pbrMaterial.metallicRoughnessUVSet,
|
|
2664
|
+
pbrMaterial.metallicRoughnessUVTransform
|
|
2665
|
+
);
|
|
2666
|
+
vec2 normalUV = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
|
|
2667
|
+
vec2 occlusionUV = getMaterialUV(pbrMaterial.occlusionUVSet, pbrMaterial.occlusionUVTransform);
|
|
2668
|
+
vec2 emissiveUV = getMaterialUV(pbrMaterial.emissiveUVSet, pbrMaterial.emissiveUVTransform);
|
|
2669
|
+
vec2 specularColorUV = getMaterialUV(
|
|
2670
|
+
pbrMaterial.specularColorUVSet,
|
|
2671
|
+
pbrMaterial.specularColorUVTransform
|
|
2672
|
+
);
|
|
2673
|
+
vec2 specularIntensityUV = getMaterialUV(
|
|
2674
|
+
pbrMaterial.specularIntensityUVSet,
|
|
2675
|
+
pbrMaterial.specularIntensityUVTransform
|
|
2676
|
+
);
|
|
2677
|
+
vec2 transmissionUV = getMaterialUV(
|
|
2678
|
+
pbrMaterial.transmissionUVSet,
|
|
2679
|
+
pbrMaterial.transmissionUVTransform
|
|
2680
|
+
);
|
|
2681
|
+
vec2 thicknessUV = getMaterialUV(pbrMaterial.thicknessUVSet, pbrMaterial.thicknessUVTransform);
|
|
2682
|
+
vec2 clearcoatUV = getMaterialUV(pbrMaterial.clearcoatUVSet, pbrMaterial.clearcoatUVTransform);
|
|
2683
|
+
vec2 clearcoatRoughnessUV = getMaterialUV(
|
|
2684
|
+
pbrMaterial.clearcoatRoughnessUVSet,
|
|
2685
|
+
pbrMaterial.clearcoatRoughnessUVTransform
|
|
2686
|
+
);
|
|
2687
|
+
vec2 clearcoatNormalUV = getMaterialUV(
|
|
2688
|
+
pbrMaterial.clearcoatNormalUVSet,
|
|
2689
|
+
pbrMaterial.clearcoatNormalUVTransform
|
|
2690
|
+
);
|
|
2691
|
+
vec2 sheenColorUV = getMaterialUV(
|
|
2692
|
+
pbrMaterial.sheenColorUVSet,
|
|
2693
|
+
pbrMaterial.sheenColorUVTransform
|
|
2694
|
+
);
|
|
2695
|
+
vec2 sheenRoughnessUV = getMaterialUV(
|
|
2696
|
+
pbrMaterial.sheenRoughnessUVSet,
|
|
2697
|
+
pbrMaterial.sheenRoughnessUVTransform
|
|
2698
|
+
);
|
|
2699
|
+
vec2 iridescenceUV = getMaterialUV(
|
|
2700
|
+
pbrMaterial.iridescenceUVSet,
|
|
2701
|
+
pbrMaterial.iridescenceUVTransform
|
|
2702
|
+
);
|
|
2703
|
+
vec2 iridescenceThicknessUV = getMaterialUV(
|
|
2704
|
+
pbrMaterial.iridescenceThicknessUVSet,
|
|
2705
|
+
pbrMaterial.iridescenceThicknessUVTransform
|
|
2706
|
+
);
|
|
2707
|
+
vec2 anisotropyUV = getMaterialUV(
|
|
2708
|
+
pbrMaterial.anisotropyUVSet,
|
|
2709
|
+
pbrMaterial.anisotropyUVTransform
|
|
2710
|
+
);
|
|
2711
|
+
|
|
2551
2712
|
// The albedo may be defined from a base texture or a flat color
|
|
2552
2713
|
#ifdef HAS_BASECOLORMAP
|
|
2553
|
-
vec4 baseColor =
|
|
2714
|
+
vec4 baseColor =
|
|
2715
|
+
SRGBtoLINEAR(texture(pbr_baseColorSampler, baseColorUV)) * pbrMaterial.baseColorFactor;
|
|
2554
2716
|
#else
|
|
2555
2717
|
vec4 baseColor = pbrMaterial.baseColorFactor;
|
|
2556
2718
|
#endif
|
|
@@ -2577,14 +2739,14 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2577
2739
|
#ifdef HAS_METALROUGHNESSMAP
|
|
2578
2740
|
// Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
|
|
2579
2741
|
// This layout intentionally reserves the 'r' channel for (optional) occlusion map data
|
|
2580
|
-
vec4 mrSample = texture(pbr_metallicRoughnessSampler,
|
|
2742
|
+
vec4 mrSample = texture(pbr_metallicRoughnessSampler, metallicRoughnessUV);
|
|
2581
2743
|
perceptualRoughness = mrSample.g * perceptualRoughness;
|
|
2582
2744
|
metallic = mrSample.b * metallic;
|
|
2583
2745
|
#endif
|
|
2584
2746
|
perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
|
|
2585
2747
|
metallic = clamp(metallic, 0.0, 1.0);
|
|
2586
|
-
mat3 tbn = getTBN();
|
|
2587
|
-
vec3 n = getNormal(tbn); // normal at surface point
|
|
2748
|
+
mat3 tbn = getTBN(normalUV);
|
|
2749
|
+
vec3 n = getNormal(tbn, normalUV); // normal at surface point
|
|
2588
2750
|
vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
|
|
2589
2751
|
float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
|
|
2590
2752
|
#ifdef USE_MATERIAL_EXTENSIONS
|
|
@@ -2685,7 +2847,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2685
2847
|
|
|
2686
2848
|
#ifdef HAS_OCCLUSIONMAP
|
|
2687
2849
|
if (pbrMaterial.occlusionMapEnabled) {
|
|
2688
|
-
float ao = texture(pbr_occlusionSampler,
|
|
2850
|
+
float ao = texture(pbr_occlusionSampler, occlusionUV).r;
|
|
2689
2851
|
color = mix(color, color * ao, pbrMaterial.occlusionStrength);
|
|
2690
2852
|
}
|
|
2691
2853
|
#endif
|
|
@@ -2693,7 +2855,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2693
2855
|
vec3 emissive = pbrMaterial.emissiveFactor;
|
|
2694
2856
|
#ifdef HAS_EMISSIVEMAP
|
|
2695
2857
|
if (pbrMaterial.emissiveMapEnabled) {
|
|
2696
|
-
emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler,
|
|
2858
|
+
emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler, emissiveUV)).rgb;
|
|
2697
2859
|
}
|
|
2698
2860
|
#endif
|
|
2699
2861
|
color += emissive * pbrMaterial.emissiveStrength;
|
|
@@ -2710,55 +2872,55 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2710
2872
|
float specularIntensity = pbrMaterial.specularIntensityFactor;
|
|
2711
2873
|
#ifdef HAS_SPECULARINTENSITYMAP
|
|
2712
2874
|
if (pbrMaterial.specularIntensityMapEnabled) {
|
|
2713
|
-
specularIntensity *= texture(pbr_specularIntensitySampler,
|
|
2875
|
+
specularIntensity *= texture(pbr_specularIntensitySampler, specularIntensityUV).a;
|
|
2714
2876
|
}
|
|
2715
2877
|
#endif
|
|
2716
2878
|
|
|
2717
2879
|
vec3 specularFactor = pbrMaterial.specularColorFactor;
|
|
2718
2880
|
#ifdef HAS_SPECULARCOLORMAP
|
|
2719
2881
|
if (pbrMaterial.specularColorMapEnabled) {
|
|
2720
|
-
specularFactor *= SRGBtoLINEAR(texture(pbr_specularColorSampler,
|
|
2882
|
+
specularFactor *= SRGBtoLINEAR(texture(pbr_specularColorSampler, specularColorUV)).rgb;
|
|
2721
2883
|
}
|
|
2722
2884
|
#endif
|
|
2723
2885
|
|
|
2724
2886
|
transmission = pbrMaterial.transmissionFactor;
|
|
2725
2887
|
#ifdef HAS_TRANSMISSIONMAP
|
|
2726
2888
|
if (pbrMaterial.transmissionMapEnabled) {
|
|
2727
|
-
transmission *= texture(pbr_transmissionSampler,
|
|
2889
|
+
transmission *= texture(pbr_transmissionSampler, transmissionUV).r;
|
|
2728
2890
|
}
|
|
2729
2891
|
#endif
|
|
2730
2892
|
transmission = clamp(transmission * (1.0 - metallic), 0.0, 1.0);
|
|
2731
2893
|
float thickness = max(pbrMaterial.thicknessFactor, 0.0);
|
|
2732
2894
|
#ifdef HAS_THICKNESSMAP
|
|
2733
|
-
thickness *= texture(pbr_thicknessSampler,
|
|
2895
|
+
thickness *= texture(pbr_thicknessSampler, thicknessUV).g;
|
|
2734
2896
|
#endif
|
|
2735
2897
|
|
|
2736
2898
|
float clearcoatFactor = pbrMaterial.clearcoatFactor;
|
|
2737
2899
|
float clearcoatRoughness = pbrMaterial.clearcoatRoughnessFactor;
|
|
2738
2900
|
#ifdef HAS_CLEARCOATMAP
|
|
2739
2901
|
if (pbrMaterial.clearcoatMapEnabled) {
|
|
2740
|
-
clearcoatFactor *= texture(pbr_clearcoatSampler,
|
|
2902
|
+
clearcoatFactor *= texture(pbr_clearcoatSampler, clearcoatUV).r;
|
|
2741
2903
|
}
|
|
2742
2904
|
#endif
|
|
2743
2905
|
#ifdef HAS_CLEARCOATROUGHNESSMAP
|
|
2744
2906
|
if (pbrMaterial.clearcoatRoughnessMapEnabled) {
|
|
2745
|
-
clearcoatRoughness *= texture(pbr_clearcoatRoughnessSampler,
|
|
2907
|
+
clearcoatRoughness *= texture(pbr_clearcoatRoughnessSampler, clearcoatRoughnessUV).g;
|
|
2746
2908
|
}
|
|
2747
2909
|
#endif
|
|
2748
2910
|
clearcoatFactor = clamp(clearcoatFactor, 0.0, 1.0);
|
|
2749
2911
|
clearcoatRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);
|
|
2750
|
-
vec3 clearcoatNormal = getClearcoatNormal(
|
|
2912
|
+
vec3 clearcoatNormal = getClearcoatNormal(getTBN(clearcoatNormalUV), n, clearcoatNormalUV);
|
|
2751
2913
|
|
|
2752
2914
|
vec3 sheenColor = pbrMaterial.sheenColorFactor;
|
|
2753
2915
|
float sheenRoughness = pbrMaterial.sheenRoughnessFactor;
|
|
2754
2916
|
#ifdef HAS_SHEENCOLORMAP
|
|
2755
2917
|
if (pbrMaterial.sheenColorMapEnabled) {
|
|
2756
|
-
sheenColor *= SRGBtoLINEAR(texture(pbr_sheenColorSampler,
|
|
2918
|
+
sheenColor *= SRGBtoLINEAR(texture(pbr_sheenColorSampler, sheenColorUV)).rgb;
|
|
2757
2919
|
}
|
|
2758
2920
|
#endif
|
|
2759
2921
|
#ifdef HAS_SHEENROUGHNESSMAP
|
|
2760
2922
|
if (pbrMaterial.sheenRoughnessMapEnabled) {
|
|
2761
|
-
sheenRoughness *= texture(pbr_sheenRoughnessSampler,
|
|
2923
|
+
sheenRoughness *= texture(pbr_sheenRoughnessSampler, sheenRoughnessUV).a;
|
|
2762
2924
|
}
|
|
2763
2925
|
#endif
|
|
2764
2926
|
sheenRoughness = clamp(sheenRoughness, c_MinRoughness, 1.0);
|
|
@@ -2766,7 +2928,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2766
2928
|
float iridescence = pbrMaterial.iridescenceFactor;
|
|
2767
2929
|
#ifdef HAS_IRIDESCENCEMAP
|
|
2768
2930
|
if (pbrMaterial.iridescenceMapEnabled) {
|
|
2769
|
-
iridescence *= texture(pbr_iridescenceSampler,
|
|
2931
|
+
iridescence *= texture(pbr_iridescenceSampler, iridescenceUV).r;
|
|
2770
2932
|
}
|
|
2771
2933
|
#endif
|
|
2772
2934
|
iridescence = clamp(iridescence, 0.0, 1.0);
|
|
@@ -2779,7 +2941,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2779
2941
|
iridescenceThickness = mix(
|
|
2780
2942
|
pbrMaterial.iridescenceThicknessRange.x,
|
|
2781
2943
|
pbrMaterial.iridescenceThicknessRange.y,
|
|
2782
|
-
texture(pbr_iridescenceThicknessSampler,
|
|
2944
|
+
texture(pbr_iridescenceThicknessSampler, iridescenceThicknessUV).g
|
|
2783
2945
|
);
|
|
2784
2946
|
#endif
|
|
2785
2947
|
|
|
@@ -2787,7 +2949,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2787
2949
|
vec2 anisotropyDirection = normalizeDirection(pbrMaterial.anisotropyDirection);
|
|
2788
2950
|
#ifdef HAS_ANISOTROPYMAP
|
|
2789
2951
|
if (pbrMaterial.anisotropyMapEnabled) {
|
|
2790
|
-
vec3 anisotropySample = texture(pbr_anisotropySampler,
|
|
2952
|
+
vec3 anisotropySample = texture(pbr_anisotropySampler, anisotropyUV).rgb;
|
|
2791
2953
|
anisotropyStrength *= anisotropySample.b;
|
|
2792
2954
|
vec2 mappedDirection = anisotropySample.rg * 2.0 - 1.0;
|
|
2793
2955
|
if (length(mappedDirection) > 0.0001) {
|
|
@@ -2950,7 +3112,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2950
3112
|
// Apply optional PBR terms for additional (optional) shading
|
|
2951
3113
|
#ifdef HAS_OCCLUSIONMAP
|
|
2952
3114
|
if (pbrMaterial.occlusionMapEnabled) {
|
|
2953
|
-
float ao = texture(pbr_occlusionSampler,
|
|
3115
|
+
float ao = texture(pbr_occlusionSampler, occlusionUV).r;
|
|
2954
3116
|
color = mix(color, color * ao, pbrMaterial.occlusionStrength);
|
|
2955
3117
|
}
|
|
2956
3118
|
#endif
|
|
@@ -2958,7 +3120,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2958
3120
|
vec3 emissive = pbrMaterial.emissiveFactor;
|
|
2959
3121
|
#ifdef HAS_EMISSIVEMAP
|
|
2960
3122
|
if (pbrMaterial.emissiveMapEnabled) {
|
|
2961
|
-
emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler,
|
|
3123
|
+
emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler, emissiveUV)).rgb;
|
|
2962
3124
|
}
|
|
2963
3125
|
#endif
|
|
2964
3126
|
color += emissive * pbrMaterial.emissiveStrength;
|
|
@@ -2988,16 +3150,23 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2988
3150
|
float alpha = clamp(baseColor.a * (1.0 - transmission), 0.0, 1.0);
|
|
2989
3151
|
return vec4(pow(color,vec3(1.0/2.2)), alpha);
|
|
2990
3152
|
}
|
|
2991
|
-
`;var
|
|
3153
|
+
`;var zr=`struct PBRFragmentInputs {
|
|
2992
3154
|
pbr_vPosition: vec3f,
|
|
2993
|
-
|
|
3155
|
+
pbr_vUV0: vec2f,
|
|
3156
|
+
pbr_vUV1: vec2f,
|
|
2994
3157
|
pbr_vTBN: mat3x3f,
|
|
2995
3158
|
pbr_vNormal: vec3f
|
|
2996
3159
|
};
|
|
2997
3160
|
|
|
2998
3161
|
var<private> fragmentInputs: PBRFragmentInputs;
|
|
2999
3162
|
|
|
3000
|
-
fn pbr_setPositionNormalTangentUV(
|
|
3163
|
+
fn pbr_setPositionNormalTangentUV(
|
|
3164
|
+
position: vec4f,
|
|
3165
|
+
normal: vec4f,
|
|
3166
|
+
tangent: vec4f,
|
|
3167
|
+
uv0: vec2f,
|
|
3168
|
+
uv1: vec2f
|
|
3169
|
+
)
|
|
3001
3170
|
{
|
|
3002
3171
|
var pos: vec4f = pbrProjection.modelMatrix * position;
|
|
3003
3172
|
fragmentInputs.pbr_vPosition = pos.xyz / pos.w;
|
|
@@ -3007,7 +3176,8 @@ fn pbr_setPositionNormalTangentUV(position: vec4f, normal: vec4f, tangent: vec4f
|
|
|
3007
3176
|
vec3f(0.0, 1.0, 0.0),
|
|
3008
3177
|
vec3f(0.0, 0.0, 1.0)
|
|
3009
3178
|
);
|
|
3010
|
-
fragmentInputs.
|
|
3179
|
+
fragmentInputs.pbr_vUV0 = vec2f(0.0, 0.0);
|
|
3180
|
+
fragmentInputs.pbr_vUV1 = uv1;
|
|
3011
3181
|
|
|
3012
3182
|
#ifdef HAS_NORMALS
|
|
3013
3183
|
let normalW: vec3f = normalize((pbrProjection.normalMatrix * vec4f(normal.xyz, 0.0)).xyz);
|
|
@@ -3020,7 +3190,7 @@ fn pbr_setPositionNormalTangentUV(position: vec4f, normal: vec4f, tangent: vec4f
|
|
|
3020
3190
|
#endif
|
|
3021
3191
|
|
|
3022
3192
|
#ifdef HAS_UV
|
|
3023
|
-
fragmentInputs.
|
|
3193
|
+
fragmentInputs.pbr_vUV0 = uv0;
|
|
3024
3194
|
#endif
|
|
3025
3195
|
}
|
|
3026
3196
|
|
|
@@ -3092,6 +3262,41 @@ struct pbrMaterialUniforms {
|
|
|
3092
3262
|
scaleDiffBaseMR: vec4f,
|
|
3093
3263
|
scaleFGDSpec: vec4f,
|
|
3094
3264
|
// #endif
|
|
3265
|
+
|
|
3266
|
+
baseColorUVSet: i32,
|
|
3267
|
+
baseColorUVTransform: mat3x3f,
|
|
3268
|
+
metallicRoughnessUVSet: i32,
|
|
3269
|
+
metallicRoughnessUVTransform: mat3x3f,
|
|
3270
|
+
normalUVSet: i32,
|
|
3271
|
+
normalUVTransform: mat3x3f,
|
|
3272
|
+
occlusionUVSet: i32,
|
|
3273
|
+
occlusionUVTransform: mat3x3f,
|
|
3274
|
+
emissiveUVSet: i32,
|
|
3275
|
+
emissiveUVTransform: mat3x3f,
|
|
3276
|
+
specularColorUVSet: i32,
|
|
3277
|
+
specularColorUVTransform: mat3x3f,
|
|
3278
|
+
specularIntensityUVSet: i32,
|
|
3279
|
+
specularIntensityUVTransform: mat3x3f,
|
|
3280
|
+
transmissionUVSet: i32,
|
|
3281
|
+
transmissionUVTransform: mat3x3f,
|
|
3282
|
+
thicknessUVSet: i32,
|
|
3283
|
+
thicknessUVTransform: mat3x3f,
|
|
3284
|
+
clearcoatUVSet: i32,
|
|
3285
|
+
clearcoatUVTransform: mat3x3f,
|
|
3286
|
+
clearcoatRoughnessUVSet: i32,
|
|
3287
|
+
clearcoatRoughnessUVTransform: mat3x3f,
|
|
3288
|
+
clearcoatNormalUVSet: i32,
|
|
3289
|
+
clearcoatNormalUVTransform: mat3x3f,
|
|
3290
|
+
sheenColorUVSet: i32,
|
|
3291
|
+
sheenColorUVTransform: mat3x3f,
|
|
3292
|
+
sheenRoughnessUVSet: i32,
|
|
3293
|
+
sheenRoughnessUVTransform: mat3x3f,
|
|
3294
|
+
iridescenceUVSet: i32,
|
|
3295
|
+
iridescenceUVTransform: mat3x3f,
|
|
3296
|
+
iridescenceThicknessUVSet: i32,
|
|
3297
|
+
iridescenceThicknessUVTransform: mat3x3f,
|
|
3298
|
+
anisotropyUVSet: i32,
|
|
3299
|
+
anisotropyUVTransform: mat3x3f,
|
|
3095
3300
|
}
|
|
3096
3301
|
|
|
3097
3302
|
@group(3) @binding(auto) var<uniform> pbrMaterial : pbrMaterialUniforms;
|
|
@@ -3205,13 +3410,22 @@ fn SRGBtoLINEAR(srgbIn: vec4f ) -> vec4f
|
|
|
3205
3410
|
return vec4f(linOut, srgbIn.w);
|
|
3206
3411
|
}
|
|
3207
3412
|
|
|
3413
|
+
fn getMaterialUV(uvSet: i32, uvTransform: mat3x3f) -> vec2f
|
|
3414
|
+
{
|
|
3415
|
+
var baseUV = fragmentInputs.pbr_vUV0;
|
|
3416
|
+
if (uvSet == 1) {
|
|
3417
|
+
baseUV = fragmentInputs.pbr_vUV1;
|
|
3418
|
+
}
|
|
3419
|
+
return (uvTransform * vec3f(baseUV, 1.0)).xy;
|
|
3420
|
+
}
|
|
3421
|
+
|
|
3208
3422
|
// Build the tangent basis from interpolated attributes or screen-space derivatives.
|
|
3209
|
-
fn getTBN() -> mat3x3f
|
|
3423
|
+
fn getTBN(uv: vec2f) -> mat3x3f
|
|
3210
3424
|
{
|
|
3211
3425
|
let pos_dx: vec3f = dpdx(fragmentInputs.pbr_vPosition);
|
|
3212
3426
|
let pos_dy: vec3f = dpdy(fragmentInputs.pbr_vPosition);
|
|
3213
|
-
let tex_dx: vec3f = dpdx(vec3f(
|
|
3214
|
-
let tex_dy: vec3f = dpdy(vec3f(
|
|
3427
|
+
let tex_dx: vec3f = dpdx(vec3f(uv, 0.0));
|
|
3428
|
+
let tex_dy: vec3f = dpdy(vec3f(uv, 0.0));
|
|
3215
3429
|
var t: vec3f = (tex_dy.y * pos_dx - tex_dx.y * pos_dy) / (tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y);
|
|
3216
3430
|
|
|
3217
3431
|
var ng: vec3f = cross(pos_dx, pos_dy);
|
|
@@ -3234,14 +3448,15 @@ fn getMappedNormal(
|
|
|
3234
3448
|
normalSampler: texture_2d<f32>,
|
|
3235
3449
|
normalSamplerBinding: sampler,
|
|
3236
3450
|
tbn: mat3x3f,
|
|
3237
|
-
normalScale: f32
|
|
3451
|
+
normalScale: f32,
|
|
3452
|
+
uv: vec2f
|
|
3238
3453
|
) -> vec3f
|
|
3239
3454
|
{
|
|
3240
|
-
let n = textureSample(normalSampler, normalSamplerBinding,
|
|
3455
|
+
let n = textureSample(normalSampler, normalSamplerBinding, uv).rgb;
|
|
3241
3456
|
return normalize(tbn * ((2.0 * n - 1.0) * vec3f(normalScale, normalScale, 1.0)));
|
|
3242
3457
|
}
|
|
3243
3458
|
|
|
3244
|
-
fn getNormal(tbn: mat3x3f) -> vec3f
|
|
3459
|
+
fn getNormal(tbn: mat3x3f, uv: vec2f) -> vec3f
|
|
3245
3460
|
{
|
|
3246
3461
|
// The tbn matrix is linearly interpolated, so we need to re-normalize
|
|
3247
3462
|
var n: vec3f = normalize(tbn[2].xyz);
|
|
@@ -3250,21 +3465,23 @@ fn getNormal(tbn: mat3x3f) -> vec3f
|
|
|
3250
3465
|
pbr_normalSampler,
|
|
3251
3466
|
pbr_normalSamplerSampler,
|
|
3252
3467
|
tbn,
|
|
3253
|
-
pbrMaterial.normalScale
|
|
3468
|
+
pbrMaterial.normalScale,
|
|
3469
|
+
uv
|
|
3254
3470
|
);
|
|
3255
3471
|
#endif
|
|
3256
3472
|
|
|
3257
3473
|
return n;
|
|
3258
3474
|
}
|
|
3259
3475
|
|
|
3260
|
-
fn getClearcoatNormal(tbn: mat3x3f, baseNormal: vec3f) -> vec3f
|
|
3476
|
+
fn getClearcoatNormal(tbn: mat3x3f, baseNormal: vec3f, uv: vec2f) -> vec3f
|
|
3261
3477
|
{
|
|
3262
3478
|
#ifdef HAS_CLEARCOATNORMALMAP
|
|
3263
3479
|
return getMappedNormal(
|
|
3264
3480
|
pbr_clearcoatNormalSampler,
|
|
3265
3481
|
pbr_clearcoatNormalSamplerSampler,
|
|
3266
3482
|
tbn,
|
|
3267
|
-
1.0
|
|
3483
|
+
1.0,
|
|
3484
|
+
uv
|
|
3268
3485
|
);
|
|
3269
3486
|
#else
|
|
3270
3487
|
return baseNormal;
|
|
@@ -3569,11 +3786,62 @@ fn calculateFinalColor(pbrInfo: PBRInfo, lightColor: vec3<f32>) -> vec3<f32> {
|
|
|
3569
3786
|
}
|
|
3570
3787
|
|
|
3571
3788
|
fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
3789
|
+
let baseColorUV = getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform);
|
|
3790
|
+
let metallicRoughnessUV = getMaterialUV(
|
|
3791
|
+
pbrMaterial.metallicRoughnessUVSet,
|
|
3792
|
+
pbrMaterial.metallicRoughnessUVTransform
|
|
3793
|
+
);
|
|
3794
|
+
let normalUV = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
|
|
3795
|
+
let occlusionUV = getMaterialUV(pbrMaterial.occlusionUVSet, pbrMaterial.occlusionUVTransform);
|
|
3796
|
+
let emissiveUV = getMaterialUV(pbrMaterial.emissiveUVSet, pbrMaterial.emissiveUVTransform);
|
|
3797
|
+
let specularColorUV = getMaterialUV(
|
|
3798
|
+
pbrMaterial.specularColorUVSet,
|
|
3799
|
+
pbrMaterial.specularColorUVTransform
|
|
3800
|
+
);
|
|
3801
|
+
let specularIntensityUV = getMaterialUV(
|
|
3802
|
+
pbrMaterial.specularIntensityUVSet,
|
|
3803
|
+
pbrMaterial.specularIntensityUVTransform
|
|
3804
|
+
);
|
|
3805
|
+
let transmissionUV = getMaterialUV(
|
|
3806
|
+
pbrMaterial.transmissionUVSet,
|
|
3807
|
+
pbrMaterial.transmissionUVTransform
|
|
3808
|
+
);
|
|
3809
|
+
let thicknessUV = getMaterialUV(pbrMaterial.thicknessUVSet, pbrMaterial.thicknessUVTransform);
|
|
3810
|
+
let clearcoatUV = getMaterialUV(pbrMaterial.clearcoatUVSet, pbrMaterial.clearcoatUVTransform);
|
|
3811
|
+
let clearcoatRoughnessUV = getMaterialUV(
|
|
3812
|
+
pbrMaterial.clearcoatRoughnessUVSet,
|
|
3813
|
+
pbrMaterial.clearcoatRoughnessUVTransform
|
|
3814
|
+
);
|
|
3815
|
+
let clearcoatNormalUV = getMaterialUV(
|
|
3816
|
+
pbrMaterial.clearcoatNormalUVSet,
|
|
3817
|
+
pbrMaterial.clearcoatNormalUVTransform
|
|
3818
|
+
);
|
|
3819
|
+
let sheenColorUV = getMaterialUV(
|
|
3820
|
+
pbrMaterial.sheenColorUVSet,
|
|
3821
|
+
pbrMaterial.sheenColorUVTransform
|
|
3822
|
+
);
|
|
3823
|
+
let sheenRoughnessUV = getMaterialUV(
|
|
3824
|
+
pbrMaterial.sheenRoughnessUVSet,
|
|
3825
|
+
pbrMaterial.sheenRoughnessUVTransform
|
|
3826
|
+
);
|
|
3827
|
+
let iridescenceUV = getMaterialUV(
|
|
3828
|
+
pbrMaterial.iridescenceUVSet,
|
|
3829
|
+
pbrMaterial.iridescenceUVTransform
|
|
3830
|
+
);
|
|
3831
|
+
let iridescenceThicknessUV = getMaterialUV(
|
|
3832
|
+
pbrMaterial.iridescenceThicknessUVSet,
|
|
3833
|
+
pbrMaterial.iridescenceThicknessUVTransform
|
|
3834
|
+
);
|
|
3835
|
+
let anisotropyUV = getMaterialUV(
|
|
3836
|
+
pbrMaterial.anisotropyUVSet,
|
|
3837
|
+
pbrMaterial.anisotropyUVTransform
|
|
3838
|
+
);
|
|
3839
|
+
|
|
3572
3840
|
// The albedo may be defined from a base texture or a flat color
|
|
3573
3841
|
var baseColor: vec4<f32> = pbrMaterial.baseColorFactor;
|
|
3574
3842
|
#ifdef HAS_BASECOLORMAP
|
|
3575
3843
|
baseColor = SRGBtoLINEAR(
|
|
3576
|
-
textureSample(pbr_baseColorSampler, pbr_baseColorSamplerSampler,
|
|
3844
|
+
textureSample(pbr_baseColorSampler, pbr_baseColorSamplerSampler, baseColorUV)
|
|
3577
3845
|
) * pbrMaterial.baseColorFactor;
|
|
3578
3846
|
#endif
|
|
3579
3847
|
|
|
@@ -3600,15 +3868,15 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3600
3868
|
let mrSample = textureSample(
|
|
3601
3869
|
pbr_metallicRoughnessSampler,
|
|
3602
3870
|
pbr_metallicRoughnessSamplerSampler,
|
|
3603
|
-
|
|
3871
|
+
metallicRoughnessUV
|
|
3604
3872
|
);
|
|
3605
3873
|
perceptualRoughness = mrSample.g * perceptualRoughness;
|
|
3606
3874
|
metallic = mrSample.b * metallic;
|
|
3607
3875
|
#endif
|
|
3608
3876
|
perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
|
|
3609
3877
|
metallic = clamp(metallic, 0.0, 1.0);
|
|
3610
|
-
let tbn = getTBN();
|
|
3611
|
-
let n = getNormal(tbn); // normal at surface point
|
|
3878
|
+
let tbn = getTBN(normalUV);
|
|
3879
|
+
let n = getNormal(tbn, normalUV); // normal at surface point
|
|
3612
3880
|
let v = normalize(pbrProjection.camera - fragmentInputs.pbr_vPosition); // Vector from surface point to camera
|
|
3613
3881
|
let NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
|
|
3614
3882
|
var useExtendedPBR = false;
|
|
@@ -3713,8 +3981,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3713
3981
|
|
|
3714
3982
|
#ifdef HAS_OCCLUSIONMAP
|
|
3715
3983
|
if (pbrMaterial.occlusionMapEnabled != 0) {
|
|
3716
|
-
let ao =
|
|
3717
|
-
textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, fragmentInputs.pbr_vUV).r;
|
|
3984
|
+
let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, occlusionUV).r;
|
|
3718
3985
|
color = mix(color, color * ao, pbrMaterial.occlusionStrength);
|
|
3719
3986
|
}
|
|
3720
3987
|
#endif
|
|
@@ -3723,7 +3990,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3723
3990
|
#ifdef HAS_EMISSIVEMAP
|
|
3724
3991
|
if (pbrMaterial.emissiveMapEnabled != 0u) {
|
|
3725
3992
|
emissive *= SRGBtoLINEAR(
|
|
3726
|
-
textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler,
|
|
3993
|
+
textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler, emissiveUV)
|
|
3727
3994
|
).rgb;
|
|
3728
3995
|
}
|
|
3729
3996
|
#endif
|
|
@@ -3744,7 +4011,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3744
4011
|
specularIntensity *= textureSample(
|
|
3745
4012
|
pbr_specularIntensitySampler,
|
|
3746
4013
|
pbr_specularIntensitySamplerSampler,
|
|
3747
|
-
|
|
4014
|
+
specularIntensityUV
|
|
3748
4015
|
).a;
|
|
3749
4016
|
}
|
|
3750
4017
|
#endif
|
|
@@ -3756,7 +4023,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3756
4023
|
textureSample(
|
|
3757
4024
|
pbr_specularColorSampler,
|
|
3758
4025
|
pbr_specularColorSamplerSampler,
|
|
3759
|
-
|
|
4026
|
+
specularColorUV
|
|
3760
4027
|
)
|
|
3761
4028
|
).rgb;
|
|
3762
4029
|
}
|
|
@@ -3768,7 +4035,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3768
4035
|
transmission *= textureSample(
|
|
3769
4036
|
pbr_transmissionSampler,
|
|
3770
4037
|
pbr_transmissionSamplerSampler,
|
|
3771
|
-
|
|
4038
|
+
transmissionUV
|
|
3772
4039
|
).r;
|
|
3773
4040
|
}
|
|
3774
4041
|
#endif
|
|
@@ -3778,7 +4045,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3778
4045
|
thickness *= textureSample(
|
|
3779
4046
|
pbr_thicknessSampler,
|
|
3780
4047
|
pbr_thicknessSamplerSampler,
|
|
3781
|
-
|
|
4048
|
+
thicknessUV
|
|
3782
4049
|
).g;
|
|
3783
4050
|
#endif
|
|
3784
4051
|
|
|
@@ -3789,7 +4056,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3789
4056
|
clearcoatFactor *= textureSample(
|
|
3790
4057
|
pbr_clearcoatSampler,
|
|
3791
4058
|
pbr_clearcoatSamplerSampler,
|
|
3792
|
-
|
|
4059
|
+
clearcoatUV
|
|
3793
4060
|
).r;
|
|
3794
4061
|
}
|
|
3795
4062
|
#endif
|
|
@@ -3798,13 +4065,13 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3798
4065
|
clearcoatRoughness *= textureSample(
|
|
3799
4066
|
pbr_clearcoatRoughnessSampler,
|
|
3800
4067
|
pbr_clearcoatRoughnessSamplerSampler,
|
|
3801
|
-
|
|
4068
|
+
clearcoatRoughnessUV
|
|
3802
4069
|
).g;
|
|
3803
4070
|
}
|
|
3804
4071
|
#endif
|
|
3805
4072
|
clearcoatFactor = clamp(clearcoatFactor, 0.0, 1.0);
|
|
3806
4073
|
clearcoatRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);
|
|
3807
|
-
let clearcoatNormal = getClearcoatNormal(
|
|
4074
|
+
let clearcoatNormal = getClearcoatNormal(getTBN(clearcoatNormalUV), n, clearcoatNormalUV);
|
|
3808
4075
|
|
|
3809
4076
|
var sheenColor = pbrMaterial.sheenColorFactor;
|
|
3810
4077
|
var sheenRoughness = pbrMaterial.sheenRoughnessFactor;
|
|
@@ -3814,7 +4081,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3814
4081
|
textureSample(
|
|
3815
4082
|
pbr_sheenColorSampler,
|
|
3816
4083
|
pbr_sheenColorSamplerSampler,
|
|
3817
|
-
|
|
4084
|
+
sheenColorUV
|
|
3818
4085
|
)
|
|
3819
4086
|
).rgb;
|
|
3820
4087
|
}
|
|
@@ -3824,7 +4091,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3824
4091
|
sheenRoughness *= textureSample(
|
|
3825
4092
|
pbr_sheenRoughnessSampler,
|
|
3826
4093
|
pbr_sheenRoughnessSamplerSampler,
|
|
3827
|
-
|
|
4094
|
+
sheenRoughnessUV
|
|
3828
4095
|
).a;
|
|
3829
4096
|
}
|
|
3830
4097
|
#endif
|
|
@@ -3836,7 +4103,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3836
4103
|
iridescence *= textureSample(
|
|
3837
4104
|
pbr_iridescenceSampler,
|
|
3838
4105
|
pbr_iridescenceSamplerSampler,
|
|
3839
|
-
|
|
4106
|
+
iridescenceUV
|
|
3840
4107
|
).r;
|
|
3841
4108
|
}
|
|
3842
4109
|
#endif
|
|
@@ -3853,7 +4120,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3853
4120
|
textureSample(
|
|
3854
4121
|
pbr_iridescenceThicknessSampler,
|
|
3855
4122
|
pbr_iridescenceThicknessSamplerSampler,
|
|
3856
|
-
|
|
4123
|
+
iridescenceThicknessUV
|
|
3857
4124
|
).g
|
|
3858
4125
|
);
|
|
3859
4126
|
#endif
|
|
@@ -3865,7 +4132,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3865
4132
|
let anisotropySample = textureSample(
|
|
3866
4133
|
pbr_anisotropySampler,
|
|
3867
4134
|
pbr_anisotropySamplerSampler,
|
|
3868
|
-
|
|
4135
|
+
anisotropyUV
|
|
3869
4136
|
).rgb;
|
|
3870
4137
|
anisotropyStrength *= anisotropySample.b;
|
|
3871
4138
|
let mappedDirection = anisotropySample.rg * 2.0 - 1.0;
|
|
@@ -4032,8 +4299,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
4032
4299
|
// Apply optional PBR terms for additional (optional) shading
|
|
4033
4300
|
#ifdef HAS_OCCLUSIONMAP
|
|
4034
4301
|
if (pbrMaterial.occlusionMapEnabled != 0) {
|
|
4035
|
-
let ao =
|
|
4036
|
-
textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, fragmentInputs.pbr_vUV).r;
|
|
4302
|
+
let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, occlusionUV).r;
|
|
4037
4303
|
color = mix(color, color * ao, pbrMaterial.occlusionStrength);
|
|
4038
4304
|
}
|
|
4039
4305
|
#endif
|
|
@@ -4042,7 +4308,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
4042
4308
|
#ifdef HAS_EMISSIVEMAP
|
|
4043
4309
|
if (pbrMaterial.emissiveMapEnabled != 0u) {
|
|
4044
4310
|
emissive *= SRGBtoLINEAR(
|
|
4045
|
-
textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler,
|
|
4311
|
+
textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler, emissiveUV)
|
|
4046
4312
|
).rgb;
|
|
4047
4313
|
}
|
|
4048
4314
|
#endif
|
|
@@ -4072,13 +4338,13 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
4072
4338
|
let alpha = clamp(baseColor.a * (1.0 - transmission), 0.0, 1.0);
|
|
4073
4339
|
return vec4<f32>(pow(color, vec3<f32>(1.0 / 2.2)), alpha);
|
|
4074
4340
|
}
|
|
4075
|
-
`;var
|
|
4341
|
+
`;var Gr=`layout(std140) uniform pbrProjectionUniforms {
|
|
4076
4342
|
mat4 modelViewProjectionMatrix;
|
|
4077
4343
|
mat4 modelMatrix;
|
|
4078
4344
|
mat4 normalMatrix;
|
|
4079
4345
|
vec3 camera;
|
|
4080
4346
|
} pbrProjection;
|
|
4081
|
-
`,
|
|
4347
|
+
`,Ho=`struct pbrProjectionUniforms {
|
|
4082
4348
|
modelViewProjectionMatrix: mat4x4<f32>,
|
|
4083
4349
|
modelMatrix: mat4x4<f32>,
|
|
4084
4350
|
normalMatrix: mat4x4<f32>,
|
|
@@ -4086,6 +4352,35 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
4086
4352
|
};
|
|
4087
4353
|
|
|
4088
4354
|
@group(0) @binding(auto) var<uniform> pbrProjection: pbrProjectionUniforms;
|
|
4089
|
-
`,
|
|
4355
|
+
`,Hr={name:"pbrProjection",bindingLayout:[{name:"pbrProjection",group:0}],source:Ho,vs:Gr,fs:Gr,getUniforms:e=>e,uniformTypes:{modelViewProjectionMatrix:"mat4x4<f32>",modelMatrix:"mat4x4<f32>",normalMatrix:"mat4x4<f32>",camera:"vec3<f32>"}};var $r={props:{},uniforms:{},defaultUniforms:{unlit:!1,baseColorMapEnabled:!1,baseColorFactor:[1,1,1,1],normalMapEnabled:!1,normalScale:1,emissiveMapEnabled:!1,emissiveFactor:[0,0,0],metallicRoughnessValues:[1,1],metallicRoughnessMapEnabled:!1,occlusionMapEnabled:!1,occlusionStrength:1,alphaCutoffEnabled:!1,alphaCutoff:.5,IBLenabled:!1,scaleIBLAmbient:[1,1],scaleDiffBaseMR:[0,0,0,0],scaleFGDSpec:[0,0,0,0],specularColorFactor:[1,1,1],specularIntensityFactor:1,specularColorMapEnabled:!1,specularIntensityMapEnabled:!1,ior:1.5,transmissionFactor:0,transmissionMapEnabled:!1,thicknessFactor:0,attenuationDistance:1e9,attenuationColor:[1,1,1],clearcoatFactor:0,clearcoatRoughnessFactor:0,clearcoatMapEnabled:!1,clearcoatRoughnessMapEnabled:!1,sheenColorFactor:[0,0,0],sheenRoughnessFactor:0,sheenColorMapEnabled:!1,sheenRoughnessMapEnabled:!1,iridescenceFactor:0,iridescenceIor:1.3,iridescenceThicknessRange:[100,400],iridescenceMapEnabled:!1,anisotropyStrength:0,anisotropyRotation:0,anisotropyDirection:[1,0],anisotropyMapEnabled:!1,emissiveStrength:1,baseColorUVSet:0,baseColorUVTransform:[1,0,0,0,1,0,0,0,1],metallicRoughnessUVSet:0,metallicRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],normalUVSet:0,normalUVTransform:[1,0,0,0,1,0,0,0,1],occlusionUVSet:0,occlusionUVTransform:[1,0,0,0,1,0,0,0,1],emissiveUVSet:0,emissiveUVTransform:[1,0,0,0,1,0,0,0,1],specularColorUVSet:0,specularColorUVTransform:[1,0,0,0,1,0,0,0,1],specularIntensityUVSet:0,specularIntensityUVTransform:[1,0,0,0,1,0,0,0,1],transmissionUVSet:0,transmissionUVTransform:[1,0,0,0,1,0,0,0,1],thicknessUVSet:0,thicknessUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatUVSet:0,clearcoatUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatRoughnessUVSet:0,clearcoatRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],clearcoatNormalUVSet:0,clearcoatNormalUVTransform:[1,0,0,0,1,0,0,0,1],sheenColorUVSet:0,sheenColorUVTransform:[1,0,0,0,1,0,0,0,1],sheenRoughnessUVSet:0,sheenRoughnessUVTransform:[1,0,0,0,1,0,0,0,1],iridescenceUVSet:0,iridescenceUVTransform:[1,0,0,0,1,0,0,0,1],iridescenceThicknessUVSet:0,iridescenceThicknessUVTransform:[1,0,0,0,1,0,0,0,1],anisotropyUVSet:0,anisotropyUVTransform:[1,0,0,0,1,0,0,0,1]},name:"pbrMaterial",firstBindingSlot:0,bindingLayout:[{name:"pbrMaterial",group:3},{name:"pbr_baseColorSampler",group:3},{name:"pbr_normalSampler",group:3},{name:"pbr_emissiveSampler",group:3},{name:"pbr_metallicRoughnessSampler",group:3},{name:"pbr_occlusionSampler",group:3},{name:"pbr_specularColorSampler",group:3},{name:"pbr_specularIntensitySampler",group:3},{name:"pbr_transmissionSampler",group:3},{name:"pbr_thicknessSampler",group:3},{name:"pbr_clearcoatSampler",group:3},{name:"pbr_clearcoatRoughnessSampler",group:3},{name:"pbr_clearcoatNormalSampler",group:3},{name:"pbr_sheenColorSampler",group:3},{name:"pbr_sheenRoughnessSampler",group:3},{name:"pbr_iridescenceSampler",group:3},{name:"pbr_iridescenceThicknessSampler",group:3},{name:"pbr_anisotropySampler",group:3}],dependencies:[B,Oe,Hr],source:zr,vs:kr,fs:Dr,defines:{LIGHTING_FRAGMENT:!0,HAS_NORMALMAP:!1,HAS_EMISSIVEMAP:!1,HAS_OCCLUSIONMAP:!1,HAS_BASECOLORMAP:!1,HAS_METALROUGHNESSMAP:!1,HAS_SPECULARCOLORMAP:!1,HAS_SPECULARINTENSITYMAP:!1,HAS_TRANSMISSIONMAP:!1,HAS_THICKNESSMAP:!1,HAS_CLEARCOATMAP:!1,HAS_CLEARCOATROUGHNESSMAP:!1,HAS_CLEARCOATNORMALMAP:!1,HAS_SHEENCOLORMAP:!1,HAS_SHEENROUGHNESSMAP:!1,HAS_IRIDESCENCEMAP:!1,HAS_IRIDESCENCETHICKNESSMAP:!1,HAS_ANISOTROPYMAP:!1,USE_MATERIAL_EXTENSIONS:!1,ALPHA_CUTOFF:!1,USE_IBL:!1,PBR_DEBUG:!1},getUniforms:e=>e,uniformTypes:{unlit:"i32",baseColorMapEnabled:"i32",baseColorFactor:"vec4<f32>",normalMapEnabled:"i32",normalScale:"f32",emissiveMapEnabled:"i32",emissiveFactor:"vec3<f32>",metallicRoughnessValues:"vec2<f32>",metallicRoughnessMapEnabled:"i32",occlusionMapEnabled:"i32",occlusionStrength:"f32",alphaCutoffEnabled:"i32",alphaCutoff:"f32",specularColorFactor:"vec3<f32>",specularIntensityFactor:"f32",specularColorMapEnabled:"i32",specularIntensityMapEnabled:"i32",ior:"f32",transmissionFactor:"f32",transmissionMapEnabled:"i32",thicknessFactor:"f32",attenuationDistance:"f32",attenuationColor:"vec3<f32>",clearcoatFactor:"f32",clearcoatRoughnessFactor:"f32",clearcoatMapEnabled:"i32",clearcoatRoughnessMapEnabled:"i32",sheenColorFactor:"vec3<f32>",sheenRoughnessFactor:"f32",sheenColorMapEnabled:"i32",sheenRoughnessMapEnabled:"i32",iridescenceFactor:"f32",iridescenceIor:"f32",iridescenceThicknessRange:"vec2<f32>",iridescenceMapEnabled:"i32",anisotropyStrength:"f32",anisotropyRotation:"f32",anisotropyDirection:"vec2<f32>",anisotropyMapEnabled:"i32",emissiveStrength:"f32",IBLenabled:"i32",scaleIBLAmbient:"vec2<f32>",scaleDiffBaseMR:"vec4<f32>",scaleFGDSpec:"vec4<f32>",baseColorUVSet:"i32",baseColorUVTransform:"mat3x3<f32>",metallicRoughnessUVSet:"i32",metallicRoughnessUVTransform:"mat3x3<f32>",normalUVSet:"i32",normalUVTransform:"mat3x3<f32>",occlusionUVSet:"i32",occlusionUVTransform:"mat3x3<f32>",emissiveUVSet:"i32",emissiveUVTransform:"mat3x3<f32>",specularColorUVSet:"i32",specularColorUVTransform:"mat3x3<f32>",specularIntensityUVSet:"i32",specularIntensityUVTransform:"mat3x3<f32>",transmissionUVSet:"i32",transmissionUVTransform:"mat3x3<f32>",thicknessUVSet:"i32",thicknessUVTransform:"mat3x3<f32>",clearcoatUVSet:"i32",clearcoatUVTransform:"mat3x3<f32>",clearcoatRoughnessUVSet:"i32",clearcoatRoughnessUVTransform:"mat3x3<f32>",clearcoatNormalUVSet:"i32",clearcoatNormalUVTransform:"mat3x3<f32>",sheenColorUVSet:"i32",sheenColorUVTransform:"mat3x3<f32>",sheenRoughnessUVSet:"i32",sheenRoughnessUVTransform:"mat3x3<f32>",iridescenceUVSet:"i32",iridescenceUVTransform:"mat3x3<f32>",iridescenceThicknessUVSet:"i32",iridescenceThicknessUVTransform:"mat3x3<f32>",anisotropyUVSet:"i32",anisotropyUVTransform:"mat3x3<f32>"}};var Wr=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1],jr=`layout(std140) uniform pbrSceneUniforms {
|
|
4356
|
+
float exposure;
|
|
4357
|
+
int toneMapMode;
|
|
4358
|
+
float environmentIntensity;
|
|
4359
|
+
float environmentRotation;
|
|
4360
|
+
vec2 framebufferSize;
|
|
4361
|
+
mat4 viewMatrix;
|
|
4362
|
+
mat4 projectionMatrix;
|
|
4363
|
+
} pbrScene;
|
|
4364
|
+
|
|
4365
|
+
#ifdef USE_TRANSMISSION_FRAMEBUFFER
|
|
4366
|
+
uniform sampler2D pbr_transmissionFramebufferSampler;
|
|
4367
|
+
#endif
|
|
4368
|
+
`,$o=`struct pbrSceneUniforms {
|
|
4369
|
+
exposure: f32,
|
|
4370
|
+
toneMapMode: i32,
|
|
4371
|
+
environmentIntensity: f32,
|
|
4372
|
+
environmentRotation: f32,
|
|
4373
|
+
framebufferSize: vec2<f32>,
|
|
4374
|
+
viewMatrix: mat4x4<f32>,
|
|
4375
|
+
projectionMatrix: mat4x4<f32>
|
|
4376
|
+
};
|
|
4377
|
+
|
|
4378
|
+
@group(1) @binding(auto) var<uniform> pbrScene: pbrSceneUniforms;
|
|
4379
|
+
|
|
4380
|
+
#ifdef USE_TRANSMISSION_FRAMEBUFFER
|
|
4381
|
+
@group(1) @binding(auto) var pbr_transmissionFramebufferSampler: texture_2d<f32>;
|
|
4382
|
+
@group(1) @binding(auto) var pbr_transmissionFramebufferSamplerSampler: sampler;
|
|
4383
|
+
#endif
|
|
4384
|
+
`,qr={name:"pbrScene",bindingLayout:[{name:"pbrScene",group:1},{name:"pbr_transmissionFramebufferSampler",group:1}],source:$o,vs:jr,fs:jr,getUniforms:e=>e,uniformTypes:{exposure:"f32",toneMapMode:"i32",environmentIntensity:"f32",environmentRotation:"f32",framebufferSize:"vec2<f32>",viewMatrix:"mat4x4<f32>",projectionMatrix:"mat4x4<f32>"},defaultUniforms:{exposure:1,toneMapMode:2,environmentIntensity:1,environmentRotation:Math.PI*.5,framebufferSize:[1,1],viewMatrix:Wr,projectionMatrix:Wr}};return rn(ce);})();
|
|
4090
4385
|
return __exports__;
|
|
4091
4386
|
});
|