1997 lines
600 KiB
JavaScript
1997 lines
600 KiB
JavaScript
![]() |
/*!
|
||
|
* PixiJS - v8.1.4
|
||
|
* Compiled Fri, 17 May 2024 12:41:01 UTC
|
||
|
*
|
||
|
* PixiJS is licensed under the MIT License.
|
||
|
* http://www.opensource.org/licenses/mit-license
|
||
|
*/var PIXI=function(d){"use strict";"use strict";var Kb=Object.defineProperty,qb=Object.defineProperties,Zb=Object.getOwnPropertyDescriptors,rl=Object.getOwnPropertySymbols,Qb=Object.prototype.hasOwnProperty,Jb=Object.prototype.propertyIsEnumerable,il=(r,t,e)=>t in r?Kb(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,sl=(r,t)=>{for(var e in t||(t={}))Qb.call(t,e)&&il(r,e,t[e]);if(rl)for(var e of rl(t))Jb.call(t,e)&&il(r,e,t[e]);return r},tv=(r,t)=>qb(r,Zb(t)),x=(r=>(r.Application="application",r.WebGLPipes="webgl-pipes",r.WebGLPipesAdaptor="webgl-pipes-adaptor",r.WebGLSystem="webgl-system",r.WebGPUPipes="webgpu-pipes",r.WebGPUPipesAdaptor="webgpu-pipes-adaptor",r.WebGPUSystem="webgpu-system",r.CanvasSystem="canvas-system",r.CanvasPipesAdaptor="canvas-pipes-adaptor",r.CanvasPipes="canvas-pipes",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.Environment="environment",r))(x||{});const Ds=r=>{if(typeof r=="function"||typeof r=="object"&&r.extension){const t=typeof r.extension!="object"?{type:r.extension}:r.extension;r=tv(sl({},t),{ref:r})}if(typeof r=="object")r=sl({},r);else throw new Error("Invalid extension type");return typeof r.type=="string"&&(r.type=[r.type]),r},Qe=(r,t)=>{var e;return(e=Ds(r).priority)!=null?e:t},U={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...r){return r.map(Ds).forEach(t=>{t.type.forEach(e=>{var i,s;return(s=(i=this._removeHandlers)[e])==null?void 0:s.call(i,t)})}),this},add(...r){return r.map(Ds).forEach(t=>{t.type.forEach(e=>{var i,s;const n=this._addHandlers,o=this._queue;n[e]?(s=n[e])==null||s.call(n,t):(o[e]=o[e]||[],(i=o[e])==null||i.push(t))})}),this},handle(r,t,e){var i;const s=this._addHandlers,n=this._removeHandlers;s[r]=t,n[r]=e;const o=this._queue;return o[r]&&((i=o[r])==null||i.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,i=>{t.findIndex(s=>s.name===i.name)>=0||(t.push({name:i.name,value:i.ref}),t.sort((s,n)=>Qe(n.value,e)-Qe(s.value,e)))},i=>{const s=t.findIndex(n=>n.name===i.name);s!==-1&&t.splice(s,1)})},handleByList(r,t,e=-1){return this.handle(r,i=>{t.includes(i.ref)||(t.push(i.ref),t.sort((s,n)=>Qe(n,e)-Qe(s,e)))},i=>{const s=t.indexOf(i.ref);s!==-1&&t.splice(s,1)})}};var BA=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function Us(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function IA(r){return r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function FA(r){return r&&Object.prototype.hasOwnProperty.call(r,"default")&&Object.keys(r).length===1?r.default:r}function DA(r){if(r.__esModule)return r;var t=r.default;if(typeof t=="function"){var e=function i(){return this instanceof 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(i){var s=Object.getOwnPropertyDescriptor(r,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return r[i]}})}),e}var ks={exports:{}},UA=ks.exports;(function(r){"use strict";var t=Object.prototype.hasOwnProperty,e="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(e=!1));function s(u,l,c){this.fn=u,this.context=l,this.once=c||!1}function n(u,l,c,h,p){if(typeof c!="function")throw new TypeError("The listener must be a function");var f=new s(c,h||u,p),m=e?e+l:l;return u._events[m]?u._events[m].fn?u._events[m]=[u._events[m],f]:u._events[m].push(f):(u._events[m]=f,u._eventsCount++),u}function o(u,l){--u._eventsCount===0?u._events=new i:delete u._events[l]}function a(){this._events=new i,this._eventsCount=0}a.prototype.eventNames=function(){var l=[],c,h;if(this._eventsCou
|
||
|
Deprecated since v${r}`):(i=i.split(`
|
||
|
`).splice(e).join(`
|
||
|
`),console.groupCollapsed?(console.groupCollapsed("%cPixiJS Deprecation Warning: %c%s","color:#614108;background:#fffbe6","font-weight:normal;color:#614108;background:#fffbe6",`${t}
|
||
|
Deprecated since v${r}`),console.warn(i),console.groupEnd()):(console.warn("PixiJS Deprecation Warning: ",`${t}
|
||
|
Deprecated since v${r}`),console.warn(i))),_h[t]=!0}const vh=class Zu{constructor(t,e,i,s){this.uid=J("fillGradient"),this.type="linear",this.gradientStops=[],this.x0=t,this.y0=e,this.x1=i,this.y1=s}addColorStop(t,e){return this.gradientStops.push({offset:t,color:K.shared.setValue(e).toHex()}),this}buildLinearGradient(){const t=Zu.defaultTextureSize,{gradientStops:e}=this,i=z.get().createCanvas();i.width=t,i.height=t;const s=i.getContext("2d"),n=s.createLinearGradient(0,0,Zu.defaultTextureSize,1);for(let _=0;_<e.length;_++){const g=e[_];n.addColorStop(g.offset,g.color)}s.fillStyle=n,s.fillRect(0,0,t,t),this.texture=new P({source:new pe({resource:i,addressModeU:"clamp-to-edge",addressModeV:"repeat"})});const{x0:o,y0:a,x1:u,y1:l}=this,c=new G,h=u-o,p=l-a,f=Math.sqrt(h*h+p*p),m=Math.atan2(p,h);c.translate(-o,-a),c.scale(1/t,1/t),c.rotate(-m),c.scale(256/f,1),this.transform=c}};vh.defaultTextureSize=256;let Ai=vh;var ox=ux,qn={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},ax=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function ux(r){var t=[];return r.replace(ax,function(e,i,s){var n=i.toLowerCase();for(s=cx(s),n=="m"&&s.length>2&&(t.push([i].concat(s.splice(0,2))),n="l",i=i=="m"?"l":"L");;){if(s.length==qn[n])return s.unshift(i),t.push(s);if(s.length<qn[n])throw new Error("malformed path data");t.push([i].concat(s.splice(0,qn[n])))}}),t}var lx=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function cx(r){var t=r.match(lx);return t?t.map(Number):[]}var hx=Us(ox);function yh(r,t){const e=hx(r),i=[];let s=null,n=0,o=0;for(let a=0;a<e.length;a++){const u=e[a],l=u[0],c=u;switch(l){case"M":n=c[1],o=c[2],t.moveTo(n,o);break;case"m":n+=c[1],o+=c[2],t.moveTo(n,o);break;case"H":n=c[1],t.lineTo(n,o);break;case"h":n+=c[1],t.lineTo(n,o);break;case"V":o=c[1],t.lineTo(n,o);break;case"v":o+=c[1],t.lineTo(n,o);break;case"L":n=c[1],o=c[2],t.lineTo(n,o);break;case"l":n+=c[1],o+=c[2],t.lineTo(n,o);break;case"C":n=c[5],o=c[6],t.bezierCurveTo(c[1],c[2],c[3],c[4],n,o);break;case"c":t.bezierCurveTo(n+c[1],o+c[2],n+c[3],o+c[4],n+c[5],o+c[6]),n+=c[5],o+=c[6];break;case"S":n=c[3],o=c[4],t.bezierCurveToShort(c[1],c[2],n,o);break;case"s":t.bezierCurveToShort(n+c[1],o+c[2],n+c[3],o+c[4]),n+=c[3],o+=c[4];break;case"Q":n=c[3],o=c[4],t.quadraticCurveTo(c[1],c[2],n,o);break;case"q":t.quadraticCurveTo(n+c[1],o+c[2],n+c[3],o+c[4]),n+=c[3],o+=c[4];break;case"T":n=c[1],o=c[2],t.quadraticCurveToShort(n,o);break;case"t":n+=c[1],o+=c[2],t.quadraticCurveToShort(n,o);break;case"A":n=c[6],o=c[7],t.arcToSvg(c[1],c[2],c[3],c[4],c[5],n,o);break;case"a":n+=c[6],o+=c[7],t.arcToSvg(c[1],c[2],c[3],c[4],c[5],n,o);break;case"Z":case"z":t.closePath(),i.length>0&&(s=i.pop(),s?(n=s.startX,o=s.startY):(n=0,o=0)),s=null;break;default:}l!=="Z"&&l!=="z"&&s===null&&(s={startX:n,startY:o},i.push(s))}return t}class Pi{constructor(t=0,e=0,i=0){this.type="circle",this.x=t,this.y=e,this.radius=i}clone(){return new Pi(this.x,this.y,this.radius)}contains(t,e){if(this.radius<=0)return!1;const i=this.radius*this.radius;let s=this.x-t,n=this.y-e;return s*=s,n*=n,s+n<=i}strokeContains(t,e,i){if(this.radius===0)return!1;const s=this.x-t,n=this.y-e,o=this.radius,a=i/2,u=Math.sqrt(s*s+n*n);return u<o+a&&u>o-a}getBounds(t){return t=t||new j,t.x=this.x-this.radius,t.y=this.y-this.radius,t.width=this.radius*2,t.height=this.radius*2,t}copyFrom(t){return this.x=t.x,this.y=t.y,this.radius=t.radius,this}copyTo(t){return t.copyFrom(this),t}}class wi{constructor(t=0,e=0,i=0,s=0){this.type="ellipse",this.x=t,this.y=e,this.halfWidth=i,this.halfHeight=s}clone(){return new wi(this.x,this.y,this.halfWidth,this.halfHeight)}contains(t,e){if(this.halfWidth<=0||this.halfHeight<=0)return!1;let i=(t-this.x)/this.halfWidth,s=(e-this.y)/this.halfHeight;return i*=i,s*=s,i+s<=1}strokeContains(t,e,i){const{halfWidth:s,halfHeight:n}=this;if(s<=0||n<=0)return!1;const o=i/2,a=s-o,u=n-o,l=s+o,c=n+o,h=t-this.x,p=e-this.y,f=h*h/(a*a)+p*p/(u*u),m=h*h/(l*l)+p*p/(c*c);return f>1&&m<=1}getBounds(){return new j(this.x-this.halfWidth,this.y-this.halfHeight,this.halfWidth*2,this.halfHeight*2)}copyFrom(t){return this.x=t.x,this.y=t.y,this.halfWidth=t.halfWidth
|
||
|
`:t,t}static _getFromCache(t,e,i,s){let n=i[t];return typeof n!="number"&&(n=C._measureText(t,e,s)+e,i[t]=n),n}static _collapseSpaces(t){return t==="normal"||t==="pre-line"}static _collapseNewlines(t){return t==="normal"}static _trimRight(t){if(typeof t!="string")return"";for(let e=t.length-1;e>=0;e--){const i=t[e];if(!C.isBreakingSpace(i))break;t=t.slice(0,-1)}return t}static _isNewline(t){return typeof t!="string"?!1:C._newlines.includes(t.charCodeAt(0))}static isBreakingSpace(t,e){return typeof t!="string"?!1:C._breakingSpaces.includes(t.charCodeAt(0))}static _tokenize(t){const e=[];let i="";if(typeof t!="string")return e;for(let s=0;s<t.length;s++){const n=t[s],o=t[s+1];if(C.isBreakingSpace(n,o)||C._isNewline(n)){i!==""&&(e.push(i),i=""),e.push(n);continue}i+=n}return i!==""&&e.push(i),e}static canBreakWords(t,e){return e}static canBreakChars(t,e,i,s,n){return!0}static wordWrapSplit(t){return C.graphemeSegmenter(t)}static measureFont(t){if(C._fonts[t])return C._fonts[t];const e=C._context;e.font=t;const i=e.measureText(C.METRICS_STRING+C.BASELINE_SYMBOL),s={ascent:i.actualBoundingBoxAscent,descent:i.actualBoundingBoxDescent,fontSize:i.actualBoundingBoxAscent+i.actualBoundingBoxDescent};return C._fonts[t]=s,s}static clearMetrics(t=""){t?delete C._fonts[t]:C._fonts={}}static get _canvas(){if(!C.__canvas){let t;try{const e=new OffscreenCanvas(0,0),i=e.getContext("2d",co);if(i!=null&&i.measureText)return C.__canvas=e,e;t=z.get().createCanvas()}catch(e){t=z.get().createCanvas()}t.width=t.height=10,C.__canvas=t}return C.__canvas}static get _context(){return C.__context||(C.__context=C._canvas.getContext("2d",co)),C.__context}};Dt.METRICS_STRING="|\xC9q\xC5",Dt.BASELINE_SYMBOL="M",Dt.BASELINE_MULTIPLIER=1.4,Dt.HEIGHT_MULTIPLIER=2,Dt.graphemeSegmenter=(()=>{if(typeof(Intl==null?void 0:Intl.Segmenter)=="function"){const r=new Intl.Segmenter;return t=>[...r.segment(t)].map(e=>e.segment)}return r=>[...r]})(),Dt.experimentalLetterSpacing=!1,Dt._fonts={},Dt._newlines=[10,13],Dt._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288],Dt._measurementCache={};let Ut=Dt;function Sr(r,t){if(r.texture===P.WHITE&&!r.fill)return K.shared.setValue(r.color).toHex();if(r.fill){if(r.fill instanceof so){const e=r.fill,i=t.createPattern(e.texture.source.resource,"repeat"),s=e.transform.copyTo(G.shared);return s.scale(e.texture.frame.width,e.texture.frame.height),i.setTransform(s),i}else if(r.fill instanceof Ai){const e=r.fill;if(e.type==="linear"){const i=t.createLinearGradient(e.x0,e.y0,e.x1,e.y1);return e.gradientStops.forEach(s=>{i.addColorStop(s.offset,K.shared.setValue(s.color).toHex())}),i}}}else{const e=t.createPattern(r.texture.source.resource,"repeat"),i=r.matrix.copyTo(G.shared);return i.scale(r.texture.frame.width,r.texture.frame.height),e.setTransform(i),e}return"red"}class ho{constructor(t){this._activeTextures={},this._renderer=t}getTextureSize(t,e,i){const s=Ut.measureText(t||" ",i);let n=Math.ceil(Math.ceil(Math.max(1,s.width)+i.padding*2)*e),o=Math.ceil(Math.ceil(Math.max(1,s.height)+i.padding*2)*e);return n=Math.ceil(n-1e-6),o=Math.ceil(o-1e-6),n=he(n),o=he(o),{width:n,height:o}}getTexture(t,e,i,s){typeof t=="string"&&(bh("8.0.0","CanvasTextSystem.getTexture: Use object TextOptions instead of separate arguments"),t={text:t,style:i,resolution:e}),t.style instanceof Ft||(t.style=new Ft(t.style));const{texture:n,canvasAndContext:o}=this.createTextureAndCanvas(t);return this._renderer.texture.initSource(n._source),Ht.returnCanvasAndContext(o),n}createTextureAndCanvas(t){var e;const{text:i,style:s}=t,n=(e=t.resolution)!=null?e:this._renderer.resolution,o=Ut.measureText(i||" ",s),a=Math.ceil(Math.ceil(Math.max(1,o.width)+s.padding*2)*n),u=Math.ceil(Math.ceil(Math.max(1,o.height)+s.padding*2)*n),l=Ht.getOptimalCanvasAndContext(a,u),{canvas:c}=l;this.renderTextToCanvas(i,s,n,l);const h=lo(c,a,u,n);if(s.trim){const p=gh(c,n);h.frame.copyFrom(p),h.updateUvs()}return{texture:h,canvasAndContext:l}}getManagedTexture(t){const e=t._getKey();if(this._activeTextures[e])return this._increaseReferenceCount(e),this._
|
||
|
`&&T!=="\r"&&T!==" "&&T!==" "&&(v=!0,b=Math.ceil(Math.max(S,b))),p+M>512&&(f+=b,b=S,p=0,f+b>512)){c.update();const N=this._nextPage();u=N.canvasAndContext.canvas,l=N.canvasAndContext.context,c=N.texture.source,f=0}const A=R/m-((i=(e=h.dropShadow)==null?void 0:e.distance)!=null?i:0)-((n=(s=h._stroke)==null?void 0:s.width)!=null?n:0);if(this.chars[T]={id:T.codePointAt(0),xOffset:-this._padding,yOffset:-this._padding,xAdvance:A,kerning:{}},v){this._drawGlyph(l,E,p+_,f+_,m,h);const N=c.width*m,L=c.height*m,O=new j(p/N*c.width,f/L*c.height,M/N*c.width,S/L*c.height);this.chars[T].texture=new P({source:c,frame:O}),p+=Math.ceil(M)}}c.update(),this._currentX=p,this._currentY=f,this._skipKerning&&this._applyKerning(o,l)}get pageTextures(){return this.pages}_applyKerning(t,e){const i=this._measureCache;for(let s=0;s<t.length;s++){const n=t[s];for(let o=0;o<this._currentChars.length;o++){const a=this._currentChars[o];let u=i[n];u||(u=i[n]=e.measureText(n).width);let l=i[a];l||(l=i[a]=e.measureText(a).width);let c=e.measureText(n+a).width,h=c-(u+l);h&&(this.chars[n].kerning[a]=h),c=e.measureText(n+a).width,h=c-(u+l),h&&(this.chars[a].kerning[n]=h)}}}_nextPage(){this._currentPageIndex++;const t=this.resolution,e=Ht.getOptimalCanvasAndContext(512,512,t);this._setupContext(e.context,this._style,t);const i=t*(this.baseRenderedFontSize/this.baseMeasurementFontSize),s=new P({source:new pe({resource:e.canvas,resolution:i,alphaMode:"premultiply-alpha-on-upload"})}),n={canvasAndContext:e,texture:s};return this.pages[this._currentPageIndex]=n,n}_setupContext(t,e,i){var s;e.fontSize=this.baseRenderedFontSize,t.scale(i,i),t.font=Tr(e),e.fontSize=this.baseMeasurementFontSize,t.textBaseline=e.textBaseline;const n=e._stroke,o=(s=n==null?void 0:n.width)!=null?s:0;if(n&&(t.lineWidth=o,t.lineJoin=n.join,t.miterLimit=n.miterLimit,t.strokeStyle=Sr(n,t)),e._fill&&(t.fillStyle=Sr(e._fill,t)),e.dropShadow){const a=e.dropShadow,u=K.shared.setValue(a.color).toArray(),l=a.blur*i,c=a.distance*i;t.shadowColor=`rgba(${u[0]*255},${u[1]*255},${u[2]*255},${a.alpha})`,t.shadowBlur=l,t.shadowOffsetX=Math.cos(a.angle)*c,t.shadowOffsetY=Math.sin(a.angle)*c}else t.shadowColor="black",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0}_drawGlyph(t,e,i,s,n,o){var a;const u=e.text,l=e.fontProperties,c=o._stroke,h=((a=c==null?void 0:c.width)!=null?a:0)*n,p=i+h/2,f=s-h/2,m=l.descent*n,_=e.lineHeight*n;o.stroke&&h&&t.strokeText(u,p,f+_-m),o._fill&&t.fillText(u,p,f+_-m)}destroy(){super.destroy();for(let t=0;t<this.pages.length;t++){const{canvasAndContext:e,texture:i}=this.pages[t];Ht.returnCanvasAndContext(e),i.destroy(!0)}this.pages=null}}function go(r,t,e){const i={width:0,height:0,offsetY:0,scale:t.fontSize/e.baseMeasurementFontSize,lines:[{width:0,charPositions:[],spaceWidth:0,spacesIndex:[],chars:[]}]};i.offsetY=e.baseLineOffset;let s=i.lines[0],n=null,o=!0;const a={spaceWord:!1,width:0,start:0,index:0,positions:[],chars:[]},u=f=>{const m=s.width;for(let _=0;_<a.index;_++){const g=f.positions[_];s.chars.push(f.chars[_]),s.charPositions.push(g+m)}s.width+=f.width,o=!1,a.width=0,a.index=0,a.chars.length=0},l=()=>{let f=s.chars.length-1,m=s.chars[f];for(;m===" ";)s.width-=e.chars[m].xAdvance,m=s.chars[--f];i.width=Math.max(i.width,s.width),s={width:0,charPositions:[],chars:[],spaceWidth:0,spacesIndex:[]},o=!0,i.lines.push(s),i.height+=e.lineHeight},c=e.baseMeasurementFontSize/t.fontSize,h=t.letterSpacing*c,p=t.wordWrapWidth*c;for(let f=0;f<r.length+1;f++){let m;const _=f===r.length;_||(m=r[f]);const g=e.chars[m]||e.chars[" "];if(/(?:\s)/.test(m)||m==="\r"||m===`
|
||
|
`||_){if(!o&&t.wordWrap&&s.width+a.width-h>p?(l(),u(a),_||s.charPositions.push(0)):(a.start=s.width,u(a),_||s.charPositions.push(0)),m==="\r"||m===`
|
||
|
`)s.width!==0&&l();else if(!_){const b=g.xAdvance+(g.kerning[n]||0)+h;s.width+=b,s.spaceWidth=b,s.spacesIndex.push(s.charPositions.length),s.chars.push(m)}}else{const b=g.kerning[n]||0,v=g.xAdvance+b+h;a.positions[a.index++]=a.width+b,a.chars.push(m),a.width+=v}n=m}return l(),t.align==="center"?Xx(i):t.align==="right"?zx(i):t.align==="justify"&&jx(i),i}function Xx(r){for(let t=0;t<r.lines.length;t++){const e=r.lines[t],i=r.width/2-e.width/2;for(let s=0;s<e.charPositions.length;s++)e.charPositions[s]+=i}}function zx(r){for(let t=0;t<r.lines.length;t++){const e=r.lines[t],i=r.width-e.width;for(let s=0;s<e.charPositions.length;s++)e.charPositions[s]+=i}}function jx(r){const t=r.width;for(let e=0;e<r.lines.length;e++){const i=r.lines[e];let s=0,n=i.spacesIndex[s++],o=0;const a=i.spacesIndex.length,u=(t-i.width)/a;for(let l=0;l<i.charPositions.length;l++)l===n&&(n=i.spacesIndex[s++],o+=u),i.charPositions[l]+=o}}var Vx=Object.defineProperty,Xh=Object.getOwnPropertySymbols,Wx=Object.prototype.hasOwnProperty,Yx=Object.prototype.propertyIsEnumerable,zh=(r,t,e)=>t in r?Vx(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,_o=(r,t)=>{for(var e in t||(t={}))Wx.call(t,e)&&zh(r,e,t[e]);if(Xh)for(var e of Xh(t))Yx.call(t,e)&&zh(r,e,t[e]);return r};let Kx=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}}getFont(t,e){var i;let s=`${e.fontFamily}-bitmap`,n=!0;if(e._fill.fill&&(s+=e._fill.fill.uid,n=!1),!q.has(s)){const a=new mo(_o({style:e,overrideFill:n,overrideSize:!0},this.defaultOptions));a.once("destroy",()=>q.remove(s)),q.set(s,a)}const o=q.get(s);return(i=o.ensureCharacters)==null||i.call(o,t),o}getLayout(t,e){const i=this.getFont(t,e);return go([...t],e,i)}measureText(t,e){return this.getLayout(t,e)}install(...t){var e,i,s,n;let o=t[0];typeof o=="string"&&(o={name:o,style:t[1],chars:(e=t[2])==null?void 0:e.chars,resolution:(i=t[2])==null?void 0:i.resolution,padding:(s=t[2])==null?void 0:s.padding,skipKerning:(n=t[2])==null?void 0:n.skipKerning});const a=o==null?void 0:o.name;if(!a)throw new Error("[BitmapFontManager] Property `name` is required.");o=_o(_o({},this.defaultOptions),o);const u=o.style,l=u instanceof Ft?u:new Ft(u),c=l._fill.fill!==null&&l._fill.fill!==void 0,h=new mo({style:l,overrideFill:c,skipKerning:o.skipKerning,padding:o.padding,resolution:o.resolution,overrideSize:!1}),p=fo(o.chars);return h.ensureCharacters(p.join("")),q.set(`${a}-bitmap`,h),h.once("destroy",()=>q.remove(`${a}-bitmap`)),h}uninstall(t){const e=`${t}-bitmap`,i=q.get(e);i&&(q.remove(e),i.destroy())}};const Er=new Kx;class bo extends po{constructor(t,e){var i;super();const{textures:s,data:n}=t;Object.keys(n.pages).forEach(o=>{const a=n.pages[parseInt(o,10)],u=s[a.id];this.pages.push({texture:u})}),Object.keys(n.chars).forEach(o=>{var a;const u=n.chars[o],{frame:l,source:c}=s[u.page],h=new j(u.x+l.x,u.y+l.y,u.width,u.height),p=new P({source:c,frame:h});this.chars[o]={id:o.codePointAt(0),xOffset:u.xOffset,yOffset:u.yOffset,xAdvance:u.xAdvance,kerning:(a=u.kerning)!=null?a:{},texture:p}}),this.baseRenderedFontSize=n.fontSize,this.baseMeasurementFontSize=n.fontSize,this.fontMetrics={ascent:0,descent:0,fontSize:n.fontSize},this.baseLineOffset=n.baseLineOffset,this.lineHeight=n.lineHeight,this.fontFamily=n.fontFamily,this.distanceField=(i=n.distanceField)!=null?i:{type:"none",range:0},this.url=e}destroy(){super.destroy();for(let t=0;t<this.pages.length;t++){const{texture:e}=this.pages[t];e.destroy(!0)}this.pages=null}static install(t){Er.install(t)}static uninstall(t){Er.uninstall(t)}}const Gi={test(r){return typeof r=="string"&&r.startsWith("info face=")},parse(r){var t,e,i;const s=r.match(/^[a-z]+\s+.+$/gm),n={info:[],common:[],page:[],char:[],chars:[],kerning:[],kernings:[],distanceField:[]};for(const m in s){const _=s[m].match(/^[a-z]+/gm)[0],g=s[m].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm),b={};for(const v in g){const y=g[v].split("="),T=y[0],E=
|
||
|
|
||
|
#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 Qh(r,t,e){const i=e?t.maxSupportedFragmentPrecision:t.maxSupportedVertexPrecision;if(r.substring(0,9)!=="precision"){let s=e?t.requestedFragmentPrecision:t.requestedVertexPrecision;return s==="highp"&&i!=="highp"&&(s="mediump"),`precision ${s} float;
|
||
|
${r}`}else if(i!=="highp"&&r.substring(0,15)==="precision highp")return r.replace("precision highp","precision mediump");return r}function Jh(r,t){return t?`#version 300 es
|
||
|
${r}`:r}const t0={},e0={};function td(r,{name:t="pixi-program"},e=!0){t=t.replace(/\s+/g,"-"),t+=e?"-fragment":"-vertex";const i=e?t0:e0;return i[t]?(i[t]++,t+=`-${i[t]}`):i[t]=1,r.indexOf("#define SHADER_NAME")!==-1?r:`${`#define SHADER_NAME ${t}`}
|
||
|
${r}`}function ed(r,t){return t?r.replace("#version 300 es",""):r}var r0=Object.defineProperty,rd=Object.getOwnPropertySymbols,i0=Object.prototype.hasOwnProperty,s0=Object.prototype.propertyIsEnumerable,id=(r,t,e)=>t in r?r0(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,sd=(r,t)=>{for(var e in t||(t={}))i0.call(t,e)&&id(r,e,t[e]);if(rd)for(var e of rd(t))s0.call(t,e)&&id(r,e,t[e]);return r};const xo={stripVersion:ed,ensurePrecision:Qh,addProgramDefines:Zh,setProgramName:td,insertVersion:Jh},To=Object.create(null),nd=class Qu{constructor(t){t=sd(sd({},Qu.defaultOptions),t);const e=t.fragment.indexOf("#version 300 es")!==-1,i={stripVersion:e,ensurePrecision:{requestedFragmentPrecision:t.preferredFragmentPrecision,requestedVertexPrecision:t.preferredVertexPrecision,maxSupportedVertexPrecision:"highp",maxSupportedFragmentPrecision:qh()},setProgramName:{name:t.name},addProgramDefines:e,insertVersion:e};let s=t.fragment,n=t.vertex;Object.keys(xo).forEach(o=>{const a=i[o];s=xo[o](s,a,!0),n=xo[o](n,a,!1)}),this.fragment=s,this.vertex=n,this._key=_r(`${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}static from(t){const e=`${t.vertex}:${t.fragment}`;return To[e]||(To[e]=new Qu(t)),To[e]}};nd.defaultOptions={preferredVertexPrecision:"highp",preferredFragmentPrecision:"mediump"};let Mt=nd;const od={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 Ue(r){var t;return(t=od[r])!=null?t:od.float32}const n0={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",u32:"uint32","vec2<u32>":"uint32x2","vec3<u32>":"uint32x3","vec4<u32>":"uint32x4",bool:"uint32","vec2<bool>":"uint32x2","vec3<bool>":"uint32x3","vec4<bool>":"uint32x4"};function ad({source:r,entryPoint:t}){var e;const i={},s=r.indexOf(`fn ${t}`);if(s!==-1){const n=r.indexOf("->",s);if(n!==-1){const o=r.substring(s,n),a=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|$)/g;let u;for(;(u=a.exec(o))!==null;){const l=(e=n0[u[3]])!=null?e:"float32";i[u[2]]={location:parseInt(u[1],10),format:l,stride:Ue(l).stride,offset:0,instance:!1,start:0}}}}return i}function Fi(r){var t,e,i;const s=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,n=/@group\((\d+)\)/,o=/@binding\((\d+)\)/,a=/var(<[^>]+>)? (\w+)/,u=/:\s*(\w+)/,l=/struct\s+(\w+)\s*{([^}]+)}/g,c=/(\w+)\s*:\s*([\w\<\>]+)/g,h=/struct\s+(\w+)/,p=(t=r.match(s))==null?void 0:t.map(m=>({group:parseInt(m.match(n)[1],10),binding:parseInt(m.match(o)[1],10),name:m.match(a)[2],isUniform:m.match(a)[1]==="<uniform>",type:m.match(u)[1]}));if(!p)return{groups:[],structs:[]};const f=(i=(e=r.match(l))==null?void 0:e.map(m=>{const _=
|
||
|
`);let o=t.replace(/@in\s+[^;]+;\s*/g,"");return o=o.replace("{{in}}",`
|
||
|
${n}
|
||
|
`),o}function pd(r,t){let e;const i=/@out\s+([^;]+);/g;for(;(e=i.exec(r))!==null;)t.push(e[1])}function o0(r){const t=/\b(\w+)\s*:/g.exec(r);return t?t[1]:""}function a0(r){const t=/@.*?\s+/g;return r.replace(t,"")}function fd(r,t){const e=[];pd(t,e),r.forEach(u=>{u.header&&pd(u.header,e)});let i=0;const s=e.sort().map(u=>u.indexOf("builtin")>-1?u:`@location(${i++}) ${u}`).join(`,
|
||
|
`),n=e.sort().map(u=>` var ${a0(u)};`).join(`
|
||
|
`),o=`return VSOutput(
|
||
|
${e.sort().map(u=>` ${o0(u)}`).join(`,
|
||
|
`)});`;let a=t.replace(/@out\s+[^;]+;\s*/g,"");return a=a.replace("{{struct}}",`
|
||
|
${s}
|
||
|
`),a=a.replace("{{start}}",`
|
||
|
${n}
|
||
|
`),a=a.replace("{{return}}",`
|
||
|
${o}
|
||
|
`),a}function wo(r,t){let e=r;for(const i in t){const s=t[i];s.join(`
|
||
|
`).length?e=e.replace(`{{${i}}}`,`//-----${i} START-----//
|
||
|
${s.join(`
|
||
|
`)}
|
||
|
//----${i} FINISH----//`):e=e.replace(`{{${i}}}`,"")}return e}const ve=Object.create(null),Ro=new Map;let u0=0;function md({template:r,bits:t}){const e=_d(r,t);if(ve[e])return ve[e];const{vertex:i,fragment:s}=l0(r,t);return ve[e]=bd(i,s,t),ve[e]}function gd({template:r,bits:t}){const e=_d(r,t);return ve[e]||(ve[e]=bd(r.vertex,r.fragment,t)),ve[e]}function l0(r,t){const e=t.map(o=>o.vertex).filter(o=>!!o),i=t.map(o=>o.fragment).filter(o=>!!o);let s=Po(e,r.vertex,!0);s=fd(e,s);const n=Po(i,r.fragment,!0);return{vertex:s,fragment:n}}function _d(r,t){return t.map(e=>(Ro.has(e)||Ro.set(e,u0++),Ro.get(e))).sort((e,i)=>e-i).join("-")+r.vertex+r.fragment}function bd(r,t,e){const i=Ao(r),s=Ao(t);return e.forEach(n=>{Eo(n.vertex,i,n.name),Eo(n.fragment,s,n.name)}),{vertex:wo(r,i),fragment:wo(t,s)}}const vd=`
|
||
|
@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}}
|
||
|
};
|
||
|
`,yd=`
|
||
|
@in vUV : vec2<f32>;
|
||
|
@in vColor : vec4<f32>;
|
||
|
|
||
|
{{header}}
|
||
|
|
||
|
@fragment
|
||
|
fn main(
|
||
|
{{in}}
|
||
|
) -> @location(0) vec4<f32> {
|
||
|
|
||
|
{{start}}
|
||
|
|
||
|
var outColor:vec4<f32>;
|
||
|
|
||
|
{{main}}
|
||
|
|
||
|
return outColor * vColor;
|
||
|
};
|
||
|
`,xd=`
|
||
|
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}}
|
||
|
}
|
||
|
`,Td=`
|
||
|
|
||
|
in vec4 vColor;
|
||
|
in vec2 vUV;
|
||
|
|
||
|
out vec4 finalColor;
|
||
|
|
||
|
{{header}}
|
||
|
|
||
|
void main(void) {
|
||
|
|
||
|
{{start}}
|
||
|
|
||
|
vec4 outColor;
|
||
|
|
||
|
{{main}}
|
||
|
|
||
|
finalColor = outColor * vColor;
|
||
|
}
|
||
|
`,Sd={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;
|
||
|
`}},c0={name:"global-uniforms-ubo-bit",vertex:{header:`
|
||
|
uniform globalUniforms {
|
||
|
mat3 uProjectionMatrix;
|
||
|
mat3 uWorldTransformMatrix;
|
||
|
vec4 uWorldColorAlpha;
|
||
|
vec2 uResolution;
|
||
|
};
|
||
|
`}},Ed={name:"global-uniforms-bit",vertex:{header:`
|
||
|
uniform mat3 uProjectionMatrix;
|
||
|
uniform mat3 uWorldTransformMatrix;
|
||
|
uniform vec4 uWorldColorAlpha;
|
||
|
uniform vec2 uResolution;
|
||
|
`}};var h0=Object.defineProperty,Ad=Object.getOwnPropertySymbols,d0=Object.prototype.hasOwnProperty,p0=Object.prototype.propertyIsEnumerable,Pd=(r,t,e)=>t in r?h0(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,f0=(r,t)=>{for(var e in t||(t={}))d0.call(t,e)&&Pd(r,e,t[e]);if(Ad)for(var e of Ad(t))p0.call(t,e)&&Pd(r,e,t[e]);return r};function Le({bits:r,name:t}){const e=md({template:{fragment:yd,vertex:vd},bits:[Sd,...r]});return vt.from({name:t,vertex:{source:e.vertex,entryPoint:"main"},fragment:{source:e.fragment,entryPoint:"main"}})}function $e({bits:r,name:t}){return new Mt(f0({name:t},gd({template:{vertex:xd,fragment:Td},bits:[Ed,...r]})))}const Di={name:"color-bit",vertex:{header:`
|
||
|
@in aColor: vec4<f32>;
|
||
|
`,main:`
|
||
|
vColor *= vec4<f32>(aColor.rgb * aColor.a, aColor.a);
|
||
|
`}},Ui={name:"color-bit",vertex:{header:`
|
||
|
in vec4 aColor;
|
||
|
`,main:`
|
||
|
vColor *= vec4(aColor.rgb * aColor.a, aColor.a);
|
||
|
`}},Mo={};function m0(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 i=0;i<r;i++)t.push(`@group(1) @binding(${e++}) var textureSource${i+1}: texture_2d<f32>;`),t.push(`@group(1) @binding(${e++}) var textureSampler${i+1}: sampler;`)}return t.join(`
|
||
|
`)}function g0(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 ki(r){return Mo[r]||(Mo[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;
|
||
|
|
||
|
${m0(dt)}
|
||
|
`,main:`
|
||
|
var uvDx = dpdx(vUV);
|
||
|
var uvDy = dpdy(vUV);
|
||
|
|
||
|
${g0(dt)}
|
||
|
`}}),Mo[r]}const Co={};function _0(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 Li(r){return Co[r]||(Co[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:`
|
||
|
|
||
|
${_0(dt)}
|
||
|
`}}),Co[r]}const Ne={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;
|
||
|
}
|
||
|
`}},He={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;
|
||
|
}
|
||
|
`}},wd=new Int32Array(dt);for(let r=0;r<dt;r++)wd[r]=r;const $i=new nt({uTextures:{value:wd,type:"i32",size:dt}},{isStatic:!0});var yt=(r=>(r[r.WEBGL=1]="WEBGL",r[r.WEBGPU=2]="WEBGPU",r[r.BOTH=3]="BOTH",r))(yt||{}),b0=Object.defineProperty,Ni=Object.getOwnPropertySymbols,Rd=Object.prototype.hasOwnProperty,Md=Object.prototype.propertyIsEnumerable,Cd=(r,t,e)=>t in r?b0(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,v0=(r,t)=>{for(var e in t||(t={}))Rd.call(t,e)&&Cd(r,e,t[e]);if(Ni)for(var e of Ni(t))Md.call(t,e)&&Cd(r,e,t[e]);return r},y0=(r,t)=>{var e={};for(var i in r)Rd.call(r,i)&&t.indexOf(i)<0&&(e[i]=r[i]);if(r!=null&&Ni)for(var i of Ni(r))t.indexOf(i)<0&&Md.call(r,i)&&(e[i]=r[i]);return e};class xt extends pt{constructor(t){super(),this._uniformBindMap=Object.create(null),this._ownedBindGroups=[];let{gpuProgram:e,glProgram:i,groups:s,resources:n,compatibleRenderers:o,groupMap:a}=t;this.gpuProgram=e,this.glProgram=i,o===void 0&&(o=0,e&&(o|=yt.WEBGPU),i&&(o|=yt.WEBGL)),this.compatibleRenderers=o;const u={};if(!n&&!s&&(n={}),n&&s)throw new Error("[Shader] Cannot have both resources and groups");if(!e&&s&&!a)throw new Error("[Shader] No group map or WebGPU shader provided - consider using resources instead.");if(!e&&s&&a)for(const l in a)for(const c in a[l]){const h=a[l][c];u[h]={group:l,binding:c,name:h}}else if(e&&s&&!a){const l=e.structsAndGroups.groups;a={},l.forEach(c=>{a[c.group]=a[c.group]||{},a[c.group][c.binding]=c.name,u[c.name]=c})}else if(n){if(e){const l=e.structsAndGroups.groups;a={},l.forEach(c=>{a[c.group]=a[c.group]||{},a[c.group][c.binding]=c.name,u[c.name]=c})}else{a={},s={99:new Nt},this._ownedBindGroups.push(s[99]);let l=0;for(const c in n)u[c]={group:99,binding:l,name:c},a[99]=a[99]||{},a[99][l]=c,l++}s={};for(const l in n){const c=l;let h=n[l];!h.source&&!h._resourceType&&(h=new nt(h));const p=u[c];p&&(s[p.group]||(s[p.group]=new Nt,this._ownedBindGroups.push(s[p.group])),s[p.group].setResource(h,p.binding))}}this.groups=s,this._uniformBindMap=a,this.resources=this._buildResourceAccessor(s,u)}addResource(t,e,i){var s,n;(s=this._uniformBindMap)[e]||(s[e]={}),(n=this._uniformBindMap[e])[i]||(n[i]=t),this.groups[e]||(this.groups[e]=new Nt,this._ownedBindGroups.push(this.groups[e]))}_buildResourceAccessor(t,e){const i={};for(const s in e){const n=e[s];Object.defineProperty(i,n.name,{get(){return t[n.group].getResource(n.binding)},set(o){t[n.group].setResource(o,n.binding)}})}return i}destroy(t=!1){var e,i;this.emit("destroy",this),t&&((e=this.gpuProgram)==null||e.destroy(),(i=this.glProgram)==null||i.destroy()),this.gpuProgram=null,this.glProgram=null,this.removeAllListeners(),this._uniformBindMap=null,this._ownedBindGroups.forEach(s=>{s.destroy()}),this._ownedBindGroups=null,this.resources=null,this.groups=null}static from(t){const e=t,{gpu:i,gl:s}=e,n=y0(e,["gpu","gl"]);let o,a;return i&&(o=vt.from(i)),s&&(a=Mt.from(s)),new xt(v0({gpuProgram:o,glProgram:a},n))}}const Od={name:"local-uniform-msdf-bit",vertex:{header:`
|
||
|
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 = vColor * calculateMSDFAlpha(outColor, localUniforms.uDistance);
|
||
|
`}},Gd={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 = vColor * calculateMSDFAlpha(outColor, uDistance);
|
||
|
`}},Bd={name:"msdf-bit",fragment:{header:`
|
||
|
fn calculateMSDFAlpha(msdfColor: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;
|
||
|
}
|
||
|
|
||
|
return alpha;
|
||
|
}
|
||
|
`}},Id={name:"msdf-bit",fragment:{header:`
|
||
|
float calculateMSDFAlpha(vec4 msdfColor, 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;
|
||
|
}
|
||
|
|
||
|
return alpha;
|
||
|
}
|
||
|
`}};class Fd extends xt{constructor(){const t=new nt({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new G,type:"mat3x3<f32>"},uDistance:{value:4,type:"f32"},uRound:{value:0,type:"f32"}}),e=Le({name:"sdf-shader",bits:[Di,ki(dt),Od,Bd,Ne]}),i=$e({name:"sdf-shader",bits:[Ui,Li(dt),Gd,Id,He]});super({glProgram:i,gpuProgram:e,resources:{localUniforms:t,batchSamplers:$i}})}}class Oo{constructor(t){this._gpuBitmapText={},this._renderer=t}validateRenderable(t){const e=this._getGpuBitmapText(t);return t._didTextUpdate&&(t._didTextUpdate=!1,this._updateContext(t,e)),this._renderer.renderPipes.graphics.validateRenderable(e)}addRenderable(t,e){const i=this._getGpuBitmapText(t);Dd(t,i),t._didTextUpdate&&(t._didTextUpdate=!1,this._updateContext(t,i)),this._renderer.renderPipes.graphics.addRenderable(i,e),i.context.customShader&&this._updateDistanceField(t)}destroyRenderable(t){this._destroyRenderableByUid(t.uid)}_destroyRenderableByUid(t){W.return(this._gpuBitmapText[t]),this._gpuBitmapText[t]=null}updateRenderable(t){const e=this._getGpuBitmapText(t);Dd(t,e),this._renderer.renderPipes.graphics.updateRenderable(e),e.context.customShader&&this._updateDistanceField(t)}_updateContext(t,e){var i;const{context:s}=e,n=Er.getFont(t.text,t._style);s.clear(),n.distanceField.type!=="none"&&(s.customShader||(this._sdfShader||(this._sdfShader=new Fd),s.customShader=this._sdfShader));const o=Array.from(t.text),a=t._style;let u=(((i=a._stroke)==null?void 0:i.width)||0)/2;u+=n.baseLineOffset;const l=go(o,a,n);let c=0;const h=a.padding,p=l.scale;s.translate(-t._anchor._x*l.width-h,-t._anchor._y*(l.height+l.offsetY)-h).scale(p,p);const f=a._fill.color;for(let m=0;m<l.lines.length;m++){const _=l.lines[m];for(let g=0;g<_.charPositions.length;g++){const b=o[c++],v=n.chars[b];v!=null&&v.texture&&s.texture(v.texture,f||"black",Math.round(_.charPositions[g]+v.xOffset),Math.round(u+v.yOffset))}u+=n.lineHeight}}_getGpuBitmapText(t){return this._gpuBitmapText[t.uid]||this.initGpuText(t)}initGpuText(t){const e=W.get(De);return this._gpuBitmapText[t.uid]=e,this._updateContext(t,e),t.on("destroyed",()=>{this.destroyRenderable(t)}),this._gpuBitmapText[t.uid]}_updateDistanceField(t){var e;const i=this._getGpuBitmapText(t).context,s=t._style.fontFamily,n=q.get(`${s}-bitmap`),{a:o,b:a,c:u,d:l}=t.groupTransform,c=Math.sqrt(o*o+a*a),h=Math.sqrt(u*u+l*l),p=(Math.abs(c)+Math.abs(h))/2,f=n.baseRenderedFontSize/t._style.fontSize,m=(e=t.resolution)!=null?e:this._renderer.resolution,_=p*n.distanceField.range*(1/f)*m;i.customShader.resources.localUniforms.uniforms.uDistance=_}destroy(){var t;for(const e in this._gpuBitmapText)this._destroyRenderableByUid(e);this._gpuBitmapText=null,(t=this._sdfShader)==null||t.destroy(!0),this._sdfShader=null,this._renderer=null}}Oo.extension={type:[x.WebGLPipes,x.WebGPUPipes,x.CanvasPipes],name:"bitmapText"};function Dd(r,t){t.groupTransform=r.groupTransform,t.groupColorAlpha=r.groupColorAlpha,t.groupColor=r.groupColor,t.groupBlendMode=r.groupBlendMode,t.globalDisplayStatus=r.globalDisplayStatus,t.groupTransform=r.groupTransform,t.localDisplayStatus=r.localDisplayStatus,t.groupAlpha=r.groupAlpha,t._roundPixels=r._roundPixels}U.add(Oo,Vh,jh);class Go{constructor(t){this._gpuText=Object.create(null),this._renderer=t}validateRenderable(t){const e=this._getGpuText(t),i=t._getKey();return e.textureNeedsUploading?(e.textureNeedsUploading=!1,!0):e.currentKey!==i}addRenderable(t){const e=this._getGpuText(t).batchableSprite;t._didTextUpdate&&this._updateText(t),this._renderer.renderPipes.batch.addToBatch(e)}updateRenderable(t){const e=this._getGpuText(t).batchableSprite;t._didTextUpdate&&this._updateText(t),e.batcher.updateElement(e)}destroyRenderable(t){this._destroyRenderableById(t.uid)}_destroyRenderableById(t){const e=this._gpuText[t];this._renderer.htmlText.decreaseReferenceCount(e.currentKey),W.return(e.batchableSprite),this._gpuText[t]=null}_updateText(t){const e=t._getKey(),i=this._getGpuText(t),s=i.batchableSprite;i.currentKey!==e&&this._updateGpuText(t).catch(o=>{console.error(o)}),t._didTextUp
|
||
|
font-family: "${r.fontFamily}";
|
||
|
src: url('${e}');
|
||
|
font-weight: ${r.fontWeight};
|
||
|
font-style: ${r.fontStyle};
|
||
|
}`}const Ar=new Map;async function jd(r,t,e){const i=r.filter(s=>q.has(`${s}-and-url`)).map((s,n)=>{if(!Ar.has(s)){const{url:o}=q.get(`${s}-and-url`);n===0?Ar.set(s,Do(t,o)):Ar.set(s,Do({fontWeight:e.fontWeight,fontStyle:e.fontStyle,fontFamily:s},o))}return Ar.get(s)});return(await Promise.all(i)).join(`
|
||
|
`)}function Vd(r,t,e,i,s){const{domElement:n,styleElement:o,svgRoot:a}=s;n.innerHTML=`<style>${t.cssStyle}</style><div>${r}</div>`,n.setAttribute("style",`transform: scale(${e});transform-origin: top left; display: inline-block`),o.textContent=i;const{width:u,height:l}=s.image;return a.setAttribute("width",u.toString()),a.setAttribute("height",l.toString()),new XMLSerializer().serializeToString(a)}function Wd(r,t){const e=Ht.getOptimalCanvasAndContext(r.width,r.height,t),{context:i}=e;return i.clearRect(0,0,r.width,r.height),i.drawImage(r,0,0),Ht.returnCanvasAndContext(e),e.canvas}function Yd(r,t,e){return new Promise(async i=>{e&&await new Promise(s=>setTimeout(s,100)),r.onload=()=>{i()},r.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(t)}`,r.crossOrigin="anonymous"})}let Kd;function Uo(r,t,e,i){i=i||Kd||(Kd=new Fo);const{domElement:s,styleElement:n,svgRoot:o}=i;s.innerHTML=`<style>${t.cssStyle}</style><div>${r}</div>`,s.setAttribute("style","transform-origin: top left; display: inline-block"),e&&(n.textContent=e),document.body.appendChild(o);const a=s.getBoundingClientRect();o.remove();const u=Ut.measureFont(t.fontStyle).descent;return{width:a.width,height:a.height+u}}class Hi{constructor(t){this._activeTextures={},this._renderer=t,this._createCanvas=t.type===yt.WEBGPU}getTexture(t){return this._buildTexturePromise(t.text,t.resolution,t.style)}getManagedTexture(t,e,i,s){if(this._activeTextures[s])return this._increaseReferenceCount(s),this._activeTextures[s].promise;const n=this._buildTexturePromise(t,e,i).then(o=>(this._activeTextures[s].texture=o,o));return this._activeTextures[s]={texture:null,promise:n,usageCount:1},n}async _buildTexturePromise(t,e,i){const s=W.get(Fo),n=Xd(t,i),o=await jd(n,i,ye.defaultTextStyle),a=Uo(t,i,o,s),u=Math.ceil(Math.ceil(Math.max(1,a.width)+i.padding*2)*e),l=Math.ceil(Math.ceil(Math.max(1,a.height)+i.padding*2)*e),c=s.image;c.width=u|0,c.height=l|0;const h=Vd(t,i,e,o,s);await Yd(c,h,Ud()&&n.length>0);let p=c;this._createCanvas&&(p=Wd(c,e));const f=lo(p,c.width,c.height,e);return this._createCanvas&&this._renderer.texture.initSource(f.source),W.return(s),f}_increaseReferenceCount(t){this._activeTextures[t].usageCount++}decreaseReferenceCount(t){const e=this._activeTextures[t];e&&(e.usageCount--,e.usageCount===0&&(e.texture?this._cleanUp(e):e.promise.then(i=>{e.texture=i,this._cleanUp(e)}).catch(()=>{}),this._activeTextures[t]=null))}_cleanUp(t){ct.returnTexture(t.texture),t.texture.source.resource=null,t.texture.source.uploadMethodId="unknown"}getReferenceCount(t){return this._activeTextures[t].usageCount}destroy(){this._activeTextures=null}}Hi.extension={type:[x.WebGLSystem,x.WebGPUSystem,x.CanvasSystem],name:"htmlText"},Hi.defaultFontOptions={fontFamily:"Arial",fontStyle:"normal",fontWeight:"normal"},U.add(Hi),U.add(Go);var T0=Object.defineProperty,qd=Object.getOwnPropertySymbols,S0=Object.prototype.hasOwnProperty,E0=Object.prototype.propertyIsEnumerable,Zd=(r,t,e)=>t in r?T0(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Qd=(r,t)=>{for(var e in t||(t={}))S0.call(t,e)&&Zd(r,e,t[e]);if(qd)for(var e of qd(t))E0.call(t,e)&&Zd(r,e,t[e]);return r};const Jd=class Ob extends Oe{constructor(...t){var e;let i=(e=t[0])!=null?e:{};i instanceof Float32Array&&(i={positions:i,uvs:t[1],indices:t[2]}),i=Qd(Qd({},Ob.defaultOptions),i);const s=i.positions||new Float32Array([0,0,1,0,1,1,0,1]),n=i.uvs||new Float32Array([0,0,1,0,1,1,0,1]),o=i.indices||new Uint32Array([0,1,2,0,2,3]),a=i.shrinkBuffersToFit,u=new bt({data:s,label:"attribute-mesh-positions",shrinkToFit:a,usage:H.VERTEX|H.COPY_DST}),l=new bt({data:n,label:"attribute-mesh-uvs",shrinkToFit:a,usage:H.VERTEX|H.COPY_DST}),c=new bt({data:o,label:"index-mesh-buffer",shrinkToFit:a,usage:H.INDEX|H.COPY_DST});super({attributes:{aPosition:{buffer:u,format:"float32x2",stride:2*4,offset:0},aUV:{buffer:l,format:"float32x2",stride:2*4,offset:0}},indexBuffer:c,topology:i.topology}),this.batchMode="auto"}get positions(){return this.attributes.aPosition.buffer.data}set positions(t){this.attributes.aPosition.buffer.data=t}get uvs(){re
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
`}},sp=ip(rp({},Xe),{vertex:ip(rp({},Xe.vertex),{header:Xe.vertex.header.replace("group(1)","group(2)")})}),Xi={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);
|
||
|
}
|
||
|
`}},np={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);
|
||
|
`}},op={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 ko,Lo;class ap extends xt{constructor(){ko!=null||(ko=Le({name:"tiling-sprite-shader",bits:[Xe,np,Ne]})),Lo!=null||(Lo=$e({name:"tiling-sprite-shader",bits:[Xi,op,He]}));const t=new nt({uMapCoord:{value:new G,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 G,type:"mat3x3<f32>"},uSizeAnchor:{value:new Float32Array([100,100,.5,.5]),type:"vec4<f32>"}});super({glProgram:Lo,gpuProgram:ko,resources:{localUniforms:new nt({uTransformMatrix:{value:new G,type:"mat3x3<f32>"},uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uRound:{value:0,type:"f32"}}),tilingUniforms:t,uTexture:P.EMPTY.source,uSampler:P.EMPTY.source.style}})}updateUniforms(t,e,i,s,n,o){const a=this.resources.tilingUniforms,u=o.width,l=o.height,c=o.textureMatrix,h=a.uniforms.uTextureTransform;h.set(i.a*u/t,i.b*u/e,i.c*l/t,i.d*l/e,i.tx/t,i.ty/e),h.invert(),a.uniforms.uMapCoord=c.mapCoord,a.uniforms.uClampFrame=c.uClampFrame,a.uniforms.uClampOffset=c.uClampOffset,a.uniforms.uTextureTransform=h,a.uniforms.uSizeAnchor[0]=t,a.uniforms.uSizeAnchor[1]=e,a.uniforms.uSizeAnchor[2]=s,a.uniforms.uSizeAnchor[3]=n,o&&(this.resources.uTexture=o.source,this.resources.uSampler=o.source.style)}}class up extends Jt{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 lp(r,t){const e=r.anchor.x,i=r.anchor.y;t[0]=-e*r.width,t[1]=-i*r.height,t[2]=(1-e)*r.width,t[3]=-i*r.height,t[4]=(1-e)*r.width,t[5]=(1-i)*r.height,t[6]=-e*r.width,t[7]=(1-i)*r.height}function cp(r,t,e,i){let s=0;const n=r.length/(t||2),o=i.a,a=i.b,u=i.c,l=i.d,c=i.tx,h=i.ty;for(e*=t;s<n;){const p=r[e],f=r[e+1];r[e]=o*p+u*f+c,r[e+1]=a*p+l*f+h,e+=t,s++}}function hp(r,t){const e=r.texture,i=e.frame.width,s=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=G.shared;a.copyFrom(r._tileTransform.matrix),a.tx/=r.width,a.ty/=r.height,a.invert(),a.scale(r.width/i,r.height/s),cp(t,2,0,a)}const zi=new up;class $o{constructor(t){this._tilingSpriteDataHash=Object.create(null),this._renderer=t}validateRenderable(t){const e=this._getTilingSpriteData(t),i=e.canBatch;this._updateCanBatch(t);const s=e.canBatch;if(s&&s===i){const{batchableMesh:n}=e;if(n.texture._source!==t.texture._source)return!n.batcher.checkAndUpdateTexture(n,t.texture)}return i!==s}addRenderable(t,e){const i=this._renderer.renderPipes.batch;this._updateCanBatch(t);const s=this._getTilingSpriteData(t),{geometry:n,canBatch:o}=s;if(o){s.batchableMesh||(s.batchableMesh=new Si);const a=s.batchableMesh;t._didTilingSpriteUpdate&&(t._didTilingSpriteUpdate=!1,this._updateBatchableMesh(t),a.geometry=n,a.mesh=t,a.texture=t._texture),a.roundPixels=this._renderer._roundPixels|t._roundPixels,i.addToBatch(a)}else i.break(e),s.shader||(s.shader=new ap),this.updateRenderable(t),e.add(t)}execute(t){const{shader:e}=this._tilingSpriteDataHash[t.uid];e.groups[0]=this._renderer.globalUniforms.bindGroup;const i=e.resources.localUniforms.uniforms;i.uTransformMatrix=t.groupTransform,i.uRound=this._renderer._roundPixels|t._roundPixels,gr(t.groupColorAlpha,i.uColor,0),this._renderer.encoder.draw({geometry:zi,shader:e,state:Bt.default2d})}updateRenderable(t){const e=this._getTilingSpriteData(t),{canBatch:i}=e;if(i){const{batchableMesh:s}=e;t._didTilingSpriteUpdate&&this._updateBatchableMesh(t),s.batcher.updateElement(s)}else if(t._didTilingSpriteUpdate){const{shader:s}=e;s.updateUniforms(t.width,t.height,t._tileTransform.matrix,t.anchor.x,t.anchor.y,t.texture)}t._didTilingSpriteUpdate=!1}destroyRenderable(t){var e;const i=this._getTilingSpriteData(t);i.batchableMesh=null,(e=i.shader)==null||e.destroy(),this._tilingSpriteDataHash[t.uid]=null}_getTilingSpriteData(t){return this._tilingSpriteDataHash[t.uid]||this._initTilingSpriteData(t)}_initTilingSpriteData(t){const e=new Jt({indices:zi.indices,positions:zi.positions.slice(),uvs:zi.uvs.slice()});return
|
||
|
${h}`)}});return await Promise.all(u),n?s[o[0].src]:s}async unload(t){const e=Rt(t,i=>({alias:[i],src:i})).map(async i=>{var s,n;const o=ft.toAbsolute(i.src),a=this.promiseCache[o];if(a){const u=await a.promise;delete this.promiseCache[o],await((n=(s=a.parser)==null?void 0:s.unload)==null?void 0:n.call(s,u,i,this))}});await Promise.all(e)}_validateParsers(){this._parsersValidated=!0,this._parserHash=this._parsers.filter(t=>t.name).reduce((t,e)=>(e.name&&t[e.name],i1(r1({},t),{[e.name]:e})),{})}}function xe(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 Ct(r,t){const e=r.split("?")[0],i=ft.extname(e).toLowerCase();return Array.isArray(t)?t.includes(i):i===t}const s1=".json",n1="application/json",Vp={extension:{type:x.LoadParser,priority:_t.Low},name:"loadJson",test(r){return xe(r,n1)||Ct(r,s1)},async load(r){return await(await z.get().fetch(r)).json()}},o1=".txt",a1="text/plain",Wp={name:"loadTxt",extension:{type:x.LoadParser,priority:_t.Low},test(r){return xe(r,a1)||Ct(r,o1)},async load(r){return await(await z.get().fetch(r)).text()}};var u1=Object.defineProperty,l1=Object.defineProperties,c1=Object.getOwnPropertyDescriptors,Yp=Object.getOwnPropertySymbols,h1=Object.prototype.hasOwnProperty,d1=Object.prototype.propertyIsEnumerable,Kp=(r,t,e)=>t in r?u1(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,p1=(r,t)=>{for(var e in t||(t={}))h1.call(t,e)&&Kp(r,e,t[e]);if(Yp)for(var e of Yp(t))d1.call(t,e)&&Kp(r,e,t[e]);return r},f1=(r,t)=>l1(r,c1(t));const m1=["normal","bold","100","200","300","400","500","600","700","800","900"],g1=[".ttf",".otf",".woff",".woff2"],_1=["font/ttf","font/otf","font/woff","font/woff2"],b1=/^(--|-?[A-Z_])[0-9A-Z_-]*$/i;function qp(r){const t=ft.extname(r),e=ft.basename(r,t).replace(/(-|_)/g," ").toLowerCase().split(" ").map(n=>n.charAt(0).toUpperCase()+n.slice(1));let i=e.length>0;for(const n of e)if(!n.match(b1)){i=!1;break}let s=e.join(" ");return i||(s=`"${s.replace(/[\\"]/g,"\\$&")}"`),s}const v1=/^[0-9A-Za-z%:/?#\[\]@!\$&'()\*\+,;=\-._~]*$/;function y1(r){return v1.test(r)?r:encodeURI(r)}const Zp={extension:{type:x.LoadParser,priority:_t.Low},name:"loadWebFont",test(r){return xe(r,_1)||Ct(r,g1)},async load(r,t){var e,i,s,n,o,a;const u=z.get().getFontFaceSet();if(u){const l=[],c=(i=(e=t.data)==null?void 0:e.family)!=null?i:qp(r),h=(o=(n=(s=t.data)==null?void 0:s.weights)==null?void 0:n.filter(f=>m1.includes(f)))!=null?o:["normal"],p=(a=t.data)!=null?a:{};for(let f=0;f<h.length;f++){const m=h[f],_=new FontFace(c,`url(${y1(r)})`,f1(p1({},p),{weight:m}));await _.load(),u.add(_),l.push(_)}return q.set(`${c}-and-url`,{url:r,fontFaces:l}),l.length===1?l[0]:l}return null},unload(r){(Array.isArray(r)?r:[r]).forEach(t=>{q.remove(t.family),z.get().getFontFaceSet().delete(t)})}};function Wi(r,t=1){var e;const i=(e=qt.RETINA_PREFIX)==null?void 0:e.exec(r);return i?parseFloat(i[1]):t}function ee(r,t,e){r.label=e,r._sourceOrigin=e;const i=new P({source:r,label:e}),s=()=>{delete t.promiseCache[e],q.has(e)&&q.remove(e)};return i.source.once("destroy",()=>{t.promiseCache[e]&&s()}),i.once("destroy",()=>{r.destroyed||s()}),i}var x1=Object.defineProperty,Yi=Object.getOwnPropertySymbols,Qp=Object.prototype.hasOwnProperty,Jp=Object.prototype.propertyIsEnumerable,tf=(r,t,e)=>t in r?x1(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,T1=(r,t)=>{for(var e in t||(t={}))Qp.call(t,e)&&tf(r,e,t[e]);if(Yi)for(var e of Yi(t))Jp.call(t,e)&&tf(r,e,t[e]);return r},S1=(r,t)=>{var e={};for(var i in r)Qp.call(r,i)&&t.indexOf(i)<0&&(e[i]=r[i]);if(r!=null&&Yi)for(var i of Yi(r))t.indexOf(i)<0&&Jp.call(r,i)&&(e[i]=r[i]);return e};const E1=".svg",A1="image/svg+xml",ef={extension:{type:x.LoadParser,priority:_t.Low},name:"loadSVG",config:{crossOrigin:"anonymous",parseAsGraphicsContext:!1},test(r){return xe(r,A1)||Ct(r,E1)},async load(r,t,e){var i;return((i=t.data.parseAsGraphicsContext)!=null?i:this.config.parseAsGraphicsContext)?w1(r):P1(r,t,e,this.config.crossOrigin)},unload(r){r.destroy(!0)}};async function P1(r,t,e,i){v
|
||
|
`;let ze=null,Qo=class{constructor(){ze||(ze=URL.createObjectURL(new Blob([R1],{type:"application/javascript"}))),this.worker=new Worker(ze)}};Qo.revokeObjectURL=function(){ze&&(URL.revokeObjectURL(ze),ze=null)};const M1='(function(){"use strict";async function e(t){const a=await fetch(t);if(!a.ok)throw new Error(`[WorkerManager.loadImageBitmap] Failed to fetch ${t}: ${a.status} ${a.statusText}`);const s=await a.blob();return await createImageBitmap(s)}self.onmessage=async t=>{try{const a=await e(t.data.data[0]);self.postMessage({data:a,uuid:t.data.uuid,id:t.data.id},[a])}catch(a){self.postMessage({error:a,uuid:t.data.uuid,id:t.data.id})}}})();\n';let je=null,rf=class{constructor(){je||(je=URL.createObjectURL(new Blob([M1],{type:"application/javascript"}))),this.worker=new Worker(je)}};rf.revokeObjectURL=function(){je&&(URL.revokeObjectURL(je),je=null)};let sf=0,Jo,C1=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 Qo;e.addEventListener("message",i=>{e.terminate(),Qo.revokeObjectURL(),t(i.data)})}),this._isImageBitmapSupported)}loadImageBitmap(t){return this._run("loadImageBitmap",[t])}async _initWorkers(){this._initialized||(this._initialized=!0)}_getWorker(){Jo===void 0&&(Jo=navigator.hardwareConcurrency||4);let t=this._workerPool.pop();return!t&&this._createdWorkers<Jo&&(this._createdWorkers++,t=new rf().worker,t.addEventListener("message",e=>{this._complete(e.data),this._returnWorker(e.target),this._next()})),t}_returnWorker(t){this._workerPool.push(t)}_complete(t){t.error!==void 0?this._resolveHash[t.uuid].reject(t.error):this._resolveHash[t.uuid].resolve(t.data),this._resolveHash[t.uuid]=null}async _run(t,e){await this._initWorkers();const i=new Promise((s,n)=>{this._queue.push({id:t,arguments:e,resolve:s,reject:n})});return this._next(),i}_next(){if(!this._queue.length)return;const t=this._getWorker();if(!t)return;const e=this._queue.pop(),i=e.id;this._resolveHash[sf]={resolve:e.resolve,reject:e.reject},t.postMessage({data:e.arguments,uuid:sf++,id:i})}};const ta=new C1;var O1=Object.defineProperty,nf=Object.getOwnPropertySymbols,G1=Object.prototype.hasOwnProperty,B1=Object.prototype.propertyIsEnumerable,of=(r,t,e)=>t in r?O1(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,I1=(r,t)=>{for(var e in t||(t={}))G1.call(t,e)&&of(r,e,t[e]);if(nf)for(var e of nf(t))B1.call(t,e)&&of(r,e,t[e]);return r};const F1=[".jpeg",".jpg",".png",".webp",".avif"],D1=["image/jpeg","image/png","image/webp","image/avif"];async function af(r){const t=await z.get().fetch(r);if(!t.ok)throw new Error(`[loadImageBitmap] Failed to fetch ${r}: ${t.status} ${t.statusText}`);const e=await t.blob();return await createImageBitmap(e)}const ea={name:"loadTextures",extension:{type:x.LoadParser,priority:_t.High},config:{preferWorkers:!0,preferCreateImageBitmap:!0,crossOrigin:"anonymous"},test(r){return xe(r,D1)||Ct(r,F1)},async load(r,t,e){var i;let s=null;globalThis.createImageBitmap&&this.config.preferCreateImageBitmap?this.config.preferWorkers&&await ta.isImageBitmapSupported()?s=await ta.loadImageBitmap(r):s=await af(r):s=await new Promise(o=>{s=new Image,s.crossOrigin=this.config.crossOrigin,s.src=r,s.complete?o(s):s.onload=()=>{o(s)}});const n=new pe(I1({resource:s,alphaMode:"premultiply-alpha-on-upload",resolution:((i=t.data)==null?void 0:i.resolution)||Wi(r)},t.data));return ee(n,e,r)},unload(r){r.destroy(!0)}};var U1=Object.defineProperty,k1=Object.defineProperties,L1=Object.getOwnPropertyDescriptors,uf=Object.getOwnPropertySymbols,$1=Object.prototype.hasOwnProperty,N1=Object.prototype.propertyIsEnumerable,lf=(r,t,e)=>t in r?U1(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,ra=(r,t)=>{for(var e in t||(t={}))$1.call(t,e)&&lf(r,e,t[e]);if(uf)for(var e of uf(t))N1.call(t,e)&&lf(r,e,t[e]);return r},cf=(r,t)=>k1(r,L1(t));const hf=[".mp4",".m4v",".webm",".ogg",".ogv",".h264",".avi",".m
|
||
|
bitCount = ${t}, rBitMask = ${e}, gBitMask = ${i}, aBitMask = ${n}`)}const iT={extension:{type:x.LoadParser,priority:_t.High},name:"loadDDS",test(r){return Ct(r,[".dds"])},async load(r,t,e){const i=await Br(),s=await(await fetch(r)).arrayBuffer(),n=Pf(s,i),o=new Gr(n);return ee(o,e,r)},unload(r){Array.isArray(r)?r.forEach(t=>t.destroy(!0)):r.destroy(!0)}};var wf=(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_6x6_KHR=37844]="COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR",r[r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR=37845]="COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR",r[r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR=37846]="COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR",r[r.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR=37847]="COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR",r[r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR=37848]="COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR",r[r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR=37849]="COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR",r[r.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_
|
||
|
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);
|
||
|
|
||
|
{MAIN}
|
||
|
}
|
||
|
`,Hf=`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();
|
||
|
}
|
||
|
`,Xf=`
|
||
|
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 out = vec4<f32>(0.0,0.0,0.0,0.0);
|
||
|
|
||
|
{MAIN}
|
||
|
|
||
|
return out;
|
||
|
}`,MT=Object.defineProperty,zf=Object.getOwnPropertySymbols,CT=Object.prototype.hasOwnProperty,OT=Object.prototype.propertyIsEnumerable,jf=(r,t,e)=>t in r?MT(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Vf=(r,t)=>{for(var e in t||(t={}))CT.call(t,e)&&jf(r,e,t[e]);if(zf)for(var e of zf(t))OT.call(t,e)&&jf(r,e,t[e]);return r};class GT extends Kt{constructor(t){const e=t.gpu,i=Wf(Vf({source:Xf},e)),s=vt.from({vertex:{source:i,entryPoint:"mainVertex"},fragment:{source:i,entryPoint:"mainFragment"}}),n=t.gl,o=Wf(Vf({source:Nf},n)),a=Mt.from({vertex:Hf,fragment:o}),u=new nt({uBlend:{value:1,type:"f32"}});super({gpuProgram:s,glProgram:a,blendRequired:!0,resources:{blendUniforms:u,uBackTexture:P.EMPTY}})}}function Wf(r){const{source:t,functions:e,main:i}=r;return t.replace("{FUNCTIONS}",e).replace("{MAIN}",i)}const BT=`
|
||
|
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;
|
||
|
}
|
||
|
`,IT=`
|
||
|
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 is=`in vec2 aPosition;
|
||
|
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();
|
||
|
}
|
||
|
`,Yf=`
|
||
|
in vec2 vTextureCoord;
|
||
|
|
||
|
out vec4 finalColor;
|
||
|
|
||
|
uniform float uAlpha;
|
||
|
uniform sampler2D uTexture;
|
||
|
|
||
|
void main()
|
||
|
{
|
||
|
finalColor = texture(uTexture, vTextureCoord) * uAlpha;
|
||
|
}
|
||
|
`,da=`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;
|
||
|
}`,FT=Object.defineProperty,DT=Object.defineProperties,UT=Object.getOwnPropertyDescriptors,ss=Object.getOwnPropertySymbols,Kf=Object.prototype.hasOwnProperty,qf=Object.prototype.propertyIsEnumerable,Zf=(r,t,e)=>t in r?FT(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,pa=(r,t)=>{for(var e in t||(t={}))Kf.call(t,e)&&Zf(r,e,t[e]);if(ss)for(var e of ss(t))qf.call(t,e)&&Zf(r,e,t[e]);return r},kT=(r,t)=>DT(r,UT(t)),LT=(r,t)=>{var e={};for(var i in r)Kf.call(r,i)&&t.indexOf(i)<0&&(e[i]=r[i]);if(r!=null&&ss)for(var i of ss(r))t.indexOf(i)<0&&qf.call(r,i)&&(e[i]=r[i]);return e};const Qf=class Fb extends Kt{constructor(t){t=pa(pa({},Fb.defaultOptions),t);const e=vt.from({vertex:{source:da,entryPoint:"mainVertex"},fragment:{source:da,entryPoint:"mainFragment"}}),i=Mt.from({vertex:is,fragment:Yf,name:"alpha-filter"}),s=t,{alpha:n}=s,o=LT(s,["alpha"]),a=new nt({uAlpha:{value:n,type:"f32"}});super(kT(pa({},o),{gpuProgram:e,glProgram:i,resources:{alphaUniforms:a}}))}get alpha(){return this.resources.alphaUniforms.uniforms.uAlpha}set alpha(t){this.resources.alphaUniforms.uniforms.uAlpha=t}};Qf.defaultOptions={alpha:1};let $T=Qf;const fa={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]},NT=["in vec2 vBlurTexCoords[%size%];","uniform sampler2D uTexture;","out vec4 finalColor;","void main(void)","{"," finalColor = vec4(0.0);"," %blur%","}"].join(`
|
||
|
`);function Jf(r){const t=fa[r],e=t.length;let i=NT,s="";const n="finalColor += texture(uTexture, vBlurTexCoords[%index%]) * %value%;";let o;for(let a=0;a<r;a++){let u=n.replace("%index%",a.toString());o=a,a>=e&&(o=r-a-1),u=u.replace("%value%",t[o].toString()),s+=u,s+=`
|
||
|
`}return i=i.replace("%blur%",s),i=i.replace("%size%",r.toString()),i}const HT=`
|
||
|
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 tm(r,t){const e=Math.ceil(r/2);let i=HT,s="",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`),s+=a,s+=`
|
||
|
`}return i=i.replace("%blur%",s),i=i.replace("%size%",r.toString()),i=i.replace("%dimension%",t?"z":"w"),i}function em(r,t){const e=tm(t,r),i=Jf(t);return Mt.from({vertex:e,fragment:i,name:`blur-${r?"horizontal":"vertical"}-pass-filter`})}var rm=`
|
||
|
|
||
|
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 strength = gfu.uInputSize.w * 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 im(r,t){const e=fa[t],i=e.length,s=[],n=[],o=[];for(let h=0;h<t;h++){s[h]=`@location(${h}) offset${h}: vec2<f32>,`,r?n[h]=`filteredCord + vec2(${h-i+1} * strength, 0.0),`:n[h]=`filteredCord + vec2(0.0, ${h-i+1} * strength),`;const p=h<i?h:t-h-1,f=e[p].toString();o[h]=`finalColor += textureSample(uTexture, uSampler, offset${h}) * ${f};`}const a=s.join(`
|
||
|
`),u=n.join(`
|
||
|
`),l=o.join(`
|
||
|
`),c=rm.replace("%blur-struct%",a).replace("%blur-vertex-out%",u).replace("%blur-fragment-in%",a).replace("%blur-sampling%",l);return vt.from({vertex:{source:c,entryPoint:"mainVertex"},fragment:{source:c,entryPoint:"mainFragment"}})}var XT=Object.defineProperty,sm=Object.getOwnPropertySymbols,zT=Object.prototype.hasOwnProperty,jT=Object.prototype.propertyIsEnumerable,nm=(r,t,e)=>t in r?XT(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,ma=(r,t)=>{for(var e in t||(t={}))zT.call(t,e)&&nm(r,e,t[e]);if(sm)for(var e of sm(t))jT.call(t,e)&&nm(r,e,t[e]);return r};const om=class Db extends Kt{constructor(t){t=ma(ma({},Db.defaultOptions),t);const e=em(t.horizontal,t.kernelSize),i=im(t.horizontal,t.kernelSize);super(ma({glProgram:e,gpuProgram:i,resources:{blurUniforms:{uStrength:{value:0,type:"f32"}}}},t)),this.horizontal=t.horizontal,this._quality=0,this.quality=t.quality,this.blur=t.strength,this._uniforms=this.resources.blurUniforms.uniforms}apply(t,e,i,s){if(this._uniforms.uStrength=this.strength/this.passes,this.passes===1)t.applyFilter(this,e,i,s);else{const n=ct.getSameSizeTexture(e);let o=e,a=n;this._state.blend=!1;for(let u=0;u<this.passes-1;u++){t.applyFilter(this,o,a,t.renderer.type===yt.WEBGPU);const l=a;a=o,o=l}this._state.blend=!0,t.applyFilter(this,o,i,s),ct.returnTexture(n)}}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}};om.defaultOptions={strength:8,quality:4,kernelSize:5};let ns=om;var VT=Object.defineProperty,WT=Object.defineProperties,YT=Object.getOwnPropertyDescriptors,os=Object.getOwnPropertySymbols,am=Object.prototype.hasOwnProperty,um=Object.prototype.propertyIsEnumerable,lm=(r,t,e)=>t in r?VT(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Dr=(r,t)=>{for(var e in t||(t={}))am.call(t,e)&&lm(r,e,t[e]);if(os)for(var e of os(t))um.call(t,e)&&lm(r,e,t[e]);return r},KT=(r,t)=>WT(r,YT(t)),qT=(r,t)=>{var e={};for(var i in r)am.call(r,i)&&t.indexOf(i)<0&&(e[i]=r[i]);if(r!=null&&os)for(var i of os(r))t.indexOf(i)<0&&um.call(r,i)&&(e[i]=r[i]);return e};class cm extends Kt{constructor(...t){var e;let i=(e=t[0])!=null?e:{};typeof i=="number"&&(i={strength:i},t[1]&&(i.quality=t[1]),t[2]&&(i.resolution=t[2]),t[3]&&(i.kernelSize=t[3])),i=Dr(Dr({},ns.defaultOptions),i);const s=i,{strength:n,quality:o}=s,a=qT(s,["strength","quality"]);super(KT(Dr({},a),{compatibleRenderers:yt.BOTH,resources:{}})),this._repeatEdgePixels=!1,this.blurXFilter=new ns(Dr({horizontal:!1},i)),this.blurYFilter=new ns(Dr({horizontal:!0},i)),this.quality=o,this.blur=n,this.repeatEdgePixels=!1}apply(t,e,i,s){const n=Math.abs(this.blurXFilter.strength),o=Math.abs(this.blurYFilter.strength);if(n&&o){const a=ct.getSameSizeTexture(e);this.blurXFilter.apply(t,e,a,!0),this.blurYFilter.apply(t,a,i,s),ct.returnTexture(a)}else o?this.blurYFilter.apply(t,e,i,s):this.blurXFilter.apply(t,e,i,s)}updatePadding(){this._repeatEdgePixels?this.padding=0:this.padding=Math.max(Math.abs(this.blurXFilter.blur),Math.abs(this.blurYFilter.blur))*2}get blur(){return this.blurXFilter.blur}set blur(t){this.blurXFilter.blur=this.blurYFilter.blur=t,this.updatePadding()}get quality(){return this.blurXFilter.quality}set quality(t){this.blurXFilter.quality=this.blurYFilter.quality=t}get blurX(){return this.blurXFilter.blur}set blurX(t){this.blurXFilter.blur=t,this.updatePadding()}get blurY(){return this.blurYFilter.blur}set blurY(t){this.blurYFilter.blur=t,this.updatePadding()}get blendMode(){return this.blurYFilter.blendMode}set blendMode(t){this.blurYFilter.blendMode=t}get repeatEdgePixels(){return this._repeatEdgePixels}set repeatEdgePixels(t){this._repeatEdgePixels=t,this.updatePadding()}}cm.defaultOptions={strength:8,quality:4,kernelSize:5};var hm=`
|
||
|
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);
|
||
|
}
|
||
|
`,ga=`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);
|
||
|
}`,ZT=Object.defineProperty,QT=Object.defineProperties,JT=Object.getOwnPropertyDescriptors,dm=Object.getOwnPropertySymbols,tS=Object.prototype.hasOwnProperty,eS=Object.prototype.propertyIsEnumerable,pm=(r,t,e)=>t in r?ZT(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,rS=(r,t)=>{for(var e in t||(t={}))tS.call(t,e)&&pm(r,e,t[e]);if(dm)for(var e of dm(t))eS.call(t,e)&&pm(r,e,t[e]);return r},iS=(r,t)=>QT(r,JT(t));class sS extends Kt{constructor(t={}){const e=new nt({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"}}),i=vt.from({vertex:{source:ga,entryPoint:"mainVertex"},fragment:{source:ga,entryPoint:"mainFragment"}}),s=Mt.from({vertex:is,fragment:hm,name:"color-matrix-filter"});super(iS(rS({},t),{gpuProgram:i,glProgram:s,resources:{colorMatrixUniforms:e}})),this.alpha=1}_loadMatrix(t,e=!1){let i=t;e&&(this._multiply(i,this.matrix,t),i=this._colorMatrix(i)),this.resources.colorMatrixUniforms.uniforms.uColorMatrix=i,this.resources.colorMatrixUniforms.update()}_multiply(t,e,i){return t[0]=e[0]*i[0]+e[1]*i[5]+e[2]*i[10]+e[3]*i[15],t[1]=e[0]*i[1]+e[1]*i[6]+e[2]*i[11]+e[3]*i[16],t[2]=e[0]*i[2]+e[1]*i[7]+e[2]*i[12]+e[3]*i[17],t[3]=e[0]*i[3]+e[1]*i[8]+e[2]*i[13]+e[3]*i[18],t[4]=e[0]*i[4]+e[1]*i[9]+e[2]*i[14]+e[3]*i[19]+e[4],t[5]=e[5]*i[0]+e[6]*i[5]+e[7]*i[10]+e[8]*i[15],t[6]=e[5]*i[1]+e[6]*i[6]+e[7]*i[11]+e[8]*i[16],t[7]=e[5]*i[2]+e[6]*i[7]+e[7]*i[12]+e[8]*i[17],t[8]=e[5]*i[3]+e[6]*i[8]+e[7]*i[13]+e[8]*i[18],t[9]=e[5]*i[4]+e[6]*i[9]+e[7]*i[14]+e[8]*i[19]+e[9],t[10]=e[10]*i[0]+e[11]*i[5]+e[12]*i[10]+e[13]*i[15],t[11]=e[10]*i[1]+e[11]*i[6]+e[12]*i[11]+e[13]*i[16],t[12]=e[10]*i[2]+e[11]*i[7]+e[12]*i[12]+e[13]*i[17],t[13]=e[10]*i[3]+e[11]*i[8]+e[12]*i[13]+e[13]*i[18],t[14]=e[10]*i[4]+e[11]*i[9]+e[12]*i[14]+e[13]*i[19]+e[14],t[15]=e[15]*i[0]+e[16]*i[5]+e[17]*i[10]+e[18]*i[15],t[16]=e[15]*i[1]+e[16]*i[6]+e[17]*i[11]+e[18]*i[16],t[17]=e[15]*i[2]+e[16]*i[7]+e[17]*i[12]+e[18]*i[17],t[18]=e[15]*i[3]+e[16]*i[8]+e[17]*i[13]+e[18]*i[18],t[19]=e[15]*i[4]+e[16]*i[9]+e[17]*i[14]+e[18]*i[19]+e[19],t}_colorMatrix(t){const e=new Float32Array(t);return e[4]/=255,e[9]/=255,e[14]/=255,e[19]/=255,e}brightness(t,e){const i=[t,0,0,0,0,0,t,0,0,0,0,0,t,0,0,0,0,0,1,0];this._loadMatrix(i,e)}tint(t,e){const[i,s,n]=K.shared.setValue(t).toArray(),o=[i,0,0,0,0,0,s,0,0,0,0,0,n,0,0,0,0,0,1,0];this._loadMatrix(o,e)}greyscale(t,e){const i=[t,t,t,0,0,t,t,t,0,0,t,t,t,0,0,0,0,0,1,0];this._loadMatrix(i,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 i=Math.cos(t),s=Math.sin(t),n=Math.sqrt,o=1/3,a=n(o),u=i+(1-i)*o,l=o*(1-i)-a*s,c=o*(1-i)+a*s,h=o*(1-i)+a*s,p=i+o*(1-i),f=o*(1-i)-a*s,m=o*(1-i)-a*s,_=o*(1-i)+a*s,g=i+o*(1-i),b=[u,l,c,0,0,h,p,f,0,0,m,_,g,0,0,0,0,0,1,0];this._loadMatrix(b,e)}contrast(t,e){const i=(t||0)+1,s=-.5*(i-1),n=[i,0,0,0,s,0,i,0,0,s,0,0,i,0,s,0,0,0,1,0];this._loadMatrix(n,e)}saturate(t=0,e){const i=t*2/3+1,s=(i-1)*-.5,n=[i,s,s,0,0,s,i,s,0,0,s,s,i,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,11.793603434377337,-.3087833385928097,1.7658908555458428,-.10601743074722245,0,-70.35205161461398,-.231103377548616,-.7501899197440212,1.847597816108189,0,30.950940869491138,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,63.72958762196502,-.16404339962244616,1.0835251566291304,-.05498805115633132,0,24.732407896706203,-.16786010706155763,-.5603416277695248,1.6014850761964943,0,35.62982
|
||
|
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));
|
||
|
}
|
||
|
`,mm=`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();
|
||
|
}
|
||
|
`,_a=`
|
||
|
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));
|
||
|
}`,nS=Object.defineProperty,oS=Object.defineProperties,aS=Object.getOwnPropertyDescriptors,as=Object.getOwnPropertySymbols,gm=Object.prototype.hasOwnProperty,_m=Object.prototype.propertyIsEnumerable,bm=(r,t,e)=>t in r?nS(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,uS=(r,t)=>{for(var e in t||(t={}))gm.call(t,e)&&bm(r,e,t[e]);if(as)for(var e of as(t))_m.call(t,e)&&bm(r,e,t[e]);return r},lS=(r,t)=>oS(r,aS(t)),cS=(r,t)=>{var e={};for(var i in r)gm.call(r,i)&&t.indexOf(i)<0&&(e[i]=r[i]);if(r!=null&&as)for(var i of as(r))t.indexOf(i)<0&&_m.call(r,i)&&(e[i]=r[i]);return e};class hS extends Kt{constructor(...t){let e=t[0];e instanceof Gt&&(e={sprite:e,scale:t[1]});const i=e,{sprite:s,scale:n}=i,o=cS(i,["sprite","scale"]);let a=n!=null?n:20;typeof a=="number"&&(a=new V(a,a));const u=new nt({uFilterMatrix:{value:new G,type:"mat3x3<f32>"},uScale:{value:a,type:"vec2<f32>"},uRotation:{value:new Float32Array([0,0,0,0]),type:"mat2x2<f32>"}}),l=Mt.from({vertex:mm,fragment:fm,name:"displacement-filter"}),c=vt.from({vertex:{source:_a,entryPoint:"mainVertex"},fragment:{source:_a,entryPoint:"mainFragment"}}),h=s.texture.source;super(lS(uS({},o),{gpuProgram:c,glProgram:l,resources:{filterUniforms:u,uMapTexture:h,uMapSampler:h.style}})),this._sprite=e.sprite,this._sprite.renderable=!1}apply(t,e,i,s){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),u=Math.sqrt(o.c*o.c+o.d*o.d);a!==0&&u!==0&&(n.uRotation[0]=o.a/a,n.uRotation[1]=o.b/a,n.uRotation[2]=o.c/u,n.uRotation[3]=o.d/u),this.resources.uMapTexture=this._sprite.texture.source,t.applyFilter(this,e,i,s)}get scale(){return this.resources.filterUniforms.uniforms.uScale}}var vm=`
|
||
|
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;
|
||
|
}
|
||
|
`,ba=`
|
||
|
|
||
|
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;
|
||
|
}`,dS=Object.defineProperty,pS=Object.defineProperties,fS=Object.getOwnPropertyDescriptors,us=Object.getOwnPropertySymbols,ym=Object.prototype.hasOwnProperty,xm=Object.prototype.propertyIsEnumerable,Tm=(r,t,e)=>t in r?dS(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,va=(r,t)=>{for(var e in t||(t={}))ym.call(t,e)&&Tm(r,e,t[e]);if(us)for(var e of us(t))xm.call(t,e)&&Tm(r,e,t[e]);return r},mS=(r,t)=>pS(r,fS(t)),gS=(r,t)=>{var e={};for(var i in r)ym.call(r,i)&&t.indexOf(i)<0&&(e[i]=r[i]);if(r!=null&&us)for(var i of us(r))t.indexOf(i)<0&&xm.call(r,i)&&(e[i]=r[i]);return e};const Sm=class Ub extends Kt{constructor(t={}){t=va(va({},Ub.defaultOptions),t);const e=vt.from({vertex:{source:ba,entryPoint:"mainVertex"},fragment:{source:ba,entryPoint:"mainFragment"}}),i=Mt.from({vertex:is,fragment:vm,name:"noise-filter"}),s=t,{noise:n,seed:o}=s,a=gS(s,["noise","seed"]);super(mS(va({},a),{gpuProgram:e,glProgram:i,resources:{noiseUniforms:new nt({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}};Sm.defaultOptions={noise:.5};let _S=Sm;var Em=`in vec2 vMaskCoord;
|
||
|
in vec2 vTextureCoord;
|
||
|
|
||
|
uniform sampler2D uTexture;
|
||
|
uniform sampler2D uMaskTexture;
|
||
|
|
||
|
uniform float uAlpha;
|
||
|
uniform vec4 uMaskClamp;
|
||
|
|
||
|
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 alphaMul = 1.0 - npmAlpha * (1.0 - masky.a);
|
||
|
|
||
|
original *= (alphaMul * masky.r * uAlpha * clip);
|
||
|
|
||
|
finalColor = original;
|
||
|
}
|
||
|
`,Am=`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);
|
||
|
}
|
||
|
`,ya=`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,
|
||
|
};
|
||
|
|
||
|
|
||
|
@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 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 npmAlpha = 0.0;
|
||
|
|
||
|
var alphaMul = 1.0 - npmAlpha * (1.0 - mask.a);
|
||
|
|
||
|
var a = (alphaMul * mask.r) * clip;
|
||
|
|
||
|
return vec4(source.rgb, source.a) * a;
|
||
|
}`,bS=Object.defineProperty,vS=Object.defineProperties,yS=Object.getOwnPropertyDescriptors,ls=Object.getOwnPropertySymbols,Pm=Object.prototype.hasOwnProperty,wm=Object.prototype.propertyIsEnumerable,Rm=(r,t,e)=>t in r?bS(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,xS=(r,t)=>{for(var e in t||(t={}))Pm.call(t,e)&&Rm(r,e,t[e]);if(ls)for(var e of ls(t))wm.call(t,e)&&Rm(r,e,t[e]);return r},TS=(r,t)=>vS(r,yS(t)),SS=(r,t)=>{var e={};for(var i in r)Pm.call(r,i)&&t.indexOf(i)<0&&(e[i]=r[i]);if(r!=null&&ls)for(var i of ls(r))t.indexOf(i)<0&&wm.call(r,i)&&(e[i]=r[i]);return e};class Mm extends Kt{constructor(t){const e=t,{sprite:i}=e,s=SS(e,["sprite"]),n=new ln(i.texture),o=new nt({uFilterMatrix:{value:new G,type:"mat3x3<f32>"},uMaskClamp:{value:n.uClampFrame,type:"vec4<f32>"},uAlpha:{value:1,type:"f32"}}),a=vt.from({vertex:{source:ya,entryPoint:"mainVertex"},fragment:{source:ya,entryPoint:"mainFragment"}}),u=Mt.from({vertex:Am,fragment:Em,name:"mask-filter"});super(TS(xS({},s),{gpuProgram:a,glProgram:u,resources:{filterUniforms:o,uMaskTexture:i.texture.source}})),this.sprite=i,this._textureMatrix=n}apply(t,e,i,s){this._textureMatrix.texture=this.sprite.texture,t.calculateSpriteMatrix(this.resources.filterUniforms.uniforms.uFilterMatrix,this.sprite).prepend(this._textureMatrix.mapCoord),this.resources.uMaskTexture=this.sprite.texture.source,t.applyFilter(this,e,i,s)}}var ES=`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;
|
||
|
}`;function xa(r,t,e,i,s,n,o,a){const u=o-e,l=a-i,c=s-e,h=n-i,p=r-e,f=t-i,m=u*u+l*l,_=u*c+l*h,g=u*p+l*f,b=c*c+h*h,v=c*p+h*f,y=1/(m*b-_*_),T=(b*g-_*v)*y,E=(m*v-_*g)*y;return T>=0&&E>=0&&T+E<1}class Ta{constructor(t=0,e=0,i=0,s=0,n=0,o=0){this.type="triangle",this.x=t,this.y=e,this.x2=i,this.y2=s,this.x3=n,this.y3=o}contains(t,e){const i=(this.x-this.x3)*(e-this.y3)-(this.y-this.y3)*(t-this.x3),s=(this.x2-this.x)*(e-this.y)-(this.y2-this.y)*(t-this.x);if(i<0!=s<0&&i!==0&&s!==0)return!1;const n=(this.x3-this.x2)*(e-this.y2)-(this.y3-this.y2)*(t-this.x2);return n===0||n<0==i+s<=0}strokeContains(t,e,i){const s=i/2,n=s*s,{x:o,x2:a,x3:u,y:l,y2:c,y3:h}=this;return br(t,e,o,l,a,h)<=n||br(t,e,a,c,u,h)<=n||br(t,e,u,h,o,l)<=n}clone(){return new Ta(this.x,this.y,this.x2,this.y2,this.x3,this.y3)}copyFrom(t){return this.x=t.x,this.y=t.y,this.x2=t.x2,this.y2=t.y2,this.x3=t.x3,this.y3=t.y3,this}copyTo(t){return t.copyFrom(this),t}getBounds(t){t=t||new j;const e=Math.min(this.x,this.x2,this.x3),i=Math.max(this.x,this.x2,this.x3),s=Math.min(this.y,this.y2,this.y3),n=Math.max(this.y,this.y2,this.y3);return t.x=e,t.y=s,t.width=i-e,t.height=n-s,t}}const Cm=class kb{constructor(t){this._tick=()=>{this.timeout=setTimeout(this._processQueue,0)},this._processQueue=()=>{const{queue:e}=this;let i=0;for(;e.length&&i<kb.uploadsPerFrame;){const s=e.shift();this.uploadQueueItem(s),i++}e.length?ht.system.addOnce(this._tick,this,Vt.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 i of e)i instanceof Y?this._addContainer(i):this.resolveQueueItem(i,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(),ht.system.addOnce(this._tick,this,Vt.UTILITY)):e()})}dedupeQueue(){const t=Object.create(null);let e=0;for(let i=0;i<this.queue.length;i++){const s=this.queue[i];t[s.uid]||(t[s.uid]=!0,this.queue[e++]=s)}this.queue.length=e}_resolve(){const{resolves:t}=this,e=t.slice(0);t.length=0;for(const i of e)i()}};Cm.uploadsPerFrame=4;let Om=Cm;var AS=Object.defineProperty,cs=Object.getOwnPropertySymbols,Gm=Object.prototype.hasOwnProperty,Bm=Object.prototype.propertyIsEnumerable,Im=(r,t,e)=>t in r?AS(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,PS=(r,t)=>{for(var e in t||(t={}))Gm.call(t,e)&&Im(r,e,t[e]);if(cs)for(var e of cs(t))Bm.call(t,e)&&Im(r,e,t[e]);return r},wS=(r,t)=>{var e={};for(var i in r)Gm.call(r,i)&&t.indexOf(i)<0&&(e[i]=r[i]);if(r!=null&&cs)for(var i of cs(r))t.indexOf(i)<0&&Bm.call(r,i)&&(e[i]=r[i]);return e};class Ur extends Y{constructor(...t){var e;let i=t[0];i instanceof Oe&&(i={geometry:i,shader:t[1]},t[3]&&(i.geometry.topology=t[3]));const s=i,{geometry:n,shader:o,texture:a,roundPixels:u,state:l}=s,c=wS(s,["geometry","shader","texture","roundPixels","state"]);super(PS({label:"Mesh"},c)),this.renderPipeId="mesh",this.canBundle=!0,this._roundPixels=0,this.allowChildren=!1,this.shader=o,this.texture=(e=a!=null?a:o==null?void 0:o.texture)!=null?e:P.WHITE,this.state=l!=null?l:Bt.for2d(),this._geometry=n,this._geometry.on("update",this.onViewUpdate,this),this.roundPixels=u!=null?u:!1}get roundPixels(){return!!this._roundPixels}set roundPixels(t){this._roundPixels=t?1:0}get material(){return this._shader}set shader(t){this._shader!==t&&(this._shader=t,this.onViewUpdate())}get shader(){return this._shader}set geometry(t){var e;this._geometry!==t&&((e=this._geometry)==null||e.off("update",this.onViewUpdate,this),t.on("update",this.onViewUpdate,this),this._geometry=t,this.onViewUpdate())}get geometry(){return this._geometry}set texture(t){t||(t=P.EMPTY);const e=this._texture;e!==t&&(e&&e.dynamic&&e.off("update",this.onViewUpdate,this),t.dynamic&&t.on("update",this.onViewUpdate,this),this.shader&&(this.shader.texture=t),this._texture=t,this.onViewUpdate())}get texture(){return this._texture}get batched(){return this._shader?!1:this._geometry instanceof Jt?this.
|
||
|
`)}const Km={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);
|
||
|
`}},qm={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);
|
||
|
`}};function Zm(r,t){const e=r.root,i=r.instructionSet;i.reset(),t.batch.buildStart(i),t.blendMode.buildStart(),t.colorMask.buildStart(),e.sortableChildren&&e.sortChildren(),Qm(e,i,t,!0),t.batch.buildEnd(i),t.blendMode.buildEnd(i)}function $r(r,t,e){r.globalDisplayStatus<7||!r.includeInBuild||(r.sortableChildren&&r.sortChildren(),r.isSimple?DS(r,t,e):Qm(r,t,e,!1))}function DS(r,t,e){if(r.renderPipeId&&(e.blendMode.setBlendMode(r,r.groupBlendMode,t),r.didViewUpdate=!1,e[r.renderPipeId].addRenderable(r,t)),!r.renderGroup){const i=r.children,s=i.length;for(let n=0;n<s;n++)$r(i[n],t,e)}}function Qm(r,t,e,i){if(!i&&r.renderGroup)e.renderGroup.addRenderGroup(r.renderGroup,t);else{for(let o=0;o<r.effects.length;o++){const a=r.effects[o];e[a.pipe].push(a,r,t)}const s=r.renderPipeId;s&&(e.blendMode.setBlendMode(r,r.groupBlendMode,t),r.didViewUpdate=!1,e[s].addRenderable(r,t));const n=r.children;if(n.length)for(let o=0;o<n.length;o++)$r(n[o],t,e);for(let o=r.effects.length-1;o>=0;o--){const a=r.effects[o];e[a.pipe].pop(a,r,t)}}}const US=new lt;class kS extends er{constructor(){super(),this.filters=[new Mm({sprite:new Gt(P.EMPTY)})]}get sprite(){return this.filters[0].sprite}set sprite(t){this.filters[0].sprite=t}}class wa{constructor(t){this._activeMaskStage=[],this._renderer=t}push(t,e,i){const s=this._renderer;if(s.renderPipes.batch.break(i),i.add({renderPipeId:"alphaMask",action:"pushMaskBegin",mask:t,canBundle:!1,maskedContainer:e}),t.renderMaskToTexture){const n=t.mask;n.includeInBuild=!0,$r(n,i,s.renderPipes),n.includeInBuild=!1}s.renderPipes.batch.break(i),i.add({renderPipeId:"alphaMask",action:"pushMaskEnd",mask:t,maskedContainer:e,canBundle:!1})}pop(t,e,i){this._renderer.renderPipes.batch.break(i),i.add({renderPipeId:"alphaMask",action:"popMaskEnd",mask:t,canBundle:!1})}execute(t){const e=this._renderer,i=t.mask.renderMaskToTexture;if(t.action==="pushMaskBegin"){const s=W.get(kS);if(i){t.mask.mask.measurable=!0;const n=rr(t.mask.mask,!0,US);t.mask.mask.measurable=!1,n.ceil();const o=ct.getOptimalTexture(n.width,n.height,1,!1);e.renderTarget.push(o,!0),e.globalUniforms.push({offset:n,worldColor:4294967295});const a=s.sprite;a.texture=o,a.worldTransform.tx=n.minX,a.worldTransform.ty=n.minY,this._activeMaskStage.push({filterEffect:s,maskedContainer:t.maskedContainer,filterTexture:o})}else s.sprite=t.mask.mask,this._activeMaskStage.push({filterEffect:s,maskedContainer:t.maskedContainer})}else if(t.action==="pushMaskEnd"){const s=this._activeMaskStage[this._activeMaskStage.length-1];i&&(e.renderTarget.pop(),e.globalUniforms.pop()),e.filter.push({renderPipeId:"filter",action:"pushFilter",container:s.maskedContainer,filterEffect:s.filterEffect,canBundle:!1})}else if(t.action==="popMaskEnd"){e.filter.pop();const s=this._activeMaskStage.pop();i&&ct.returnTexture(s.filterTexture),W.return(s.filterEffect)}}destroy(){this._renderer=null,this._activeMaskStage=null}}wa.extension={type:[x.WebGLPipes,x.WebGPUPipes,x.CanvasPipes],name:"alphaMask"};class Ra{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,i){this._renderer.renderPipes.batch.break(i);const s=this._colorStack;s[this._colorStackIndex]=s[this._colorStackIndex-1]&t.mask;const n=this._colorStack[this._colorStackIndex];n!==this._currentColor&&(this._currentColor=n,i.add({renderPipeId:"colorMask",colorMask:n,canBundle:!1})),this._colorStackIndex++}pop(t,e,i){this._renderer.renderPipes.batch.break(i);const s=this._colorStack;this._colorStackIndex--;const n=s[this._colorStackIndex-1];n!==this._currentColor&&(this._currentColor=n,i.add({renderPipeId:"colorMask",colorMask:n,canBundle:!1}))}execute(t){this._renderer.colorMask.setMask(t.colorMask)}destroy(){this._colorStack=null}}Ra.extension={type:[x.WebGLPipes,x.WebGPUPipes,x.CanvasPipes],name:"colorMask"};class LS{constructor(t){this.priority=0,this.pipe="scissorMask",this.mask=t,this.mask.renderable=!1,this.mask.measurable=!1}addBounds(t,e){ci(this.mask,t,e)}addLocalBounds(t,e){hi(this.m
|
||
|
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 xt({glProgram:s,resources:{uTexture:P.WHITE.source}})}renderStart(t){const e=this._renderer.renderTarget.getRenderTarget(t.target);if(this._useBackBufferThisRender=this.useBackBuffer&&!!e.isRoot,this._useBackBufferThisRender){const i=this._renderer.renderTarget.getRenderTarget(t.target);this._targetTexture=i.colorTexture,t.target=this._getBackBufferTexture(i.colorTexture)}}renderEnd(){this._presentBackBuffer()}_presentBackBuffer(){const t=this._renderer;t.renderTarget.finishRenderPass(),this._useBackBufferThisRender&&(t.renderTarget.bind(this._targetTexture,!1),this._bigTriangleShader.resources.uTexture=this._backBufferTexture.source,t.encoder.draw({geometry:qS,shader:this._bigTriangleShader,state:this._state}))}_getBackBufferTexture(t){return this._backBufferTexture=this._backBufferTexture||new P({source:new rt({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)}};Da.extension={type:[x.WebGLSystem],name:"backBuffer",priority:1},Da.defaultOptions={useBackBuffer:!1};let hg=Da;class Ua{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)))}}Ua.extension={type:[x.WebGLSystem],name:"colorMask"};class ka{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:i,shader:s,state:n,skipSync:o,topology:a,size:u,start:l,instanceCount:c}=t;e.shader.bind(s,o),e.geometry.bind(i,e.shader._activeProgram),n&&e.state.set(n),e.geometry.draw(a,u,l,c!=null?c:i.instanceCount)}destroy(){this._renderer=null}}ka.extension={type:[x.WebGLSystem],name:"encoder"};class dg{constructor(){this.width=-1,this.height=-1,this.msaa=!1,this.msaaRenderBuffer=[]}}const re=[];re[st.NONE]=void 0,re[st.DISABLED]={stencilWriteMask:0,stencilReadMask:0},re[st.RENDERING_MASK_ADD]={stencilFront:{compare:"equal",passOp:"increment-clamp"},stencilBack:{compare:"equal",passOp:"increment-clamp"}},re[st.RENDERING_MASK_REMOVE]={stencilFront:{compare:"equal",passOp:"decrement-clamp"},stencilBack:{compare:"equal",passOp:"decrement-clamp"}},re[st.MASK_ACTIVE]={stencilWriteMask:0,stencilFront:{compare:"equal",passOp:"keep"},stencilBack:{compare:"equal",passOp:"keep"}};class La{constructor(t){this._stencilCache={enabled:!1,stencilReference:0,stencilMode:st.NONE},this._renderTargetStencilState=Object.create(null),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._stencilCache.enabled=!1,this._stencilCache.stencilMode=st.NONE,this._stencilCache.stencilReference=0}onRenderTargetChange(t){if(this._activeRenderTarget===t)return;this._activeRenderTarget=t;let e=this._renderTargetStencilState[t.uid];e||(e=this._renderTargetStencilState[t.uid]={stencilMode:st.DISABLED,stencilReference:0}),this.setStencilMode(e.stencilMode,e.stencilReference)}setStencilMode(t,e){const i=this._renderTargetStencilState[this._activeRenderTarget.uid],s=this._gl,n=re[t],o=this._stencilCache;if(i.stencilMode=t,i.stencilReference=e,t===st.DISABLED){this._stencilCache.enabled&&(this._stencilCache.enabled=!1,s.disable(s.STENCIL_TEST));return}this._stencilCache.enabled||(this._stencilCache.enabled=!0,s.enable(s.STENCIL_TEST)),(t!==o.stencilMode||o.stencilReference!==e)&&(o.stencilMode=t,o.stencilReference=e,s.stencilFunc(this._comparisonFuncMapping[n.stencilBack.compare],e,255),s
|
||
|
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 Ha(r,t,e,i){const s=[`
|
||
|
var v = null;
|
||
|
var v2 = null;
|
||
|
var t = 0;
|
||
|
var index = 0;
|
||
|
var name = null;
|
||
|
var arrayOffset = null;
|
||
|
`];let n=0;for(let a=0;a<r.length;a++){const u=r[a],l=u.data.name;let c=!1,h=0;for(let p=0;p<ie.length;p++)if(ie[p].test(u.data)){h=u.offset/4,s.push(`name = "${l}";`,`offset += ${h-n};`,ie[p][t]||ie[p].ubo),c=!0;break}if(!c)if(u.data.size>1)h=u.offset/4,s.push(e(u,h-n));else{const p=i[u.data.type];h=u.offset/4,s.push(`
|
||
|
v = uv.${l};
|
||
|
offset += ${h-n};
|
||
|
${p};
|
||
|
`)}n=h}const o=s.join(`
|
||
|
`);return new Function("uv","data","offset",o)}var ZS=Object.defineProperty,QS=Object.defineProperties,JS=Object.getOwnPropertyDescriptors,fg=Object.getOwnPropertySymbols,t2=Object.prototype.hasOwnProperty,e2=Object.prototype.propertyIsEnumerable,mg=(r,t,e)=>t in r?ZS(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,r2=(r,t)=>{for(var e in t||(t={}))t2.call(t,e)&&mg(r,e,t[e]);if(fg)for(var e of fg(t))e2.call(t,e)&&mg(r,e,t[e]);return r},i2=(r,t)=>QS(r,JS(t));function Ye(r,t){return`
|
||
|
for (let i = 0; i < ${r*t}; i++) {
|
||
|
data[offset + (((i / ${r})|0) * 4) + (i % ${r})] = v[i];
|
||
|
}
|
||
|
`}const Xa={f32:`
|
||
|
data[offset] = v;`,i32:`
|
||
|
data[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];`,"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>":Ye(3,2),"mat4x2<f32>":Ye(4,2),"mat2x3<f32>":Ye(2,3),"mat4x3<f32>":Ye(4,3),"mat2x4<f32>":Ye(2,4),"mat3x4<f32>":Ye(3,4)},gg=i2(r2({},Xa),{"mat2x2<f32>":`
|
||
|
data[offset] = v[0];
|
||
|
data[offset + 1] = v[1];
|
||
|
data[offset + 2] = v[2];
|
||
|
data[offset + 3] = v[3];
|
||
|
`});function _g(r,t){const e=Math.max(Na[r.data.type]/16,1),i=r.data.value.length/r.data.size,s=(4-i%4)%4;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 < ${i}; j++)
|
||
|
{
|
||
|
data[arrayOffset++] = v[t++];
|
||
|
}
|
||
|
${s!==0?`arrayOffset += ${s};`:""}
|
||
|
}
|
||
|
`}function bg(r){return Ha(r,"uboStd40",_g,Xa)}class za extends $a{constructor(){super({createUboElements:pg,generateUboSync:bg})}}za.extension={type:[x.WebGLSystem],name:"ubo"};class vg{constructor(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new j}init(t,e){this._renderer=t,this._renderTargetSystem=e,t.runners.contextChange.add(this)}contextChange(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new j}copyToTexture(t,e,i,s,n){const o=this._renderTargetSystem,a=this._renderer,u=o.getGpuRenderTarget(t),l=a.gl;return this.finishRenderPass(t),l.bindFramebuffer(l.FRAMEBUFFER,u.resolveTargetFramebuffer),a.texture.bind(e,0),l.copyTexSubImage2D(l.TEXTURE_2D,0,n.x,n.y,i.x,i.y,s.width,s.height),e}startRenderPass(t,e=!0,i,s){const n=this._renderTargetSystem,o=t.colorTexture,a=n.getGpuRenderTarget(t);let u=s.y;t.isRoot&&(u=o.pixelHeight-s.height),t.colorTextures.forEach(h=>{this._renderer.texture.unbind(h)});const l=this._renderer.gl;l.bindFramebuffer(l.FRAMEBUFFER,a.framebuffer);const c=this._viewPortCache;(c.x!==s.x||c.y!==u||c.width!==s.width||c.height!==s.height)&&(c.x=s.x,c.y=u,c.width=s.width,c.height=s.height,l.viewport(s.x,u,s.width,s.height)),!a.depthStencilRenderBuffer&&(t.stencil||t.depth)&&this._initStencil(a),this.clear(t,e,i)}finishRenderPass(t){const e=this._renderTargetSystem.getGpuRenderTarget(t);if(!e.msaa)return;const i=this._renderer.gl;i.bindFramebuffer(i.FRAMEBUFFER,e.resolveTargetFramebuffer),i.bindFramebuffer(i.READ_FRAMEBUFFER,e.framebuffer),i.blitFramebuffer(0,0,e.width,e.height,0,0,e.width,e.height,i.COLOR_BUFFER_BIT,i.NEAREST),i.bindFramebuffer(i.FRAMEBUFFER,e.framebuffer)}initGpuRenderTarget(t){const e=this._renderer,i=e.gl,s=new dg;return t.colorTexture.resource===e.gl.canvas?(s.framebuffer=null,s):(this._initColor(t,s),i.bindFramebuffer(i.FRAMEBUFFER,null),s)}destroyGpuRenderTarget(t){const e=this._renderer.gl;t.framebuffer&&(e.deleteFramebuffer(t.framebuffer),t.framebuffer=null),t.resolveTargetFramebuffer&&(e.deleteFramebuffer(t.resolveTargetFramebuffer),t.resolveTargetFramebuffer=null),t.depthStencilRenderBuffer&&(e.deleteRenderbuffer(t.depthStencilRenderBuffer),t.depthStencilRenderBuffer=null),t.msaaRenderBuffer.forEach(i=>{e.deleteRenderbuffer(i)}),t.msaaRenderBuffer=null}clear(t,e,i){if(!e)return;const s=this._renderTargetSystem;typeof e=="boolean"&&(e=e?mt.ALL:mt.NONE);const n=this._renderer.gl;if(e&mt.COLOR){i!=null||(i=s.defaultClearColor);const o=this._clearColorCache,a=i;(o[0]!==a[0]||o[1]!==a[1]||o[2]!==a[2]||o[3]!==a[3])&&(o[0]=a[0],o[1]=a[1],o[2]=a[2],o[3]=a[3],n.clearColor(a[0],a[1],a[2],a[3]))}n.clear(e)}resizeGpuRenderTarget(t){if(t.isRoot)return;const e=this._renderTargetSystem.getGpuRenderTarget(t);this._resizeColor(t,e),t.stencil&&this._resizeStencil(e)}_initColor(t,e){const i=this._renderer,s=i.gl,n=s.createFramebuffer();if(e.resolveTargetFramebuffer=n,s.bindFramebuffer(s.FRAMEBUFFER,n),e.width=t.colorTexture.source.pixelWidth,e.height=t.colorTexture.source.pixelHeight,t.colorTextures.forEach((o,a)=>{const u=o.source;u.antialias&&(i.context.supports.msaa?e.msaa=!0:_s("[RenderTexture] Antialiasing on textures is not supported in WebGL1")),i.texture.bindSource(u,0);const l=i.texture.getGlSource(u).texture;s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+a,3553,l,0)}),e.msaa){const o=s.createFramebuffer();e.framebuffer=o,s.bindFramebuffer(s.FRAMEBUFFER,o),t.colorTextures.forEach((a,u)=>{const l=s.createRenderbuffer();e.msaaRenderBuffer[u]=l})}else e.framebuffer=n;this._resizeColor(t,e)}_resizeColor(t,e){const i=t.colorTexture.source;if(e.width=i.pixelWidth,e.height=i.pixelHeight,t.colorTextures.forEach((s,n)=>{n!==0&&s.source.resize(i.width,i.height,i._resolution)}),e.msaa){const s=this._renderer,n=s.gl,o=e.framebuffer;n.bindFramebuffer(n.FRAMEBUFFER,o),t.colorTextures.forEach((a,u)=>{const l=a.source;s.texture.bindSource(l,0);const c=s.texture.getGlSource(l).internalFormat,h=e.msaaRenderBuffer[u];n.bindRenderbuffer(n.RENDERBUFFER,h),n.renderbufferStorageMultisample(n.RENDERBUFFER,4,c,l.pixelWidth,l.pixelHeight),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COL
|
||
|
var g = s.groups;
|
||
|
var sS = r.shader;
|
||
|
var p = s.glProgram;
|
||
|
var ugS = r.uniformGroup;
|
||
|
var resources;
|
||
|
`];let s=!1,n=0,o=0;const a=t._getProgramData(r.glProgram);for(const l in r.groups){const c=r.groups[l];e.push(`
|
||
|
resources = g[${l}].resources;
|
||
|
`);for(const h in c.resources){const p=c.resources[h];if(p instanceof nt)p.ubo?e.push(`
|
||
|
sS.bindUniformBlock(
|
||
|
resources[${h}],
|
||
|
sS._uniformBindMap[${l}[${h}],
|
||
|
${n++}
|
||
|
);
|
||
|
`):e.push(`
|
||
|
ugS.updateUniformGroup(resources[${h}], p, sD);
|
||
|
`);else if(p instanceof ys)e.push(`
|
||
|
sS.bindUniformBlock(
|
||
|
resources[${h}],
|
||
|
sS._uniformBindMap[${l}[${h}],
|
||
|
${n++}
|
||
|
);
|
||
|
`);else if(p instanceof rt){const f=r._uniformBindMap[l][h],m=a.uniformData[f];m&&(s||(s=!0,i.push(`
|
||
|
var tS = r.texture;
|
||
|
`)),t._gl.uniform1i(m.location,o),e.push(`
|
||
|
tS.bind(resources[${h}], ${o});
|
||
|
`),o++)}}}const u=[...i,...e].join(`
|
||
|
`);return new Function("r","s","sD",u)}class d2{}class Mg{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 Ya(r,t,e){const i=r.createShader(t);return r.shaderSource(i,e),r.compileShader(i),i}function Ka(r){const t=new Array(r);for(let e=0;e<t.length;e++)t[e]=!1;return t}function qa(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 Ka(2*t);case"bvec3":return Ka(3*t);case"bvec4":return Ka(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 xs=null;const Cg={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_CUBE:"samplerCube",INT_SAMPLER_CUBE:"samplerCube",UNSIGNED_INT_SAMPLER_CUBE:"samplerCube",SAMPLER_2D_ARRAY:"sampler2DArray",INT_SAMPLER_2D_ARRAY:"sampler2DArray",UNSIGNED_INT_SAMPLER_2D_ARRAY:"sampler2DArray"},p2={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 Za(r,t){if(!xs){const e=Object.keys(Cg);xs={};for(let i=0;i<e.length;++i){const s=e[i];xs[r[s]]=Cg[s]}}return xs[t]}function Og(r,t){const e=Za(r,t);return p2[e]||"float32"}function Gg(r,t,e=!1){const i={},s=t.getProgramParameter(r,t.ACTIVE_ATTRIBUTES);for(let o=0;o<s;o++){const a=t.getActiveAttrib(r,o);if(a.name.startsWith("gl_"))continue;const u=Og(t,a.type);i[a.name]={location:0,format:u,stride:Ue(u).stride,offset:0,instance:!1,start:0}}const n=Object.keys(i);if(e){n.sort((o,a)=>o>a?1:-1);for(let o=0;o<n.length;o++)i[n[o]].location=o,t.bindAttribLocation(r,o,n[o]);t.linkProgram(r)}else for(let o=0;o<n.length;o++)i[n[o]].location=t.getAttribLocation(r,n[o]);return i}function Bg(r,t){if(!t.ACTIVE_UNIFORM_BLOCKS)return{};const e={},i=t.getProgramParameter(r,t.ACTIVE_UNIFORM_BLOCKS);for(let s=0;s<i;s++){const n=t.getActiveUniformBlockName(r,s),o=t.getUniformBlockIndex(r,n),a=t.getActiveUniformBlockParameter(r,s,t.UNIFORM_BLOCK_DATA_SIZE);e[n]={name:n,index:o,size:a}}return e}function Ig(r,t){const e={},i=t.getProgramParameter(r,t.ACTIVE_UNIFORMS);for(let s=0;s<i;s++){const n=t.getActiveUniform(r,s),o=n.name.replace(/\[.*?\]$/,""),a=!!n.name.match(/\[.*?\]$/),u=Za(t,n.type);e[o]={name:o,index:s,type:u,size:n.size,isArray:a,value:qa(u,n.size)}}return e}function Fg(r,t){const e=r.getShaderSource(t).split(`
|
||
|
`).map((l,c)=>`${c}: ${l}`),i=r.getShaderInfoLog(t),s=i.split(`
|
||
|
`),n={},o=s.map(l=>parseFloat(l.replace(/^ERROR\: 0\:([\d]+)\:.*$/,"$1"))).filter(l=>l&&!n[l]?(n[l]=!0,!0):!1),a=[""];o.forEach(l=>{e[l-1]=`%c${e[l-1]}%c`,a.push("background: #FF0000; color:#FFFFFF; font-size: 10px","font-size: 10px")});const u=e.join(`
|
||
|
`);a[0]=u,console.error(i),console.groupCollapsed("click to view full shader code"),console.warn(...a),console.groupEnd()}function Dg(r,t,e,i){r.getProgramParameter(t,r.LINK_STATUS)||(r.getShaderParameter(e,r.COMPILE_STATUS)||Fg(r,e),r.getShaderParameter(i,r.COMPILE_STATUS)||Fg(r,i),console.error("PixiJS Error: Could not initialize shader."),r.getProgramInfoLog(t)!==""&&console.warn("PixiJS Warning: gl.getProgramInfoLog()",r.getProgramInfoLog(t)))}function Ug(r,t){const e=Ya(r,r.VERTEX_SHADER,t.vertex),i=Ya(r,r.FRAGMENT_SHADER,t.fragment),s=r.createProgram();r.attachShader(s,e),r.attachShader(s,i);const n=t.transformFeedbackVaryings;n&&(typeof r.transformFeedbackVaryings!="function"||r.transformFeedbackVaryings(s,n.names,n.bufferMode==="separate"?r.SEPARATE_ATTRIBS:r.INTERLEAVED_ATTRIBS)),r.linkProgram(s),r.getProgramParameter(s,r.LINK_STATUS)||Dg(r,s,e,i),t._attributeData=Gg(s,r,!/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(t.vertex)),t._uniformData=Ig(s,r),t._uniformBlockData=Bg(s,r),r.deleteShader(e),r.deleteShader(i);const o={};for(const a in t._uniformData){const u=t._uniformData[a];o[a]={location:r.getUniformLocation(s,a),value:qa(u.type,u.size)}}return new Mg(s,o)}const Ts={textureCount:0,blockIndex:0};class Qa{constructor(t){this._activeProgram=null,this._programDataHash=Object.create(null),this._nextIndex=0,this._boundUniformsIdsToIndexHash=Object.create(null),this._boundIndexToUniformsHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._renderer=t}contextChange(t){this._gl=t,this._maxBindings=t.MAX_UNIFORM_BUFFER_BINDINGS?t.getParameter(t.MAX_UNIFORM_BUFFER_BINDINGS):0,this._programDataHash=Object.create(null),this._boundUniformsIdsToIndexHash=Object.create(null),this._boundIndexToUniformsHash=Object.create(null),this._activeProgram=null}bind(t,e){if(this._setProgram(t.glProgram),e)return;Ts.textureCount=0,Ts.blockIndex=0;let i=this._shaderSyncFunctions[t.glProgram._key];i||(i=this._shaderSyncFunctions[t.glProgram._key]=this._generateShaderSync(t,this)),i(this._renderer,t,Ts)}updateUniformGroup(t){this._renderer.uniformGroup.updateUniformGroup(t,this._activeProgram,Ts)}bindUniformBlock(t,e,i=0){const s=this._renderer.buffer,n=this._getProgramData(this._activeProgram),o=t._bufferResource;o&&this._renderer.ubo.updateUniformGroup(t),s.updateBuffer(t.buffer);let a=this._boundUniformsIdsToIndexHash[t.uid];if(a===void 0){const c=this._nextIndex++%this._maxBindings,h=this._boundIndexToUniformsHash[c];h&&(this._boundUniformsIdsToIndexHash[h.uid]=void 0),a=this._boundUniformsIdsToIndexHash[t.uid]=c,this._boundIndexToUniformsHash[c]=t,o?s.bindBufferRange(t.buffer,c,t.offset):s.bindBufferBase(t.buffer,c)}const u=this._gl,l=this._activeProgram._uniformBlockData[e].index;n.uniformBlockBindings[i]!==a&&(n.uniformBlockBindings[i]=a,u.uniformBlockBinding(n.program,l,a))}_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]=Ug(this._gl,t),this._programDataHash[e]}destroy(){for(const t of Object.keys(this._programDataHash))this._programDataHash[t].destroy(),this._programDataHash[t]=null;this._programDataHash=null,this._boundUniformsIdsToIndexHash=null}_generateShaderSync(t,e){return Rg(t,e)}}Qa.extension={type:[x.WebGLSystem],name:"shader"};const kg={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);"},Lg={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 $g(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 i in r.uniforms){if(!t[i]){r.uniforms[i]instanceof nt?r.uniforms[i].ubo?e.push(`
|
||
|
renderer.shader.bindUniformBlock(uv.${i}, "${i}");
|
||
|
`):e.push(`
|
||
|
renderer.shader.updateUniformGroup(uv.${i});
|
||
|
`):r.uniforms[i]instanceof ys&&e.push(`
|
||
|
renderer.shader.bindBufferResource(uv.${i}, "${i}");
|
||
|
`);continue}const s=r.uniformStructures[i];let n=!1;for(let o=0;o<ie.length;o++){const a=ie[o];if(s.type===a.type&&a.test(s)){e.push(`name = "${i}";`,ie[o].uniform),n=!0;break}}if(!n){const o=(s.size===1?kg:Lg)[s.type].replace("location",`ud["${i}"].location`);e.push(`
|
||
|
cu = ud["${i}"];
|
||
|
cv = cu.value;
|
||
|
v = uv["${i}"];
|
||
|
${o};`)}}return new Function("ud","uv","renderer","syncData",e.join(`
|
||
|
`))}class Ja{constructor(t){this._cache={},this._uniformGroupSyncHash={},this._renderer=t,this.gl=null,this._cache={}}contextChange(t){this.gl=t}updateUniformGroup(t,e,i){const s=this._renderer.shader._getProgramData(e);(!t.isStatic||t._dirtyId!==s.uniformDirtyGroups[t.uid])&&(s.uniformDirtyGroups[t.uid]=t._dirtyId,this._getUniformSyncFunction(t,e)(s.uniformData,t.uniforms,this._renderer,i))}_getUniformSyncFunction(t,e){var i;return((i=this._uniformGroupSyncHash[t._signature])==null?void 0:i[e._key])||this._createUniformSyncFunction(t,e)}_createUniformSyncFunction(t,e){const i=this._uniformGroupSyncHash[t._signature]||(this._uniformGroupSyncHash[t._signature]={}),s=this._getSignature(t,e._uniformData,"u");return this._cache[s]||(this._cache[s]=this._generateUniformsSync(t,e._uniformData)),i[e._key]=this._cache[s],i[e._key]}_generateUniformsSync(t,e){return $g(t,e)}_getSignature(t,e,i){const s=t.uniforms,n=[`${i}-`];for(const o in s)n.push(o),e[o]&&n.push(e[o].type);return n.join("-")}destroy(){this._renderer=null,this._cache=null}}Ja.extension={type:[x.WebGLSystem],name:"uniformGroup"};function f2(r){return r=r.replaceAll("texture2D","texture").replaceAll("gl_FragColor","finalColor").replaceAll("varying","in"),r=`
|
||
|
out vec4 finalColor;
|
||
|
${r}
|
||
|
`,r}const m2={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 g2(r){return m2[r]}function Ng(r){const t={};return 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],t}const _2=0,b2=1,v2=2,y2=3,x2=4,T2=5,Hg=class el{constructor(){this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode="none",this._blendEq=!1,this.map=[],this.map[_2]=this.setBlend,this.map[b2]=this.setOffset,this.map[v2]=this.setCullFace,this.map[y2]=this.setDepthTest,this.map[x2]=this.setFrontFace,this.map[T2]=this.setDepthMask,this.checks=[],this.defaultState=Bt.for2d()}contextChange(t){this.gl=t,this.blendModesMap=Ng(t),this.reset()}set(t){if(t=t||this.defaultState,this.stateId!==t.data){let e=this.stateId^t.data,i=0;for(;e;)e&1&&this.map[i].call(this,!!(t.data&1<<i)),e=e>>1,i++;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(el._checkBlendMode,t),this.gl[t?"enable":"disable"](this.gl.BLEND)}setOffset(t){this._updateCheck(el._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)}setCullFace(t){this.gl[t?"enable":"disable"](this.gl.CULL_FACE)}setFrontFace(t){this.gl.frontFace(this.gl[t?"CW":"CCW"])}setBlendMode(t){if(this.blendModesMap[t]||(t="normal"),t===this.blendMode)return;this.blendMode=t;const e=this.blendModesMap[t],i=this.gl;e.length===2?i.blendFunc(e[0],e[1]):i.blendFuncSeparate(e[0],e[1],e[2],e[3]),e.length===6?(this._blendEq=!0,i.blendEquationSeparate(e[4],e[5])):this._blendEq&&(this._blendEq=!1,i.blendEquationSeparate(i.FUNC_ADD,i.FUNC_ADD))}setPolygonOffset(t,e){this.gl.polygonOffset(t,e)}reset(){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 i=this.checks.indexOf(t);e&&i===-1?this.checks.push(t):!e&&i!==-1&&this.checks.splice(i,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}};Hg.extension={type:[x.WebGLSystem],name:"state"};let Xg=Hg;class zg{constructor(t){this.target=Ia.TEXTURE_2D,this.texture=t,this.width=-1,this.height=-1,this.type=X.UNSIGNED_BYTE,this.internalFormat=bs.RGBA,this.format=bs.RGBA,this.samplerType=0}}const jg={id:"buffer",upload(r,t,e){t.width===r.width||t.height===r.height?e.texSubImage2D(e.TEXTURE_2D,0,0,0,r.width,r.height,t.format,t.type,r.resource):e.texImage2D(t.target,0,t.internalFormat,r.width,r.height,0,t.format,t.type,r.resource),t.width=r.width,t.height=r.height}},S2={"bc1-rgba-unorm":!0,"bc1-rgba-unorm-srgb":!0,"bc2-rgba-unorm":!0,"bc2-rgba-unorm-srgb":!0,"bc3-rgba-unorm":!0,"bc3-rgba-unorm-srgb":!0,"bc4-r-unorm":!0,"bc4-r-snorm":!0,"bc5-rg-unorm":!0,"bc5-rg-snorm":!0,"bc6h-rgb-ufloat":!0,"bc6h-rgb-float":!0,"bc7-rgba-unorm":!0,"bc7-rgba-unorm-srgb":!0,"etc2-rgb8unorm":!0,"etc2-rgb8unorm-srgb":!0,"etc2-rgb8a1unorm":!0,"etc2-rgb8a1unorm-srgb":!0,"etc2-rgba8unorm":!0,"etc2-rgba8unorm-srgb":!0,"eac-r11unorm":!0,"eac-r11snorm":!0,"eac-rg11unorm":!0,"eac-rg11snorm":!0,"astc-4x4-unorm":!0,"astc-4x4-unorm-srgb":!0,"astc-5x4-unorm":!0,"astc-5x4-unorm-srgb":!0,"astc-5x5-unorm":!0,"astc-5x5-unorm-srgb":!0,"astc-6x5-unorm":!0,"astc-6x5-unorm-srgb":!0,"astc-6x6-unorm":!0,"a
|
||
|
|
||
|
`,"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 ${Su} - ${r} - http://www.pixijs.com/`);f_=!0}}class Es{constructor(t){this._renderer=t}init(t){if(t.hello){let e=this._renderer.name;this._renderer.type===yt.WEBGL&&(e+=` ${this._renderer.context.webGLVersion}`),m_(e)}}}Es.extension={type:[x.WebGLSystem,x.WebGPUSystem,x.CanvasSystem],name:"hello",priority:-2},Es.defaultOptions={hello:!1};var Q2=Object.defineProperty,g_=Object.getOwnPropertySymbols,J2=Object.prototype.hasOwnProperty,tE=Object.prototype.propertyIsEnumerable,__=(r,t,e)=>t in r?Q2(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,b_=(r,t)=>{for(var e in t||(t={}))J2.call(t,e)&&__(r,e,t[e]);if(g_)for(var e of g_(t))tE.call(t,e)&&__(r,e,t[e]);return r};const Eu=class zb{constructor(t){this._renderer=t,this.count=0,this.checkCount=0}init(t){t=b_(b_({},zb.defaultOptions),t),this.checkCountMax=t.textureGCCheckCountMax,this.maxIdle=t.textureGCAMaxIdle,this.active=t.textureGCActive}postrender(){this._renderer.renderingToScreen&&(this.count++,this.active&&(this.checkCount++,this.checkCount>this.checkCountMax&&(this.checkCount=0,this.run())))}run(){const t=this._renderer.texture.managedTextures;for(let e=0;e<t.length;e++){const i=t[e];i.autoGarbageCollect&&i.resource&&i._touched>-1&&this.count-i._touched>this.maxIdle&&(i._touched=-1,i.unload())}}destroy(){this._renderer=null}};Eu.extension={type:[x.WebGLSystem,x.WebGPUSystem],name:"textureGC"},Eu.defaultOptions={textureGCActive:!0,textureGCAMaxIdle:3600,textureGCCheckCountMax:600};let Au=Eu;U.add(Au);var eE=Object.defineProperty,v_=Object.getOwnPropertySymbols,rE=Object.prototype.hasOwnProperty,iE=Object.prototype.propertyIsEnumerable,y_=(r,t,e)=>t in r?eE(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,x_=(r,t)=>{for(var e in t||(t={}))rE.call(t,e)&&y_(r,e,t[e]);if(v_)for(var e of v_(t))iE.call(t,e)&&y_(r,e,t[e]);return r};const Pu=class jb{get resolution(){return this.texture.source._resolution}set resolution(t){this.texture.source.resize(this.texture.source.width,this.texture.source.height,t)}init(t){t=x_(x_({},jb.defaultOptions),t),t.view&&(t.canvas=t.view),this.screen=new j(0,0,t.width,t.height),this.canvas=t.canvas||z.get().createCanvas(),this.antialias=!!t.antialias,this.texture=ja(this.canvas,t),this.renderTarget=new vs({colorTextures:[this.texture],depth:!!t.depth,isRoot:!0}),this.texture.source.transparent=t.backgroundAlpha<1,this.multiView=!!t.multiView,this.autoDensity&&(this.canvas.style.width=`${this.texture.width}px`,this.canvas.style.height=`${this.texture.height}px`),this.resolution=t.resolution}resize(t,e,i){this.texture.source.resize(t,e,i),this.screen.width=this.texture.frame.width,this.screen.height=this.texture.frame.height,this.autoDensity&&(this.canvas.style.width=`${t}px`,this.canvas.style.height=`${e}px`)}destroy(t=!1){(typeof t=="boolean"?t:t!=null&&t.removeView)&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas)}};Pu.extension={type:[x.WebGLSystem,x.WebGPUSystem,x.CanvasSystem],name:"view",priority:0},Pu.defaultOptions={width:800,height:600,autoDensity:!1,antialias:!1};let T_=Pu;const wu=[a_,Tu,Es,T_,fu,Au,xu,c_],Ru=[_u,Pa,mu,uu,wa,Ma,Ra,ou],sE=[...wu,za,hg,ig,Ca,iu,Wa,Fa,Ja,Qa,ka,Xg,La,Ua],nE=[...Ru],oE=[Ea,nu,su],S_=[],E_=[],A_=[];U.handleByNamedList(x.WebGLSystem,S_),U.handleByNamedList(x.WebGLPipes,E_),U.handleByNamedList(x.WebGLPipesAdaptor,A_),U.add(...sE,...nE,...oE);class P_ extends wr{constructor(){const t={name:"webgl",type:yt.WEBGL,systems:S_,renderPipes:E_,renderPipeAdaptors:A_};super(t)}}var aE={__proto__:null,WebGLRenderer:P_};class Mu{constructor(t){this._hash=Object.create(null),this._renderer=t}contextChange(t){this._gpu=t}getBindGroup(t,e,i){return t._updateKey(),this._hash[t._key]||this._createBindGroup(t,e,i)}_createBindGroup
|
||
|
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++)
|
||
|
{
|
||
|
data[arrayOffset++] = v[t++];
|
||
|
}
|
||
|
${s!==0?`arrayOffset += ${s};`:""}
|
||
|
}
|
||
|
`}function B_(r){return Ha(r,"uboWgsl",G_,gg)}class Iu extends $a{constructor(){super({createUboElements:O_,generateUboSync:B_})}}Iu.extension={type:[x.WebGPUSystem],name:"ubo"};const se=128;class Fu{constructor(t){this._bindGroupHash=Object.create(null),this._buffers=[],this._bindGroups=[],this._bufferResources=[],this._renderer=t,this._batchBuffer=new w_({minUniformOffsetAlignment:se});const e=256/se;for(let i=0;i<e;i++){let s=H.UNIFORM|H.COPY_DST;i===0&&(s|=H.COPY_SRC),this._buffers.push(new bt({data:this._batchBuffer.data,usage:s}))}}renderEnd(){this._uploadBindGroups(),this._resetBindGroups()}_resetBindGroups(){for(const t in this._bindGroupHash)this._bindGroupHash[t]=null;this._batchBuffer.clear()}getUniformBindGroup(t,e){if(!e&&this._bindGroupHash[t.uid])return this._bindGroupHash[t.uid];this._renderer.ubo.ensureUniformGroup(t);const i=t.buffer.data,s=this._batchBuffer.addEmptyGroup(i.length);return this._renderer.ubo.syncUniformGroup(t,this._batchBuffer.data,s/4),this._bindGroupHash[t.uid]=this._getBindGroup(s/se),this._bindGroupHash[t.uid]}getUboResource(t){this._renderer.ubo.updateUniformGroup(t);const e=t.buffer.data,i=this._batchBuffer.addGroup(e);return this._getBufferResource(i/se)}getArrayBindGroup(t){const e=this._batchBuffer.addGroup(t);return this._getBindGroup(e/se)}getArrayBufferResource(t){const e=this._batchBuffer.addGroup(t)/se;return this._getBufferResource(e)}_getBufferResource(t){if(!this._bufferResources[t]){const e=this._buffers[t%2];this._bufferResources[t]=new ys({buffer:e,offset:(t/2|0)*256,size:se})}return this._bufferResources[t]}_getBindGroup(t){if(!this._bindGroups[t]){const e=new Nt({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 i=this._renderer.gpu.device.createCommandEncoder();for(let s=1;s<this._buffers.length;s++){const n=this._buffers[s];i.copyBufferToBuffer(t.getGPUBuffer(e),se,t.getGPUBuffer(n),0,this._batchBuffer.byteIndex)}this._renderer.gpu.device.queue.submit([i.finish()])}destroy(){for(let t=0;t<this._bindGroups.length;t++)this._bindGroups[t].destroy();this._bindGroups=null,this._bindGroupHash=null;for(let t=0;t<this._buffers.length;t++)this._buffers[t].destroy();this._buffers=null;for(let t=0;t<this._bufferResources.length;t++)this._bufferResources[t].destroy();this._bufferResources=null,this._batchBuffer.destroy(),this._bindGroupHash=null,this._renderer=null}}Fu.extension={type:[x.WebGPUPipes],name:"uniformBatch"};var dE=Object.defineProperty,pE=Object.defineProperties,fE=Object.getOwnPropertyDescriptors,I_=Object.getOwnPropertySymbols,mE=Object.prototype.hasOwnProperty,gE=Object.prototype.propertyIsEnumerable,F_=(r,t,e)=>t in r?dE(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,_E=(r,t)=>{for(var e in t||(t={}))mE.call(t,e)&&F_(r,e,t[e]);if(I_)for(var e of I_(t))gE.call(t,e)&&F_(r,e,t[e]);return r},bE=(r,t)=>pE(r,fE(t));const vE={"point-list":0,"line-list":1,"line-strip":2,"triangle-list":3,"triangle-strip":4};function yE(r,t,e,i,s){return r<<24|t<<16|e<<10|i<<5|s}function xE(r,t,e,i){return e<<6|r<<3|i<<1|t}class Du{constructor(t){this._moduleCache=Object.create(null),this._bufferLayoutsCache=Object.create(null),this._pipeCache=Object.create(null),this._pipeStateCaches=Object.create(null),this._colorMask=15,this._multisampleCount=1,this._renderer=t}contextChange(t){this._gpu=t,this.setStencilMode(st.DISABLED),this._updatePipeHash()}setMultisampleCount(t){this._multisampleCount!==t&&(this._multisampleCount=t,this._updatePipeHash())}setRenderTarget(t){this._multisampleCount=t.msaaSamples,this._depthStencilAttachment=t.descriptor.depthStencilAttachment?1:0,this._updatePipeHash()}setColorMask(t){this._colorMask!==t&&(this._colorMask=t,this._updatePipeHash())}setStencilMode(t){this._stencilMode!==t&&(this._stencilMode=t,this._stencilState=re[t],this._updatePipeHash())}setPipeline(t,e,i,s){const n=this.getPipeline(t,e,i);s.setPipeline(n)}getPipeline(t,e,i,s){t._layoutKey||(Ba(t,e.attributeDat
|
||
|
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 i=t;const s=t.depthOrArrayLayers||1,n=t.usage&GPUTextureUsage.RENDER_ATTACHMENT;if(!n){const u={size:{width:Math.ceil(t.width/2),height:Math.ceil(t.height/2),depthOrArrayLayers:s},format:t.format,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_SRC|GPUTextureUsage.RENDER_ATTACHMENT,mipLevelCount:t.mipLevelCount-1};i=this.device.createTexture(u)}const o=this.device.createCommandEncoder({}),a=e.getBindGroupLayout(0);for(let u=0;u<s;++u){let l=t.createView({baseMipLevel:0,mipLevelCount:1,dimension:"2d",baseArrayLayer:u,arrayLayerCount:1}),c=n?1:0;for(let h=1;h<t.mipLevelCount;++h){const p=i.createView({baseMipLevel:c++,mipLevelCount:1,dimension:"2d",baseArrayLayer:u,arrayLayerCount:1}),f=o.beginRenderPass({colorAttachments:[{view:p,storeOp:"store",loadOp:"clear",clearValue:{r:0,g:0,b:0,a:0}}]}),m=this.device.createBindGroup({layout:a,entries:[{binding:0,resource:this.sampler},{binding:1,resource:l}]});f.setPipeline(e),f.setBindGroup(0,m),f.draw(3,1,0,0),f.end(),l=p}}if(!n){const u={width:Math.ceil(t.width/2),height:Math.ceil(t.height/2),depthOrArrayLayers:s};for(let l=1;l<t.mipLevelCount;++l)o.copyTextureToTexture({texture:i,mipLevel:l-1},{texture:t,mipLevel:l},u),u.width=Math.ceil(u.width/2),u.height=Math.ceil(u.height/2)}return this.device.queue.submit([o.finish()]),n||i.destroy(),t}}class Hu{constructor(t){this.managedTextures=[],this._gpuSources=Object.create(null),this._gpuSamplers=Object.create(null),this._bindGroupHash=Object.create(null),this._textureViewHash=Object.create(null),this._uploads={image:Nu,buffer:k_,video:$_,compressed:L_},this._renderer=t}contextChange(t){this._gpu=t}initSource(t){if(t.autoGenerateMipmaps){const u=Math.max(t.pixelWidth,t.pixelHeight);t.mipLevelCount=Math.floor(Math.log2(u))+1}let e=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST;t.uploadMethodId!=="compressed"&&(e|=GPUTextureUsage.RENDER_ATTACHMENT,e|=GPUTextureUsage.COPY_SRC);const i=$u[t.format]||{blockBytes:4,blockWidth:1,blockHeight:1},s=Math.ceil(t.pixelWidth/i.blockWidth)*i.blockWidth,n=Math.ceil(t.pixelHeight/i.blockHeight)*i.blockHeight,o={label:t.label,size:{width:s,height:n},format:t.format,sampleCount:t.sampleCount,mipLevelCount:t.mipLevelCount,dimension:t.dimension,usage:e},a=this._gpu.device.createTexture(o);return this._gpuSources[t.uid]=a,this.managedTextures.includes(t)||(t.on("update",this.onSourceUpdate,this),t.on("resize",this.onSourceResize,this),t.on("destroy",this.onSourceDestroy,this),t.on("unload",this.onSourceUnload,this),t.on("updateMipmaps",this.onUpdateMipmaps,this),this.managedTextures.push(t)),this.onSourceUpdate(t),a}onSourceUpdate(t){const e=this.getGpuSource(t);e&&(this._uploads[t.uploadMethodId]&&this._uploads[t.uploadMethodId].upload(t,e,this._gpu),t.autoGenerateMipmaps&&t.mipLevelCount>1&&this.onUpdateMipmaps(t))}onSourceUnload(t){const e=this._gpuSources[t.uid];e&&(this._gpuSources[t.uid]=null,e.destroy())}onUpdateMipmaps(t){this._mipmapGenerator||(this._mipmapGenerator=new N_(this._gpu.device));const e=this.getGpuSource(t);this._mipmapGenerator.generateMipmap(e)}onSourceDestroy(t){t.off("update",this.onSourceUpdate,this),t.off("unload",this.onSourceUnload,this),t.off("destroy",this.onSourceDestroy,this),t.off("resize",this.onSourceResize,this),t.off("updateMipmaps",this.onUpdateMipmaps,this),this.managedTextures.splice(this.managedTextures.indexOf(t),1),this.onSourceUnload(t)}onSourceResize(t){const e=this._gpuSources[t.uid];e?(e.width!==t.pixelWidth||e.height!==t.pixelHeight)&&(this._textureViewHash[t.uid]=null,this._bindGroupHash[t.uid]=null,this.onSourceUnload(t),this.initSource(t)):this.initSource(t)}_initSampler(t){return this._gpuSamplers
|
||
|
//# sourceMappingURL=pixi.min.js.map
|