2341 lines
810 KiB
JavaScript
2341 lines
810 KiB
JavaScript
var IS=Object.defineProperty;var Zc=Object.getOwnPropertySymbols;var FS=Object.prototype.hasOwnProperty,BS=Object.prototype.propertyIsEnumerable;var Qc=(r,t,e)=>t in r?IS(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Jc=(r,t)=>{for(var e in t||(t={}))FS.call(t,e)&&Qc(r,e,t[e]);if(Zc)for(var e of Zc(t))BS.call(t,e)&&Qc(r,e,t[e]);return r};/*!
|
|||
|
|
* PixiJS - v8.21.0
|
||
|
|
* Compiled Thu, 17 Sep 2026 07:42:29 UTC
|
||
|
|
*
|
||
|
|
* PixiJS is licensed under the MIT License.
|
||
|
|
* http://www.opensource.org/licenses/mit-license
|
||
|
|
*/var DS=Object.defineProperty,$S=Object.defineProperties,US=Object.getOwnPropertyDescriptors,td=Object.getOwnPropertySymbols,kS=Object.prototype.hasOwnProperty,LS=Object.prototype.propertyIsEnumerable,ed=(r,t,e)=>t in r?DS(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,rd=(r,t)=>{for(var e in t||(t={}))kS.call(t,e)&&ed(r,e,t[e]);if(td)for(var e of td(t))LS.call(t,e)&&ed(r,e,t[e]);return r},NS=(r,t)=>$S(r,US(t)),T=(r=>(r.Application="application",r.WebGLPipes="webgl-pipes",r.WebGLPipesAdaptor="webgl-pipes-adaptor",r.WebGLSystem="webgl-system",r.WebGLLoader="webgl-loader",r.WebGPUPipes="webgpu-pipes",r.WebGPUPipesAdaptor="webgpu-pipes-adaptor",r.WebGPUSystem="webgpu-system",r.WebGPULoader="webgpu-loader",r.CanvasSystem="canvas-system",r.CanvasPipesAdaptor="canvas-pipes-adaptor",r.CanvasPipes="canvas-pipes",r.CanvasLoader="canvas-loader",r.Asset="asset",r.LoadParser="load-parser",r.ResolveParser="resolve-parser",r.CacheParser="cache-parser",r.DetectionParser="detection-parser",r.MaskEffect="mask-effect",r.BlendMode="blend-mode",r.TextureSource="texture-source",r.TextureUploaderWebGL="texture-uploader-webgl",r.TextureUploaderWebGPU="texture-uploader-webgpu",r.Environment="environment",r.ShapeBuilder="shape-builder",r.Batcher="batcher",r))(T||{});const No=r=>{if(typeof r=="function"||typeof r=="object"&&r.extension){const t=typeof r.extension!="object"?{type:r.extension}:r.extension;r=NS(rd({},t),{ref:r})}if(typeof r=="object")r=rd({},r);else throw new Error("Invalid extension type");return typeof r.type=="string"&&(r.type=[r.type]),r},ds=(r,t)=>{var e;return(e=No(r).priority)!=null?e:t},L={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...r){return r.map(No).forEach(t=>{t.type.forEach(e=>{var s,i;return(i=(s=this._removeHandlers)[e])==null?void 0:i.call(s,t)})}),this},add(...r){return r.map(No).forEach(t=>{t.type.forEach(e=>{var s,i;const n=this._addHandlers,o=this._queue;n[e]?(i=n[e])==null||i.call(n,t):(o[e]=o[e]||[],(s=o[e])==null||s.push(t))})}),this},handle(r,t,e){var s;const i=this._addHandlers,n=this._removeHandlers;i[r]=t,n[r]=e;const o=this._queue;return o[r]&&((s=o[r])==null||s.forEach(a=>t(a)),delete o[r]),this},handleByMap(r,t){return this.handle(r,e=>{e.name&&(t[e.name]=e.ref)},e=>{e.name&&delete t[e.name]})},handleByNamedList(r,t,e=-1){return this.handle(r,s=>{t.findIndex(i=>i.name===s.name)>=0||(t.push({name:s.name,value:s.ref}),t.sort((i,n)=>ds(n.value,e)-ds(i.value,e)))},s=>{const i=t.findIndex(n=>n.name===s.name);i!==-1&&t.splice(i,1)})},handleByList(r,t,e=-1){return this.handle(r,s=>{t.includes(s.ref)||(t.push(s.ref),t.sort((i,n)=>ds(n,e)-ds(i,e)))},s=>{const i=t.indexOf(s.ref);i!==-1&&t.splice(i,1)})},mixin(r,...t){for(const e of t)Object.defineProperties(r.prototype,Object.getOwnPropertyDescriptors(e))}};var $B=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function jS(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function UB(r){return r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function kB(r){return r&&Object.prototype.hasOwnProperty.call(r,"default")&&Object.keys(r).length===1?r.default:r}function LB(r){if(Object.prototype.hasOwnProperty.call(r,"__esModule"))return r;var t=r.default;if(typeof t=="function"){var e=function s(){var i=!1;try{i=this instanceof s}catch(n){}return i?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};e.prototype=t.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(r).forEach(function(s){var i=Object.getOwnPropertyDescriptor(r,s);Object.defineProperty(e,s,i.get?i:{enumerable:!0,get:function(){return r[s]}})}),e}var fi={exports:{}},NB=fi.exports,sd;function XS(){return sd||(sd=1,(function(r){"use strict";var t=Object.prototype.hasOwnProperty,e="~";function s(){}Object.create&&(s.prototype=Object.create(null),new s().__proto__||(e=!1));function i(l,u,h){this.fn=l,this.context=u,this.once=h||!1}function n(l,u,h,c,d){if(typeof h!="function")
|
||
|
|
color: transparent;
|
||
|
|
pointer-events: none;
|
||
|
|
padding: 0;
|
||
|
|
margin: 0;
|
||
|
|
border: 0;
|
||
|
|
outline: 0;
|
||
|
|
background: transparent;
|
||
|
|
box-sizing: border-box;
|
||
|
|
user-select: none;
|
||
|
|
-webkit-user-select: none;
|
||
|
|
-moz-user-select: none;
|
||
|
|
-ms-user-select: none;
|
||
|
|
`,t.accessibleText&&(e.innerText=t.accessibleText)),e.style.width=`${Sp}px`,e.style.height=`${Sp}px`,e.style.backgroundColor=this.debug?"rgba(255,255,255,0.5)":"transparent",e.style.position="absolute",e.style.zIndex=wp.toString(),e.style.borderStyle="none",navigator.userAgent.toLowerCase().includes("chrome")?e.setAttribute("aria-live","off"):e.setAttribute("aria-live","polite"),navigator.userAgent.match(/rv:.*Gecko\//)?e.setAttribute("aria-relevant","additions"):e.setAttribute("aria-relevant","text"),e.addEventListener("click",this._onClick.bind(this)),e.addEventListener("focus",this._onFocus.bind(this)),e.addEventListener("focusout",this._onFocusOut.bind(this))),e.style.pointerEvents=t.accessiblePointerEvents,e.type=t.accessibleType,t.accessibleTitle&&t.accessibleTitle!==null?e.title=t.accessibleTitle:(!t.accessibleHint||t.accessibleHint===null)&&(e.title=`container ${t.tabIndex}`),t.accessibleHint&&t.accessibleHint!==null&&e.setAttribute("aria-label",t.accessibleHint),t.interactive?e.tabIndex=t.tabIndex:e.tabIndex=0,this.debug&&this._updateDebugHTML(e),t._accessibleActive=!0,t._accessibleDiv=e,e.container=t,this._children.push(t),this._div.appendChild(t._accessibleDiv)}_dispatchEvent(t,e){const{container:s}=t.target,i=this._renderer.events.rootBoundary,n=Object.assign(new ns(i),{target:s});i.rootTarget=this._renderer.lastObjectRendered,e.forEach(o=>i.dispatchEvent(n,o))}_onClick(t){this._dispatchEvent(t,["click","pointertap","tap"])}_onFocus(t){t.target.getAttribute("aria-live")||t.target.setAttribute("aria-live","assertive"),this._dispatchEvent(t,["mouseover"])}_onFocusOut(t){t.target.getAttribute("aria-live")||t.target.setAttribute("aria-live","polite"),this._dispatchEvent(t,["mouseout"])}_onKeyDown(t){t.keyCode!==V2||!this._activateOnTab||this._activate()}_onMouseMove(t){t.movementX===0&&t.movementY===0||this._deactivate()}destroy(){var t;this._deactivate(),this._destroyTouchHook(),(t=this._canvasObserver)==null||t.destroy(),this._canvasObserver=null,this._div=null,this._pools=null,this._children=null,this._renderer=null,this._hookDiv=null,globalThis.removeEventListener("keydown",this._boundOnKeyDown),this._boundOnKeyDown=null,globalThis.document.removeEventListener("mousemove",this._boundOnMouseMove,!0),this._boundOnMouseMove=null}setAccessibilityEnabled(t){t?this._activate():this._deactivate()}_getPool(t){return this._pools[t]||(this._pools[t]=[]),this._pools[t]}};oa.extension={type:[T.WebGLSystem,T.WebGPUSystem],name:"accessibility"},oa.defaultOptions={enabledByDefault:!1,debug:!1,activateOnTab:!0,deactivateOnMouseMove:!0};let Ap=oa;const Pp={accessible:!1,accessibleTitle:null,accessibleHint:null,tabIndex:0,accessibleType:"button",accessibleText:null,accessiblePointerEvents:"auto",accessibleChildren:!0,_accessibleActive:!1,_accessibleDiv:null,_renderId:-1};L.add(Ap),L.mixin(dt,Pp);class aa{constructor(t){this._attachedDomElements=[],this._renderer=t,this._renderer.runners.postrender.add(this),this._renderer.runners.init.add(this),this._domElement=document.createElement("div"),this._domElement.style.position="absolute",this._domElement.style.top="0",this._domElement.style.left="0",this._domElement.style.pointerEvents="none",this._domElement.style.zIndex="1000"}init(){this._canvasObserver=new sa({domElement:this._domElement,renderer:this._renderer})}addRenderable(t,e){this._attachedDomElements.includes(t)||this._attachedDomElements.push(t)}updateRenderable(t){}validateRenderable(t){return!0}postrender(){const t=this._attachedDomElements;if(t.length===0){this._domElement.remove();return}this._canvasObserver.ensureAttached();for(let e=0;e<t.length;e++){const s=t[e],i=s.element;if(!s.parent||s.globalDisplayStatus<7)i==null||i.remove(),t.splice(e,1),e--;else{this._domElement.contains(i)||(i.style.position="absolute",i.style.pointerEvents="auto",this._domElement.appendChild(i));const n=s.worldTransform,o=s._anchor,a=s.width*o.x,l=s.height*o.y;i.style.transformOrigin=`${a}px ${l}px`,i.style.transform=`matrix(${n.a}, ${n.b}, ${n.c}, ${n.d}, ${n.tx-a}, ${n.ty-l})`,i.style.opacity=s.groupAlpha.toString
|
||
|
|
|
||
|
|
#ifdef GL_ES // This checks if it is WebGL1
|
||
|
|
#define in varying
|
||
|
|
#define finalColor gl_FragColor
|
||
|
|
#define texture texture2D
|
||
|
|
#endif
|
||
|
|
${r}
|
||
|
|
`):`
|
||
|
|
|
||
|
|
#ifdef GL_ES // This checks if it is WebGL1
|
||
|
|
#define in attribute
|
||
|
|
#define out varying
|
||
|
|
#endif
|
||
|
|
${r}
|
||
|
|
`}function af(r,t,e){const s=e?t.maxSupportedFragmentPrecision:t.maxSupportedVertexPrecision;if(r.substring(0,9)!=="precision"){let i=e?t.requestedFragmentPrecision:t.requestedVertexPrecision;return i==="highp"&&s!=="highp"&&(i="mediump"),`precision ${i} float;
|
||
|
|
${r}`}else if(s!=="highp"&&r.substring(0,15)==="precision highp")return r.replace("precision highp","precision mediump");return r}function lf(r,t){return t?`#version 300 es
|
||
|
|
${r}`:r}const Uw={},kw={};function uf(r,{name:t="pixi-program"},e=!0){t=t.replace(/\s+/g,"-"),t+=e?"-fragment":"-vertex";const s=e?Uw:kw;return s[t]?(s[t]++,t+=`-${s[t]}`):s[t]=1,r.indexOf("#define SHADER_NAME")!==-1?r:`${`#define SHADER_NAME ${t}`}
|
||
|
|
${r}`}function hf(r,t){return t?r.replace("#version 300 es",""):r}var Lw=Object.defineProperty,cf=Object.getOwnPropertySymbols,Nw=Object.prototype.hasOwnProperty,jw=Object.prototype.propertyIsEnumerable,df=(r,t,e)=>t in r?Lw(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,pf=(r,t)=>{for(var e in t||(t={}))Nw.call(t,e)&&df(r,e,t[e]);if(cf)for(var e of cf(t))jw.call(t,e)&&df(r,e,t[e]);return r};const Ra={stripVersion:hf,ensurePrecision:af,addProgramDefines:of,setProgramName:uf,insertVersion:lf},Es=Object.create(null),ff=class $c{constructor(t){t=pf(pf({},$c.defaultOptions),t);const e=t.fragment.indexOf("#version 300 es")!==-1,s={stripVersion:e,ensurePrecision:{requestedFragmentPrecision:t.preferredFragmentPrecision,requestedVertexPrecision:t.preferredVertexPrecision,maxSupportedVertexPrecision:"highp",maxSupportedFragmentPrecision:nf()},setProgramName:{name:t.name},addProgramDefines:e,insertVersion:e};let i=t.fragment,n=t.vertex;Object.keys(Ra).forEach(o=>{const a=s[o];i=Ra[o](i,a,!0),n=Ra[o](n,a,!1)}),this.fragment=i,this.vertex=n,this.transformFeedbackVaryings=t.transformFeedbackVaryings,this._key=ur(`${this.vertex}:${this.fragment}`,"gl-program")}destroy(){this.fragment=null,this.vertex=null,this._attributeData=null,this._uniformData=null,this._uniformBlockData=null,this.transformFeedbackVaryings=null,Es[this._cacheKey]=null}static from(t){const e=`${t.vertex}:${t.fragment}`;return Es[e]||(Es[e]=new $c(t),Es[e]._cacheKey=e),Es[e]}};ff.defaultOptions={preferredVertexPrecision:"highp",preferredFragmentPrecision:"mediump"};let Yt=ff;const mf={uint8x2:{size:2,stride:2,normalised:!1},uint8x4:{size:4,stride:4,normalised:!1},sint8x2:{size:2,stride:2,normalised:!1},sint8x4:{size:4,stride:4,normalised:!1},unorm8x2:{size:2,stride:2,normalised:!0},unorm8x4:{size:4,stride:4,normalised:!0},snorm8x2:{size:2,stride:2,normalised:!0},snorm8x4:{size:4,stride:4,normalised:!0},uint16x2:{size:2,stride:4,normalised:!1},uint16x4:{size:4,stride:8,normalised:!1},sint16x2:{size:2,stride:4,normalised:!1},sint16x4:{size:4,stride:8,normalised:!1},unorm16x2:{size:2,stride:4,normalised:!0},unorm16x4:{size:4,stride:8,normalised:!0},snorm16x2:{size:2,stride:4,normalised:!0},snorm16x4:{size:4,stride:8,normalised:!0},float16x2:{size:2,stride:4,normalised:!1},float16x4:{size:4,stride:8,normalised:!1},float32:{size:1,stride:4,normalised:!1},float32x2:{size:2,stride:8,normalised:!1},float32x3:{size:3,stride:12,normalised:!1},float32x4:{size:4,stride:16,normalised:!1},uint32:{size:1,stride:4,normalised:!1},uint32x2:{size:2,stride:8,normalised:!1},uint32x3:{size:3,stride:12,normalised:!1},uint32x4:{size:4,stride:16,normalised:!1},sint32:{size:1,stride:4,normalised:!1},sint32x2:{size:2,stride:8,normalised:!1},sint32x3:{size:3,stride:12,normalised:!1},sint32x4:{size:4,stride:16,normalised:!1}};function Be(r){var t;return(t=mf[r])!=null?t:mf.float32}const Xw={f32:"float32","vec2<f32>":"float32x2","vec3<f32>":"float32x3","vec4<f32>":"float32x4",vec2f:"float32x2",vec3f:"float32x3",vec4f:"float32x4",i32:"sint32","vec2<i32>":"sint32x2","vec3<i32>":"sint32x3","vec4<i32>":"sint32x4",vec2i:"sint32x2",vec3i:"sint32x3",vec4i:"sint32x4",u32:"uint32","vec2<u32>":"uint32x2","vec3<u32>":"uint32x3","vec4<u32>":"uint32x4",vec2u:"uint32x2",vec3u:"uint32x3",vec4u:"uint32x4",bool:"uint32","vec2<bool>":"uint32x2","vec3<bool>":"uint32x3","vec4<bool>":"uint32x4"},gf=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|\)|$)/g;function _f(r,t){var e;let s;for(;(s=gf.exec(r))!==null;){const i=(e=Xw[s[3]])!=null?e:"float32";t[s[2]]={location:parseInt(s[1],10),format:i,stride:Be(i).stride,offset:0,instance:!1,start:0}}gf.lastIndex=0}function Hw(r){return r.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}function xf({source:r,entryPoint:t}){const e={},s=Hw(r),i=s.indexOf(`fn ${t}(`);if(i===-1)return e;const n=s.indexOf("->",i);if(n===-1)return e;const o=s.substring(i,n);if(_f(o,e),Object.keys(e).length===0){const a=o.match(/\(\s*\w+\s*:\s*(\w+)/);if(a){const l=a[1],u=new RegExp(`struct\\s+${l}\\s*\\{([^}]+)\\}`,"s"),h=s.match(u);h&&_f(h[1],e)}}ret
|
||
|
|
out vec2 vTextureCoord;
|
||
|
|
|
||
|
|
uniform vec4 uInputSize;
|
||
|
|
uniform vec4 uOutputFrame;
|
||
|
|
uniform vec4 uOutputTexture;
|
||
|
|
|
||
|
|
vec4 filterVertexPosition( void )
|
||
|
|
{
|
||
|
|
vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
|
||
|
|
|
||
|
|
position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
|
||
|
|
position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
|
||
|
|
|
||
|
|
return vec4(position, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
vec2 filterTextureCoord( void )
|
||
|
|
{
|
||
|
|
return aPosition * (uOutputFrame.zw * uInputSize.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
void main(void)
|
||
|
|
{
|
||
|
|
gl_Position = filterVertexPosition();
|
||
|
|
vTextureCoord = filterTextureCoord();
|
||
|
|
}
|
||
|
|
`,$f=`in vec2 vTextureCoord;
|
||
|
|
out vec4 finalColor;
|
||
|
|
uniform sampler2D uTexture;
|
||
|
|
void main() {
|
||
|
|
finalColor = texture(uTexture, vTextureCoord);
|
||
|
|
}
|
||
|
|
`,La=`struct GlobalFilterUniforms {
|
||
|
|
uInputSize: vec4<f32>,
|
||
|
|
uInputPixel: vec4<f32>,
|
||
|
|
uInputClamp: vec4<f32>,
|
||
|
|
uOutputFrame: vec4<f32>,
|
||
|
|
uGlobalFrame: vec4<f32>,
|
||
|
|
uOutputTexture: vec4<f32>,
|
||
|
|
};
|
||
|
|
|
||
|
|
@group(0) @binding(0) var <uniform> gfu: GlobalFilterUniforms;
|
||
|
|
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
||
|
|
@group(0) @binding(2) var uSampler: sampler;
|
||
|
|
|
||
|
|
struct VSOutput {
|
||
|
|
@builtin(position) position: vec4<f32>,
|
||
|
|
@location(0) uv: vec2<f32>
|
||
|
|
};
|
||
|
|
|
||
|
|
fn filterVertexPosition(aPosition: vec2<f32>) -> vec4<f32>
|
||
|
|
{
|
||
|
|
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
||
|
|
|
||
|
|
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
||
|
|
position.y = position.y * (2.0 * gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
|
||
|
|
|
||
|
|
return vec4(position, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn filterTextureCoord(aPosition: vec2<f32>) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
@vertex
|
||
|
|
fn mainVertex(
|
||
|
|
@location(0) aPosition: vec2<f32>,
|
||
|
|
) -> VSOutput {
|
||
|
|
return VSOutput(
|
||
|
|
filterVertexPosition(aPosition),
|
||
|
|
filterTextureCoord(aPosition)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
@fragment
|
||
|
|
fn mainFragment(
|
||
|
|
@location(0) uv: vec2<f32>,
|
||
|
|
) -> @location(0) vec4<f32> {
|
||
|
|
return textureSample(uTexture, uSampler, uv);
|
||
|
|
}
|
||
|
|
`;class Uf extends Ae{constructor(){const t=zt.from({vertex:{source:La,entryPoint:"mainVertex"},fragment:{source:La,entryPoint:"mainFragment"},name:"passthrough-filter"}),e=Yt.from({vertex:Ps,fragment:$f,name:"passthrough-filter"});super({gpuProgram:t,glProgram:e})}}var st=(r=>(r[r.MAP_READ=1]="MAP_READ",r[r.MAP_WRITE=2]="MAP_WRITE",r[r.COPY_SRC=4]="COPY_SRC",r[r.COPY_DST=8]="COPY_DST",r[r.INDEX=16]="INDEX",r[r.VERTEX=32]="VERTEX",r[r.UNIFORM=64]="UNIFORM",r[r.STORAGE=128]="STORAGE",r[r.INDIRECT=256]="INDIRECT",r[r.QUERY_RESOLVE=512]="QUERY_RESOLVE",r[r.STATIC=1024]="STATIC",r))(st||{});class qt extends It{constructor(t){let{data:e,size:s}=t;const{usage:i,label:n,shrinkToFit:o}=t;super(),this._gpuData=Object.create(null),this._gcLastUsed=-1,this.autoGarbageCollect=!0,this.uid=ut("buffer"),this._resourceType="buffer",this._resourceId=ut("resource"),this._updateID=1,this._updateOffset=0,this._dataInt32=null,this.shrinkToFit=!0,this.destroyed=!1,e instanceof Array&&(e=new Float32Array(e)),this._data=e,s!=null||(s=e==null?void 0:e.byteLength);const a=!!e;this.descriptor={size:s,usage:i,mappedAtCreation:a,label:n},this.shrinkToFit=o!=null?o:!0}get data(){return this._data}set data(t){this.setDataWithSize(t,t.length,!0)}get dataInt32(){return this._dataInt32||(this._dataInt32=new Int32Array(this.data.buffer)),this._dataInt32}get static(){return!!(this.descriptor.usage&st.STATIC)}set static(t){t?this.descriptor.usage|=st.STATIC:this.descriptor.usage&=~st.STATIC}setDataWithSize(t,e,s){if(this._updateID++,this._updateSize=e*t.BYTES_PER_ELEMENT,this._updateOffset=0,this._data===t){s&&this.emit("update",this);return}const i=this._data;if(this._data=t,this._dataInt32=null,!i||i.length!==t.length){!this.shrinkToFit&&i&&t.byteLength<i.byteLength?s&&this.emit("update",this):(this.descriptor.size=t.byteLength,this._resourceId=ut("resource"),this.emit("change",this));return}s&&this.emit("update",this)}update(t,e){this._updateSize=t!=null?t:this._updateSize,this._updateOffset=e||0,this._updateID++,this.emit("update",this)}unload(){var t;this.emit("unload",this);for(const e in this._gpuData)(t=this._gpuData[e])==null||t.destroy();this._gpuData=Object.create(null),this.destroyed||(this._resourceId=ut("resource"),this.emit("change",this))}destroy(){this.destroyed=!0,this.unload(),this.emit("destroy",this),this.emit("change",this),this._data=null,this.descriptor=null,this.removeAllListeners()}}function Na(r,t){if(!(r instanceof qt)){let e=t?st.INDEX:st.VERTEX;r instanceof Array&&(t?(r=new Uint32Array(r),e=st.INDEX|st.COPY_DST):(r=new Float32Array(r),e=st.VERTEX|st.COPY_DST)),r=new qt({data:r,label:t?"index-mesh-buffer":"vertex-mesh-buffer",usage:e})}return r}function kf(r,t,e){const s=r.getAttribute(t);if(!s)return e.minX=0,e.minY=0,e.maxX=0,e.maxY=0,e;const i=s.buffer.data;let n=1/0,o=1/0,a=-1/0,l=-1/0;const u=i.BYTES_PER_ELEMENT,h=(s.offset||0)/u,c=(s.stride||8)/u;for(let d=h;d<i.length;d+=c){const p=i[d],f=i[d+1];p>a&&(a=p),f>l&&(l=f),p<n&&(n=p),f<o&&(o=f)}return e.minX=n,e.minY=o,e.maxX=a,e.maxY=l,e}function iE(r){return(r instanceof qt||Array.isArray(r)||r.BYTES_PER_ELEMENT)&&(r={buffer:r}),r.buffer=Na(r.buffer,!1),r}class hr extends It{constructor(t={}){var e,s;super(),this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this.uid=ut("geometry"),this._layoutKey=0,this.instanceCount=1,this.indexCount=0,this._bounds=new Ct,this._boundsDirty=!0,this._vertexCount=0,this._vertexCountDirty=!0;const{attributes:i,indexBuffer:n,topology:o}=t;if(this.buffers=[],this.attributes={},i)for(const a in i)this.addAttribute(a,i[a]);this.instanceCount=(e=t.instanceCount)!=null?e:1,this.indexCount=(s=t.indexCount)!=null?s:0,n&&this.addIndex(n),this.topology=o||"triangle-list"}onBufferUpdate(){this._boundsDirty=!0,this._vertexCountDirty=!0,this.emit("update",this)}getAttribute(t){return this.attributes[t]}getIndex(){return this.indexBuffer}getBuffer(t){return this.getAttribute(t).buffer}get vertexCount(){if(!this._vertexCountDirty)return this._vertexCount;this._vertexCountDirty=!1;const t=this.attributes;for(const e in t){const s
|
||
|
|
${c}`);throw c instanceof Error&&c.stack&&(p.stack=c.stack),p}}};_m.defaultOptions={onProgress:void 0,onError:void 0,strategy:"throw",retryCount:3,retryDelay:250};let xm=_m;function dr(r,t){if(Array.isArray(t)){for(const e of t)if(r.startsWith(`data:${e}`))return!0;return!1}return r.startsWith(`data:${t}`)}function he(r,t){const e=r.split("?")[0],s=Vt.extname(e).toLowerCase();return Array.isArray(t)?t.includes(s):s===t}const HE=".json",zE="application/json",vm={extension:{type:T.LoadParser,priority:ee.Low},name:"loadJson",id:"json",test(r){return dr(r,zE)||he(r,HE)},async load(r){return await(await X.get().fetch(r)).json()}},WE=".txt",VE="text/plain",bm={name:"loadTxt",id:"text",extension:{type:T.LoadParser,priority:ee.Low,name:"loadTxt"},test(r){return dr(r,VE)||he(r,WE)},async load(r){return await(await X.get().fetch(r)).text()}};var YE=Object.defineProperty,KE=Object.defineProperties,qE=Object.getOwnPropertyDescriptors,ym=Object.getOwnPropertySymbols,ZE=Object.prototype.hasOwnProperty,QE=Object.prototype.propertyIsEnumerable,Tm=(r,t,e)=>t in r?YE(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,JE=(r,t)=>{for(var e in t||(t={}))ZE.call(t,e)&&Tm(r,e,t[e]);if(ym)for(var e of ym(t))QE.call(t,e)&&Tm(r,e,t[e]);return r},tA=(r,t)=>KE(r,qE(t));const eA=["normal","bold","100","200","300","400","500","600","700","800","900"],rA=[".ttf",".otf",".woff",".woff2"],sA=["font/ttf","font/otf","font/woff","font/woff2"],iA=/^(--|-?[A-Z_])[0-9A-Z_-]*$/i;function Sm(r){const t=Vt.extname(r),e=Vt.basename(r,t).replace(/(-|_)/g," ").toLowerCase().split(" ").map(n=>n.charAt(0).toUpperCase()+n.slice(1));let s=e.length>0;for(const n of e)if(!n.match(iA)){s=!1;break}let i=e.join(" ");return s||(i=`"${i.replace(/[\\"]/g,"\\$&")}"`),i}const nA=/^[0-9A-Za-z%:/?#\[\]@!\$&'()\*\+,;=\-._~]*$/;function oA(r){return nA.test(r)?r:encodeURI(r)}const wm={extension:{type:T.LoadParser,priority:ee.Low},name:"loadWebFont",id:"web-font",test(r){return dr(r,sA)||he(r,rA)},async load(r,t){var e,s,i,n,o,a;const l=X.get().getFontFaceSet();if(l){const u=[],h=(s=(e=t.data)==null?void 0:e.family)!=null?s:Sm(r),c=(o=(n=(i=t.data)==null?void 0:i.weights)==null?void 0:n.filter(p=>eA.includes(p)))!=null?o:["normal"],d=(a=t.data)!=null?a:{};for(let p=0;p<c.length;p++){const f=c[p],m=new FontFace(h,`url('${oA(r)}')`,tA(JE({},d),{weight:f}));await m.load(),l.add(m),u.push(m)}return rt.has(`${h}-and-url`)?rt.get(`${h}-and-url`).entries.push({url:r,faces:u}):rt.set(`${h}-and-url`,{entries:[{url:r,faces:u}]}),u.length===1?u[0]:u}return null},unload(r){const t=Array.isArray(r)?r:[r],e=t[0].family,s=rt.get(`${e}-and-url`),i=s.entries.find(n=>n.faces.some(o=>t.indexOf(o)!==-1));i.faces=i.faces.filter(n=>t.indexOf(n)===-1),i.faces.length===0&&(s.entries=s.entries.filter(n=>n!==i)),t.forEach(n=>{X.get().getFontFaceSet().delete(n)}),s.entries.length===0&&rt.remove(`${e}-and-url`)}},nl={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},aA=/([astvzqmhlc])([^astvzqmhlc]*)/gi,lA=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;function uA(r){const t=[];return r.replace(aA,(e,s,i)=>{let n=s.toLowerCase(),o=s;const a=hA(i);for(n==="m"&&a.length>2&&(t.push([o,...a.splice(0,2)]),n="l",o=o==="m"?"l":"L");;){if(a.length===nl[n])return t.push([o,...a]),"";if(a.length<nl[n])throw new Error("malformed path data");t.push([o,...a.splice(0,nl[n])])}}),t}function hA(r){const t=r.match(lA);return t?t.map(Number):[]}function Em(r,t){const e=uA(r),s=[];let i=null,n=0,o=0;for(let a=0;a<e.length;a++){const l=e[a],u=l[0],h=l;switch(u){case"M":n=h[1],o=h[2],t.moveTo(n,o);break;case"m":n+=h[1],o+=h[2],t.moveTo(n,o);break;case"H":n=h[1],t.lineTo(n,o);break;case"h":n+=h[1],t.lineTo(n,o);break;case"V":o=h[1],t.lineTo(n,o);break;case"v":o+=h[1],t.lineTo(n,o);break;case"L":n=h[1],o=h[2],t.lineTo(n,o);break;case"l":n+=h[1],o+=h[2],t.lineTo(n,o);break;case"C":n=h[5],o=h[6],t.bezierCurveTo(h[1],h[2],h[3],h[4],n,o);break;case"c":t.bezierCurveTo(n+h[1],o+h[2],n+h[3],o+h[4],n+h[5],o+h[6]),n+=h[5],o+=h[6];break;case"S":n=h[3],o=h[4],t.bezierCurveToShort(h[1],h[2],n,o);break;case"s":t.bezierCurveToShort(n+h[1],o+h[2],n+h[3],
|
||
|
|
Deprecated since v${r}`,n=typeof console.groupCollapsed=="function"&&!Br.noColor;typeof s=="undefined"?console.warn("PixiJS Deprecation Warning: ",i):(s=s.split(`
|
||
|
|
`).splice(e).join(`
|
||
|
|
`),n?(console.groupCollapsed("%cPixiJS Deprecation Warning: %c%s","color:#614108;background:#fffbe6","font-weight:normal;color:#614108;background:#fffbe6",i),console.warn(s),console.groupEnd()):(console.warn("PixiJS Deprecation Warning: ",i),console.warn(s))),Pm.add(t)});Object.defineProperties($s,{quiet:{get:()=>Br.quiet,set:r=>{Br.quiet=r},enumerable:!0,configurable:!1},noColor:{get:()=>Br.noColor,set:r=>{Br.noColor=r},enumerable:!0,configurable:!1}});function Wi(r,t,e,s){if(e!=null||(e=0),s!=null||(s=Math.min(r.byteLength-e,t.byteLength)),!(e&7)&&!(s&7)){const i=s/8;new Float64Array(t,0,i).set(new Float64Array(r,e,i))}else if(!(e&3)&&!(s&3)){const i=s/4;new Float32Array(t,0,i).set(new Float32Array(r,e,i))}else new Uint8Array(t).set(new Uint8Array(r,e,s))}const Cm={normal:"normal-npm",add:"add-npm",screen:"screen-npm"};var bt=(r=>(r[r.DISABLED=0]="DISABLED",r[r.RENDERING_MASK_ADD=1]="RENDERING_MASK_ADD",r[r.MASK_ACTIVE=2]="MASK_ACTIVE",r[r.INVERSE_MASK_ACTIVE=3]="INVERSE_MASK_ACTIVE",r[r.RENDERING_MASK_REMOVE=4]="RENDERING_MASK_REMOVE",r[r.NONE=5]="NONE",r))(bt||{});function Dr(r,t){return t.alphaMode==="no-premultiply-alpha"&&Cm[r]||r}const fA=["precision mediump float;","void main(void){","float test = 0.1;","%forloop%","gl_FragColor = vec4(0.0);","}"].join(`
|
||
|
|
`);function mA(r){let t="";for(let e=0;e<r;++e)e>0&&(t+=`
|
||
|
|
else `),e<r-1&&(t+=`if(test == ${e}.0){}`);return t}function al(r,t){if(r===0)throw new Error("Invalid value of `0` passed to `checkMaxIfStatementsInShader`");const e=t.createShader(t.FRAGMENT_SHADER);try{for(;;){const s=fA.replace(/%forloop%/gi,mA(r));if(t.shaderSource(e,s),t.compileShader(e),!t.getShaderParameter(e,t.COMPILE_STATUS))r=r/2|0;else break}}finally{t.deleteShader(e)}return r}let $r=null;function Rm(){var r;if($r)return $r;const t=Ca();return $r=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),$r=al($r,t),(r=t.getExtension("WEBGL_lose_context"))==null||r.loseContext(),$r}class Mm{constructor(){this.ids=Object.create(null),this.textures=[],this.count=0}clear(){for(let t=0;t<this.count;t++){const e=this.textures[t];this.textures[t]=null,this.ids[e.uid]=null}this.count=0}}var gA=Object.defineProperty,Om=Object.getOwnPropertySymbols,_A=Object.prototype.hasOwnProperty,xA=Object.prototype.propertyIsEnumerable,Gm=(r,t,e)=>t in r?gA(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Im=(r,t)=>{for(var e in t||(t={}))_A.call(t,e)&&Gm(r,e,t[e]);if(Om)for(var e of Om(t))xA.call(t,e)&&Gm(r,e,t[e]);return r};class Fm{constructor(){this.renderPipeId="batch",this.action="startBatch",this.start=0,this.size=0,this.textures=new Mm,this.blendMode="normal",this.topology="triangle-strip",this.canBundle=!0}destroy(){this.textures=null,this.gpuBindGroup=null,this.bindGroup=null,this.batcher=null,this.elements=null}}const Us=[];let Vi=0;tr.register({clear:()=>{if(Us.length>0)for(const r of Us)r&&r.destroy();Us.length=0,Vi=0}});function Bm(){return Vi>0?Us[--Vi]:new Fm}function Dm(r){r.elements=null,Us[Vi++]=r}let ks=0;const $m=class oS{constructor(t){this.uid=ut("batcher"),this.dirty=!0,this.batchIndex=0,this.batches=[],this._elements=[],t=Im(Im({},oS.defaultOptions),t),t.maxTextures||($s("v8.8.0","maxTextures is a required option for Batcher now, please pass it in the options"),t.maxTextures=Rm());const{maxTextures:e,attributesInitialSize:s,indicesInitialSize:i}=t;this.attributeBuffer=new pr(s*4),this.indexBuffer=new Uint16Array(i),this.maxTextures=e}begin(){this.elementSize=0,this.elementStart=0,this.indexSize=0,this.attributeSize=0;for(let t=0;t<this.batchIndex;t++)Dm(this.batches[t]);this.batchIndex=0,this._batchIndexStart=0,this._batchIndexSize=0,this.dirty=!0}add(t){this._elements[this.elementSize++]=t,t._indexStart=this.indexSize,t._attributeStart=this.attributeSize,t._batcher=this,this.indexSize+=t.indexSize,this.attributeSize+=t.attributeSize*this.vertexSize}checkAndUpdateTexture(t,e){const s=t._batch.textures.ids[e._source.uid];return!s&&s!==0?!1:(t._textureId=s,t.texture=e,!0)}updateElement(t){this.dirty=!0;const e=this.attributeBuffer;t.packAsQuad?this.packQuadAttributes(t,e.float32View,e.uint32View,t._attributeStart,t._textureId):this.packAttributes(t,e.float32View,e.uint32View,t._attributeStart,t._textureId)}break(t){const e=this._elements;if(!e[this.elementStart])return;let s=Bm(),i=s.textures;i.clear();const n=e[this.elementStart];let o=Dr(n.blendMode,n.texture._source),a=n.topology;this.attributeSize*4>this.attributeBuffer.size&&this._resizeAttributeBuffer(this.attributeSize*4),this.indexSize>this.indexBuffer.length&&this._resizeIndexBuffer(this.indexSize);const l=this.attributeBuffer.float32View,u=this.attributeBuffer.uint32View,h=this.indexBuffer;let c=this._batchIndexSize,d=this._batchIndexStart,p="startBatch",f=[];const m=this.maxTextures;for(let g=this.elementStart;g<this.elementSize;++g){const _=e[g];e[g]=null;const x=_.texture._source,v=Dr(_.blendMode,x),b=o!==v||a!==_.topology;if(x._batchTick===ks&&!b){_._textureId=x._textureBindLocation,c+=_.indexSize,_.packAsQuad?(this.packQuadAttributes(_,l,u,_._attributeStart,_._textureId),this.packQuadIndex(h,_._indexStart,_._attributeStart/this.vertexSize)):(this.packAttributes(_,l,u,_._attributeStart,_._textureId),this.packIndex(_,h,_._indexStart,_._attributeStart/this.vertexSize)),_._batch=s,f.push(_);continue}x._batchTick=ks,(i.count>=m||b)&&(this._finishBatch(s,d,c-d,i,o,a,t,p,f),p="renderBatch",d=c,o=v,a=_.topology,s=Bm(),i=s.textures,i.clear(),f=[],++ks),
|
||
|
|
`);let o=t.replace(/@in\s+[^;]+;\s*/g,"");return o=o.replace("{{in}}",`
|
||
|
|
${n}
|
||
|
|
`),o}function Nm(r,t){let e;const s=/@out\s+([^;]+);/g;for(;(e=s.exec(r))!==null;)t.push(e[1])}function TA(r){const t=/\b(\w+)\s*:/g.exec(r);return t?t[1]:""}function SA(r){const t=/@.*?\s+/g;return r.replace(t,"")}function jm(r,t){const e=[];Nm(t,e),r.forEach(l=>{l.header&&Nm(l.header,e)});let s=0;const i=e.sort().map(l=>l.indexOf("builtin")>-1?l:`@location(${s++}) ${l}`).join(`,
|
||
|
|
`),n=e.sort().map(l=>` var ${SA(l)};`).join(`
|
||
|
|
`),o=`return VSOutput(
|
||
|
|
${e.sort().map(l=>` ${TA(l)}`).join(`,
|
||
|
|
`)});`;let a=t.replace(/@out\s+[^;]+;\s*/g,"");return a=a.replace("{{struct}}",`
|
||
|
|
${i}
|
||
|
|
`),a=a.replace("{{start}}",`
|
||
|
|
${n}
|
||
|
|
`),a=a.replace("{{return}}",`
|
||
|
|
${o}
|
||
|
|
`),a}function cl(r,t){let e=r;for(const s in t){const i=t[s];i.join(`
|
||
|
|
`).length?e=e.replace(`{{${s}}}`,`//-----${s} START-----//
|
||
|
|
${i.join(`
|
||
|
|
`)}
|
||
|
|
//----${s} FINISH----//`):e=e.replace(`{{${s}}}`,"")}return e}const fr=Object.create(null),dl=new Map;let wA=0;function Xm({template:r,bits:t}){const e=zm(r,t);if(fr[e])return fr[e];const{vertex:s,fragment:i}=EA(r,t);return fr[e]=Wm(s,i,t),fr[e]}function Hm({template:r,bits:t}){const e=zm(r,t);return fr[e]||(fr[e]=Wm(r.vertex,r.fragment,t)),fr[e]}function EA(r,t){const e=t.map(o=>o.vertex).filter(o=>!!o),s=t.map(o=>o.fragment).filter(o=>!!o);let i=hl(e,r.vertex,!0);i=jm(e,i);const n=hl(s,r.fragment,!0);return{vertex:i,fragment:n}}function zm(r,t){return t.map(e=>(dl.has(e)||dl.set(e,wA++),dl.get(e))).sort((e,s)=>e-s).join("-")+r.vertex+r.fragment}function Wm(r,t,e){const s=ul(r),i=ul(t);return e.forEach(n=>{ll(n.vertex,s,n.name),ll(n.fragment,i,n.name)}),{vertex:cl(r,s),fragment:cl(t,i)}}const Vm=`
|
||
|
|
@in aPosition: vec2<f32>;
|
||
|
|
@in aUV: vec2<f32>;
|
||
|
|
|
||
|
|
@out @builtin(position) vPosition: vec4<f32>;
|
||
|
|
@out vUV : vec2<f32>;
|
||
|
|
@out vColor : vec4<f32>;
|
||
|
|
|
||
|
|
{{header}}
|
||
|
|
|
||
|
|
struct VSOutput {
|
||
|
|
{{struct}}
|
||
|
|
};
|
||
|
|
|
||
|
|
@vertex
|
||
|
|
fn main( {{in}} ) -> VSOutput {
|
||
|
|
|
||
|
|
var worldTransformMatrix = globalUniforms.uWorldTransformMatrix;
|
||
|
|
var modelMatrix = mat3x3<f32>(
|
||
|
|
1.0, 0.0, 0.0,
|
||
|
|
0.0, 1.0, 0.0,
|
||
|
|
0.0, 0.0, 1.0
|
||
|
|
);
|
||
|
|
var position = aPosition;
|
||
|
|
var uv = aUV;
|
||
|
|
|
||
|
|
{{start}}
|
||
|
|
|
||
|
|
vColor = vec4<f32>(1., 1., 1., 1.);
|
||
|
|
|
||
|
|
{{main}}
|
||
|
|
|
||
|
|
vUV = uv;
|
||
|
|
|
||
|
|
var modelViewProjectionMatrix = globalUniforms.uProjectionMatrix * worldTransformMatrix * modelMatrix;
|
||
|
|
|
||
|
|
vPosition = vec4<f32>((modelViewProjectionMatrix * vec3<f32>(position, 1.0)).xy, 0.0, 1.0);
|
||
|
|
|
||
|
|
vColor *= globalUniforms.uWorldColorAlpha;
|
||
|
|
|
||
|
|
{{end}}
|
||
|
|
|
||
|
|
{{return}}
|
||
|
|
};
|
||
|
|
`,Ym=`
|
||
|
|
@in vUV : vec2<f32>;
|
||
|
|
@in vColor : vec4<f32>;
|
||
|
|
|
||
|
|
{{header}}
|
||
|
|
|
||
|
|
@fragment
|
||
|
|
fn main(
|
||
|
|
{{in}}
|
||
|
|
) -> @location(0) vec4<f32> {
|
||
|
|
|
||
|
|
{{start}}
|
||
|
|
|
||
|
|
var outColor:vec4<f32>;
|
||
|
|
|
||
|
|
{{main}}
|
||
|
|
|
||
|
|
var finalColor:vec4<f32> = outColor * vColor;
|
||
|
|
|
||
|
|
{{end}}
|
||
|
|
|
||
|
|
return finalColor;
|
||
|
|
};
|
||
|
|
`,Km=`
|
||
|
|
in vec2 aPosition;
|
||
|
|
in vec2 aUV;
|
||
|
|
|
||
|
|
out vec4 vColor;
|
||
|
|
out vec2 vUV;
|
||
|
|
|
||
|
|
{{header}}
|
||
|
|
|
||
|
|
void main(void){
|
||
|
|
|
||
|
|
mat3 worldTransformMatrix = uWorldTransformMatrix;
|
||
|
|
mat3 modelMatrix = mat3(
|
||
|
|
1.0, 0.0, 0.0,
|
||
|
|
0.0, 1.0, 0.0,
|
||
|
|
0.0, 0.0, 1.0
|
||
|
|
);
|
||
|
|
vec2 position = aPosition;
|
||
|
|
vec2 uv = aUV;
|
||
|
|
|
||
|
|
{{start}}
|
||
|
|
|
||
|
|
vColor = vec4(1.);
|
||
|
|
|
||
|
|
{{main}}
|
||
|
|
|
||
|
|
vUV = uv;
|
||
|
|
|
||
|
|
mat3 modelViewProjectionMatrix = uProjectionMatrix * worldTransformMatrix * modelMatrix;
|
||
|
|
|
||
|
|
gl_Position = vec4((modelViewProjectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);
|
||
|
|
|
||
|
|
vColor *= uWorldColorAlpha;
|
||
|
|
|
||
|
|
{{end}}
|
||
|
|
}
|
||
|
|
`,qm=`
|
||
|
|
|
||
|
|
in vec4 vColor;
|
||
|
|
in vec2 vUV;
|
||
|
|
|
||
|
|
out vec4 finalColor;
|
||
|
|
|
||
|
|
{{header}}
|
||
|
|
|
||
|
|
void main(void) {
|
||
|
|
|
||
|
|
{{start}}
|
||
|
|
|
||
|
|
vec4 outColor;
|
||
|
|
|
||
|
|
{{main}}
|
||
|
|
|
||
|
|
finalColor = outColor * vColor;
|
||
|
|
|
||
|
|
{{end}}
|
||
|
|
}
|
||
|
|
`,Zm={name:"global-uniforms-bit",vertex:{header:`
|
||
|
|
struct GlobalUniforms {
|
||
|
|
uProjectionMatrix:mat3x3<f32>,
|
||
|
|
uWorldTransformMatrix:mat3x3<f32>,
|
||
|
|
uWorldColorAlpha: vec4<f32>,
|
||
|
|
uResolution: vec2<f32>,
|
||
|
|
}
|
||
|
|
|
||
|
|
@group(0) @binding(0) var<uniform> globalUniforms : GlobalUniforms;
|
||
|
|
`}},AA={name:"global-uniforms-ubo-bit",vertex:{header:`
|
||
|
|
uniform globalUniforms {
|
||
|
|
mat3 uProjectionMatrix;
|
||
|
|
mat3 uWorldTransformMatrix;
|
||
|
|
vec4 uWorldColorAlpha;
|
||
|
|
vec2 uResolution;
|
||
|
|
};
|
||
|
|
`}},Qm={name:"global-uniforms-bit",vertex:{header:`
|
||
|
|
uniform mat3 uProjectionMatrix;
|
||
|
|
uniform mat3 uWorldTransformMatrix;
|
||
|
|
uniform vec4 uWorldColorAlpha;
|
||
|
|
uniform vec2 uResolution;
|
||
|
|
`}};var PA=Object.defineProperty,Jm=Object.getOwnPropertySymbols,CA=Object.prototype.hasOwnProperty,RA=Object.prototype.propertyIsEnumerable,tg=(r,t,e)=>t in r?PA(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,MA=(r,t)=>{for(var e in t||(t={}))CA.call(t,e)&&tg(r,e,t[e]);if(Jm)for(var e of Jm(t))RA.call(t,e)&&tg(r,e,t[e]);return r};function Ur({bits:r,name:t}){const e=Xm({template:{fragment:Ym,vertex:Vm},bits:[Zm,...r]});return zt.from({name:t,vertex:{source:e.vertex,entryPoint:"main"},fragment:{source:e.fragment,entryPoint:"main"}})}function kr({bits:r,name:t}){return new Yt(MA({name:t},Hm({template:{vertex:Km,fragment:qm},bits:[Qm,...r]})))}const Yi={name:"color-bit",vertex:{header:`
|
||
|
|
@in aColor: vec4<f32>;
|
||
|
|
`,main:`
|
||
|
|
vColor *= vec4<f32>(aColor.rgb * aColor.a, aColor.a);
|
||
|
|
`}},Ki={name:"color-bit",vertex:{header:`
|
||
|
|
in vec4 aColor;
|
||
|
|
`,main:`
|
||
|
|
vColor *= vec4(aColor.rgb * aColor.a, aColor.a);
|
||
|
|
`}},pl={};function OA(r){const t=[];if(r===1)t.push("@group(1) @binding(0) var textureSource1: texture_2d<f32>;"),t.push("@group(1) @binding(1) var textureSampler1: sampler;");else{let e=0;for(let s=0;s<r;s++)t.push(`@group(1) @binding(${e++}) var textureSource${s+1}: texture_2d<f32>;`),t.push(`@group(1) @binding(${e++}) var textureSampler${s+1}: sampler;`)}return t.join(`
|
||
|
|
`)}function GA(r){const t=[];if(r===1)t.push("outColor = textureSampleGrad(textureSource1, textureSampler1, vUV, uvDx, uvDy);");else{t.push("switch vTextureId {");for(let e=0;e<r;e++)e===r-1?t.push(" default:{"):t.push(` case ${e}:{`),t.push(` outColor = textureSampleGrad(textureSource${e+1}, textureSampler${e+1}, vUV, uvDx, uvDy);`),t.push(" break;}");t.push("}")}return t.join(`
|
||
|
|
`)}function qi(r){return pl[r]||(pl[r]={name:"texture-batch-bit",vertex:{header:`
|
||
|
|
@in aTextureIdAndRound: vec2<u32>;
|
||
|
|
@out @interpolate(flat) vTextureId : u32;
|
||
|
|
`,main:`
|
||
|
|
vTextureId = aTextureIdAndRound.y;
|
||
|
|
`,end:`
|
||
|
|
if(aTextureIdAndRound.x == 1)
|
||
|
|
{
|
||
|
|
vPosition = vec4<f32>(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
|
||
|
|
}
|
||
|
|
`},fragment:{header:`
|
||
|
|
@in @interpolate(flat) vTextureId: u32;
|
||
|
|
|
||
|
|
${OA(r)}
|
||
|
|
`,main:`
|
||
|
|
var uvDx = dpdx(vUV);
|
||
|
|
var uvDy = dpdy(vUV);
|
||
|
|
|
||
|
|
${GA(r)}
|
||
|
|
`}}),pl[r]}const fl={};function IA(r){const t=[];for(let e=0;e<r;e++)e>0&&t.push("else"),e<r-1&&t.push(`if(vTextureId < ${e}.5)`),t.push("{"),t.push(` outColor = texture(uTextures[${e}], vUV);`),t.push("}");return t.join(`
|
||
|
|
`)}function Zi(r){return fl[r]||(fl[r]={name:"texture-batch-bit",vertex:{header:`
|
||
|
|
in vec2 aTextureIdAndRound;
|
||
|
|
out float vTextureId;
|
||
|
|
|
||
|
|
`,main:`
|
||
|
|
vTextureId = aTextureIdAndRound.y;
|
||
|
|
`,end:`
|
||
|
|
if(aTextureIdAndRound.x == 1.)
|
||
|
|
{
|
||
|
|
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
||
|
|
}
|
||
|
|
`},fragment:{header:`
|
||
|
|
in float vTextureId;
|
||
|
|
|
||
|
|
uniform sampler2D uTextures[${r}];
|
||
|
|
|
||
|
|
`,main:`
|
||
|
|
|
||
|
|
${IA(r)}
|
||
|
|
`}}),fl[r]}const Lr={name:"round-pixels-bit",vertex:{header:`
|
||
|
|
fn roundPixels(position: vec2<f32>, targetSize: vec2<f32>) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
||
|
|
}
|
||
|
|
`}},Nr={name:"round-pixels-bit",vertex:{header:`
|
||
|
|
vec2 roundPixels(vec2 position, vec2 targetSize)
|
||
|
|
{
|
||
|
|
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
||
|
|
}
|
||
|
|
`}},eg={};function Qi(r){let t=eg[r];if(t)return t;const e=new Int32Array(r);for(let s=0;s<r;s++)e[s]=s;return t=eg[r]=new wt({uTextures:{value:e,type:"i32",size:r}},{isStatic:!0}),t}class ml extends ne{constructor(t){const e=kr({name:"batch",bits:[Ki,Zi(t),Nr]}),s=Ur({name:"batch",bits:[Yi,qi(t),Lr]});super({glProgram:e,gpuProgram:s,resources:{batchSamplers:Qi(t)}}),this.maxTextures=t}}let Ls=null;const rg=class aS extends Um{constructor(t){super(t),this.geometry=new km,this.name=aS.extension.name,this.vertexSize=6,Ls!=null||(Ls=new ml(t.maxTextures)),this.shader=Ls}packAttributes(t,e,s,i,n){const o=n<<16|t.roundPixels&65535,a=t.transform,l=a.a,u=a.b,h=a.c,c=a.d,d=a.tx,p=a.ty,{positions:f,uvs:m}=t,g=t.color,_=t.attributeOffset,x=_+t.attributeSize;for(let v=_;v<x;v++){const b=v*2,S=f[b],y=f[b+1];e[i++]=l*S+h*y+d,e[i++]=c*y+u*S+p,e[i++]=m[b],e[i++]=m[b+1],s[i++]=g,s[i++]=o}}packQuadAttributes(t,e,s,i,n){const o=t.texture,a=t.transform,l=a.a,u=a.b,h=a.c,c=a.d,d=a.tx,p=a.ty,f=t.bounds,m=f.maxX,g=f.minX,_=f.maxY,x=f.minY,v=o.uvs,b=t.color,S=n<<16|t.roundPixels&65535;e[i+0]=l*g+h*x+d,e[i+1]=c*x+u*g+p,e[i+2]=v.x0,e[i+3]=v.y0,s[i+4]=b,s[i+5]=S,e[i+6]=l*m+h*x+d,e[i+7]=c*x+u*m+p,e[i+8]=v.x1,e[i+9]=v.y1,s[i+10]=b,s[i+11]=S,e[i+12]=l*m+h*_+d,e[i+13]=c*_+u*m+p,e[i+14]=v.x2,e[i+15]=v.y2,s[i+16]=b,s[i+17]=S,e[i+18]=l*g+h*_+d,e[i+19]=c*_+u*g+p,e[i+20]=v.x3,e[i+21]=v.y3,s[i+22]=b,s[i+23]=S}_updateMaxTextures(t){this.shader.maxTextures!==t&&(Ls=new ml(t),this.shader=Ls)}destroy(){this.shader=null,super.destroy()}};rg.extension={type:[T.Batcher],name:"default"};let Ji=rg;class kt{constructor(t){this.items=Object.create(null);const{renderer:e,type:s,onUnload:i,priority:n,name:o}=t;this._renderer=e,e.gc.addResourceHash(this,"items",s,n!=null?n:0),this._onUnload=i,this.name=o}add(t){return this.items[t.uid]?!1:(this.items[t.uid]=t,t.once("unload",this.remove,this),t._gcLastUsed=this._renderer.gc.now,!0)}remove(t,...e){var s;if(!this.items[t.uid])return;const i=t._gpuData[this._renderer.uid];i&&((s=this._onUnload)==null||s.call(this,t,...e),t.off("unload",this.remove,this),i.destroy(),t._gpuData[this._renderer.uid]=null,this.items[t.uid]=null)}removeAll(...t){Object.values(this.items).forEach(e=>e&&this.remove(e,...t))}destroy(...t){this.removeAll(...t),this.items=Object.create(null),this._renderer=null,this._onUnload=null}}function gl(r,t,e,s,i,n,o,a=null){let l=0;e*=t,i*=n;const u=a.a,h=a.b,c=a.c,d=a.d,p=a.tx,f=a.ty;for(;l<o;){const m=r[e],g=r[e+1];s[i]=u*m+c*g+p,s[i+1]=h*m+d*g+f,i+=n,e+=t,l++}}function _l(r,t,e,s){let i=0;for(t*=e;i<s;)r[t]=0,r[t+1]=0,t+=e,i++}function tn(r,t,e,s,i){const n=t.a,o=t.b,a=t.c,l=t.d,u=t.tx,h=t.ty;e||(e=0),s||(s=2),i||(i=r.length/s-e);let c=e*s;for(let d=0;d<i;d++){const p=r[c],f=r[c+1];r[c]=n*p+a*f+u,r[c+1]=o*p+l*f+h,c+=s}}const FA=new D;class en{constructor(){this.packAsQuad=!1,this.batcherName="default",this.topology="triangle-list",this.applyTransform=!0,this.roundPixels=0,this._batcher=null,this._batch=null}get uvs(){return this.geometryData.uvs}get positions(){return this.geometryData.vertices}get indices(){return this.geometryData.indices}get blendMode(){return this.renderable&&this.applyTransform?this.renderable.groupBlendMode:"normal"}get color(){const t=this.baseColor,e=t>>16|t&65280|(t&255)<<16,s=this.renderable;return s?be(e,s.groupColor)+(this.alpha*s.groupAlpha*255<<24):e+(this.alpha*255<<24)}get transform(){var t;return((t=this.renderable)==null?void 0:t.groupTransform)||FA}copyTo(t){t.indexOffset=this.indexOffset,t.indexSize=this.indexSize,t.attributeOffset=this.attributeOffset,t.attributeSize=this.attributeSize,t.baseColor=this.baseColor,t.alpha=this.alpha,t.texture=this.texture,t.geometryData=this.geometryData,t.topology=this.topology}reset(){this.applyTransform=!0,this.renderable=null,this.topology="triangle-list"}destroy(){this.renderable=null,this.texture=null,this.geometryData=null,this._batcher=null,this._batch=null}}var BA=Object.defineProperty,DA=Object.defineProperties,$A=Object.getOwnPropertyDescriptors,sg=Object.getOwnPropertySymbols,UA=Object.prototype.hasOwnProperty,kA=Obj
|
||
|
|
`;let Vr=null,$l=class{constructor(){Vr||(Vr=URL.createObjectURL(new Blob([FP],{type:"application/javascript"}))),this.worker=new Worker(Vr)}};$l.revokeObjectURL=function(){Vr&&(URL.revokeObjectURL(Vr),Vr=null)};const BP='(function(){"use strict";async function s(a,t){const e=await fetch(a);if(!e.ok)throw new Error(`[WorkerManager.loadImageBitmap] Failed to fetch ${a}: ${e.status} ${e.statusText}`);const i=await e.blob();return t==="premultiplied-alpha"?createImageBitmap(i,{premultiplyAlpha:"none"}):createImageBitmap(i)}self.onmessage=async a=>{try{const t=await s(a.data.data[0],a.data.data[1]);self.postMessage({data:t,uuid:a.data.uuid,id:a.data.id},[t])}catch(t){self.postMessage({error:t,uuid:a.data.uuid,id:a.data.id})}}})();\n';let Yr=null,i_=class{constructor(){Yr||(Yr=URL.createObjectURL(new Blob([BP],{type:"application/javascript"}))),this.worker=new Worker(Yr)}};i_.revokeObjectURL=function(){Yr&&(URL.revokeObjectURL(Yr),Yr=null)};let n_=0,Ul,DP=class{constructor(){this._initialized=!1,this._createdWorkers=0,this._workerPool=[],this._queue=[],this._resolveHash={}}isImageBitmapSupported(){return this._isImageBitmapSupported!==void 0?this._isImageBitmapSupported:(this._isImageBitmapSupported=new Promise(t=>{const{worker:e}=new $l;e.addEventListener("message",s=>{e.terminate(),$l.revokeObjectURL(),t(s.data)})}),this._isImageBitmapSupported)}loadImageBitmap(t,e){var s;return this._run("loadImageBitmap",[t,(s=e==null?void 0:e.data)==null?void 0:s.alphaMode])}async _initWorkers(){this._initialized||(this._initialized=!0)}_getWorker(){Ul===void 0&&(Ul=navigator.hardwareConcurrency||4);let t=this._workerPool.pop();return!t&&this._createdWorkers<Ul&&(this._createdWorkers++,t=new i_().worker,t.addEventListener("message",e=>{this._complete(e.data),this._returnWorker(e.target),this._next()})),t}_returnWorker(t){this._workerPool.push(t)}_complete(t){this._resolveHash[t.uuid]&&(t.error!==void 0?this._resolveHash[t.uuid].reject(t.error):this._resolveHash[t.uuid].resolve(t.data),delete this._resolveHash[t.uuid])}async _run(t,e){await this._initWorkers();const s=new Promise((i,n)=>{this._queue.push({id:t,arguments:e,resolve:i,reject:n})});return this._next(),s}_next(){if(!this._queue.length)return;const t=this._getWorker();if(!t)return;const e=this._queue.pop(),s=e.id;this._resolveHash[n_]={resolve:e.resolve,reject:e.reject},t.postMessage({data:e.arguments,uuid:n_++,id:s})}reset(){this._workerPool.forEach(t=>t.terminate()),this._workerPool.length=0,Object.values(this._resolveHash).forEach(({reject:t})=>{t==null||t(new Error("WorkerManager has been reset before completion"))}),this._resolveHash={},this._queue.length=0,this._initialized=!1,this._createdWorkers=0}};const kl=new DP;var $P=Object.defineProperty,o_=Object.getOwnPropertySymbols,UP=Object.prototype.hasOwnProperty,kP=Object.prototype.propertyIsEnumerable,a_=(r,t,e)=>t in r?$P(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,LP=(r,t)=>{for(var e in t||(t={}))UP.call(t,e)&&a_(r,e,t[e]);if(o_)for(var e of o_(t))kP.call(t,e)&&a_(r,e,t[e]);return r};const NP=[".jpeg",".jpg",".png",".webp",".avif"],jP=["image/jpeg","image/png","image/webp","image/avif"];async function l_(r,t){var e;const s=await X.get().fetch(r);if(!s.ok)throw new Error(`[loadImageBitmap] Failed to fetch ${r}: ${s.status} ${s.statusText}`);const i=await s.blob();return((e=t==null?void 0:t.data)==null?void 0:e.alphaMode)==="premultiplied-alpha"?createImageBitmap(i,{premultiplyAlpha:"none"}):createImageBitmap(i)}const Ll={name:"loadTextures",id:"texture",extension:{type:T.LoadParser,priority:ee.High,name:"loadTextures"},config:{preferWorkers:!0,preferCreateImageBitmap:!0,crossOrigin:"anonymous"},test(r){return dr(r,jP)||he(r,NP)},async load(r,t,e){var s;let i=null;globalThis.createImageBitmap&&this.config.preferCreateImageBitmap?this.config.preferWorkers&&await kl.isImageBitmapSupported()?i=await kl.loadImageBitmap(r,t):i=await l_(r,t):i=await new Promise((o,a)=>{i=X.get().createImage(),i.crossOrigin=this.config.crossOrigin,i.src=r,i.complete?o(i):(i.onload=()=>{o(i)},i.onerror=a)});const n=new je(LP
|
||
|
|
bitCount = ${t}, rBitMask = ${e}, gBitMask = ${s}, aBitMask = ${n}`)}var PC=Object.defineProperty,CC=Object.defineProperties,RC=Object.getOwnPropertyDescriptors,G_=Object.getOwnPropertySymbols,MC=Object.prototype.hasOwnProperty,OC=Object.prototype.propertyIsEnumerable,I_=(r,t,e)=>t in r?PC(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,GC=(r,t)=>{for(var e in t||(t={}))MC.call(t,e)&&I_(r,e,t[e]);if(G_)for(var e of G_(t))OC.call(t,e)&&I_(r,e,t[e]);return r},IC=(r,t)=>CC(r,RC(t));const FC={extension:{type:T.LoadParser,priority:ee.High,name:"loadDDS"},name:"loadDDS",id:"dds",test(r){return he(r,[".dds"])},async load(r,t,e){var s;const i=await zs(),n=await(await fetch(r)).arrayBuffer(),o=O_(n,i),a=new Hs(IC(GC({},o),{resolution:((s=t.data)==null?void 0:s.resolution)||ze(r)}));return We(a,e,r)},unload(r){Array.isArray(r)?r.forEach(t=>t.destroy(!0)):r.destroy(!0)}};var F_=(r=>(r[r.RGBA8_SNORM=36759]="RGBA8_SNORM",r[r.RGBA=6408]="RGBA",r[r.RGBA8UI=36220]="RGBA8UI",r[r.SRGB8_ALPHA8=35907]="SRGB8_ALPHA8",r[r.RGBA8I=36238]="RGBA8I",r[r.RGBA8=32856]="RGBA8",r[r.COMPRESSED_RGB_S3TC_DXT1_EXT=33776]="COMPRESSED_RGB_S3TC_DXT1_EXT",r[r.COMPRESSED_RGBA_S3TC_DXT1_EXT=33777]="COMPRESSED_RGBA_S3TC_DXT1_EXT",r[r.COMPRESSED_RGBA_S3TC_DXT3_EXT=33778]="COMPRESSED_RGBA_S3TC_DXT3_EXT",r[r.COMPRESSED_RGBA_S3TC_DXT5_EXT=33779]="COMPRESSED_RGBA_S3TC_DXT5_EXT",r[r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT=35917]="COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT",r[r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT=35918]="COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT",r[r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT=35919]="COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT",r[r.COMPRESSED_SRGB_S3TC_DXT1_EXT=35916]="COMPRESSED_SRGB_S3TC_DXT1_EXT",r[r.COMPRESSED_RED_RGTC1_EXT=36283]="COMPRESSED_RED_RGTC1_EXT",r[r.COMPRESSED_SIGNED_RED_RGTC1_EXT=36284]="COMPRESSED_SIGNED_RED_RGTC1_EXT",r[r.COMPRESSED_RED_GREEN_RGTC2_EXT=36285]="COMPRESSED_RED_GREEN_RGTC2_EXT",r[r.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT=36286]="COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT",r[r.COMPRESSED_R11_EAC=37488]="COMPRESSED_R11_EAC",r[r.COMPRESSED_SIGNED_R11_EAC=37489]="COMPRESSED_SIGNED_R11_EAC",r[r.COMPRESSED_RG11_EAC=37490]="COMPRESSED_RG11_EAC",r[r.COMPRESSED_SIGNED_RG11_EAC=37491]="COMPRESSED_SIGNED_RG11_EAC",r[r.COMPRESSED_RGB8_ETC2=37492]="COMPRESSED_RGB8_ETC2",r[r.COMPRESSED_RGBA8_ETC2_EAC=37496]="COMPRESSED_RGBA8_ETC2_EAC",r[r.COMPRESSED_SRGB8_ETC2=37493]="COMPRESSED_SRGB8_ETC2",r[r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC=37497]="COMPRESSED_SRGB8_ALPHA8_ETC2_EAC",r[r.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2=37494]="COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2",r[r.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2=37495]="COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2",r[r.COMPRESSED_RGBA_ASTC_4x4_KHR=37808]="COMPRESSED_RGBA_ASTC_4x4_KHR",r[r.COMPRESSED_RGBA_ASTC_5x4_KHR=37809]="COMPRESSED_RGBA_ASTC_5x4_KHR",r[r.COMPRESSED_RGBA_ASTC_5x5_KHR=37810]="COMPRESSED_RGBA_ASTC_5x5_KHR",r[r.COMPRESSED_RGBA_ASTC_6x5_KHR=37811]="COMPRESSED_RGBA_ASTC_6x5_KHR",r[r.COMPRESSED_RGBA_ASTC_6x6_KHR=37812]="COMPRESSED_RGBA_ASTC_6x6_KHR",r[r.COMPRESSED_RGBA_ASTC_8x5_KHR=37813]="COMPRESSED_RGBA_ASTC_8x5_KHR",r[r.COMPRESSED_RGBA_ASTC_8x6_KHR=37814]="COMPRESSED_RGBA_ASTC_8x6_KHR",r[r.COMPRESSED_RGBA_ASTC_8x8_KHR=37815]="COMPRESSED_RGBA_ASTC_8x8_KHR",r[r.COMPRESSED_RGBA_ASTC_10x5_KHR=37816]="COMPRESSED_RGBA_ASTC_10x5_KHR",r[r.COMPRESSED_RGBA_ASTC_10x6_KHR=37817]="COMPRESSED_RGBA_ASTC_10x6_KHR",r[r.COMPRESSED_RGBA_ASTC_10x8_KHR=37818]="COMPRESSED_RGBA_ASTC_10x8_KHR",r[r.COMPRESSED_RGBA_ASTC_10x10_KHR=37819]="COMPRESSED_RGBA_ASTC_10x10_KHR",r[r.COMPRESSED_RGBA_ASTC_12x10_KHR=37820]="COMPRESSED_RGBA_ASTC_12x10_KHR",r[r.COMPRESSED_RGBA_ASTC_12x12_KHR=37821]="COMPRESSED_RGBA_ASTC_12x12_KHR",r[r.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR=37840]="COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR",r[r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR=37841]="COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR",r[r.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR=37842]="COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR",r[r.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR=37843]="COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR",r[r.COMPRESSED_SRGB8_ALPHA8_ASTC_
|
||
|
|
in vec2 vTextureCoord;
|
||
|
|
in vec4 vColor;
|
||
|
|
|
||
|
|
out vec4 finalColor;
|
||
|
|
|
||
|
|
uniform float uBlend;
|
||
|
|
|
||
|
|
uniform sampler2D uTexture;
|
||
|
|
uniform sampler2D uBackTexture;
|
||
|
|
|
||
|
|
{FUNCTIONS}
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 back = texture(uBackTexture, vTextureCoord);
|
||
|
|
vec4 front = texture(uTexture, vTextureCoord);
|
||
|
|
float blendedAlpha = front.a + back.a * (1.0 - front.a);
|
||
|
|
|
||
|
|
{MAIN}
|
||
|
|
}
|
||
|
|
`,q_=`in vec2 aPosition;
|
||
|
|
out vec2 vTextureCoord;
|
||
|
|
out vec2 backgroundUv;
|
||
|
|
|
||
|
|
uniform vec4 uInputSize;
|
||
|
|
uniform vec4 uOutputFrame;
|
||
|
|
uniform vec4 uOutputTexture;
|
||
|
|
|
||
|
|
vec4 filterVertexPosition( void )
|
||
|
|
{
|
||
|
|
vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
|
||
|
|
|
||
|
|
position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
|
||
|
|
position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
|
||
|
|
|
||
|
|
return vec4(position, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
vec2 filterTextureCoord( void )
|
||
|
|
{
|
||
|
|
return aPosition * (uOutputFrame.zw * uInputSize.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
void main(void)
|
||
|
|
{
|
||
|
|
gl_Position = filterVertexPosition();
|
||
|
|
vTextureCoord = filterTextureCoord();
|
||
|
|
}
|
||
|
|
`,Z_=`
|
||
|
|
struct GlobalFilterUniforms {
|
||
|
|
uInputSize:vec4<f32>,
|
||
|
|
uInputPixel:vec4<f32>,
|
||
|
|
uInputClamp:vec4<f32>,
|
||
|
|
uOutputFrame:vec4<f32>,
|
||
|
|
uGlobalFrame:vec4<f32>,
|
||
|
|
uOutputTexture:vec4<f32>,
|
||
|
|
};
|
||
|
|
|
||
|
|
struct BlendUniforms {
|
||
|
|
uBlend:f32,
|
||
|
|
};
|
||
|
|
|
||
|
|
@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
|
||
|
|
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
||
|
|
@group(0) @binding(2) var uSampler : sampler;
|
||
|
|
@group(0) @binding(3) var uBackTexture: texture_2d<f32>;
|
||
|
|
|
||
|
|
@group(1) @binding(0) var<uniform> blendUniforms : BlendUniforms;
|
||
|
|
|
||
|
|
|
||
|
|
struct VSOutput {
|
||
|
|
@builtin(position) position: vec4<f32>,
|
||
|
|
@location(0) uv : vec2<f32>
|
||
|
|
};
|
||
|
|
|
||
|
|
fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
|
||
|
|
{
|
||
|
|
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
||
|
|
|
||
|
|
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
||
|
|
position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
|
||
|
|
|
||
|
|
return vec4(position, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
@vertex
|
||
|
|
fn mainVertex(
|
||
|
|
@location(0) aPosition : vec2<f32>,
|
||
|
|
) -> VSOutput {
|
||
|
|
return VSOutput(
|
||
|
|
filterVertexPosition(aPosition),
|
||
|
|
filterTextureCoord(aPosition)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
{FUNCTIONS}
|
||
|
|
|
||
|
|
@fragment
|
||
|
|
fn mainFragment(
|
||
|
|
@location(0) uv: vec2<f32>
|
||
|
|
) -> @location(0) vec4<f32> {
|
||
|
|
|
||
|
|
|
||
|
|
var back = textureSample(uBackTexture, uSampler, uv);
|
||
|
|
var front = textureSample(uTexture, uSampler, uv);
|
||
|
|
var blendedAlpha = front.a + back.a * (1.0 - front.a);
|
||
|
|
|
||
|
|
var out = vec4<f32>(0.0,0.0,0.0,0.0);
|
||
|
|
|
||
|
|
{MAIN}
|
||
|
|
|
||
|
|
return out;
|
||
|
|
}`,CR=Object.defineProperty,Q_=Object.getOwnPropertySymbols,RR=Object.prototype.hasOwnProperty,MR=Object.prototype.propertyIsEnumerable,J_=(r,t,e)=>t in r?CR(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,tx=(r,t)=>{for(var e in t||(t={}))RR.call(t,e)&&J_(r,e,t[e]);if(Q_)for(var e of Q_(t))MR.call(t,e)&&J_(r,e,t[e]);return r};class OR extends Ae{constructor(t){const e=t.gpu,s=ex(tx({source:Z_},e)),i=zt.from({vertex:{source:s,entryPoint:"mainVertex"},fragment:{source:s,entryPoint:"mainFragment"}}),n=t.gl,o=ex(tx({source:K_},n)),a=Yt.from({vertex:q_,fragment:o}),l=new wt({uBlend:{value:1,type:"f32"}});super({gpuProgram:i,glProgram:a,blendRequired:!0,resources:{blendUniforms:l,uBackTexture:B.EMPTY}})}}function ex(r){const{source:t,functions:e,main:s}=r;return t.replace("{FUNCTIONS}",e).replace("{MAIN}",s)}const GR=`
|
||
|
|
float getLuminosity(vec3 c) {
|
||
|
|
return 0.3 * c.r + 0.59 * c.g + 0.11 * c.b;
|
||
|
|
}
|
||
|
|
|
||
|
|
vec3 setLuminosity(vec3 c, float lum) {
|
||
|
|
float modLum = lum - getLuminosity(c);
|
||
|
|
vec3 color = c.rgb + vec3(modLum);
|
||
|
|
|
||
|
|
// clip back into legal range
|
||
|
|
modLum = getLuminosity(color);
|
||
|
|
vec3 modLumVec = vec3(modLum);
|
||
|
|
|
||
|
|
float cMin = min(color.r, min(color.g, color.b));
|
||
|
|
float cMax = max(color.r, max(color.g, color.b));
|
||
|
|
|
||
|
|
if(cMin < 0.0) {
|
||
|
|
color = mix(modLumVec, color, modLum / (modLum - cMin));
|
||
|
|
}
|
||
|
|
|
||
|
|
if(cMax > 1.0) {
|
||
|
|
color = mix(modLumVec, color, (1.0 - modLum) / (cMax - modLum));
|
||
|
|
}
|
||
|
|
|
||
|
|
return color;
|
||
|
|
}
|
||
|
|
|
||
|
|
float getSaturation(vec3 c) {
|
||
|
|
return max(c.r, max(c.g, c.b)) - min(c.r, min(c.g, c.b));
|
||
|
|
}
|
||
|
|
|
||
|
|
vec3 setSaturationMinMidMax(vec3 cSorted, float s) {
|
||
|
|
vec3 colorSorted = cSorted;
|
||
|
|
|
||
|
|
if(colorSorted.z > colorSorted.x) {
|
||
|
|
colorSorted.y = (((colorSorted.y - colorSorted.x) * s) / (colorSorted.z - colorSorted.x));
|
||
|
|
colorSorted.z = s;
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
colorSorted.y = 0.0;
|
||
|
|
colorSorted.z = 0.0;
|
||
|
|
}
|
||
|
|
|
||
|
|
colorSorted.x = 0.0;
|
||
|
|
|
||
|
|
return colorSorted;
|
||
|
|
}
|
||
|
|
|
||
|
|
vec3 setSaturation(vec3 c, float s) {
|
||
|
|
vec3 color = c;
|
||
|
|
|
||
|
|
if(color.r <= color.g && color.r <= color.b) {
|
||
|
|
if(color.g <= color.b) {
|
||
|
|
color = setSaturationMinMidMax(color.rgb, s).rgb;
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
color = setSaturationMinMidMax(color.rbg, s).rbg;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else if(color.g <= color.r && color.g <= color.b) {
|
||
|
|
if(color.r <= color.b) {
|
||
|
|
color = setSaturationMinMidMax(color.grb, s).grb;
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
color = setSaturationMinMidMax(color.gbr, s).gbr;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
// Using bgr for both fixes part of hue
|
||
|
|
if(color.r <= color.g) {
|
||
|
|
color = setSaturationMinMidMax(color.brg, s).brg;
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
color = setSaturationMinMidMax(color.bgr, s).bgr;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return color;
|
||
|
|
}
|
||
|
|
`,IR=`
|
||
|
|
fn getLuminosity(c: vec3<f32>) -> f32
|
||
|
|
{
|
||
|
|
return 0.3*c.r + 0.59*c.g + 0.11*c.b;
|
||
|
|
}
|
||
|
|
|
||
|
|
fn setLuminosity(c: vec3<f32>, lum: f32) -> vec3<f32>
|
||
|
|
{
|
||
|
|
var modLum: f32 = lum - getLuminosity(c);
|
||
|
|
var color: vec3<f32> = c.rgb + modLum;
|
||
|
|
|
||
|
|
// clip back into legal range
|
||
|
|
modLum = getLuminosity(color);
|
||
|
|
let modLumVec = vec3<f32>(modLum);
|
||
|
|
|
||
|
|
let cMin: f32 = min(color.r, min(color.g, color.b));
|
||
|
|
let cMax: f32 = max(color.r, max(color.g, color.b));
|
||
|
|
|
||
|
|
if(cMin < 0.0)
|
||
|
|
{
|
||
|
|
color = mix(modLumVec, color, modLum / (modLum - cMin));
|
||
|
|
}
|
||
|
|
|
||
|
|
if(cMax > 1.0)
|
||
|
|
{
|
||
|
|
color = mix(modLumVec, color, (1 - modLum) / (cMax - modLum));
|
||
|
|
}
|
||
|
|
|
||
|
|
return color;
|
||
|
|
}
|
||
|
|
|
||
|
|
fn getSaturation(c: vec3<f32>) -> f32
|
||
|
|
{
|
||
|
|
return max(c.r, max(c.g, c.b)) - min(c.r, min(c.g, c.b));
|
||
|
|
}
|
||
|
|
|
||
|
|
fn setSaturationMinMidMax(cSorted: vec3<f32>, s: f32) -> vec3<f32>
|
||
|
|
{
|
||
|
|
var colorSorted = cSorted;
|
||
|
|
|
||
|
|
if(colorSorted.z > colorSorted.x)
|
||
|
|
{
|
||
|
|
colorSorted.y = (((colorSorted.y - colorSorted.x) * s) / (colorSorted.z - colorSorted.x));
|
||
|
|
colorSorted.z = s;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
colorSorted.y = 0;
|
||
|
|
colorSorted.z = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
colorSorted.x = 0;
|
||
|
|
|
||
|
|
return colorSorted;
|
||
|
|
}
|
||
|
|
|
||
|
|
fn setSaturation(c: vec3<f32>, s: f32) -> vec3<f32>
|
||
|
|
{
|
||
|
|
var color = c;
|
||
|
|
|
||
|
|
if (color.r <= color.g && color.r <= color.b)
|
||
|
|
{
|
||
|
|
if (color.g <= color.b)
|
||
|
|
{
|
||
|
|
color = vec3<f32>(setSaturationMinMidMax(color.rgb, s)).rgb;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
color = vec3<f32>(setSaturationMinMidMax(color.rbg, s)).rbg;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else if (color.g <= color.r && color.g <= color.b)
|
||
|
|
{
|
||
|
|
if (color.r <= color.b)
|
||
|
|
{
|
||
|
|
color = vec3<f32>(setSaturationMinMidMax(color.grb, s)).grb;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
color = vec3<f32>(setSaturationMinMidMax(color.gbr, s)).gbr;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
// Using bgr for both fixes part of hue
|
||
|
|
if (color.r <= color.g)
|
||
|
|
{
|
||
|
|
color = vec3<f32>(setSaturationMinMidMax(color.brg, s)).brg;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
color = vec3<f32>(setSaturationMinMidMax(color.bgr, s)).bgr;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return color;
|
||
|
|
}
|
||
|
|
`;var rx=`
|
||
|
|
in vec2 vTextureCoord;
|
||
|
|
|
||
|
|
out vec4 finalColor;
|
||
|
|
|
||
|
|
uniform float uAlpha;
|
||
|
|
uniform sampler2D uTexture;
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
finalColor = texture(uTexture, vTextureCoord) * uAlpha;
|
||
|
|
}
|
||
|
|
`,tu=`struct GlobalFilterUniforms {
|
||
|
|
uInputSize:vec4<f32>,
|
||
|
|
uInputPixel:vec4<f32>,
|
||
|
|
uInputClamp:vec4<f32>,
|
||
|
|
uOutputFrame:vec4<f32>,
|
||
|
|
uGlobalFrame:vec4<f32>,
|
||
|
|
uOutputTexture:vec4<f32>,
|
||
|
|
};
|
||
|
|
|
||
|
|
struct AlphaUniforms {
|
||
|
|
uAlpha:f32,
|
||
|
|
};
|
||
|
|
|
||
|
|
@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
|
||
|
|
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
||
|
|
@group(0) @binding(2) var uSampler : sampler;
|
||
|
|
|
||
|
|
@group(1) @binding(0) var<uniform> alphaUniforms : AlphaUniforms;
|
||
|
|
|
||
|
|
struct VSOutput {
|
||
|
|
@builtin(position) position: vec4<f32>,
|
||
|
|
@location(0) uv : vec2<f32>
|
||
|
|
};
|
||
|
|
|
||
|
|
fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
|
||
|
|
{
|
||
|
|
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
||
|
|
|
||
|
|
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
||
|
|
position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
|
||
|
|
|
||
|
|
return vec4(position, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn getSize() -> vec2<f32>
|
||
|
|
{
|
||
|
|
return gfu.uGlobalFrame.zw;
|
||
|
|
}
|
||
|
|
|
||
|
|
@vertex
|
||
|
|
fn mainVertex(
|
||
|
|
@location(0) aPosition : vec2<f32>,
|
||
|
|
) -> VSOutput {
|
||
|
|
return VSOutput(
|
||
|
|
filterVertexPosition(aPosition),
|
||
|
|
filterTextureCoord(aPosition)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
@fragment
|
||
|
|
fn mainFragment(
|
||
|
|
@location(0) uv: vec2<f32>,
|
||
|
|
@builtin(position) position: vec4<f32>
|
||
|
|
) -> @location(0) vec4<f32> {
|
||
|
|
|
||
|
|
var sample = textureSample(uTexture, uSampler, uv);
|
||
|
|
|
||
|
|
return sample * alphaUniforms.uAlpha;
|
||
|
|
}`,FR=Object.defineProperty,BR=Object.defineProperties,DR=Object.getOwnPropertyDescriptors,xn=Object.getOwnPropertySymbols,sx=Object.prototype.hasOwnProperty,ix=Object.prototype.propertyIsEnumerable,nx=(r,t,e)=>t in r?FR(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,eu=(r,t)=>{for(var e in t||(t={}))sx.call(t,e)&&nx(r,e,t[e]);if(xn)for(var e of xn(t))ix.call(t,e)&&nx(r,e,t[e]);return r},$R=(r,t)=>BR(r,DR(t)),UR=(r,t)=>{var e={};for(var s in r)sx.call(r,s)&&t.indexOf(s)<0&&(e[s]=r[s]);if(r!=null&&xn)for(var s of xn(r))t.indexOf(s)<0&&ix.call(r,s)&&(e[s]=r[s]);return e};const ox=class lS extends Ae{constructor(t){t=eu(eu({},lS.defaultOptions),t);const e=zt.from({vertex:{source:tu,entryPoint:"mainVertex"},fragment:{source:tu,entryPoint:"mainFragment"}}),s=Yt.from({vertex:Ps,fragment:rx,name:"alpha-filter"}),i=t,{alpha:n}=i,o=UR(i,["alpha"]),a=new wt({uAlpha:{value:n,type:"f32"}});super($R(eu({},o),{gpuProgram:e,glProgram:s,resources:{alphaUniforms:a}}))}get alpha(){return this.resources.alphaUniforms.uniforms.uAlpha}set alpha(t){this.resources.alphaUniforms.uniforms.uAlpha=t}};ox.defaultOptions={alpha:1};let kR=ox;const ru={5:[.153388,.221461,.250301],7:[.071303,.131514,.189879,.214607],9:[.028532,.067234,.124009,.179044,.20236],11:[.0093,.028002,.065984,.121703,.175713,.198596],13:[.002406,.009255,.027867,.065666,.121117,.174868,.197641],15:[489e-6,.002403,.009246,.02784,.065602,.120999,.174697,.197448]},LR=["in vec2 vBlurTexCoords[%size%];","uniform sampler2D uTexture;","uniform vec4 uInputClamp;","out vec4 finalColor;","void main(void)","{"," %blur%","}"].join(`
|
||
|
|
`);function ax(r){const t=ru[r],e=t.length;let s="";const i="finalColor = ",n=" + ",o="texture(uTexture, clamp(vBlurTexCoords[%index%], uInputClamp.xy, uInputClamp.zw)) * %value%";for(let a=0;a<r;a++){const l=a===0?i:n,u=a<e?a:r-a-1,h=o.replace("%index%",a.toString()).replace("%value%",t[u].toString());s+=`${l}${h}
|
||
|
|
`}return LR.replace("%blur%",`${s};`).replace("%size%",r.toString())}const NR=`
|
||
|
|
in vec2 aPosition;
|
||
|
|
|
||
|
|
uniform float uStrength;
|
||
|
|
|
||
|
|
out vec2 vBlurTexCoords[%size%];
|
||
|
|
|
||
|
|
uniform vec4 uInputSize;
|
||
|
|
uniform vec4 uOutputFrame;
|
||
|
|
uniform vec4 uOutputTexture;
|
||
|
|
|
||
|
|
vec4 filterVertexPosition( void )
|
||
|
|
{
|
||
|
|
vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
|
||
|
|
|
||
|
|
position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
|
||
|
|
position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
|
||
|
|
|
||
|
|
return vec4(position, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
vec2 filterTextureCoord( void )
|
||
|
|
{
|
||
|
|
return aPosition * (uOutputFrame.zw * uInputSize.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
void main(void)
|
||
|
|
{
|
||
|
|
gl_Position = filterVertexPosition();
|
||
|
|
|
||
|
|
float pixelStrength = uInputSize.%dimension% * uStrength;
|
||
|
|
|
||
|
|
vec2 textureCoord = filterTextureCoord();
|
||
|
|
%blur%
|
||
|
|
}`;function lx(r,t){const e=Math.ceil(r/2);let s=NR,i="",n;t?n="vBlurTexCoords[%index%] = textureCoord + vec2(%sampleIndex% * pixelStrength, 0.0);":n="vBlurTexCoords[%index%] = textureCoord + vec2(0.0, %sampleIndex% * pixelStrength);";for(let o=0;o<r;o++){let a=n.replace("%index%",o.toString());a=a.replace("%sampleIndex%",`${o-(e-1)}.0`),i+=a,i+=`
|
||
|
|
`}return s=s.replace("%blur%",i),s=s.replace("%size%",r.toString()),s=s.replace("%dimension%",t?"z":"w"),s}function ux(r,t){const e=lx(t,r),s=ax(t);return Yt.from({vertex:e,fragment:s,name:`blur-${r?"horizontal":"vertical"}-pass-filter`})}var hx=`
|
||
|
|
|
||
|
|
struct GlobalFilterUniforms {
|
||
|
|
uInputSize:vec4<f32>,
|
||
|
|
uInputPixel:vec4<f32>,
|
||
|
|
uInputClamp:vec4<f32>,
|
||
|
|
uOutputFrame:vec4<f32>,
|
||
|
|
uGlobalFrame:vec4<f32>,
|
||
|
|
uOutputTexture:vec4<f32>,
|
||
|
|
};
|
||
|
|
|
||
|
|
struct BlurUniforms {
|
||
|
|
uStrength:f32,
|
||
|
|
};
|
||
|
|
|
||
|
|
@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
|
||
|
|
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
||
|
|
@group(0) @binding(2) var uSampler : sampler;
|
||
|
|
|
||
|
|
@group(1) @binding(0) var<uniform> blurUniforms : BlurUniforms;
|
||
|
|
|
||
|
|
|
||
|
|
struct VSOutput {
|
||
|
|
@builtin(position) position: vec4<f32>,
|
||
|
|
%blur-struct%
|
||
|
|
};
|
||
|
|
|
||
|
|
fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
|
||
|
|
{
|
||
|
|
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
||
|
|
|
||
|
|
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
||
|
|
position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
|
||
|
|
|
||
|
|
return vec4(position, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn getSize() -> vec2<f32>
|
||
|
|
{
|
||
|
|
return gfu.uGlobalFrame.zw;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@vertex
|
||
|
|
fn mainVertex(
|
||
|
|
@location(0) aPosition : vec2<f32>,
|
||
|
|
) -> VSOutput {
|
||
|
|
|
||
|
|
let filteredCord = filterTextureCoord(aPosition);
|
||
|
|
|
||
|
|
let pixelStrength = gfu.uInputSize.%dimension% * blurUniforms.uStrength;
|
||
|
|
|
||
|
|
return VSOutput(
|
||
|
|
filterVertexPosition(aPosition),
|
||
|
|
%blur-vertex-out%
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
@fragment
|
||
|
|
fn mainFragment(
|
||
|
|
@builtin(position) position: vec4<f32>,
|
||
|
|
%blur-fragment-in%
|
||
|
|
) -> @location(0) vec4<f32> {
|
||
|
|
|
||
|
|
var finalColor = vec4(0.0);
|
||
|
|
|
||
|
|
%blur-sampling%
|
||
|
|
|
||
|
|
return finalColor;
|
||
|
|
}
|
||
|
|
`;function cx(r,t){const e=ru[t],s=e.length,i=[],n=[],o=[];for(let c=0;c<t;c++){i[c]=`@location(${c}) offset${c}: vec2<f32>,`,r?n[c]=`filteredCord + vec2(${c-s+1} * pixelStrength, 0.0),`:n[c]=`filteredCord + vec2(0.0, ${c-s+1} * pixelStrength),`;const d=c<s?c:t-c-1,p=e[d].toString();o[c]=`finalColor += textureSample(uTexture, uSampler,
|
||
|
|
clamp(offset${c}, gfu.uInputClamp.xy, gfu.uInputClamp.zw)) * ${p};`}const a=i.join(`
|
||
|
|
`),l=n.join(`
|
||
|
|
`),u=o.join(`
|
||
|
|
`),h=hx.replace("%blur-struct%",a).replace("%blur-vertex-out%",l).replace("%blur-fragment-in%",a).replace("%blur-sampling%",u).replace("%dimension%",r?"z":"w");return zt.from({vertex:{source:h,entryPoint:"mainVertex"},fragment:{source:h,entryPoint:"mainFragment"}})}var jR=Object.defineProperty,dx=Object.getOwnPropertySymbols,XR=Object.prototype.hasOwnProperty,HR=Object.prototype.propertyIsEnumerable,px=(r,t,e)=>t in r?jR(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,su=(r,t)=>{for(var e in t||(t={}))XR.call(t,e)&&px(r,e,t[e]);if(dx)for(var e of dx(t))HR.call(t,e)&&px(r,e,t[e]);return r};const fx=class uS extends Ae{constructor(t){var e;t=su(su({},uS.defaultOptions),t);const s=ux(t.horizontal,t.kernelSize),i=cx(t.horizontal,t.kernelSize);super(su({glProgram:s,gpuProgram:i,resources:{blurUniforms:{uStrength:{value:0,type:"f32"}}}},t)),this.horizontal=t.horizontal,this.legacy=(e=t.legacy)!=null?e:!1,this._quality=0,this.quality=t.quality,this.blur=t.strength,this._blurUniforms=this.resources.blurUniforms,this._uniforms=this._blurUniforms.uniforms}apply(t,e,s,i){this.legacy?this._applyLegacy(t,e,s,i):this._applyOptimized(t,e,s,i)}_applyLegacy(t,e,s,i){if(this._uniforms.uStrength=this.strength/this.passes,this.passes===1)t.applyFilter(this,e,s,i);else{const n=ft.getSameSizeTexture(e);let o=e,a=n;this._state.blend=!1;const l=t.renderer.type===Mt.WEBGPU;for(let u=0;u<this.passes-1;u++){t.applyFilter(this,o,a,u===0?!0:l);const h=a;a=o,o=h}this._state.blend=!0,t.applyFilter(this,o,s,i),ft.returnTexture(n)}}_applyOptimized(t,e,s,i){if(this._uniforms.uStrength=this._calculateInitialStrength(),this.passes===1)t.applyFilter(this,e,s,i);else{const n=ft.getSameSizeTexture(e);let o=e,a=n;this._state.blend=!1;const l=t.renderer,u=l.type===Mt.WEBGPU,h=u?l.renderPipes.uniformBatch:null;for(let c=0;c<this.passes-1;c++){h&&this.groups[1].setResource(h.getUboResource(this._blurUniforms),0),t.applyFilter(this,o,a,u);const d=a;a=o,o=d,this._uniforms.uStrength*=.5}h&&this.groups[1].setResource(h.getUboResource(this._blurUniforms),0),this._state.blend=!0,t.applyFilter(this,o,s,i),ft.returnTexture(n)}}_calculateInitialStrength(){let t=1,e=.5;for(let s=1;s<this.passes;s++)t+=e*e,e*=.5;return this.strength/Math.sqrt(t)}get blur(){return this.strength}set blur(t){this.padding=1+Math.abs(t)*2,this.strength=t}get quality(){return this._quality}set quality(t){this._quality=t,this.passes=t}};fx.defaultOptions={strength:8,quality:4,kernelSize:5,legacy:!1};let vn=fx;var zR=Object.defineProperty,WR=Object.defineProperties,VR=Object.getOwnPropertyDescriptors,bn=Object.getOwnPropertySymbols,mx=Object.prototype.hasOwnProperty,gx=Object.prototype.propertyIsEnumerable,_x=(r,t,e)=>t in r?zR(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ks=(r,t)=>{for(var e in t||(t={}))mx.call(t,e)&&_x(r,e,t[e]);if(bn)for(var e of bn(t))gx.call(t,e)&&_x(r,e,t[e]);return r},YR=(r,t)=>WR(r,VR(t)),KR=(r,t)=>{var e={};for(var s in r)mx.call(r,s)&&t.indexOf(s)<0&&(e[s]=r[s]);if(r!=null&&bn)for(var s of bn(r))t.indexOf(s)<0&&gx.call(r,s)&&(e[s]=r[s]);return e};class xx extends Ae{constructor(...t){var e;let s=(e=t[0])!=null?e:{};typeof s=="number"&&(s={strength:s},t[1]!==void 0&&(s.quality=t[1]),t[2]!==void 0&&(s.resolution=t[2]||"inherit"),t[3]!==void 0&&(s.kernelSize=t[3])),s=Ks(Ks({},vn.defaultOptions),s);const i=s,{strength:n,strengthX:o,strengthY:a,quality:l}=i,u=KR(i,["strength","strengthX","strengthY","quality"]);super(YR(Ks({},u),{compatibleRenderers:Mt.BOTH,resources:{}})),this._repeatEdgePixels=!1,this.blurXFilter=new vn(Ks({horizontal:!0},s)),this.blurYFilter=new vn(Ks({horizontal:!1},s)),this.quality=l,this.strengthX=o!=null?o:n,this.strengthY=a!=null?a:n,this.repeatEdgePixels=!1}apply(t,e,s,i){const n=Math.abs(this.blurXFilter.strength),o=Math.abs(this.blurYFilter.strength);if(n&&o){const a=ft.getSameSizeTexture(e);this.blurXFilter.blendMode="normal",this.blurXFilter.apply(t,e,a,!0),this.blurYFilter.blendMode=this.blendMode,this.blurYFilter.apply(t,a,s,i),ft.returnTexture(a)}else o?(this.blurYFilter.blendMode=this.blendMode,this.blurYFi
|
||
|
|
in vec2 vTextureCoord;
|
||
|
|
in vec4 vColor;
|
||
|
|
|
||
|
|
out vec4 finalColor;
|
||
|
|
|
||
|
|
uniform float uColorMatrix[20];
|
||
|
|
uniform float uAlpha;
|
||
|
|
|
||
|
|
uniform sampler2D uTexture;
|
||
|
|
|
||
|
|
float rand(vec2 co)
|
||
|
|
{
|
||
|
|
return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
|
||
|
|
}
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 color = texture(uTexture, vTextureCoord);
|
||
|
|
float randomValue = rand(gl_FragCoord.xy * 0.2);
|
||
|
|
float diff = (randomValue - 0.5) * 0.5;
|
||
|
|
|
||
|
|
if (uAlpha == 0.0) {
|
||
|
|
finalColor = color;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (color.a > 0.0) {
|
||
|
|
color.rgb /= color.a;
|
||
|
|
}
|
||
|
|
|
||
|
|
vec4 result;
|
||
|
|
|
||
|
|
result.r = (uColorMatrix[0] * color.r);
|
||
|
|
result.r += (uColorMatrix[1] * color.g);
|
||
|
|
result.r += (uColorMatrix[2] * color.b);
|
||
|
|
result.r += (uColorMatrix[3] * color.a);
|
||
|
|
result.r += uColorMatrix[4];
|
||
|
|
|
||
|
|
result.g = (uColorMatrix[5] * color.r);
|
||
|
|
result.g += (uColorMatrix[6] * color.g);
|
||
|
|
result.g += (uColorMatrix[7] * color.b);
|
||
|
|
result.g += (uColorMatrix[8] * color.a);
|
||
|
|
result.g += uColorMatrix[9];
|
||
|
|
|
||
|
|
result.b = (uColorMatrix[10] * color.r);
|
||
|
|
result.b += (uColorMatrix[11] * color.g);
|
||
|
|
result.b += (uColorMatrix[12] * color.b);
|
||
|
|
result.b += (uColorMatrix[13] * color.a);
|
||
|
|
result.b += uColorMatrix[14];
|
||
|
|
|
||
|
|
result.a = (uColorMatrix[15] * color.r);
|
||
|
|
result.a += (uColorMatrix[16] * color.g);
|
||
|
|
result.a += (uColorMatrix[17] * color.b);
|
||
|
|
result.a += (uColorMatrix[18] * color.a);
|
||
|
|
result.a += uColorMatrix[19];
|
||
|
|
|
||
|
|
vec3 rgb = mix(color.rgb, result.rgb, uAlpha);
|
||
|
|
|
||
|
|
// Premultiply alpha again.
|
||
|
|
rgb *= result.a;
|
||
|
|
|
||
|
|
finalColor = vec4(rgb, result.a);
|
||
|
|
}
|
||
|
|
`,iu=`struct GlobalFilterUniforms {
|
||
|
|
uInputSize:vec4<f32>,
|
||
|
|
uInputPixel:vec4<f32>,
|
||
|
|
uInputClamp:vec4<f32>,
|
||
|
|
uOutputFrame:vec4<f32>,
|
||
|
|
uGlobalFrame:vec4<f32>,
|
||
|
|
uOutputTexture:vec4<f32>,
|
||
|
|
};
|
||
|
|
|
||
|
|
struct ColorMatrixUniforms {
|
||
|
|
uColorMatrix:array<vec4<f32>, 5>,
|
||
|
|
uAlpha:f32,
|
||
|
|
};
|
||
|
|
|
||
|
|
|
||
|
|
@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
|
||
|
|
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
||
|
|
@group(0) @binding(2) var uSampler : sampler;
|
||
|
|
@group(1) @binding(0) var<uniform> colorMatrixUniforms : ColorMatrixUniforms;
|
||
|
|
|
||
|
|
|
||
|
|
struct VSOutput {
|
||
|
|
@builtin(position) position: vec4<f32>,
|
||
|
|
@location(0) uv : vec2<f32>,
|
||
|
|
};
|
||
|
|
|
||
|
|
fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
|
||
|
|
{
|
||
|
|
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
||
|
|
|
||
|
|
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
||
|
|
position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
|
||
|
|
|
||
|
|
return vec4(position, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
@vertex
|
||
|
|
fn mainVertex(
|
||
|
|
@location(0) aPosition : vec2<f32>,
|
||
|
|
) -> VSOutput {
|
||
|
|
return VSOutput(
|
||
|
|
filterVertexPosition(aPosition),
|
||
|
|
filterTextureCoord(aPosition),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@fragment
|
||
|
|
fn mainFragment(
|
||
|
|
@location(0) uv: vec2<f32>,
|
||
|
|
) -> @location(0) vec4<f32> {
|
||
|
|
|
||
|
|
|
||
|
|
var c = textureSample(uTexture, uSampler, uv);
|
||
|
|
|
||
|
|
if (colorMatrixUniforms.uAlpha == 0.0) {
|
||
|
|
return c;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
// Un-premultiply alpha before applying the color matrix. See issue #3539.
|
||
|
|
if (c.a > 0.0) {
|
||
|
|
c.r /= c.a;
|
||
|
|
c.g /= c.a;
|
||
|
|
c.b /= c.a;
|
||
|
|
}
|
||
|
|
|
||
|
|
var cm = colorMatrixUniforms.uColorMatrix;
|
||
|
|
|
||
|
|
|
||
|
|
var result = vec4<f32>(0.);
|
||
|
|
|
||
|
|
result.r = (cm[0][0] * c.r);
|
||
|
|
result.r += (cm[0][1] * c.g);
|
||
|
|
result.r += (cm[0][2] * c.b);
|
||
|
|
result.r += (cm[0][3] * c.a);
|
||
|
|
result.r += cm[1][0];
|
||
|
|
|
||
|
|
result.g = (cm[1][1] * c.r);
|
||
|
|
result.g += (cm[1][2] * c.g);
|
||
|
|
result.g += (cm[1][3] * c.b);
|
||
|
|
result.g += (cm[2][0] * c.a);
|
||
|
|
result.g += cm[2][1];
|
||
|
|
|
||
|
|
result.b = (cm[2][2] * c.r);
|
||
|
|
result.b += (cm[2][3] * c.g);
|
||
|
|
result.b += (cm[3][0] * c.b);
|
||
|
|
result.b += (cm[3][1] * c.a);
|
||
|
|
result.b += cm[3][2];
|
||
|
|
|
||
|
|
result.a = (cm[3][3] * c.r);
|
||
|
|
result.a += (cm[4][0] * c.g);
|
||
|
|
result.a += (cm[4][1] * c.b);
|
||
|
|
result.a += (cm[4][2] * c.a);
|
||
|
|
result.a += cm[4][3];
|
||
|
|
|
||
|
|
var rgb = mix(c.rgb, result.rgb, colorMatrixUniforms.uAlpha);
|
||
|
|
|
||
|
|
rgb.r *= result.a;
|
||
|
|
rgb.g *= result.a;
|
||
|
|
rgb.b *= result.a;
|
||
|
|
|
||
|
|
return vec4(rgb, result.a);
|
||
|
|
}`,qR=Object.defineProperty,ZR=Object.defineProperties,QR=Object.getOwnPropertyDescriptors,bx=Object.getOwnPropertySymbols,JR=Object.prototype.hasOwnProperty,tM=Object.prototype.propertyIsEnumerable,yx=(r,t,e)=>t in r?qR(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,eM=(r,t)=>{for(var e in t||(t={}))JR.call(t,e)&&yx(r,e,t[e]);if(bx)for(var e of bx(t))tM.call(t,e)&&yx(r,e,t[e]);return r},rM=(r,t)=>ZR(r,QR(t));class sM extends Ae{constructor(t={}){const e=new wt({uColorMatrix:{value:[1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0],type:"f32",size:20},uAlpha:{value:1,type:"f32"}}),s=zt.from({vertex:{source:iu,entryPoint:"mainVertex"},fragment:{source:iu,entryPoint:"mainFragment"}}),i=Yt.from({vertex:Ps,fragment:vx,name:"color-matrix-filter"});super(rM(eM({},t),{gpuProgram:s,glProgram:i,resources:{colorMatrixUniforms:e}})),this.alpha=1}_loadMatrix(t,e=!1){if(e){const s=[...t];this._multiply(s,this.matrix,t),this.resources.colorMatrixUniforms.uniforms.uColorMatrix=s}else this.resources.colorMatrixUniforms.uniforms.uColorMatrix=t;this.resources.colorMatrixUniforms.update()}_multiply(t,e,s){return t[0]=e[0]*s[0]+e[1]*s[5]+e[2]*s[10]+e[3]*s[15],t[1]=e[0]*s[1]+e[1]*s[6]+e[2]*s[11]+e[3]*s[16],t[2]=e[0]*s[2]+e[1]*s[7]+e[2]*s[12]+e[3]*s[17],t[3]=e[0]*s[3]+e[1]*s[8]+e[2]*s[13]+e[3]*s[18],t[4]=e[0]*s[4]+e[1]*s[9]+e[2]*s[14]+e[3]*s[19]+e[4],t[5]=e[5]*s[0]+e[6]*s[5]+e[7]*s[10]+e[8]*s[15],t[6]=e[5]*s[1]+e[6]*s[6]+e[7]*s[11]+e[8]*s[16],t[7]=e[5]*s[2]+e[6]*s[7]+e[7]*s[12]+e[8]*s[17],t[8]=e[5]*s[3]+e[6]*s[8]+e[7]*s[13]+e[8]*s[18],t[9]=e[5]*s[4]+e[6]*s[9]+e[7]*s[14]+e[8]*s[19]+e[9],t[10]=e[10]*s[0]+e[11]*s[5]+e[12]*s[10]+e[13]*s[15],t[11]=e[10]*s[1]+e[11]*s[6]+e[12]*s[11]+e[13]*s[16],t[12]=e[10]*s[2]+e[11]*s[7]+e[12]*s[12]+e[13]*s[17],t[13]=e[10]*s[3]+e[11]*s[8]+e[12]*s[13]+e[13]*s[18],t[14]=e[10]*s[4]+e[11]*s[9]+e[12]*s[14]+e[13]*s[19]+e[14],t[15]=e[15]*s[0]+e[16]*s[5]+e[17]*s[10]+e[18]*s[15],t[16]=e[15]*s[1]+e[16]*s[6]+e[17]*s[11]+e[18]*s[16],t[17]=e[15]*s[2]+e[16]*s[7]+e[17]*s[12]+e[18]*s[17],t[18]=e[15]*s[3]+e[16]*s[8]+e[17]*s[13]+e[18]*s[18],t[19]=e[15]*s[4]+e[16]*s[9]+e[17]*s[14]+e[18]*s[19]+e[19],t}brightness(t,e){const s=[t,0,0,0,0,0,t,0,0,0,0,0,t,0,0,0,0,0,1,0];this._loadMatrix(s,e)}tint(t,e){const[s,i,n]=tt.shared.setValue(t).toArray(),o=[s,0,0,0,0,0,i,0,0,0,0,0,n,0,0,0,0,0,1,0];this._loadMatrix(o,e)}greyscale(t,e){const s=[t,t,t,0,0,t,t,t,0,0,t,t,t,0,0,0,0,0,1,0];this._loadMatrix(s,e)}grayscale(t,e){this.greyscale(t,e)}blackAndWhite(t){const e=[.3,.6,.1,0,0,.3,.6,.1,0,0,.3,.6,.1,0,0,0,0,0,1,0];this._loadMatrix(e,t)}hue(t,e){t=(t||0)/180*Math.PI;const s=Math.cos(t),i=Math.sin(t),n=Math.sqrt,o=1/3,a=n(o),l=s+(1-s)*o,u=o*(1-s)-a*i,h=o*(1-s)+a*i,c=o*(1-s)+a*i,d=s+o*(1-s),p=o*(1-s)-a*i,f=o*(1-s)-a*i,m=o*(1-s)+a*i,g=s+o*(1-s),_=[l,u,h,0,0,c,d,p,0,0,f,m,g,0,0,0,0,0,1,0];this._loadMatrix(_,e)}contrast(t,e){const s=(t||0)+1,i=-.5*(s-1),n=[s,0,0,0,i,0,s,0,0,i,0,0,s,0,i,0,0,0,1,0];this._loadMatrix(n,e)}saturate(t=0,e){const s=t*2/3+1,i=(s-1)*-.5,n=[s,i,i,0,0,i,s,i,0,0,i,i,s,0,0,0,0,0,1,0];this._loadMatrix(n,e)}desaturate(){this.saturate(-1)}negative(t){const e=[-1,0,0,1,0,0,-1,0,1,0,0,0,-1,1,0,0,0,0,1,0];this._loadMatrix(e,t)}sepia(t){const e=[.393,.7689999,.18899999,0,0,.349,.6859999,.16799999,0,0,.272,.5339999,.13099999,0,0,0,0,0,1,0];this._loadMatrix(e,t)}technicolor(t){const e=[1.9125277891456083,-.8545344976951645,-.09155508482755585,0,.046249425232852304,-.3087833385928097,1.7658908555458428,-.10601743074722245,0,-.2758903984886823,-.231103377548616,-.7501899197440212,1.847597816108189,0,.12137623870388682,0,0,0,1,0];this._loadMatrix(e,t)}polaroid(t){const e=[1.438,-.062,-.062,0,0,-.122,1.378,-.122,0,0,-.016,-.016,1.483,0,0,0,0,0,1,0];this._loadMatrix(e,t)}toBGR(t){const e=[0,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0];this._loadMatrix(e,t)}kodachrome(t){const e=[1.1285582396593525,-.3967382283601348,-.03992559172921793,0,.24991995145868634,-.16404339962244616,1.0835251566291304,-.05498805115633132,0,.09698983488904393,-.16786010706155763,-.5603416277695248,1.6014850761964943,0,.13972481597886063,0,0,0,1,0];this._loadMatrix(e,t)
|
||
|
|
in vec2 vTextureCoord;
|
||
|
|
in vec2 vFilterUv;
|
||
|
|
|
||
|
|
out vec4 finalColor;
|
||
|
|
|
||
|
|
uniform sampler2D uTexture;
|
||
|
|
uniform sampler2D uMapTexture;
|
||
|
|
|
||
|
|
uniform vec4 uInputClamp;
|
||
|
|
uniform highp vec4 uInputSize;
|
||
|
|
uniform mat2 uRotation;
|
||
|
|
uniform vec2 uScale;
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 map = texture(uMapTexture, vFilterUv);
|
||
|
|
|
||
|
|
vec2 offset = uInputSize.zw * (uRotation * (map.xy - 0.5)) * uScale;
|
||
|
|
|
||
|
|
finalColor = texture(uTexture, clamp(vTextureCoord + offset, uInputClamp.xy, uInputClamp.zw));
|
||
|
|
}
|
||
|
|
`,Sx=`in vec2 aPosition;
|
||
|
|
out vec2 vTextureCoord;
|
||
|
|
out vec2 vFilterUv;
|
||
|
|
|
||
|
|
|
||
|
|
uniform vec4 uInputSize;
|
||
|
|
uniform vec4 uOutputFrame;
|
||
|
|
uniform vec4 uOutputTexture;
|
||
|
|
|
||
|
|
uniform mat3 uFilterMatrix;
|
||
|
|
|
||
|
|
vec4 filterVertexPosition( void )
|
||
|
|
{
|
||
|
|
vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
|
||
|
|
|
||
|
|
position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
|
||
|
|
position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
|
||
|
|
|
||
|
|
return vec4(position, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
vec2 filterTextureCoord( void )
|
||
|
|
{
|
||
|
|
return aPosition * (uOutputFrame.zw * uInputSize.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
vec2 getFilterCoord( void )
|
||
|
|
{
|
||
|
|
return ( uFilterMatrix * vec3( filterTextureCoord(), 1.0) ).xy;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
void main(void)
|
||
|
|
{
|
||
|
|
gl_Position = filterVertexPosition();
|
||
|
|
vTextureCoord = filterTextureCoord();
|
||
|
|
vFilterUv = getFilterCoord();
|
||
|
|
}
|
||
|
|
`,nu=`
|
||
|
|
struct GlobalFilterUniforms {
|
||
|
|
uInputSize:vec4<f32>,
|
||
|
|
uInputPixel:vec4<f32>,
|
||
|
|
uInputClamp:vec4<f32>,
|
||
|
|
uOutputFrame:vec4<f32>,
|
||
|
|
uGlobalFrame:vec4<f32>,
|
||
|
|
uOutputTexture:vec4<f32>,
|
||
|
|
};
|
||
|
|
|
||
|
|
struct DisplacementUniforms {
|
||
|
|
uFilterMatrix:mat3x3<f32>,
|
||
|
|
uScale:vec2<f32>,
|
||
|
|
uRotation:mat2x2<f32>
|
||
|
|
};
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
|
||
|
|
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
||
|
|
@group(0) @binding(2) var uSampler : sampler;
|
||
|
|
|
||
|
|
@group(1) @binding(0) var<uniform> filterUniforms : DisplacementUniforms;
|
||
|
|
@group(1) @binding(1) var uMapTexture: texture_2d<f32>;
|
||
|
|
@group(1) @binding(2) var uMapSampler : sampler;
|
||
|
|
|
||
|
|
struct VSOutput {
|
||
|
|
@builtin(position) position: vec4<f32>,
|
||
|
|
@location(0) uv : vec2<f32>,
|
||
|
|
@location(1) filterUv : vec2<f32>,
|
||
|
|
};
|
||
|
|
|
||
|
|
fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
|
||
|
|
{
|
||
|
|
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
||
|
|
|
||
|
|
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
||
|
|
position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
|
||
|
|
|
||
|
|
return vec4(position, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn getFilterCoord(aPosition:vec2<f32> ) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return ( filterUniforms.uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;
|
||
|
|
}
|
||
|
|
|
||
|
|
fn getSize() -> vec2<f32>
|
||
|
|
{
|
||
|
|
|
||
|
|
|
||
|
|
return gfu.uGlobalFrame.zw;
|
||
|
|
}
|
||
|
|
|
||
|
|
@vertex
|
||
|
|
fn mainVertex(
|
||
|
|
@location(0) aPosition : vec2<f32>,
|
||
|
|
) -> VSOutput {
|
||
|
|
return VSOutput(
|
||
|
|
filterVertexPosition(aPosition),
|
||
|
|
filterTextureCoord(aPosition),
|
||
|
|
getFilterCoord(aPosition)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
@fragment
|
||
|
|
fn mainFragment(
|
||
|
|
@location(0) uv: vec2<f32>,
|
||
|
|
@location(1) filterUv: vec2<f32>,
|
||
|
|
@builtin(position) position: vec4<f32>
|
||
|
|
) -> @location(0) vec4<f32> {
|
||
|
|
|
||
|
|
var map = textureSample(uMapTexture, uMapSampler, filterUv);
|
||
|
|
|
||
|
|
var offset = gfu.uInputSize.zw * (filterUniforms.uRotation * (map.xy - 0.5)) * filterUniforms.uScale;
|
||
|
|
|
||
|
|
return textureSample(uTexture, uSampler, clamp(uv + offset, gfu.uInputClamp.xy, gfu.uInputClamp.zw));
|
||
|
|
}`,iM=Object.defineProperty,nM=Object.defineProperties,oM=Object.getOwnPropertyDescriptors,yn=Object.getOwnPropertySymbols,wx=Object.prototype.hasOwnProperty,Ex=Object.prototype.propertyIsEnumerable,Ax=(r,t,e)=>t in r?iM(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,aM=(r,t)=>{for(var e in t||(t={}))wx.call(t,e)&&Ax(r,e,t[e]);if(yn)for(var e of yn(t))Ex.call(t,e)&&Ax(r,e,t[e]);return r},lM=(r,t)=>nM(r,oM(t)),uM=(r,t)=>{var e={};for(var s in r)wx.call(r,s)&&t.indexOf(s)<0&&(e[s]=r[s]);if(r!=null&&yn)for(var s of yn(r))t.indexOf(s)<0&&Ex.call(r,s)&&(e[s]=r[s]);return e};class hM extends Ae{constructor(...t){let e=t[0];e instanceof _e&&(e={sprite:e,scale:t[1]});const s=e,{sprite:i,scale:n}=s,o=uM(s,["sprite","scale"]);let a=n!=null?n:20;typeof a=="number"&&(a=new lt(a,a));const l=new wt({uFilterMatrix:{value:new D,type:"mat3x3<f32>"},uScale:{value:a,type:"vec2<f32>"},uRotation:{value:new Float32Array([0,0,0,0]),type:"mat2x2<f32>"}}),u=Yt.from({vertex:Sx,fragment:Tx,name:"displacement-filter"}),h=zt.from({vertex:{source:nu,entryPoint:"mainVertex"},fragment:{source:nu,entryPoint:"mainFragment"}}),c=i.texture.source;super(lM(aM({},o),{gpuProgram:h,glProgram:u,resources:{filterUniforms:l,uMapTexture:c,uMapSampler:c.style}})),this._sprite=e.sprite,this._sprite.renderable=!1}apply(t,e,s,i){const n=this.resources.filterUniforms.uniforms;t.calculateSpriteMatrix(n.uFilterMatrix,this._sprite);const o=this._sprite.worldTransform,a=Math.sqrt(o.a*o.a+o.b*o.b),l=Math.sqrt(o.c*o.c+o.d*o.d);a!==0&&l!==0&&(n.uRotation[0]=o.a/a,n.uRotation[1]=o.b/a,n.uRotation[2]=o.c/l,n.uRotation[3]=o.d/l),this.resources.uMapTexture=this._sprite.texture.source,t.applyFilter(this,e,s,i)}get scale(){return this.resources.filterUniforms.uniforms.uScale}}var Px=`
|
||
|
|
in vec2 vTextureCoord;
|
||
|
|
in vec4 vColor;
|
||
|
|
|
||
|
|
out vec4 finalColor;
|
||
|
|
|
||
|
|
uniform float uNoise;
|
||
|
|
uniform float uSeed;
|
||
|
|
uniform sampler2D uTexture;
|
||
|
|
|
||
|
|
float rand(vec2 co)
|
||
|
|
{
|
||
|
|
return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
|
||
|
|
}
|
||
|
|
|
||
|
|
void main()
|
||
|
|
{
|
||
|
|
vec4 color = texture(uTexture, vTextureCoord);
|
||
|
|
float randomValue = rand(gl_FragCoord.xy * uSeed);
|
||
|
|
float diff = (randomValue - 0.5) * uNoise;
|
||
|
|
|
||
|
|
// Un-premultiply alpha before applying the color matrix. See issue #3539.
|
||
|
|
if (color.a > 0.0) {
|
||
|
|
color.rgb /= color.a;
|
||
|
|
}
|
||
|
|
|
||
|
|
color.r += diff;
|
||
|
|
color.g += diff;
|
||
|
|
color.b += diff;
|
||
|
|
|
||
|
|
// Premultiply alpha again.
|
||
|
|
color.rgb *= color.a;
|
||
|
|
|
||
|
|
finalColor = color;
|
||
|
|
}
|
||
|
|
`,ou=`
|
||
|
|
|
||
|
|
struct GlobalFilterUniforms {
|
||
|
|
uInputSize:vec4<f32>,
|
||
|
|
uInputPixel:vec4<f32>,
|
||
|
|
uInputClamp:vec4<f32>,
|
||
|
|
uOutputFrame:vec4<f32>,
|
||
|
|
uGlobalFrame:vec4<f32>,
|
||
|
|
uOutputTexture:vec4<f32>,
|
||
|
|
};
|
||
|
|
|
||
|
|
struct NoiseUniforms {
|
||
|
|
uNoise:f32,
|
||
|
|
uSeed:f32,
|
||
|
|
};
|
||
|
|
|
||
|
|
@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
|
||
|
|
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
||
|
|
@group(0) @binding(2) var uSampler : sampler;
|
||
|
|
|
||
|
|
@group(1) @binding(0) var<uniform> noiseUniforms : NoiseUniforms;
|
||
|
|
|
||
|
|
struct VSOutput {
|
||
|
|
@builtin(position) position: vec4<f32>,
|
||
|
|
@location(0) uv : vec2<f32>
|
||
|
|
};
|
||
|
|
|
||
|
|
fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
|
||
|
|
{
|
||
|
|
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
||
|
|
|
||
|
|
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
||
|
|
position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
|
||
|
|
|
||
|
|
return vec4(position, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn getSize() -> vec2<f32>
|
||
|
|
{
|
||
|
|
return gfu.uGlobalFrame.zw;
|
||
|
|
}
|
||
|
|
|
||
|
|
@vertex
|
||
|
|
fn mainVertex(
|
||
|
|
@location(0) aPosition : vec2<f32>,
|
||
|
|
) -> VSOutput {
|
||
|
|
return VSOutput(
|
||
|
|
filterVertexPosition(aPosition),
|
||
|
|
filterTextureCoord(aPosition)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn rand(co:vec2<f32>) -> f32
|
||
|
|
{
|
||
|
|
return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
@fragment
|
||
|
|
fn mainFragment(
|
||
|
|
@location(0) uv: vec2<f32>,
|
||
|
|
@builtin(position) position: vec4<f32>
|
||
|
|
) -> @location(0) vec4<f32> {
|
||
|
|
|
||
|
|
var pixelPosition = globalTextureCoord(position.xy);// / (getSize());//- gfu.uOutputFrame.xy);
|
||
|
|
|
||
|
|
|
||
|
|
var sample = textureSample(uTexture, uSampler, uv);
|
||
|
|
var randomValue = rand(pixelPosition.xy * noiseUniforms.uSeed);
|
||
|
|
var diff = (randomValue - 0.5) * noiseUniforms.uNoise;
|
||
|
|
|
||
|
|
// Un-premultiply alpha before applying the color matrix. See issue #3539.
|
||
|
|
if (sample.a > 0.0) {
|
||
|
|
sample.r /= sample.a;
|
||
|
|
sample.g /= sample.a;
|
||
|
|
sample.b /= sample.a;
|
||
|
|
}
|
||
|
|
|
||
|
|
sample.r += diff;
|
||
|
|
sample.g += diff;
|
||
|
|
sample.b += diff;
|
||
|
|
|
||
|
|
// Premultiply alpha again.
|
||
|
|
sample.r *= sample.a;
|
||
|
|
sample.g *= sample.a;
|
||
|
|
sample.b *= sample.a;
|
||
|
|
|
||
|
|
return sample;
|
||
|
|
}`,cM=Object.defineProperty,dM=Object.defineProperties,pM=Object.getOwnPropertyDescriptors,Tn=Object.getOwnPropertySymbols,Cx=Object.prototype.hasOwnProperty,Rx=Object.prototype.propertyIsEnumerable,Mx=(r,t,e)=>t in r?cM(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,au=(r,t)=>{for(var e in t||(t={}))Cx.call(t,e)&&Mx(r,e,t[e]);if(Tn)for(var e of Tn(t))Rx.call(t,e)&&Mx(r,e,t[e]);return r},fM=(r,t)=>dM(r,pM(t)),mM=(r,t)=>{var e={};for(var s in r)Cx.call(r,s)&&t.indexOf(s)<0&&(e[s]=r[s]);if(r!=null&&Tn)for(var s of Tn(r))t.indexOf(s)<0&&Rx.call(r,s)&&(e[s]=r[s]);return e};const Ox=class hS extends Ae{constructor(t={}){t=au(au({},hS.defaultOptions),t);const e=zt.from({vertex:{source:ou,entryPoint:"mainVertex"},fragment:{source:ou,entryPoint:"mainFragment"}}),s=Yt.from({vertex:Ps,fragment:Px,name:"noise-filter"}),i=t,{noise:n,seed:o}=i,a=mM(i,["noise","seed"]);super(fM(au({},a),{gpuProgram:e,glProgram:s,resources:{noiseUniforms:new wt({uNoise:{value:1,type:"f32"},uSeed:{value:1,type:"f32"}})}})),this.noise=n,this.seed=o!=null?o:Math.random()}get noise(){return this.resources.noiseUniforms.uniforms.uNoise}set noise(t){this.resources.noiseUniforms.uniforms.uNoise=t}get seed(){return this.resources.noiseUniforms.uniforms.uSeed}set seed(t){this.resources.noiseUniforms.uniforms.uSeed=t}};Ox.defaultOptions={noise:.5};let gM=Ox;var Gx=`in vec2 vMaskCoord;
|
||
|
|
in vec2 vTextureCoord;
|
||
|
|
|
||
|
|
uniform sampler2D uTexture;
|
||
|
|
uniform sampler2D uMaskTexture;
|
||
|
|
|
||
|
|
uniform float uAlpha;
|
||
|
|
uniform vec4 uMaskClamp;
|
||
|
|
uniform float uInverse;
|
||
|
|
uniform float uChannel;
|
||
|
|
|
||
|
|
out vec4 finalColor;
|
||
|
|
|
||
|
|
void main(void)
|
||
|
|
{
|
||
|
|
float clip = step(3.5,
|
||
|
|
step(uMaskClamp.x, vMaskCoord.x) +
|
||
|
|
step(uMaskClamp.y, vMaskCoord.y) +
|
||
|
|
step(vMaskCoord.x, uMaskClamp.z) +
|
||
|
|
step(vMaskCoord.y, uMaskClamp.w));
|
||
|
|
|
||
|
|
// TODO look into why this is needed
|
||
|
|
float npmAlpha = uAlpha;
|
||
|
|
vec4 original = texture(uTexture, vTextureCoord);
|
||
|
|
vec4 masky = texture(uMaskTexture, vMaskCoord);
|
||
|
|
|
||
|
|
float a;
|
||
|
|
if (uChannel == 1.0) {
|
||
|
|
a = masky.a * npmAlpha * clip;
|
||
|
|
} else {
|
||
|
|
float alphaMul = 1.0 - npmAlpha * (1.0 - masky.a);
|
||
|
|
a = alphaMul * masky.r * npmAlpha * clip;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (uInverse == 1.0) {
|
||
|
|
a = 1.0 - a;
|
||
|
|
}
|
||
|
|
|
||
|
|
finalColor = original * a;
|
||
|
|
}
|
||
|
|
`,Ix=`in vec2 aPosition;
|
||
|
|
|
||
|
|
out vec2 vTextureCoord;
|
||
|
|
out vec2 vMaskCoord;
|
||
|
|
|
||
|
|
|
||
|
|
uniform vec4 uInputSize;
|
||
|
|
uniform vec4 uOutputFrame;
|
||
|
|
uniform vec4 uOutputTexture;
|
||
|
|
uniform mat3 uFilterMatrix;
|
||
|
|
|
||
|
|
vec4 filterVertexPosition( vec2 aPosition )
|
||
|
|
{
|
||
|
|
vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
|
||
|
|
|
||
|
|
position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
|
||
|
|
position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
|
||
|
|
|
||
|
|
return vec4(position, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
vec2 filterTextureCoord( vec2 aPosition )
|
||
|
|
{
|
||
|
|
return aPosition * (uOutputFrame.zw * uInputSize.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
vec2 getFilterCoord( vec2 aPosition )
|
||
|
|
{
|
||
|
|
return ( uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;
|
||
|
|
}
|
||
|
|
|
||
|
|
void main(void)
|
||
|
|
{
|
||
|
|
gl_Position = filterVertexPosition(aPosition);
|
||
|
|
vTextureCoord = filterTextureCoord(aPosition);
|
||
|
|
vMaskCoord = getFilterCoord(aPosition);
|
||
|
|
}
|
||
|
|
`,lu=`struct GlobalFilterUniforms {
|
||
|
|
uInputSize:vec4<f32>,
|
||
|
|
uInputPixel:vec4<f32>,
|
||
|
|
uInputClamp:vec4<f32>,
|
||
|
|
uOutputFrame:vec4<f32>,
|
||
|
|
uGlobalFrame:vec4<f32>,
|
||
|
|
uOutputTexture:vec4<f32>,
|
||
|
|
};
|
||
|
|
|
||
|
|
struct MaskUniforms {
|
||
|
|
uFilterMatrix:mat3x3<f32>,
|
||
|
|
uMaskClamp:vec4<f32>,
|
||
|
|
uAlpha:f32,
|
||
|
|
uInverse:f32,
|
||
|
|
uChannel:f32,
|
||
|
|
};
|
||
|
|
|
||
|
|
@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
|
||
|
|
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
||
|
|
@group(0) @binding(2) var uSampler : sampler;
|
||
|
|
|
||
|
|
@group(1) @binding(0) var<uniform> filterUniforms : MaskUniforms;
|
||
|
|
@group(1) @binding(1) var uMaskTexture: texture_2d<f32>;
|
||
|
|
|
||
|
|
struct VSOutput {
|
||
|
|
@builtin(position) position: vec4<f32>,
|
||
|
|
@location(0) uv : vec2<f32>,
|
||
|
|
@location(1) filterUv : vec2<f32>,
|
||
|
|
};
|
||
|
|
|
||
|
|
fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
|
||
|
|
{
|
||
|
|
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
||
|
|
|
||
|
|
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
||
|
|
position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
|
||
|
|
|
||
|
|
return vec4(position, 0.0, 1.0);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn getFilterCoord(aPosition:vec2<f32> ) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return ( filterUniforms.uFilterMatrix * vec3( filterTextureCoord(aPosition), 1.0) ).xy;
|
||
|
|
}
|
||
|
|
|
||
|
|
fn getSize() -> vec2<f32>
|
||
|
|
{
|
||
|
|
return gfu.uGlobalFrame.zw;
|
||
|
|
}
|
||
|
|
|
||
|
|
@vertex
|
||
|
|
fn mainVertex(
|
||
|
|
@location(0) aPosition : vec2<f32>,
|
||
|
|
) -> VSOutput {
|
||
|
|
return VSOutput(
|
||
|
|
filterVertexPosition(aPosition),
|
||
|
|
filterTextureCoord(aPosition),
|
||
|
|
getFilterCoord(aPosition)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
@fragment
|
||
|
|
fn mainFragment(
|
||
|
|
@location(0) uv: vec2<f32>,
|
||
|
|
@location(1) filterUv: vec2<f32>,
|
||
|
|
@builtin(position) position: vec4<f32>
|
||
|
|
) -> @location(0) vec4<f32> {
|
||
|
|
|
||
|
|
var maskClamp = filterUniforms.uMaskClamp;
|
||
|
|
var uAlpha = filterUniforms.uAlpha;
|
||
|
|
|
||
|
|
var clip = step(3.5,
|
||
|
|
step(maskClamp.x, filterUv.x) +
|
||
|
|
step(maskClamp.y, filterUv.y) +
|
||
|
|
step(filterUv.x, maskClamp.z) +
|
||
|
|
step(filterUv.y, maskClamp.w));
|
||
|
|
|
||
|
|
var mask = textureSample(uMaskTexture, uSampler, filterUv);
|
||
|
|
var source = textureSample(uTexture, uSampler, uv);
|
||
|
|
|
||
|
|
var a: f32;
|
||
|
|
if (filterUniforms.uChannel == 1.0) {
|
||
|
|
a = mask.a * uAlpha * clip;
|
||
|
|
} else {
|
||
|
|
var alphaMul = 1.0 - uAlpha * (1.0 - mask.a);
|
||
|
|
a = alphaMul * mask.r * uAlpha * clip;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (filterUniforms.uInverse == 1.0) {
|
||
|
|
a = 1.0 - a;
|
||
|
|
}
|
||
|
|
|
||
|
|
return source * a;
|
||
|
|
}
|
||
|
|
`,_M=Object.defineProperty,xM=Object.defineProperties,vM=Object.getOwnPropertyDescriptors,Sn=Object.getOwnPropertySymbols,Fx=Object.prototype.hasOwnProperty,Bx=Object.prototype.propertyIsEnumerable,Dx=(r,t,e)=>t in r?_M(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,bM=(r,t)=>{for(var e in t||(t={}))Fx.call(t,e)&&Dx(r,e,t[e]);if(Sn)for(var e of Sn(t))Bx.call(t,e)&&Dx(r,e,t[e]);return r},yM=(r,t)=>xM(r,vM(t)),TM=(r,t)=>{var e={};for(var s in r)Fx.call(r,s)&&t.indexOf(s)<0&&(e[s]=r[s]);if(r!=null&&Sn)for(var s of Sn(r))t.indexOf(s)<0&&Bx.call(r,s)&&(e[s]=r[s]);return e};class $x extends Ae{constructor(t){const e=t,{sprite:s}=e,i=TM(e,["sprite"]),n=new Zo(s.texture),o=new wt({uFilterMatrix:{value:new D,type:"mat3x3<f32>"},uMaskClamp:{value:n.uClampFrame,type:"vec4<f32>"},uAlpha:{value:1,type:"f32"},uInverse:{value:t.inverse?1:0,type:"f32"},uChannel:{value:t.channel==="alpha"?1:0,type:"f32"}}),a=zt.from({vertex:{source:lu,entryPoint:"mainVertex"},fragment:{source:lu,entryPoint:"mainFragment"}}),l=Yt.from({vertex:Ix,fragment:Gx,name:"mask-filter"});super(yM(bM({},i),{gpuProgram:a,glProgram:l,clipToViewport:!1,resources:{filterUniforms:o,uMaskTexture:s.texture.source}})),this.sprite=s,this._textureMatrix=n}setSprite(t){this.sprite=t;const e=this._getSafeTexture();this._textureMatrix.texture=e,this.resources.uMaskTexture=e.source}set inverse(t){this.resources.filterUniforms.uniforms.uInverse=t?1:0}get inverse(){return this.resources.filterUniforms.uniforms.uInverse===1}set channel(t){this.resources.filterUniforms.uniforms.uChannel=t==="alpha"?1:0}get channel(){return this.resources.filterUniforms.uniforms.uChannel===1?"alpha":"red"}apply(t,e,s,i){const n=this._getSafeTexture();this._textureMatrix.texture=n,t.calculateSpriteMatrix(this.resources.filterUniforms.uniforms.uFilterMatrix,this.sprite).prepend(this._textureMatrix.mapCoord),this.resources.uMaskTexture=n.source,t.applyFilter(this,e,s,i)}_getSafeTexture(){const t=this.sprite.texture;return t.destroyed||!t.source||t.source.destroyed?B.EMPTY:t}destroy(t=!1){this._textureMatrix.destroy(),super.destroy(t)}}var SM=`fn getLuminosity(c: vec3<f32>) -> f32 {
|
||
|
|
return 0.3 * c.r + 0.59 * c.g + 0.11 * c.b;
|
||
|
|
}
|
||
|
|
|
||
|
|
fn setLuminosity(c: vec3<f32>, lum: f32) -> vec3<f32> {
|
||
|
|
let d: f32 = lum - getLuminosity(c);
|
||
|
|
let newColor: vec3<f32> = c.rgb + vec3<f32>(d, d, d);
|
||
|
|
|
||
|
|
// clip back into legal range
|
||
|
|
let newLum: f32 = getLuminosity(newColor);
|
||
|
|
let cMin: f32 = min(newColor.r, min(newColor.g, newColor.b));
|
||
|
|
let cMax: f32 = max(newColor.r, max(newColor.g, newColor.b));
|
||
|
|
|
||
|
|
let t1: f32 = newLum / (newLum - cMin);
|
||
|
|
let t2: f32 = (1.0 - newLum) / (cMax - newLum);
|
||
|
|
|
||
|
|
let finalColor = mix(vec3<f32>(newLum, newLum, newLum), newColor, select(select(1.0, t2, cMax > 1.0), t1, cMin < 0.0));
|
||
|
|
|
||
|
|
return finalColor;
|
||
|
|
}
|
||
|
|
|
||
|
|
fn getSaturation(c: vec3<f32>) -> f32 {
|
||
|
|
return max(c.r, max(c.g, c.b)) - min(c.r, min(c.g, c.b));
|
||
|
|
}
|
||
|
|
|
||
|
|
// Set saturation if color components are sorted in ascending order.
|
||
|
|
fn setSaturationMinMidMax(cSorted: vec3<f32>, s: f32) -> vec3<f32> {
|
||
|
|
var result: vec3<f32>;
|
||
|
|
if (cSorted.z > cSorted.x) {
|
||
|
|
let newY = (((cSorted.y - cSorted.x) * s) / (cSorted.z - cSorted.x));
|
||
|
|
result = vec3<f32>(0.0, newY, s);
|
||
|
|
} else {
|
||
|
|
result = vec3<f32>(0.0, 0.0, 0.0);
|
||
|
|
}
|
||
|
|
return vec3<f32>(result.x, result.y, result.z);
|
||
|
|
}
|
||
|
|
|
||
|
|
fn setSaturation(c: vec3<f32>, s: f32) -> vec3<f32> {
|
||
|
|
var result: vec3<f32> = c;
|
||
|
|
|
||
|
|
if (c.r <= c.g && c.r <= c.b) {
|
||
|
|
if (c.g <= c.b) {
|
||
|
|
result = setSaturationMinMidMax(result, s);
|
||
|
|
} else {
|
||
|
|
var temp: vec3<f32> = vec3<f32>(result.r, result.b, result.g);
|
||
|
|
temp = setSaturationMinMidMax(temp, s);
|
||
|
|
result = vec3<f32>(temp.r, temp.b, temp.g);
|
||
|
|
}
|
||
|
|
} else if (c.g <= c.r && c.g <= c.b) {
|
||
|
|
if (c.r <= c.b) {
|
||
|
|
var temp: vec3<f32> = vec3<f32>(result.g, result.r, result.b);
|
||
|
|
temp = setSaturationMinMidMax(temp, s);
|
||
|
|
result = vec3<f32>(temp.g, temp.r, temp.b);
|
||
|
|
} else {
|
||
|
|
var temp: vec3<f32> = vec3<f32>(result.g, result.b, result.r);
|
||
|
|
temp = setSaturationMinMidMax(temp, s);
|
||
|
|
result = vec3<f32>(temp.g, temp.b, temp.r);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
if (c.r <= c.g) {
|
||
|
|
var temp: vec3<f32> = vec3<f32>(result.b, result.r, result.g);
|
||
|
|
temp = setSaturationMinMidMax(temp, s);
|
||
|
|
result = vec3<f32>(temp.b, temp.r, temp.g);
|
||
|
|
} else {
|
||
|
|
var temp: vec3<f32> = vec3<f32>(result.b, result.g, result.r);
|
||
|
|
temp = setSaturationMinMidMax(temp, s);
|
||
|
|
result = vec3<f32>(temp.b, temp.g, temp.r);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return result;
|
||
|
|
}`;const Ux=class cS{constructor(t){this._tick=()=>{this._destroyed||(this.timeout=setTimeout(this._processQueue,0))},this._processQueue=()=>{if(this._destroyed)return;const{queue:e}=this;let s=0;for(;e.length&&s<cS.uploadsPerFrame;){const i=e.shift();this.uploadQueueItem(i),s++}e.length?Rt.system.addOnce(this._tick,this,Te.UTILITY):this._resolve()},this.renderer=t,this.queue=[],this.resolves=[]}getQueue(){return[...this.queue]}add(t){const e=Array.isArray(t)?t:[t];for(const s of e)s instanceof dt?this._addContainer(s):this.resolveQueueItem(s,this.queue);return this}_addContainer(t){this.resolveQueueItem(t,this.queue);for(const e of t.children)this._addContainer(e)}upload(t){return t&&this.add(t),new Promise(e=>{this.queue.length?(this.resolves.push(e),this.dedupeQueue(),Rt.system.addOnce(this._tick,this,Te.UTILITY)):e()})}dedupeQueue(){const t=Object.create(null);let e=0;for(let s=0;s<this.queue.length;s++){const i=this.queue[s];t[i.uid]||(t[i.uid]=!0,this.queue[e++]=i)}this.queue.length=e}destroy(){this._destroyed=!0,clearTimeout(this.timeout)}_resolve(){const{resolves:t}=this,e=t.slice(0);t.length=0;for(const s of e)s()}};Ux.uploadsPerFrame=4;let kx=Ux,wM=class{constructor(){this.isBatchable=!1}reset(){this.isBatchable=!1,this.context=null,this.graphicsData&&(this.graphicsData.destroy(),this.graphicsData=null)}destroy(){this.reset()}},EM=class{constructor(){this.instructions=new yi}init(){this.instructions.reset()}destroy(){this.instructions.destroy(),this.instructions=null}};const uu=class jc{constructor(t){this._renderer=t,this._managedContexts=new kt({renderer:t,type:"resource",name:"graphicsContext"})}init(t){var e;jc.defaultOptions.bezierSmoothness=(e=t==null?void 0:t.bezierSmoothness)!=null?e:jc.defaultOptions.bezierSmoothness}getContextRenderData(t){return this.getGpuContext(t).graphicsData||this._initContextRenderData(t)}updateGpuContext(t){const e=t._gpuData,s=!!e[this._renderer.uid],i=e[this._renderer.uid]||this._initContext(t);return(t.dirty||!s)&&(s&&i.reset(),i.isBatchable=!1,t.dirty=!1),i}getGpuContext(t){return t._gpuData[this._renderer.uid]||this._initContext(t)}_initContextRenderData(t){const e=new EM,s=this.getGpuContext(t);return s.graphicsData=e,e.init(),e}_initContext(t){const e=new wM;return e.context=t,t._gpuData[this._renderer.uid]=e,this._managedContexts.add(t),e}destroy(){this._managedContexts.destroy(),this._renderer=null}};uu.extension={type:[T.CanvasSystem],name:"graphicsContext"},uu.defaultOptions={bezierSmoothness:.5};let Lx=uu;class hu{constructor(t,e){this.state=Kt.for2d(),this.renderer=t,this._adaptor=e,this.renderer.runners.contextChange.add(this),this._managedGraphics=new kt({renderer:t,type:"renderable",priority:-1,name:"graphics"})}contextChange(){this._adaptor.contextChange(this.renderer)}validateRenderable(t){return!1}addRenderable(t,e){this._managedGraphics.add(t),this.renderer.renderPipes.batch.break(e),e.add(t)}updateRenderable(t){}execute(t){t.isRenderable&&this._adaptor.execute(this,t)}destroy(){this._managedGraphics.destroy(),this.renderer=null,this._adaptor.destroy(),this._adaptor=null}}hu.extension={type:[T.CanvasPipes],name:"graphics"};function AM(r,t,e,s){e[s++]=(r>>16&255)/255,e[s++]=(r>>8&255)/255,e[s++]=(r&255)/255,e[s++]=t}function Zr(r,t,e){const s=(r>>24&255)/255;t[e++]=(r&255)/255*s,t[e++]=(r>>8&255)/255*s,t[e++]=(r>>16&255)/255*s,t[e++]=s}class Nx{constructor(){this.batches=[],this.batched=!1}destroy(){this.batches.forEach(t=>{St.return(t)}),this.batches.length=0}}class cu{constructor(t,e){this.state=Kt.for2d(),this.renderer=t,this._adaptor=e,this.renderer.runners.contextChange.add(this),this._managedGraphics=new kt({renderer:t,type:"renderable",priority:-1,name:"graphics"})}contextChange(){this._adaptor.contextChange(this.renderer)}validateRenderable(t){const e=t.context,s=!!t._gpuData,i=this.renderer.graphicsContext.updateGpuContext(e);return!!(i.isBatchable||s!==i.isBatchable)}addRenderable(t,e){const s=this.renderer.graphicsContext.updateGpuContext(t.context);(t.didViewUpdate||!t._gpuData[this.renderer.uid])&&this._rebuild(t),s.isBatchable?this._addToBatch
|
||
|
|
|
||
|
|
struct LocalUniforms {
|
||
|
|
uTransformMatrix:mat3x3<f32>,
|
||
|
|
uColor:vec4<f32>,
|
||
|
|
uRound:f32,
|
||
|
|
}
|
||
|
|
|
||
|
|
@group(1) @binding(0) var<uniform> localUniforms : LocalUniforms;
|
||
|
|
`,main:`
|
||
|
|
vColor *= localUniforms.uColor;
|
||
|
|
modelMatrix *= localUniforms.uTransformMatrix;
|
||
|
|
`,end:`
|
||
|
|
if(localUniforms.uRound == 1)
|
||
|
|
{
|
||
|
|
vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
|
||
|
|
}
|
||
|
|
`}},ov=nv(iv({},Jr),{vertex:nv(iv({},Jr.vertex),{header:Jr.vertex.header.replace("group(1)","group(2)")})}),Rn={name:"local-uniform-bit",vertex:{header:`
|
||
|
|
|
||
|
|
uniform mat3 uTransformMatrix;
|
||
|
|
uniform vec4 uColor;
|
||
|
|
uniform float uRound;
|
||
|
|
`,main:`
|
||
|
|
vColor *= uColor;
|
||
|
|
modelMatrix = uTransformMatrix;
|
||
|
|
`,end:`
|
||
|
|
if(uRound == 1.)
|
||
|
|
{
|
||
|
|
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
||
|
|
}
|
||
|
|
`}},av={name:"tiling-bit",vertex:{header:`
|
||
|
|
struct TilingUniforms {
|
||
|
|
uMapCoord:mat3x3<f32>,
|
||
|
|
uClampFrame:vec4<f32>,
|
||
|
|
uClampOffset:vec2<f32>,
|
||
|
|
uTextureTransform:mat3x3<f32>,
|
||
|
|
uSizeAnchor:vec4<f32>
|
||
|
|
};
|
||
|
|
|
||
|
|
@group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms;
|
||
|
|
@group(2) @binding(1) var uTexture: texture_2d<f32>;
|
||
|
|
@group(2) @binding(2) var uSampler: sampler;
|
||
|
|
`,main:`
|
||
|
|
uv = (tilingUniforms.uTextureTransform * vec3(uv, 1.0)).xy;
|
||
|
|
|
||
|
|
position = (position - tilingUniforms.uSizeAnchor.zw) * tilingUniforms.uSizeAnchor.xy;
|
||
|
|
`},fragment:{header:`
|
||
|
|
struct TilingUniforms {
|
||
|
|
uMapCoord:mat3x3<f32>,
|
||
|
|
uClampFrame:vec4<f32>,
|
||
|
|
uClampOffset:vec2<f32>,
|
||
|
|
uTextureTransform:mat3x3<f32>,
|
||
|
|
uSizeAnchor:vec4<f32>
|
||
|
|
};
|
||
|
|
|
||
|
|
@group(2) @binding(0) var<uniform> tilingUniforms: TilingUniforms;
|
||
|
|
@group(2) @binding(1) var uTexture: texture_2d<f32>;
|
||
|
|
@group(2) @binding(2) var uSampler: sampler;
|
||
|
|
`,main:`
|
||
|
|
|
||
|
|
var coord = vUV + ceil(tilingUniforms.uClampOffset - vUV);
|
||
|
|
coord = (tilingUniforms.uMapCoord * vec3(coord, 1.0)).xy;
|
||
|
|
var unclamped = coord;
|
||
|
|
coord = clamp(coord, tilingUniforms.uClampFrame.xy, tilingUniforms.uClampFrame.zw);
|
||
|
|
|
||
|
|
var bias = 0.;
|
||
|
|
|
||
|
|
if(unclamped.x == coord.x && unclamped.y == coord.y)
|
||
|
|
{
|
||
|
|
bias = -32.;
|
||
|
|
}
|
||
|
|
|
||
|
|
outColor = textureSampleBias(uTexture, uSampler, coord, bias);
|
||
|
|
`}},lv={name:"tiling-bit",vertex:{header:`
|
||
|
|
uniform mat3 uTextureTransform;
|
||
|
|
uniform vec4 uSizeAnchor;
|
||
|
|
|
||
|
|
`,main:`
|
||
|
|
uv = (uTextureTransform * vec3(aUV, 1.0)).xy;
|
||
|
|
|
||
|
|
position = (position - uSizeAnchor.zw) * uSizeAnchor.xy;
|
||
|
|
`},fragment:{header:`
|
||
|
|
uniform sampler2D uTexture;
|
||
|
|
uniform mat3 uMapCoord;
|
||
|
|
uniform vec4 uClampFrame;
|
||
|
|
uniform vec2 uClampOffset;
|
||
|
|
`,main:`
|
||
|
|
|
||
|
|
vec2 coord = vUV + ceil(uClampOffset - vUV);
|
||
|
|
coord = (uMapCoord * vec3(coord, 1.0)).xy;
|
||
|
|
vec2 unclamped = coord;
|
||
|
|
coord = clamp(coord, uClampFrame.xy, uClampFrame.zw);
|
||
|
|
|
||
|
|
outColor = texture(uTexture, coord, unclamped == coord ? 0.0 : -32.0);// lod-bias very negative to force lod 0
|
||
|
|
|
||
|
|
`}};let mu,gu;class uv extends ne{constructor(){mu!=null||(mu=Ur({name:"tiling-sprite-shader",bits:[Jr,av,Lr]})),gu!=null||(gu=kr({name:"tiling-sprite-shader",bits:[Rn,lv,Nr]}));const t=new wt({uMapCoord:{value:new D,type:"mat3x3<f32>"},uClampFrame:{value:new Float32Array([0,0,1,1]),type:"vec4<f32>"},uClampOffset:{value:new Float32Array([0,0]),type:"vec2<f32>"},uTextureTransform:{value:new D,type:"mat3x3<f32>"},uSizeAnchor:{value:new Float32Array([100,100,.5,.5]),type:"vec4<f32>"}});super({glProgram:gu,gpuProgram:mu,resources:{localUniforms:new wt({uTransformMatrix:{value:new D,type:"mat3x3<f32>"},uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uRound:{value:0,type:"f32"}}),tilingUniforms:t,uTexture:B.EMPTY.source,uSampler:B.EMPTY.source.style}})}updateUniforms(t,e,s,i,n,o){const a=this.resources.tilingUniforms,l=o.width,u=o.height,h=o.textureMatrix,c=a.uniforms.uTextureTransform;c.set(s.a*l/t,s.b*l/e,s.c*u/t,s.d*u/e,s.tx/t,s.ty/e),c.invert(),a.uniforms.uMapCoord=h.mapCoord,a.uniforms.uClampFrame=h.uClampFrame,a.uniforms.uClampOffset=h.uClampOffset,a.uniforms.uTextureTransform=c,a.uniforms.uSizeAnchor[0]=t,a.uniforms.uSizeAnchor[1]=e,a.uniforms.uSizeAnchor[2]=i,a.uniforms.uSizeAnchor[3]=n,o&&(this.resources.uTexture=o.source,this.resources.uSampler=o.source.style)}}class hv extends Ve{constructor(){super({positions:new Float32Array([0,0,1,0,1,1,0,1]),uvs:new Float32Array([0,0,1,0,1,1,0,1]),indices:new Uint32Array([0,1,2,0,2,3])})}}function cv(r,t){const e=r.anchor.x,s=r.anchor.y;t[0]=-e*r.width,t[1]=-s*r.height,t[2]=(1-e)*r.width,t[3]=-s*r.height,t[4]=(1-e)*r.width,t[5]=(1-s)*r.height,t[6]=-e*r.width,t[7]=(1-s)*r.height}function dv(r,t,e,s){let i=0;const n=r.length/(t||2),o=s.a,a=s.b,l=s.c,u=s.d,h=s.tx,c=s.ty;for(e*=t;i<n;){const d=r[e],p=r[e+1];r[e]=o*d+l*p+h,r[e+1]=a*d+u*p+c,e+=t,i++}}function pv(r,t){const e=r.texture,s=e.frame.width,i=e.frame.height;let n=0,o=0;r.applyAnchorToTexture&&(n=r.anchor.x,o=r.anchor.y),t[0]=t[6]=-n,t[2]=t[4]=1-n,t[1]=t[3]=-o,t[5]=t[7]=1-o;const a=r._tileTransform.matrix,l=D.shared;l.set(a.a*s/r.width,a.b*s/r.height,a.c*i/r.width,a.d*i/r.height,a.tx/r.width,a.ty/r.height),l.invert(),dv(t,2,0,l)}const Mn=new hv;class fv{constructor(){this.canBatch=!0,this.geometry=new Ve({indices:Mn.indices.slice(),positions:Mn.positions.slice(),uvs:Mn.uvs.slice()})}destroy(){var t;this.geometry.destroy(),(t=this.shader)==null||t.destroy()}}class _u{constructor(t){this._state=Kt.default2d,this._renderer=t,this._managedTilingSprites=new kt({renderer:t,type:"renderable",name:"tilingSprite"})}validateRenderable(t){const e=this._getTilingSpriteData(t),s=e.canBatch;this._updateCanBatch(t);const i=e.canBatch;if(i&&i===s){const{batchableMesh:n}=e;return!n._batcher.checkAndUpdateTexture(n,t.texture)}return s!==i}addRenderable(t,e){const s=this._renderer.renderPipes.batch;this._updateCanBatch(t);const i=this._getTilingSpriteData(t),{geometry:n,canBatch:o}=i;if(o){i.batchableMesh||(i.batchableMesh=new En);const a=i.batchableMesh;t.didViewUpdate&&(this._updateBatchableMesh(t),a.geometry=n,a.renderable=t,a.transform=t.groupTransform,a.setTexture(t._texture)),a.roundPixels=this._renderer._roundPixels|t._roundPixels,s.addToBatch(a,e)}else s.break(e),i.shader||(i.shader=new uv),this.updateRenderable(t),e.add(t)}execute(t){const e=this._renderer,{shader:s}=this._getTilingSpriteData(t);s.groups[0]=e.globalUniforms.bindGroup;const i=s.resources.localUniforms.uniforms;i.uTransformMatrix=t.groupTransform,i.uRound=e._roundPixels|t._roundPixels,Zr(t.groupColorAlpha,i.uColor,0),this._state.blendMode=Dr(t.groupBlendMode,t.texture._source),e.encoder.draw({geometry:Mn,shader:s,state:this._state})}updateRenderable(t){const e=this._getTilingSpriteData(t),{canBatch:s}=e;if(s){const{batchableMesh:i}=e;t.didViewUpdate&&this._updateBatchableMesh(t),i._batcher.updateElement(i)}else if(t.didViewUpdate){const{shader:i}=e;i.updateUniforms(t.width,t.height,t._tileTransform.matrix,t.anchor.x,t.anchor.y,t.texture)}}_getTilingSpriteData(t){return t._gpuData[this._renderer.uid]||this._initTilingSpriteData(t)}_initTilingSpriteDat
|
||
|
|
* tiny-lru
|
||
|
|
*
|
||
|
|
* @copyright 2026 Jason Mulligan <jason.mulligan@avoidwork.com>
|
||
|
|
* @license BSD-3-Clause
|
||
|
|
* @version 11.4.7
|
||
|
|
*/class JM{constructor(t=0,e=0,s=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.resetTtl=s,this.size=0,this.ttl=e}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.has(t)){const e=this.items[t];delete this.items[t],this.size--,e.prev!==null&&(e.prev.next=e.next),e.next!==null&&(e.next.prev=e.prev),this.first===e&&(this.first=e.next),this.last===e&&(this.last=e.prev)}return this}entries(t=this.keys()){const e=new Array(t.length);for(let s=0;s<t.length;s++){const i=t[s];e[s]=[i,this.get(i)]}return e}evict(t=!1){if(t||this.size>0){const e=this.first;delete this.items[e.key],--this.size===0?(this.first=null,this.last=null):(this.first=e.next,this.first.prev=null)}return this}expiresAt(t){let e;return this.has(t)&&(e=this.items[t].expiry),e}get(t){const e=this.items[t];if(e!==void 0){if(this.ttl>0&&e.expiry<=Date.now()){this.delete(t);return}return this.moveToEnd(e),e.value}}has(t){return t in this.items}moveToEnd(t){this.last!==t&&(t.prev!==null&&(t.prev.next=t.next),t.next!==null&&(t.next.prev=t.prev),this.first===t&&(this.first=t.next),t.prev=this.last,t.next=null,this.last!==null&&(this.last.next=t),this.last=t,this.first===null&&(this.first=t))}keys(){const t=new Array(this.size);let e=this.first,s=0;for(;e!==null;)t[s++]=e.key,e=e.next;return t}setWithEvicted(t,e,s=this.resetTtl){let i=null;if(this.has(t))this.set(t,e,!0,s);else{this.max>0&&this.size===this.max&&(i=Jc({},this.first),this.evict(!0));let n=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e};++this.size===1?this.first=n:this.last.next=n,this.last=n}return i}set(t,e,s=!1,i=this.resetTtl){let n=this.items[t];return s||n!==void 0?(n.value=e,s===!1&&i&&(n.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.moveToEnd(n)):(this.max>0&&this.size===this.max&&this.evict(!0),n=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e},++this.size===1?this.first=n:this.last.next=n,this.last=n),this}values(t=this.keys()){const e=new Array(t.length);for(let s=0;s<t.length;s++)e[s]=this.get(t[s]);return e}}function Av(r=1e3,t=0,e=!1){if(isNaN(r)||r<0)throw new TypeError("Invalid max value");if(isNaN(t)||t<0)throw new TypeError("Invalid ttl value");if(typeof e!="boolean")throw new TypeError("Invalid resetTtl value");return new JM(r,t,e)}function Bn(r){return!!r.tagStyles&&Object.keys(r.tagStyles).length>0}function Dn(r){return r.includes("<")}function tO(r,t){return r.clone().assign(t)}function xu(r,t){const e=[],s=t.tagStyles;if(!Bn(t)||!Dn(r))return e.push({text:r,style:t}),e;const i=[t],n=[];let o="",a=0;for(;a<r.length;){const l=r[a];if(l==="<"){const u=r.indexOf(">",a);if(u===-1){o+=l,a++;continue}const h=r.indexOf("<",a+1);if(h!==-1&&h<u){o+=l,a++;continue}const c=r.slice(a+1,u);if(c.startsWith("/")){const d=c.slice(1).trim();if(n.length>0&&n[n.length-1]===d){o.length>0&&(e.push({text:o,style:i[i.length-1]}),o=""),i.pop(),n.pop(),a=u+1;continue}else{o+=r.slice(a,u+1),a=u+1;continue}}else{const d=c.trim();if(s[d]){o.length>0&&(e.push({text:o,style:i[i.length-1]}),o="");const p=i[i.length-1],f=tO(p,s[d]);i.push(f),n.push(d),a=u+1;continue}else{o+=r.slice(a,u+1),a=u+1;continue}}}else o+=l,a++}return o.length>0&&e.push({text:o,style:i[i.length-1]}),e}function eO(r,t){return!Bn(t)||!Dn(r)?r:xu(r,t).map(e=>e.text).join("")}const Pv=[10,13],Cv=new Set(Pv),Rv=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288],Mv=new Set(Rv),Ov=[9,32],Gv=new Set(Ov),Iv=[45,8208,8211,8212,173],Fv=new Set(Iv),Bv=/(\r\n|\r|\n)/,Dv=/(?:\r\n|\r|\n)/;function Zs(r){return typeof r!="string"?!1:Cv.has(r.charCodeAt(0))}function Jt(r,t){return typeof r!="string"?!1:Mv.has(r.charCodeAt(0))}function vu(r){return typeof r!="string"?!1:Gv.has(r.charCodeAt(0))}function bu(r){return typeof r!="string"?!1:Fv.has(r.charCodeAt(0))}function $n(r){return r==="normal"||r==="pre-line"}function Un(r){return r==="normal"}function Ce(r){if(typeof r!="string")return"";let t=r.length-1;for(;t>=0&&Jt(r[t]);)t--;
|
||
|
|
`?(t.push(`\r
|
||
|
|
`),s++):t.push(i);continue}e.push(i),bu(i)&&n&&!Jt(n)&&!Zs(n)&&(t.push(e.join("")),e.length=0)}return e.length>0&&t.push(e.join("")),t}function Tu(r,t,e,s){const i=e(r),n=[];for(let o=0;o<i.length;o++){let a=i[o],l=a,u=1;for(;i[o+u];){const h=i[o+u];if(!s(l,h,r,o,t))a+=h,l=h,u++;else break}o+=u-1,n.push(a)}return n}const rO=/\r\n|\r|\n/g;function $v(r,t,e,s,i,n,o,a,l){var u,h;const c=xu(r,t);if(Un(t.whiteSpace))for(let G=0;G<c.length;G++){const M=c[G];c[G]={text:M.text.replace(rO," "),style:M.style}}const d=[];let p=[];for(const G of c){const M=G.text.split(Bv);for(let I=0;I<M.length;I++){const U=M[I];U===`\r
|
||
|
|
`||U==="\r"||U===`
|
||
|
|
`?(d.push(p),p=[]):U.length>0&&p.push({text:U,style:G.style})}}(p.length>0||d.length===0)&&d.push(p);const f=e?Uv(d,t,s,n,a,l):d,m=[],g=[],_=[],x=[],v=[];let b=0;const S=t._fontString,y=o(S);y.fontSize===0&&(y.fontSize=t.fontSize,y.ascent=t.fontSize);let w="",E=!!t.dropShadow,A=((u=t._stroke)==null?void 0:u.width)||0;for(const G of f){let M=0,I=y.ascent,U=y.descent,j="";for(const K of G){const N=K.style._fontString,k=o(N);N!==w&&(s.font=N,w=N);const $=i(K.text,K.style.letterSpacing,s);M+=$,I=Math.max(I,k.ascent),U=Math.max(U,k.descent),j+=K.text;const z=((h=K.style._stroke)==null?void 0:h.width)||0;z>A&&(A=z),!E&&K.style.dropShadow&&(E=!0)}G.length===0&&(I=y.ascent,U=y.descent),m.push(M),g.push(I),_.push(U),v.push(j);const Q=t.lineHeight||I+U;x.push(Q+t.leading),b=Math.max(b,M)}const P=A,C=b+P+(t.dropShadow?t.dropShadow.distance:0);let O=0;for(let G=0;G<x.length;G++)O+=x[G];O=Math.max(O,x[0]+P);const F=O+(t.dropShadow?t.dropShadow.distance:0),R=t.lineHeight||y.fontSize;return{width:C,height:F,lines:v,lineWidths:m,lineHeight:R+t.leading,maxLineWidth:b,fontProperties:y,runsByLine:f,lineAscents:g,lineDescents:_,lineHeights:x,hasDropShadow:E}}function Uv(r,t,e,s,i,n){var o,a,l;const{letterSpacing:u,whiteSpace:h,wordWrapWidth:c,breakWords:d}=t,p=$n(h),f=c+u,m={};let g="";const _=(v,b)=>{const S=`${v}|${b.styleKey}`;let y=m[S];if(y===void 0){const w=b._fontString;w!==g&&(e.font=w,g=w),y=s(v,b.letterSpacing,e)+b.letterSpacing,m[S]=y}return y},x=[];for(const v of r){const b=kv(v),S=x.length,y=R=>{let G=0,M=R;do{const{token:I,style:U}=b[M];G+=_(I,U),M++}while(M<b.length&&b[M].continuesFromPrevious);return G},w=R=>{const G=[];let M=R;do G.push({token:b[M].token,style:b[M].style}),M++;while(M<b.length&&b[M].continuesFromPrevious);return G};let E=[],A=0,P=!p,C=null;const O=()=>{C&&C.text.length>0&&E.push(C),C=null},F=()=>{if(O(),E.length>0){const R=E[E.length-1];R.text=Ce(R.text),R.text.length===0&&E.pop()}x.push(E),E=[],A=0,P=!1};for(let R=0;R<b.length;R++){const{token:G,style:M,continuesFromPrevious:I}=b[R],U=_(G,M);if(p){const K=Jt(G),N=(l=(a=C==null?void 0:C.text[C.text.length-1])!=null?a:(o=E[E.length-1])==null?void 0:o.text.slice(-1))!=null?l:"",k=N?Jt(N):!1;if(K&&k)continue}const j=!I,Q=j?y(R):U;if(Q>f&&j)if(A>0&&F(),d){const K=w(R);for(let N=0;N<K.length;N++){const k=K[N].token,$=K[N].style,z=Tu(k,d,n,i);for(const et of z){const mt=_(et,$);mt+A>f&&F(),!C||C.style!==$?(O(),C={text:et,style:$}):C.text+=et,A+=mt}}R+=K.length-1}else{const K=w(R);O(),x.push(K.map(N=>({text:N.token,style:N.style}))),P=!1,R+=K.length-1}else if(Q+A>f&&j){if(Jt(G)){P=!1;continue}F(),C={text:G,style:M},A=U}else if(I&&!d)!C||C.style!==M?(O(),C={text:G,style:M}):C.text+=G,A+=U;else{const K=Jt(G);if(A===0&&K&&!P)continue;!C||C.style!==M?(O(),C={text:G,style:M}):C.text+=G,A+=U}}if(O(),E.length>0){const R=E[E.length-1];R.text=Ce(R.text),R.text.length===0&&E.pop()}(E.length>0||x.length===S)&&x.push(E)}return x}function kv(r){const t=[];let e=!1;for(const s of r){const i=yu(s.text);let n=!0;for(const o of i){const a=Jt(o)||Zs(o),l=n&&e&&!a;t.push({token:o,style:s.style,continuesFromPrevious:l}),e=!a,n=!1}}return t}const sO={willReadFrequently:!0};function Lv(r,t,e,s,i){let n=e[r];return typeof n!="number"&&(n=i(r,t,s)+t,e[r]=n),n}function Nv(r,t,e,s,i,n,o){const a=e.getContext("2d",sO);a.font=t._fontString;let l=0,u="";const h=[],c=Object.create(null),{letterSpacing:d,whiteSpace:p}=t,f=$n(p),m=Un(p);let g=!f;const _=t.wordWrapWidth+d,x=yu(r);for(let b=0;b<x.length;b++){let S=x[b];if(Zs(S)){if(!m){h.push(Ce(u)),g=!f,u="",l=0;continue}S=" "}if(f){const w=Jt(S),E=Jt(u[u.length-1]);if(w&&E)continue}const y=Lv(S,d,c,a,s);if(y>_)if(u!==""&&(h.push(Ce(u)),u="",l=0),i(S,t.breakWords)){const w=Tu(S,t.breakWords,o,n);for(const E of w){const A=Lv(E,d,c,a,s);A+l>_&&(h.push(Ce(u)),g=!1,u="",l=0),u+=E,l+=A}}else u.length>0&&(h.push(Ce(u)),u="",l=0),h.push(Ce(S)),g=!1,u="",l=0;else y+l>_&&(g=!1,h.push(Ce(u)),u="",l=0),(u.length>0||!Jt(S)||g)&&(u+=S,l+=y)}const v=Ce(u);return v.length>0&&h.push(v),h.join(`
|
||
|
|
`)}const jv={willReadFrequently:!0},Ue=class V{static get experimentalLetterSpacingSupported(){let t=V._experimentalLetterSpacingSupported;if(t===void 0){const e=X.get().getCanvasRenderingContext2D().prototype;t=V._experimentalLetterSpacingSupported="letterSpacing"in e||"textLetterSpacing"in e}return t}constructor(t,e,s,i,n,o,a,l,u,h){this.text=t,this.style=e,this.width=s,this.height=i,this.lines=n,this.lineWidths=o,this.lineHeight=a,this.maxLineWidth=l,this.fontProperties=u,h&&(this.runsByLine=h.runsByLine,this.lineAscents=h.lineAscents,this.lineDescents=h.lineDescents,this.lineHeights=h.lineHeights,this.hasDropShadow=h.hasDropShadow)}static measureText(t=" ",e,s=V._canvas,i=e.wordWrap){var n,o;const a=`${t}-${e.styleKey}-wordWrap-${i}`;if(V._measurementCache.has(a))return V._measurementCache.get(a);if(Bn(e)&&Dn(t)){const b=$v(t,e,i,V._context,V._measureText,V._measureTextAdvance,V.measureFont,V.canBreakChars,V.wordWrapSplit),S=new V(t,e,b.width,b.height,b.lines,b.lineWidths,b.lineHeight,b.maxLineWidth,b.fontProperties,{runsByLine:b.runsByLine,lineAscents:b.lineAscents,lineDescents:b.lineDescents,lineHeights:b.lineHeights,hasDropShadow:b.hasDropShadow});return V._measurementCache.set(a,S),S}const l=e._fontString,u=V.measureFont(l);u.fontSize===0&&(u.fontSize=e.fontSize,u.ascent=e.fontSize,u.descent=0);const h=V._context;h.font=l;const c=(i?V._wordWrap(t,e,s):t).split(Dv),d=new Array(c.length);let p=0;for(let b=0;b<c.length;b++){const S=V._measureText(c[b],e.letterSpacing,h);d[b]=S,p=Math.max(p,S)}const f=(o=(n=e._stroke)==null?void 0:n.width)!=null?o:0,m=e.lineHeight||u.fontSize,g=V._adjustWidthForStyle(p,e),_=Math.max(m,u.fontSize+f)+(c.length-1)*(m+e.leading),x=V._adjustHeightForStyle(_,e),v=new V(t,e,g,x,c,d,m+e.leading,p,u);return V._measurementCache.set(a,v),v}static _adjustWidthForStyle(t,e){var s;const i=((s=e._stroke)==null?void 0:s.width)||0;let n=t+i;return e.dropShadow&&(n+=e.dropShadow.distance),n}static _adjustHeightForStyle(t,e){let s=t;return e.dropShadow&&(s+=e.dropShadow.distance),s}static _measureText(t,e,s){var i,n;const{metricWidth:o,metrics:a,letterSpacingVal:l}=V._measureTextCore(t,e,s),u=-((i=a.actualBoundingBoxLeft)!=null?i:0);let h=((n=a.actualBoundingBoxRight)!=null?n:0)-u;return a.width>0&&(h+=l),Math.max(o,h)}static _measureTextAdvance(t,e,s){return V._measureTextCore(t,e,s).metricWidth}static _measureTextCore(t,e,s){let i=!1;V.experimentalLetterSpacingSupported&&(V.experimentalLetterSpacing?(s.letterSpacing=`${e}px`,s.textLetterSpacing=`${e}px`,i=!0):(s.letterSpacing="0px",s.textLetterSpacing="0px"));const n=s.measureText(t);let o=n.width,a=0;return o>0&&(i?a=-e:a=(V.graphemeSegmenter(t).length-1)*e,o+=a),{metricWidth:o,metrics:n,letterSpacingVal:a}}static _wordWrap(t,e,s=V._canvas){return Nv(t,e,s,V._measureTextAdvance,V.canBreakWords,V.canBreakChars,V.wordWrapSplit)}static isBreakingSpace(t,e){return Jt(t,e)}static canBreakWords(t,e){return e}static canBreakChars(t,e,s,i,n){return!0}static wordWrapSplit(t){return V.graphemeSegmenter(t)}static measureFont(t){var e,s;if(V._fonts[t])return V._fonts[t];const i=V._context;i.font=t;const n=i.measureText(V.METRICS_STRING+V.BASELINE_SYMBOL),o=(e=n.actualBoundingBoxAscent)!=null?e:0,a=(s=n.actualBoundingBoxDescent)!=null?s:0,l={ascent:o,descent:a,fontSize:o+a};return V._fonts[t]=l,l}static clearMetrics(t=""){t?delete V._fonts[t]:V._fonts={}}static get _canvas(){if(!V.__canvas){let t;try{const e=new OffscreenCanvas(0,0),s=e.getContext("2d",jv);if(s!=null&&s.measureText)return V.__canvas=e,e;t=X.get().createCanvas()}catch(e){t=X.get().createCanvas()}t.width=t.height=10,V.__canvas=t}return V.__canvas}static get _context(){return V.__context||(V.__context=V._canvas.getContext("2d",jv)),V.__context}};Ue.METRICS_STRING="|\xC9q\xC5",Ue.BASELINE_SYMBOL="M",Ue.BASELINE_MULTIPLIER=1.4,Ue.HEIGHT_MULTIPLIER=2,Ue.graphemeSegmenter=(()=>{if(typeof(Intl==null?void 0:Intl.Segmenter)=="function"){const r=new Intl.Segmenter;return t=>{const e=r.segment(t),s=[];let i=0;for(const n of e)s[i++]=n.segment;return s}}return r=>[...r]})(),Ue.experimentalLetterSpacing=!1,U
|
||
|
|
`&&y!=="\r"&&y!==" "&&y!==" "&&(x=!0,f=Math.ceil(Math.max(O,f))),d+C>v&&(p+=f,f=O,d=0,p+f>b)){h.update();const R=this._nextPage();l=R.canvasAndContext.canvas,u=R.canvasAndContext.context,h=R.texture.source,d=0,p=0,f=0}const F=u.measureText(y).width/m;if(this.chars[y]={id:y.codePointAt(0),xOffset:-(_/m),yOffset:-(_/m),xAdvance:F,kerning:{}},x){this._drawGlyph(u,w,d+_,p+_,m,c);const R=h.width*m,G=h.height*m,M=new it(d/R*h.width,p/G*h.height,C/R*h.width,O/G*h.height);this.chars[y].texture=new B({source:h,frame:M}),d+=Math.ceil(C)}}h.update(),this._currentX=d,this._currentY=p,this._currentMaxCharHeight=f,this._skipKerning||this._applyKerning(o,u,m)}get pageTextures(){return this.pages}_applyKerning(t,e,s){const i=this._measureCache;for(let n=0;n<t.length;n++){const o=t[n];for(let a=0;a<this._currentChars.length;a++){const l=this._currentChars[a];let u=i[o];u||(u=i[o]=e.measureText(o).width);let h=i[l];h||(h=i[l]=e.measureText(l).width);let c=e.measureText(o+l).width,d=c-(u+h);d&&this.chars[o]&&(this.chars[o].kerning[l]=d/s),c=e.measureText(o+l).width,d=c-(u+h),d&&this.chars[l]&&(this.chars[l].kerning[o]=d/s)}}}_nextPage(){this._currentPageIndex++;const t=this.resolution,e=se.getOptimalCanvasAndContext(this._textureSize,this._textureSize,t);this._setupContext(e.context,this._style,t);const s=t*(this.baseRenderedFontSize/this.baseMeasurementFontSize),i=new B({source:new je({resource:e.canvas,resolution:s,alphaMode:"premultiply-alpha-on-upload",autoGenerateMipmaps:this._mipmap})});this._textureStyle&&(i.source.style=this._textureStyle);const n={canvasAndContext:e,texture:i};return this.pages[this._currentPageIndex]=n,n}_setupContext(t,e,s){var i;e.fontSize=this.baseRenderedFontSize,t.scale(s,s),t.font=ts(e),e.fontSize=this.baseMeasurementFontSize,t.textBaseline=e.textBaseline;const n=e._stroke,o=(i=n==null?void 0:n.width)!=null?i:0;if(n&&(t.lineWidth=o,t.lineJoin=n.join,t.miterLimit=n.miterLimit,t.strokeStyle=xr(n,t)),e._fill&&(t.fillStyle=xr(e._fill,t)),e.dropShadow){const a=e.dropShadow,l=tt.shared.setValue(a.color).toArray(),u=a.blur*s,h=a.distance*s;t.shadowColor=`rgba(${l[0]*255},${l[1]*255},${l[2]*255},${a.alpha})`,t.shadowBlur=u,t.shadowOffsetX=Math.cos(a.angle)*h,t.shadowOffsetY=Math.sin(a.angle)*h}else t.shadowColor="black",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0}_drawGlyph(t,e,s,i,n,o){var a;const l=e.text,u=e.fontProperties,h=o._stroke,c=((a=h==null?void 0:h.width)!=null?a:0)*n,d=s+c/2,p=i-c/2,f=u.descent*n,m=e.lineHeight*n;let g=!1;o.stroke&&c&&(g=!0,t.strokeText(l,d,p+m-f));const{shadowBlur:_,shadowOffsetX:x,shadowOffsetY:v}=t;o._fill&&(g&&(t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0),t.fillText(l,d,p+m-f)),g&&(t.shadowBlur=_,t.shadowOffsetX=x,t.shadowOffsetY=v)}destroy(){super.destroy();for(let t=0;t<this.pages.length;t++){const{canvasAndContext:e,texture:s}=this.pages[t];se.returnCanvasAndContext(e),s.destroy(!0)}this.pages=null}};Qv.defaultOptions={textureSize:512,style:new Xt,mipmap:!0};let Ru=Qv;function Ln(r,t,e,s){var i,n;const o={width:0,height:0,offsetY:0,scale:t.fontSize/e.baseMeasurementFontSize,lines:[{width:0,charPositions:[],spaceWidth:0,spacesIndex:[],chars:[]}]};o.offsetY=e.baseLineOffset;let a=o.lines[0],l=null,u=!0;const h={spaceWord:!1,width:0,start:0,index:0,positions:[],chars:[]},c=e.baseMeasurementFontSize/t.fontSize,d=t.letterSpacing*c,p=t.wordWrapWidth*c,f=t.lineHeight?t.lineHeight*c:e.lineHeight,m=t.wordWrap&&t.breakWords,g=$n(t.whiteSpace),_=Un(t.whiteSpace);if(g||_){const S=[];let y=g;for(let w=0;w<r.length;w++){let E=r[w];if(E==="\r"||E===`
|
||
|
|
`)if(_)E==="\r"&&r[w+1]===`
|
||
|
|
`&&w++,E=" ";else{g&&(y=!0),S.push(E);continue}if(Jt(E))if(g&&vu(E)){if(y)continue;y=!0,S.push(" ")}else y=!1,S.push(E);else y=!1,S.push(E)}r=S}const x=S=>{const y=a.width;for(let w=0;w<h.index;w++){const E=S.positions[w];a.chars.push(S.chars[w]),a.charPositions.push(E+y)}a.width+=S.width,(h.index>0||!g)&&(u=!1),h.width=0,h.index=0,h.chars.length=0},v=()=>{let S=a.chars.length-1;if(s){let y=a.chars[S];for(;vu(y);)a.width-=e.chars[y].xAdvance,a.spacesIndex.pop(),y=a.chars[--S]}o.width=Math.max(o.width,a.width),a={width:0,charPositions:[],chars:[],spaceWidth:0,spacesIndex:[]},u=!0,o.lines.push(a),o.height+=f},b=S=>S-d>p;for(let S=0;S<r.length+1;S++){let y;const w=S===r.length;w||(y=r[S]);const E=e.chars[y];if(/(?:\s)/.test(y)||y==="\r"||y===`
|
||
|
|
`||w){if(!u&&t.wordWrap&&b(a.width+h.width)?(v(),x(h),!w&&E&&a.charPositions.push(0)):(h.start=a.width,x(h),!w&&E&&a.charPositions.push(0)),y==="\r"||y===`
|
||
|
|
`)v();else if(!w&&E){const A=E.xAdvance+(((i=E.kerning)==null?void 0:i[l])||0)+d;a.width+=A,a.spaceWidth=A,a.spacesIndex.push(a.charPositions.length),a.chars.push(y)}}else if(E){const A=((n=E.kerning)==null?void 0:n[l])||0,P=E.xAdvance+A+d;m&&b(h.width+P)&&(u||v(),x(h),v()),h.positions[h.index++]=h.width+A,h.chars.push(y),h.width+=P,bu(y)&&(!u&&t.wordWrap&&b(a.width+h.width)&&v(),x(h))}l=y}return v(),t.align==="center"?_O(o):t.align==="right"?xO(o):t.align==="justify"&&vO(o),o}function _O(r){for(let t=0;t<r.lines.length;t++){const e=r.lines[t],s=r.width/2-e.width/2;for(let i=0;i<e.charPositions.length;i++)e.charPositions[i]+=s}}function xO(r){for(let t=0;t<r.lines.length;t++){const e=r.lines[t],s=r.width-e.width;for(let i=0;i<e.charPositions.length;i++)e.charPositions[i]+=s}}function vO(r){const t=r.width;for(let e=0;e<r.lines.length-2;e++){const s=r.lines[e];let i=0,n=s.spacesIndex[i++],o=0;const a=s.spacesIndex.length,l=(t-s.width)/a;for(let u=0;u<s.charPositions.length;u++)u===n&&(n=s.spacesIndex[i++],o+=l),s.charPositions[u]+=o}}function Jv(r){if(r==="")return[];typeof r=="string"&&(r=[r]);const t=[];for(let e=0,s=r.length;e<s;e++){const i=r[e];if(Array.isArray(i)){if(i.length!==2)throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${i.length}.`);if(i[0].length===0||i[1].length===0)throw new Error("[BitmapFont]: Invalid character delimiter.");const n=i[0].charCodeAt(0),o=i[1].charCodeAt(0);if(o<n)throw new Error("[BitmapFont]: Invalid character range.");for(let a=n,l=o;a<=l;a++)t.push(String.fromCharCode(a))}else t.push(...Array.from(i))}if(t.length===0)throw new Error("[BitmapFont]: Empty set when resolving characters.");return t}var bO=Object.defineProperty,tb=Object.getOwnPropertySymbols,yO=Object.prototype.hasOwnProperty,TO=Object.prototype.propertyIsEnumerable,eb=(r,t,e)=>t in r?bO(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Mu=(r,t)=>{for(var e in t||(t={}))yO.call(t,e)&&eb(r,e,t[e]);if(tb)for(var e of tb(t))TO.call(t,e)&&eb(r,e,t[e]);return r};let Nn=0,SO=class{constructor(){this.ALPHA=[["a","z"],["A","Z"]," "],this.NUMERIC=[["0","9"]],this.ALPHANUMERIC=[["a","z"],["A","Z"],["0","9"]," "],this.ASCII=[[" ","~"]],this.defaultOptions={chars:this.ALPHANUMERIC,resolution:1,padding:4,skipKerning:!1,textureStyle:null},this.measureCache=Av(1e3)}getFont(t,e){var s,i;let n=`${e.fontFamily}-bitmap`,o=!0;if(rt.has(n)){const l=rt.get(n);return(s=l.ensureCharacters)==null||s.call(l,t),l}if(e._fill.fill&&!e._stroke?(n+=e._fill.fill.styleKey,o=!1):(e._stroke||e.dropShadow)&&(n=`${e.styleKey}-bitmap`,o=!1),n+=`-${e.fontStyle}`,n+=`-${e.fontVariant}`,n+=`-${e.fontWeight}`,!rt.has(n)){const l=Object.create(e);l._lineHeight=0;const u=new Ru(Mu({style:l,overrideFill:o,overrideSize:!0},this.defaultOptions));Nn++,Nn>50&&Bt("BitmapText",`You have dynamically created ${Nn} bitmap fonts, this can be inefficient. Try pre installing your font styles using \`BitmapFont.install({name:"style1", style})\``),u.once("destroy",()=>{Nn--,rt.remove(n)}),rt.set(n,u)}const a=rt.get(n);return(i=a.ensureCharacters)==null||i.call(a,t),a}getLayout(t,e,s=!0){const i=this.getFont(t,e),n=`${t}-${e.styleKey}-${s}`;if(this.measureCache.has(n))return this.measureCache.get(n);const o=vt.graphemeSegmenter(t),a=Ln(o,e,i,s);return this.measureCache.set(n,a),a}measureText(t,e,s=!0){return this.getLayout(t,e,s)}install(...t){var e,s,i,n,o;let a=t[0];typeof a=="string"&&(a={name:a,style:t[1],chars:(e=t[2])==null?void 0:e.chars,resolution:(s=t[2])==null?void 0:s.resolution,padding:(i=t[2])==null?void 0:i.padding,skipKerning:(n=t[2])==null?void 0:n.skipKerning});const l=a==null?void 0:a.name;if(!l)throw new Error("[BitmapFontManager] Property `name` is required.");a=Mu(Mu({},this.defaultOptions),a);const u=a.style,h=u instanceof Xt?u:new Xt(u),c=(o=a.dynamicFill)!=null?o:this._canUseTintForStyle(h),d=new Ru({style:h,overrideFill:c,skipKerning:a.skipKerning,padding:a.padding,resolution:a.resolution,overrideSize:!1,textureStyle:a.textureStyle}),p=Jv(a.chars);return d.ensureCharacters(p.join("")),rt.set(`${l}-bitmap`,d),d.
|
||
|
|
struct LocalUniforms {
|
||
|
|
uColor:vec4<f32>,
|
||
|
|
uTransformMatrix:mat3x3<f32>,
|
||
|
|
uDistance: f32,
|
||
|
|
uRound:f32,
|
||
|
|
}
|
||
|
|
|
||
|
|
@group(2) @binding(0) var<uniform> localUniforms : LocalUniforms;
|
||
|
|
`,main:`
|
||
|
|
vColor *= localUniforms.uColor;
|
||
|
|
modelMatrix *= localUniforms.uTransformMatrix;
|
||
|
|
`,end:`
|
||
|
|
if(localUniforms.uRound == 1)
|
||
|
|
{
|
||
|
|
vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
|
||
|
|
}
|
||
|
|
`},fragment:{header:`
|
||
|
|
struct LocalUniforms {
|
||
|
|
uColor:vec4<f32>,
|
||
|
|
uTransformMatrix:mat3x3<f32>,
|
||
|
|
uDistance: f32
|
||
|
|
}
|
||
|
|
|
||
|
|
@group(2) @binding(0) var<uniform> localUniforms : LocalUniforms;
|
||
|
|
`,main:`
|
||
|
|
outColor = vec4<f32>(calculateMSDFAlpha(outColor, vColor, localUniforms.uDistance));
|
||
|
|
`}},nb={name:"local-uniform-msdf-bit",vertex:{header:`
|
||
|
|
uniform mat3 uTransformMatrix;
|
||
|
|
uniform vec4 uColor;
|
||
|
|
uniform float uRound;
|
||
|
|
`,main:`
|
||
|
|
vColor *= uColor;
|
||
|
|
modelMatrix *= uTransformMatrix;
|
||
|
|
`,end:`
|
||
|
|
if(uRound == 1.)
|
||
|
|
{
|
||
|
|
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
||
|
|
}
|
||
|
|
`},fragment:{header:`
|
||
|
|
uniform float uDistance;
|
||
|
|
`,main:`
|
||
|
|
outColor = vec4(calculateMSDFAlpha(outColor, vColor, uDistance));
|
||
|
|
`}},ob={name:"msdf-bit",fragment:{header:`
|
||
|
|
fn calculateMSDFAlpha(msdfColor:vec4<f32>, shapeColor:vec4<f32>, distance:f32) -> f32 {
|
||
|
|
|
||
|
|
// MSDF
|
||
|
|
var median = msdfColor.r + msdfColor.g + msdfColor.b -
|
||
|
|
min(msdfColor.r, min(msdfColor.g, msdfColor.b)) -
|
||
|
|
max(msdfColor.r, max(msdfColor.g, msdfColor.b));
|
||
|
|
|
||
|
|
// SDF
|
||
|
|
median = min(median, msdfColor.a);
|
||
|
|
|
||
|
|
var screenPxDistance = distance * (median - 0.5);
|
||
|
|
var alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
||
|
|
if (median < 0.01) {
|
||
|
|
alpha = 0.0;
|
||
|
|
} else if (median > 0.99) {
|
||
|
|
alpha = 1.0;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Gamma correction for coverage-like alpha
|
||
|
|
var luma: f32 = dot(shapeColor.rgb, vec3<f32>(0.299, 0.587, 0.114));
|
||
|
|
var gamma: f32 = mix(1.0, 1.0 / 2.2, luma);
|
||
|
|
var coverage: f32 = pow(shapeColor.a * alpha, gamma);
|
||
|
|
|
||
|
|
return coverage;
|
||
|
|
|
||
|
|
}
|
||
|
|
`}},ab={name:"msdf-bit",fragment:{header:`
|
||
|
|
float calculateMSDFAlpha(vec4 msdfColor, vec4 shapeColor, float distance) {
|
||
|
|
|
||
|
|
// MSDF
|
||
|
|
float median = msdfColor.r + msdfColor.g + msdfColor.b -
|
||
|
|
min(msdfColor.r, min(msdfColor.g, msdfColor.b)) -
|
||
|
|
max(msdfColor.r, max(msdfColor.g, msdfColor.b));
|
||
|
|
|
||
|
|
// SDF
|
||
|
|
median = min(median, msdfColor.a);
|
||
|
|
|
||
|
|
float screenPxDistance = distance * (median - 0.5);
|
||
|
|
float alpha = clamp(screenPxDistance + 0.5, 0.0, 1.0);
|
||
|
|
|
||
|
|
if (median < 0.01) {
|
||
|
|
alpha = 0.0;
|
||
|
|
} else if (median > 0.99) {
|
||
|
|
alpha = 1.0;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Gamma correction for coverage-like alpha
|
||
|
|
float luma = dot(shapeColor.rgb, vec3(0.299, 0.587, 0.114));
|
||
|
|
float gamma = mix(1.0, 1.0 / 2.2, luma);
|
||
|
|
float coverage = pow(shapeColor.a * alpha, gamma);
|
||
|
|
|
||
|
|
return coverage;
|
||
|
|
}
|
||
|
|
`}};let Iu,Fu;class lb extends ne{constructor(t){const e=new wt({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new D,type:"mat3x3<f32>"},uDistance:{value:4,type:"f32"},uRound:{value:0,type:"f32"}});Iu!=null||(Iu=Ur({name:"sdf-shader",bits:[Yi,qi(t),ib,ob,Lr]})),Fu!=null||(Fu=kr({name:"sdf-shader",bits:[Ki,Zi(t),nb,ab,Nr]})),super({glProgram:Fu,gpuProgram:Iu,resources:{localUniforms:e,batchSamplers:Qi(t)}})}}class Bu extends Ou{getSdfShader(){return new lb(this._renderer.limits.maxBatchableTextures)}}Bu.extension={type:[T.WebGLPipes,T.WebGPUPipes],name:"bitmapText"},L.add(Gu),L.add(Bu);class Du extends In{constructor(...t){var e,s,i;const n=Fn(t,"BitmapText");(e=n.style)!=null||(n.style=n.style||{}),(i=(s=n.style).fill)!=null||(s.fill=16777215),super(n,Xt),this.renderPipeId="bitmapText"}_onTouch(t){var e;this._gcLastUsed=t;for(const s in this._gpuData)(e=this._gpuData[s])==null||e._onTouch(t)}updateBounds(){const t=this._bounds,e=this._anchor,s=rs.measureText(this.text,this._style),i=s.scale,n=s.offsetY*i;let o=s.width*i,a=s.height*i;const l=this._style._stroke;l&&(o+=l.width,a+=l.width),t.minX=-e._x*o,t.maxX=t.minX+o,t.minY=-e._y*(a+n),t.maxY=t.minY+a}set resolution(t){}get resolution(){return this._resolution}}var wO=Object.defineProperty,ub=Object.getOwnPropertySymbols,EO=Object.prototype.hasOwnProperty,AO=Object.prototype.propertyIsEnumerable,hb=(r,t,e)=>t in r?wO(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,$u=(r,t)=>{for(var e in t||(t={}))EO.call(t,e)&&hb(r,e,t[e]);if(ub)for(var e of ub(t))AO.call(t,e)&&hb(r,e,t[e]);return r};function cb(r){var t;const e=r._stroke,s=r._fill,i=[`div { ${[`color: ${tt.shared.setValue(s.color).setAlpha((t=s.alpha)!=null?t:1).toHexa()}`,`font-size: ${r.fontSize}px`,`font-family: ${r.fontFamily}`,`font-weight: ${r.fontWeight}`,`font-style: ${r.fontStyle}`,`font-variant: ${r.fontVariant}`,`letter-spacing: ${r.letterSpacing}px`,`text-align: ${r.align}`,`padding: ${r.padding}px`,`white-space: ${r.whiteSpace==="pre"&&r.wordWrap?"pre-wrap":r.whiteSpace}`,...r.lineHeight?[`line-height: ${r.lineHeight}px`]:[],...r.wordWrap?[`word-break: ${r.breakWords?"break-word":"normal"}`,`max-width: ${r.wordWrapWidth}px`]:[],...e?[db(e)]:[],...r.dropShadow?[Uu(r.dropShadow)]:[],...r.cssOverrides].join(";")} }`];return PO(r.tagStyles,i),i.join(" ")}function Uu(r){var t;const e=$u({},r),s=tt.shared.setValue(e.color).setAlpha((t=e.alpha)!=null?t:1).toHexa(),i=Math.round(Math.cos(e.angle)*e.distance),n=Math.round(Math.sin(e.angle)*e.distance),o=`${i}px ${n}px`;return e.blur>0?`text-shadow: ${o} ${e.blur}px ${s}`:`text-shadow: ${o} ${s}`}function db(r){var t;const e=tt.shared.setValue(r.color).setAlpha((t=r.alpha)!=null?t:1).toHexa();return[`-webkit-text-stroke-width: ${r.width}px`,`-webkit-text-stroke-color: ${e}`,`text-stroke-width: ${r.width}px`,`text-stroke-color: ${e}`,"paint-order: stroke"].join(";")}const pb={fontSize:"font-size: {{VALUE}}px",fontFamily:"font-family: {{VALUE}}",fontWeight:"font-weight: {{VALUE}}",fontStyle:"font-style: {{VALUE}}",fontVariant:"font-variant: {{VALUE}}",letterSpacing:"letter-spacing: {{VALUE}}px",align:"text-align: {{VALUE}}",padding:"padding: {{VALUE}}px",whiteSpace:"white-space: {{VALUE}}",lineHeight:"line-height: {{VALUE}}px",wordWrapWidth:"max-width: {{VALUE}}px"},fb={fill:r=>`color: ${tt.shared.setValue(r).toHexa()}`,breakWords:r=>`word-break: ${r?"break-all":"normal"}`,stroke:db,dropShadow:r=>r===!0?Uu(Xt.defaultDropShadow):r&&typeof r=="object"?Uu($u($u({},Xt.defaultDropShadow),r)):""};function PO(r,t){for(const e in r){const s=r[e],i=[];for(const n in s)fb[n]?i.push(fb[n](s[n])):pb[n]&&i.push(pb[n].replace("{{VALUE}}",s[n]));t.push(`${e} { ${i.join(";")} }`)}}var CO=Object.defineProperty,mb=Object.getOwnPropertySymbols,RO=Object.prototype.hasOwnProperty,MO=Object.prototype.propertyIsEnumerable,gb=(r,t,e)=>t in r?CO(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,_b=(r,t)=>{for(var e in t||(t={}))RO.call(t,e)&&gb(r,e,t[e]);if(mb)for(var e of mb(t))MO.call(t,e)&&gb(r,e,t[e]);return r};cl
|
||
|
|
font-family: "${r.fontFamily}";
|
||
|
|
font-weight: ${r.fontWeight};
|
||
|
|
font-style: ${r.fontStyle};
|
||
|
|
src: url('${e}');
|
||
|
|
}`}const jn=new Map;async function Eb(r){const t=r.filter(e=>rt.has(`${e}-and-url`)).map(e=>{if(!jn.has(e)){const{entries:s}=rt.get(`${e}-and-url`),i=[];s.forEach(n=>{const o=n.url,a=n.faces.map(l=>({weight:l.weight,style:l.style}));i.push(...a.map(l=>wb({fontWeight:l.weight,fontStyle:l.style,fontFamily:e},o)))}),jn.set(e,Promise.all(i).then(n=>n.join(`
|
||
|
|
`)))}return jn.get(e)});return(await Promise.all(t)).join(`
|
||
|
|
`)}function Ab(r,t,e,s,i){const{domElement:n,styleElement:o,svgRoot:a}=i;n.innerHTML=`<style>${t.cssStyle}</style><div style='padding:0;'>${r}</div>`,n.setAttribute("style",`transform: scale(${e});transform-origin: top left; display: inline-block`),o.textContent=s;const{width:l,height:u}=i.image;return a.setAttribute("width",l.toString()),a.setAttribute("height",u.toString()),new XMLSerializer().serializeToString(a)}function Pb(r,t){const e=se.getOptimalCanvasAndContext(r.width,r.height,t),{context:s}=e;return s.clearRect(0,0,r.width,r.height),s.drawImage(r,0,0),e}function Cb(r,t,e){return new Promise(async s=>{e&&await new Promise(i=>setTimeout(i,100)),r.onload=()=>{s()},r.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(t)}`,r.crossOrigin="anonymous"})}class Xu{constructor(t){this._activeTextures={},this._renderer=t,this._createCanvas=t.type===Mt.WEBGPU}getTexture(t){return this.getTexturePromise(t)}getManagedTexture(t){const e=t.styleKey;if(this._activeTextures[e])return this._increaseReferenceCount(e),this._activeTextures[e].promise;const s=this._buildTexturePromise(t).then(i=>(this._activeTextures[e].texture=i,i));return this._activeTextures[e]={texture:null,promise:s,usageCount:1},s}getReferenceCount(t){var e,s;return(s=(e=this._activeTextures[t])==null?void 0:e.usageCount)!=null?s:null}_increaseReferenceCount(t){this._activeTextures[t].usageCount++}decreaseReferenceCount(t){const e=this._activeTextures[t];e&&(e.usageCount--,e.usageCount===0&&(e.texture?this._cleanUp(e.texture):e.promise.then(s=>{e.texture=s,this._cleanUp(e.texture)}).catch(()=>{}),this._activeTextures[t]=null))}getTexturePromise(t){return this._buildTexturePromise(t)}async _buildTexturePromise(t){var e;const{text:s,style:i,resolution:n,textureStyle:o,autoGenerateMipmaps:a}=t,l=St.get(ku),u=Tb(s,i),h=await Eb(u),c=Lu(s,i,h,l),d=Math.ceil(Math.ceil(Math.max(1,c.width)+i.padding*2)*n),p=Math.ceil(Math.ceil(Math.max(1,c.height)+i.padding*2)*n),f=l.image,m=2;f.width=(d|0)+m,f.height=(p|0)+m;const g=Ab(s,i,n,h,l);await Cb(f,g,ju()&&u.length>0);const _=f;let x;this._createCanvas&&(x=Pb(f,n));const v=Di(x?x.canvas:_,f.width-m,f.height-m,n,a,o==null?void 0:o.scaleMode);return(e=this._renderer)==null||e.texture.initSource(v.source),this._createCanvas&&se.returnCanvasAndContext(x),St.return(l),v}returnTexturePromise(t){t.then(e=>{this._cleanUp(e)}).catch(()=>{})}_cleanUp(t){const e=t.source;ft.returnTexture(t),e.resource=null,e.uploadMethodId="unknown"}destroy(){this._renderer=null;for(const t in this._activeTextures)this._activeTextures[t]&&this.returnTexturePromise(this._activeTextures[t].promise);this._activeTextures=null}}Xu.extension={type:[T.WebGLSystem,T.WebGPUSystem,T.CanvasSystem],name:"htmlText"},L.add(Xu),L.add(Nu);class Rb extends In{constructor(...t){var e;const s=Fn(t,"HtmlText");super(s,Do),this.renderPipeId="htmlText",s.textureStyle&&(this.textureStyle=s.textureStyle instanceof ae?s.textureStyle:new ae(s.textureStyle),this.textureStyle,void 0),this.autoGenerateMipmaps=(e=s.autoGenerateMipmaps)!=null?e:ct.defaultOptions.autoGenerateMipmaps}updateBounds(){const t=this._bounds,e=this._anchor,s=Lu(this.text,this._style),{width:i,height:n}=s;t.minX=-e._x*i,t.maxX=t.minX+i,t.minY=-e._y*n,t.maxY=t.minY+n}get text(){return this._text}set text(t){const e=this._sanitiseText(t.toString());super.text=e}_sanitiseText(t){return this._removeInvalidHtmlTags(t.replace(/<br>/gi,"<br/>").replace(/<hr>/gi,"<hr/>").replace(/ /gi," "))}_removeInvalidHtmlTags(t){const e=/<[^>]*?(?=<|$)/g;return t.replace(e,"")}}class Mb extends Yv{uploadQueueItem(t){t instanceof ct?this.uploadTextureSource(t):t instanceof Js?this.uploadText(t):t instanceof Rb?this.uploadHTMLText(t):t instanceof Du?this.uploadBitmapText(t):t instanceof Nt&&this.uploadGraphicsContext(t)}uploadTextureSource(t){this.renderer.texture.initSource(t)}uploadText(t){this.renderer.renderPipes.text.initGpuText(t)}uploadBitmapText(t){this.renderer.renderPipes.bitmapText.initGpuText(t)}uploadHTMLText(t){this.renderer.renderPipes.htmlText.initGpuText(t)}uploadGraphicsContext(t){this.renderer.g
|
||
|
|
`)}const Ib={name:"texture-bit",vertex:{header:`
|
||
|
|
|
||
|
|
struct TextureUniforms {
|
||
|
|
uTextureMatrix:mat3x3<f32>,
|
||
|
|
}
|
||
|
|
|
||
|
|
@group(2) @binding(2) var<uniform> textureUniforms : TextureUniforms;
|
||
|
|
`,main:`
|
||
|
|
uv = (textureUniforms.uTextureMatrix * vec3(uv, 1.0)).xy;
|
||
|
|
`},fragment:{header:`
|
||
|
|
@group(2) @binding(0) var uTexture: texture_2d<f32>;
|
||
|
|
@group(2) @binding(1) var uSampler: sampler;
|
||
|
|
|
||
|
|
|
||
|
|
`,main:`
|
||
|
|
outColor = textureSample(uTexture, uSampler, vUV);
|
||
|
|
`}},Fb={name:"texture-bit",vertex:{header:`
|
||
|
|
uniform mat3 uTextureMatrix;
|
||
|
|
`,main:`
|
||
|
|
uv = (uTextureMatrix * vec3(uv, 1.0)).xy;
|
||
|
|
`},fragment:{header:`
|
||
|
|
uniform sampler2D uTexture;
|
||
|
|
|
||
|
|
|
||
|
|
`,main:`
|
||
|
|
outColor = texture(uTexture, vUV);
|
||
|
|
`}},FO=new Ct;let BO=class extends ms{constructor(){super(),this._placeholderSprite=new _e(B.EMPTY),this.filters=[new $x({sprite:this._placeholderSprite,inverse:!1,resolution:"inherit",antialias:"inherit"})]}get sprite(){return this.filters[0].sprite}set sprite(t){this.filters[0].setSprite(t)}get inverse(){return this.filters[0].inverse}set inverse(t){this.filters[0].inverse=t}get channel(){return this.filters[0].channel}set channel(t){this.filters[0].channel=t}reset(){this._placeholderSprite.texture=B.EMPTY,this.sprite=this._placeholderSprite}};class zn{constructor(t){this._activeMaskStage=[],this._usedEffects=[],this._renderer=t,t.runners.postrender.add(this)}push(t,e,s){var i;const n=this._renderer;if(n.renderPipes.batch.break(s),s.add({renderPipeId:"alphaMask",action:"pushMaskBegin",mask:t,inverse:e._maskOptions.inverse,canBundle:!1,maskedContainer:e}),t.inverse=e._maskOptions.inverse,t.channel=(i=e._maskOptions.channel)!=null?i:"red",t.renderMaskToTexture){const o=t.mask;o.includeInBuild=!0,o.collectRenderables(s,n,null),o.includeInBuild=!1}n.renderPipes.batch.break(s),s.add({renderPipeId:"alphaMask",action:"pushMaskEnd",mask:t,maskedContainer:e,inverse:e._maskOptions.inverse,canBundle:!1})}pop(t,e,s){this._renderer.renderPipes.batch.break(s),s.add({renderPipeId:"alphaMask",action:"popMaskEnd",mask:t,inverse:e._maskOptions.inverse,canBundle:!1})}execute(t){const e=this._renderer,s=t.mask.renderMaskToTexture;if(t.action==="pushMaskBegin"){const i=St.get(BO);if(i.inverse=t.inverse,i.channel=t.mask.channel,s){t.mask.mask.measurable=!0;const n=gs(t.mask.mask,!0,FO);t.mask.mask.measurable=!1,n.ceil();const o=e.renderTarget.renderTarget.colorTexture.source,a=ft.getOptimalTexture({width:n.width,height:n.height,resolution:o._resolution,antialias:o.antialias});e.renderTarget.push({target:a,clear:!0}),e.globalUniforms.push({offset:n,worldColor:4294967295});const l=i.sprite;l.texture=a,l.worldTransform.tx=n.minX,l.worldTransform.ty=n.minY,this._activeMaskStage.push({filterEffect:i,maskedContainer:t.maskedContainer,filterTexture:a})}else i.sprite=t.mask.mask,this._activeMaskStage.push({filterEffect:i,maskedContainer:t.maskedContainer})}else if(t.action==="pushMaskEnd"){const i=this._activeMaskStage[this._activeMaskStage.length-1];s&&(e.type===Mt.WEBGL&&e.renderTarget.finishRenderPass(),e.renderTarget.pop(),e.globalUniforms.pop()),e.filter.push({renderPipeId:"filter",action:"pushFilter",container:i.maskedContainer,filterEffect:i.filterEffect,canBundle:!1})}else if(t.action==="popMaskEnd"){e.filter.pop();const i=this._activeMaskStage.pop();s&&ft.returnTexture(i.filterTexture),this._usedEffects.push(i.filterEffect)}}postrender(){const t=this._usedEffects;for(let e=0;e<t.length;e++)St.return(t[e]);t.length=0}destroy(){this.postrender(),this._renderer.runners.postrender.remove(this),this._renderer=null,this._activeMaskStage=null,this._usedEffects=null}}zn.extension={type:[T.WebGLPipes,T.WebGPUPipes,T.CanvasPipes],name:"alphaMask"};class Yu{constructor(t){this._colorStack=[],this._colorStackIndex=0,this._currentColor=0,this._renderer=t}buildStart(){this._colorStack[0]=15,this._colorStackIndex=1,this._currentColor=15}push(t,e,s){this._renderer.renderPipes.batch.break(s);const i=this._colorStack;i[this._colorStackIndex]=i[this._colorStackIndex-1]&t.mask;const n=this._colorStack[this._colorStackIndex];n!==this._currentColor&&(this._currentColor=n,s.add({renderPipeId:"colorMask",colorMask:n,canBundle:!1})),this._colorStackIndex++}pop(t,e,s){this._renderer.renderPipes.batch.break(s);const i=this._colorStack;this._colorStackIndex--;const n=i[this._colorStackIndex-1];n!==this._currentColor&&(this._currentColor=n,s.add({renderPipeId:"colorMask",colorMask:n,canBundle:!1}))}execute(t){}destroy(){this._renderer=null,this._colorStack=null}}Yu.extension={type:[T.CanvasPipes],name:"colorMask"};class Ku{constructor(t){this._colorStack=[],this._colorStackIndex=0,this._currentColor=0,this._renderer=t}buildStart(){this._colorStack[0]=15,this._colorStackIndex=1,this._currentColor=15}push(t,e,s){this._renderer.renderPipes.batch.break(s);const i
|
||
|
|
|
||
|
|
`,"background: #E72264; padding:5px 0;","background: #6CA2EA; padding:5px 0;","background: #B5D33D; padding:5px 0;","background: #FED23F; padding:5px 0;","color: #FFFFFF; background: #E72264; padding:5px 0;","color: #E72264; background: #FFFFFF; padding:5px 0;"];globalThis.console.log(...t)}else globalThis.console&&globalThis.console.log(`PixiJS ${Bs} - ${r} - http://www.pixijs.com/`);ny=!0}}class eo{constructor(t){this._renderer=t}init(t){if(t.hello){let e=this._renderer.name;this._renderer.type===Mt.WEBGL&&(e+=` ${this._renderer.context.webGLVersion}`),oy(e)}}}eo.extension={type:[T.WebGLSystem,T.WebGPUSystem,T.CanvasSystem],name:"hello",priority:-2},eo.defaultOptions={hello:!1};var w3=Object.defineProperty,ay=Object.getOwnPropertySymbols,E3=Object.prototype.hasOwnProperty,A3=Object.prototype.propertyIsEnumerable,ly=(r,t,e)=>t in r?w3(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,uy=(r,t)=>{for(var e in t||(t={}))E3.call(t,e)&&ly(r,e,t[e]);if(ay)for(var e of ay(t))A3.call(t,e)&&ly(r,e,t[e]);return r};const ph=class xS{constructor(t){this._renderer=t}init(t){t=uy(uy({},xS.defaultOptions),t),this.maxUnusedTime=t.renderableGCMaxUnusedTime}get enabled(){return this._renderer.gc.enabled}set enabled(t){this._renderer.gc.enabled=t}addManagedHash(t,e){this._renderer.gc.addCollection(t,e,"hash")}addManagedArray(t,e){this._renderer.gc.addCollection(t,e,"array")}addRenderable(t){this._renderer.gc.addResource(t,"renderable")}run(){this._renderer.gc.run()}destroy(){this._renderer=null}};ph.extension={type:[T.WebGLSystem,T.WebGPUSystem,T.CanvasSystem],name:"renderableGC",priority:0},ph.defaultOptions={renderableGCActive:!0,renderableGCMaxUnusedTime:6e4,renderableGCFrequency:3e4};let hy=ph;const fh=class Ro{get count(){return this._renderer.tick}get checkCount(){return this._checkCount}set checkCount(t){this._checkCount=t}get maxIdle(){return this._renderer.gc.maxUnusedTime/1e3*60}set maxIdle(t){this._renderer.gc.maxUnusedTime=t/60*1e3}get checkCountMax(){return Math.floor(this._renderer.gc._frequency/1e3)}set checkCountMax(t){}get active(){return this._renderer.gc.enabled}set active(t){this._renderer.gc.enabled=t}constructor(t){this._renderer=t,this._checkCount=0}init(t){t.textureGCActive!==Ro.defaultOptions.textureGCActive&&(this.active=t.textureGCActive),t.textureGCMaxIdle!==Ro.defaultOptions.textureGCMaxIdle&&(this.maxIdle=t.textureGCMaxIdle),t.textureGCCheckCountMax!==Ro.defaultOptions.textureGCCheckCountMax&&(this.checkCountMax=t.textureGCCheckCountMax)}run(){this._renderer.gc.run()}destroy(){this._renderer=null}};fh.extension={type:[T.WebGLSystem,T.WebGPUSystem],name:"textureGC"},fh.defaultOptions={textureGCActive:!0,textureGCAMaxIdle:null,textureGCMaxIdle:3600,textureGCCheckCountMax:600};let cy=fh;var P3=Object.defineProperty,dy=Object.getOwnPropertySymbols,C3=Object.prototype.hasOwnProperty,R3=Object.prototype.propertyIsEnumerable,py=(r,t,e)=>t in r?P3(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,fy=(r,t)=>{for(var e in t||(t={}))C3.call(t,e)&&py(r,e,t[e]);if(dy)for(var e of dy(t))R3.call(t,e)&&py(r,e,t[e]);return r};const my=class vS extends It{constructor(t={}){var e;super(),this.uid=ut("renderTarget"),this.colorAttachments=[],this.dirtyId=0,this.isRoot=!1,this._size=new Float32Array(2),this._managedColorTextures=!1,this._depth=!1,this._stencil=!1,this._colorTextures=null;const s="colorAttachments"in t?t:this._normalizeOptions(t);if(this.isRoot=(e=s.isRoot)!=null?e:!1,this.label=s.label,this.colorAttachments=s.colorAttachments,this.depthStencilAttachment=s.depthStencilAttachment,this.depthStencilAttachment){const i=this.depthStencilAttachment.texture.format;this._depth||(this._depth=i.includes("depth")),this._stencil||(this._stencil=i.includes("stencil"))}if(this.colorAttachments.length===0&&!this.depthStencilAttachment)throw new Error("[RenderTarget] no color textures or depth textures were provided. Provide a depthStencilTexture or set depth/stencil to true when using colorTextures: 0.");if(this.colorAttachments.length>0){const i=this.colorTexture;this.resize(i.width,i.height,i._resol
|
||
|
|
attribute vec2 aPosition;
|
||
|
|
out vec2 vUv;
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
gl_Position = vec4(aPosition, 0.0, 1.0);
|
||
|
|
|
||
|
|
vUv = (aPosition + 1.0) / 2.0;
|
||
|
|
|
||
|
|
// flip dem UVs
|
||
|
|
vUv.y = 1.0 - vUv.y;
|
||
|
|
}`,fragment:`
|
||
|
|
in vec2 vUv;
|
||
|
|
out vec4 finalColor;
|
||
|
|
|
||
|
|
uniform sampler2D uTexture;
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
finalColor = texture(uTexture, vUv);
|
||
|
|
}`,name:"big-triangle"});this._bigTriangleShader=new ne({glProgram:i,resources:{uTexture:B.WHITE.source}})}renderStart(t){const e=this._renderer.renderTarget.getRenderTarget(t.target);if(this._useBackBufferThisRender=this.useBackBuffer&&!!e.isRoot,this._useBackBufferThisRender){const s=this._renderer.renderTarget.getRenderTarget(t.target);this._targetTexture=s.colorTexture,t.target=this._getBackBufferTexture(s.colorTexture)}}renderEnd(){this._presentBackBuffer()}_presentBackBuffer(){const t=this._renderer;t.renderTarget.finishRenderPass(),this._useBackBufferThisRender&&(t.renderTarget.bind({target:this._targetTexture,clear:!1}),this._bigTriangleShader.resources.uTexture=this._backBufferTexture.source,t.encoder.draw({geometry:Q3,shader:this._bigTriangleShader,state:this._state}))}_getBackBufferTexture(t){return this._backBufferTexture=this._backBufferTexture||new B({source:new ct({width:t.width,height:t.height,resolution:t._resolution,antialias:this._antialias})}),this._backBufferTexture.source.resize(t.width,t.height,t._resolution),this._backBufferTexture}destroy(){this._backBufferTexture&&(this._backBufferTexture.destroy(),this._backBufferTexture=null)}};Sh.extension={type:[T.WebGLSystem],name:"backBuffer",priority:1},Sh.defaultOptions={useBackBuffer:!1};let jy=Sh;class wh{constructor(t){this._colorMaskCache=15,this._renderer=t}setMask(t){this._colorMaskCache!==t&&(this._colorMaskCache=t,this._renderer.gl.colorMask(!!(t&8),!!(t&4),!!(t&2),!!(t&1)))}}wh.extension={type:[T.WebGLSystem],name:"colorMask"};class Eh{constructor(t){this.commandFinished=Promise.resolve(),this._renderer=t}setGeometry(t,e){this._renderer.geometry.bind(t,e.glProgram)}finishRenderPass(){}draw(t){const e=this._renderer,{geometry:s,shader:i,state:n,skipSync:o,topology:a,size:l,start:u,instanceCount:h}=t;e.shader.bind(i,o),e.geometry.bind(s,e.shader._activeProgram),n&&e.state.set(n),e.geometry.draw(a,l,u,h!=null?h:s.instanceCount)}destroy(){this._renderer=null}}Eh.extension={type:[T.WebGLSystem],name:"encoder"};class Ah{constructor(t){this._renderer=t}contextChange(){const t=this._renderer.gl;this.maxTextures=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),this.maxBatchableTextures=al(this.maxTextures,t);const e=this._renderer.context.webGLVersion===2;this.maxUniformBindings=e?t.getParameter(t.MAX_UNIFORM_BUFFER_BINDINGS):0}destroy(){}}Ah.extension={type:[T.WebGLSystem],name:"limits"};class Xy{constructor(){this.width=-1,this.height=-1,this.msaa=!1,this._attachedMipLevel=0,this._attachedLayer=0,this.msaaRenderBuffer=[],this.stencilMode=bt.DISABLED,this.stencilReference=0,this.maskStackIndex=0}}const ke=[];ke[bt.NONE]=void 0,ke[bt.DISABLED]={stencilWriteMask:0,stencilReadMask:0},ke[bt.RENDERING_MASK_ADD]={stencilFront:{compare:"equal",passOp:"increment-clamp"},stencilBack:{compare:"equal",passOp:"increment-clamp"}},ke[bt.RENDERING_MASK_REMOVE]={stencilFront:{compare:"equal",passOp:"decrement-clamp"},stencilBack:{compare:"equal",passOp:"decrement-clamp"}},ke[bt.MASK_ACTIVE]={stencilWriteMask:0,stencilFront:{compare:"equal",passOp:"keep"},stencilBack:{compare:"equal",passOp:"keep"}},ke[bt.INVERSE_MASK_ACTIVE]={stencilWriteMask:0,stencilFront:{compare:"not-equal",passOp:"keep"},stencilBack:{compare:"not-equal",passOp:"keep"}};class Ph{constructor(t){this._stencilCache={enabled:!1,stencilReference:0,stencilMode:bt.NONE},this._renderer=t,t.renderTarget.onRenderTargetChange.add(this)}contextChange(t){this._gl=t,this._comparisonFuncMapping={always:t.ALWAYS,never:t.NEVER,equal:t.EQUAL,"not-equal":t.NOTEQUAL,less:t.LESS,"less-equal":t.LEQUAL,greater:t.GREATER,"greater-equal":t.GEQUAL},this._stencilOpsMapping={keep:t.KEEP,zero:t.ZERO,replace:t.REPLACE,invert:t.INVERT,"increment-clamp":t.INCR,"decrement-clamp":t.DECR,"increment-wrap":t.INCR_WRAP,"decrement-wrap":t.DECR_WRAP},this._activeGpuRenderTarget=null,this.resetState()}onRenderTargetChange(t){if(this._activeRenderTarget===t)return;this._activeRenderTarget=t;const e=this._renderer.renderTarget.getGpuRenderTarget(t);this._activeGpuRenderTarget=e,this.setStencilMode(e.stencilMode,e.stencilReference)
|
||
|
|
var matrix = uv[name].toArray(true);
|
||
|
|
data[offset] = matrix[0];
|
||
|
|
data[offset + 1] = matrix[1];
|
||
|
|
data[offset + 2] = matrix[2];
|
||
|
|
data[offset + 4] = matrix[3];
|
||
|
|
data[offset + 5] = matrix[4];
|
||
|
|
data[offset + 6] = matrix[5];
|
||
|
|
data[offset + 8] = matrix[6];
|
||
|
|
data[offset + 9] = matrix[7];
|
||
|
|
data[offset + 10] = matrix[8];
|
||
|
|
`,uniform:`
|
||
|
|
gl.uniformMatrix3fv(ud[name].location, false, uv[name].toArray(true));
|
||
|
|
`},{type:"vec4<f32>",test:r=>r.type==="vec4<f32>"&&r.size===1&&r.value.width!==void 0,ubo:`
|
||
|
|
v = uv[name];
|
||
|
|
data[offset] = v.x;
|
||
|
|
data[offset + 1] = v.y;
|
||
|
|
data[offset + 2] = v.width;
|
||
|
|
data[offset + 3] = v.height;
|
||
|
|
`,uniform:`
|
||
|
|
cv = ud[name].value;
|
||
|
|
v = uv[name];
|
||
|
|
if (cv[0] !== v.x || cv[1] !== v.y || cv[2] !== v.width || cv[3] !== v.height) {
|
||
|
|
cv[0] = v.x;
|
||
|
|
cv[1] = v.y;
|
||
|
|
cv[2] = v.width;
|
||
|
|
cv[3] = v.height;
|
||
|
|
gl.uniform4f(ud[name].location, v.x, v.y, v.width, v.height);
|
||
|
|
}
|
||
|
|
`},{type:"vec2<f32>",test:r=>r.type==="vec2<f32>"&&r.size===1&&r.value.x!==void 0,ubo:`
|
||
|
|
v = uv[name];
|
||
|
|
data[offset] = v.x;
|
||
|
|
data[offset + 1] = v.y;
|
||
|
|
`,uniform:`
|
||
|
|
cv = ud[name].value;
|
||
|
|
v = uv[name];
|
||
|
|
if (cv[0] !== v.x || cv[1] !== v.y) {
|
||
|
|
cv[0] = v.x;
|
||
|
|
cv[1] = v.y;
|
||
|
|
gl.uniform2f(ud[name].location, v.x, v.y);
|
||
|
|
}
|
||
|
|
`},{type:"vec4<f32>",test:r=>r.type==="vec4<f32>"&&r.size===1&&r.value.red!==void 0,ubo:`
|
||
|
|
v = uv[name];
|
||
|
|
data[offset] = v.red;
|
||
|
|
data[offset + 1] = v.green;
|
||
|
|
data[offset + 2] = v.blue;
|
||
|
|
data[offset + 3] = v.alpha;
|
||
|
|
`,uniform:`
|
||
|
|
cv = ud[name].value;
|
||
|
|
v = uv[name];
|
||
|
|
if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue || cv[3] !== v.alpha) {
|
||
|
|
cv[0] = v.red;
|
||
|
|
cv[1] = v.green;
|
||
|
|
cv[2] = v.blue;
|
||
|
|
cv[3] = v.alpha;
|
||
|
|
gl.uniform4f(ud[name].location, v.red, v.green, v.blue, v.alpha);
|
||
|
|
}
|
||
|
|
`},{type:"vec3<f32>",test:r=>r.type==="vec3<f32>"&&r.size===1&&r.value.red!==void 0,ubo:`
|
||
|
|
v = uv[name];
|
||
|
|
data[offset] = v.red;
|
||
|
|
data[offset + 1] = v.green;
|
||
|
|
data[offset + 2] = v.blue;
|
||
|
|
`,uniform:`
|
||
|
|
cv = ud[name].value;
|
||
|
|
v = uv[name];
|
||
|
|
if (cv[0] !== v.red || cv[1] !== v.green || cv[2] !== v.blue) {
|
||
|
|
cv[0] = v.red;
|
||
|
|
cv[1] = v.green;
|
||
|
|
cv[2] = v.blue;
|
||
|
|
gl.uniform3f(ud[name].location, v.red, v.green, v.blue);
|
||
|
|
}
|
||
|
|
`}];function Mh(r,t,e){const s=[`
|
||
|
|
var v = null;
|
||
|
|
var v2 = null;
|
||
|
|
var t = 0;
|
||
|
|
var index = 0;
|
||
|
|
var name = null;
|
||
|
|
var arrayOffset = null;
|
||
|
|
`];let i=0;for(let o=0;o<r.length;o++){const a=r[o],l=a.data.name;let u=!1,h=0;for(let c=0;c<br.length;c++)if(br[c].test(a.data)){h=a.offset/4,s.push(`name = "${l}";`,`offset += ${h-i};`,br[c].ubo),u=!0;break}if(!u)if(a.data.size>1)h=a.offset/4,s.push(e(a,h-i));else{const c=t[a.data.type];h=a.offset/4,s.push(`
|
||
|
|
v = uv.${l};
|
||
|
|
offset += ${h-i};
|
||
|
|
${c};
|
||
|
|
`)}i=h}const n=s.join(`
|
||
|
|
`);return new Function("uv","data","dataInt32","offset",n)}var J3=Object.defineProperty,tG=Object.defineProperties,eG=Object.getOwnPropertyDescriptors,zy=Object.getOwnPropertySymbols,rG=Object.prototype.hasOwnProperty,sG=Object.prototype.propertyIsEnumerable,Wy=(r,t,e)=>t in r?J3(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,iG=(r,t)=>{for(var e in t||(t={}))rG.call(t,e)&&Wy(r,e,t[e]);if(zy)for(var e of zy(t))sG.call(t,e)&&Wy(r,e,t[e]);return r},nG=(r,t)=>tG(r,eG(t));function ss(r,t){return`
|
||
|
|
for (let i = 0; i < ${r*t}; i++) {
|
||
|
|
data[offset + (((i / ${r})|0) * 4) + (i % ${r})] = v[i];
|
||
|
|
}
|
||
|
|
`}const Oh={f32:`
|
||
|
|
data[offset] = v;`,i32:`
|
||
|
|
dataInt32[offset] = v;`,u32:`
|
||
|
|
dataInt32[offset] = v;`,"vec2<f32>":`
|
||
|
|
data[offset] = v[0];
|
||
|
|
data[offset + 1] = v[1];`,"vec3<f32>":`
|
||
|
|
data[offset] = v[0];
|
||
|
|
data[offset + 1] = v[1];
|
||
|
|
data[offset + 2] = v[2];`,"vec4<f32>":`
|
||
|
|
data[offset] = v[0];
|
||
|
|
data[offset + 1] = v[1];
|
||
|
|
data[offset + 2] = v[2];
|
||
|
|
data[offset + 3] = v[3];`,"vec2<i32>":`
|
||
|
|
dataInt32[offset] = v[0];
|
||
|
|
dataInt32[offset + 1] = v[1];`,"vec3<i32>":`
|
||
|
|
dataInt32[offset] = v[0];
|
||
|
|
dataInt32[offset + 1] = v[1];
|
||
|
|
dataInt32[offset + 2] = v[2];`,"vec4<i32>":`
|
||
|
|
dataInt32[offset] = v[0];
|
||
|
|
dataInt32[offset + 1] = v[1];
|
||
|
|
dataInt32[offset + 2] = v[2];
|
||
|
|
dataInt32[offset + 3] = v[3];`,"vec2<u32>":`
|
||
|
|
dataInt32[offset] = v[0];
|
||
|
|
dataInt32[offset + 1] = v[1];`,"vec3<u32>":`
|
||
|
|
dataInt32[offset] = v[0];
|
||
|
|
dataInt32[offset + 1] = v[1];
|
||
|
|
dataInt32[offset + 2] = v[2];`,"vec4<u32>":`
|
||
|
|
dataInt32[offset] = v[0];
|
||
|
|
dataInt32[offset + 1] = v[1];
|
||
|
|
dataInt32[offset + 2] = v[2];
|
||
|
|
dataInt32[offset + 3] = v[3];`,"mat2x2<f32>":`
|
||
|
|
data[offset] = v[0];
|
||
|
|
data[offset + 1] = v[1];
|
||
|
|
data[offset + 4] = v[2];
|
||
|
|
data[offset + 5] = v[3];`,"mat3x3<f32>":`
|
||
|
|
data[offset] = v[0];
|
||
|
|
data[offset + 1] = v[1];
|
||
|
|
data[offset + 2] = v[2];
|
||
|
|
data[offset + 4] = v[3];
|
||
|
|
data[offset + 5] = v[4];
|
||
|
|
data[offset + 6] = v[5];
|
||
|
|
data[offset + 8] = v[6];
|
||
|
|
data[offset + 9] = v[7];
|
||
|
|
data[offset + 10] = v[8];`,"mat4x4<f32>":`
|
||
|
|
for (let i = 0; i < 16; i++) {
|
||
|
|
data[offset + i] = v[i];
|
||
|
|
}`,"mat3x2<f32>":ss(3,2),"mat4x2<f32>":ss(4,2),"mat2x3<f32>":ss(2,3),"mat4x3<f32>":ss(4,3),"mat2x4<f32>":ss(2,4),"mat3x4<f32>":ss(3,4)},Vy=nG(iG({},Oh),{"mat2x2<f32>":`
|
||
|
|
data[offset] = v[0];
|
||
|
|
data[offset + 1] = v[1];
|
||
|
|
data[offset + 2] = v[2];
|
||
|
|
data[offset + 3] = v[3];
|
||
|
|
`});function Yy(r,t){const e=Math.max(Rh[r.data.type]/16,1),s=r.data.value.length/r.data.size,i=(4-s%4)%4,n=r.data.type.indexOf("i32")>=0?"dataInt32":"data";return`
|
||
|
|
v = uv.${r.data.name};
|
||
|
|
offset += ${t};
|
||
|
|
|
||
|
|
arrayOffset = offset;
|
||
|
|
|
||
|
|
t = 0;
|
||
|
|
|
||
|
|
for(var i=0; i < ${r.data.size*e}; i++)
|
||
|
|
{
|
||
|
|
for(var j = 0; j < ${s}; j++)
|
||
|
|
{
|
||
|
|
${n}[arrayOffset++] = v[t++];
|
||
|
|
}
|
||
|
|
${i!==0?`arrayOffset += ${i};`:""}
|
||
|
|
}
|
||
|
|
`}function Ky(r){return Mh(r,Oh,Yy)}class Gh extends Ch{constructor(){super({createUboElements:Hy,generateUboSync:Ky})}}Gh.extension={type:[T.WebGLSystem],name:"ubo"};class qy{constructor(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new it,this._boundFramebuffer=void 0}init(t,e){this._renderer=t,this._renderTargetSystem=e,t.runners.contextChange.add(this)}contextChange(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new it,this._boundFramebuffer=void 0;const t=this._renderer.gl;this._drawBuffersCache=[];for(let e=1;e<=16;e++)this._drawBuffersCache[e]=Array.from({length:e},(s,i)=>t.COLOR_ATTACHMENT0+i)}copyToTexture(t,e,s,i,n){const o=this._renderTargetSystem,a=this._renderer,l=o.getGpuRenderTarget(t),u=a.gl;return this.finishRenderPass(t),u.bindFramebuffer(u.FRAMEBUFFER,l.resolveTargetFramebuffer),this._boundFramebuffer=l.resolveTargetFramebuffer,a.texture.bind(e,0),u.copyTexSubImage2D(u.TEXTURE_2D,0,n.x,n.y,s.x,s.y,i.width,i.height),e}copyDepthTexture(t,e,s,i,n){const o=this._renderTargetSystem,a=this._renderer.gl;this.finishRenderPass(t);const l=o.getRenderTarget(e),u=o.getGpuRenderTarget(t),h=o.getGpuRenderTarget(l);a.bindFramebuffer(a.READ_FRAMEBUFFER,u.framebuffer),a.bindFramebuffer(a.DRAW_FRAMEBUFFER,h.framebuffer),this._boundFramebuffer=void 0,a.blitFramebuffer(s.x,s.y,s.x+i.width,s.y+i.height,n.x,n.y,n.x+i.width,n.y+i.height,a.DEPTH_BUFFER_BIT,a.NEAREST)}startRenderPass(t,e=!0,s,i,n=0,o=0){const a=this._renderTargetSystem.getGpuRenderTarget(t);if(o!==0&&this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to array layers requires WebGL2.");if(n>0){if(a.msaa)throw new Error("[RenderTargetSystem] Rendering to mip levels is not supported with MSAA render targets.");if(this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to mip levels requires WebGL2.")}t.colorAttachments.forEach(c=>{this._renderer.texture.unbind(c.texture)});const l=this._renderer.gl;this.bindFramebuffer(a.framebuffer),!t.isRoot&&t.colorAttachments.length>0&&(a._attachedMipLevel!==n||a._attachedLayer!==o)&&(t.colorAttachments.forEach((c,d)=>{const p=c.texture,f=this._renderer.texture.getGlSource(p);if(f.target===l.TEXTURE_2D){if(o!==0)throw new Error("[RenderTargetSystem] layer must be 0 when rendering to 2D textures in WebGL.");l.framebufferTexture2D(l.FRAMEBUFFER,l.COLOR_ATTACHMENT0+d,l.TEXTURE_2D,f.texture,n)}else if(f.target===l.TEXTURE_2D_ARRAY){if(this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to 2D array textures requires WebGL2.");l.framebufferTextureLayer(l.FRAMEBUFFER,l.COLOR_ATTACHMENT0+d,f.texture,n,o)}else if(f.target===l.TEXTURE_CUBE_MAP){if(o<0||o>5)throw new Error("[RenderTargetSystem] Cube map layer must be between 0 and 5.");l.framebufferTexture2D(l.FRAMEBUFFER,l.COLOR_ATTACHMENT0+d,l.TEXTURE_CUBE_MAP_POSITIVE_X+o,f.texture,n)}else throw new Error("[RenderTargetSystem] Unsupported texture target for render-to-layer in WebGL.")}),a._attachedMipLevel=n,a._attachedLayer=o),a.framebuffer&&(t.depthStencilAttachment?this._attachDepthStencilTexture(t,n,o):!a.depthStencilRenderBuffer&&(t.stencil||t.depth)&&this._initStencil(a)),t.colorAttachments.length>1&&this._setDrawBuffers(t,l);let u=i.y;t.isRoot&&(u=t.pixelHeight-i.height-i.y);const h=this._viewPortCache;(h.x!==i.x||h.y!==u||h.width!==i.width||h.height!==i.height)&&(h.x=i.x,h.y=u,h.width=i.width,h.height=i.height,l.viewport(i.x,u,i.width,i.height)),this.clear(t,e,s)}finishRenderPass(t){const e=this._renderTargetSystem.getGpuRenderTarget(t);if(!e.msaa||t.colorAttachments.length===0)return;const s=this._renderer.gl;s.bindFramebuffer(s.FRAMEBUFFER,e.resolveTargetFramebuffer),s.bindFramebuffer(s.READ_FRAMEBUFFER,e.framebuffer),s.blitFramebuffer(0,0,e.width,e.height,0,0,e.width,e.height,s.COLOR_BUFFER_BIT,s.NEAREST),s.bindFramebuffer(s.FRAMEBUFFER,e.framebuffer),this._boundFramebuffer=e.framebuffer}initGpuRenderTarget(t){const e=this._renderer.gl,s=new Xy;s._attachedMipLevel=0,s._attachedLayer=0;const i=t.colorTexture;return i instanceof re?(this._renderer.context.en
|
||
|
|
var g = s.groups;
|
||
|
|
var sS = r.shader;
|
||
|
|
var p = s.glProgram;
|
||
|
|
var ugS = r.uniformGroup;
|
||
|
|
var resources;
|
||
|
|
`];let i=!1,n=0;const o=t._getProgramData(r.glProgram);for(const l in r.groups){const u=r.groups[l];e.push(`
|
||
|
|
resources = g[${l}].resources;
|
||
|
|
`);for(const h in u.resources){const c=u.resources[h];if(c instanceof wt)if(c.ubo){const d=r._uniformBindMap[l][Number(h)];e.push(`
|
||
|
|
sS.bindUniformBlock(
|
||
|
|
resources[${h}],
|
||
|
|
'${d}',
|
||
|
|
${r.glProgram._uniformBlockData[d].index}
|
||
|
|
);
|
||
|
|
`)}else e.push(`
|
||
|
|
ugS.updateUniformGroup(resources[${h}], p, sD);
|
||
|
|
`);else if(c instanceof lo){const d=r._uniformBindMap[l][Number(h)];e.push(`
|
||
|
|
sS.bindUniformBlock(
|
||
|
|
resources[${h}],
|
||
|
|
'${d}',
|
||
|
|
${r.glProgram._uniformBlockData[d].index}
|
||
|
|
);
|
||
|
|
`)}else if(c instanceof ct||c instanceof Zy){const d=r._uniformBindMap[l][h],p=o.uniformData[d];p&&(i||(i=!0,s.push(`
|
||
|
|
var tS = r.texture;
|
||
|
|
`)),t._gl.uniform1i(p.location,n),e.push(`
|
||
|
|
tS.bind(resources[${h}], ${n});
|
||
|
|
`),n++)}}}const a=[...s,...e].join(`
|
||
|
|
`);return new Function("r","s","sD",a)}class oG{}class Jy{constructor(t,e){this.program=t,this.uniformData=e,this.uniformGroups={},this.uniformDirtyGroups={},this.uniformBlockBindings={}}destroy(){this.uniformData=null,this.uniformGroups=null,this.uniformDirtyGroups=null,this.uniformBlockBindings=null,this.program=null}}function Fh(r,t,e){const s=r.createShader(t);return r.shaderSource(s,e),r.compileShader(s),s}function Bh(r){const t=new Array(r);for(let e=0;e<t.length;e++)t[e]=!1;return t}function Dh(r,t){switch(r){case"float":return 0;case"vec2":return new Float32Array(2*t);case"vec3":return new Float32Array(3*t);case"vec4":return new Float32Array(4*t);case"int":case"uint":case"sampler2D":case"sampler2DArray":return 0;case"ivec2":return new Int32Array(2*t);case"ivec3":return new Int32Array(3*t);case"ivec4":return new Int32Array(4*t);case"uvec2":return new Uint32Array(2*t);case"uvec3":return new Uint32Array(3*t);case"uvec4":return new Uint32Array(4*t);case"bool":return!1;case"bvec2":return Bh(2*t);case"bvec3":return Bh(3*t);case"bvec4":return Bh(4*t);case"mat2":return new Float32Array([1,0,0,1]);case"mat3":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}let uo=null;const t0={FLOAT:"float",FLOAT_VEC2:"vec2",FLOAT_VEC3:"vec3",FLOAT_VEC4:"vec4",INT:"int",INT_VEC2:"ivec2",INT_VEC3:"ivec3",INT_VEC4:"ivec4",UNSIGNED_INT:"uint",UNSIGNED_INT_VEC2:"uvec2",UNSIGNED_INT_VEC3:"uvec3",UNSIGNED_INT_VEC4:"uvec4",BOOL:"bool",BOOL_VEC2:"bvec2",BOOL_VEC3:"bvec3",BOOL_VEC4:"bvec4",FLOAT_MAT2:"mat2",FLOAT_MAT3:"mat3",FLOAT_MAT4:"mat4",SAMPLER_2D:"sampler2D",INT_SAMPLER_2D:"sampler2D",UNSIGNED_INT_SAMPLER_2D:"sampler2D",SAMPLER_2D_SHADOW:"sampler2DShadow",SAMPLER_CUBE:"samplerCube",INT_SAMPLER_CUBE:"samplerCube",UNSIGNED_INT_SAMPLER_CUBE:"samplerCube",SAMPLER_CUBE_SHADOW:"samplerCubeShadow",SAMPLER_2D_ARRAY:"sampler2DArray",INT_SAMPLER_2D_ARRAY:"sampler2DArray",UNSIGNED_INT_SAMPLER_2D_ARRAY:"sampler2DArray",SAMPLER_2D_ARRAY_SHADOW:"sampler2DArrayShadow"},aG={float:"float32",vec2:"float32x2",vec3:"float32x3",vec4:"float32x4",int:"sint32",ivec2:"sint32x2",ivec3:"sint32x3",ivec4:"sint32x4",uint:"uint32",uvec2:"uint32x2",uvec3:"uint32x3",uvec4:"uint32x4",bool:"uint32",bvec2:"uint32x2",bvec3:"uint32x3",bvec4:"uint32x4"};function $h(r,t){if(!uo){const e=Object.keys(t0);uo={};for(let s=0;s<e.length;++s){const i=e[s];uo[r[i]]=t0[i]}}return uo[t]}function e0(r,t){const e=$h(r,t);return aG[e]||"float32"}function r0(r,t,e=!1){const s={},i=t.getProgramParameter(r,t.ACTIVE_ATTRIBUTES);for(let o=0;o<i;o++){const a=t.getActiveAttrib(r,o);if(a.name.startsWith("gl_"))continue;const l=e0(t,a.type);s[a.name]={location:0,format:l,stride:Be(l).stride,offset:0,instance:!1,start:0}}const n=Object.keys(s);if(e){n.sort((o,a)=>o>a?1:-1);for(let o=0;o<n.length;o++)s[n[o]].location=o,t.bindAttribLocation(r,o,n[o]);t.linkProgram(r)}else for(let o=0;o<n.length;o++)s[n[o]].location=t.getAttribLocation(r,n[o]);return s}function s0(r,t){if(!t.ACTIVE_UNIFORM_BLOCKS)return{};const e={},s=t.getProgramParameter(r,t.ACTIVE_UNIFORM_BLOCKS);for(let i=0;i<s;i++){const n=t.getActiveUniformBlockName(r,i),o=t.getUniformBlockIndex(r,n),a=t.getActiveUniformBlockParameter(r,i,t.UNIFORM_BLOCK_DATA_SIZE);e[n]={name:n,index:o,size:a}}return e}function i0(r,t){const e={},s=t.getProgramParameter(r,t.ACTIVE_UNIFORMS);for(let i=0;i<s;i++){const n=t.getActiveUniform(r,i),o=n.name.replace(/\[.*?\]$/,""),a=!!n.name.match(/\[.*?\]$/),l=$h(t,n.type);e[o]={name:o,index:i,type:l,size:n.size,isArray:a,value:Dh(l,n.size)}}return e}function n0(r,t){var e;const s=r.getShaderSource(t);if(s===null){console.error("PixiJS Error: Could not retrieve shader source (WebGL context may be lost).");return}const i=s.split(`
|
||
|
|
`).map((c,d)=>`${d}: ${c}`),n=(e=r.getShaderInfoLog(t))!=null?e:"",o=n.split(`
|
||
|
|
`),a={},l=o.map(c=>parseFloat(c.replace(/^ERROR\: 0\:([\d]+)\:.*$/,"$1"))).filter(c=>c&&!a[c]?(a[c]=!0,!0):!1),u=[""];l.forEach(c=>{i[c-1]=`%c${i[c-1]}%c`,u.push("background: #FF0000; color:#FFFFFF; font-size: 10px","font-size: 10px")});const h=i.join(`
|
||
|
|
`);u[0]=h,console.error(n),console.groupCollapsed("click to view full shader code"),console.warn(...u),console.groupEnd()}function o0(r,t,e,s){r.getProgramParameter(t,r.LINK_STATUS)||(r.getShaderParameter(e,r.COMPILE_STATUS)||n0(r,e),r.getShaderParameter(s,r.COMPILE_STATUS)||n0(r,s),console.error("PixiJS Error: Could not initialize shader."),r.getProgramInfoLog(t)!==""&&console.warn("PixiJS Warning: gl.getProgramInfoLog()",r.getProgramInfoLog(t)))}function a0(r,t){const e=Fh(r,r.VERTEX_SHADER,t.vertex),s=Fh(r,r.FRAGMENT_SHADER,t.fragment),i=r.createProgram();r.attachShader(i,e),r.attachShader(i,s);const n=t.transformFeedbackVaryings;n&&(typeof r.transformFeedbackVaryings!="function"||r.transformFeedbackVaryings(i,n.names,n.bufferMode==="separate"?r.SEPARATE_ATTRIBS:r.INTERLEAVED_ATTRIBS)),r.linkProgram(i),r.getProgramParameter(i,r.LINK_STATUS)||o0(r,i,e,s),t._attributeData=r0(i,r,!/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(t.vertex)),t._uniformData=i0(i,r),t._uniformBlockData=s0(i,r),r.deleteShader(e),r.deleteShader(s);const o={};for(const a in t._uniformData){const l=t._uniformData[a];o[a]={location:r.getUniformLocation(i,a),value:Dh(l.type,l.size)}}return new Jy(i,o)}const ho={textureCount:0,blockIndex:0};class Uh{constructor(t){this._activeProgram=null,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._renderer=t}contextChange(t){this._gl=t,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._activeProgram=null}bind(t,e){if(this._setProgram(t.glProgram),e)return;ho.textureCount=0,ho.blockIndex=0;let s=this._shaderSyncFunctions[t.glProgram._key];s||(s=this._shaderSyncFunctions[t.glProgram._key]=this._generateShaderSync(t,this)),this._renderer.buffer.nextBindBase(!!t.glProgram.transformFeedbackVaryings),s(this._renderer,t,ho)}updateUniformGroup(t){this._renderer.uniformGroup.updateUniformGroup(t,this._activeProgram,ho)}bindUniformBlock(t,e,s=0){const i=this._renderer.buffer,n=this._getProgramData(this._activeProgram),o=t._bufferResource;o||this._renderer.ubo.updateUniformGroup(t);const a=t.buffer,l=i.updateBuffer(a),u=i.freeLocationForBufferBase(l);if(o){const{offset:c,size:d}=t;c===0&&d===a.data.byteLength?i.bindBufferBase(l,u):i.bindBufferRange(l,u,c)}else i.getLastBindBaseLocation(l)!==u&&i.bindBufferBase(l,u);const h=this._activeProgram._uniformBlockData[e].index;n.uniformBlockBindings[s]!==u&&(n.uniformBlockBindings[s]=u,this._renderer.gl.uniformBlockBinding(n.program,h,u))}_setProgram(t){if(this._activeProgram===t)return;this._activeProgram=t;const e=this._getProgramData(t);this._gl.useProgram(e.program)}_getProgramData(t){return this._programDataHash[t._key]||this._createProgramData(t)}_createProgramData(t){const e=t._key;return this._programDataHash[e]=a0(this._gl,t),this._programDataHash[e]}destroy(){for(const t of Object.keys(this._programDataHash))this._programDataHash[t].destroy();this._programDataHash=null,this._shaderSyncFunctions=null,this._activeProgram=null,this._renderer=null,this._gl=null}_generateShaderSync(t,e){return Qy(t,e)}resetState(){this._activeProgram=null}}Uh.extension={type:[T.WebGLSystem],name:"shader"};const l0={f32:`if (cv !== v) {
|
||
|
|
cu.value = v;
|
||
|
|
gl.uniform1f(location, v);
|
||
|
|
}`,"vec2<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
|
||
|
|
cv[0] = v[0];
|
||
|
|
cv[1] = v[1];
|
||
|
|
gl.uniform2f(location, v[0], v[1]);
|
||
|
|
}`,"vec3<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
|
||
|
|
cv[0] = v[0];
|
||
|
|
cv[1] = v[1];
|
||
|
|
cv[2] = v[2];
|
||
|
|
gl.uniform3f(location, v[0], v[1], v[2]);
|
||
|
|
}`,"vec4<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
|
||
|
|
cv[0] = v[0];
|
||
|
|
cv[1] = v[1];
|
||
|
|
cv[2] = v[2];
|
||
|
|
cv[3] = v[3];
|
||
|
|
gl.uniform4f(location, v[0], v[1], v[2], v[3]);
|
||
|
|
}`,i32:`if (cv !== v) {
|
||
|
|
cu.value = v;
|
||
|
|
gl.uniform1i(location, v);
|
||
|
|
}`,"vec2<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
|
||
|
|
cv[0] = v[0];
|
||
|
|
cv[1] = v[1];
|
||
|
|
gl.uniform2i(location, v[0], v[1]);
|
||
|
|
}`,"vec3<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
|
||
|
|
cv[0] = v[0];
|
||
|
|
cv[1] = v[1];
|
||
|
|
cv[2] = v[2];
|
||
|
|
gl.uniform3i(location, v[0], v[1], v[2]);
|
||
|
|
}`,"vec4<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
|
||
|
|
cv[0] = v[0];
|
||
|
|
cv[1] = v[1];
|
||
|
|
cv[2] = v[2];
|
||
|
|
cv[3] = v[3];
|
||
|
|
gl.uniform4i(location, v[0], v[1], v[2], v[3]);
|
||
|
|
}`,u32:`if (cv !== v) {
|
||
|
|
cu.value = v;
|
||
|
|
gl.uniform1ui(location, v);
|
||
|
|
}`,"vec2<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
|
||
|
|
cv[0] = v[0];
|
||
|
|
cv[1] = v[1];
|
||
|
|
gl.uniform2ui(location, v[0], v[1]);
|
||
|
|
}`,"vec3<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
|
||
|
|
cv[0] = v[0];
|
||
|
|
cv[1] = v[1];
|
||
|
|
cv[2] = v[2];
|
||
|
|
gl.uniform3ui(location, v[0], v[1], v[2]);
|
||
|
|
}`,"vec4<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
|
||
|
|
cv[0] = v[0];
|
||
|
|
cv[1] = v[1];
|
||
|
|
cv[2] = v[2];
|
||
|
|
cv[3] = v[3];
|
||
|
|
gl.uniform4ui(location, v[0], v[1], v[2], v[3]);
|
||
|
|
}`,bool:`if (cv !== v) {
|
||
|
|
cu.value = v;
|
||
|
|
gl.uniform1i(location, v);
|
||
|
|
}`,"vec2<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
|
||
|
|
cv[0] = v[0];
|
||
|
|
cv[1] = v[1];
|
||
|
|
gl.uniform2i(location, v[0], v[1]);
|
||
|
|
}`,"vec3<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
|
||
|
|
cv[0] = v[0];
|
||
|
|
cv[1] = v[1];
|
||
|
|
cv[2] = v[2];
|
||
|
|
gl.uniform3i(location, v[0], v[1], v[2]);
|
||
|
|
}`,"vec4<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
|
||
|
|
cv[0] = v[0];
|
||
|
|
cv[1] = v[1];
|
||
|
|
cv[2] = v[2];
|
||
|
|
cv[3] = v[3];
|
||
|
|
gl.uniform4i(location, v[0], v[1], v[2], v[3]);
|
||
|
|
}`,"mat2x2<f32>":"gl.uniformMatrix2fv(location, false, v);","mat3x3<f32>":"gl.uniformMatrix3fv(location, false, v);","mat4x4<f32>":"gl.uniformMatrix4fv(location, false, v);"},u0={f32:"gl.uniform1fv(location, v);","vec2<f32>":"gl.uniform2fv(location, v);","vec3<f32>":"gl.uniform3fv(location, v);","vec4<f32>":"gl.uniform4fv(location, v);","mat2x2<f32>":"gl.uniformMatrix2fv(location, false, v);","mat3x3<f32>":"gl.uniformMatrix3fv(location, false, v);","mat4x4<f32>":"gl.uniformMatrix4fv(location, false, v);",i32:"gl.uniform1iv(location, v);","vec2<i32>":"gl.uniform2iv(location, v);","vec3<i32>":"gl.uniform3iv(location, v);","vec4<i32>":"gl.uniform4iv(location, v);",u32:"gl.uniform1iv(location, v);","vec2<u32>":"gl.uniform2iv(location, v);","vec3<u32>":"gl.uniform3iv(location, v);","vec4<u32>":"gl.uniform4iv(location, v);",bool:"gl.uniform1iv(location, v);","vec2<bool>":"gl.uniform2iv(location, v);","vec3<bool>":"gl.uniform3iv(location, v);","vec4<bool>":"gl.uniform4iv(location, v);"};function h0(r,t){const e=[`
|
||
|
|
var v = null;
|
||
|
|
var cv = null;
|
||
|
|
var cu = null;
|
||
|
|
var t = 0;
|
||
|
|
var gl = renderer.gl;
|
||
|
|
var name = null;
|
||
|
|
`];for(const s in r.uniforms){if(!t[s]){r.uniforms[s]instanceof wt?r.uniforms[s].ubo?e.push(`
|
||
|
|
renderer.shader.bindUniformBlock(uv.${s}, "${s}");
|
||
|
|
`):e.push(`
|
||
|
|
renderer.shader.updateUniformGroup(uv.${s});
|
||
|
|
`):r.uniforms[s]instanceof lo&&e.push(`
|
||
|
|
renderer.shader.bindBufferResource(uv.${s}, "${s}");
|
||
|
|
`);continue}const i=r.uniformStructures[s];let n=!1;for(let o=0;o<br.length;o++){const a=br[o];if(i.type===a.type&&a.test(i)){e.push(`name = "${s}";`,br[o].uniform),n=!0;break}}if(!n){const o=(i.size===1?l0:u0)[i.type].replace("location",`ud["${s}"].location`);e.push(`
|
||
|
|
cu = ud["${s}"];
|
||
|
|
cv = cu.value;
|
||
|
|
v = uv["${s}"];
|
||
|
|
${o};`)}}return new Function("ud","uv","renderer","syncData",e.join(`
|
||
|
|
`))}class kh{constructor(t){this._cache={},this._uniformGroupSyncHash={},this._renderer=t,this.gl=null,this._cache={}}contextChange(t){this.gl=t}updateUniformGroup(t,e,s){const i=this._renderer.shader._getProgramData(e);(!t.isStatic||t._dirtyId!==i.uniformDirtyGroups[t.uid])&&(i.uniformDirtyGroups[t.uid]=t._dirtyId,this._getUniformSyncFunction(t,e)(i.uniformData,t.uniforms,this._renderer,s))}_getUniformSyncFunction(t,e){var s;return((s=this._uniformGroupSyncHash[t._signature])==null?void 0:s[e._key])||this._createUniformSyncFunction(t,e)}_createUniformSyncFunction(t,e){const s=this._uniformGroupSyncHash[t._signature]||(this._uniformGroupSyncHash[t._signature]={}),i=this._getSignature(t,e._uniformData,"u");return this._cache[i]||(this._cache[i]=this._generateUniformsSync(t,e._uniformData)),s[e._key]=this._cache[i],s[e._key]}_generateUniformsSync(t,e){return h0(t,e)}_getSignature(t,e,s){const i=t.uniforms,n=[`${s}-`];for(const o in i)n.push(o),e[o]&&n.push(e[o].type);return n.join("-")}destroy(){this._renderer=null,this._cache=null}}kh.extension={type:[T.WebGLSystem],name:"uniformGroup"};function lG(r){return r=r.replaceAll("texture2D","texture").replaceAll("gl_FragColor","finalColor").replaceAll("varying","in"),r=`
|
||
|
|
out vec4 finalColor;
|
||
|
|
${r}
|
||
|
|
`,r}const uG={float:1,vec2:2,vec3:3,vec4:4,int:1,ivec2:2,ivec3:3,ivec4:4,uint:1,uvec2:2,uvec3:3,uvec4:4,bool:1,bvec2:2,bvec3:3,bvec4:4,mat2:4,mat3:9,mat4:16,sampler2D:1};function hG(r){return uG[r]}function c0(r){const t={};if(t.normal=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t.add=[r.ONE,r.ONE],t.multiply=[r.DST_COLOR,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA],t.screen=[r.ONE,r.ONE_MINUS_SRC_COLOR,r.ONE,r.ONE_MINUS_SRC_ALPHA],t.none=[0,0],t["normal-npm"]=[r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA],t["add-npm"]=[r.SRC_ALPHA,r.ONE,r.ONE,r.ONE],t["screen-npm"]=[r.SRC_ALPHA,r.ONE_MINUS_SRC_COLOR,r.ONE,r.ONE_MINUS_SRC_ALPHA],t.erase=[r.ZERO,r.ONE_MINUS_SRC_ALPHA],!(r instanceof X.get().getWebGLRenderingContext()))t.min=[r.ONE,r.ONE,r.ONE,r.ONE,r.MIN,r.MIN],t.max=[r.ONE,r.ONE,r.ONE,r.ONE,r.MAX,r.MAX];else{const e=r.getExtension("EXT_blend_minmax");e&&(t.min=[r.ONE,r.ONE,r.ONE,r.ONE,e.MIN_EXT,e.MIN_EXT],t.max=[r.ONE,r.ONE,r.ONE,r.ONE,e.MAX_EXT,e.MAX_EXT])}return t}const{BLEND:cG,OFFSET:dG,CULLING:pG,DEPTH_TEST:fG,WINDING:mG,DEPTH_MASK:d0}=Oa,p0=class Xc{constructor(t){this._invertFrontFace=!1,this._renderer=t,this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode="none",this._blendEq=!1,this.map=[],this.map[cG]=this.setBlend,this.map[dG]=this.setOffset,this.map[pG]=this.setCullFace,this.map[fG]=this.setDepthTest,this.map[mG]=this.setFrontFace,this.map[d0]=this.setDepthMask,this.checks=[],this.defaultState=Kt.for2d(),t.renderTarget.onRenderTargetChange.add(this)}onRenderTargetChange(t){this._invertFrontFace=this._renderer.renderTarget.isFrontFaceInverted(t,t.flipY),this._cullFace?this.setFrontFace(this._frontFace):this._frontFaceDirty=!0}contextChange(t){this.gl=t,this.blendModesMap=c0(t),this.resetState()}set(t){if(t||(t=this.defaultState),this.stateId!==t.data){let e=this.stateId^t.data,s=0;for(;e;)e&1&&this.map[s].call(this,!!(t.data&1<<s)),e>>=1,s++;this.stateId=t.data}for(let e=0;e<this.checks.length;e++)this.checks[e](this,t)}forceState(t){t||(t=this.defaultState);for(let e=0;e<this.map.length;e++)this.map[e].call(this,!!(t.data&1<<e));for(let e=0;e<this.checks.length;e++)this.checks[e](this,t);this.stateId=t.data}setBlend(t){this._updateCheck(Xc._checkBlendMode,t),this.gl[t?"enable":"disable"](this.gl.BLEND)}setOffset(t){this._updateCheck(Xc._checkPolygonOffset,t),this.gl[t?"enable":"disable"](this.gl.POLYGON_OFFSET_FILL)}setDepthTest(t){this.gl[t?"enable":"disable"](this.gl.DEPTH_TEST)}setDepthMask(t){this.gl.depthMask(t)}get depthMaskEnabled(){return!!(this.stateId&1<<d0)}setCullFace(t){this._cullFace=t,this.gl[t?"enable":"disable"](this.gl.CULL_FACE),this._cullFace&&this._frontFaceDirty&&this.setFrontFace(this._frontFace)}setFrontFace(t){this._frontFace=t,this._frontFaceDirty=!1;const e=this._invertFrontFace?!t:t;this._glFrontFace!==e&&(this._glFrontFace=e,this.gl.frontFace(this.gl[e?"CW":"CCW"]))}setBlendMode(t){if(this.blendModesMap[t]||(t="normal"),t===this.blendMode)return;this.blendMode=t;const e=this.blendModesMap[t],s=this.gl;e.length===2?s.blendFunc(e[0],e[1]):s.blendFuncSeparate(e[0],e[1],e[2],e[3]),e.length===6?(this._blendEq=!0,s.blendEquationSeparate(e[4],e[5])):this._blendEq&&(this._blendEq=!1,s.blendEquationSeparate(s.FUNC_ADD,s.FUNC_ADD))}setPolygonOffset(t,e){this.gl.polygonOffset(t,e)}resetState(){this._glFrontFace=!1,this._frontFace=!1,this._cullFace=!1,this._frontFaceDirty=!1,this._invertFrontFace=!1,this.gl.frontFace(this.gl.CCW),this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,!1),this.forceState(this.defaultState),this._blendEq=!0,this.blendMode="",this.setBlendMode("normal")}_updateCheck(t,e){const s=this.checks.indexOf(t);e&&s===-1?this.checks.push(t):!e&&s!==-1&&this.checks.splice(s,1)}static _checkBlendMode(t,e){t.setBlendMode(e.blendMode)}static _checkPolygonOffset(t,e){t.setPolygonOffset(1,e.polygonOffset)}destroy(){this.gl=null,this.checks.length=0,this._renderer=null}};p0.extension={type:[T.WebGLSystem],name:"state"};let f0=p0;class Lh{constructor(t){this.target=ao.TEXTURE_2D,this._layerInitMask=0,this.texture=t,this.width=-1,this.height=-1,this.type=at.UNSIG
|
||
|
|
@compute @workgroup_size(1) fn main() {}`});t.createComputePipeline({layout:"auto",compute:{module:e,entryPoint:"main",constants:{TEST_VALUE:1}}}),t.popErrorScope().then(s=>{this.supportsOverrideConstants=!s})}destroy(){}}Qh.extension={type:[T.WebGPUSystem],name:"limits"};class Jh{constructor(t){this._renderer=t,t.renderTarget.onRenderTargetChange.add(this)}contextChange(){this._activeGpuRenderTarget=null}onRenderTargetChange(t){const e=this._renderer.renderTarget.getGpuRenderTarget(t);this._activeRenderTarget=t,this._activeGpuRenderTarget=e,this.setStencilMode(e.stencilMode,e.stencilReference)}setStencilMode(t,e){var s;const i=(s=this._activeGpuRenderTarget)!=null?s:this._activeGpuRenderTarget=this._renderer.renderTarget.getGpuRenderTarget(this._activeRenderTarget);i.stencilMode=t,i.stencilReference=e;const n=this._renderer;n.pipeline.setStencilMode(t),n.encoder.setStencilReference(e)}destroy(){this._renderer.renderTarget.onRenderTargetChange.remove(this),this._renderer=null,this._activeRenderTarget=null,this._activeGpuRenderTarget=null}}Jh.extension={type:[T.WebGPUSystem],name:"stencil"};const si={i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},f16:{align:2,size:2},"vec2<i32>":{align:8,size:8},"vec2<u32>":{align:8,size:8},"vec2<f32>":{align:8,size:8},"vec2<f16>":{align:4,size:4},"vec3<i32>":{align:16,size:12},"vec3<u32>":{align:16,size:12},"vec3<f32>":{align:16,size:12},"vec3<f16>":{align:8,size:6},"vec4<i32>":{align:16,size:16},"vec4<u32>":{align:16,size:16},"vec4<f32>":{align:16,size:16},"vec4<f16>":{align:8,size:8},"mat2x2<f32>":{align:8,size:16},"mat2x2<f16>":{align:4,size:8},"mat3x2<f32>":{align:8,size:24},"mat3x2<f16>":{align:4,size:12},"mat4x2<f32>":{align:8,size:32},"mat4x2<f16>":{align:4,size:16},"mat2x3<f32>":{align:16,size:32},"mat2x3<f16>":{align:8,size:16},"mat3x3<f32>":{align:16,size:48},"mat3x3<f16>":{align:8,size:24},"mat4x3<f32>":{align:16,size:64},"mat4x3<f16>":{align:8,size:32},"mat2x4<f32>":{align:16,size:32},"mat2x4<f16>":{align:8,size:16},"mat3x4<f32>":{align:16,size:48},"mat3x4<f16>":{align:8,size:24},"mat4x4<f32>":{align:16,size:64},"mat4x4<f16>":{align:8,size:32}};function k0(r){const t=r.map(s=>({data:s,offset:0,size:0}));let e=0;for(let s=0;s<t.length;s++){const i=t[s];let n=si[i.data.type].size;const o=si[i.data.type].align;if(!si[i.data.type])throw new Error(`[Pixi.js] WebGPU UniformBuffer: Unknown type ${i.data.type}`);i.data.size>1&&(n=Math.max(n,o)*i.data.size),e=Math.ceil(e/o)*o,i.size=n,i.offset=e,e+=n}return e=Math.ceil(e/16)*16,{uboElements:t,size:e}}function L0(r,t){const{size:e,align:s}=si[r.data.type],i=(s-e)/4,n=r.data.type.indexOf("i32")>=0?"dataInt32":"data";return`
|
||
|
|
v = uv.${r.data.name};
|
||
|
|
${t!==0?`offset += ${t};`:""}
|
||
|
|
|
||
|
|
arrayOffset = offset;
|
||
|
|
|
||
|
|
t = 0;
|
||
|
|
|
||
|
|
for(var i=0; i < ${r.data.size*(e/4)}; i++)
|
||
|
|
{
|
||
|
|
for(var j = 0; j < ${e/4}; j++)
|
||
|
|
{
|
||
|
|
${n}[arrayOffset++] = v[t++];
|
||
|
|
}
|
||
|
|
${i!==0?`arrayOffset += ${i};`:""}
|
||
|
|
}
|
||
|
|
`}function N0(r){return Mh(r,Vy,L0)}class tc extends Ch{constructor(){super({createUboElements:k0,generateUboSync:N0})}}tc.extension={type:[T.WebGPUSystem],name:"ubo"};const Ye=128;class ec{constructor(t){this._bindGroupHash=Object.create(null),this._buffers=[],this._bindGroups=[],this._bufferResources=[],this._renderer=t,this._batchBuffer=new $0({minUniformOffsetAlignment:Ye});const e=256/Ye;for(let s=0;s<e;s++){let i=st.UNIFORM|st.COPY_DST;s===0&&(i|=st.COPY_SRC),this._buffers.push(new qt({data:this._batchBuffer.data,usage:i}))}}renderEnd(){this._uploadBindGroups(),this._resetBindGroups()}_resetBindGroups(){this._bindGroupHash=Object.create(null),this._batchBuffer.clear()}getUniformBindGroup(t,e){if(!e&&this._bindGroupHash[t.uid])return this._bindGroupHash[t.uid];this._renderer.ubo.ensureUniformGroup(t);const s=t.buffer.data,i=this._batchBuffer.addEmptyGroup(s.length);return this._renderer.ubo.syncUniformGroup(t,this._batchBuffer.data,i/4),this._bindGroupHash[t.uid]=this._getBindGroup(i/Ye),this._bindGroupHash[t.uid]}getUboResource(t){this._renderer.ubo.updateUniformGroup(t);const e=t.buffer.data,s=this._batchBuffer.addGroup(e);return this._getBufferResource(s/Ye)}getArrayBindGroup(t){const e=this._batchBuffer.addGroup(t);return this._getBindGroup(e/Ye)}getArrayBufferResource(t){const e=this._batchBuffer.addGroup(t)/Ye;return this._getBufferResource(e)}_getBufferResource(t){if(!this._bufferResources[t]){const e=this._buffers[t%2];this._bufferResources[t]=new lo({buffer:e,offset:(t/2|0)*256,size:Ye})}return this._bufferResources[t]}_getBindGroup(t){if(!this._bindGroups[t]){const e=new Ee({0:this._getBufferResource(t)});this._bindGroups[t]=e}return this._bindGroups[t]}_uploadBindGroups(){const t=this._renderer.buffer,e=this._buffers[0];e.update(this._batchBuffer.byteIndex),t.updateBuffer(e);const s=this._renderer.gpu.device.createCommandEncoder();for(let i=1;i<this._buffers.length;i++){const n=this._buffers[i];s.copyBufferToBuffer(t.getGPUBuffer(e),Ye,t.getGPUBuffer(n),0,this._batchBuffer.byteIndex)}this._renderer.gpu.device.queue.submit([s.finish()])}destroy(){var t;for(let e=0;e<this._bindGroups.length;e++)(t=this._bindGroups[e])==null||t.destroy();this._bindGroups=null,this._bindGroupHash=null;for(let e=0;e<this._buffers.length;e++)this._buffers[e].destroy();this._buffers=null;for(let e=0;e<this._bufferResources.length;e++)this._bufferResources[e].destroy();this._bufferResources=null,this._batchBuffer.destroy(),this._renderer=null}}ec.extension={type:[T.WebGPUPipes],name:"uniformBatch"};var kG=Object.defineProperty,LG=Object.defineProperties,NG=Object.getOwnPropertyDescriptors,j0=Object.getOwnPropertySymbols,jG=Object.prototype.hasOwnProperty,XG=Object.prototype.propertyIsEnumerable,X0=(r,t,e)=>t in r?kG(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,HG=(r,t)=>{for(var e in t||(t={}))jG.call(t,e)&&X0(r,e,t[e]);if(j0)for(var e of j0(t))XG.call(t,e)&&X0(r,e,t[e]);return r},zG=(r,t)=>LG(r,NG(t));const H0={"point-list":0,"line-list":1,"line-strip":2,"triangle-list":3,"triangle-strip":4},WG=new as({}),VG={"depth24plus-stencil8":{depth:!0,stencil:!0,index:1},depth24plus:{depth:!0,stencil:!1,index:2},depth32float:{depth:!0,stencil:!1,index:3},"depth32float-stencil8":{depth:!0,stencil:!0,index:4},depth16unorm:{depth:!0,stencil:!1,index:5},stencil8:{depth:!1,stencil:!0,index:6}},z0={depth:!1,stencil:!1,index:0};function rc(r,t){for(const[e,s]of Object.entries(t)){const i=new RegExp(`override\\s+${e}\\s*:\\s*(\\w+)\\s*(?:=[^;]*)?;`);r=r.replace(i,(n,o)=>{let a;return o==="u32"?a=`${Math.trunc(s)}u`:o==="i32"?a=`${Math.trunc(s)}`:a=Number.isInteger(s)?`${s}.0`:`${s}`,`const ${e}: ${o} = ${a};`})}return r}function W0(r,t,e,s,i,n){return r*35184372088832+t*536870912+n*16384+(e<<8)+(s<<3)+i}const V0=Object.create(null);let YG=0;function Y0(r){let t=V0[r];return t===void 0&&(t=V0[r]=YG++),t}function KG(r,t,e,s,i,n,o,a){return a<<20|n<<16|i<<13|e<<9|r<<6|o<<5|s<<1|t}function qG(r,t,e,s,i,n,o){return o<<11|n<<10|i<<9|s<<8|e<<5|t<<1|r}class sc{constructor(t){this._moduleCache=Object.create(null),this._bufferLayou
|
||
|
|
var<private> pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
|
||
|
|
vec2<f32>(-1.0, -1.0), vec2<f32>(-1.0, 3.0), vec2<f32>(3.0, -1.0));
|
||
|
|
|
||
|
|
struct VertexOutput {
|
||
|
|
@builtin(position) position : vec4<f32>,
|
||
|
|
@location(0) texCoord : vec2<f32>,
|
||
|
|
};
|
||
|
|
|
||
|
|
@vertex
|
||
|
|
fn vertexMain(@builtin(vertex_index) vertexIndex : u32) -> VertexOutput {
|
||
|
|
var output : VertexOutput;
|
||
|
|
output.texCoord = pos[vertexIndex] * vec2<f32>(0.5, -0.5) + vec2<f32>(0.5);
|
||
|
|
output.position = vec4<f32>(pos[vertexIndex], 0.0, 1.0);
|
||
|
|
return output;
|
||
|
|
}
|
||
|
|
|
||
|
|
@group(0) @binding(0) var imgSampler : sampler;
|
||
|
|
@group(0) @binding(1) var img : texture_2d<f32>;
|
||
|
|
|
||
|
|
@fragment
|
||
|
|
fn fragmentMain(@location(0) texCoord : vec2<f32>) -> @location(0) vec4<f32> {
|
||
|
|
return textureSample(img, imgSampler, texCoord);
|
||
|
|
}
|
||
|
|
`})),e=this.device.createRenderPipeline({layout:"auto",vertex:{module:this.mipmapShaderModule,entryPoint:"vertexMain"},fragment:{module:this.mipmapShaderModule,entryPoint:"fragmentMain",targets:[{format:t}]}}),this.pipelines[t]=e),e}generateMipmap(t){const e=this._getMipmapPipeline(t.format);if(t.dimension==="3d"||t.dimension==="1d")throw new Error("Generating mipmaps for non-2d textures is currently unsupported!");let s=t;const i=t.depthOrArrayLayers||1,n=t.usage&GPUTextureUsage.RENDER_ATTACHMENT;if(!n){const l={size:{width:Math.ceil(t.width/2),height:Math.ceil(t.height/2),depthOrArrayLayers:i},format:t.format,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_SRC|GPUTextureUsage.RENDER_ATTACHMENT,mipLevelCount:t.mipLevelCount-1};s=this.device.createTexture(l)}const o=this.device.createCommandEncoder({}),a=e.getBindGroupLayout(0);for(let l=0;l<i;++l){let u=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:"2d",baseArrayLayer:l,arrayLayerCount:1}),h=n?1:0;for(let c=1;c<t.mipLevelCount;++c){const d=s.createView({baseMipLevel:h++,mipLevelCount:1,dimension:"2d",baseArrayLayer:l,arrayLayerCount:1}),p=o.beginRenderPass({colorAttachments:[{view:d,storeOp:"store",loadOp:"clear",clearValue:{r:0,g:0,b:0,a:0}}]}),f=this.device.createBindGroup({layout:a,entries:[{binding:0,resource:this.sampler},{binding:1,resource:u}]});p.setPipeline(e),p.setBindGroup(0,f),p.draw(3,1,0,0),p.end(),u=d}}if(!n){const l={width:Math.ceil(t.width/2),height:Math.ceil(t.height/2),depthOrArrayLayers:i};for(let u=1;u<t.mipLevelCount;++u)o.copyTextureToTexture({texture:s,mipLevel:u-1},{texture:t,mipLevel:u},l),l.width=Math.ceil(l.width/2),l.height=Math.ceil(l.height/2)}return this.device.queue.submit([o.finish()]),n||s.destroy(),t}}var iI=Object.defineProperty,nI=Object.defineProperties,oI=Object.getOwnPropertyDescriptors,n1=Object.getOwnPropertySymbols,aI=Object.prototype.hasOwnProperty,lI=Object.prototype.propertyIsEnumerable,o1=(r,t,e)=>t in r?iI(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,fo=(r,t)=>{for(var e in t||(t={}))aI.call(t,e)&&o1(r,e,t[e]);if(n1)for(var e of n1(t))lI.call(t,e)&&o1(r,e,t[e]);return r},uI=(r,t)=>nI(r,oI(t));class uc{constructor(t){this.textureView=null,this.textureViews=Object.create(null),this.gpuTexture=t}destroy(){this.gpuTexture.destroy(),this.textureView=null,this.textureViews=null,this.gpuTexture=null}}function a1(r){return`${r.format||""}.${r.dimension||""}.${r.aspect||""}.${r.baseMipLevel||0}.${r.mipLevelCount||""}.${r.baseArrayLayer||0}.${r.arrayLayerCount||""}`}const hc=class wS{constructor(t){this._gpuSamplers=Object.create(null),this._bindGroupHash=Object.create(null),this._renderer=t,t.gc.addCollection(this,"_bindGroupHash","hash"),this._managedTextures=new kt({renderer:t,type:"resource",onUnload:this.onSourceUnload.bind(this),name:"gpuTextureSource"});const e=fo({image:lc,buffer:J0,video:s1,compressed:t1},wS.uploadExtensions);this._uploads=uI(fo({},e),{cube:r1(e)})}get managedTextures(){return Object.values(this._managedTextures.items)}contextChange(t){this._gpu=t,this._managedTextures.removeAll(),this._gpuSamplers=Object.create(null),this._mipmapGenerator=null}initSource(t){var e;return((e=t._gpuData[this._renderer.uid])==null?void 0:e.gpuTexture)||this._initSource(t)}_initSource(t){if(t.autoGenerateMipmaps){const l=Math.max(t.pixelWidth,t.pixelHeight);t.mipLevelCount=Math.floor(Math.log2(l))+1}let e;t.sampleCount>1?(e=GPUTextureUsage.RENDER_ATTACHMENT,t.transient&&this._renderer.device.extensions.transientAttachment&&(e|=GPUTextureUsage.TRANSIENT_ATTACHMENT)):(e=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST,t.uploadMethodId!=="compressed"&&(e|=GPUTextureUsage.RENDER_ATTACHMENT,e|=GPUTextureUsage.COPY_SRC));const s=ac[t.format]||{blockBytes:4,blockWidth:1,blockHeight:1},i=Math.ceil(t.pixelWidth/s.blockWidth)*s.blockWidth,n=Math.ceil(t.pixelHeight/s.blockHeight)*s.blockHeight,o={label:t.label,size:{width:i,height:n,depthOrArrayLayers:t.arrayLayerCount},format:t.format,sampleCount:t.sampleCount,mipLevelCount:t.mipLevelCount,dimension:t.dimension,usage:e}
|
||
|
|
|
||
|
|
var index = 0;
|
||
|
|
|
||
|
|
for (let i = 0; i < ps.length; ++i)
|
||
|
|
{
|
||
|
|
const p = ps[i];
|
||
|
|
|
||
|
|
`);let s=0;for(const n in r){const o=r[n];if(t!==o.dynamic)continue;e.push(`offset = index + ${s}`),e.push(o.code);const a=Be(o.format);s+=a.stride/4}e.push(`
|
||
|
|
index += stride * 4;
|
||
|
|
}
|
||
|
|
`),e.unshift(`
|
||
|
|
var stride = ${s};
|
||
|
|
`);const i=e.join(`
|
||
|
|
`);return new Function("ps","f32v","u32v",i)}class hT{constructor(t){this._size=0,this._generateParticleUpdateCache={};var e;const s=this._size=(e=t.size)!=null?e:1e3,i=t.properties;let n=0,o=0;for(const c in i){const d=i[c],p=Be(d.format);d.dynamic?o+=p.stride:n+=p.stride}this._dynamicStride=o/4,this._staticStride=n/4,this.staticAttributeBuffer=new pr(s*4*n),this.dynamicAttributeBuffer=new pr(s*4*o),this.indexBuffer=Tc(s);const a=new hr;let l=0,u=0;this._staticBuffer=new qt({data:new Float32Array(1),label:"static-particle-buffer",shrinkToFit:!1,usage:st.VERTEX|st.COPY_DST}),this._dynamicBuffer=new qt({data:new Float32Array(1),label:"dynamic-particle-buffer",shrinkToFit:!1,usage:st.VERTEX|st.COPY_DST});for(const c in i){const d=i[c],p=Be(d.format);d.dynamic?(a.addAttribute(d.attributeName,{buffer:this._dynamicBuffer,stride:this._dynamicStride*4,offset:l*4,format:d.format}),l+=p.size):(a.addAttribute(d.attributeName,{buffer:this._staticBuffer,stride:this._staticStride*4,offset:u*4,format:d.format}),u+=p.size)}a.addIndex(this.indexBuffer);const h=this.getParticleUpdate(i);this._dynamicUpload=h.dynamicUpdate,this._staticUpload=h.staticUpdate,this.geometry=a}getParticleUpdate(t){const e=UF(t);return this._generateParticleUpdateCache[e]?this._generateParticleUpdateCache[e]:(this._generateParticleUpdateCache[e]=this.generateParticleUpdate(t),this._generateParticleUpdateCache[e])}generateParticleUpdate(t){return lT(t)}update(t,e){t.length>this._size&&(e=!0,this._size=Math.max(t.length,this._size*1.5|0),this.staticAttributeBuffer=new pr(this._size*this._staticStride*4*4),this.dynamicAttributeBuffer=new pr(this._size*this._dynamicStride*4*4),this.indexBuffer=Tc(this._size),this.geometry.indexBuffer.setDataWithSize(this.indexBuffer,this.indexBuffer.byteLength,!0));const s=this.dynamicAttributeBuffer;if(this._dynamicUpload(t,s.float32View,s.uint32View),this._dynamicBuffer.setDataWithSize(this.dynamicAttributeBuffer.float32View,t.length*this._dynamicStride*4,!0),e){const i=this.staticAttributeBuffer;this._staticUpload(t,i.float32View,i.uint32View),this._staticBuffer.setDataWithSize(i.float32View,t.length*this._staticStride*4,!0)}}destroy(){this._staticBuffer.destroy(),this._dynamicBuffer.destroy(),this.geometry.destroy()}}function UF(r){const t=[];for(const e in r){const s=r[e];t.push(e,s.code,s.dynamic?"d":"s")}return t.join("_")}var cT=`varying vec2 vUV;
|
||
|
|
varying vec4 vColor;
|
||
|
|
|
||
|
|
uniform sampler2D uTexture;
|
||
|
|
|
||
|
|
void main(void){
|
||
|
|
vec4 color = texture2D(uTexture, vUV) * vColor;
|
||
|
|
gl_FragColor = color;
|
||
|
|
}`,dT=`attribute vec2 aVertex;
|
||
|
|
attribute vec2 aUV;
|
||
|
|
attribute vec4 aColor;
|
||
|
|
|
||
|
|
attribute vec2 aPosition;
|
||
|
|
attribute float aRotation;
|
||
|
|
|
||
|
|
uniform mat3 uTranslationMatrix;
|
||
|
|
uniform float uRound;
|
||
|
|
uniform vec2 uResolution;
|
||
|
|
uniform vec4 uColor;
|
||
|
|
|
||
|
|
varying vec2 vUV;
|
||
|
|
varying vec4 vColor;
|
||
|
|
|
||
|
|
vec2 roundPixels(vec2 position, vec2 targetSize)
|
||
|
|
{
|
||
|
|
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
||
|
|
}
|
||
|
|
|
||
|
|
void main(void){
|
||
|
|
float cosRotation = cos(aRotation);
|
||
|
|
float sinRotation = sin(aRotation);
|
||
|
|
float x = aVertex.x * cosRotation - aVertex.y * sinRotation;
|
||
|
|
float y = aVertex.x * sinRotation + aVertex.y * cosRotation;
|
||
|
|
|
||
|
|
vec2 v = vec2(x, y);
|
||
|
|
v = v + aPosition;
|
||
|
|
|
||
|
|
gl_Position = vec4((uTranslationMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);
|
||
|
|
|
||
|
|
if(uRound == 1.0)
|
||
|
|
{
|
||
|
|
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
||
|
|
}
|
||
|
|
|
||
|
|
vUV = aUV;
|
||
|
|
vColor = vec4(aColor.rgb * aColor.a, aColor.a) * uColor;
|
||
|
|
}
|
||
|
|
`,Sc=`
|
||
|
|
struct ParticleUniforms {
|
||
|
|
uTranslationMatrix:mat3x3<f32>,
|
||
|
|
uColor:vec4<f32>,
|
||
|
|
uRound:f32,
|
||
|
|
uResolution:vec2<f32>,
|
||
|
|
};
|
||
|
|
|
||
|
|
fn roundPixels(position: vec2<f32>, targetSize: vec2<f32>) -> vec2<f32>
|
||
|
|
{
|
||
|
|
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
||
|
|
}
|
||
|
|
|
||
|
|
@group(0) @binding(0) var<uniform> uniforms: ParticleUniforms;
|
||
|
|
|
||
|
|
@group(1) @binding(0) var uTexture: texture_2d<f32>;
|
||
|
|
@group(1) @binding(1) var uSampler : sampler;
|
||
|
|
|
||
|
|
struct VSOutput {
|
||
|
|
@builtin(position) position: vec4<f32>,
|
||
|
|
@location(0) uv : vec2<f32>,
|
||
|
|
@location(1) color : vec4<f32>,
|
||
|
|
};
|
||
|
|
@vertex
|
||
|
|
fn mainVertex(
|
||
|
|
@location(0) aVertex: vec2<f32>,
|
||
|
|
@location(1) aPosition: vec2<f32>,
|
||
|
|
@location(2) aUV: vec2<f32>,
|
||
|
|
@location(3) aColor: vec4<f32>,
|
||
|
|
@location(4) aRotation: f32,
|
||
|
|
) -> VSOutput {
|
||
|
|
|
||
|
|
let v = vec2(
|
||
|
|
aVertex.x * cos(aRotation) - aVertex.y * sin(aRotation),
|
||
|
|
aVertex.x * sin(aRotation) + aVertex.y * cos(aRotation)
|
||
|
|
) + aPosition;
|
||
|
|
|
||
|
|
var position = vec4((uniforms.uTranslationMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);
|
||
|
|
|
||
|
|
if(uniforms.uRound == 1.0) {
|
||
|
|
position = vec4(roundPixels(position.xy, uniforms.uResolution), position.zw);
|
||
|
|
}
|
||
|
|
|
||
|
|
let vColor = vec4(aColor.rgb * aColor.a, aColor.a) * uniforms.uColor;
|
||
|
|
|
||
|
|
return VSOutput(
|
||
|
|
position,
|
||
|
|
aUV,
|
||
|
|
vColor,
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
@fragment
|
||
|
|
fn mainFragment(
|
||
|
|
@location(0) uv: vec2<f32>,
|
||
|
|
@location(1) color: vec4<f32>,
|
||
|
|
@builtin(position) position: vec4<f32>,
|
||
|
|
) -> @location(0) vec4<f32> {
|
||
|
|
|
||
|
|
var sample = textureSample(uTexture, uSampler, uv) * color;
|
||
|
|
|
||
|
|
return sample;
|
||
|
|
}`;class pT extends ne{constructor(){const t=Yt.from({vertex:dT,fragment:cT}),e=zt.from({fragment:{source:Sc,entryPoint:"mainFragment"},vertex:{source:Sc,entryPoint:"mainVertex"}});super({glProgram:t,gpuProgram:e,resources:{uTexture:B.WHITE.source,uSampler:new ae({}),uniforms:{uTranslationMatrix:{value:new D,type:"mat3x3<f32>"},uColor:{value:new tt(16777215),type:"vec4<f32>"},uRound:{value:1,type:"f32"},uResolution:{value:[0,0],type:"vec2<f32>"}}}})}}class ni{constructor(t,e){this.state=Kt.for2d(),this.localUniforms=new wt({uTranslationMatrix:{value:new D,type:"mat3x3<f32>"},uColor:{value:new Float32Array(4),type:"vec4<f32>"},uRound:{value:1,type:"f32"},uResolution:{value:[0,0],type:"vec2<f32>"}}),this.renderer=t,this.adaptor=e,this.defaultShader=new pT,this.state=Kt.for2d(),this._managedContainers=new kt({renderer:t,type:"renderable",name:"particleContainer"})}validateRenderable(t){return!1}addRenderable(t,e){this.renderer.renderPipes.batch.break(e),e.add(t)}getBuffers(t){return t._gpuData[this.renderer.uid]||this._initBuffer(t)}_initBuffer(t){return t._gpuData[this.renderer.uid]=new hT({size:t.particleChildren.length,properties:t._properties}),this._managedContainers.add(t),t._gpuData[this.renderer.uid]}updateRenderable(t){}execute(t){const e=t.particleChildren;if(e.length===0)return;const s=this.renderer,i=this.getBuffers(t);t.texture||(t.texture=e[0].texture);const n=this.state;i.update(e,t._childrenDirty),t._childrenDirty=!1,n.blendMode=Dr(t.groupBlendMode,t.texture._source);const o=this.localUniforms.uniforms,a=o.uTranslationMatrix;t.worldTransform.copyTo(a);const l=s.globalUniforms.globalUniformData;a.tx-=l.offset.x,a.ty-=l.offset.y,a.prepend(l.projectionMatrix),o.uResolution=l.resolution,o.uRound=s._roundPixels|t._roundPixels;const u=t.groupColorAlpha,h=l.worldColor,c=(u>>>24)*(h>>>24)/255|0,d=be(u&16777215,h&16777215);Zr((c<<24|d)>>>0,o.uColor,0),this.adaptor.execute(this,t)}destroy(){this._managedContainers.destroy(),this.renderer=null,this.defaultShader&&(this.defaultShader.destroy(),this.defaultShader=null)}}ni.extension={type:[T.CanvasPipes],name:"particle"};class wc extends ni{constructor(t){super(t,new aT)}}wc.extension={type:[T.CanvasPipes],name:"particle"};class fT{execute(t,e){const s=t.state,i=t.renderer,n=e.shader||t.defaultShader;n.resources.uTexture=e.texture._source,n.resources.uniforms=t.localUniforms;const o=i.gl,a=t.getBuffers(e);i.shader.bind(n),i.state.set(s),i.geometry.bind(a.geometry,n.glProgram);const l=a.geometry.indexBuffer.data.BYTES_PER_ELEMENT===2?o.UNSIGNED_SHORT:o.UNSIGNED_INT;o.drawElements(o.TRIANGLES,e.particleChildren.length*6,l,0)}}class Ec extends ni{constructor(t){super(t,new fT)}}Ec.extension={type:[T.WebGLPipes],name:"particle"};class mT{execute(t,e){const s=t.renderer,i=e.shader||t.defaultShader;i.groups[0]=s.renderPipes.uniformBatch.getUniformBindGroup(t.localUniforms,!0),i.groups[1]=s.texture.getTextureBindGroup(e.texture);const n=t.state,o=t.getBuffers(e);s.encoder.draw({geometry:o.geometry,shader:e.shader||t.defaultShader,state:n,size:e.particleChildren.length*6})}}class Ac extends ni{constructor(t){super(t,new mT)}}Ac.extension={type:[T.WebGPUPipes],name:"particle"};var kF=Object.defineProperty,gT=Object.getOwnPropertySymbols,LF=Object.prototype.hasOwnProperty,NF=Object.prototype.propertyIsEnumerable,_T=(r,t,e)=>t in r?kF(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,xT=(r,t)=>{for(var e in t||(t={}))LF.call(t,e)&&_T(r,e,t[e]);if(gT)for(var e of gT(t))NF.call(t,e)&&_T(r,e,t[e]);return r};const vT=class Hc{constructor(t){if(t instanceof B)this.texture=t,Ei(this,Hc.defaultOptions,{});else{const e=xT(xT({},Hc.defaultOptions),t);Ei(this,e,{})}}get alpha(){return this._alpha}set alpha(t){this._alpha=Math.min(Math.max(t,0),1),this._updateColor()}get tint(){return ye(this._tint)}set tint(t){this._tint=tt.shared.setValue(t!=null?t:16777215).toBgrNumber(),this._updateColor()}_updateColor(){this.color=this._tint+((this._alpha*255|0)<<24)}};vT.defaultOptions={anchorX:0,anchorY:0,x:0,y:0,scaleX:1,scaleY:1,rotation:0,tint:16777215,alpha:1};let jF=vT;const Pc={ver
|
||
|
|
const texture = p.texture;
|
||
|
|
const sx = p.scaleX;
|
||
|
|
const sy = p.scaleY;
|
||
|
|
const ax = p.anchorX;
|
||
|
|
const ay = p.anchorY;
|
||
|
|
const trim = texture.trim;
|
||
|
|
const orig = texture.orig;
|
||
|
|
|
||
|
|
if (trim)
|
||
|
|
{
|
||
|
|
w1 = trim.x - (ax * orig.width);
|
||
|
|
w0 = w1 + trim.width;
|
||
|
|
|
||
|
|
h1 = trim.y - (ay * orig.height);
|
||
|
|
h0 = h1 + trim.height;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
w1 = -ax * (orig.width);
|
||
|
|
w0 = w1 + orig.width;
|
||
|
|
|
||
|
|
h1 = -ay * (orig.height);
|
||
|
|
h0 = h1 + orig.height;
|
||
|
|
}
|
||
|
|
|
||
|
|
f32v[offset] = w1 * sx;
|
||
|
|
f32v[offset + 1] = h1 * sy;
|
||
|
|
|
||
|
|
f32v[offset + stride] = w0 * sx;
|
||
|
|
f32v[offset + stride + 1] = h1 * sy;
|
||
|
|
|
||
|
|
f32v[offset + (stride * 2)] = w0 * sx;
|
||
|
|
f32v[offset + (stride * 2) + 1] = h0 * sy;
|
||
|
|
|
||
|
|
f32v[offset + (stride * 3)] = w1 * sx;
|
||
|
|
f32v[offset + (stride * 3) + 1] = h0 * sy;
|
||
|
|
`,dynamic:!1},position:{attributeName:"aPosition",format:"float32x2",code:`
|
||
|
|
var x = p.x;
|
||
|
|
var y = p.y;
|
||
|
|
|
||
|
|
f32v[offset] = x;
|
||
|
|
f32v[offset + 1] = y;
|
||
|
|
|
||
|
|
f32v[offset + stride] = x;
|
||
|
|
f32v[offset + stride + 1] = y;
|
||
|
|
|
||
|
|
f32v[offset + (stride * 2)] = x;
|
||
|
|
f32v[offset + (stride * 2) + 1] = y;
|
||
|
|
|
||
|
|
f32v[offset + (stride * 3)] = x;
|
||
|
|
f32v[offset + (stride * 3) + 1] = y;
|
||
|
|
`,dynamic:!0},rotation:{attributeName:"aRotation",format:"float32",code:`
|
||
|
|
var rotation = p.rotation;
|
||
|
|
|
||
|
|
f32v[offset] = rotation;
|
||
|
|
f32v[offset + stride] = rotation;
|
||
|
|
f32v[offset + (stride * 2)] = rotation;
|
||
|
|
f32v[offset + (stride * 3)] = rotation;
|
||
|
|
`,dynamic:!1},uvs:{attributeName:"aUV",format:"float32x2",code:`
|
||
|
|
var uvs = p.texture.uvs;
|
||
|
|
|
||
|
|
f32v[offset] = uvs.x0;
|
||
|
|
f32v[offset + 1] = uvs.y0;
|
||
|
|
|
||
|
|
f32v[offset + stride] = uvs.x1;
|
||
|
|
f32v[offset + stride + 1] = uvs.y1;
|
||
|
|
|
||
|
|
f32v[offset + (stride * 2)] = uvs.x2;
|
||
|
|
f32v[offset + (stride * 2) + 1] = uvs.y2;
|
||
|
|
|
||
|
|
f32v[offset + (stride * 3)] = uvs.x3;
|
||
|
|
f32v[offset + (stride * 3) + 1] = uvs.y3;
|
||
|
|
`,dynamic:!1},color:{attributeName:"aColor",format:"unorm8x4",code:`
|
||
|
|
const c = p.color;
|
||
|
|
|
||
|
|
u32v[offset] = c;
|
||
|
|
u32v[offset + stride] = c;
|
||
|
|
u32v[offset + (stride * 2)] = c;
|
||
|
|
u32v[offset + (stride * 3)] = c;
|
||
|
|
`,dynamic:!1}};L.add(Ec),L.add(Ac),L.add(wc);var XF=Object.defineProperty,HF=Object.defineProperties,zF=Object.getOwnPropertyDescriptors,wo=Object.getOwnPropertySymbols,bT=Object.prototype.hasOwnProperty,yT=Object.prototype.propertyIsEnumerable,TT=(r,t,e)=>t in r?XF(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,is=(r,t)=>{for(var e in t||(t={}))bT.call(t,e)&&TT(r,e,t[e]);if(wo)for(var e of wo(t))yT.call(t,e)&&TT(r,e,t[e]);return r},ST=(r,t)=>HF(r,zF(t)),WF=(r,t)=>{var e={};for(var s in r)bT.call(r,s)&&t.indexOf(s)<0&&(e[s]=r[s]);if(r!=null&&wo)for(var s of wo(r))t.indexOf(s)<0&&yT.call(r,s)&&(e[s]=r[s]);return e};const VF=new Ct(0,0,0,0),wT=class zc extends Se{constructor(t={}){t=ST(is(is({},zc.defaultOptions),t),{dynamicProperties:is(is({},zc.defaultOptions.dynamicProperties),t==null?void 0:t.dynamicProperties)});const e=t,{dynamicProperties:s,shader:i,roundPixels:n,texture:o,particles:a}=e,l=WF(e,["dynamicProperties","shader","roundPixels","texture","particles"]);super(is({label:"ParticleContainer"},l)),this.renderPipeId="particle",this.batched=!1,this._childrenDirty=!1,this.texture=o||null,this.shader=i,this._properties={};for(const u in Pc){const h=Pc[u],c=s[u];this._properties[u]=ST(is({},h),{dynamic:c})}this.allowChildren=!0,this.roundPixels=n!=null?n:!1,this.particleChildren=a!=null?a:[]}addParticle(...t){for(let e=0;e<t.length;e++)this.particleChildren.push(t[e]);return this.onViewUpdate(),t[0]}removeParticle(...t){let e=!1;for(let s=0;s<t.length;s++){const i=this.particleChildren.indexOf(t[s]);i>-1&&(this.particleChildren.splice(i,1),e=!0)}return e&&this.onViewUpdate(),t[0]}update(){this._childrenDirty=!0}onViewUpdate(){this._childrenDirty=!0,super.onViewUpdate()}get bounds(){return VF}updateBounds(){}destroy(t=!1){var e,s,i;if(super.destroy(t),typeof t=="boolean"?t:t==null?void 0:t.texture){const n=typeof t=="boolean"?t:t==null?void 0:t.textureSource,o=(s=this.texture)!=null?s:(e=this.particleChildren[0])==null?void 0:e.texture;o&&o.destroy(n)}this.texture=null,(i=this.shader)==null||i.destroy()}removeParticles(t,e){t!=null||(t=0),e!=null||(e=this.particleChildren.length);const s=this.particleChildren.splice(t,e-t);return this.onViewUpdate(),s}removeParticleAt(t){const e=this.particleChildren.splice(t,1);return this.onViewUpdate(),e[0]}addParticleAt(t,e){return this.particleChildren.splice(e,0,t),this.onViewUpdate(),t}addChild(...t){throw new Error("ParticleContainer.addChild() is not available. Please use ParticleContainer.addParticle()")}removeChild(...t){throw new Error("ParticleContainer.removeChild() is not available. Please use ParticleContainer.removeParticle()")}removeChildren(t,e){throw new Error("ParticleContainer.removeChildren() is not available. Please use ParticleContainer.removeParticles()")}removeChildAt(t){throw new Error("ParticleContainer.removeChildAt() is not available. Please use ParticleContainer.removeParticleAt()")}getChildAt(t){throw new Error("ParticleContainer.getChildAt() is not available. Please use ParticleContainer.getParticleAt()")}setChildIndex(t,e){throw new Error("ParticleContainer.setChildIndex() is not available. Please use ParticleContainer.setParticleIndex()")}getChildIndex(t){throw new Error("ParticleContainer.getChildIndex() is not available. Please use ParticleContainer.getParticleIndex()")}addChildAt(t,e){throw new Error("ParticleContainer.addChildAt() is not available. Please use ParticleContainer.addParticleAt()")}swapChildren(t,e){throw new Error("ParticleContainer.swapChildren() is not available. Please use ParticleContainer.swapParticles()")}reparentChild(...t){throw new Error("ParticleContainer.reparentChild() is not available with the particle container")}reparentChildAt(t,e){throw new Error("ParticleContainer.reparentChildAt() is not available with the particle container")}};wT.defaultOptions={dynamicProperties:{vertex:!1,position:!0,rotation:!1,uvs:!1,color:!1},roundPixels:!1};let YF=wT;const Cc=[[0,0],[0,0],[0,0]],Rc=[[0,0],[0,0],[0,0]],Mc=[[0,0],[0,0],[0,0]],Oc=[[0,0],[0,0],[0,0]];function Eo(r,t,e,s,i,n,o){r[0][0]=t,r[0][1]=e,r[1
|
||
|
|
`||r===`\r
|
||
|
|
`}const pB=/^\s*$/;function fB(r,t){const e=[];let s=t.lines[0],i="",n=[],o=0;return r.forEach(a=>{const l=pB.test(a),u=Bc(a),h=i.length===0&&l;l&&!u&&h&&(!s||!s.startsWith(a))||(u||(i+=a),n.push(a),i.length>=s.length&&(e.push({line:i,chars:n}),n=[],i="",o++,s=t.lines[o]))}),e}function jT(r){var t,e;const{text:s,style:i,chars:n}=r,o=i,a=vt.measureText(s,o);if(a.runsByLine&&a.runsByLine.length>0)return mB(a,o,n,s);const l=vt.graphemeSegmenter(s),u=fB(l,a),h=o.align,c=a.lineWidths.reduce((F,R)=>Math.max(F,R),0),d=(t=o._fill)==null?void 0:t.fill,p=(e=o._stroke)==null?void 0:e.fill,f=d instanceof Lt,m=p instanceof Lt,g=f||m,_=f&&d.textureSpace==="local"||m&&p.textureSpace==="local",x=a.width,v=a.height,b=o.clone();b.align="left";let S=0,y=0;if(b.trim){const{frame:F,canvasAndContext:R}=me.getCanvasAndContext({text:s,style:o,resolution:1});me.returnCanvasAndContext(R),S=-F.x,y=-F.y,b.trim=!1}const w=[],E=[],A=[];let P=0,C=0;const O=_?{width:x,height:v}:null;return u.forEach((F,R)=>{const G=new dt({label:`line-${R}`});G.y=P+y,E.push(G);const M=a.lineWidths[R];let I=NT(h,M,c),U=new dt({label:"word"});U.x=I+S;const j=vt._context;j.font=b._fontString,vt.experimentalLetterSpacingSupported&&(j.letterSpacing="0px",j.textLetterSpacing="0px");let Q=F.line,K=j.measureText(Q).width;if(F.chars.forEach(N=>{if(Bc(N))return;Q=Q.slice(N.length);const k=Q.length>0?j.measureText(Q).width:0,$=K-k;if(K=k,$!==0)if(N===" ")U.children.length>0&&(A.push(U),G.addChild(U)),I+=$+o.letterSpacing,U=new dt({label:"word"}),U.x=I+S;else{let z=b;g&&(z=b.clone(),z._gradientOffset={x:-I,y:-P},O&&(z._gradientBounds=O));let et;C<n.length?(et=n[C++],et.text=N,et.style=z,et.setFromMatrix(D.IDENTITY),et.x=I-U.x+S):et=new Js({text:N,style:z,x:I-U.x+S}),w.push(et),U.addChild(et),I+=$+o.letterSpacing}}),U.children.length>0&&(A.push(U),G.addChild(U)),h==="justify"&&o.wordWrap&&R<u.length-1){const N=G.children,k=N.length-1;if(k>0){const $=(c-M)/k;for(let z=1;z<N.length;z++)N[z].x+=z*$}}P+=a.lineHeight}),{chars:w,lines:E,words:A}}function mB(r,t,e,s){const{runsByLine:i}=r,n=t.align,o=r.lineWidths.reduce((f,m)=>Math.max(f,m),0);let a=0,l=0;if(t.trim){const{frame:f,canvasAndContext:m}=me.getCanvasAndContext({text:s,style:t,resolution:1});me.returnCanvasAndContext(m),a=-f.x,l=-f.y}const u=[],h=[],c=[];let d=0,p=0;return i.forEach((f,m)=>{var g,_,x,v;const b=new dt({label:`line-${m}`});b.y=d+l,h.push(b);const S=r.lineWidths[m];let y=NT(n,S,o),w=new dt({label:"word"});w.x=y+a;for(const A of f){const P=A.style,C=(g=P._fill)==null?void 0:g.fill,O=(_=P._stroke)==null?void 0:_.fill,F=C instanceof Lt,R=O instanceof Lt,G=F||R,M=F&&C.textureSpace==="local"||R&&O.textureSpace==="local",I=vt.graphemeSegmenter(A.text),U=P.clone();U.align="left",U.wordWrap=!1,U.trim&&(U.trim=!1),U.tagStyles=void 0,U._lineHeight=0;const j=vt._context;j.font=U._fontString,vt.experimentalLetterSpacingSupported&&(j.letterSpacing="0px",j.textLetterSpacing="0px");let Q=A.text,K=j.measureText(Q).width;const N=y,k=K,$=vt.measureFont(U._fontString),z=P.lineHeight||$.fontSize,et=M?{width:k,height:z}:null;for(const mt of I){Q=Q.slice(mt.length);const J=Q.length>0?j.measureText(Q).width:0,ot=K-J;if(K=J,!Bc(mt)&&ot!==0)if(mt===" ")w.children.length>0&&(c.push(w),b.addChild(w)),y+=ot+P.letterSpacing,w=new dt({label:"word"}),w.x=y+a;else{let nt=U;G&&(nt=U.clone(),M?(nt._gradientOffset={x:-(y-N),y:0},nt._gradientBounds=et):nt._gradientOffset={x:-(y-N),y:0});let ht;p<e.length?(ht=e[p++],ht.text=mt,ht.style=nt,ht.setFromMatrix(D.IDENTITY),ht.x=y-w.x+a):ht=new Js({text:mt,style:nt,x:y-w.x+a}),u.push(ht),w.addChild(ht),y+=ot+P.letterSpacing}}}if(w.children.length>0&&(c.push(w),b.addChild(w)),n==="justify"&&t.wordWrap&&m<i.length-1){const A=b.children,P=A.length-1;if(P>0){const C=(o-S)/P;for(let O=1;O<A.length;O++)A[O].x+=O*C}}const E=(v=(x=r.lineHeights)==null?void 0:x[m])!=null?v:r.lineHeight;d+=E}),{chars:u,lines:h,words:c}}var gB=Object.defineProperty,_B=Object.defineProperties,xB=Object.getOwnPropertyDescriptors,XT=Object.getOwnPropertySymbols,vB=Object.prototype.hasOwnProperty,bB=Object.prototype.propertyIsEnumerable,
|
||
|
|
//# sourceMappingURL=pixi.min.mjs.map
|