WGLContainer.bbd0fcb8.js 180 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245
  1. import{F as _e,t as G,a as E,r as Ne,cb as Be,aV as yt,M as De,aX as pe,J as St,cc as Tt,aW as bt,b5 as nt,e as oe,b7 as Et,b2 as It,g as ae,s as ze,p as Ge,B as Ct,cd as Ot,aB as Ye,ce as At,z as Pt,af as He,R as Dt}from"./index.6c049565.js";import{I as V,M as re,P as B,U as Ce,G as q,L as N,D as Q,o as Y,F as J,C as m,E as R,R as D,O as X,Y as Rt,V as Lt,B as it,_ as We,N as Mt}from"./enums.2d9e6f64.js";import{s as Nt}from"./pixelUtils.f4eba4af.js";import{r as ot,p as at,s as fe,i as zt}from"./utils.eb2c3fd5.js";import{E as se}from"./Texture.8e8dfb11.js";import{E as ee,a as le,s as rt,x as st}from"./VertexArrayObject.729879be.js";import{t as ge}from"./VertexElementDescriptor.1fdca6da.js";import{ad as Oe,S as wt,B as Ft,C as Vt,ae as Ut,af as Bt,ag as Gt,ah as Yt,ai as Ht,aj as Wt,Q as Re,ak as $,al as lt,am as ke}from"./enums.0295eb81.js";import{g as ce,b as me,S as te,I as U,n as xe,e as H}from"./Utils.e8554a0e.js";import{e as kt,a as Ae}from"./ProgramTemplate.83fdf5b6.js";import{U as $t,w as Zt,N as qt,Z as Kt,C as jt,P as Xt}from"./MaterialKey.bbaab8f1.js";import{r as de,l as Z,n as $e}from"./StyleDefinition.d56936e4.js";import{e as Ze}from"./config.82550349.js";import{M as qe}from"./GeometryUtils.51c4032a.js";import{x as Qt}from"./earcut.afc1d357.js";class W{constructor(){this.name=this.constructor.name||"UnnamedBrush",this.brushEffect=null}prepareState(e,t){}draw(e,t,n){}drawMany(e,t,n){for(const o of t)o.visible&&this.draw(e,o,n)}}class Jt extends W{constructor(){super(...arguments),this._visualState={time:0,dvsMat3:_e(),displayViewMat3:_e()}}dispose(){}prepareState(e){const{context:t}=e;t.setColorMask(!0,!0,!0,!0),t.setStencilFunction(V.EQUAL,0,255)}draw(e,t){const{requestRender:n,allowDelayedRender:o}=e,{displayData:i}=t;if(G(i)||(i.state.name==="loaded"&&i.attach(e),i.state.name!=="attached"))return;const a=i.state.resources;o&&!a.ready&&E(n)?n():(this._visualState.time=e.time/1e3,this._visualState.dvsMat3=t.transforms.dvs,this._visualState.displayViewMat3=e.state.displayViewMat3,i.flowStyle.render(e,this._visualState,a),i.flowStyle.animated&&E(n)&&n())}}function en(l,e,t="nearest",n=!1){var s;const o=!(n&&e.pixelType==="u8"),i=o?q.FLOAT:q.UNSIGNED_BYTE,a=e.pixels==null||e.pixels.length===0?null:o?e.getAsRGBAFloat():e.getAsRGBA(),r=(s=l.capabilities.textureFloat)==null?void 0:s.textureFloatLinear,c={width:e.width,height:e.height,target:re.TEXTURE_2D,pixelFormat:B.RGBA,internalFormat:l.type===Ne.WEBGL2&&o?Ce.RGBA32F:B.RGBA,samplingMode:!r||t!=="bilinear"&&t!=="cubic"?N.NEAREST:N.LINEAR,dataType:i,wrapMode:Q.CLAMP_TO_EDGE,flipped:!1};return new se(l,c,a)}function tn(l,e){const{spacing:t,offsets:n,coefficients:o,size:[i,a]}=e,r=t[0]>1,c={width:r?4*i:i,height:a,target:re.TEXTURE_2D,pixelFormat:B.RGBA,internalFormat:l.type===Ne.WEBGL2?Ce.RGBA32F:B.RGBA,dataType:q.FLOAT,samplingMode:N.NEAREST,wrapMode:Q.CLAMP_TO_EDGE,flipped:!1},s=new Float32Array(r?i*a*16:2*n.length);if(r)for(let u=0,f=0;u<o.length;u++)s[f++]=o[u],u%3==2&&(s[f++]=1);else for(let u=0;u<a;u++)for(let f=0;f<i;f++){const _=4*(u*i+f),v=2*(f*a+u);s[_]=n[v],s[_+1]=n[v+1],s[_+3]=n[v]===-1?0:1}return new se(l,c,s)}function Ke(l,e){const t={width:e.length/4,height:1,target:re.TEXTURE_2D,pixelFormat:B.RGBA,internalFormat:B.RGBA,dataType:q.UNSIGNED_BYTE,samplingMode:N.NEAREST,wrapMode:Q.CLAMP_TO_EDGE,flipped:!1};return new se(l,t,e)}function nn(l,e,t,n=1,o=!0){return{u_flipY:o,u_applyTransform:!!l,u_opacity:n,u_transformSpacing:l?l.spacing:Be,u_transformGridSize:l?l.size:Be,u_targetImageSize:e,u_srcImageSize:t}}function on(l,e){return{u_colormapOffset:e||0,u_colormapMaxIndex:l?l.length/4-1:0}}function an(l,e){return{u_scale:l,u_offset:e}}function rn(l){return{u_bandCount:l.bandCount,u_minOutput:l.outMin,u_maxOutput:l.outMax,u_minCutOff:l.minCutOff,u_maxCutOff:l.maxCutOff,u_factor:l.factor,u_useGamma:l.useGamma,u_gamma:l.gamma,u_gammaCorrection:l.gammaCorrection}}function sn(l){return{u_hillshadeType:l.hillshadeType,u_sinZcosAs:l.sinZcosAs,u_sinZsinAs:l.sinZsinAs,u_cosZs:l.cosZs,u_weights:l.weights,u_factor:l.factor,u_minValue:l.minValue,u_maxValue:l.maxValue}}function ln(l,e){const t=l.gl,n=e.glName,o=t.getProgramParameter(n,t.ACTIVE_UNIFORMS),i=new Map;let a;for(let r=0;r<o;r++)a=t.getActiveUniform(n,r),a&&i.set(a.name,{location:t.getUniformLocation(n,a.name),info:a});return i}function Se(l,e,t){Object.keys(t).forEach(n=>{const o=e.get(n)||e.get(n+"[0]");o&&un(l,n,t[n],o)})}function cn(l,e,t,n){t.length===n.length&&(n.some(o=>o==null)||t.some(o=>o==null)||t.forEach((o,i)=>{e.setUniform1i(o,i),l.bindTexture(n[i],i)}))}function un(l,e,t,n){if(n===null||t==null)return!1;const{info:o}=n;switch(o.type){case Y.FLOAT:o.size>1?l.setUniform1fv(e,t):l.setUniform1f(e,t);break;case Y.FLOAT_VEC2:l.setUniform2fv(e,t);break;case Y.FLOAT_VEC3:l.setUniform3fv(e,t);break;case Y.FLOAT_VEC4:l.setUniform4fv(e,t);break;case Y.FLOAT_MAT3:l.setUniformMatrix3fv(e,t);break;case Y.FLOAT_MAT4:l.setUniformMatrix4fv(e,t);break;case Y.INT:o.size>1?l.setUniform1iv(e,t):l.setUniform1i(e,t);break;case Y.BOOL:l.setUniform1i(e,t?1:0);break;case Y.INT_VEC2:case Y.BOOL_VEC2:l.setUniform2iv(e,t);break;case Y.INT_VEC3:case Y.BOOL_VEC3:l.setUniform3iv(e,t);break;case Y.INT_VEC4:case Y.BOOL_VEC4:l.setUniform4iv(e,t);break;default:return!1}return!0}const fn={bandCount:3,outMin:0,outMax:1,minCutOff:[0,0,0],maxCutOff:[255,255,255],factor:[1/255,1/255,1/255],useGamma:!1,gamma:[1,1,1],gammaCorrection:[1,1,1],colormap:null,colormapOffset:null,stretchType:"none",type:"stretch"};class xi extends ot{constructor(e=null,t=null,n=null){super(),this._textureInvalidated=!0,this._colormapTextureInvalidated=!0,this._supportsBilinearTexture=!0,this.stencilRef=0,this.coordScale=[1,1],this._symbolizerParameters=null,this.height=null,this.isRendereredSource=!1,this.pixelRatio=1,this.resolution=0,this.rotation=0,this._source=null,this.rawPixelData=null,this._suspended=!1,this._bandIds=null,this._interpolation=null,this._transformGrid=null,this.width=null,this.x=0,this.y=0,this.source=e,this.transformGrid=t,this.interpolation=n}destroy(){var e;(e=this.getTextures())==null||e.textures.forEach(t=>t.dispose()),this._rasterTexture=null,this._transformGridTexture=null,this._colormapTexture=null}get symbolizerParameters(){return this._symbolizerParameters||fn}set symbolizerParameters(e){this._symbolizerParameters!==e&&(this._symbolizerParameters=e,this._colormapTextureInvalidated=!0)}get source(){return this._source}set source(e){this._source!==e&&(this._source=e,this._rasterTexture&&(this._rasterTexture.dispose(),this._rasterTexture=null,this._rasterTextureBandIds=null),this.invalidateTexture())}get suspended(){return this._suspended}set suspended(e){this._suspended&&!e&&this.stage&&(this.ready(),this.requestRender()),this._suspended=e}get bandIds(){return this._bandIds}set bandIds(e){this._bandIds=e,this._isBandIdschanged(e)&&this.invalidateTexture()}get interpolation(){return this._interpolation||"nearest"}set interpolation(e){this._interpolation=e,this._rasterTexture&&this._rasterTexture.setSamplingMode(this._getTextureSamplingMethod(e)==="bilinear"?N.LINEAR:N.NEAREST)}get transformGrid(){return this._transformGrid}set transformGrid(e){this._transformGrid=e,this._transformGridTexture&&(this._transformGridTexture.dispose(),this._transformGridTexture=null)}invalidateTexture(){this._textureInvalidated||(this._textureInvalidated=!0,this.requestRender())}_createTransforms(){return{dvs:_e()}}setTransform(e){const t=yt(this.transforms.dvs),[n,o]=e.toScreenNoRotation([0,0],[this.x,this.y]),i=this.resolution/this.pixelRatio/e.resolution,a=i*this.width,r=i*this.height,c=Math.PI*this.rotation/180;De(t,t,pe(n,o)),De(t,t,pe(a/2,r/2)),St(t,t,-c),De(t,t,pe(-a/2,-r/2)),Tt(t,t,pe(a,r)),bt(this.transforms.dvs,e.displayViewMat3,t)}getTextures(){if(!this._rasterTexture)return null;const e=[],t=[];return this._transformGridTexture&&(t.push(this._transformGridTexture),e.push("u_transformGrid")),this._rasterTexture&&(t.push(this._rasterTexture),e.push("u_image")),this._colormapTexture&&(t.push(this._colormapTexture),e.push("u_colormap")),{names:e,textures:t}}onAttach(){this.invalidateTexture()}onDetach(){this.invalidateTexture()}updateTexture({context:e}){var n,o,i;if(!this.stage)return(n=this._rasterTexture)==null||n.dispose(),(o=this._transformGridTexture)==null||o.dispose(),(i=this._colormapTexture)==null||i.dispose(),this._rasterTexture=null,this._rasterTextureBandIds=null,this._transformGridTexture=null,void(this._colormapTexture=null);const t=this._isValidSource(this.source);t&&this._colormapTextureInvalidated&&(this._colormapTextureInvalidated=!1,this._updateColormapTexture(e)),this._textureInvalidated&&(this._textureInvalidated=!1,this._createOrDestroyRasterTexture(e),this._rasterTexture&&(t?this.transformGrid&&!this._transformGridTexture&&(this._transformGridTexture=tn(e,this.transformGrid)):this._rasterTexture.setData(null)),this.suspended||(this.ready(),this.requestRender()))}_createOrDestroyRasterTexture(e){var a,r;const t=E(this.source)?Nt(this.source,this.bandIds):null;if(!this._isValidSource(t))return void(this._rasterTexture&&(this._rasterTexture.dispose(),this._rasterTextureBandIds=null,this._rasterTexture=null));const n=!this._isBandIdschanged(this.bandIds);if(this._rasterTexture){if(n)return;this._rasterTexture.dispose(),this._rasterTextureBandIds=null,this._rasterTexture=null}this._supportsBilinearTexture=(a=e.capabilities.textureFloat)==null?void 0:a.textureFloatLinear;const o=this._getTextureSamplingMethod(this.interpolation),i=this.isRendereredSource||!((r=e.capabilities.textureFloat)!=null&&r.textureFloat);this._rasterTexture=en(e,t,o,i),this._rasterTextureBandIds=this.bandIds?[...this.bandIds]:null}_isBandIdschanged(e){const t=this._rasterTextureBandIds;return!(t==null&&e==null||t&&e&&t.join("")===e.join(""))}_isValidSource(e){var t;return E(e)&&((t=e.pixels)==null?void 0:t.length)>0}_getTextureSamplingMethod(e){const{type:t,colormap:n}=this.symbolizerParameters,o=t==="lut"||t==="stretch"&&E(n);return!this._supportsBilinearTexture||o||e!=="bilinear"&&e!=="cubic"?"nearest":"bilinear"}_updateColormapTexture(e){const t=this._colormap,n=this.symbolizerParameters.colormap;return n?t?n.length!==t.length||n.some((o,i)=>o!==t[i])?(this._colormapTexture&&(this._colormapTexture.dispose(),this._colormapTexture=null),this._colormapTexture=Ke(e,n),void(this._colormap=n)):void 0:(this._colormapTexture=Ke(e,n),void(this._colormap=n)):(this._colormapTexture&&(this._colormapTexture.dispose(),this._colormapTexture=null),void(this._colormap=null))}}function _n(l){return E(l.source)}class we{constructor(e,t){this._rctx=e,this._vertexBuffer=ee.createVertex(e,J.STATIC_DRAW,new Uint16Array(t)),this._vao=new le(e,new Map([["a_position",0]]),{geometry:[new ge("a_position",2,m.SHORT,0,4)]},{geometry:this._vertexBuffer}),this._count=t.length/2}bind(){this._rctx.bindVAO(this._vao)}unbind(){this._rctx.bindVAO(null)}dispose(){this._vao.dispose(!1),this._vertexBuffer.dispose()}draw(){this._rctx.bindVAO(this._vao),this._rctx.drawArrays(R.TRIANGLE_STRIP,0,this._count)}}class dn extends W{constructor(){super(...arguments),this._desc={lut:{vsPath:"raster/lut",fsPath:"raster/lut",attributes:new Map([["a_position",0],["a_texcoord",1]])},stretch:{vsPath:"raster/stretch",fsPath:"raster/stretch",attributes:new Map([["a_position",0],["a_texcoord",1]])},hillshade:{vsPath:"raster/hillshade",fsPath:"raster/hillshade",attributes:new Map([["a_position",0],["a_texcoord",1]])}},this._rendererUniformInfos=new Map}dispose(){this._quad&&this._quad.dispose()}prepareState({context:e}){e.setBlendingEnabled(!0),e.setBlendFunctionSeparate(D.ONE,D.ONE_MINUS_SRC_ALPHA,D.ONE,D.ONE_MINUS_SRC_ALPHA),e.setColorMask(!0,!0,!0,!0),e.setStencilWriteMask(0),e.setStencilTestEnabled(!0)}draw(e,t){var s;if(!_n(t)||t.suspended)return;const{timeline:n,context:o,painter:i}=e;n.begin(this.name),o.setStencilFunction(V.EQUAL,t.stencilRef,255);const a=!((s=o.capabilities.textureFloat)!=null&&s.textureFloatLinear);t.updateTexture(e);const r=this._getShaderVariations(t,a),c=i.materialManager.getProgram(this._desc[t.symbolizerParameters.type],r);this._drawWithProgram(e,c,t),n.end(this.name)}_drawWithProgram({context:e,requestRender:t,allowDelayedRender:n},o,i,a=1,r=[0,0],c=!1){if(this._quad||(this._quad=new we(e,[0,0,1,0,0,1,1,1])),n&&E(t)&&!o.isCompiled)return void t();const{symbolizerParameters:s,transformGrid:u,width:f,height:_,opacity:v}=i,g=s.type;e.useProgram(o);const p=this._getShaderVariations(i),d=this._getUniformInfos(g,e,o,p),{names:I,textures:h}=i.getTextures();cn(e,o,I,h);const O=an(a,r),P=nn(u,[f,_],[i.source.width,i.source.height],v,c);if(Se(o,d,{u_coordScale:i.coordScale,u_dvsMat3:i.transforms.dvs,...O,...P}),s.colormap){const{colormap:S,colormapOffset:y}=s,x=on(S,y);Se(o,d,x)}if(s.type==="stretch"){const S=rn(s);Se(o,d,S)}else if(s.type==="hillshade"){const S=sn(s);Se(o,d,S)}this._quad.draw()}_getUniformInfos(e,t,n,o){const i=o.length>0?e+"-"+o.join("-"):e;if(this._rendererUniformInfos.has(i))return this._rendererUniformInfos.get(i);const a=ln(t,n);return this._rendererUniformInfos.set(i,a),a}_getShaderVariations(e,t=!1){const n=[],{interpolation:o}=e,{type:i,colormap:a}=e.symbolizerParameters;return o==="cubic"?n.push("bicubic"):o==="bilinear"&&i==="stretch"&&a!=null?(n.push("bilinear"),n.push("nnedge")):t&&o==="bilinear"&&n.push("bilinear"),e.isRendereredSource?n.push("noop"):a&&n.push("applyColormap"),e.transformGrid&&(n.push("applyProjection"),e.transformGrid.spacing[0]===1&&n.push("lookupProjection")),n}}const Te=new Float32Array([.27058823529411763,.4588235294117647,.7098039215686275,1,.396078431372549,.5372549019607843,.7215686274509804,1,.5176470588235295,.6196078431372549,.7294117647058823,1,.6352941176470588,.7058823529411765,.7411764705882353,1,.7529411764705882,.8,.7450980392156863,1,.8705882352941177,.8901960784313725,.7490196078431373,1,1,1,.7490196078431373,1,1,.8627450980392157,.6313725490196078,1,.9803921568627451,.7254901960784313,.5176470588235295,1,.9607843137254902,.596078431372549,.4117647058823529,1,.9294117647058824,.4588235294117647,.3176470588235294,1,.9098039215686274,.08235294117647059,.08235294117647059,1]),je={beaufort_ft:Te,beaufort_m:Te,beaufort_km:Te,beaufort_mi:Te,beaufort_kn:new Float32Array([.1568627450980392,.5725490196078431,.7803921568627451,1,.34901960784313724,.6352941176470588,.7294117647058823,1,.5058823529411764,.7019607843137254,.6705882352941176,1,.6274509803921569,.7607843137254902,.6078431372549019,1,.7490196078431373,.8313725490196079,.5411764705882353,1,.8549019607843137,.9019607843137255,.4666666666666667,1,.9803921568627451,.9803921568627451,.39215686274509803,1,.9882352941176471,.8352941176470589,.3254901960784314,1,.9882352941176471,.7019607843137254,.4,1,.9803921568627451,.5529411764705883,.20392156862745098,1,.9686274509803922,.43137254901960786,.16470588235294117,1,.9411764705882353,.2784313725490196,.11372549019607843,1]),classified_arrow:new Float32Array([.2196078431372549,.6588235294117647,0,1,.5450980392156862,1.2117647058823529,0,1,1,1,0,1,1,.5019607843137255,0,1,1,0,0,1]),ocean_current_m:new Float32Array([.3058823529411765,.10196078431372549,.6,1,.7019607843137254,.10588235294117647,.10196078431372549,1,.792156862745098,.5019607843137255,.10196078431372549,1,.6941176470588235,.6941176470588235,.6941176470588235,1]),ocean_current_kn:new Float32Array([0,0,0,1,0,.1450980392156863,.39215686274509803,1,.3058823529411765,.10196078431372549,.6,1,.592156862745098,0,.39215686274509803,1,.7019607843137254,.10588235294117647,.10196078431372549,1,.6941176470588235,.3058823529411765,.10196078431372549,1,.792156862745098,.5019607843137255,.10196078431372549,1,.6941176470588235,.7019607843137254,.20392156862745098,1,.6941176470588235,.6941176470588235,.6941176470588235,1]),single_arrow:new Float32Array([0,92/255,230/255,1]),wind_speed:new Float32Array([0,0,0,1])};class mn extends W{constructor(){super(...arguments),this._desc={magdir:{vsPath:"raster/magdir",fsPath:"raster/magdir",attributes:new Map([["a_pos",0],["a_offset",1],["a_vv",2]])},scalar:{vsPath:"raster/scalar",fsPath:"raster/scalar",attributes:new Map([["a_pos",0],["a_offset",1],["a_vv",2]])}}}dispose(){}prepareState({context:e}){e.setBlendingEnabled(!0),e.setBlendFunctionSeparate(D.ONE,D.ONE_MINUS_SRC_ALPHA,D.ONE,D.ONE_MINUS_SRC_ALPHA),e.setColorMask(!0,!0,!0,!0),e.setStencilWriteMask(0),e.setStencilTestEnabled(!0),e.setStencilOp(X.KEEP,X.KEEP,X.REPLACE)}draw(e,t){if(G(t.source)||t.source.validPixelCount===0)return;const{context:n,timeline:o}=e;if(o.begin(this.name),n.setStencilFunction(V.EQUAL,t.stencilRef,255),t.updateVectorFieldVAO(e),e.renderPass==="scalar"){const i=t.vaoData.scalar;i&&this._drawScalars(e,t,i.vao,i.elementCount)}else{const i=t.vaoData.magdir;i&&this._drawTriangles(e,t,i.vao,i.elementCount)}o.end(this.name)}_drawTriangles(e,t,n,o){const{context:i,painter:a,requestRender:r,allowDelayedRender:c}=e,{symbolizerParameters:s}=t,u=s.dataRange?["dataRange"]:[];s.rotationType==="geographic"&&u.push("rotationGeographic");const f=a.materialManager.getProgram(this._desc.magdir,u);if(c&&E(r)&&!f.isCompiled)return void r();i.useProgram(f);const{coordScale:_,opacity:v,transforms:g}=t;f.setUniform2fv("u_coordScale",_),f.setUniform1f("u_opacity",v),f.setUniformMatrix3fv("u_dvsMat3",g.dvs);const{style:p,dataRange:d,rotation:I,symbolPercentRange:h}=s;f.setUniform4fv("u_colors",je[p]||je.single_arrow),f.setUniform2fv("u_dataRange",d),f.setUniform1f("u_rotation",I),f.setUniform2fv("u_symbolPercentRange",h);const O=this._getSymbolSize(e,t);f.setUniform2fv("u_symbolSize",O),i.bindVAO(n),i.drawElements(R.TRIANGLES,o,m.UNSIGNED_INT,0)}_drawScalars(e,t,n,o){const{context:i,painter:a,requestRender:r,allowDelayedRender:c}=e,{symbolizerParameters:s}=t,u=[];s.style==="wind_speed"?u.push("innerCircle"):s.dataRange&&u.push("dataRange"),s.rotationType==="geographic"&&u.push("rotationGeographic");const f=a.materialManager.getProgram(this._desc.scalar,u);if(c&&E(r)&&!f.isCompiled)return void r();i.useProgram(f);const{coordScale:_,opacity:v,transforms:g}=t;f.setUniform2fv("u_coordScale",_),f.setUniform1f("u_opacity",v),f.setUniformMatrix3fv("u_dvsMat3",g.dvs);const{dataRange:p,symbolPercentRange:d}=s;f.setUniform2fv("u_dataRange",p),f.setUniform2fv("u_symbolPercentRange",d);const I=this._getSymbolSize(e,t);f.setUniform2fv("u_symbolSize",I),i.bindVAO(n),i.drawElements(R.TRIANGLES,o,m.UNSIGNED_INT,0)}_getSymbolSize(e,t){const n=t.key?2**(e.displayLevel-t.key.level):t.resolution/e.state.resolution,{symbolTileSize:o}=t.symbolizerParameters;return[o/(Math.round((t.width-t.offset[0])/o)*o)/n,o/(Math.round((t.height-t.offset[1])/o)*o)/n]}}const Le={nearest:{defines:[],samplingMode:N.NEAREST,mips:!1},bilinear:{defines:[],samplingMode:N.LINEAR,mips:!1},bicubic:{defines:["bicubic"],samplingMode:N.LINEAR,mips:!1},trilinear:{defines:[],samplingMode:N.LINEAR_MIPMAP_LINEAR,mips:!0}},vn=(l,e,t)=>{if(t.samplingMode==="dynamic"){const{state:n}=l,o=e.resolution/e.pixelRatio/n.resolution,i=Math.round(l.pixelRatio)!==l.pixelRatio,a=o>1.05||o<.95;return n.rotation||a||i||e.isSourceScaled||e.rotation?Le.bilinear:Le.nearest}return Le[t.samplingMode]};class pn extends W{constructor(){super(...arguments),this._desc={vsPath:"raster/bitmap",fsPath:"raster/bitmap",attributes:new Map([["a_pos",0]])}}dispose(){this._quad&&this._quad.dispose()}prepareState({context:e}){e.setBlendingEnabled(!0),e.setColorMask(!0,!0,!0,!0),e.setStencilWriteMask(0),e.setStencilTestEnabled(!0)}draw(e,t){const{context:n,renderingOptions:o,painter:i,requestRender:a,allowDelayedRender:r}=e;if(!t.source||!t.isReady)return;const c=vn(e,t,o),s=i.materialManager.getProgram(this._desc,c.defines);if(r&&E(a)&&!s.isCompiled)return void a();e.timeline.begin(this.name),t.blendFunction==="additive"?n.setBlendFunctionSeparate(D.ONE,D.ONE,D.ONE,D.ONE):n.setBlendFunctionSeparate(D.ONE,D.ONE_MINUS_SRC_ALPHA,D.ONE,D.ONE_MINUS_SRC_ALPHA),n.setStencilFunction(V.EQUAL,t.stencilRef,255),this._quad||(this._quad=new we(n,[0,0,1,0,0,1,1,1]));const{coordScale:u,computedOpacity:f,transforms:_}=t;t.setSamplingProfile(c),t.bind(e.context,Oe),n.useProgram(s),s.setUniformMatrix3fv("u_dvsMat3",_.dvs),s.setUniform1i("u_texture",Oe),s.setUniform2fv("u_coordScale",u),s.setUniform1f("u_opacity",f),this._quad.draw(),e.timeline.end(this.name)}}function ct(){return new Float32Array(4)}function gn(l){const e=new Float32Array(4);return e[0]=l[0],e[1]=l[1],e[2]=l[2],e[3]=l[3],e}function K(l,e,t,n){const o=new Float32Array(4);return o[0]=l,o[1]=e,o[2]=t,o[3]=n,o}function hn(l,e){return new Float32Array(l,e,4)}function ut(){return ct()}function ft(){return K(1,1,1,1)}function _t(){return K(1,0,0,0)}function dt(){return K(0,1,0,0)}function mt(){return K(0,0,1,0)}function vt(){return K(0,0,0,1)}const xn=ut(),yn=ft(),Sn=_t(),Tn=dt(),bn=mt(),En=vt();Object.freeze(Object.defineProperty({__proto__:null,create:ct,clone:gn,fromValues:K,createView:hn,zeros:ut,ones:ft,unitX:_t,unitY:dt,unitZ:mt,unitW:vt,ZEROS:xn,ONES:yn,UNIT_X:Sn,UNIT_Y:Tn,UNIT_Z:bn,UNIT_W:En},Symbol.toStringTag,{value:"Module"}));const In={background:{"background.frag":`uniform lowp vec4 u_color;
  2. void main() {
  3. gl_FragColor = u_color;
  4. }`,"background.vert":`attribute vec2 a_pos;
  5. uniform highp mat3 u_dvsMat3;
  6. uniform mediump vec2 u_coord_range;
  7. uniform mediump float u_depth;
  8. void main() {
  9. vec3 v_pos = u_dvsMat3 * vec3(u_coord_range * a_pos, 1.0);
  10. gl_Position = vec4(v_pos.xy, 0.0, 1.0);
  11. }`},bitBlit:{"bitBlit.frag":`uniform lowp sampler2D u_tex;
  12. uniform lowp float u_opacity;
  13. varying mediump vec2 v_uv;
  14. void main() {
  15. lowp vec4 color = texture2D(u_tex, v_uv);
  16. gl_FragColor = color * u_opacity;
  17. }`,"bitBlit.vert":`attribute vec2 a_pos;
  18. attribute vec2 a_tex;
  19. varying mediump vec2 v_uv;
  20. void main(void) {
  21. gl_Position = vec4(a_pos, 0.0, 1.0);
  22. v_uv = a_tex;
  23. }`},blend:{"blend.frag":`precision mediump float;
  24. uniform sampler2D u_layerTexture;
  25. uniform lowp float u_opacity;
  26. uniform lowp float u_inFadeOpacity;
  27. #ifndef NORMAL
  28. uniform sampler2D u_backbufferTexture;
  29. #endif
  30. varying mediump vec2 v_uv;
  31. float rgb2v(in vec3 c) {
  32. return max(c.x, max(c.y, c.z));
  33. }
  34. vec3 rgb2hsv(in vec3 c) {
  35. vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
  36. vec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
  37. vec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);
  38. float d = q.x - min(q.w, q.y);
  39. float e = 1.0e-10;
  40. return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), min(d / (q.x + e), 1.0), q.x);
  41. }
  42. vec3 hsv2rgb(in vec3 c) {
  43. vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
  44. vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
  45. return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
  46. }
  47. vec3 tint(in vec3 Cb, in vec3 Cs) {
  48. float vIn = rgb2v(Cb);
  49. vec3 hsvTint = rgb2hsv(Cs);
  50. vec3 hsvOut = vec3(hsvTint.x, hsvTint.y, vIn * hsvTint.z);
  51. return hsv2rgb(hsvOut);
  52. }
  53. float overlay(in float Cb, in float Cs) {
  54. return (1.0 - step(0.5, Cs)) * (1.0 - 2.0 * (1.0 - Cs ) * (1.0 - Cb)) + step(0.5, Cs) * (2.0 * Cs * Cb);
  55. }
  56. float colorDodge(in float Cb, in float Cs) {
  57. return (Cb == 0.0) ? 0.0 : (Cs == 1.0) ? 1.0 : min(1.0, Cb / (1.0 - Cs));
  58. }
  59. float colorBurn(in float Cb, in float Cs) {
  60. return (Cb == 1.0) ? 1.0 : (Cs == 0.0) ? 0.0 : 1.0 - min(1.0, (1.0 - Cb) / Cs);
  61. }
  62. float hardLight(in float Cb, in float Cs) {
  63. return (1.0 - step(0.5, Cs)) * (2.0 * Cs * Cb) + step(0.5, Cs) * (1.0 - 2.0 * (1.0 - Cs) * (1.0 - Cb));
  64. }
  65. float reflectBlend(in float Cb, in float Cs) {
  66. return (Cs == 1.0) ? Cs : min(Cb * Cb / (1.0 - Cs), 1.0);
  67. }
  68. float softLight(in float Cb, in float Cs) {
  69. if (Cs <= 0.5) {
  70. return Cb - (1.0 - 2.0 * Cs) * Cb * (1.0 - Cb);
  71. }
  72. if (Cb <= 0.25) {
  73. return Cb + (2.0 * Cs - 1.0) * Cb * ((16.0 * Cb - 12.0) * Cb + 3.0);
  74. }
  75. return Cb + (2.0 * Cs - 1.0) * (sqrt(Cb) - Cb);
  76. }
  77. float vividLight(in float Cb, in float Cs) {
  78. return (1.0 - step(0.5, Cs)) * colorBurn(Cb, 2.0 * Cs) + step(0.5, Cs) * colorDodge(Cb, (2.0 * (Cs - 0.5)));
  79. }
  80. float minv3(in vec3 c) {
  81. return min(min(c.r, c.g), c.b);
  82. }
  83. float maxv3(in vec3 c) {
  84. return max(max(c.r, c.g), c.b);
  85. }
  86. float lumv3(in vec3 c) {
  87. return dot(c, vec3(0.3, 0.59, 0.11));
  88. }
  89. float satv3(vec3 c) {
  90. return maxv3(c) - minv3(c);
  91. }
  92. vec3 clipColor(vec3 color) {
  93. float lum = lumv3(color);
  94. float mincol = minv3(color);
  95. float maxcol = maxv3(color);
  96. if (mincol < 0.0) {
  97. color = lum + ((color - lum) * lum) / (lum - mincol);
  98. }
  99. if (maxcol > 1.0) {
  100. color = lum + ((color - lum) * (1.0 - lum)) / (maxcol - lum);
  101. }
  102. return color;
  103. }
  104. vec3 setLum(vec3 cbase, vec3 clum) {
  105. float lbase = lumv3(cbase);
  106. float llum = lumv3(clum);
  107. float ldiff = llum - lbase;
  108. vec3 color = cbase + vec3(ldiff);
  109. return clipColor(color);
  110. }
  111. vec3 setLumSat(vec3 cbase, vec3 csat, vec3 clum)
  112. {
  113. float minbase = minv3(cbase);
  114. float sbase = satv3(cbase);
  115. float ssat = satv3(csat);
  116. vec3 color;
  117. if (sbase > 0.0) {
  118. color = (cbase - minbase) * ssat / sbase;
  119. } else {
  120. color = vec3(0.0);
  121. }
  122. return setLum(color, clum);
  123. }
  124. void main() {
  125. vec4 src = texture2D(u_layerTexture, v_uv);
  126. #ifdef NORMAL
  127. gl_FragColor = src * u_opacity;
  128. #else
  129. vec4 dst = texture2D(u_backbufferTexture, v_uv);
  130. vec3 Cs = src.a == 0.0 ? src.rgb : vec3(src.rgb / src.a);
  131. vec3 Cb = dst.a == 0.0 ? dst.rgb : vec3(dst.rgb / dst.a);
  132. float as = u_opacity * src.a;
  133. float ab = dst.a;
  134. #ifdef DESTINATION_OVER
  135. gl_FragColor = vec4(as * Cs * (1.0 - ab) + ab * Cb, as + ab - as * ab);
  136. #endif
  137. #ifdef SOURCE_IN
  138. vec4 color = vec4(as * Cs * ab, as * ab);
  139. vec4 fadeColor = (1.0 - u_opacity) * u_inFadeOpacity * vec4(ab * Cb, ab);
  140. gl_FragColor = color + fadeColor;
  141. #endif
  142. #ifdef DESTINATION_IN
  143. vec4 color = vec4(ab * Cb * as, ab * as);
  144. vec4 fadeColor = (1.0 - u_opacity) * u_inFadeOpacity * vec4(ab * Cb, ab);
  145. gl_FragColor = color + fadeColor;
  146. #endif
  147. #ifdef SOURCE_OUT
  148. gl_FragColor = vec4(as * Cs * (1.0 - ab), as * (1.0 - ab));
  149. #endif
  150. #ifdef DESTINATION_OUT
  151. gl_FragColor = vec4(ab * Cb * (1.0 - as), ab * (1.0 - as));
  152. #endif
  153. #ifdef SOURCE_ATOP
  154. gl_FragColor = vec4(as * Cs * ab + ab * Cb * (1.0 - as), ab);
  155. #endif
  156. #ifdef DESTINATION_ATOP
  157. gl_FragColor = vec4(as * Cs * (1.0 - ab) + ab * Cb * as, as);
  158. #endif
  159. #ifdef XOR
  160. gl_FragColor = vec4(as * Cs * (1.0 - ab) + ab * Cb * (1.0 - as),
  161. as * (1.0 - ab) + ab * (1.0 - as));
  162. #endif
  163. #ifdef MULTIPLY
  164. gl_FragColor = vec4(as * Cs * ab * Cb + (1.0 - ab) * as * Cs + (1.0 - as) * ab * Cb,
  165. as + ab * (1.0 - as));
  166. #endif
  167. #ifdef SCREEN
  168. gl_FragColor = vec4((Cs + Cb - Cs * Cb) * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  169. as + ab * (1.0 - as));
  170. #endif
  171. #ifdef OVERLAY
  172. vec3 f = vec3(overlay(Cb.r, Cs.r), overlay(Cb.g, Cs.g), overlay(Cb.b, Cs.b));
  173. gl_FragColor = vec4(f * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  174. as + ab * (1.0 - as));
  175. #endif
  176. #ifdef DARKEN
  177. gl_FragColor = vec4(min(Cs, Cb) * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  178. as + ab * (1.0 - as));
  179. #endif
  180. #ifdef LIGHTER
  181. gl_FragColor = vec4(as * Cs + ab * Cb, as + ab);
  182. #endif
  183. #ifdef LIGHTEN
  184. gl_FragColor = vec4(max(Cs, Cb) * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  185. as + ab * (1.0 - as));
  186. #endif
  187. #ifdef COLOR_DODGE
  188. vec3 f = clamp(vec3(colorDodge(Cb.r, Cs.r), colorDodge(Cb.g, Cs.g), colorDodge(Cb.b, Cs.b)), vec3(0.0), vec3(1.0));
  189. gl_FragColor = vec4(f * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  190. as + ab * (1.0 - as));
  191. #endif
  192. #ifdef COLOR_BURN
  193. vec3 f = vec3(colorBurn(Cb.r, Cs.r), colorBurn(Cb.g, Cs.g), colorBurn(Cb.b, Cs.b));
  194. gl_FragColor = vec4(f * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  195. as + ab * (1.0 - as));
  196. #endif
  197. #ifdef HARD_LIGHT
  198. vec3 f = vec3(hardLight(Cb.r, Cs.r), hardLight(Cb.g, Cs.g), hardLight(Cb.b, Cs.b));
  199. gl_FragColor = vec4(f * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  200. as + ab * (1.0 - as));
  201. #endif
  202. #ifdef SOFT_LIGHT
  203. vec3 f = vec3(softLight(Cb.r, Cs.r), softLight(Cb.g, Cs.g), softLight(Cb.b, Cs.b));
  204. gl_FragColor = vec4(f * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  205. as + ab * (1.0 - as));
  206. #endif
  207. #ifdef DIFFERENCE
  208. gl_FragColor = vec4(abs(Cb - Cs) * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  209. as + ab * (1.0 - as));
  210. #endif
  211. #ifdef EXCLUSION
  212. vec3 f = Cs + Cb - 2.0 * Cs * Cb;
  213. gl_FragColor = vec4(f * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  214. as + ab * (1.0 - as));
  215. #endif
  216. #ifdef INVERT
  217. gl_FragColor = vec4((1.0 - Cb) * as * ab + Cb * ab * (1.0 - as), ab);
  218. #endif
  219. #ifdef VIVID_LIGHT
  220. vec3 f = vec3(clamp(vividLight(Cb.r, Cs.r), 0.0, 1.0),
  221. clamp(vividLight(Cb.g, Cs.g), 0.0, 1.0),
  222. clamp(vividLight(Cb.b, Cs.b), 0.0, 1.0));
  223. gl_FragColor = vec4(f * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  224. as + ab * (1.0 - as));
  225. #endif
  226. #ifdef HUE
  227. vec3 f = setLumSat(Cs,Cb,Cb);
  228. gl_FragColor = vec4(f * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  229. as + ab * (1.0 - as));
  230. #endif
  231. #ifdef SATURATION
  232. vec3 f = setLumSat(Cb,Cs,Cb);
  233. gl_FragColor = vec4(f * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  234. as + ab * (1.0 - as));
  235. #endif
  236. #ifdef COLOR
  237. vec3 f = setLum(Cs,Cb);
  238. gl_FragColor = vec4(f * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  239. as + ab * (1.0 - as));
  240. #endif
  241. #ifdef LUMINOSITY
  242. vec3 f = setLum(Cb,Cs);
  243. gl_FragColor = vec4(f * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  244. as + ab * (1.0 - as));
  245. #endif
  246. #ifdef PLUS
  247. gl_FragColor = clamp(vec4(src.r + Cb.r, src.g + Cb.g, src.b + Cb.b, as + ab), 0.0, 1.0);
  248. #endif
  249. #ifdef MINUS
  250. gl_FragColor = vec4(clamp(vec3(Cb.r - src.r, Cb.g - src.g, Cb.b - src.b), 0.0, 1.0), ab * as);
  251. #endif
  252. #ifdef AVERAGE
  253. vec3 f = (Cb + Cs) / 2.0;
  254. gl_FragColor = vec4(f * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  255. as + ab * (1.0 - as));
  256. #endif
  257. #ifdef REFLECT
  258. vec3 f = clamp(vec3(reflectBlend(Cb.r, Cs.r),
  259. reflectBlend(Cb.g, Cs.g),
  260. reflectBlend(Cb.b, Cs.b)), vec3(0.0), vec3(1.0));
  261. gl_FragColor = vec4(f * as * ab + Cs * as * (1.0 - ab) + Cb * ab *(1.0 - as),
  262. as + ab * (1.0 - as));
  263. #endif
  264. #endif
  265. }`,"blend.vert":`attribute vec2 a_position;
  266. varying mediump vec2 v_uv;
  267. void main(void) {
  268. gl_Position = vec4(a_position , 0.0, 1.0);
  269. v_uv = (a_position + 1.0) / 2.0;
  270. }`},debug:{overlay:{"overlay.frag":`precision mediump float;
  271. varying vec4 v_color;
  272. void main(void) {
  273. gl_FragColor = v_color;
  274. }`,"overlay.vert":`attribute vec3 a_PositionAndFlags;
  275. uniform mat3 u_dvsMat3;
  276. uniform vec4 u_colors[4];
  277. uniform float u_opacities[4];
  278. varying vec4 v_color;
  279. void main(void) {
  280. vec2 position = a_PositionAndFlags.xy;
  281. float flags = a_PositionAndFlags.z;
  282. int colorIndex = int(mod(flags, 4.0));
  283. vec4 color;
  284. for (int i = 0; i < 4; i++) {
  285. color = u_colors[i];
  286. if (i == colorIndex) {
  287. break;
  288. }
  289. }
  290. int opacityIndex = int(mod(floor(flags / 4.0), 4.0));
  291. float opacity;
  292. for (int i = 0; i < 4; i++) {
  293. opacity = u_opacities[i];
  294. if (i == opacityIndex) {
  295. break;
  296. }
  297. }
  298. v_color = color * opacity;
  299. gl_Position = vec4((u_dvsMat3 * vec3(position, 1.0)).xy, 0.0, 1.0);
  300. }`}},dot:{dot:{"dot.frag":`precision mediump float;
  301. varying vec4 v_color;
  302. varying float v_dotRatio;
  303. varying float v_invEdgeRatio;
  304. uniform highp float u_tileZoomFactor;
  305. void main()
  306. {
  307. float dist = length(gl_PointCoord - vec2(.5, .5)) * 2.;
  308. float alpha = smoothstep(0., 1., v_invEdgeRatio * (dist - v_dotRatio) + 1.);
  309. gl_FragColor = v_color * alpha;
  310. }`,"dot.vert":`precision highp float;
  311. attribute vec2 a_pos;
  312. uniform sampler2D u_texture;
  313. uniform highp mat3 u_dvsMat3;
  314. uniform highp float u_tileZoomFactor;
  315. uniform highp float u_dotSize;
  316. uniform highp float u_pixelRatio;
  317. varying vec2 v_pos;
  318. varying vec4 v_color;
  319. varying float v_dotRatio;
  320. varying float v_invEdgeRatio;
  321. const float EPSILON = 0.000001;
  322. void main()
  323. {
  324. mat3 tileToTileTexture = mat3( 1., 0., 0.,
  325. 0., -1., 0.,
  326. 0., 1., 1. );
  327. vec3 texCoords = tileToTileTexture * vec3(a_pos.xy / 512., 1.);
  328. v_color = texture2D(u_texture, texCoords.xy);
  329. float smoothEdgeWidth = max(u_dotSize / 2., 1.) ;
  330. float z = 0.;
  331. z += 2.0 * step(v_color.a, EPSILON);
  332. gl_PointSize = (smoothEdgeWidth + u_dotSize);
  333. gl_Position = vec4((u_dvsMat3 * vec3(a_pos + .5, 1.)).xy, z, 1.);
  334. v_dotRatio = u_dotSize / gl_PointSize;
  335. v_invEdgeRatio = -1. / ( smoothEdgeWidth / gl_PointSize );
  336. gl_PointSize *= (u_pixelRatio * u_tileZoomFactor);
  337. }`}},filtering:{"bicubic.glsl":`vec4 computeWeights(float v) {
  338. float b = 1.0 / 6.0;
  339. float v2 = v * v;
  340. float v3 = v2 * v;
  341. float w0 = b * (-v3 + 3.0 * v2 - 3.0 * v + 1.0);
  342. float w1 = b * (3.0 * v3 - 6.0 * v2 + 4.0);
  343. float w2 = b * (-3.0 * v3 + 3.0 * v2 + 3.0 * v + 1.0);
  344. float w3 = b * v3;
  345. return vec4(w0, w1, w2, w3);
  346. }
  347. vec4 bicubicOffsetsAndWeights(float v) {
  348. vec4 w = computeWeights(v);
  349. float g0 = w.x + w.y;
  350. float g1 = w.z + w.w;
  351. float h0 = 1.0 - (w.y / g0) + v;
  352. float h1 = 1.0 + (w.w / g1) - v;
  353. return vec4(h0, h1, g0, g1);
  354. }
  355. vec4 sampleBicubicBSpline(sampler2D sampler, vec2 coords, vec2 texSize) {
  356. vec2 eX = vec2(1.0 / texSize.x, 0.0);
  357. vec2 eY = vec2(0.0, 1.0 / texSize.y);
  358. vec2 texel = coords * texSize - 0.5;
  359. vec3 hgX = bicubicOffsetsAndWeights(fract(texel).x).xyz;
  360. vec3 hgY = bicubicOffsetsAndWeights(fract(texel).y).xyz;
  361. vec2 coords10 = coords + hgX.x * eX;
  362. vec2 coords00 = coords - hgX.y * eX;
  363. vec2 coords11 = coords10 + hgY.x * eY;
  364. vec2 coords01 = coords00 + hgY.x * eY;
  365. coords10 = coords10 - hgY.y * eY;
  366. coords00 = coords00 - hgY.y * eY;
  367. vec4 color00 = texture2D(sampler, coords00);
  368. vec4 color10 = texture2D(sampler, coords10);
  369. vec4 color01 = texture2D(sampler, coords01);
  370. vec4 color11 = texture2D(sampler, coords11);
  371. color00 = mix(color00, color01, hgY.z);
  372. color10 = mix(color10, color11, hgY.z);
  373. color00 = mix(color00, color10, hgX.z);
  374. return color00;
  375. }`,"bilinear.glsl":`vec4 sampleBilinear(sampler2D sampler, vec2 coords, vec2 texSize) {
  376. vec2 texelStart = floor(coords * texSize);
  377. vec2 coord0 = texelStart / texSize;
  378. vec2 coord1 = (texelStart + vec2(1.0, 0.0)) / texSize;
  379. vec2 coord2 = (texelStart + vec2(0.0, 1.0)) / texSize;
  380. vec2 coord3 = (texelStart + vec2(1.0, 1.0)) / texSize;
  381. vec4 color0 = texture2D(sampler, coord0);
  382. vec4 color1 = texture2D(sampler, coord1);
  383. vec4 color2 = texture2D(sampler, coord2);
  384. vec4 color3 = texture2D(sampler, coord3);
  385. vec2 blend = fract(coords * texSize);
  386. vec4 color01 = mix(color0, color1, blend.x);
  387. vec4 color23 = mix(color2, color3, blend.x);
  388. vec4 color = mix(color01, color23, blend.y);
  389. #ifdef NNEDGE
  390. float alpha = floor(color0.a * color1.a * color2.a * color3.a + 0.5);
  391. color = color * alpha + (1.0 - alpha) * texture2D(sampler, coords);
  392. #endif
  393. return color;
  394. }`,"epx.glsl":`vec4 sampleEPX(sampler2D sampler, float size, vec2 coords, vec2 texSize) {
  395. vec2 invSize = 1.0 / texSize;
  396. vec2 texel = coords * texSize;
  397. vec2 texel_i = floor(texel);
  398. vec2 texel_frac = fract(texel);
  399. vec4 colorP = texture2D(sampler, texel_i * invSize);
  400. vec4 colorP1 = vec4(colorP);
  401. vec4 colorP2 = vec4(colorP);
  402. vec4 colorP3 = vec4(colorP);
  403. vec4 colorP4 = vec4(colorP);
  404. vec4 colorA = texture2D(sampler, (texel_i - vec2(0.0, 1.0)) * invSize);
  405. vec4 colorB = texture2D(sampler, (texel_i + vec2(1.0, 0.0)) * invSize);
  406. vec4 colorC = texture2D(sampler, (texel_i - vec2(1.0, 0.0)) * invSize);
  407. vec4 colorD = texture2D(sampler, (texel_i + vec2(0.0, 1.0)) * invSize);
  408. if (colorC == colorA && colorC != colorD && colorA != colorB) {
  409. colorP1 = colorA;
  410. }
  411. if (colorA == colorB && colorA != colorC && colorB != colorD) {
  412. colorP2 = colorB;
  413. }
  414. if (colorD == colorC && colorD != colorB && colorC != colorA) {
  415. colorP3 = colorC;
  416. }
  417. if (colorB == colorD && colorB != colorA && colorD != colorC) {
  418. colorP4 = colorD;
  419. }
  420. vec4 colorP12 = mix(colorP1, colorP2, texel_frac.x);
  421. vec4 colorP34 = mix(colorP1, colorP2, texel_frac.x);
  422. return mix(colorP12, colorP34, texel_frac.y);
  423. }`},fx:{integrate:{"integrate.frag":`precision mediump float;
  424. uniform lowp sampler2D u_sourceTexture;
  425. uniform lowp sampler2D u_maskTexture;
  426. uniform mediump float u_zoomLevel;
  427. uniform highp float u_timeDelta;
  428. uniform highp float u_animationTime;
  429. varying highp vec2 v_texcoord;
  430. #include <materials/utils.glsl>
  431. void main()
  432. {
  433. #ifdef DELTA
  434. vec4 texel = texture2D(u_sourceTexture, v_texcoord);
  435. vec4 data0 = texture2D(u_maskTexture, v_texcoord);
  436. float flags = data0.r * 255.0;
  437. float groupMinZoom = data0.g * 255.0;
  438. float isVisible = getFilterBit(flags, 0);
  439. float wouldClip = step(groupMinZoom, u_zoomLevel);
  440. float direction = wouldClip * 1.0 + (1.0 - wouldClip) * -1.0;
  441. float dt = u_timeDelta / max(u_animationTime, 0.0001);
  442. vec4 nextState = vec4(texel + direction * dt);
  443. gl_FragColor = vec4(nextState);
  444. #elif defined(UPDATE)
  445. vec4 texel = texture2D(u_sourceTexture, v_texcoord);
  446. gl_FragColor = texel;
  447. #endif
  448. }`,"integrate.vert":`precision mediump float;
  449. attribute vec2 a_pos;
  450. varying highp vec2 v_texcoord;
  451. void main()
  452. {
  453. v_texcoord = a_pos;
  454. gl_Position = vec4(a_pos * 2.0 - 1.0, 0.0, 1.0);
  455. }`}},heatmap:{heatmapResolve:{"heatmapResolve.frag":`precision highp float;
  456. #ifdef HEATMAP_PRECISION_HALF_FLOAT
  457. #define COMPRESSION_FACTOR 4.0
  458. #else
  459. #define COMPRESSION_FACTOR 1.0
  460. #endif
  461. uniform sampler2D u_texture;
  462. uniform sampler2D u_gradient;
  463. uniform vec2 u_densityMinAndInvRange;
  464. uniform float u_densityNormalization;
  465. varying vec2 v_uv;
  466. void main() {
  467. vec4 data = texture2D(u_texture, v_uv);
  468. float density = data.r * COMPRESSION_FACTOR;
  469. density *= u_densityNormalization;
  470. density = (density - u_densityMinAndInvRange.x) * u_densityMinAndInvRange.y;
  471. vec4 color = texture2D(u_gradient, vec2(density, 0.5));
  472. gl_FragColor = vec4(color.rgb * color.a, color.a);
  473. }`,"heatmapResolve.vert":`precision highp float;
  474. attribute vec2 a_pos;
  475. varying vec2 v_uv;
  476. void main() {
  477. v_uv = a_pos;
  478. gl_Position = vec4(a_pos * 2.0 - 1.0, 1., 1.);
  479. }`}},highlight:{"blur.frag":`varying mediump vec2 v_texcoord;
  480. uniform mediump vec4 u_direction;
  481. uniform mediump mat4 u_channelSelector;
  482. uniform mediump float u_sigma;
  483. uniform sampler2D u_texture;
  484. mediump float gauss1(mediump vec2 dir) {
  485. return exp(-dot(dir, dir) / (2.0 * u_sigma * u_sigma));
  486. }
  487. mediump vec4 selectChannel(mediump vec4 sample) {
  488. return u_channelSelector * sample;
  489. }
  490. void accumGauss1(mediump float i, inout mediump float tot, inout mediump float weight) {
  491. mediump float w = gauss1(i * u_direction.xy);
  492. tot += selectChannel(texture2D(u_texture, v_texcoord + i * u_direction.zw))[3] * w;
  493. weight += w;
  494. }
  495. void main(void) {
  496. mediump float tot = 0.0;
  497. mediump float weight = 0.0;
  498. accumGauss1(-5.0, tot, weight);
  499. accumGauss1(-4.0, tot, weight);
  500. accumGauss1(-3.0, tot, weight);
  501. accumGauss1(-2.0, tot, weight);
  502. accumGauss1(-1.0, tot, weight);
  503. accumGauss1(0.0, tot, weight);
  504. accumGauss1(1.0, tot, weight);
  505. accumGauss1(2.0, tot, weight);
  506. accumGauss1(3.0, tot, weight);
  507. accumGauss1(4.0, tot, weight);
  508. accumGauss1(5.0, tot, weight);
  509. gl_FragColor = vec4(0.0, 0.0, 0.0, tot / weight);
  510. }`,"highlight.frag":`varying mediump vec2 v_texcoord;
  511. uniform sampler2D u_texture;
  512. uniform mediump float u_sigma;
  513. uniform sampler2D u_shade;
  514. uniform mediump vec2 u_minMaxDistance;
  515. mediump float estimateDistance() {
  516. mediump float y = texture2D(u_texture, v_texcoord)[3];
  517. const mediump float y0 = 0.5;
  518. mediump float m0 = 1.0 / (sqrt(2.0 * 3.1415) * u_sigma);
  519. mediump float d = (y - y0) / m0;
  520. return d;
  521. }
  522. mediump vec4 shade(mediump float d) {
  523. mediump float mappedDistance = (d - u_minMaxDistance.x) / (u_minMaxDistance.y - u_minMaxDistance.x);
  524. mappedDistance = clamp(mappedDistance, 0.0, 1.0);
  525. return texture2D(u_shade, vec2(mappedDistance, 0.5));
  526. }
  527. void main(void) {
  528. mediump float d = estimateDistance();
  529. gl_FragColor = shade(d);
  530. }`,"textured.vert":`attribute mediump vec2 a_position;
  531. attribute mediump vec2 a_texcoord;
  532. varying mediump vec2 v_texcoord;
  533. void main(void) {
  534. gl_Position = vec4(a_position, 0.0, 1.0);
  535. v_texcoord = a_texcoord;
  536. }`},magnifier:{"magnifier.frag":`uniform lowp vec4 u_background;
  537. uniform mediump sampler2D u_readbackTexture;
  538. uniform mediump sampler2D u_maskTexture;
  539. uniform mediump sampler2D u_overlayTexture;
  540. uniform bool u_maskEnabled;
  541. uniform bool u_overlayEnabled;
  542. varying mediump vec2 v_texCoord;
  543. const lowp float barrelFactor = 1.1;
  544. lowp vec2 barrel(lowp vec2 uv) {
  545. lowp vec2 uvn = uv * 2.0 - 1.0;
  546. if (uvn.x == 0.0 && uvn.y == 0.0) {
  547. return vec2(0.5, 0.5);
  548. }
  549. lowp float theta = atan(uvn.y, uvn.x);
  550. lowp float r = pow(length(uvn), barrelFactor);
  551. return r * vec2(cos(theta), sin(theta)) * 0.5 + 0.5;
  552. }
  553. void main(void)
  554. {
  555. lowp vec4 color = texture2D(u_readbackTexture, barrel(v_texCoord));
  556. color = (color + (1.0 - color.a) * u_background);
  557. lowp float mask = u_maskEnabled ? texture2D(u_maskTexture, v_texCoord).a : 1.0;
  558. color *= mask;
  559. lowp vec4 overlayColor = u_overlayEnabled ? texture2D(u_overlayTexture, v_texCoord) : vec4(0);
  560. gl_FragColor = overlayColor + (1.0 - overlayColor.a) * color;
  561. }`,"magnifier.vert":`precision mediump float;
  562. attribute mediump vec2 a_pos;
  563. uniform mediump vec4 u_drawPos;
  564. varying mediump vec2 v_texCoord;
  565. void main(void)
  566. {
  567. v_texCoord = a_pos;
  568. gl_Position = vec4(u_drawPos.xy + vec2(a_pos - 0.5) * u_drawPos.zw, 0.0, 1.0);
  569. }`},materials:{"attributeData.glsl":`uniform highp sampler2D u_attributeData0;
  570. uniform highp sampler2D u_attributeData1;
  571. uniform highp sampler2D u_attributeData2;
  572. uniform highp sampler2D u_attributeData3;
  573. uniform highp sampler2D u_attributeData4;
  574. uniform highp sampler2D u_attributeData5;
  575. uniform highp int u_attributeTextureSize;
  576. highp vec2 getAttributeDataCoords(in highp vec3 id) {
  577. highp vec3 texel = unpackDisplayIdTexel(id);
  578. highp float size = float(u_attributeTextureSize);
  579. highp float u32 = float(int(texel.r) + int(texel.g) * 256 + int(texel.b) * 256 * 256);
  580. highp float col = mod(u32, size);
  581. highp float row = (u32 - col) / size;
  582. highp float u = col / size;
  583. highp float v = row / size;
  584. return vec2(u, v);
  585. }
  586. highp vec2 getAttributeDataTextureCoords(in highp vec3 id) {
  587. return (getAttributeDataCoords(id) * 2.0) - 1.0 + (.5 / vec2(u_attributeTextureSize));
  588. }
  589. highp vec4 getAttributeData0(in highp vec3 id) {
  590. vec2 coords = getAttributeDataCoords(id);
  591. return texture2D(u_attributeData0, coords);
  592. }
  593. highp vec4 getAttributeData1(in highp vec3 id) {
  594. highp vec2 coords = getAttributeDataCoords(id);
  595. return texture2D(u_attributeData1, coords);
  596. }
  597. highp vec4 getAttributeData2(in highp vec3 id) {
  598. highp vec2 coords = getAttributeDataCoords(id);
  599. return texture2D(u_attributeData2, coords);
  600. }
  601. highp vec4 getAttributeData3(in highp vec3 id) {
  602. highp vec2 coords = getAttributeDataCoords(id);
  603. return texture2D(u_attributeData3, coords);
  604. }
  605. highp vec4 getAttributeData4(in highp vec3 id) {
  606. highp vec2 coords = getAttributeDataCoords(id);
  607. return texture2D(u_attributeData4, coords);
  608. }
  609. highp vec4 getAttributeData5(in highp vec3 id) {
  610. highp vec2 coords = getAttributeDataCoords(id);
  611. return texture2D(u_attributeData5, coords);
  612. }
  613. float u88VVToFloat(in vec2 v) {
  614. bool isMagic = v.x == 255.0 && v.y == 255.0;
  615. if (isMagic) {
  616. return NAN_MAGIC_NUMBER;
  617. }
  618. return (v.x + v.y * float(0x100)) - 32768.0;
  619. }`,"barycentric.glsl":`float inTriangle(vec3 bary) {
  620. vec3 absBary = abs(bary);
  621. return step((absBary.x + absBary.y + absBary.z), 1.05);
  622. }
  623. vec3 xyToBarycentric(in vec2 pos, in vec2 v0, in vec2 v1, in vec2 v2) {
  624. mat3 xyToBarycentricMat3 = mat3(
  625. v1.x * v2.y - v2.x * v1.y, v2.x * v0.y - v0.x * v2.y, v0.x * v1.y - v1.x * v0.y,
  626. v1.y - v2.y, v2.y - v0.y, v0.y - v1.y,
  627. v2.x - v1.x, v0.x - v2.x, v1.x - v0.x
  628. );
  629. float A2 = v0.x * (v1.y - v2.y) + v1.x * (v2.y - v0.y) + v2.x * (v0.y - v1.y);
  630. return (1. / A2) * xyToBarycentricMat3 * vec3(1., pos);
  631. }`,"constants.glsl":`const float C_DEG_TO_RAD = 3.14159265359 / 180.0;
  632. const float C_256_TO_RAD = 3.14159265359 / 128.0;
  633. const float C_RAD_TO_DEG = 180.0 / 3.141592654;
  634. const float POSITION_PRECISION = 1.0 / 8.0;
  635. const float FILL_POSITION_PRECISION = 1.0 / 1.0;
  636. const float SOFT_EDGE_RATIO = 1.0;
  637. const float THIN_LINE_WIDTH_FACTOR = 1.1;
  638. const float THIN_LINE_HALF_WIDTH = 1.0;
  639. const float EXTRUDE_SCALE_PLACEMENT_PADDING = 1.0 / 4.0;
  640. const float OFFSET_PRECISION = 1.0 / 8.0;
  641. const float OUTLINE_SCALE = 1.0 / 5.0;
  642. const float SDF_FONT_SIZE = 24.0;
  643. const float MAX_SDF_DISTANCE = 8.0;
  644. const float PLACEMENT_PADDING = 8.0;
  645. const float EPSILON = 0.00001;
  646. const float EPSILON_HITTEST = 0.05;
  647. const int MAX_FILTER_COUNT = 2;
  648. const int ATTR_VV_SIZE = 0;
  649. const int ATTR_VV_COLOR = 1;
  650. const int ATTR_VV_OPACITY = 2;
  651. const int ATTR_VV_ROTATION = 3;
  652. const highp float NAN_MAGIC_NUMBER = 1e-30;
  653. const int BITSET_GENERIC_LOCK_COLOR = 1;
  654. const int BITSET_GENERIC_CONSIDER_ALPHA_ONLY = 4;
  655. const int BITSET_MARKER_ALIGNMENT_MAP = 0;
  656. const int BITSET_MARKER_OUTLINE_ALLOW_COLOR_OVERRIDE = 2;
  657. const int BITSET_MARKER_SCALE_SYMBOLS_PROPORTIONALLY = 3;
  658. const int BITSET_TYPE_FILL_OUTLINE = 0;
  659. const int BITSET_FILL_RANDOM_PATTERN_OFFSET = 2;
  660. const int BITSET_LINE_SCALE_DASH = 2;`,fill:{"common.glsl":`#include <materials/symbologyTypeUtils.glsl>
  661. #ifdef PATTERN
  662. uniform mediump vec2 u_mosaicSize;
  663. varying mediump float v_sampleAlphaOnly;
  664. #endif
  665. #if SYMBOLOGY_TYPE == SYMBOLOGY_TYPE_DOT_DENSITY
  666. uniform lowp vec4 u_isActive[ 2 ];
  667. uniform highp float u_dotValue;
  668. uniform highp float u_tileDotsOverArea;
  669. uniform highp float u_dotTextureDotCount;
  670. uniform mediump float u_tileZoomFactor;
  671. #endif
  672. varying highp vec3 v_id;
  673. varying lowp vec4 v_color;
  674. varying lowp float v_opacity;
  675. varying mediump vec4 v_aux1;
  676. #ifdef PATTERN
  677. varying mediump vec2 v_tileTextureCoord;
  678. #endif
  679. #ifdef SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE
  680. varying lowp float v_isOutline;
  681. #endif
  682. #if SYMBOLOGY_TYPE == SYMBOLOGY_TYPE_DOT_DENSITY
  683. varying highp vec2 v_dotTextureCoords;
  684. varying highp vec4 v_dotThresholds[ 2 ];
  685. #endif`,"fill.frag":`precision highp float;
  686. #include <materials/constants.glsl>
  687. #include <materials/utils.glsl>
  688. #include <materials/fill/common.glsl>
  689. #ifdef PATTERN
  690. uniform lowp sampler2D u_texture;
  691. #endif
  692. #if SYMBOLOGY_TYPE == SYMBOLOGY_TYPE_DOT_DENSITY
  693. uniform mediump mat4 u_dotColors[ 2 ];
  694. uniform sampler2D u_dotTextures[ 2 ];
  695. uniform vec4 u_dotBackgroundColor;
  696. #endif
  697. #ifdef SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE
  698. #include <materials/shared/line/common.glsl>
  699. #include <materials/shared/line/line.frag>
  700. lowp vec4 drawLine() {
  701. float v_lineWidth = v_aux1.x;
  702. vec2 v_normal = v_aux1.yz;
  703. LineData inputs = LineData(
  704. v_color,
  705. v_normal,
  706. v_lineWidth,
  707. v_opacity,
  708. v_id
  709. );
  710. return shadeLine(inputs);
  711. }
  712. #endif
  713. lowp vec4 drawFill() {
  714. lowp vec4 out_color = vec4(0.);
  715. #ifdef HITTEST
  716. out_color = v_color;
  717. #elif defined(PATTERN)
  718. mediump vec4 v_tlbr = v_aux1;
  719. mediump vec2 normalizedTextureCoord = mod(v_tileTextureCoord, 1.0);
  720. mediump vec2 samplePos = mix(v_tlbr.xy, v_tlbr.zw, normalizedTextureCoord);
  721. lowp vec4 color = texture2D(u_texture, samplePos);
  722. #ifdef VV_COLOR
  723. if (v_sampleAlphaOnly > 0.5) {
  724. color.rgb = vec3(color.a);
  725. }
  726. #endif
  727. out_color = v_opacity * v_color * color;
  728. #elif SYMBOLOGY_TYPE == SYMBOLOGY_TYPE_DOT_DENSITY && !defined(HIGHLIGHT)
  729. vec4 textureThresholds0 = texture2D(u_dotTextures[0], v_dotTextureCoords);
  730. vec4 textureThresholds1 = texture2D(u_dotTextures[1], v_dotTextureCoords);
  731. vec4 difference0 = v_dotThresholds[0] - textureThresholds0;
  732. vec4 difference1 = v_dotThresholds[1] - textureThresholds1;
  733. #ifdef DD_DOT_BLENDING
  734. vec4 isPositive0 = step(0.0, difference0);
  735. vec4 isPositive1 = step(0.0, difference1);
  736. float weightSum = dot(isPositive0, difference0) + dot(isPositive1, difference1);
  737. float lessThanEqZero = step(weightSum, 0.0);
  738. float greaterThanZero = 1.0 - lessThanEqZero ;
  739. float divisor = (weightSum + lessThanEqZero);
  740. vec4 weights0 = difference0 * isPositive0 / divisor;
  741. vec4 weights1 = difference1 * isPositive1 / divisor;
  742. vec4 dotColor = u_dotColors[0] * weights0 + u_dotColors[1] * weights1;
  743. vec4 preEffectColor = greaterThanZero * dotColor + lessThanEqZero * u_dotBackgroundColor;
  744. #else
  745. float diffMax = max(max4(difference0), max4(difference1));
  746. float lessThanZero = step(diffMax, 0.0);
  747. float greaterOrEqZero = 1.0 - lessThanZero;
  748. vec4 isMax0 = step(diffMax, difference0);
  749. vec4 isMax1 = step(diffMax, difference1);
  750. vec4 dotColor = u_dotColors[0] * isMax0 + u_dotColors[1] * isMax1;
  751. vec4 preEffectColor = greaterOrEqZero * dotColor + lessThanZero * u_dotBackgroundColor;
  752. #endif
  753. out_color = preEffectColor;
  754. #else
  755. out_color = v_opacity * v_color;
  756. #endif
  757. #ifdef HIGHLIGHT
  758. out_color.a = 1.0;
  759. #endif
  760. return out_color;
  761. }
  762. void main() {
  763. #ifdef SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE
  764. if (v_isOutline > 0.5) {
  765. gl_FragColor = drawLine();
  766. } else {
  767. gl_FragColor = drawFill();
  768. }
  769. #else
  770. gl_FragColor = drawFill();
  771. #endif
  772. }`,"fill.vert":`#include <materials/symbologyTypeUtils.glsl>
  773. #define PACKED_LINE
  774. precision highp float;
  775. attribute float a_bitset;
  776. #if SYMBOLOGY_TYPE == SYMBOLOGY_TYPE_DOT_DENSITY
  777. attribute float a_inverseArea;
  778. vec4 a_color = vec4(0.0, 0.0, 0.0, 1.0);
  779. vec2 a_zoomRange = vec2(0.0, 10000.0);
  780. #else
  781. attribute vec4 a_color;
  782. attribute vec4 a_aux2;
  783. attribute vec4 a_aux3;
  784. #ifndef SYMBOLOGY_TYPE_IS_SIMPLE_LIKE
  785. attribute vec4 a_aux1;
  786. attribute vec2 a_zoomRange;
  787. #else
  788. vec2 a_zoomRange = vec2(0.0, 10000.0);
  789. #endif
  790. #endif
  791. uniform vec2 u_tileOffset;
  792. #include <util/encoding.glsl>
  793. #include <materials/vcommon.glsl>
  794. #include <materials/fill/common.glsl>
  795. #include <materials/fill/hittest.glsl>
  796. const float INV_SCALE_COMPRESSION_FACTOR = 1.0 / 128.0;
  797. #if SYMBOLOGY_TYPE == SYMBOLOGY_TYPE_DOT_DENSITY
  798. vec4 dotThreshold(vec4 featureAttrOverFeatureArea, float dotValue, float tileDotsOverArea) {
  799. return featureAttrOverFeatureArea * (1.0 / dotValue) * (1.0 / tileDotsOverArea);
  800. }
  801. #endif
  802. #ifdef SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE
  803. #include <materials/shared/line/common.glsl>
  804. #include <materials/shared/line/line.vert>
  805. void drawLine(out lowp vec4 out_color, out highp vec3 out_pos) {
  806. LineData outputs = buildLine(
  807. out_pos,
  808. a_id,
  809. a_pos,
  810. a_color,
  811. (a_aux3.xy - 128.) / 16.,
  812. (a_aux3.zw - 128.) / 16.,
  813. 0.,
  814. a_aux2.z / 16.,
  815. a_bitset,
  816. vec4(0.),
  817. vec2(0.),
  818. a_aux2.w / 16.
  819. );
  820. v_id = outputs.id;
  821. v_opacity = outputs.opacity;
  822. v_aux1 = vec4(outputs.lineHalfWidth, outputs.normal, 0.);
  823. out_color = outputs.color;
  824. }
  825. #endif
  826. void drawFill(out lowp vec4 out_color, out highp vec3 out_pos) {
  827. float a_bitSet = a_bitset;
  828. out_color = getColor(a_color, a_bitSet, BITSET_GENERIC_LOCK_COLOR);
  829. v_opacity = getOpacity();
  830. v_id = norm(a_id);
  831. #if SYMBOLOGY_TYPE == SYMBOLOGY_TYPE_DOT_DENSITY
  832. mat3 tileToTileNormalized = mat3( 2. / 512., 0., 0.,
  833. 0., -2. / 512., 0.,
  834. -1., 1., 1. );
  835. out_pos = tileToTileNormalized * vec3((a_pos * FILL_POSITION_PRECISION), 1.);
  836. #else
  837. out_pos = u_dvsMat3 * vec3(a_pos * FILL_POSITION_PRECISION, 1.);
  838. #endif
  839. #ifdef PATTERN
  840. vec4 a_tlbr = a_aux1;
  841. float a_width = a_aux2.x;
  842. float a_height = a_aux2.y;
  843. vec2 a_offset = a_aux2.zw;
  844. vec2 a_scale = a_aux3.xy;
  845. float a_angle = a_aux3.z;
  846. vec2 scale = INV_SCALE_COMPRESSION_FACTOR * a_scale;
  847. float width = u_zoomFactor * a_width * scale.x;
  848. float height = u_zoomFactor * a_height * scale.y;
  849. float angle = C_256_TO_RAD * a_angle;
  850. float sinA = sin(angle);
  851. float cosA = cos(angle);
  852. float dx = 0.0;
  853. float dy = 0.0;
  854. if (getBit(a_bitset, BITSET_FILL_RANDOM_PATTERN_OFFSET) > 0.5) {
  855. float id = rgba2float(vec4(a_id, 0.0));
  856. dx = rand(vec2(id, 0.0));
  857. dy = rand(vec2(0.0, id));
  858. }
  859. mat3 patternMatrix = mat3(cosA / width, sinA / height, 0,
  860. -sinA / width, cosA / height, 0,
  861. dx, dy, 1);
  862. vec2 tileOffset = vec2(u_tileOffset.x * cosA - u_tileOffset.y * sinA, u_tileOffset.x * sinA + u_tileOffset.y * cosA);
  863. tileOffset = mod(tileOffset, vec2(a_aux2.x, a_aux2.y));
  864. vec2 symbolOffset = (a_offset - tileOffset) / vec2(width, height);
  865. v_tileTextureCoord = (patternMatrix * vec3(a_pos * FILL_POSITION_PRECISION, 1.0)).xy - symbolOffset;
  866. v_aux1 = a_tlbr / u_mosaicSize.xyxy;
  867. v_sampleAlphaOnly = getBit(a_bitset, BITSET_GENERIC_CONSIDER_ALPHA_ONLY);
  868. #elif SYMBOLOGY_TYPE == SYMBOLOGY_TYPE_DOT_DENSITY
  869. vec4 ddAttributeData0 = getAttributeData2(a_id) * u_isActive[0] * a_inverseArea;
  870. vec4 ddAttributeData1 = getAttributeData3(a_id) * u_isActive[1] * a_inverseArea;
  871. float size = u_tileZoomFactor * 512.0 * 1.0 / u_pixelRatio;
  872. v_dotThresholds[0] = dotThreshold(ddAttributeData0, u_dotValue, u_tileDotsOverArea);
  873. v_dotThresholds[1] = dotThreshold(ddAttributeData1, u_dotValue, u_tileDotsOverArea);
  874. v_dotTextureCoords = (a_pos * FILL_POSITION_PRECISION + 0.5) / size;
  875. #endif
  876. }
  877. #ifdef HITTEST
  878. void draw(out lowp vec4 out_color, out highp vec3 out_pos) {
  879. #ifdef SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE
  880. if (getBit(a_bitset, BITSET_TYPE_FILL_OUTLINE) > 0.5) {
  881. out_pos = vec3(0., 0., 2.);
  882. return;
  883. }
  884. #endif
  885. hittestFill(out_color, out_pos);
  886. gl_PointSize = 1.0;
  887. }
  888. #elif defined(SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE)
  889. void draw(out lowp vec4 out_color, out highp vec3 out_pos) {
  890. v_isOutline = getBit(a_bitset, BITSET_TYPE_FILL_OUTLINE);
  891. if (v_isOutline > 0.5) {
  892. drawLine(out_color, out_pos);
  893. } else {
  894. drawFill(out_color, out_pos);
  895. }
  896. }
  897. #else
  898. #define draw drawFill
  899. #endif
  900. void main()
  901. {
  902. INIT;
  903. highp vec3 pos = vec3(0.);
  904. highp vec4 color = vec4(0.);
  905. draw(color, pos);
  906. v_color = color;
  907. gl_Position = vec4(clip(v_color, pos, getFilterFlags(), a_zoomRange), 1.0);
  908. }`,"hittest.glsl":`#ifdef HITTEST
  909. #include <materials/hittest/common.glsl>
  910. attribute vec2 a_pos1;
  911. attribute vec2 a_pos2;
  912. void hittestFill(
  913. out lowp vec4 out_color,
  914. out highp vec3 out_pos
  915. ) {
  916. vec3 pos = u_viewMat3 * u_tileMat3 * vec3(a_pos * FILL_POSITION_PRECISION, 1.);
  917. vec3 pos1 = u_viewMat3 * u_tileMat3 * vec3(a_pos1 * FILL_POSITION_PRECISION, 1.);
  918. vec3 pos2 = u_viewMat3 * u_tileMat3 * vec3(a_pos2 * FILL_POSITION_PRECISION, 1.);
  919. float hittestDist = u_hittestDist;
  920. float dist = distPointTriangle(u_hittestPos, pos.xy, pos1.xy, pos2.xy);
  921. out_pos = vec3(getAttributeDataTextureCoords(a_id), 0.0);
  922. if (dist < 0. || dist >= hittestDist) {
  923. out_pos.z += 2.0;
  924. }
  925. out_color = vec4(1. / 255., 0, 0, dist == 0. ? (1. / 255.) : 0.);
  926. }
  927. #endif`},hittest:{"common.glsl":`#ifdef HITTEST
  928. uniform float u_hittestDist;
  929. uniform highp vec2 u_hittestPos;
  930. float projectScalar(vec2 a, vec2 b) {
  931. return dot(a, normalize(b));
  932. }
  933. float distPointSegment(vec2 p0, vec2 p1, vec2 p2) {
  934. vec2 L = p2 - p1;
  935. vec2 A = p0 - p1;
  936. float projAL = projectScalar(A, L);
  937. float t = clamp(projAL / length(L), 0., 1.);
  938. return distance(p0, p1 + t * (p2 - p1));
  939. }
  940. void hittestMarker(out lowp vec4 out_color, out highp vec3 out_pos, in highp vec3 pos, float size) {
  941. float dist = distance(pos, vec3(u_hittestPos, 1.));
  942. out_pos = vec3(getAttributeDataTextureCoords(a_id), 0.0);
  943. if ((dist - size) > u_hittestDist) {
  944. out_pos.z += 2.0;
  945. }
  946. out_color = vec4(1. / 255., 0, 0, (dist - size) < 0. ? (1. / 255.) : 0.);
  947. }
  948. float intersectPointTriangleBary(vec2 p, vec2 a, vec2 b, vec2 c) {
  949. return inTriangle(xyToBarycentric(p, a, b, c));
  950. }
  951. float distPointTriangle(vec2 p, vec2 a, vec2 b, vec2 c) {
  952. vec2 ba = b - a;
  953. vec2 ca = c - a;
  954. float crossProduct = ba.x * ca.y - ca.x * ba.y;
  955. bool isParallel = crossProduct < EPSILON_HITTEST && crossProduct > -EPSILON_HITTEST;
  956. if (isParallel) {
  957. return -1.;
  958. }
  959. if (intersectPointTriangleBary(p.xy, a, b, c) == 1.) {
  960. return 0.;
  961. }
  962. float distAB = distPointSegment(p, a, b);
  963. float distBC = distPointSegment(p, b, c);
  964. float distCA = distPointSegment(p, c, a);
  965. return min(min(distAB, distBC), distCA);
  966. }
  967. #endif`},icon:{"common.glsl":`#include <util/encoding.glsl>
  968. uniform lowp vec2 u_mosaicSize;
  969. varying lowp vec4 v_color;
  970. varying highp vec3 v_id;
  971. varying highp vec4 v_sizeTex;
  972. varying mediump vec3 v_pos;
  973. varying lowp float v_opacity;
  974. uniform lowp sampler2D u_texture;
  975. #ifdef SDF
  976. varying lowp vec4 v_outlineColor;
  977. varying mediump float v_outlineWidth;
  978. varying mediump float v_distRatio;
  979. varying mediump float v_overridingOutlineColor;
  980. varying mediump float v_isThin;
  981. #endif
  982. #ifdef SDF
  983. vec4 getColor(vec2 v_size, vec2 v_tex) {
  984. lowp vec4 fillPixelColor = v_color;
  985. float d = 0.5 - rgba2float(texture2D(u_texture, v_tex));
  986. float size = max(v_size.x, v_size.y);
  987. float dist = d * size * SOFT_EDGE_RATIO * v_distRatio;
  988. fillPixelColor *= clamp(0.5 - dist, 0.0, 1.0);
  989. float outlineWidth = v_outlineWidth;
  990. #ifdef HIGHLIGHT
  991. outlineWidth = max(outlineWidth, 4.0 * v_isThin);
  992. #endif
  993. if (outlineWidth > 0.25) {
  994. lowp vec4 outlinePixelColor = v_overridingOutlineColor * v_color + (1.0 - v_overridingOutlineColor) * v_outlineColor;
  995. float clampedOutlineSize = min(outlineWidth, size);
  996. outlinePixelColor *= clamp(0.5 - abs(dist) + clampedOutlineSize * 0.5, 0.0, 1.0);
  997. return v_opacity * ((1.0 - outlinePixelColor.a) * fillPixelColor + outlinePixelColor);
  998. }
  999. return v_opacity * fillPixelColor;
  1000. }
  1001. #else
  1002. vec4 getColor(vec2 _v_size, vec2 v_tex) {
  1003. lowp vec4 texColor = texture2D(u_texture, v_tex);
  1004. return v_opacity * texColor * v_color;
  1005. }
  1006. #endif`,heatmapAccumulate:{"common.glsl":`varying lowp vec4 v_hittestResult;
  1007. varying mediump vec2 v_offsetFromCenter;
  1008. varying highp float v_fieldValue;`,"heatmapAccumulate.frag":`precision mediump float;
  1009. #include <materials/icon/heatmapAccumulate/common.glsl>
  1010. #ifdef HEATMAP_PRECISION_HALF_FLOAT
  1011. #define COMPRESSION_FACTOR 0.25
  1012. #else
  1013. #define COMPRESSION_FACTOR 1.0
  1014. #endif
  1015. uniform lowp sampler2D u_texture;
  1016. void main() {
  1017. #ifdef HITTEST
  1018. gl_FragColor = v_hittestResult;
  1019. #else
  1020. float radius = length(v_offsetFromCenter);
  1021. float shapeWeight = step(radius, 1.0);
  1022. float oneMinusRadiusSquared = 1.0 - radius * radius;
  1023. float kernelWeight = oneMinusRadiusSquared * oneMinusRadiusSquared;
  1024. gl_FragColor = vec4(shapeWeight * kernelWeight * v_fieldValue * COMPRESSION_FACTOR);
  1025. #endif
  1026. }`,"heatmapAccumulate.vert":`precision highp float;
  1027. attribute vec2 a_vertexOffset;
  1028. vec4 a_color = vec4(0.0);
  1029. vec2 a_zoomRange = vec2(0.0, 10000.0);
  1030. uniform float u_radius;
  1031. uniform float u_isFieldActive;
  1032. #include <materials/vcommon.glsl>
  1033. #include <materials/hittest/common.glsl>
  1034. #include <materials/icon/heatmapAccumulate/common.glsl>
  1035. void main() {
  1036. float filterFlags = getFilterFlags();
  1037. #ifdef HITTEST
  1038. highp vec4 out_hittestResult = vec4(0.);
  1039. highp vec3 out_pos = vec3(0.);
  1040. vec3 pos = u_viewMat3 * u_tileMat3 * vec3(a_pos * POSITION_PRECISION, 1.0);
  1041. hittestMarker(out_hittestResult, out_pos, pos, u_radius);
  1042. v_hittestResult = out_hittestResult;
  1043. gl_PointSize = 1.;
  1044. gl_Position = vec4(clip(a_color, out_pos, filterFlags, a_zoomRange), 1.0);
  1045. #else
  1046. v_offsetFromCenter = sign(a_vertexOffset);
  1047. v_fieldValue = getAttributeData2(a_id).x * u_isFieldActive + 1.0 - u_isFieldActive;
  1048. vec3 centerPos = u_dvsMat3 * vec3(a_pos * POSITION_PRECISION, 1.0);
  1049. vec3 vertexPos = centerPos + u_displayViewMat3 * vec3(v_offsetFromCenter, 0.0) * u_radius;
  1050. gl_Position = vec4(clip(a_color, vertexPos, filterFlags, a_zoomRange), 1.0);
  1051. #endif
  1052. }`},"hittest.glsl":`#ifdef HITTEST
  1053. #include <materials/hittest/common.glsl>
  1054. attribute vec2 a_vertexOffset1;
  1055. attribute vec2 a_vertexOffset2;
  1056. attribute vec2 a_texCoords1;
  1057. attribute vec2 a_texCoords2;
  1058. vec2 getTextureCoords(in vec3 bary, in vec2 texCoords0, in vec2 texCoords1, in vec2 texCoords2) {
  1059. return texCoords0 * bary.x + texCoords1 * bary.y + texCoords2 * bary.z;
  1060. }
  1061. void hittestIcon(
  1062. inout lowp vec4 out_color,
  1063. out highp vec3 out_pos,
  1064. in vec3 pos,
  1065. in vec3 offset,
  1066. in vec2 size,
  1067. in float scaleFactor,
  1068. in float isMapAligned
  1069. ) {
  1070. out_pos = vec3(getAttributeDataTextureCoords(a_id), 0.0);
  1071. vec3 posBase = u_viewMat3 * u_tileMat3 * pos;
  1072. vec3 offset1 = scaleFactor * vec3(a_vertexOffset1 / 16.0, 0.);
  1073. vec3 offset2 = scaleFactor * vec3(a_vertexOffset2 / 16.0, 0.);
  1074. vec2 pos0 = (posBase + getMatrixNoDisplay(isMapAligned) * offset).xy;
  1075. vec2 pos1 = (posBase + getMatrixNoDisplay(isMapAligned) * offset1).xy;
  1076. vec2 pos2 = (posBase + getMatrixNoDisplay(isMapAligned) * offset2).xy;
  1077. vec3 bary0 = xyToBarycentric(u_hittestPos + vec2(-u_hittestDist, -u_hittestDist), pos0, pos1, pos2);
  1078. vec3 bary1 = xyToBarycentric(u_hittestPos + vec2(0., -u_hittestDist), pos0, pos1, pos2);
  1079. vec3 bary2 = xyToBarycentric(u_hittestPos + vec2(u_hittestDist, -u_hittestDist), pos0, pos1, pos2);
  1080. vec3 bary3 = xyToBarycentric(u_hittestPos + vec2(-u_hittestDist, 0.), pos0, pos1, pos2);
  1081. vec3 bary4 = xyToBarycentric(u_hittestPos, pos0, pos1, pos2);
  1082. vec3 bary5 = xyToBarycentric(u_hittestPos + vec2(u_hittestDist, 0.), pos0, pos1, pos2);
  1083. vec3 bary6 = xyToBarycentric(u_hittestPos + vec2(-u_hittestDist, u_hittestDist), pos0, pos1, pos2);
  1084. vec3 bary7 = xyToBarycentric(u_hittestPos + vec2(0., u_hittestDist), pos0, pos1, pos2);
  1085. vec3 bary8 = xyToBarycentric(u_hittestPos + vec2(u_hittestDist, u_hittestDist), pos0, pos1, pos2);
  1086. vec2 tex0 = a_texCoords / u_mosaicSize;
  1087. vec2 tex1 = a_texCoords1 / u_mosaicSize;
  1088. vec2 tex2 = a_texCoords2 / u_mosaicSize;
  1089. float alphaSum = 0.;
  1090. alphaSum += inTriangle(bary0) * getColor(size, getTextureCoords(bary0, tex0, tex1, tex2)).a;
  1091. alphaSum += inTriangle(bary1) * getColor(size, getTextureCoords(bary1, tex0, tex1, tex2)).a;
  1092. alphaSum += inTriangle(bary2) * getColor(size, getTextureCoords(bary2, tex0, tex1, tex2)).a;
  1093. alphaSum += inTriangle(bary3) * getColor(size, getTextureCoords(bary3, tex0, tex1, tex2)).a;
  1094. alphaSum += inTriangle(bary4) * getColor(size, getTextureCoords(bary4, tex0, tex1, tex2)).a;
  1095. alphaSum += inTriangle(bary5) * getColor(size, getTextureCoords(bary5, tex0, tex1, tex2)).a;
  1096. alphaSum += inTriangle(bary6) * getColor(size, getTextureCoords(bary6, tex0, tex1, tex2)).a;
  1097. alphaSum += inTriangle(bary7) * getColor(size, getTextureCoords(bary7, tex0, tex1, tex2)).a;
  1098. out_pos.z += step(alphaSum, .05) * 2.0;
  1099. out_color = vec4(1. / 255., 0., 0., alphaSum / 255.);
  1100. }
  1101. #endif`,"icon.frag":`precision mediump float;
  1102. #include <materials/constants.glsl>
  1103. #include <materials/utils.glsl>
  1104. #include <materials/icon/common.glsl>
  1105. void main()
  1106. {
  1107. #ifdef HITTEST
  1108. vec4 color = v_color;
  1109. #else
  1110. vec4 color = getColor(v_sizeTex.xy, v_sizeTex.zw);
  1111. #endif
  1112. #ifdef HIGHLIGHT
  1113. color.a = step(1.0 / 255.0, color.a);
  1114. #endif
  1115. gl_FragColor = color;
  1116. }`,"icon.vert":`precision highp float;
  1117. attribute vec4 a_color;
  1118. attribute vec4 a_outlineColor;
  1119. attribute vec4 a_sizeAndOutlineWidth;
  1120. attribute vec2 a_vertexOffset;
  1121. attribute vec2 a_texCoords;
  1122. attribute vec2 a_bitSetAndDistRatio;
  1123. attribute vec2 a_zoomRange;
  1124. #include <materials/vcommon.glsl>
  1125. #include <materials/icon/common.glsl>
  1126. #include <materials/icon/hittest.glsl>
  1127. float getMarkerScaleFactor(inout vec2 size, in float referenceSize) {
  1128. #ifdef VV_SIZE
  1129. float f = getSize(size.y) / size.y;
  1130. float sizeFactor = size.y / referenceSize;
  1131. return getSize(referenceSize) / referenceSize;
  1132. #else
  1133. return 1.;
  1134. #endif
  1135. }
  1136. void main()
  1137. {
  1138. INIT;
  1139. float a_bitSet = a_bitSetAndDistRatio.x;
  1140. vec3 pos = vec3(a_pos * POSITION_PRECISION, 1.0);
  1141. vec2 size = a_sizeAndOutlineWidth.xy * a_sizeAndOutlineWidth.xy / 128.0;
  1142. vec3 offset = vec3(a_vertexOffset / 16.0, 0.);
  1143. float outlineSize = a_sizeAndOutlineWidth.z * a_sizeAndOutlineWidth.z / 128.0;
  1144. float isMapAligned = getBit(a_bitSet, BITSET_MARKER_ALIGNMENT_MAP);
  1145. float referenceSize = a_sizeAndOutlineWidth.w * a_sizeAndOutlineWidth.w / 128.0;
  1146. float scaleSymbolProportionally = getBit(a_bitSet, BITSET_MARKER_SCALE_SYMBOLS_PROPORTIONALLY);
  1147. float scaleFactor = getMarkerScaleFactor(size, referenceSize);
  1148. size.xy *= scaleFactor;
  1149. offset.xy *= scaleFactor;
  1150. outlineSize *= scaleSymbolProportionally * (scaleFactor - 1.0) + 1.0;
  1151. vec2 v_tex = a_texCoords / u_mosaicSize;
  1152. float filterFlags = getFilterFlags();
  1153. v_color = getColor(a_color, a_bitSet, BITSET_GENERIC_LOCK_COLOR);
  1154. v_opacity = getOpacity();
  1155. v_id = norm(a_id);
  1156. v_pos = u_dvsMat3 * pos + getMatrix(isMapAligned) * getRotation() * offset;
  1157. v_sizeTex = vec4(size.xy, v_tex.xy);
  1158. #ifdef SDF
  1159. v_isThin = getBit(a_bitSet, BITSET_MARKER_OUTLINE_ALLOW_COLOR_OVERRIDE);
  1160. #ifdef VV_COLOR
  1161. v_overridingOutlineColor = v_isThin;
  1162. #else
  1163. v_overridingOutlineColor = 0.0;
  1164. #endif
  1165. v_outlineWidth = min(outlineSize, max(max(size.x, size.y) - 0.99, 0.0));
  1166. v_outlineColor = a_outlineColor;
  1167. v_distRatio = a_bitSetAndDistRatio.y / 126.0;
  1168. #endif
  1169. #ifdef HITTEST
  1170. highp vec4 out_color = vec4(0.);
  1171. highp vec3 out_pos = vec3(0.);
  1172. hittestIcon(out_color, out_pos, pos, offset, size, scaleFactor, isMapAligned);
  1173. v_color = out_color;
  1174. gl_PointSize = 1.;
  1175. gl_Position = vec4(clip(v_color, out_pos, filterFlags, a_zoomRange), 1.0);
  1176. #else
  1177. gl_Position = vec4(clip(v_color, v_pos, filterFlags, a_zoomRange), 1.0);
  1178. #endif
  1179. }`},label:{"common.glsl":`uniform mediump float u_zoomLevel;
  1180. uniform mediump float u_mapRotation;
  1181. uniform mediump float u_mapAligned;
  1182. uniform mediump vec2 u_mosaicSize;
  1183. varying mediump float v_antialiasingWidth;
  1184. varying mediump float v_edgeDistanceOffset;
  1185. varying mediump vec2 v_tex;
  1186. varying mediump vec4 v_color;
  1187. varying lowp vec4 v_animation;`,"label.frag":"#include <materials/text/text.frag>","label.vert":`precision highp float;
  1188. #include <materials/vcommon.glsl>
  1189. #include <materials/text/common.glsl>
  1190. attribute vec4 a_color;
  1191. attribute vec4 a_haloColor;
  1192. attribute vec4 a_texAndSize;
  1193. attribute vec4 a_refSymbolAndPlacementOffset;
  1194. attribute vec4 a_glyphData;
  1195. attribute vec2 a_vertexOffset;
  1196. attribute vec2 a_texCoords;
  1197. uniform float u_isHalo;
  1198. uniform float u_mapRotation;
  1199. uniform float u_mapAligned;
  1200. float getZ(in float minZoom, in float maxZoom, in float angle) {
  1201. float glyphAngle = angle * 360.0 / 254.0;
  1202. float mapAngle = u_mapRotation * 360.0 / 254.0;
  1203. float diffAngle = min(360.0 - abs(mapAngle - glyphAngle), abs(mapAngle - glyphAngle));
  1204. float z = 0.0;
  1205. z += u_mapAligned * (2.0 * (1.0 - step(minZoom, u_currentZoom)));
  1206. z += u_mapAligned * 2.0 * step(90.0, diffAngle);
  1207. z += 2.0 * (1.0 - step(u_currentZoom, maxZoom));
  1208. return z;
  1209. }
  1210. void main()
  1211. {
  1212. INIT;
  1213. float groupMinZoom = getMinZoom();
  1214. float glyphMinZoom = a_glyphData.x;
  1215. float glyphMaxZoom = a_glyphData.y;
  1216. float glyphAngle = a_glyphData.z;
  1217. float a_minZoom = max(groupMinZoom, glyphMinZoom);
  1218. float a_placementPadding = a_refSymbolAndPlacementOffset.x * EXTRUDE_SCALE_PLACEMENT_PADDING;
  1219. vec2 a_placementDir = unpack_u8_nf32(a_refSymbolAndPlacementOffset.zw);
  1220. float a_refSymbolSize = a_refSymbolAndPlacementOffset.y;
  1221. float fontSize = a_texAndSize.z;
  1222. float haloSize = a_texAndSize.w * OUTLINE_SCALE;
  1223. vec2 vertexOffset = a_vertexOffset * OFFSET_PRECISION;
  1224. vec3 pos = vec3(a_pos * POSITION_PRECISION, 1.0);
  1225. float z = getZ(a_minZoom, glyphMaxZoom, glyphAngle);
  1226. float fontScale = fontSize / SDF_FONT_SIZE;
  1227. float halfSize = getSize(a_refSymbolSize) / 2.0;
  1228. float animation = pow(getAnimationState(), vec4(2.0)).r;
  1229. v_color = animation * ((1.0 - u_isHalo) * a_color + (u_isHalo * a_haloColor));
  1230. v_opacity = 1.0;
  1231. v_tex = a_texCoords / u_mosaicSize;
  1232. v_edgeDistanceOffset = u_isHalo * haloSize / fontScale / MAX_SDF_DISTANCE;
  1233. v_antialiasingWidth = 0.105 * SDF_FONT_SIZE / fontSize / u_pixelRatio;
  1234. vec2 placementOffset = a_placementDir * (halfSize + a_placementPadding);
  1235. vec3 glyphOffset = u_displayMat3 * vec3(vertexOffset + placementOffset, 0.0);
  1236. vec3 v_pos = vec3((u_dvsMat3 * pos + glyphOffset).xy, z);
  1237. gl_Position = vec4(v_pos, 1.0);
  1238. #ifdef DEBUG
  1239. v_color = vec4(a_color.rgb, z == 0.0 ? 1.0 : 0.645);
  1240. #endif
  1241. }`},line:{"common.glsl":`varying lowp vec4 v_color;
  1242. varying highp vec3 v_id;
  1243. varying mediump vec2 v_normal;
  1244. varying mediump float v_lineHalfWidth;
  1245. varying lowp float v_opacity;
  1246. #ifdef PATTERN
  1247. varying mediump vec4 v_tlbr;
  1248. varying mediump vec2 v_patternSize;
  1249. #endif
  1250. #if defined(PATTERN) || defined(SDF)
  1251. varying highp float v_accumulatedDistance;
  1252. #endif
  1253. #ifdef SDF
  1254. varying mediump float v_lineWidthRatio;
  1255. #endif`,"hittest.glsl":`#include <materials/hittest/common.glsl>
  1256. #ifdef HITTEST
  1257. attribute vec2 a_pos1;
  1258. attribute vec2 a_pos2;
  1259. void hittestLine(out lowp vec4 out_color, out highp vec3 out_pos, float halfWidth) {
  1260. vec3 pos = u_viewMat3 * u_tileMat3 * vec3(a_pos * POSITION_PRECISION, 1.);
  1261. vec3 pos1 = u_viewMat3 * u_tileMat3 * vec3(a_pos1 * POSITION_PRECISION, 1.);
  1262. vec3 pos2 = u_viewMat3 * u_tileMat3 * vec3(a_pos2 * POSITION_PRECISION, 1.);
  1263. vec3 outTextureCoords = vec3(getAttributeDataTextureCoords(a_id), 0.0);
  1264. float dist = min(distPointSegment(u_hittestPos, pos.xy, pos1.xy),
  1265. distPointSegment(u_hittestPos, pos.xy, pos2.xy)) - halfWidth;
  1266. out_pos = vec3(getAttributeDataTextureCoords(a_id), 0.0);
  1267. if (dist >= u_hittestDist) {
  1268. out_pos.z += 2.0;
  1269. }
  1270. out_color = vec4(1. / 255., 0, 0, dist <= 0. ? (1. / 255.) : 0.);
  1271. }
  1272. #endif`,"line.frag":`precision lowp float;
  1273. #include <util/encoding.glsl>
  1274. #include <materials/constants.glsl>
  1275. #include <materials/symbologyTypeUtils.glsl>
  1276. #include <materials/line/common.glsl>
  1277. #include <materials/shared/line/common.glsl>
  1278. #include <materials/shared/line/line.frag>
  1279. #ifdef HITTEST
  1280. void main() {
  1281. gl_FragColor = v_color;
  1282. }
  1283. #else
  1284. void main() {
  1285. LineData inputs = LineData(
  1286. v_color,
  1287. v_normal,
  1288. v_lineHalfWidth,
  1289. v_opacity,
  1290. #ifndef SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE
  1291. #ifdef PATTERN
  1292. v_tlbr,
  1293. v_patternSize,
  1294. #endif
  1295. #ifdef SDF
  1296. v_lineWidthRatio,
  1297. #endif
  1298. #if defined(PATTERN) || defined(SDF)
  1299. v_accumulatedDistance,
  1300. #endif
  1301. #endif
  1302. v_id
  1303. );
  1304. gl_FragColor = shadeLine(inputs);
  1305. }
  1306. #endif`,"line.vert":`precision highp float;
  1307. attribute vec4 a_color;
  1308. attribute vec4 a_offsetAndNormal;
  1309. attribute vec2 a_accumulatedDistanceAndHalfWidth;
  1310. attribute vec4 a_tlbr;
  1311. attribute vec4 a_segmentDirection;
  1312. attribute vec2 a_aux;
  1313. attribute vec2 a_zoomRange;
  1314. #include <materials/vcommon.glsl>
  1315. #include <materials/symbologyTypeUtils.glsl>
  1316. #include <materials/line/common.glsl>
  1317. #include <materials/line/hittest.glsl>
  1318. #include <materials/shared/line/common.glsl>
  1319. #include <materials/shared/line/line.vert>
  1320. #ifdef HITTEST
  1321. void draw() {
  1322. float aa = 0.5 * u_antialiasing;
  1323. float a_halfWidth = a_accumulatedDistanceAndHalfWidth.y / 16.;
  1324. float a_cimHalfWidth = a_aux.x / 16. ;
  1325. vec2 a_offset = a_offsetAndNormal.xy / 16.;
  1326. float baseWidth = getBaseLineHalfWidth(a_halfWidth, a_cimHalfWidth);
  1327. float halfWidth = getLineHalfWidth(baseWidth, aa);
  1328. highp vec3 pos = vec3(0.);
  1329. v_color = vec4(0.);
  1330. hittestLine(v_color, pos, halfWidth);
  1331. gl_PointSize = 1.;
  1332. gl_Position = vec4(clip(v_color, pos, getFilterFlags(), a_zoomRange), 1.0);
  1333. }
  1334. #else
  1335. void draw()
  1336. {
  1337. highp vec3 pos = vec3(0.);
  1338. LineData outputs = buildLine(
  1339. pos,
  1340. a_id,
  1341. a_pos,
  1342. a_color,
  1343. a_offsetAndNormal.xy / 16.,
  1344. a_offsetAndNormal.zw / 16.,
  1345. a_accumulatedDistanceAndHalfWidth.x,
  1346. a_accumulatedDistanceAndHalfWidth.y / 16.,
  1347. a_segmentDirection.w,
  1348. a_tlbr,
  1349. a_segmentDirection.xy / 16.,
  1350. a_aux.x / 16.
  1351. );
  1352. v_id = outputs.id;
  1353. v_color = outputs.color;
  1354. v_normal = outputs.normal;
  1355. v_lineHalfWidth = outputs.lineHalfWidth;
  1356. v_opacity = outputs.opacity;
  1357. #ifndef SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE
  1358. #ifdef PATTERN
  1359. v_tlbr = outputs.tlbr;
  1360. v_patternSize = outputs.patternSize;
  1361. #endif
  1362. #ifdef SDF
  1363. v_lineWidthRatio = outputs.lineWidthRatio;
  1364. #endif
  1365. #if defined(PATTERN) || defined(SDF)
  1366. v_accumulatedDistance = outputs.accumulatedDistance;
  1367. #endif
  1368. #endif
  1369. gl_Position = vec4(clip(outputs.color, pos, getFilterFlags(), a_zoomRange), 1.0);
  1370. }
  1371. #endif
  1372. void main() {
  1373. INIT;
  1374. draw();
  1375. }`},pie:{"pie.frag":`precision mediump float;
  1376. #include <util/atan2.glsl>
  1377. #include <materials/constants.glsl>
  1378. #include <materials/utils.glsl>
  1379. #include <materials/icon/common.glsl>
  1380. varying float v_size;
  1381. varying vec2 v_offset;
  1382. varying vec2 v_filteredSectorToColorId[NUMBER_OF_FIELDS];
  1383. varying float v_numOfEntries;
  1384. varying float v_maxSectorAngle;
  1385. uniform lowp vec4 u_colors[NUMBER_OF_FIELDS];
  1386. uniform lowp vec4 u_defaultColor;
  1387. uniform lowp vec4 u_othersColor;
  1388. uniform lowp vec4 u_outlineColor;
  1389. uniform float u_donutRatio;
  1390. uniform float u_sectorThreshold;
  1391. struct FilteredChartInfo {
  1392. float endSectorAngle;
  1393. int colorId;
  1394. };
  1395. lowp vec4 getSectorColor(in int index, in vec2 filteredSectorToColorId[NUMBER_OF_FIELDS]) {
  1396. #if __VERSION__ == 300
  1397. mediump int colorIndex = int(filteredSectorToColorId[index].y);
  1398. return u_colors[colorIndex];
  1399. #else
  1400. mediump int colorIndex;
  1401. for (int i = 0; i < NUMBER_OF_FIELDS; ++i) {
  1402. if (i == index) {
  1403. colorIndex = int(filteredSectorToColorId[i].y);
  1404. }
  1405. }
  1406. for (int i = 0; i < NUMBER_OF_FIELDS; ++i) {
  1407. if (i == colorIndex) {
  1408. return u_colors[i];
  1409. }
  1410. }
  1411. return u_colors[NUMBER_OF_FIELDS - 1];
  1412. #endif
  1413. }
  1414. const int OTHER_SECTOR_ID = 255;
  1415. #ifdef HITTEST
  1416. vec4 getColor() {
  1417. return v_color;
  1418. }
  1419. #else
  1420. vec4 getColor() {
  1421. float angle = 90.0 - C_RAD_TO_DEG * atan2(v_offset.y, v_offset.x);
  1422. if (angle < 0.0) {
  1423. angle += 360.0;
  1424. } else if (angle > 360.0) {
  1425. angle = mod(angle, 360.0);
  1426. }
  1427. int numOfEntries = int(v_numOfEntries);
  1428. float maxSectorAngle = v_maxSectorAngle;
  1429. lowp vec4 fillColor = (maxSectorAngle > 0.0 || u_sectorThreshold > 0.0) ? u_othersColor : u_defaultColor;
  1430. lowp vec4 prevColor = vec4(0.0);
  1431. lowp vec4 nextColor = vec4(0.0);
  1432. float startSectorAngle = 0.0;
  1433. float endSectorAngle = 0.0;
  1434. if (angle < maxSectorAngle) {
  1435. for (int index = 0; index < NUMBER_OF_FIELDS; ++index) {
  1436. startSectorAngle = endSectorAngle;
  1437. endSectorAngle = v_filteredSectorToColorId[index].x;
  1438. if (endSectorAngle > angle) {
  1439. fillColor = getSectorColor(index, v_filteredSectorToColorId);
  1440. prevColor = u_sectorThreshold != 0.0 && index == 0 && abs(360.0 - maxSectorAngle) < EPSILON ? u_othersColor :
  1441. getSectorColor(index > 0 ? index - 1 : numOfEntries - 1, v_filteredSectorToColorId);
  1442. nextColor = u_sectorThreshold != 0.0 && abs(endSectorAngle - maxSectorAngle) < EPSILON ? u_othersColor :
  1443. getSectorColor(index < numOfEntries - 1 ? index + 1 : 0, v_filteredSectorToColorId);
  1444. break;
  1445. }
  1446. if (index == numOfEntries - 1) {
  1447. break;
  1448. }
  1449. }
  1450. } else {
  1451. prevColor = getSectorColor(numOfEntries - 1, v_filteredSectorToColorId);
  1452. nextColor = getSectorColor(0, v_filteredSectorToColorId);
  1453. startSectorAngle = maxSectorAngle;
  1454. endSectorAngle = 360.0;
  1455. }
  1456. lowp vec4 outlineColor = u_outlineColor;
  1457. float offset = length(v_offset);
  1458. float distanceSize = offset * v_size;
  1459. if (startSectorAngle != 0.0 || endSectorAngle != 360.0) {
  1460. float distanceToStartSector = (angle - startSectorAngle);
  1461. float distanceToEndSector = (endSectorAngle - angle);
  1462. float sectorThreshold = 0.6;
  1463. float beginSectorAlpha = smoothstep(0.0, sectorThreshold, distanceToStartSector * offset);
  1464. float endSectorAlpha = smoothstep(0.0, sectorThreshold, distanceToEndSector * offset);
  1465. if (endSectorAlpha > 0.0) {
  1466. fillColor = mix(nextColor, fillColor, endSectorAlpha);
  1467. } else if (beginSectorAlpha > 0.0) {
  1468. fillColor = mix(prevColor, fillColor, beginSectorAlpha);
  1469. }
  1470. }
  1471. float donutSize = u_donutRatio * (v_size - v_outlineWidth);
  1472. float endOfDonut = donutSize - v_outlineWidth;
  1473. float aaThreshold = 0.75;
  1474. float innerCircleAlpha = endOfDonut - aaThreshold > 0.0 ? smoothstep(endOfDonut - aaThreshold, endOfDonut + aaThreshold, distanceSize) : 1.0;
  1475. float outerCircleAlpha = 1.0 - smoothstep(v_size - aaThreshold, v_size + aaThreshold , distanceSize);
  1476. float circleAlpha = innerCircleAlpha * outerCircleAlpha;
  1477. float startOfOutline = v_size - v_outlineWidth;
  1478. if (startOfOutline > 0.0 && v_outlineWidth > 0.25) {
  1479. float outlineFactor = smoothstep(startOfOutline - aaThreshold, startOfOutline + aaThreshold, distanceSize);
  1480. float innerLineFactor = donutSize - aaThreshold > 0.0 ? 1.0 - smoothstep(donutSize - aaThreshold, donutSize + aaThreshold , distanceSize) : 0.0;
  1481. fillColor = mix(fillColor, outlineColor, innerLineFactor + outlineFactor);
  1482. }
  1483. return v_opacity * circleAlpha * fillColor;
  1484. }
  1485. #endif
  1486. void main()
  1487. {
  1488. vec4 color = getColor();
  1489. #ifdef HIGHLIGHT
  1490. color.a = step(1.0 / 255.0, color.a);
  1491. #endif
  1492. gl_FragColor = color;
  1493. }`,"pie.vert":`precision highp float;
  1494. attribute vec4 a_color;
  1495. attribute vec4 a_outlineColor;
  1496. attribute vec4 a_sizeAndOutlineWidth;
  1497. attribute vec2 a_vertexOffset;
  1498. attribute vec2 a_texCoords;
  1499. attribute vec2 a_bitSetAndDistRatio;
  1500. attribute vec2 a_zoomRange;
  1501. uniform float u_outlineWidth;
  1502. uniform mediump float u_sectorThreshold;
  1503. varying float v_size;
  1504. varying vec2 v_offset;
  1505. varying vec2 v_filteredSectorToColorId[NUMBER_OF_FIELDS];
  1506. varying float v_numOfEntries;
  1507. varying float v_maxSectorAngle;
  1508. struct FilteredChartInfo {
  1509. float endSectorAngle;
  1510. int colorId;
  1511. };
  1512. int filter(in float sectorAngle,
  1513. in int currentIndex,
  1514. inout FilteredChartInfo filteredInfo,
  1515. inout vec2 filteredSectorToColorId[NUMBER_OF_FIELDS]) {
  1516. if (sectorAngle > u_sectorThreshold * 360.0) {
  1517. filteredInfo.endSectorAngle += sectorAngle;
  1518. #if __VERSION__ == 300
  1519. filteredSectorToColorId[filteredInfo.colorId] = vec2(filteredInfo.endSectorAngle, currentIndex);
  1520. #else
  1521. for (int i = 0; i < NUMBER_OF_FIELDS; i++) {
  1522. if (i == filteredInfo.colorId) {
  1523. filteredSectorToColorId[i] = vec2(filteredInfo.endSectorAngle, currentIndex);
  1524. }
  1525. }
  1526. #endif
  1527. ++filteredInfo.colorId;
  1528. }
  1529. return 0;
  1530. }
  1531. int filterValues(inout vec2 filteredSectorToColorId[NUMBER_OF_FIELDS],
  1532. inout FilteredChartInfo filteredInfo,
  1533. in float sectorAngles[NUMBER_OF_FIELDS]) {
  1534. for (int index = 0; index < NUMBER_OF_FIELDS; ++index) {
  1535. float sectorValue = sectorAngles[index];
  1536. filter(sectorValue, index, filteredInfo, filteredSectorToColorId);
  1537. }
  1538. return filteredInfo.colorId;
  1539. }
  1540. #include <materials/vcommon.glsl>
  1541. #include <materials/icon/common.glsl>
  1542. #include <materials/hittest/common.glsl>
  1543. vec2 getMarkerSize(inout vec2 offset, inout vec2 baseSize, inout float outlineSize, in float referenceSize, in float bitSet) {
  1544. vec2 outSize = baseSize;
  1545. #ifdef VV_SIZE
  1546. float r = 0.5 * getSize(referenceSize) / referenceSize;
  1547. outSize.xy *= r;
  1548. offset.xy *= r;
  1549. float scaleSymbolProportionally = getBit(bitSet, BITSET_MARKER_SCALE_SYMBOLS_PROPORTIONALLY);
  1550. outlineSize *= scaleSymbolProportionally * (r - 1.0) + 1.0;
  1551. #endif
  1552. return outSize;
  1553. }
  1554. vec3 getOffset(in vec2 in_offset, float a_bitSet) {
  1555. float isMapAligned = getBit(a_bitSet, BITSET_MARKER_ALIGNMENT_MAP);
  1556. vec3 offset = vec3(in_offset, 0.0);
  1557. return getMatrix(isMapAligned) * offset;
  1558. }
  1559. float filterNaNValues(in float value) {
  1560. return value != NAN_MAGIC_NUMBER && value > 0.0 ? value : 0.0;
  1561. }
  1562. void main()
  1563. {
  1564. INIT;
  1565. vec2 a_size = a_sizeAndOutlineWidth.xy * a_sizeAndOutlineWidth.xy / 128.0;
  1566. vec2 a_offset = a_vertexOffset / 16.0;
  1567. float outlineSize = u_outlineWidth;
  1568. float a_bitSet = a_bitSetAndDistRatio.x;
  1569. vec2 size = getMarkerSize(a_offset, a_size, outlineSize, a_sizeAndOutlineWidth.w * a_sizeAndOutlineWidth.w / 128.0, a_bitSet);
  1570. float filterFlags = getFilterFlags();
  1571. vec3 pos = vec3(a_pos * POSITION_PRECISION, 1.0);
  1572. v_opacity = getOpacity();
  1573. v_id = norm(a_id);
  1574. v_pos = u_dvsMat3 * pos + getOffset(a_offset, a_bitSet);
  1575. v_offset = sign(a_texCoords - 0.5);
  1576. v_size = max(size.x, size.y);
  1577. v_outlineWidth = outlineSize;
  1578. float attributeData[10];
  1579. vec4 attributeData0 = getAttributeData3(a_id);
  1580. attributeData[0] = filterNaNValues(attributeData0.x);
  1581. attributeData[1] = filterNaNValues(attributeData0.y);
  1582. attributeData[2] = filterNaNValues(attributeData0.z);
  1583. attributeData[3] = filterNaNValues(attributeData0.w);
  1584. #if (NUMBER_OF_FIELDS > 4)
  1585. vec4 attributeData1 = getAttributeData4(a_id);
  1586. attributeData[4] = filterNaNValues(attributeData1.x);
  1587. attributeData[5] = filterNaNValues(attributeData1.y);
  1588. attributeData[6] = filterNaNValues(attributeData1.z);
  1589. attributeData[7] = filterNaNValues(attributeData1.w);
  1590. #endif
  1591. #if (NUMBER_OF_FIELDS > 8)
  1592. vec4 attributeData2 = getAttributeData5(a_id);
  1593. attributeData[8] = filterNaNValues(attributeData2.x);
  1594. attributeData[9] = filterNaNValues(attributeData2.y);
  1595. #endif
  1596. float sum = 0.0;
  1597. for (int i = 0; i < NUMBER_OF_FIELDS; ++i) {
  1598. sum += attributeData[i];
  1599. }
  1600. float sectorAngles[NUMBER_OF_FIELDS];
  1601. for (int i = 0; i < NUMBER_OF_FIELDS; ++i) {
  1602. sectorAngles[i] = 360.0 * attributeData[i] / sum;
  1603. }
  1604. vec2 filteredSectorToColorId[NUMBER_OF_FIELDS];
  1605. FilteredChartInfo filteredInfo = FilteredChartInfo(0.0, 0);
  1606. int numOfEntries = filterValues(filteredSectorToColorId, filteredInfo, sectorAngles);
  1607. v_numOfEntries = float(numOfEntries);
  1608. v_maxSectorAngle = filteredInfo.endSectorAngle;
  1609. #if __VERSION__ == 300
  1610. v_filteredSectorToColorId = filteredSectorToColorId;
  1611. #else
  1612. for (int i = 0; i < NUMBER_OF_FIELDS; ++i) {
  1613. if (i == numOfEntries) {
  1614. break;
  1615. }
  1616. v_filteredSectorToColorId[i] = filteredSectorToColorId[i];
  1617. }
  1618. #endif
  1619. #ifdef HITTEST
  1620. highp vec3 out_pos = vec3(0.0);
  1621. v_color = vec4(0.0);
  1622. hittestMarker(v_color, out_pos, u_viewMat3 * u_tileMat3 * pos, v_size);
  1623. gl_PointSize = 1.0;
  1624. gl_Position = vec4(clip(v_color, out_pos, filterFlags, a_zoomRange), 1.0);
  1625. #else
  1626. gl_Position = vec4(clip(v_color, v_pos, filterFlags, a_zoomRange), 1.0);
  1627. #endif
  1628. }`},shared:{line:{"common.glsl":`#if !defined(SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE) && defined(PATTERN)
  1629. uniform mediump vec2 u_mosaicSize;
  1630. varying mediump float v_sampleAlphaOnly;
  1631. #endif
  1632. struct LineData {
  1633. lowp vec4 color;
  1634. mediump vec2 normal;
  1635. mediump float lineHalfWidth;
  1636. lowp float opacity;
  1637. #ifndef SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE
  1638. #ifdef PATTERN
  1639. mediump vec4 tlbr;
  1640. mediump vec2 patternSize;
  1641. #endif
  1642. #ifdef SDF
  1643. mediump float lineWidthRatio;
  1644. #endif
  1645. #if defined(PATTERN) || defined(SDF)
  1646. highp float accumulatedDistance;
  1647. #endif
  1648. #endif
  1649. highp vec3 id;
  1650. };`,"line.frag":`uniform lowp float u_blur;
  1651. #if !defined(SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE) && !defined(HIGHLIGHT)
  1652. #if defined(PATTERN) || defined(SDF)
  1653. uniform sampler2D u_texture;
  1654. uniform highp float u_pixelRatio;
  1655. #endif
  1656. #endif
  1657. #if defined(SDF) && !defined(HIGHLIGHT) && !defined(SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE)
  1658. lowp vec4 getLineColor(LineData line) {
  1659. mediump float adjustedPatternWidth = line.patternSize.x * 2.0 * line.lineWidthRatio;
  1660. mediump float relativeTexX = fract(line.accumulatedDistance / adjustedPatternWidth);
  1661. mediump float relativeTexY = 0.5 + 0.25 * line.normal.y;
  1662. mediump vec2 texCoord = mix(line.tlbr.xy, line.tlbr.zw, vec2(relativeTexX, relativeTexY));
  1663. mediump float d = rgba2float(texture2D(u_texture, texCoord)) - 0.5;
  1664. float dist = d * line.lineHalfWidth;
  1665. return line.opacity * clamp(0.5 - dist, 0.0, 1.0) * line.color;
  1666. }
  1667. #elif defined(PATTERN) && !defined(HIGHLIGHT) && !defined(SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE)
  1668. lowp vec4 getLineColor(LineData line) {
  1669. mediump float lineHalfWidth = line.lineHalfWidth;
  1670. mediump float adjustedPatternHeight = line.patternSize.y * 2.0 * lineHalfWidth / line.patternSize.x;
  1671. mediump float relativeTexY = fract(line.accumulatedDistance / adjustedPatternHeight);
  1672. mediump float relativeTexX = 0.5 + 0.5 * line.normal.y;
  1673. mediump vec2 texCoord = mix(line.tlbr.xy, line.tlbr.zw, vec2(relativeTexX, relativeTexY));
  1674. lowp vec4 color = texture2D(u_texture, texCoord);
  1675. #ifdef VV_COLOR
  1676. if (v_sampleAlphaOnly > 0.5) {
  1677. color.rgb = vec3(color.a);
  1678. }
  1679. #endif
  1680. return line.opacity * line.color * color;
  1681. }
  1682. #else
  1683. lowp vec4 getLineColor(LineData line) {
  1684. return line.opacity * line.color;
  1685. }
  1686. #endif
  1687. vec4 shadeLine(LineData line)
  1688. {
  1689. mediump float thinLineFactor = max(THIN_LINE_WIDTH_FACTOR * step(line.lineHalfWidth, THIN_LINE_HALF_WIDTH), 1.0);
  1690. mediump float fragDist = length(line.normal) * line.lineHalfWidth;
  1691. lowp float alpha = clamp(thinLineFactor * (line.lineHalfWidth - fragDist) / (u_blur + thinLineFactor - 1.0), 0.0, 1.0);
  1692. lowp vec4 out_color = getLineColor(line) * alpha;
  1693. #ifdef HIGHLIGHT
  1694. out_color.a = step(1.0 / 255.0, out_color.a);
  1695. #endif
  1696. #ifdef ID
  1697. if (out_color.a < 1.0 / 255.0) {
  1698. discard;
  1699. }
  1700. out_color = vec4(line.id, 0.0);
  1701. #endif
  1702. return out_color;
  1703. }`,"line.vert":`float getBaseLineHalfWidth(in float lineHalfWidth, in float referenceHalfWidth) {
  1704. #ifdef VV_SIZE
  1705. float refLineWidth = 2.0 * referenceHalfWidth;
  1706. return 0.5 * (lineHalfWidth / max(referenceHalfWidth, EPSILON)) * getSize(refLineWidth);
  1707. #else
  1708. return lineHalfWidth;
  1709. #endif
  1710. }
  1711. float getLineHalfWidth(in float baseWidth, in float aa) {
  1712. float halfWidth = max(baseWidth + aa, 0.45) + 0.1 * aa;
  1713. #ifdef HIGHLIGHT
  1714. halfWidth = max(halfWidth, 2.0);
  1715. #endif
  1716. return halfWidth;
  1717. }
  1718. vec2 getDist(in vec2 offset, in float halfWidth) {
  1719. float thinLineFactor = max(THIN_LINE_WIDTH_FACTOR * step(halfWidth, THIN_LINE_HALF_WIDTH), 1.0);
  1720. return thinLineFactor * halfWidth * offset;
  1721. }
  1722. LineData buildLine(
  1723. out vec3 out_pos,
  1724. in vec3 in_id,
  1725. in vec2 in_pos,
  1726. in vec4 in_color,
  1727. in vec2 in_offset,
  1728. in vec2 in_normal,
  1729. in float in_accumulatedDist,
  1730. in float in_lineHalfWidth,
  1731. in float in_bitSet,
  1732. in vec4 in_tlbr,
  1733. in vec2 in_segmentDirection,
  1734. in float in_referenceHalfWidth
  1735. )
  1736. {
  1737. float aa = 0.5 * u_antialiasing;
  1738. float baseWidth = getBaseLineHalfWidth(in_lineHalfWidth, in_referenceHalfWidth);
  1739. float halfWidth = getLineHalfWidth(baseWidth, aa);
  1740. float z = 2.0 * step(baseWidth, 0.0);
  1741. vec2 dist = getDist(in_offset, halfWidth);
  1742. vec3 offset = u_displayViewMat3 * vec3(dist, 0.0);
  1743. vec3 pos = u_dvsMat3 * vec3(in_pos * POSITION_PRECISION, 1.0) + offset;
  1744. #ifdef SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE
  1745. vec4 color = in_color;
  1746. float opacity = 1.0;
  1747. #else
  1748. vec4 color = getColor(in_color, in_bitSet, BITSET_GENERIC_LOCK_COLOR);
  1749. float opacity = getOpacity();
  1750. #ifdef SDF
  1751. const float SDF_PATTERN_HALF_WIDTH = 15.5;
  1752. float scaleDash = getBit(in_bitSet, BITSET_LINE_SCALE_DASH);
  1753. float lineWidthRatio = (scaleDash * max(halfWidth - 0.55 * u_antialiasing, 0.25) + (1.0 - scaleDash)) / SDF_PATTERN_HALF_WIDTH;
  1754. #endif
  1755. #endif
  1756. #if !defined(SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE) && defined(PATTERN)
  1757. v_sampleAlphaOnly = getBit(in_bitSet, BITSET_GENERIC_CONSIDER_ALPHA_ONLY);
  1758. #endif
  1759. out_pos = vec3(pos.xy, z);
  1760. return LineData(
  1761. color,
  1762. in_normal,
  1763. halfWidth,
  1764. opacity,
  1765. #ifndef SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE
  1766. #ifdef PATTERN
  1767. in_tlbr / u_mosaicSize.xyxy,
  1768. vec2(in_tlbr.z - in_tlbr.x, in_tlbr.w - in_tlbr.y),
  1769. #endif
  1770. #ifdef SDF
  1771. lineWidthRatio,
  1772. #endif
  1773. #if defined(PATTERN) || defined(SDF)
  1774. in_accumulatedDist * u_zoomFactor + dot(in_segmentDirection, dist),
  1775. #endif
  1776. #endif
  1777. norm(in_id)
  1778. );
  1779. }`}},"symbologyTypeUtils.glsl":`#if SYMBOLOGY_TYPE == SYMBOLOGY_TYPE_OUTLINE_FILL || SYMBOLOGY_TYPE == SYMBOLOGY_TYPE_OUTLINE_FILL_SIMPLE
  1780. #define SYMBOLOGY_TYPE_IS_OUTLINE_FILL_LIKE
  1781. #endif
  1782. #if SYMBOLOGY_TYPE == SYMBOLOGY_TYPE_SIMPLE || SYMBOLOGY_TYPE == SYMBOLOGY_TYPE_OUTLINE_FILL_SIMPLE
  1783. #define SYMBOLOGY_TYPE_IS_SIMPLE_LIKE
  1784. #endif`,text:{"common.glsl":`uniform highp vec2 u_mosaicSize;
  1785. varying highp vec3 v_id;
  1786. varying mediump vec3 v_pos;
  1787. varying lowp float v_opacity;
  1788. varying lowp vec4 v_color;
  1789. varying highp vec2 v_tex;
  1790. varying mediump float v_antialiasingWidth;
  1791. varying mediump float v_edgeDistanceOffset;
  1792. varying lowp float v_transparency;`,"hittest.glsl":"#include <materials/hittest/common.glsl>","text.frag":`precision mediump float;
  1793. #include <materials/text/common.glsl>
  1794. uniform lowp sampler2D u_texture;
  1795. #ifdef HITTEST
  1796. vec4 getColor() {
  1797. return v_color;
  1798. }
  1799. #else
  1800. vec4 getColor()
  1801. {
  1802. float SDF_CUTOFF = (2.0 / 8.0);
  1803. float SDF_BASE_EDGE_DIST = 1.0 - SDF_CUTOFF;
  1804. lowp float dist = texture2D(u_texture, v_tex).a;
  1805. mediump float edge = SDF_BASE_EDGE_DIST - v_edgeDistanceOffset;
  1806. #ifdef HIGHLIGHT
  1807. edge /= 2.0;
  1808. #endif
  1809. lowp float aa = v_antialiasingWidth;
  1810. lowp float alpha = smoothstep(edge - aa, edge + aa, dist);
  1811. return alpha * v_color * v_opacity;
  1812. }
  1813. #endif
  1814. void main()
  1815. {
  1816. gl_FragColor = getColor();
  1817. }`,"text.vert":`precision highp float;
  1818. #include <materials/utils.glsl>
  1819. #include <materials/vcommon.glsl>
  1820. #include <materials/text/common.glsl>
  1821. #include <materials/text/hittest.glsl>
  1822. attribute vec4 a_color;
  1823. attribute vec4 a_haloColor;
  1824. attribute vec4 a_texFontSize;
  1825. attribute vec4 a_aux;
  1826. attribute vec2 a_zoomRange;
  1827. attribute vec2 a_vertexOffset;
  1828. attribute vec2 a_texCoords;
  1829. uniform float u_isHalo;
  1830. float getTextSize(inout vec2 offset, inout float baseSize, in float referenceSize) {
  1831. #ifdef VV_SIZE
  1832. float r = getSize(referenceSize) / referenceSize;
  1833. baseSize *= r;
  1834. offset.xy *= r;
  1835. return baseSize;
  1836. #endif
  1837. return baseSize;
  1838. }
  1839. void main()
  1840. {
  1841. INIT;
  1842. float a_referenceSize = a_aux.z * a_aux.z / 256.0;
  1843. float a_bitSet = a_aux.w;
  1844. float a_fontSize = a_texFontSize.z;
  1845. vec2 a_offset = a_vertexOffset * OFFSET_PRECISION;
  1846. vec3 in_pos = vec3(a_pos * POSITION_PRECISION, 1.0);
  1847. float fontSize = getTextSize(a_offset, a_fontSize, a_referenceSize);
  1848. float fontScale = fontSize / SDF_FONT_SIZE;
  1849. vec3 offset = getRotation() * vec3(a_offset, 0.0);
  1850. mat3 extrudeMatrix = getBit(a_bitSet, 0) == 1.0 ? u_displayViewMat3 : u_displayMat3;
  1851. v_color = u_isHalo * a_haloColor + (1.0 - u_isHalo) * getColor(a_color, a_bitSet, 1);
  1852. v_opacity = getOpacity();
  1853. v_id = norm(a_id);
  1854. v_tex = a_texCoords / u_mosaicSize;
  1855. v_pos = u_dvsMat3 * in_pos + extrudeMatrix * offset;
  1856. v_edgeDistanceOffset = u_isHalo * OUTLINE_SCALE * a_texFontSize.w / fontScale / MAX_SDF_DISTANCE;
  1857. v_antialiasingWidth = 0.105 * SDF_FONT_SIZE / fontSize / u_pixelRatio;
  1858. #ifdef HITTEST
  1859. highp vec3 out_pos = vec3(0.);
  1860. v_color = vec4(0.);
  1861. hittestMarker(v_color, out_pos, u_viewMat3 * u_tileMat3 * vec3(a_pos * POSITION_PRECISION, 1.0)
  1862. + u_tileMat3 * offset, fontSize / 2.);
  1863. gl_PointSize = 1.;
  1864. gl_Position = vec4(clip(v_color, out_pos, getFilterFlags(), a_zoomRange), 1.0);
  1865. #else
  1866. gl_Position = vec4(clip(v_color, v_pos, getFilterFlags(), a_zoomRange), 1.0);
  1867. #endif
  1868. }`},"utils.glsl":`float rshift(in float u32, in int amount) {
  1869. return floor(u32 / pow(2.0, float(amount)));
  1870. }
  1871. float getBit(in float bitset, in int bitIndex) {
  1872. float offset = pow(2.0, float(bitIndex));
  1873. return mod(floor(bitset / offset), 2.0);
  1874. }
  1875. float getFilterBit(in float bitset, in int bitIndex) {
  1876. return getBit(bitset, bitIndex + 1);
  1877. }
  1878. float getHighlightBit(in float bitset) {
  1879. return getBit(bitset, 0);
  1880. }
  1881. highp vec3 unpackDisplayIdTexel(in highp vec3 bitset) {
  1882. float isAggregate = getBit(bitset.b, 7);
  1883. return (1.0 - isAggregate) * bitset + isAggregate * (vec3(bitset.rgb) - vec3(0.0, 0.0, float(0x80)));
  1884. }
  1885. vec4 unpack(in float u32) {
  1886. float r = mod(rshift(u32, 0), 255.0);
  1887. float g = mod(rshift(u32, 8), 255.0);
  1888. float b = mod(rshift(u32, 16), 255.0);
  1889. float a = mod(rshift(u32, 24), 255.0);
  1890. return vec4(r, g, b, a);
  1891. }
  1892. vec3 norm(in vec3 v) {
  1893. return v /= 255.0;
  1894. }
  1895. vec4 norm(in vec4 v) {
  1896. return v /= 255.0;
  1897. }
  1898. float max4(vec4 target) {
  1899. return max(max(max(target.x, target.y), target.z), target.w);
  1900. }
  1901. vec2 unpack_u8_nf32(vec2 bytes) {
  1902. return (bytes - 127.0) / 127.0;
  1903. }
  1904. highp float rand(in vec2 co) {
  1905. highp float a = 12.9898;
  1906. highp float b = 78.233;
  1907. highp float c = 43758.5453;
  1908. highp float dt = dot(co, vec2(a,b));
  1909. highp float sn = mod(dt, 3.14);
  1910. return fract(sin(sn) * c);
  1911. }`,"vcommon.glsl":`#include <materials/constants.glsl>
  1912. #include <materials/utils.glsl>
  1913. #include <materials/attributeData.glsl>
  1914. #include <materials/vv.glsl>
  1915. #include <materials/barycentric.glsl>
  1916. attribute vec2 a_pos;
  1917. attribute highp vec3 a_id;
  1918. uniform highp mat3 u_dvsMat3;
  1919. uniform highp mat3 u_displayMat3;
  1920. uniform highp mat3 u_displayViewMat3;
  1921. uniform highp mat3 u_tileMat3;
  1922. uniform highp mat3 u_viewMat3;
  1923. uniform highp float u_pixelRatio;
  1924. uniform mediump float u_zoomFactor;
  1925. uniform mediump float u_antialiasing;
  1926. uniform mediump float u_currentZoom;
  1927. vec4 VV_ADATA = vec4(0.0);
  1928. void loadVisualVariableData(inout vec4 target) {
  1929. #ifdef SUPPORTS_TEXTURE_FLOAT
  1930. target.rgba = getAttributeData2(a_id);
  1931. #else
  1932. vec4 data0 = getAttributeData2(a_id);
  1933. vec4 data1 = getAttributeData3(a_id);
  1934. target.r = u88VVToFloat(data0.rg * 255.0);
  1935. target.g = u88VVToFloat(data0.ba * 255.0);
  1936. target.b = u88VVToFloat(data1.rg * 255.0);
  1937. target.a = u88VVToFloat(data1.ba * 255.0);
  1938. #endif
  1939. }
  1940. #ifdef VV
  1941. #define INIT loadVisualVariableData(VV_ADATA)
  1942. #else
  1943. #define INIT
  1944. #endif
  1945. vec4 getColor(in vec4 a_color, in float a_bitSet, int index) {
  1946. #ifdef VV_COLOR
  1947. float isColorLocked = getBit(a_bitSet, index);
  1948. return getVVColor(VV_ADATA[ATTR_VV_COLOR], a_color, isColorLocked);
  1949. #else
  1950. return a_color;
  1951. #endif
  1952. }
  1953. float getOpacity() {
  1954. #ifdef VV_OPACITY
  1955. return getVVOpacity(VV_ADATA[ATTR_VV_OPACITY]);
  1956. #else
  1957. return 1.0;
  1958. #endif
  1959. }
  1960. float getSize(in float in_size) {
  1961. #ifdef VV_SIZE
  1962. return getVVSize(in_size, VV_ADATA[ATTR_VV_SIZE]);
  1963. #else
  1964. return in_size;
  1965. #endif
  1966. }
  1967. mat3 getRotation() {
  1968. #ifdef VV_ROTATION
  1969. return getVVRotationMat3(mod(VV_ADATA[ATTR_VV_ROTATION], 360.0));
  1970. #else
  1971. return mat3(1.0);
  1972. #endif
  1973. }
  1974. float getFilterFlags() {
  1975. #ifdef IGNORES_SAMPLER_PRECISION
  1976. return ceil(getAttributeData0(a_id).x * 255.0);
  1977. #else
  1978. return getAttributeData0(a_id).x * 255.0;
  1979. #endif
  1980. }
  1981. vec4 getAnimationState() {
  1982. return getAttributeData1(a_id);
  1983. }
  1984. float getMinZoom() {
  1985. vec4 data0 = getAttributeData0(a_id) * 255.0;
  1986. return data0.g;
  1987. }
  1988. mat3 getMatrixNoDisplay(float isMapAligned) {
  1989. return isMapAligned * u_viewMat3 * u_tileMat3 + (1.0 - isMapAligned) * u_tileMat3;
  1990. }
  1991. mat3 getMatrix(float isMapAligned) {
  1992. return isMapAligned * u_displayViewMat3 + (1.0 - isMapAligned) * u_displayMat3;
  1993. }
  1994. vec3 clip(inout vec4 color, inout vec3 pos, in float filterFlags, in vec2 minMaxZoom) {
  1995. pos.z += 2.0 * (1.0 - getFilterBit(filterFlags, 0));
  1996. #ifdef INSIDE
  1997. pos.z += 2.0 * (1.0 - getFilterBit(filterFlags, 1));
  1998. #elif defined(OUTSIDE)
  1999. pos.z += 2.0 * getFilterBit(filterFlags, 1);
  2000. #elif defined(HIGHLIGHT)
  2001. #if !defined(HIGHLIGHT_ALL)
  2002. pos.z += 2.0 * (1.0 - getHighlightBit(filterFlags));
  2003. #endif
  2004. #endif
  2005. pos.z += 2.0 * (step(minMaxZoom.y, u_currentZoom) + (1.0 - step(minMaxZoom.x, u_currentZoom)));
  2006. return pos;
  2007. }`,"vv.glsl":`#if defined(VV_SIZE_MIN_MAX_VALUE) || defined(VV_SIZE_SCALE_STOPS) || defined(VV_SIZE_FIELD_STOPS) || defined(VV_SIZE_UNIT_VALUE)
  2008. #define VV_SIZE
  2009. #endif
  2010. #if defined(VV_COLOR) || defined(VV_SIZE) || defined(VV_OPACITY) || defined(VV_ROTATION)
  2011. #define VV
  2012. #endif
  2013. #ifdef VV_COLOR
  2014. uniform highp float u_vvColorValues[8];
  2015. uniform vec4 u_vvColors[8];
  2016. #endif
  2017. #ifdef VV_SIZE_MIN_MAX_VALUE
  2018. uniform highp vec4 u_vvSizeMinMaxValue;
  2019. #endif
  2020. #ifdef VV_SIZE_SCALE_STOPS
  2021. uniform highp float u_vvSizeScaleStopsValue;
  2022. #endif
  2023. #ifdef VV_SIZE_FIELD_STOPS
  2024. uniform highp float u_vvSizeFieldStopsValues[6];
  2025. uniform float u_vvSizeFieldStopsSizes[6];
  2026. #endif
  2027. #ifdef VV_SIZE_UNIT_VALUE
  2028. uniform highp float u_vvSizeUnitValueWorldToPixelsRatio;
  2029. #endif
  2030. #ifdef VV_OPACITY
  2031. uniform highp float u_vvOpacityValues[8];
  2032. uniform float u_vvOpacities[8];
  2033. #endif
  2034. #ifdef VV_ROTATION
  2035. uniform lowp float u_vvRotationType;
  2036. #endif
  2037. bool isNan(float val) {
  2038. return (val == NAN_MAGIC_NUMBER);
  2039. }
  2040. #ifdef VV_SIZE_MIN_MAX_VALUE
  2041. float getVVMinMaxSize(float sizeValue, float fallback) {
  2042. if (isNan(sizeValue)) {
  2043. return fallback;
  2044. }
  2045. float interpolationRatio = (sizeValue - u_vvSizeMinMaxValue.x) / (u_vvSizeMinMaxValue.y - u_vvSizeMinMaxValue.x);
  2046. interpolationRatio = clamp(interpolationRatio, 0.0, 1.0);
  2047. return u_vvSizeMinMaxValue.z + interpolationRatio * (u_vvSizeMinMaxValue.w - u_vvSizeMinMaxValue.z);
  2048. }
  2049. #endif
  2050. #ifdef VV_SIZE_FIELD_STOPS
  2051. const int VV_SIZE_N = 6;
  2052. float getVVStopsSize(float sizeValue, float fallback) {
  2053. if (isNan(sizeValue)) {
  2054. return fallback;
  2055. }
  2056. if (sizeValue <= u_vvSizeFieldStopsValues[0]) {
  2057. return u_vvSizeFieldStopsSizes[0];
  2058. }
  2059. for (int i = 1; i < VV_SIZE_N; ++i) {
  2060. if (u_vvSizeFieldStopsValues[i] >= sizeValue) {
  2061. float f = (sizeValue - u_vvSizeFieldStopsValues[i-1]) / (u_vvSizeFieldStopsValues[i] - u_vvSizeFieldStopsValues[i-1]);
  2062. return mix(u_vvSizeFieldStopsSizes[i-1], u_vvSizeFieldStopsSizes[i], f);
  2063. }
  2064. }
  2065. return u_vvSizeFieldStopsSizes[VV_SIZE_N - 1];
  2066. }
  2067. #endif
  2068. #ifdef VV_SIZE_UNIT_VALUE
  2069. float getVVUnitValue(float sizeValue, float fallback) {
  2070. if (isNan(sizeValue)) {
  2071. return fallback;
  2072. }
  2073. return u_vvSizeUnitValueWorldToPixelsRatio * sizeValue;
  2074. }
  2075. #endif
  2076. #ifdef VV_OPACITY
  2077. const int VV_OPACITY_N = 8;
  2078. float getVVOpacity(float opacityValue) {
  2079. if (isNan(opacityValue)) {
  2080. return 1.0;
  2081. }
  2082. if (opacityValue <= u_vvOpacityValues[0]) {
  2083. return u_vvOpacities[0];
  2084. }
  2085. for (int i = 1; i < VV_OPACITY_N; ++i) {
  2086. if (u_vvOpacityValues[i] >= opacityValue) {
  2087. float f = (opacityValue - u_vvOpacityValues[i-1]) / (u_vvOpacityValues[i] - u_vvOpacityValues[i-1]);
  2088. return mix(u_vvOpacities[i-1], u_vvOpacities[i], f);
  2089. }
  2090. }
  2091. return u_vvOpacities[VV_OPACITY_N - 1];
  2092. }
  2093. #endif
  2094. #ifdef VV_ROTATION
  2095. mat4 getVVRotation(float rotationValue) {
  2096. if (isNan(rotationValue)) {
  2097. return mat4(1, 0, 0, 0,
  2098. 0, 1, 0, 0,
  2099. 0, 0, 1, 0,
  2100. 0, 0, 0, 1);
  2101. }
  2102. float rotation = rotationValue;
  2103. if (u_vvRotationType == 1.0) {
  2104. rotation = 90.0 - rotation;
  2105. }
  2106. float angle = C_DEG_TO_RAD * rotation;
  2107. float sinA = sin(angle);
  2108. float cosA = cos(angle);
  2109. return mat4(cosA, sinA, 0, 0,
  2110. -sinA, cosA, 0, 0,
  2111. 0, 0, 1, 0,
  2112. 0, 0, 0, 1);
  2113. }
  2114. mat3 getVVRotationMat3(float rotationValue) {
  2115. if (isNan(rotationValue)) {
  2116. return mat3(1, 0, 0,
  2117. 0, 1, 0,
  2118. 0, 0, 1);
  2119. }
  2120. float rotation = rotationValue;
  2121. if (u_vvRotationType == 1.0) {
  2122. rotation = 90.0 - rotation;
  2123. }
  2124. float angle = C_DEG_TO_RAD * -rotation;
  2125. float sinA = sin(angle);
  2126. float cosA = cos(angle);
  2127. return mat3(cosA, -sinA, 0,
  2128. sinA, cosA, 0,
  2129. 0, 0, 1);
  2130. }
  2131. #endif
  2132. #ifdef VV_COLOR
  2133. const int VV_COLOR_N = 8;
  2134. vec4 getVVColor(float colorValue, vec4 fallback, float isColorLocked) {
  2135. if (isNan(colorValue) || isColorLocked == 1.0) {
  2136. return fallback;
  2137. }
  2138. if (colorValue <= u_vvColorValues[0]) {
  2139. return u_vvColors[0];
  2140. }
  2141. for (int i = 1; i < VV_COLOR_N; ++i) {
  2142. if (u_vvColorValues[i] >= colorValue) {
  2143. float f = (colorValue - u_vvColorValues[i-1]) / (u_vvColorValues[i] - u_vvColorValues[i-1]);
  2144. return mix(u_vvColors[i-1], u_vvColors[i], f);
  2145. }
  2146. }
  2147. return u_vvColors[VV_COLOR_N - 1];
  2148. }
  2149. #endif
  2150. float getVVSize(in float size, in float vvSize) {
  2151. #ifdef VV_SIZE_MIN_MAX_VALUE
  2152. return getVVMinMaxSize(vvSize, size);
  2153. #elif defined(VV_SIZE_SCALE_STOPS)
  2154. return u_vvSizeScaleStopsValue;
  2155. #elif defined(VV_SIZE_FIELD_STOPS)
  2156. float outSize = getVVStopsSize(vvSize, size);
  2157. return isNan(outSize) ? size : outSize;
  2158. #elif defined(VV_SIZE_UNIT_VALUE)
  2159. return getVVUnitValue(vvSize, size);
  2160. #else
  2161. return size;
  2162. #endif
  2163. }`},overlay:{overlay:{"overlay.frag":`precision lowp float;
  2164. uniform lowp sampler2D u_texture;
  2165. uniform lowp float u_opacity;
  2166. varying mediump vec2 v_uv;
  2167. void main() {
  2168. vec4 color = texture2D(u_texture, v_uv);
  2169. gl_FragColor = color * u_opacity;
  2170. }`,"overlay.vert":`precision mediump float;
  2171. attribute vec2 a_pos;
  2172. attribute vec2 a_uv;
  2173. uniform highp mat3 u_dvsMat3;
  2174. uniform mediump vec2 u_perspective;
  2175. varying mediump vec2 v_uv;
  2176. void main(void) {
  2177. v_uv = a_uv;
  2178. float w = 1.0 + dot(a_uv, u_perspective);
  2179. vec3 pos = u_dvsMat3 * vec3(a_pos, 1.0);
  2180. gl_Position = vec4(w * pos.xy, 0.0, w);
  2181. }`}},"post-processing":{blit:{"blit.frag":`precision mediump float;
  2182. uniform sampler2D u_texture;
  2183. varying vec2 v_uv;
  2184. void main() {
  2185. gl_FragColor = texture2D(u_texture, v_uv);
  2186. }`},bloom:{composite:{"composite.frag":`precision mediump float;
  2187. varying vec2 v_uv;
  2188. uniform sampler2D u_blurTexture1;
  2189. uniform sampler2D u_blurTexture2;
  2190. uniform sampler2D u_blurTexture3;
  2191. uniform sampler2D u_blurTexture4;
  2192. uniform sampler2D u_blurTexture5;
  2193. uniform float u_bloomStrength;
  2194. uniform float u_bloomRadius;
  2195. uniform float u_bloomFactors[NUMMIPS];
  2196. uniform vec3 u_bloomTintColors[NUMMIPS];
  2197. float lerpBloomFactor(const in float factor) {
  2198. float mirrorFactor = 1.2 - factor;
  2199. return mix(factor, mirrorFactor, u_bloomRadius);
  2200. }
  2201. void main() {
  2202. vec4 color = u_bloomStrength * (
  2203. lerpBloomFactor(u_bloomFactors[0]) * vec4(u_bloomTintColors[0], 1.0) * texture2D(u_blurTexture1, v_uv) +
  2204. lerpBloomFactor(u_bloomFactors[1]) * vec4(u_bloomTintColors[1], 1.0) * texture2D(u_blurTexture2, v_uv) +
  2205. lerpBloomFactor(u_bloomFactors[2]) * vec4(u_bloomTintColors[2], 1.0) * texture2D(u_blurTexture3, v_uv) +
  2206. lerpBloomFactor(u_bloomFactors[3]) * vec4(u_bloomTintColors[3], 1.0) * texture2D(u_blurTexture4, v_uv) +
  2207. lerpBloomFactor(u_bloomFactors[4]) * vec4(u_bloomTintColors[4], 1.0) * texture2D(u_blurTexture5, v_uv)
  2208. );
  2209. gl_FragColor = clamp(color, 0.0, 1.0);
  2210. }`},gaussianBlur:{"gaussianBlur.frag":`precision mediump float;
  2211. uniform sampler2D u_colorTexture;
  2212. uniform vec2 u_texSize;
  2213. uniform vec2 u_direction;
  2214. varying vec2 v_uv;
  2215. #define KERNEL_RADIUS RADIUS
  2216. #define SIGMA RADIUS
  2217. float gaussianPdf(in float x, in float sigma) {
  2218. return 0.39894 * exp(-0.5 * x * x / ( sigma * sigma)) / sigma;
  2219. }
  2220. void main() {
  2221. vec2 invSize = 1.0 / u_texSize;
  2222. float fSigma = float(SIGMA);
  2223. float weightSum = gaussianPdf(0.0, fSigma);
  2224. vec4 pixelColorSum = texture2D(u_colorTexture, v_uv) * weightSum;
  2225. for (int i = 1; i < KERNEL_RADIUS; i ++) {
  2226. float x = float(i);
  2227. float w = gaussianPdf(x, fSigma);
  2228. vec2 uvOffset = u_direction * invSize * x;
  2229. vec4 sample1 = texture2D(u_colorTexture, v_uv + uvOffset);
  2230. vec4 sample2 = texture2D(u_colorTexture, v_uv - uvOffset);
  2231. pixelColorSum += (sample1 + sample2) * w;
  2232. weightSum += 2.0 * w;
  2233. }
  2234. gl_FragColor = pixelColorSum /weightSum;
  2235. }`},luminosityHighPass:{"luminosityHighPass.frag":`precision mediump float;
  2236. uniform sampler2D u_texture;
  2237. uniform vec3 u_defaultColor;
  2238. uniform float u_defaultOpacity;
  2239. uniform float u_luminosityThreshold;
  2240. uniform float u_smoothWidth;
  2241. varying vec2 v_uv;
  2242. void main() {
  2243. vec4 texel = texture2D(u_texture, v_uv);
  2244. vec3 luma = vec3(0.299, 0.587, 0.114);
  2245. float v = dot(texel.xyz, luma);
  2246. vec4 outputColor = vec4(u_defaultColor.rgb, u_defaultOpacity);
  2247. float alpha = smoothstep(u_luminosityThreshold, u_luminosityThreshold + u_smoothWidth, v);
  2248. gl_FragColor = mix(outputColor, texel, alpha);
  2249. }`}},blur:{gaussianBlur:{"gaussianBlur.frag":`precision mediump float;
  2250. uniform sampler2D u_colorTexture;
  2251. uniform vec2 u_texSize;
  2252. uniform vec2 u_direction;
  2253. uniform float u_sigma;
  2254. varying vec2 v_uv;
  2255. #define KERNEL_RADIUS RADIUS
  2256. float gaussianPdf(in float x, in float sigma) {
  2257. return 0.39894 * exp(-0.5 * x * x / ( sigma * sigma)) / sigma;
  2258. }
  2259. void main() {
  2260. vec2 invSize = 1.0 / u_texSize;
  2261. float fSigma = u_sigma;
  2262. float weightSum = gaussianPdf(0.0, fSigma);
  2263. vec4 pixelColorSum = texture2D(u_colorTexture, v_uv) * weightSum;
  2264. for (int i = 1; i < KERNEL_RADIUS; i ++) {
  2265. float x = float(i);
  2266. float w = gaussianPdf(x, fSigma);
  2267. vec2 uvOffset = u_direction * invSize * x;
  2268. vec4 sample1 = texture2D(u_colorTexture, v_uv + uvOffset);
  2269. vec4 sample2 = texture2D(u_colorTexture, v_uv - uvOffset);
  2270. pixelColorSum += (sample1 + sample2) * w;
  2271. weightSum += 2.0 * w;
  2272. }
  2273. gl_FragColor = pixelColorSum /weightSum;
  2274. }`},"radial-blur":{"radial-blur.frag":`precision mediump float;
  2275. uniform sampler2D u_colorTexture;
  2276. varying vec2 v_uv;
  2277. const float sampleDist = 1.0;
  2278. const float sampleStrength = 2.2;
  2279. void main(void) {
  2280. float samples[10];
  2281. samples[0] = -0.08;
  2282. samples[1] = -0.05;
  2283. samples[2] = -0.03;
  2284. samples[3] = -0.02;
  2285. samples[4] = -0.01;
  2286. samples[5] = 0.01;
  2287. samples[6] = 0.02;
  2288. samples[7] = 0.03;
  2289. samples[8] = 0.05;
  2290. samples[9] = 0.08;
  2291. vec2 dir = 0.5 - v_uv;
  2292. float dist = sqrt(dir.x * dir.x + dir.y * dir.y);
  2293. dir = dir / dist;
  2294. vec4 color = texture2D(u_colorTexture,v_uv);
  2295. vec4 sum = color;
  2296. for (int i = 0; i < 10; i++) {
  2297. sum += texture2D(u_colorTexture, v_uv + dir * samples[i] * sampleDist);
  2298. }
  2299. sum *= 1.0 / 11.0;
  2300. float t = dist * sampleStrength;
  2301. t = clamp(t, 0.0, 1.0);
  2302. gl_FragColor = mix(color, sum, t);
  2303. }`}},dra:{"dra.frag":`precision mediump float;
  2304. uniform sampler2D u_minColor;
  2305. uniform sampler2D u_maxColor;
  2306. uniform sampler2D u_texture;
  2307. varying vec2 v_uv;
  2308. void main() {
  2309. vec4 minColor = texture2D(u_minColor, vec2(0.5));
  2310. vec4 maxColor = texture2D(u_maxColor, vec2(0.5));
  2311. vec4 color = texture2D(u_texture, v_uv);
  2312. vec3 minColorUnpremultiply = minColor.rgb / minColor.a;
  2313. vec3 maxColorUnpremultiply = maxColor.rgb / maxColor.a;
  2314. vec3 colorUnpremultiply = color.rgb / color.a;
  2315. vec3 range = maxColorUnpremultiply - minColorUnpremultiply;
  2316. gl_FragColor = vec4(color.a * (colorUnpremultiply - minColorUnpremultiply) / range, color.a);
  2317. }`,"min-max":{"min-max.frag":`#extension GL_EXT_draw_buffers : require
  2318. precision mediump float;
  2319. #define CELL_SIZE 2
  2320. uniform sampler2D u_minTexture;
  2321. uniform sampler2D u_maxTexture;
  2322. uniform vec2 u_srcResolution;
  2323. uniform vec2 u_dstResolution;
  2324. varying vec2 v_uv;
  2325. void main() {
  2326. vec2 srcPixel = floor(gl_FragCoord.xy) * float(CELL_SIZE);
  2327. vec2 onePixel = vec2(1.0) / u_srcResolution;
  2328. vec2 uv = (srcPixel + 0.5) / u_srcResolution;
  2329. vec4 minColor = vec4(1.0);
  2330. vec4 maxColor = vec4(0.0);
  2331. for (int y = 0; y < CELL_SIZE; ++y) {
  2332. for (int x = 0; x < CELL_SIZE; ++x) {
  2333. vec2 offset = uv + vec2(x, y) * onePixel;
  2334. minColor = min(minColor, texture2D(u_minTexture, offset));
  2335. maxColor = max(maxColor, texture2D(u_maxTexture, offset));
  2336. }
  2337. }
  2338. gl_FragData[0] = minColor;
  2339. gl_FragData[1] = maxColor;
  2340. }`}},"drop-shadow":{composite:{"composite.frag":`precision mediump float;
  2341. uniform sampler2D u_layerFBOTexture;
  2342. uniform sampler2D u_blurTexture;
  2343. uniform vec4 u_shadowColor;
  2344. uniform vec2 u_shadowOffset;
  2345. uniform highp mat3 u_displayViewMat3;
  2346. varying vec2 v_uv;
  2347. void main() {
  2348. vec3 offset = u_displayViewMat3 * vec3(u_shadowOffset, 0.0);
  2349. vec4 layerColor = texture2D(u_layerFBOTexture, v_uv);
  2350. vec4 blurColor = texture2D(u_blurTexture, v_uv - offset.xy / 2.0);
  2351. gl_FragColor = ((1.0 - layerColor.a) * blurColor.a * u_shadowColor + layerColor);
  2352. }`}},"edge-detect":{"frei-chen":{"frei-chen.frag":`precision mediump float;
  2353. uniform sampler2D u_colorTexture;
  2354. uniform vec2 u_texSize;
  2355. varying vec2 v_uv;
  2356. vec2 texel = vec2(1.0 / u_texSize.x, 1.0 / u_texSize.y);
  2357. mat3 G[9];
  2358. const mat3 g0 = mat3( 0.3535533845424652, 0, -0.3535533845424652, 0.5, 0, -0.5, 0.3535533845424652, 0, -0.3535533845424652 );
  2359. const mat3 g1 = mat3( 0.3535533845424652, 0.5, 0.3535533845424652, 0, 0, 0, -0.3535533845424652, -0.5, -0.3535533845424652 );
  2360. const mat3 g2 = mat3( 0, 0.3535533845424652, -0.5, -0.3535533845424652, 0, 0.3535533845424652, 0.5, -0.3535533845424652, 0 );
  2361. const mat3 g3 = mat3( 0.5, -0.3535533845424652, 0, -0.3535533845424652, 0, 0.3535533845424652, 0, 0.3535533845424652, -0.5 );
  2362. const mat3 g4 = mat3( 0, -0.5, 0, 0.5, 0, 0.5, 0, -0.5, 0 );
  2363. const mat3 g5 = mat3( -0.5, 0, 0.5, 0, 0, 0, 0.5, 0, -0.5 );
  2364. const mat3 g6 = mat3( 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.6666666865348816, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204 );
  2365. const mat3 g7 = mat3( -0.3333333432674408, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, 0.6666666865348816, 0.1666666716337204, -0.3333333432674408, 0.1666666716337204, -0.3333333432674408 );
  2366. const mat3 g8 = mat3( 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408, 0.3333333432674408 );
  2367. void main() {
  2368. G[0] = g0,
  2369. G[1] = g1,
  2370. G[2] = g2,
  2371. G[3] = g3,
  2372. G[4] = g4,
  2373. G[5] = g5,
  2374. G[6] = g6,
  2375. G[7] = g7,
  2376. G[8] = g8;
  2377. mat3 I;
  2378. float cnv[9];
  2379. vec3 sample;
  2380. for (float i = 0.0; i < 3.0; i++) {
  2381. for (float j = 0.0; j < 3.0; j++) {
  2382. sample = texture2D(u_colorTexture, v_uv + texel * vec2(i - 1.0,j - 1.0)).rgb;
  2383. I[int(i)][int(j)] = length(sample);
  2384. }
  2385. }
  2386. for (int i = 0; i < 9; i++) {
  2387. float dp3 = dot(G[i][0], I[0]) + dot(G[i][1], I[1]) + dot(G[i][2], I[2]);
  2388. cnv[i] = dp3 * dp3;
  2389. }
  2390. float M = (cnv[0] + cnv[1]) + (cnv[2] + cnv[3]);
  2391. float S = (cnv[4] + cnv[5]) + (cnv[6] + cnv[7]) + (cnv[8] + M);
  2392. gl_FragColor = vec4(vec3(sqrt(M / S)), texture2D(u_colorTexture, v_uv).a);
  2393. }`},sobel:{"sobel.frag":`precision mediump float;
  2394. uniform sampler2D u_colorTexture;
  2395. varying vec2 v_uv;
  2396. uniform vec2 u_texSize;
  2397. vec2 texel = vec2(1.0 / u_texSize.x, 1.0 / u_texSize.y);
  2398. mat3 G[2];
  2399. const mat3 g0 = mat3( 1.0, 2.0, 1.0, 0.0, 0.0, 0.0, -1.0, -2.0, -1.0 );
  2400. const mat3 g1 = mat3( 1.0, 0.0, -1.0, 2.0, 0.0, -2.0, 1.0, 0.0, -1.0 );
  2401. void main() {
  2402. mat3 I;
  2403. float cnv[2];
  2404. vec3 sample;
  2405. G[0] = g0;
  2406. G[1] = g1;
  2407. for (float i = 0.0; i < 3.0; i++) {
  2408. for (float j = 0.0; j < 3.0; j++) {
  2409. sample = texture2D( u_colorTexture, v_uv + texel * vec2(i-1.0,j-1.0) ).rgb;
  2410. I[int(i)][int(j)] = length(sample);
  2411. }
  2412. }
  2413. for (int i = 0; i < 2; i++) {
  2414. float dp3 = dot(G[i][0], I[0]) + dot(G[i][1], I[1]) + dot(G[i][2], I[2]);
  2415. cnv[i] = dp3 * dp3;
  2416. }
  2417. gl_FragColor = vec4(vec3(0.5 * sqrt(cnv[0] * cnv[0] + cnv[1] * cnv[1])), texture2D(u_colorTexture, v_uv).a);
  2418. }`}},"edge-enhance":{"edge-enhance.frag":`precision mediump float;
  2419. uniform sampler2D u_colorTexture;
  2420. varying vec2 v_uv;
  2421. uniform vec2 u_texSize;
  2422. vec2 texel = vec2(1.0 / u_texSize.x, 1.0 / u_texSize.y);
  2423. mat3 G[2];
  2424. const mat3 g0 = mat3( 1.0, 0.0, -1.0, 1.0, 0.0, -1.0, 1.0, 0.0, -1.0 );
  2425. const mat3 g1 = mat3( 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0 );
  2426. void main() {
  2427. mat3 I;
  2428. float cnv[2];
  2429. vec3 sample;
  2430. G[0] = g0;
  2431. G[1] = g1;
  2432. for (float i = 0.0; i < 3.0; i++) {
  2433. for (float j = 0.0; j < 3.0; j++) {
  2434. sample = texture2D( u_colorTexture, v_uv + texel * vec2(i-1.0,j-1.0) ).rgb;
  2435. I[int(i)][int(j)] = length(sample);
  2436. }
  2437. }
  2438. for (int i = 0; i < 2; i++) {
  2439. float dp3 = dot(G[i][0], I[0]) + dot(G[i][1], I[1]) + dot(G[i][2], I[2]);
  2440. cnv[i] = dp3 * dp3;
  2441. }
  2442. vec4 color = texture2D(u_colorTexture, v_uv);
  2443. gl_FragColor = vec4(0.5 * sqrt(cnv[0] * cnv[0] + cnv[1] * cnv[1]) * color);
  2444. }`},filterEffect:{"filterEffect.frag":`precision mediump float;
  2445. uniform sampler2D u_colorTexture;
  2446. uniform mat4 u_coefficients;
  2447. varying vec2 v_uv;
  2448. void main() {
  2449. vec4 color = texture2D(u_colorTexture, v_uv);
  2450. vec4 rgbw = u_coefficients * vec4(color.a > 0.0 ? color.rgb / color.a : vec3(0.0), 1.0);
  2451. float a = color.a;
  2452. gl_FragColor = vec4(a * rgbw.rgb, a);
  2453. }`},pp:{"pp.vert":`precision mediump float;
  2454. attribute vec2 a_position;
  2455. varying vec2 v_uv;
  2456. void main() {
  2457. gl_Position = vec4(a_position, 0.0, 1.0);
  2458. v_uv = (a_position + 1.0) / 2.0;
  2459. }`}},raster:{bitmap:{"bitmap.frag":`precision mediump float;
  2460. varying highp vec2 v_texcoord;
  2461. uniform sampler2D u_texture;
  2462. uniform highp vec2 u_coordScale;
  2463. uniform lowp float u_opacity;
  2464. #include <filtering/bicubic.glsl>
  2465. void main() {
  2466. #ifdef BICUBIC
  2467. vec4 color = sampleBicubicBSpline(u_texture, v_texcoord, u_coordScale);
  2468. #else
  2469. vec4 color = texture2D(u_texture, v_texcoord);
  2470. #endif
  2471. gl_FragColor = vec4(color.rgb * u_opacity, color.a * u_opacity);
  2472. }`,"bitmap.vert":`precision mediump float;
  2473. attribute vec2 a_pos;
  2474. uniform highp mat3 u_dvsMat3;
  2475. uniform highp vec2 u_coordScale;
  2476. varying highp vec2 v_texcoord;
  2477. void main()
  2478. {
  2479. v_texcoord = a_pos;
  2480. gl_Position = vec4(u_dvsMat3 * vec3(a_pos * u_coordScale, 1.0), 1.0);
  2481. }`},common:{"common.glsl":`uniform sampler2D u_image;
  2482. uniform int u_bandCount;
  2483. uniform bool u_flipY;
  2484. uniform float u_opacity;
  2485. uniform int u_resampling;
  2486. uniform vec2 u_srcImageSize;
  2487. #ifdef APPLY_PROJECTION
  2488. #include <raster/common/projection.glsl>
  2489. #endif
  2490. #ifdef BICUBIC
  2491. #include <filtering/bicubic.glsl>
  2492. #endif
  2493. #ifdef BILINEAR
  2494. #include <filtering/bilinear.glsl>
  2495. #endif
  2496. vec2 getPixelLocation(vec2 coords) {
  2497. vec2 targetLocation = u_flipY ? vec2(coords.s, 1.0 - coords.t) : coords;
  2498. #ifdef APPLY_PROJECTION
  2499. targetLocation = projectPixelLocation(targetLocation);
  2500. #endif
  2501. return targetLocation;
  2502. }
  2503. bool isOutside(vec2 coords){
  2504. if (coords.t>1.00001 ||coords.t<-0.00001 || coords.s>1.00001 ||coords.s<-0.00001) {
  2505. return true;
  2506. } else {
  2507. return false;
  2508. }
  2509. }
  2510. vec4 getPixel(vec2 pixelLocation) {
  2511. #ifdef BICUBIC
  2512. vec4 color = sampleBicubicBSpline(u_image, pixelLocation, u_srcImageSize);
  2513. #elif defined(BILINEAR)
  2514. vec4 color = sampleBilinear(u_image, pixelLocation, u_srcImageSize);
  2515. #else
  2516. vec4 color = texture2D(u_image, pixelLocation);
  2517. #endif
  2518. return color;
  2519. }`,"contrastBrightness.glsl":`uniform float u_contrastOffset;
  2520. uniform float u_brightnessOffset;
  2521. vec4 adjustContrastBrightness(vec4 currentPixel, bool isFloat) {
  2522. vec4 pixelValue = isFloat ? currentPixel * 255.0 : currentPixel;
  2523. float maxI = 255.0;
  2524. float mid = 128.0;
  2525. float c = u_contrastOffset;
  2526. float b = u_brightnessOffset;
  2527. vec4 v;
  2528. if (c > 0.0 && c < 100.0) {
  2529. v = (200.0 * pixelValue - 100.0 * maxI + 2.0 * maxI * b) / (2.0 * (100.0 - c)) + mid;
  2530. } else if (c <= 0.0 && c > -100.0) {
  2531. v = (200.0 * pixelValue - 100.0 * maxI + 2.0 * maxI * b) * (100.0 + c) / 20000.0 + mid;
  2532. } else if (c == 100.0) {
  2533. v = (200.0 * pixelValue - 100.0 * maxI + (maxI + 1.0) * (100.0 - c) + 2.0 * maxI * b);
  2534. v = (sign(v) + 1.0) / 2.0;
  2535. } else if (c == -100.0) {
  2536. v = vec4(mid, mid, mid, currentPixel.a);
  2537. }
  2538. return vec4(v.r / 255.0, v.g / 255.0, v.b / 255.0, currentPixel.a);
  2539. }`,"projection.glsl":`uniform sampler2D u_transformGrid;
  2540. uniform vec2 u_transformSpacing;
  2541. uniform vec2 u_transformGridSize;
  2542. uniform vec2 u_targetImageSize;
  2543. vec2 projectPixelLocation(vec2 coords) {
  2544. #ifdef LOOKUP_PROJECTION
  2545. vec4 pv = texture2D(u_transformGrid, coords);
  2546. return vec2(pv.r, pv.g);
  2547. #endif
  2548. vec2 index_image = floor(coords * u_targetImageSize);
  2549. vec2 oneTransformPixel = vec2(0.25 / u_transformGridSize.s, 1.0 / u_transformGridSize.t);
  2550. vec2 index_transform = floor(index_image / u_transformSpacing) / u_transformGridSize;
  2551. vec2 pos = fract((index_image + vec2(0.5, 0.5)) / u_transformSpacing);
  2552. vec2 srcLocation;
  2553. vec2 transform_location = index_transform + oneTransformPixel * 0.5;
  2554. if (pos.s <= pos.t) {
  2555. vec4 ll_abc = texture2D(u_transformGrid, vec2(transform_location.s, transform_location.t));
  2556. vec4 ll_def = texture2D(u_transformGrid, vec2(transform_location.s + oneTransformPixel.s, transform_location.t));
  2557. srcLocation.s = dot(ll_abc.rgb, vec3(pos, 1.0));
  2558. srcLocation.t = dot(ll_def.rgb, vec3(pos, 1.0));
  2559. } else {
  2560. vec4 ur_abc = texture2D(u_transformGrid, vec2(transform_location.s + 2.0 * oneTransformPixel.s, transform_location.t));
  2561. vec4 ur_def = texture2D(u_transformGrid, vec2(transform_location.s + 3.0 * oneTransformPixel.s, transform_location.t));
  2562. srcLocation.s = dot(ur_abc.rgb, vec3(pos, 1.0));
  2563. srcLocation.t = dot(ur_def.rgb, vec3(pos, 1.0));
  2564. }
  2565. return srcLocation;
  2566. }`},flow:{"getFadeOpacity.glsl":`uniform float u_decayRate;
  2567. uniform float u_fadeToZero;
  2568. float getFadeOpacity(float x) {
  2569. float cutOff = mix(0.0, exp(-u_decayRate), u_fadeToZero);
  2570. return (exp(-u_decayRate * x) - cutOff) / (1.0 - cutOff);
  2571. }`,"getFragmentColor.glsl":`vec4 getFragmentColor(vec4 color, float dist, float size, float featheringSize) {
  2572. float featheringStart = clamp(0.5 - featheringSize / size, 0.0, 0.5);
  2573. if (dist > featheringStart) {
  2574. color *= 1.0 - (dist - featheringStart) / (0.5 - featheringStart);
  2575. }
  2576. return color;
  2577. }`,imagery:{"imagery.frag":`precision highp float;
  2578. varying vec2 v_texcoord;
  2579. uniform sampler2D u_texture;
  2580. uniform float u_Min;
  2581. uniform float u_Max;
  2582. uniform float u_featheringSize;
  2583. #include <raster/flow/vv.glsl>
  2584. float getIntensity(float v) {
  2585. return u_Min + v * (u_Max - u_Min);
  2586. }
  2587. void main(void) {
  2588. vec4 sampled = texture2D(u_texture, v_texcoord);
  2589. float intensity = getIntensity(sampled.r);
  2590. gl_FragColor = getColor(intensity);
  2591. gl_FragColor.a *= getOpacity(sampled.r);
  2592. gl_FragColor.a *= sampled.a;
  2593. gl_FragColor.rgb *= gl_FragColor.a;
  2594. }`,"imagery.vert":`attribute vec2 a_position;
  2595. attribute vec2 a_texcoord;
  2596. uniform mat3 u_dvsMat3;
  2597. varying vec2 v_texcoord;
  2598. void main(void) {
  2599. vec2 xy = (u_dvsMat3 * vec3(a_position, 1.0)).xy;
  2600. gl_Position = vec4(xy, 0.0, 1.0);
  2601. v_texcoord = a_texcoord;
  2602. }`},particles:{"particles.frag":`precision highp float;
  2603. varying vec4 v_color;
  2604. varying vec2 v_texcoord;
  2605. varying float v_size;
  2606. uniform float u_featheringSize;
  2607. #include <raster/flow/getFragmentColor.glsl>
  2608. void main(void) {
  2609. gl_FragColor = getFragmentColor(v_color, length(v_texcoord - 0.5), v_size, u_featheringSize);
  2610. }`,"particles.vert":`attribute vec4 a_xyts0;
  2611. attribute vec4 a_xyts1;
  2612. attribute vec4 a_typeIdDurationSeed;
  2613. attribute vec4 a_extrudeInfo;
  2614. uniform mat3 u_dvsMat3;
  2615. uniform mat3 u_displayViewMat3;
  2616. uniform float u_time;
  2617. uniform float u_trailLength;
  2618. uniform float u_flowSpeed;
  2619. varying vec4 v_color;
  2620. varying vec2 v_texcoord;
  2621. varying float v_size;
  2622. uniform float u_featheringSize;
  2623. uniform float u_introFade;
  2624. #include <raster/flow/vv.glsl>
  2625. #include <raster/flow/getFadeOpacity.glsl>
  2626. void main(void) {
  2627. vec2 position0 = a_xyts0.xy;
  2628. float t0 = a_xyts0.z;
  2629. float speed0 = a_xyts0.w;
  2630. vec2 position1 = a_xyts1.xy;
  2631. float t1 = a_xyts1.z;
  2632. float speed1 = a_xyts1.w;
  2633. float type = a_typeIdDurationSeed.x;
  2634. float id = a_typeIdDurationSeed.y;
  2635. float duration = a_typeIdDurationSeed.z;
  2636. float seed = a_typeIdDurationSeed.w;
  2637. vec2 e0 = a_extrudeInfo.xy;
  2638. vec2 e1 = a_extrudeInfo.zw;
  2639. float animationPeriod = duration + u_trailLength;
  2640. float scaledTime = u_time * u_flowSpeed;
  2641. float randomizedTime = scaledTime + seed * animationPeriod;
  2642. float t = mod(randomizedTime, animationPeriod);
  2643. float fUnclamped = (t - t0) / (t1 - t0);
  2644. float f = clamp(fUnclamped, 0.0, 1.0);
  2645. float clampedTime = mix(t0, t1, f);
  2646. float speed = mix(speed0, speed1, f);
  2647. vec2 extrude;
  2648. vec2 position;
  2649. float fadeOpacity;
  2650. float introOpacity;
  2651. if (type == 2.0) {
  2652. if (fUnclamped < 0.0 || (fUnclamped > 1.0 && t1 != duration)) {
  2653. gl_Position = vec4(0.0, 0.0, -2.0, 1.0);
  2654. return;
  2655. }
  2656. vec2 ortho = mix(e0, e1, f);
  2657. vec2 parallel;
  2658. parallel = normalize(position1 - position0) * 0.5;
  2659. if (id == 1.0) {
  2660. extrude = ortho;
  2661. v_texcoord = vec2(0.5, 0.0);
  2662. } else if (id == 2.0) {
  2663. extrude = -ortho;
  2664. v_texcoord = vec2(0.5, 1.0);
  2665. } else if (id == 3.0) {
  2666. extrude = ortho + parallel;
  2667. v_texcoord = vec2(1.0, 0.0);
  2668. } else if (id == 4.0) {
  2669. extrude = -ortho + parallel;
  2670. v_texcoord = vec2(1.0, 1.0);
  2671. }
  2672. fadeOpacity = getFadeOpacity((t - clampedTime) / u_trailLength);
  2673. introOpacity = 1.0 - exp(-clampedTime);
  2674. v_size = getSize(speed);
  2675. v_color = getColor(speed);
  2676. v_color.a *= getOpacity(speed);
  2677. position = mix(position0, position1, f);
  2678. } else {
  2679. if (fUnclamped < 0.0) {
  2680. gl_Position = vec4(0.0, 0.0, -2.0, 1.0);
  2681. return;
  2682. }
  2683. if (id == 1.0) {
  2684. extrude = e0;
  2685. v_texcoord = vec2(0.5, 0.0);
  2686. fadeOpacity = getFadeOpacity((t - t0) / u_trailLength);
  2687. introOpacity = 1.0 - exp(-t0);
  2688. v_size = getSize(speed0);
  2689. v_color = getColor(speed0);
  2690. v_color.a *= getOpacity(speed0);
  2691. position = position0;
  2692. } else if (id == 2.0) {
  2693. extrude = -e0;
  2694. v_texcoord = vec2(0.5, 1.0);
  2695. fadeOpacity = getFadeOpacity((t - t0) / u_trailLength);
  2696. introOpacity = 1.0 - exp(-t0);
  2697. v_size = getSize(speed0);
  2698. v_color = getColor(speed0);
  2699. v_color.a *= getOpacity(speed0);
  2700. position = position0;
  2701. } else if (id == 3.0) {
  2702. extrude = mix(e0, e1, f);
  2703. v_texcoord = vec2(0.5, 0.0);
  2704. fadeOpacity = getFadeOpacity((t - clampedTime) / u_trailLength);
  2705. introOpacity = 1.0 - exp(-clampedTime);
  2706. v_size = getSize(speed);
  2707. v_color = getColor(speed);
  2708. v_color.a *= getOpacity(speed);
  2709. position = mix(position0, position1, f);
  2710. } else if (id == 4.0) {
  2711. extrude = -mix(e0, e1, f);
  2712. v_texcoord = vec2(0.5, 1.0);
  2713. fadeOpacity = getFadeOpacity((t - clampedTime) / u_trailLength);
  2714. introOpacity = 1.0 - exp(-clampedTime);
  2715. v_size = getSize(speed);
  2716. v_color = getColor(speed);
  2717. v_color.a *= getOpacity(speed);
  2718. position = mix(position0, position1, f);
  2719. }
  2720. }
  2721. vec2 xy = (u_dvsMat3 * vec3(position, 1.0) + u_displayViewMat3 * vec3(extrude * v_size, 0.0)).xy;
  2722. gl_Position = vec4(xy, 0.0, 1.0);
  2723. v_color.a *= fadeOpacity;
  2724. v_color.a *= mix(1.0, introOpacity, u_introFade);
  2725. v_color.rgb *= v_color.a;
  2726. }`},streamlines:{"streamlines.frag":`precision highp float;
  2727. varying float v_side;
  2728. varying float v_time;
  2729. varying float v_totalTime;
  2730. varying float v_timeSeed;
  2731. varying vec4 v_color;
  2732. varying float v_size;
  2733. uniform float u_time;
  2734. uniform float u_trailLength;
  2735. uniform float u_flowSpeed;
  2736. uniform float u_featheringSize;
  2737. uniform float u_introFade;
  2738. #include <raster/flow/getFragmentColor.glsl>
  2739. #include <raster/flow/getFadeOpacity.glsl>
  2740. void main(void) {
  2741. float t = mod(v_timeSeed * (v_totalTime + u_trailLength) + u_time * u_flowSpeed, v_totalTime + u_trailLength) - v_time;
  2742. vec4 color = v_color * step(0.0, t) * getFadeOpacity(t / u_trailLength);
  2743. color *= mix(1.0, 1.0 - exp(-v_time), u_introFade);
  2744. gl_FragColor = getFragmentColor(color, length((v_side + 1.0) / 2.0 - 0.5), v_size, u_featheringSize);
  2745. }`,"streamlines.vert":`attribute vec3 a_positionAndSide;
  2746. attribute vec3 a_timeInfo;
  2747. attribute vec2 a_extrude;
  2748. attribute float a_speed;
  2749. uniform mat3 u_dvsMat3;
  2750. uniform mat3 u_displayViewMat3;
  2751. varying float v_time;
  2752. varying float v_totalTime;
  2753. varying float v_timeSeed;
  2754. varying vec4 v_color;
  2755. varying float v_side;
  2756. varying float v_size;
  2757. uniform float u_featheringSize;
  2758. #include <raster/flow/vv.glsl>
  2759. void main(void) {
  2760. vec4 lineColor = getColor(a_speed);
  2761. float lineOpacity = getOpacity(a_speed);
  2762. float lineSize = getSize(a_speed);
  2763. vec2 position = a_positionAndSide.xy;
  2764. v_side = a_positionAndSide.z;
  2765. vec2 xy = (u_dvsMat3 * vec3(position, 1.0) + u_displayViewMat3 * vec3(a_extrude * lineSize, 0.0)).xy;
  2766. gl_Position = vec4(xy, 0.0, 1.0);
  2767. v_time = a_timeInfo.x;
  2768. v_totalTime = a_timeInfo.y;
  2769. v_timeSeed = a_timeInfo.z;
  2770. v_color = lineColor;
  2771. v_color.a *= lineOpacity;
  2772. v_color.rgb *= v_color.a;
  2773. v_size = lineSize;
  2774. }`},"vv.glsl":`#define MAX_STOPS 8
  2775. #ifdef VV_COLOR
  2776. uniform float u_color_stops[MAX_STOPS];
  2777. uniform vec4 u_color_values[MAX_STOPS];
  2778. uniform int u_color_count;
  2779. #else
  2780. uniform vec4 u_color;
  2781. #endif
  2782. #ifdef VV_OPACITY
  2783. uniform float u_opacity_stops[MAX_STOPS];
  2784. uniform float u_opacity_values[MAX_STOPS];
  2785. uniform int u_opacity_count;
  2786. #else
  2787. uniform float u_opacity;
  2788. #endif
  2789. #ifdef VV_SIZE
  2790. uniform float u_size_stops[MAX_STOPS];
  2791. uniform float u_size_values[MAX_STOPS];
  2792. uniform int u_size_count;
  2793. #else
  2794. uniform float u_size;
  2795. #endif
  2796. uniform float u_featheringOffset;
  2797. vec4 getColor(float x) {
  2798. #ifdef VV_COLOR
  2799. vec4 color = u_color_values[0];
  2800. {
  2801. for (int i = 1; i < MAX_STOPS; i++) {
  2802. if (i >= u_color_count) {
  2803. break;
  2804. }
  2805. float x1 = u_color_stops[i - 1];
  2806. if (x < x1) {
  2807. break;
  2808. }
  2809. float x2 = u_color_stops[i];
  2810. vec4 y2 = u_color_values[i];
  2811. if (x < x2) {
  2812. vec4 y1 = u_color_values[i - 1];
  2813. color = y1 + (y2 - y1) * (x - x1) / (x2 - x1);
  2814. } else {
  2815. color = y2;
  2816. }
  2817. }
  2818. }
  2819. #else
  2820. vec4 color = u_color;
  2821. #endif
  2822. return color;
  2823. }
  2824. float getOpacity(float x) {
  2825. #ifdef VV_OPACITY
  2826. float opacity = u_opacity_values[0];
  2827. {
  2828. for (int i = 1; i < MAX_STOPS; i++) {
  2829. if (i >= u_opacity_count) {
  2830. break;
  2831. }
  2832. float x1 = u_opacity_stops[i - 1];
  2833. if (x < x1) {
  2834. break;
  2835. }
  2836. float x2 = u_opacity_stops[i];
  2837. float y2 = u_opacity_values[i];
  2838. if (x < x2) {
  2839. float y1 = u_opacity_values[i - 1];
  2840. opacity = y1 + (y2 - y1) * (x - x1) / (x2 - x1);
  2841. } else {
  2842. opacity = y2;
  2843. }
  2844. }
  2845. }
  2846. #else
  2847. float opacity = u_opacity;
  2848. #endif
  2849. return opacity;
  2850. }
  2851. float getSize(float x) {
  2852. #ifdef VV_SIZE
  2853. float size = u_size_values[0];
  2854. {
  2855. for (int i = 1; i < MAX_STOPS; i++) {
  2856. if (i >= u_size_count) {
  2857. break;
  2858. }
  2859. float x1 = u_size_stops[i - 1];
  2860. if (x < x1) {
  2861. break;
  2862. }
  2863. float x2 = u_size_stops[i];
  2864. float y2 = u_size_values[i];
  2865. if (x < x2) {
  2866. float y1 = u_size_values[i - 1];
  2867. size = y1 + (y2 - y1) * (x - x1) / (x2 - x1);
  2868. } else {
  2869. size = y2;
  2870. }
  2871. }
  2872. }
  2873. #else
  2874. float size = u_size;
  2875. #endif
  2876. return size + 2.0 * u_featheringSize * u_featheringOffset;
  2877. }`},hillshade:{"hillshade.frag":`precision mediump float;
  2878. varying highp vec2 v_texcoord;
  2879. #include <raster/common/common.glsl>
  2880. uniform int u_hillshadeType;
  2881. uniform float u_sinZcosAs[6];
  2882. uniform float u_sinZsinAs[6];
  2883. uniform float u_cosZs[6];
  2884. uniform float u_weights[6];
  2885. uniform vec2 u_factor;
  2886. uniform float u_minValue;
  2887. uniform float u_maxValue;
  2888. #include <raster/lut/colorize.glsl>
  2889. float getNeighborHoodAlpha(float a, float b, float c, float d, float e, float f, float g, float h, float i){
  2890. if (a == 0.0 || a == 0.0 || a==0.0 || a == 0.0 || a == 0.0 || a==0.0 || a == 0.0 || a == 0.0 || a==0.0) {
  2891. return 0.0;
  2892. }
  2893. else {
  2894. return e;
  2895. }
  2896. }
  2897. vec3 rgb2hsv(vec3 c) {
  2898. vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
  2899. vec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
  2900. vec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);
  2901. float d = q.x - min(q.w, q.y);
  2902. float e = 1.0e-10;
  2903. return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), min(d / (q.x + e), 1.0), q.x);
  2904. }
  2905. vec3 hsv2rgb(vec3 c) {
  2906. vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
  2907. vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
  2908. return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
  2909. }
  2910. vec4 overlay(float val, float minValue, float maxValue, float hillshade) {
  2911. val = clamp((val - minValue) / (maxValue - minValue), 0.0, 1.0);
  2912. vec4 rgb = colorize(vec4(val, val, val, 1.0), 255.0);
  2913. vec3 hsv = rgb2hsv(rgb.xyz);
  2914. hsv.z = hillshade;
  2915. return vec4(hsv2rgb(hsv), 1.0) * rgb.a;
  2916. }
  2917. void main() {
  2918. vec2 pixelLocation = getPixelLocation(v_texcoord);
  2919. if (isOutside(pixelLocation)) {
  2920. gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
  2921. return;
  2922. }
  2923. vec4 currentPixel = getPixel(pixelLocation);
  2924. if (currentPixel.a == 0.0) {
  2925. gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
  2926. return;
  2927. }
  2928. vec2 axy = vec2(-1.0, -1.0);
  2929. vec2 bxy = vec2(0.0, -1.0);
  2930. vec2 cxy = vec2(1.0, -1.0);
  2931. vec2 dxy = vec2(-1.0, 0.0);
  2932. vec2 fxy = vec2(1.0, 0.0);
  2933. vec2 gxy = vec2(-1.0, 1.0);
  2934. vec2 hxy = vec2(0.0, 1.0);
  2935. vec2 ixy = vec2(1.0, 1.0);
  2936. vec2 onePixel = 1.0 / u_srcImageSize;
  2937. if (pixelLocation.s < onePixel.s) {
  2938. axy[0] = 1.0;
  2939. dxy[0] = 1.0;
  2940. gxy[0] = 1.0;
  2941. }
  2942. if (pixelLocation.t < onePixel.t) {
  2943. axy[1] = 1.0;
  2944. bxy[1] = 1.0;
  2945. cxy[1] = 1.0;
  2946. }
  2947. if (pixelLocation.s > 1.0 - onePixel.s) {
  2948. cxy[0] = -1.0;
  2949. fxy[0] = -1.0;
  2950. ixy[0] = -1.0;
  2951. }
  2952. if (pixelLocation.t > 1.0 - onePixel.t) {
  2953. gxy[1] = -1.0;
  2954. hxy[1] = -1.0;
  2955. ixy[1] = -1.0;
  2956. }
  2957. vec4 va = texture2D(u_image, pixelLocation + onePixel * axy);
  2958. vec4 vb = texture2D(u_image, pixelLocation + onePixel * bxy);
  2959. vec4 vc = texture2D(u_image, pixelLocation + onePixel * cxy);
  2960. vec4 vd = texture2D(u_image, pixelLocation + onePixel * dxy);
  2961. vec4 ve = texture2D(u_image, pixelLocation);
  2962. vec4 vf = texture2D(u_image, pixelLocation + onePixel * fxy);
  2963. vec4 vg = texture2D(u_image, pixelLocation + onePixel * gxy);
  2964. vec4 vh = texture2D(u_image, pixelLocation + onePixel * hxy);
  2965. vec4 vi = texture2D(u_image, pixelLocation + onePixel * ixy);
  2966. float dzx = (vc + 2.0 * vf + vi - va - 2.0 * vd - vg).r * u_factor.s;
  2967. float dzy = (vg + 2.0 * vh + vi - va - 2.0 * vb - vc).r * u_factor.t;
  2968. float dzd = sqrt(1.0 + dzx * dzx + dzy * dzy);
  2969. float hillshade = 0.0;
  2970. if (u_hillshadeType == 0){
  2971. float cosDelta = u_sinZsinAs[0] * dzy - u_sinZcosAs[0] * dzx;
  2972. float z = (u_cosZs[0] + cosDelta) / dzd;
  2973. if (z < 0.0) z = 0.0;
  2974. hillshade = z;
  2975. } else {
  2976. for (int k = 0; k < 6; k++) {
  2977. float cosDelta = u_sinZsinAs[k] * dzy - u_sinZcosAs[k] * dzx;
  2978. float z = (u_cosZs[k] + cosDelta) / dzd;
  2979. if (z < 0.0) z = 0.0;
  2980. hillshade = hillshade + z * u_weights[k];
  2981. if (k == 5) break;
  2982. }
  2983. }
  2984. float alpha = getNeighborHoodAlpha(va.a, vb.a, vc.a, vd.a, ve.a, vf.a, vg.a, vh.a, vi.a);
  2985. #ifdef APPLY_COLORMAP
  2986. gl_FragColor = overlay(ve.r, u_minValue, u_maxValue, hillshade) * alpha * u_opacity;
  2987. #else
  2988. gl_FragColor = vec4(hillshade, hillshade, hillshade, 1.0) * alpha * u_opacity;
  2989. #endif
  2990. }`,"hillshade.vert":`precision mediump float;
  2991. attribute vec2 a_pos;
  2992. uniform highp mat3 u_dvsMat3;
  2993. uniform highp vec2 u_coordScale;
  2994. varying highp vec2 v_texcoord;
  2995. void main()
  2996. {
  2997. v_texcoord = a_pos;
  2998. gl_Position = vec4(u_dvsMat3 * vec3(a_pos * u_coordScale, 1.0), 1.0);
  2999. }`},lut:{"colorize.glsl":`uniform sampler2D u_colormap;
  3000. uniform float u_colormapOffset;
  3001. uniform float u_colormapMaxIndex;
  3002. vec4 colorize(vec4 currentPixel, float scaleFactor) {
  3003. float clrIndex = clamp(currentPixel.r * scaleFactor - u_colormapOffset, 0.0, u_colormapMaxIndex);
  3004. vec2 clrPosition = vec2((clrIndex + 0.5) / (u_colormapMaxIndex + 1.0), 0.0);
  3005. vec4 color = texture2D(u_colormap, clrPosition);
  3006. vec4 result = vec4(color.rgb, color.a * currentPixel.a);
  3007. return result;
  3008. }`,"lut.frag":`precision mediump float;
  3009. varying highp vec2 v_texcoord;
  3010. #include <raster/common/common.glsl>
  3011. #include <raster/lut/colorize.glsl>
  3012. void main() {
  3013. vec2 pixelLocation = getPixelLocation(v_texcoord);
  3014. if (isOutside(pixelLocation)) {
  3015. gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
  3016. return;
  3017. }
  3018. vec4 currentPixel = getPixel(pixelLocation);
  3019. vec4 result = colorize(currentPixel, 1.0);
  3020. gl_FragColor = vec4(result.xyz, 1.0) * result.a * u_opacity;
  3021. }`,"lut.vert":`precision mediump float;
  3022. attribute vec2 a_pos;
  3023. uniform highp mat3 u_dvsMat3;
  3024. uniform highp vec2 u_coordScale;
  3025. uniform highp float u_scale;
  3026. uniform highp vec2 u_offset;
  3027. varying highp vec2 v_texcoord;
  3028. void main()
  3029. {
  3030. v_texcoord = a_pos * u_scale + u_offset;
  3031. gl_Position = vec4(u_dvsMat3 * vec3(a_pos * u_coordScale, 1.0), 1.0);
  3032. }`},magdir:{"magdir.frag":`precision mediump float;
  3033. varying vec4 v_color;
  3034. uniform lowp float u_opacity;
  3035. void main() {
  3036. gl_FragColor = v_color * u_opacity;
  3037. }`,"magdir.vert":`precision mediump float;
  3038. attribute vec2 a_pos;
  3039. attribute vec2 a_offset;
  3040. attribute vec2 a_vv;
  3041. uniform highp mat3 u_dvsMat3;
  3042. uniform highp vec2 u_coordScale;
  3043. uniform vec2 u_symbolSize;
  3044. uniform vec2 u_symbolPercentRange;
  3045. uniform vec2 u_dataRange;
  3046. uniform float u_rotation;
  3047. uniform vec4 u_colors[12];
  3048. varying vec4 v_color;
  3049. void main()
  3050. {
  3051. float angle = a_offset.y + u_rotation;
  3052. #ifndef ROTATION_GEOGRAPHIC
  3053. angle = 3.14159265359 * 2.0 - angle - 3.14159265359 / 2.0;
  3054. #endif
  3055. vec2 offset = vec2(cos(angle), sin(angle)) * a_offset.x;
  3056. #ifdef DATA_RANGE
  3057. float valuePercentage = clamp((a_vv.y - u_dataRange.x) / (u_dataRange.y - u_dataRange.x), 0.0, 1.0);
  3058. float sizeRatio = u_symbolPercentRange.x + valuePercentage * (u_symbolPercentRange.y - u_symbolPercentRange.x);
  3059. float sizePercentage = clamp(sizeRatio, u_symbolPercentRange.x, u_symbolPercentRange.y);
  3060. #else
  3061. float sizePercentage = (u_symbolPercentRange.x + u_symbolPercentRange.y) / 2.0;
  3062. #endif
  3063. vec2 pos = a_pos + offset * sizePercentage * u_symbolSize;
  3064. v_color = u_colors[int(a_vv.x)];
  3065. gl_Position = vec4(u_dvsMat3 * vec3(pos * u_coordScale, 1.0), 1.0);
  3066. }`},reproject:{"reproject.frag":`precision mediump float;
  3067. varying vec2 v_texcoord;
  3068. #include <raster/common/common.glsl>
  3069. void main() {
  3070. vec2 pixelLocation = getPixelLocation(v_texcoord);
  3071. if (isOutside(pixelLocation)) {
  3072. gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
  3073. return;
  3074. }
  3075. vec4 currentPixel = getPixel(pixelLocation);
  3076. gl_FragColor = vec4(currentPixel.rgb, 1.0) * currentPixel.a * u_opacity;
  3077. }`,"reproject.vert":`precision mediump float;
  3078. attribute vec2 a_position;
  3079. varying highp vec2 v_texcoord;
  3080. void main()
  3081. {
  3082. v_texcoord = a_position;
  3083. gl_Position = vec4(2.0 * (a_position - 0.5), 0.0, 1.0);
  3084. }`},scalar:{"scalar.frag":`precision mediump float;
  3085. uniform lowp float u_opacity;
  3086. varying vec2 v_pos;
  3087. const vec4 outlineColor = vec4(0.2, 0.2, 0.2, 1.0);
  3088. const float outlineSize = 0.02;
  3089. const float innerRadius = 0.25;
  3090. const float outerRadius = 0.42;
  3091. const float innerSquareLength = 0.15;
  3092. void main() {
  3093. mediump float dist = length(v_pos);
  3094. mediump float fillalpha1 = smoothstep(outerRadius, outerRadius + outlineSize, dist);
  3095. fillalpha1 *= (1.0-smoothstep(outerRadius + outlineSize, outerRadius + 0.1 + outlineSize, dist));
  3096. #ifdef INNER_CIRCLE
  3097. mediump float fillalpha2 = smoothstep(innerRadius, innerRadius + outlineSize, dist);
  3098. fillalpha2 *= (1.0-smoothstep(innerRadius + outlineSize, innerRadius + 0.1 + outlineSize, dist));
  3099. #else
  3100. mediump float fillalpha2 = (abs(v_pos.x) < innerSquareLength ? 1.0 : 0.0) * (abs(v_pos.y) < innerSquareLength ? 1.0 : 0.0);
  3101. #endif
  3102. gl_FragColor = (fillalpha2 + fillalpha1) * outlineColor * u_opacity;
  3103. }`,"scalar.vert":`precision mediump float;
  3104. attribute vec2 a_pos;
  3105. attribute vec2 a_offset;
  3106. attribute vec2 a_vv;
  3107. uniform highp mat3 u_dvsMat3;
  3108. uniform highp vec2 u_coordScale;
  3109. uniform vec2 u_symbolSize;
  3110. uniform vec2 u_symbolPercentRange;
  3111. uniform vec2 u_dataRange;
  3112. varying vec2 v_pos;
  3113. void main()
  3114. {
  3115. #ifdef DATA_RANGE
  3116. float valuePercentage = clamp((a_vv.y - u_dataRange.x) / (u_dataRange.y - u_dataRange.x), 0.0, 1.0);
  3117. float sizeRatio = u_symbolPercentRange.x + valuePercentage * (u_symbolPercentRange.y - u_symbolPercentRange.x);
  3118. float sizePercentage = clamp(sizeRatio, u_symbolPercentRange.x, u_symbolPercentRange.y);
  3119. #else
  3120. float sizePercentage = (u_symbolPercentRange.x + u_symbolPercentRange.y) / 2.0;
  3121. #endif
  3122. vec2 size = u_symbolSize * sizePercentage;
  3123. vec2 pos = a_pos + a_offset * size;
  3124. v_pos = a_offset;
  3125. gl_Position = vec4(u_dvsMat3 * vec3(pos * u_coordScale, 1.0), 1.0);
  3126. }`},stretch:{"stretch.frag":`precision mediump float;
  3127. varying highp vec2 v_texcoord;
  3128. #include <raster/common/common.glsl>
  3129. uniform float u_minCutOff[3];
  3130. uniform float u_maxCutOff[3];
  3131. uniform float u_minOutput;
  3132. uniform float u_maxOutput;
  3133. uniform float u_factor[3];
  3134. uniform bool u_useGamma;
  3135. uniform float u_gamma[3];
  3136. uniform float u_gammaCorrection[3];
  3137. #include <raster/lut/colorize.glsl>
  3138. float stretchOneValue(float val, float minCutOff, float maxCutOff, float minOutput, float maxOutput, float factor, bool useGamma, float gamma, float gammaCorrection) {
  3139. if (val >= maxCutOff) {
  3140. return maxOutput;
  3141. } else if (val <= minCutOff) {
  3142. return minOutput;
  3143. }
  3144. float stretchedVal;
  3145. if (useGamma) {
  3146. float tempf = 1.0;
  3147. float outRange = maxOutput - minOutput;
  3148. float relativeVal = (val - minCutOff) / (maxCutOff - minCutOff);
  3149. if (gamma > 1.0) {
  3150. tempf -= pow(1.0 / outRange, relativeVal * gammaCorrection);
  3151. }
  3152. stretchedVal = (tempf * outRange * pow(relativeVal, 1.0 / gamma) + minOutput) / 255.0;
  3153. } else {
  3154. stretchedVal = minOutput + (val - minCutOff) * factor;
  3155. }
  3156. return stretchedVal;
  3157. }
  3158. void main() {
  3159. vec2 pixelLocation = getPixelLocation(v_texcoord);
  3160. if (isOutside(pixelLocation)) {
  3161. gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
  3162. return;
  3163. }
  3164. vec4 currentPixel = getPixel(pixelLocation);
  3165. #ifdef NOOP
  3166. gl_FragColor = vec4(currentPixel.rgb, 1.0) * currentPixel.a * u_opacity;
  3167. return;
  3168. #endif
  3169. if (u_bandCount == 1) {
  3170. float grayVal = stretchOneValue(currentPixel.r, u_minCutOff[0], u_maxCutOff[0], u_minOutput, u_maxOutput, u_factor[0], u_useGamma, u_gamma[0], u_gammaCorrection[0]);
  3171. #ifdef APPLY_COLORMAP
  3172. vec4 result = colorize(vec4(grayVal, grayVal, grayVal, 1.0), u_useGamma ? 255.0 : 1.0);
  3173. gl_FragColor = vec4(result.xyz, 1.0) * result.a * currentPixel.a * u_opacity;
  3174. #else
  3175. gl_FragColor = vec4(grayVal, grayVal, grayVal, 1.0) * currentPixel.a * u_opacity;
  3176. #endif
  3177. } else {
  3178. float redVal = stretchOneValue(currentPixel.r, u_minCutOff[0], u_maxCutOff[0], u_minOutput, u_maxOutput, u_factor[0], u_useGamma, u_gamma[0], u_gammaCorrection[0]);
  3179. float greenVal = stretchOneValue(currentPixel.g, u_minCutOff[1], u_maxCutOff[1], u_minOutput, u_maxOutput, u_factor[1], u_useGamma, u_gamma[1], u_gammaCorrection[1]);
  3180. float blueVal = stretchOneValue(currentPixel.b, u_minCutOff[2], u_maxCutOff[2], u_minOutput, u_maxOutput, u_factor[2], u_useGamma, u_gamma[2], u_gammaCorrection[2]);
  3181. gl_FragColor = vec4(redVal, greenVal, blueVal, 1.0) * currentPixel.a * u_opacity;
  3182. }
  3183. }`,"stretch.vert":`precision mediump float;
  3184. attribute vec2 a_pos;
  3185. uniform highp mat3 u_dvsMat3;
  3186. uniform highp vec2 u_coordScale;
  3187. uniform highp float u_scale;
  3188. uniform highp vec2 u_offset;
  3189. varying highp vec2 v_texcoord;
  3190. void main()
  3191. {
  3192. v_texcoord = a_pos * u_scale + u_offset;
  3193. gl_Position = vec4(u_dvsMat3 * vec3(a_pos * u_coordScale, 1.0), 1.0);
  3194. }`}},stencil:{"stencil.frag":`void main() {
  3195. gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
  3196. }`,"stencil.vert":`attribute vec2 a_pos;
  3197. uniform mat3 u_worldExtent;
  3198. void main() {
  3199. gl_Position = vec4(u_worldExtent * vec3(a_pos, 1.0), 1.0);
  3200. }`},tileInfo:{"tileInfo.frag":`uniform mediump sampler2D u_texture;
  3201. varying mediump vec2 v_tex;
  3202. void main(void) {
  3203. lowp vec4 color = texture2D(u_texture, v_tex);
  3204. gl_FragColor = 0.75 * color;
  3205. }`,"tileInfo.vert":`attribute vec2 a_pos;
  3206. uniform highp mat3 u_dvsMat3;
  3207. uniform mediump float u_depth;
  3208. uniform mediump vec2 u_coord_ratio;
  3209. uniform mediump vec2 u_delta;
  3210. uniform mediump vec2 u_dimensions;
  3211. varying mediump vec2 v_tex;
  3212. void main() {
  3213. mediump vec2 offset = u_coord_ratio * vec2(u_delta + a_pos * u_dimensions);
  3214. vec3 v_pos = u_dvsMat3 * vec3(offset, 1.0);
  3215. gl_Position = vec4(v_pos.xy, 0.0, 1.0);
  3216. v_tex = a_pos;
  3217. }`},util:{"atan2.glsl":`float atan2(in float y, in float x) {
  3218. float t0, t1, t2, t3, t4;
  3219. t3 = abs(x);
  3220. t1 = abs(y);
  3221. t0 = max(t3, t1);
  3222. t1 = min(t3, t1);
  3223. t3 = 1.0 / t0;
  3224. t3 = t1 * t3;
  3225. t4 = t3 * t3;
  3226. t0 = - 0.013480470;
  3227. t0 = t0 * t4 + 0.057477314;
  3228. t0 = t0 * t4 - 0.121239071;
  3229. t0 = t0 * t4 + 0.195635925;
  3230. t0 = t0 * t4 - 0.332994597;
  3231. t0 = t0 * t4 + 0.999995630;
  3232. t3 = t0 * t3;
  3233. t3 = (abs(y) > abs(x)) ? 1.570796327 - t3 : t3;
  3234. t3 = x < 0.0 ? 3.141592654 - t3 : t3;
  3235. t3 = y < 0.0 ? -t3 : t3;
  3236. return t3;
  3237. }`,"encoding.glsl":`const vec4 rgba2float_factors = vec4(
  3238. 255.0 / (256.0),
  3239. 255.0 / (256.0 * 256.0),
  3240. 255.0 / (256.0 * 256.0 * 256.0),
  3241. 255.0 / (256.0 * 256.0 * 256.0 * 256.0)
  3242. );
  3243. float rgba2float(vec4 rgba) {
  3244. return dot(rgba, rgba2float_factors);
  3245. }`}};function Cn(l){let e=In;return l.split("/").forEach(t=>{e&&(e=e[t])}),e}const On=new kt(Cn);function Pe(l){return On.resolveIncludes(l)}const he={shaders:{vertexShader:Pe("background/background.vert"),fragmentShader:Pe("background/background.frag")},attributes:new Map([["a_pos",0]])},An=()=>ce("clip",{geometry:[{location:0,name:"a_pos",count:2,type:m.SHORT}]});class Pn extends W{constructor(){super(...arguments),this._color=K(0,1,0,1)}dispose(){this._program&&this._program.dispose()}prepareState({context:e}){e.setStencilTestEnabled(!0),e.setBlendingEnabled(!1),e.setFaceCullingEnabled(!1),e.setColorMask(!1,!1,!1,!1),e.setStencilOp(X.KEEP,X.KEEP,X.REPLACE),e.setStencilWriteMask(255),e.setStencilFunction(V.ALWAYS,0,255)}draw(e,t){const{context:n,state:o,requestRender:i,allowDelayedRender:a}=e,r=An(),c=t.getVAO(n,o,r.attributes,r.bufferLayouts);G(c.indexBuffer)||(this._program||(this._program=Ae(n,he)),a&&E(i)&&!this._program.isCompiled?i():(n.useProgram(this._program),this._program.setUniform2fv("u_coord_range",[1,1]),this._program.setUniform4fv("u_color",this._color),this._program.setUniformMatrix3fv("u_dvsMat3",o.displayMat3),n.bindVAO(c),n.drawElements(R.TRIANGLES,c.indexBuffer.size,m.UNSIGNED_INT,0),n.bindVAO()))}}const Dn=()=>ce("overlay",{geometry:[{location:0,name:"a_pos",count:2,type:m.FLOAT}],tex:[{location:1,name:"a_uv",count:2,type:m.UNSIGNED_SHORT}]});class Rn extends W{constructor(){super(...arguments),this._desc={vsPath:"overlay/overlay",fsPath:"overlay/overlay",attributes:new Map([["a_pos",0],["a_uv",1]])}}dispose(){}prepareState({context:e}){e.setBlendingEnabled(!0),e.setColorMask(!0,!0,!0,!0),e.setBlendFunctionSeparate(D.ONE,D.ONE_MINUS_SRC_ALPHA,D.ONE,D.ONE_MINUS_SRC_ALPHA),e.setStencilWriteMask(0),e.setStencilTestEnabled(!0),e.setStencilFunction(V.GREATER,255,255)}draw(e,t){const{context:n,painter:o,requestRender:i,allowDelayedRender:a}=e;if(!t.isReady)return;const{computedOpacity:r,dvsMat3:c,isWrapAround:s,perspectiveTransform:u,texture:f}=t;e.timeline.begin(this.name);const _=o.materialManager.getProgram(this._desc);if(a&&E(i)&&!_.isCompiled)return void i();const v=Dn(),g=t.getVAO(n,v.bufferLayouts,v.attributes);if(!g)return;n.bindVAO(g),n.useProgram(_),n.bindTexture(f,Oe),_.setUniformMatrix3fv("u_dvsMat3",c),_.setUniform1i("u_texture",Oe),_.setUniform1f("u_opacity",r),_.setUniform2fv("u_perspective",u);const p=s?10:4;n.drawArrays(R.TRIANGLE_STRIP,0,p),n.bindVAO(),e.timeline.end(this.name)}}class ye extends W{constructor(){super(...arguments),this._computeDesc=new Map}prepareState({context:e},t){t&&t.includes("hittest")?e.setBlendFunctionSeparate(D.ONE,D.ONE,D.ONE,D.ONE):e.setBlendFunctionSeparate(D.ONE,D.ONE_MINUS_SRC_ALPHA,D.ONE,D.ONE_MINUS_SRC_ALPHA),e.setBlendingEnabled(!0),e.setColorMask(!0,!0,!0,!0),e.setStencilWriteMask(0),e.setStencilTestEnabled(!0)}draw(e,t,n){const o=this.getGeometryType();t.commit(e);const i=t.getGeometry(o);G(i)||(e.timeline.begin(this.name),e.attributeView.bindTextures(e.context),e.context.setStencilFunction(V.EQUAL,t.stencilRef,255),i.forEachCommand(a=>{const r=$t.load(a.materialKey).symbologyType;this.supportsSymbology(r)&&this.drawGeometry(e,t,a,n)}))}_setSharedUniforms(e,t,n){const{displayLevel:o,pixelRatio:i,state:a,passOptions:r}=t;E(r)&&r.type==="hittest"&&(e.setUniform2fv("u_hittestPos",r.position),e.setUniform1f("u_hittestDist",r.distance)),e.setUniform1f("u_pixelRatio",i),e.setUniformMatrix3fv("u_tileMat3",n.transforms.tileMat3),e.setUniformMatrix3fv("u_viewMat3",a.viewMat3),e.setUniformMatrix3fv("u_dvsMat3",n.transforms.dvs),e.setUniformMatrix3fv("u_displayViewMat3",a.displayViewMat3),e.setUniform1f("u_currentZoom",Math.round(o*wt)),e.setUniform1i("u_attributeTextureSize",t.attributeView.size),e.setUniform1i("u_attributeData0",Ft),e.setUniform1i("u_attributeData1",Vt),e.setUniform1i("u_attributeData2",Ut),e.setUniform1i("u_attributeData3",Bt),e.setUniform1i("u_attributeData4",Gt),e.setUniform1i("u_attributeData5",Yt)}_setSizeVVUniforms(e,t,n,o){if(e.vvSizeMinMaxValue&&t.setUniform4fv("u_vvSizeMinMaxValue",n.vvSizeMinMaxValue),e.vvSizeScaleStops&&t.setUniform1f("u_vvSizeScaleStopsValue",n.vvSizeScaleStopsValue),e.vvSizeFieldStops){const i=n.getSizeVVFieldStops(o.key.level);t.setUniform1fv("u_vvSizeFieldStopsValues",i.values),t.setUniform1fv("u_vvSizeFieldStopsSizes",i.sizes)}e.vvSizeUnitValue&&t.setUniform1f("u_vvSizeUnitValueWorldToPixelsRatio",n.vvSizeUnitValueToPixelsRatio)}_setColorAndOpacityVVUniforms(e,t,n){e.vvColor&&(t.setUniform1fv("u_vvColorValues",n.vvColorValues),t.setUniform4fv("u_vvColors",n.vvColors)),e.vvOpacity&&(t.setUniform1fv("u_vvOpacityValues",n.vvOpacityValues),t.setUniform1fv("u_vvOpacities",n.vvOpacities))}_setRotationVVUniforms(e,t,n){e.vvRotation&&t.setUniform1f("u_vvRotationType",n.vvMaterialParameters.vvRotationType==="geographic"?0:1)}_getTriangleDesc(e,t,n=["a_pos"]){const o=t.bufferLayouts.geometry,i=n.map(c=>o.findIndex(s=>s.name===c)),a=`${e}-${i.join("-")}`;let r=this._computeDesc.get(a);if(!r){const c=t.strides,s=t.strides.geometry,u=new Map(t.attributes),f=o.map(p=>({...p})),_=Math.max(...t.attributes.values()),v={geometry:f};let g=0;for(const p of i){const d=o[p];v.geometry.push({count:d.count,name:d.name+"1",divisor:d.divisor,normalized:d.normalized,offset:s+d.offset,stride:s,type:d.type}),v.geometry.push({count:d.count,name:d.name+"2",divisor:d.divisor,normalized:d.normalized,offset:2*s+d.offset,stride:s,type:d.type}),u.set(d.name+"1",_+ ++g),u.set(d.name+"2",_+ ++g)}r={bufferLayouts:v,attributes:u,strides:c},this._computeDesc.set(a,r)}return r}}function Ln(l){const e={geometry:[{location:0,name:"a_pos",count:2,type:m.SHORT},{location:1,name:"a_id",count:3,type:m.UNSIGNED_BYTE},{location:2,name:"a_bitset",count:1,type:m.UNSIGNED_BYTE},{location:3,name:"a_color",count:4,type:m.UNSIGNED_BYTE,normalized:!0},{location:4,name:"a_aux1",count:4,type:m.UNSIGNED_SHORT},{location:5,name:"a_aux2",count:4,type:m.SHORT},{location:6,name:"a_aux3",count:4,type:m.UNSIGNED_BYTE},{location:7,name:"a_zoomRange",count:2,type:m.UNSIGNED_SHORT}]};switch(l.symbologyType){case te.SIMPLE:case te.OUTLINE_FILL_SIMPLE:e.geometry.splice(7,1),e.geometry.splice(4,1)}return{shader:"materials/fill",vertexLayout:e}}class pt extends ye{dispose(){}getGeometryType(){return me.FILL}supportsSymbology(e){return e!==te.DOT_DENSITY}drawGeometry(e,t,n,o){const{context:i,painter:a,rendererInfo:r,requiredLevel:c,passOptions:s,requestRender:u,allowDelayedRender:f}=e,_=Zt.load(n.materialKey),v=at(_.data),g=E(s)&&s.type==="hittest",p=a.materialManager,{shader:d,vertexLayout:I,hittestAttributes:h}=nt(v.programSpec,Ln(_));let O=R.TRIANGLES,P=ce(_.data,I);g&&(P=this._getTriangleDesc(n.materialKey,P,h),O=R.POINTS);const{attributes:S,bufferLayouts:y}=P,x=p.getMaterialProgram(e,_,d,S,o);if(f&&E(u)&&!x.isCompiled)return void u();if(i.useProgram(x),this._setSharedUniforms(x,e,t),x.setUniform2f("u_tileOffset",512*t.key.col,512*t.key.row),_.textureBinding){a.textureManager.bindTextures(i,x,_);const L=1/2**(c-t.key.level);x.setUniform1f("u_zoomFactor",L)}const T=1/e.pixelRatio;x.setUniform1f("u_blur",T),x.setUniform1f("u_antialiasing",T),this._setSizeVVUniforms(_,x,r,t),this._setColorAndOpacityVVUniforms(_,x,r);const b=n.target.getVAO(i,y,S,g);let A=n.indexCount,C=n.indexFrom*Uint32Array.BYTES_PER_ELEMENT;g&&(A/=3,C/=3),i.bindVAO(b),this._drawFills(e,t,x,O,A,C)}_drawFills(e,t,n,o,i,a){e.context.drawElements(o,i,m.UNSIGNED_INT,a)}}class Mn extends pt{constructor(){super(...arguments),this._dotTextureSize=0,this._dotTextures=null,this._dotSamplers=new Int32Array([Ht,Wt]),this._dotVAO=null,this._dotDesc={vsPath:"dot/dot",fsPath:"dot/dot",attributes:new Map([["a_pos",0]])}}dispose(){super.dispose(),this._disposeTextures(),this._dotFBO=oe(this._dotFBO),this._dotVAO=oe(this._dotVAO)}getGeometryType(){return me.FILL}supportsSymbology(e){return e===te.DOT_DENSITY}_drawFills(e,t,n,o,i,a){const{passOptions:r}=e;if(E(r)&&r.type==="hittest")super._drawFills(e,t,n,o,i,a);else{const c=this._drawDotLocations(e,t,n,i,a);this._drawDotDensity(e,t,c)}}_drawDotDensity(e,t,n){const{context:o,painter:i,rendererInfo:a,requestRender:r,allowDelayedRender:c}=e,s=i.materialManager.getProgram(this._dotDesc);if(c&&E(r)&&!s.isCompiled)return void r();const{rendererSchema:u}=a;fe(u,"dot-density");const f=this._createDotDensityMesh(o,this._dotDesc.attributes,{geometry:[{name:"a_pos",count:2,type:m.SHORT,divisor:0,normalized:!1,offset:0,stride:4}]});o.setStencilTestEnabled(!0),o.useProgram(s),s.setUniform1f("u_tileZoomFactor",1),s.setUniform1i("u_texture",this._dotSamplers[0]),s.setUniform1f("u_dotSize",Math.max(u.dotSize,1)),s.setUniform1f("u_pixelRatio",window.devicePixelRatio),this._setSharedUniforms(s,e,t),o.bindTexture(n,this._dotSamplers[0]),o.bindVAO(f),o.drawArrays(R.POINTS,0,262144)}_drawDotLocations(e,t,n,o,i){const{context:a,rendererInfo:r,requiredLevel:c}=e,s=a.getViewport(),{rendererSchema:u}=r;fe(u,"dot-density");const{dotScale:f,colors:_,activeDots:v,backgroundColor:g,dotValue:p}=u;a.setViewport(0,0,512,512);const d=a.getBoundFramebufferObject(),I=this._createFBO(a);a.bindFramebuffer(I),a.setClearColor(0,0,0,0),a.clear(a.gl.COLOR_BUFFER_BIT|a.gl.STENCIL_BUFFER_BIT),a.setStencilTestEnabled(!1);const h=1/2**(c-t.key.level),O=Re,P=O*window.devicePixelRatio*O*window.devicePixelRatio,S=1/h*(1/h),y=f?e.state.scale/f:1;return n.setUniform1f("u_tileZoomFactor",h),n.setUniform1f("u_tileDotsOverArea",P/(Re*window.devicePixelRatio*Re*window.devicePixelRatio)),n.setUniformMatrix4fv("u_dotColors",_),n.setUniform4fv("u_isActive",v),n.setUniform4fv("u_dotBackgroundColor",g),n.setUniform1f("u_dotValue",Math.max(1,p*y*S)),this._bindDotDensityTextures(a,n,r,O),a.drawElements(R.TRIANGLES,o,m.UNSIGNED_INT,i),a.setViewport(s.x,s.y,s.width,s.height),a.bindFramebuffer(d),I.colorTexture}_createFBO(e){if(G(this._dotFBO)){const o={target:re.TEXTURE_2D,pixelFormat:B.RGBA,dataType:q.UNSIGNED_BYTE,samplingMode:N.NEAREST,wrapMode:Q.CLAMP_TO_EDGE,width:512,height:512},i={colorTarget:Rt.TEXTURE,depthStencilTarget:Lt.DEPTH_STENCIL_RENDER_BUFFER},a=new rt(e,{width:512,height:512,internalFormat:it.DEPTH_STENCIL});this._dotFBO=new st(e,i,o,a)}return this._dotFBO}_disposeTextures(){if(this._dotTextures){for(let e=0;e<this._dotTextures.length;e++)this._dotTextures[e].dispose();this._dotTextures=null}}_bindDotDensityTextures(e,t,n,o){const{rendererSchema:i}=n;fe(i,"dot-density");const a=this._createDotDensityTextures(e,o,i.seed);t.setUniform1iv("u_dotTextures",this._dotSamplers);for(let r=0;r<a.length;r++)e.bindTexture(a[r],this._dotSamplers[r])}_createDotDensityMesh(e,t,n){if(G(this._dotVAO)){const i=new Int16Array(524288);for(let r=0;r<512;r++)for(let c=0;c<512;c++)i[2*(c+512*r)]=c,i[2*(c+512*r)+1]=r;const a=ee.createVertex(e,J.STATIC_DRAW,i);this._dotVAO=new le(e,t,n,{geometry:a},null)}return this._dotVAO}_createDotDensityTextures(e,t,n){if(this._dotTextureSize===t&&this._seed===n||(this._disposeTextures(),this._dotTextureSize=t,this._seed=n),this._dotTextures===null){const o=new Et(n);this._dotTextures=[this._allocDotDensityTexture(e,t,o),this._allocDotDensityTexture(e,t,o)]}return this._dotTextures}_allocDotDensityTexture(e,t,n){const o=new Float32Array(t*t*4);for(let i=0;i<o.length;i++)o[i]=n.getFloat();return new se(e,{wrapMode:Q.REPEAT,pixelFormat:B.RGBA,dataType:q.FLOAT,samplingMode:N.NEAREST,width:t,height:t},o)}}const Nn={shader:"materials/icon",vertexLayout:{geometry:[{location:0,name:"a_pos",count:2,type:m.SHORT},{location:1,name:"a_vertexOffset",count:2,type:m.SHORT},{location:2,name:"a_texCoords",count:2,type:m.UNSIGNED_SHORT},{location:3,name:"a_bitSetAndDistRatio",count:2,type:m.UNSIGNED_SHORT},{location:4,name:"a_id",count:4,type:m.UNSIGNED_BYTE},{location:5,name:"a_color",count:4,type:m.UNSIGNED_BYTE,normalized:!0},{location:6,name:"a_outlineColor",count:4,type:m.UNSIGNED_BYTE,normalized:!0},{location:7,name:"a_sizeAndOutlineWidth",count:4,type:m.UNSIGNED_BYTE},{location:8,name:"a_zoomRange",count:2,type:m.UNSIGNED_SHORT}]},hittestAttributes:["a_vertexOffset","a_texCoords"]};class Fe extends ye{dispose(){}getGeometryType(){return me.MARKER}supportsSymbology(e){return e!==te.HEATMAP&&e!==te.PIE_CHART}drawGeometry(e,t,n,o){const{context:i,painter:a,rendererInfo:r,state:c,passOptions:s,requestRender:u,allowDelayedRender:f}=e,_=qt.load(n.materialKey),v=at(_.data),g=E(s)&&s.type==="hittest",{shader:p,vertexLayout:d,hittestAttributes:I}=nt(v.programSpec,Nn);let h=R.TRIANGLES,O=ce(_.data,d);g&&(O=this._getTriangleDesc(n.materialKey,O,I),h=R.POINTS);const{attributes:P,bufferLayouts:S}=O,y=a.materialManager.getMaterialProgram(e,_,p,P,o);if(f&&E(u)&&!y.isCompiled)return void u();i.useProgram(y),_.textureBinding&&a.textureManager.bindTextures(i,y,_,!0),this._setSharedUniforms(y,e,t);const x=_.vvRotation?c.displayViewMat3:c.displayMat3;y.setUniformMatrix3fv("u_displayMat3",x),this._setSizeVVUniforms(_,y,r,t),this._setColorAndOpacityVVUniforms(_,y,r),this._setRotationVVUniforms(_,y,r);const T=n.target.getVAO(i,S,P,g);let b=n.indexCount,A=n.indexFrom*Uint32Array.BYTES_PER_ELEMENT;g&&(b/=3,A/=3),i.bindVAO(T),this._drawMarkers(e,t,y,h,b,A,g),i.bindVAO(null)}_drawMarkers(e,t,n,o,i,a,r){e.context.drawElements(o,i,m.UNSIGNED_INT,a)}}class zn{constructor(){this.name=this.constructor.name}createOptions(e,t){return null}}function wn(l,e){const{textureFloat:t,colorBufferFloat:n}=l.capabilities,o=t==null?void 0:t.textureFloat,i=t==null?void 0:t.textureFloatLinear,a=t==null?void 0:t.textureHalfFloat,r=t==null?void 0:t.textureHalfFloatLinear,c=t==null?void 0:t.HALF_FLOAT,s=n==null?void 0:n.textureFloat,u=n==null?void 0:n.textureHalfFloat,f=n==null?void 0:n.floatBlend,{floatBufferBlendWorking:_}=It(l.driverTest);if(!o&&!a)throw new ae("heatmap:missing-texture-float","HeatmapRenderer requires WebGL2 or the WebGL1 extension OES_texture_float or OES_texture_half_float.");if(!s&&!u)throw new ae("heatmap:missing-color-buffer-float","HeatmapRenderer requires the WebGL extension EXT_color_buffer_float or EXT_color_buffer_half_float or WEBGL_color_buffer_float.");if(!(f&&_||u))throw new ae("heatmap:missing-float-blend","HeatmapRenderer requires the WebGL extension EXT_float_blend or EXT_color_buffer_half_float."+(_?"":" This device claims support for EXT_float_blend, but does not actually support it."));const v=o&&s&&f&&_,g=a&&u,p=i,d=r,I=!!(n!=null&&n.R32F),h=!!(n!=null&&n.R16F);if(v&&(p||!d))return p||e.warnOnce("Missing WebGL extension OES_texture_float_linear. Heatmap quality may be reduced."),{dataType:q.FLOAT,samplingMode:p?N.LINEAR:N.NEAREST,pixelFormat:I?B.RED:B.RGBA,internalFormat:I?Ce.R32F:B.RGBA};if(g)return d||e.warnOnce("Missing WebGL extension OES_texture_half_float_linear. Heatmap quality may be reduced."),{dataType:c,samplingMode:d?N.LINEAR:N.NEAREST,pixelFormat:h?B.RED:B.RGBA,internalFormat:h?Ce.R16F:B.RGBA};throw new ae("heatmap:missing-hardware-support","HeatmapRenderer requires WebGL extensions that allow it to render and blend to float or half float textures.")}const Xe=ze.getLogger("esri.views.2d.engine.webgl.brushes.WGLBrushHeatmap");function Qe(l){return l.type==="heatmap"}class Fn extends Fe{constructor(){super(...arguments),this.brushEffect=new Un}supportsSymbology(e){return e===te.HEATMAP}dispose(){super.dispose(),this.brushEffect.dispose(),this.brushEffect=null}prepareState(){}drawGeometry(e,t,n,o){const{defines:i}=this.brushEffect.loadQualityProfile(e.context);super.drawGeometry(e,t,n,o?[...o,...i]:i)}_drawMarkers(e,t,n,o,i,a,r){const{context:c,rendererInfo:s,state:u}=e,{rendererSchema:f}=s;fe(f,"heatmap");const{referenceScale:_,radius:v,isFieldActive:g}=f,p=v*(_!==0?_/u.scale:1);n.setUniform1f("u_radius",p),r||(n.setUniform1f("u_isFieldActive",g),c.setStencilFunction(V.GEQUAL,t.stencilRef,255)),c.drawElements(o,i,m.UNSIGNED_INT,a)}}const Vn={vsPath:"heatmap/heatmapResolve",fsPath:"heatmap/heatmapResolve",attributes:new Map([["a_position",0]])};class Un extends zn{constructor(){super(...arguments),this.name=this.constructor.name}createOptions({passOptions:e}){return e}dispose(){this._prevFBO=null,this._accumulateOutputTexture=oe(this._accumulateOutputTexture),E(this._accumulateFramebuffer)&&this._accumulateFramebuffer.detachDepthStencilBuffer(),this._accumulateOutputStencilBuffer=oe(this._accumulateOutputStencilBuffer),this._accumulateFramebuffer=oe(this._accumulateFramebuffer),this._resolveGradientTexture=oe(this._resolveGradientTexture),this._tileQuad=oe(this._tileQuad)}bind(e){const{context:t,rendererInfo:n,passOptions:o}=e,{rendererSchema:i}=n;!(E(o)&&o.type==="hittest")&&Qe(i)&&(this._prevFBO=t.getBoundFramebufferObject(),this._prevViewport=t.getViewport(),fe(i,"heatmap"),this._loadResources(e),this._updateResources(t,i),t.bindFramebuffer(this._accumulateFramebuffer),t.setViewport(0,0,this._accumulateFramebuffer.width,this._accumulateFramebuffer.height),t.setStencilTestEnabled(!0),t.setBlendingEnabled(!0),t.setBlendFunction(D.ONE,D.ONE),t.setClearColor(0,0,0,0),t.clear(We.COLOR_BUFFER_BIT))}unbind(){this._prevFBO=null,this._prevViewport=null}draw(e){const{context:t,painter:n,rendererInfo:o,passOptions:i}=e,{rendererSchema:a}=o;if(E(i)&&i.type==="hittest"||!Qe(a))return;const{defines:r}=this.loadQualityProfile(t),c=n.materialManager.getProgram(Vn,r);t.useProgram(c),t.bindFramebuffer(this._prevFBO),t.setViewport(0,0,this._prevViewport.width,this._prevViewport.height),t.setBlendFunction(D.ONE,D.ONE_MINUS_SRC_ALPHA),t.setStencilTestEnabled(!1);const{radius:s,minDensity:u,densityRange:f}=a;t.bindTexture(this._accumulateOutputTexture,8),t.bindTexture(this._resolveGradientTexture,9),c.setUniform1i("u_texture",8),c.setUniform1i("u_gradient",9),c.setUniform2f("u_densityMinAndInvRange",u,1/f),c.setUniform1f("u_densityNormalization",3/(s*s*Math.PI)),this._tileQuad.draw()}_loadResources({context:e,painter:t}){var v,g,p,d,I;const{dataType:n,samplingMode:o,pixelFormat:i,internalFormat:a,shadingRate:r,requiresSharedStencilBuffer:c}=this.loadQualityProfile(e),{width:s,height:u}=this._prevViewport,f=s*r,_=u*r;(v=this._accumulateOutputTexture)!=null||(this._accumulateOutputTexture=new se(e,{target:re.TEXTURE_2D,pixelFormat:i,internalFormat:a,dataType:n,samplingMode:o,wrapMode:Q.CLAMP_TO_EDGE,width:f,height:_})),c||((g=this._accumulateOutputStencilBuffer)!=null||(this._accumulateOutputStencilBuffer=new rt(e,{width:f,height:_,internalFormat:it.DEPTH_STENCIL}))),(p=this._accumulateFramebuffer)!=null||(this._accumulateFramebuffer=new st(e,{},this._accumulateOutputTexture,c?t.getSharedStencilBuffer():this._accumulateOutputStencilBuffer)),(d=this._resolveGradientTexture)!=null||(this._resolveGradientTexture=new se(e,{target:re.TEXTURE_2D,pixelFormat:B.RGBA,dataType:q.UNSIGNED_BYTE,samplingMode:N.LINEAR,wrapMode:Q.CLAMP_TO_EDGE})),(I=this._tileQuad)!=null||(this._tileQuad=new we(e,[0,0,1,0,0,1,1,1]))}_updateResources(e,t){const{gradientHash:n,gradient:o}=t;this._prevGradientHash!==n&&(this._resolveGradientTexture.resize(o.length/4,1),this._resolveGradientTexture.setData(o),this._prevGradientHash=n);const{shadingRate:i,requiresSharedStencilBuffer:a}=this.loadQualityProfile(e),{width:r,height:c}=this._prevViewport,s=r*i,u=c*i,{width:f,height:_}=this._accumulateFramebuffer;if(f!==s||_!==u){const v=this._accumulateFramebuffer.depthStencilAttachment;if(a&&E(v)){const{width:g,height:p}=v.descriptor;g===s&&p===u||(Xe.errorOnce("Attempted to resize shared stencil buffer! Detaching instead."),this._accumulateFramebuffer.detachDepthStencilBuffer())}this._accumulateFramebuffer.resize(s,u)}a||e.blitFramebuffer(this._prevFBO,this._accumulateFramebuffer,0,0,this._prevFBO.width,this._prevFBO.height,0,0,this._accumulateFramebuffer.width,this._accumulateFramebuffer.height,We.STENCIL_BUFFER_BIT,N.NEAREST)}loadQualityProfile(e){if(G(this._qualityProfile)){const t=wn(e,Xe),n=e.type===Ne.WEBGL1;this._qualityProfile={...t,requiresSharedStencilBuffer:n,shadingRate:n?1:.25,defines:t.dataType!==q.FLOAT?["heatmapPrecisionHalfFloat"]:[]}}return this._qualityProfile}}const Me={geometry:[new ge("a_pos",2,m.BYTE,0,2)]},yi={geometry:[new ge("a_pos",2,m.BYTE,0,4),new ge("a_tex",2,m.BYTE,2,4)]},Si={geometry:[new ge("a_pos",2,m.UNSIGNED_SHORT,0,4)]},Je={shaders:{vertexShader:Pe("tileInfo/tileInfo.vert"),fragmentShader:Pe("tileInfo/tileInfo.frag")},attributes:new Map([["a_pos",0]])},be=300,Ee=32;class Bn extends W{constructor(){super(...arguments),this._color=K(1,0,0,1)}dispose(){this._outlineProgram&&(this._outlineProgram.dispose(),this._outlineProgram=null),this._tileInfoProgram&&(this._tileInfoProgram.dispose(),this._tileInfoProgram=null),this._outlineVertexArrayObject&&(this._outlineVertexArrayObject.dispose(),this._outlineVertexArrayObject=null),this._tileInfoVertexArrayObject&&(this._tileInfoVertexArrayObject.dispose(),this._tileInfoVertexArrayObject=null),this._canvas=null}prepareState({context:e}){e.setBlendingEnabled(!0),e.setBlendFunctionSeparate(D.ONE,D.ONE_MINUS_SRC_ALPHA,D.ONE,D.ONE_MINUS_SRC_ALPHA),e.setColorMask(!0,!0,!0,!0),e.setStencilWriteMask(0),e.setStencilTestEnabled(!1)}draw(e,t){const{context:n,requestRender:o,allowDelayedRender:i}=e;if(!t.isReady)return;if(this._loadWGLResources(n),i&&E(o)&&(!this._outlineProgram.isCompiled||!this._tileInfoProgram.isCompiled))return void o();n.bindVAO(this._outlineVertexArrayObject),n.useProgram(this._outlineProgram),this._outlineProgram.setUniformMatrix3fv("u_dvsMat3",t.transforms.dvs),this._outlineProgram.setUniform2f("u_coord_range",t.rangeX,t.rangeY),this._outlineProgram.setUniform1f("u_depth",0),this._outlineProgram.setUniform4fv("u_color",this._color),n.drawArrays(R.LINE_STRIP,0,4);const a=this._getTexture(n,t);a&&(n.bindVAO(this._tileInfoVertexArrayObject),n.useProgram(this._tileInfoProgram),n.bindTexture(a,0),this._tileInfoProgram.setUniformMatrix3fv("u_dvsMat3",t.transforms.dvs),this._tileInfoProgram.setUniform1f("u_depth",0),this._tileInfoProgram.setUniform2f("u_coord_ratio",t.rangeX/t.width,t.rangeY/t.height),this._tileInfoProgram.setUniform2f("u_delta",8,8),this._tileInfoProgram.setUniform2f("u_dimensions",a.descriptor.width,a.descriptor.height),n.drawArrays(R.TRIANGLE_STRIP,0,4)),n.bindVAO()}_loadWGLResources(e){if(this._outlineProgram&&this._tileInfoProgram)return;const t=Ae(e,he),n=Ae(e,Je),o=new Int8Array([0,0,1,0,1,1,0,1]),i=ee.createVertex(e,J.STATIC_DRAW,o),a=new le(e,he.attributes,Me,{geometry:i}),r=new Int8Array([0,0,1,0,0,1,1,1]),c=ee.createVertex(e,J.STATIC_DRAW,r),s=new le(e,Je.attributes,Me,{geometry:c});this._outlineProgram=t,this._tileInfoProgram=n,this._outlineVertexArrayObject=a,this._tileInfoVertexArrayObject=s}_getTexture(e,t){if(t.texture&&t.triangleCountReportedInDebug===t.triangleCount)return t.texture;t.triangleCountReportedInDebug=t.triangleCount,this._canvas||(this._canvas=document.createElement("canvas"),this._canvas.setAttribute("id","canvas2d"),this._canvas.setAttribute("width",`${be}`),this._canvas.setAttribute("height",`${Ee}`),this._canvas.setAttribute("style","display:none"));const n=t.triangleCount;let o=t.key.id;t.triangleCount>0&&(o+=`, ${n}`);const i=this._canvas,a=i.getContext("2d");return a.font="24px sans-serif",a.textAlign="left",a.textBaseline="top",a.clearRect(0,0,be,Ee),n>1e5?(a.fillStyle="red",a.fillRect(0,0,be,Ee),a.fillStyle="black"):(a.clearRect(0,0,be,Ee),a.fillStyle="blue"),a.fillText(o,0,0),t.texture=new se(e,{target:re.TEXTURE_2D,pixelFormat:B.RGBA,dataType:q.UNSIGNED_BYTE,samplingMode:N.NEAREST,wrapMode:Q.CLAMP_TO_EDGE},i),t.texture}}class Gn extends Fe{supportsSymbology(e){return e===te.PIE_CHART}_drawMarkers(e,t,n,o,i,a,r){const{context:c}=e,{rendererInfo:s}=e,{rendererSchema:u}=s;fe(u,"pie-chart"),n.setUniform4fv("u_colors",u.colors),n.setUniform4fv("u_defaultColor",u.defaultColor),n.setUniform4fv("u_othersColor",u.othersColor),n.setUniform4fv("u_outlineColor",u.outlineColor),n.setUniform1f("u_donutRatio",u.holePercentage),n.setUniform1f("u_sectorThreshold",u.sectorThreshold),n.setUniform1f("u_outlineWidth",u.outlineWidth),c.drawElements(o,i,m.UNSIGNED_INT,a)}}class Yn extends W{constructor(){super(...arguments),this._color=K(1,0,0,1),this._initialized=!1}dispose(){this._solidProgram&&(this._solidProgram.dispose(),this._solidProgram=null),this._solidVertexArrayObject&&(this._solidVertexArrayObject.dispose(),this._solidVertexArrayObject=null)}prepareState({context:e}){e.setDepthWriteEnabled(!1),e.setDepthTestEnabled(!1),e.setStencilTestEnabled(!0),e.setBlendingEnabled(!1),e.setColorMask(!1,!1,!1,!1),e.setStencilOp(X.KEEP,X.KEEP,X.REPLACE),e.setStencilWriteMask(255)}draw(e,t){const{context:n,requestRender:o,allowDelayedRender:i}=e;this._initialized||this._initialize(n),i&&E(o)&&!this._solidProgram.isCompiled?o():(n.setStencilFunctionSeparate(Mt.FRONT_AND_BACK,V.GREATER,t.stencilRef,255),n.bindVAO(this._solidVertexArrayObject),n.useProgram(this._solidProgram),this._solidProgram.setUniformMatrix3fv("u_dvsMat3",t.transforms.dvs),this._solidProgram.setUniform2fv("u_coord_range",[t.rangeX,t.rangeY]),this._solidProgram.setUniform1f("u_depth",0),this._solidProgram.setUniform4fv("u_color",this._color),n.drawArrays(R.TRIANGLE_STRIP,0,4),n.bindVAO())}_initialize(e){if(this._initialized)return!0;const t=Ae(e,he);if(!t)return!1;const n=new Int8Array([0,0,1,0,0,1,1,1]),o=ee.createVertex(e,J.STATIC_DRAW,n),i=new le(e,he.attributes,Me,{geometry:o});return this._solidProgram=t,this._solidVertexArrayObject=i,this._initialized=!0,!0}}class Hn extends W{constructor(){super(...arguments),this._color=K(1,0,0,1),this._patternMatrix=_e(),this._programOptions={id:!1,pattern:!1}}dispose(){this._vao&&(this._vao.dispose(),this._vao=null)}drawMany(e,t){const{context:n,painter:o,styleLayerUID:i,requestRender:a,allowDelayedRender:r}=e;this._loadWGLResources(e);const c=e.displayLevel,s=e.styleLayer,u=s.backgroundMaterial,f=o.vectorTilesMaterialManager,_=s.getPaintValue("background-color",c),v=s.getPaintValue("background-opacity",c),g=s.getPaintValue("background-pattern",c),p=g!==void 0,d=_[3]*v,I=1|window.devicePixelRatio,h=e.spriteMosaic;let O,P;const S=I>lt?2:1,y=e.drawPhase===U.HITTEST,x=this._programOptions;x.id=y,x.pattern=p;const T=f.getMaterialProgram(n,u,x);if(r&&E(a)&&!T.isCompiled)a();else{if(n.bindVAO(this._vao),n.useProgram(T),p){const b=h.getMosaicItemPosition(g,!0);if(E(b)){const{tl:A,br:C,page:L}=b;O=C[0]-A[0],P=C[1]-A[1];const M=h.getPageSize(L);E(M)&&(h.bind(n,N.LINEAR,L,$),T.setUniform4f("u_tlbr",A[0],A[1],C[0],C[1]),T.setUniform2fv("u_mosaicSize",M),T.setUniform1i("u_texture",$))}T.setUniform1f("u_opacity",v)}else this._color[0]=d*_[0],this._color[1]=d*_[1],this._color[2]=d*_[2],this._color[3]=d,T.setUniform4fv("u_color",this._color);if(T.setUniform1f("u_depth",s.z||0),y){const b=xe(i+1);T.setUniform4fv("u_id",b)}for(const b of t){if(T.setUniform1f("u_coord_range",b.rangeX),T.setUniformMatrix3fv("u_dvsMat3",b.transforms.dvs),p){const A=Math.max(2**(Math.round(c)-b.key.level),1),C=S*b.width*A,L=C/Ge(O),M=C/Ge(P);this._patternMatrix[0]=L,this._patternMatrix[4]=M,T.setUniformMatrix3fv("u_pattern_matrix",this._patternMatrix)}n.setStencilFunction(V.EQUAL,0,255),n.drawArrays(R.TRIANGLE_STRIP,0,4)}}}_loadWGLResources(e){if(this._vao)return;const{context:t,styleLayer:n}=e,o=n.backgroundMaterial,i=new Int8Array([0,0,1,0,0,1,1,1]),a=ee.createVertex(t,J.STATIC_DRAW,i),r=new le(t,o.getAttributeLocations(),o.getLayoutInfo(),{geometry:a});this._vao=r}}class Wn extends W{constructor(){super(...arguments),this._programOptions={id:!1}}dispose(){}drawMany(e,t){const{context:n,displayLevel:o,requiredLevel:i,state:a,drawPhase:r,painter:c,spriteMosaic:s,styleLayerUID:u,requestRender:f,allowDelayedRender:_}=e;if(!t.some(x=>{var T,b;return(b=(T=x.layerData.get(u))==null?void 0:T.circleIndexCount)!=null?b:!1}))return;const v=e.styleLayer,g=v.circleMaterial,p=c.vectorTilesMaterialManager,d=1.2,I=v.getPaintValue("circle-translate",o),h=v.getPaintValue("circle-translate-anchor",o),O=r===U.HITTEST,P=this._programOptions;P.id=O;const S=p.getMaterialProgram(n,g,P);if(_&&E(f)&&!S.isCompiled)return void f();n.useProgram(S),S.setUniformMatrix3fv("u_displayMat3",h===de.VIEWPORT?a.displayMat3:a.displayViewMat3),S.setUniform2fv("u_circleTranslation",I),S.setUniform1f("u_depth",v.z),S.setUniform1f("u_antialiasingWidth",d);let y=-1;if(O){const x=xe(u+1);S.setUniform4fv("u_id",x)}for(const x of t){if(!x.layerData.has(u))continue;x.key.level!==y&&(y=x.key.level,g.setDataUniforms(S,o,v,y,s));const T=x.layerData.get(u);if(!T.circleIndexCount)continue;T.prepareForRendering(n);const b=T.circleVertexArrayObject;G(b)||(n.bindVAO(b),S.setUniformMatrix3fv("u_dvsMat3",x.transforms.dvs),i!==x.key.level?n.setStencilFunction(V.EQUAL,x.stencilRef,255):n.setStencilFunction(V.GREATER,255,255),n.drawElements(R.TRIANGLES,T.circleIndexCount,m.UNSIGNED_INT,Uint32Array.BYTES_PER_ELEMENT*T.circleIndexStart),x.triangleCount+=T.circleIndexCount/3)}}}const et=1/65536;class kn extends W{constructor(){super(...arguments),this._fillProgramOptions={id:!1,pattern:!1},this._outlineProgramOptions={id:!1}}dispose(){}drawMany(e,t){const{displayLevel:n,drawPhase:o,renderPass:i,spriteMosaic:a,styleLayerUID:r}=e;let c=!1;for(const S of t)if(S.layerData.has(r)){const y=S.layerData.get(r);if(y.fillIndexCount>0||y.outlineIndexCount>0){c=!0;break}}if(!c)return;const s=e.styleLayer,u=s.getPaintProperty("fill-pattern"),f=u!==void 0,_=f&&u.isDataDriven;let v;if(f&&!_){const S=u.getValue(n);v=a.getMosaicItemPosition(S,!0)}const g=!f&&s.getPaintValue("fill-antialias",n);let p=!0,d=1;if(!f){const S=s.getPaintProperty("fill-color"),y=s.getPaintProperty("fill-opacity");if(!(S!=null&&S.isDataDriven)&&!(y!=null&&y.isDataDriven)){const x=s.getPaintValue("fill-color",n);d=s.getPaintValue("fill-opacity",n)*x[3],d>=1&&(p=!1)}}if(p&&i==="opaque")return;let I;o===U.HITTEST&&(I=xe(r+1));const h=s.getPaintValue("fill-translate",n),O=s.getPaintValue("fill-translate-anchor",n);(p||i!=="translucent")&&this._drawFill(e,r,s,t,h,O,f,v,_,I);const P=!s.hasDataDrivenOutlineColor&&s.outlineUsesFillColor&&d<1;g&&i!=="opaque"&&!P&&this._drawOutline(e,r,s,t,h,O,I)}_drawFill(e,t,n,o,i,a,r,c,s,u){if(r&&!s&&G(c))return;const{context:f,displayLevel:_,state:v,drawPhase:g,painter:p,pixelRatio:d,spriteMosaic:I,requestRender:h,allowDelayedRender:O}=e,P=n.fillMaterial,S=p.vectorTilesMaterialManager,y=d>lt?2:1,x=g===U.HITTEST,T=this._fillProgramOptions;T.id=x,T.pattern=r;const b=S.getMaterialProgram(f,P,T);if(O&&E(h)&&!b.isCompiled)return void h();if(f.useProgram(b),E(c)){const{page:C}=c,L=I.getPageSize(C);E(L)&&(I.bind(f,N.LINEAR,C,$),b.setUniform2fv("u_mosaicSize",L),b.setUniform1i("u_texture",$))}b.setUniformMatrix3fv("u_displayMat3",a===de.VIEWPORT?v.displayMat3:v.displayViewMat3),b.setUniform2fv("u_fillTranslation",i),b.setUniform1f("u_depth",n.z+et),x&&b.setUniform4fv("u_id",u);let A=-1;for(const C of o){if(!C.layerData.has(t))continue;C.key.level!==A&&(A=C.key.level,P.setDataUniforms(b,_,n,A,I));const L=C.layerData.get(t);if(!L.fillIndexCount)continue;L.prepareForRendering(f);const M=L.fillVertexArrayObject;if(!G(M)){if(f.bindVAO(M),b.setUniformMatrix3fv("u_dvsMat3",C.transforms.dvs),f.setStencilFunction(V.EQUAL,C.stencilRef,255),r){const F=Math.max(2**(Math.round(_)-C.key.level),1),z=C.rangeX/(y*C.width*F);b.setUniform1f("u_patternFactor",z)}if(s){const F=L.patternMap;if(!F)continue;for(const[z,ne]of F){const ie=I.getPageSize(z);E(ie)&&(I.bind(f,N.LINEAR,z,$),b.setUniform2fv("u_mosaicSize",ie),b.setUniform1i("u_texture",$),f.drawElements(R.TRIANGLES,ne[1],m.UNSIGNED_INT,Uint32Array.BYTES_PER_ELEMENT*ne[0]))}}else f.drawElements(R.TRIANGLES,L.fillIndexCount,m.UNSIGNED_INT,Uint32Array.BYTES_PER_ELEMENT*L.fillIndexStart);C.triangleCount+=L.fillIndexCount/3}}}_drawOutline(e,t,n,o,i,a,r){const{context:c,displayLevel:s,state:u,drawPhase:f,painter:_,pixelRatio:v,spriteMosaic:g,requestRender:p,allowDelayedRender:d}=e,I=n.outlineMaterial,h=_.vectorTilesMaterialManager,O=.75/v,P=f===U.HITTEST,S=this._outlineProgramOptions;S.id=P;const y=h.getMaterialProgram(c,I,S);if(d&&E(p)&&!y.isCompiled)return void p();c.useProgram(y),y.setUniformMatrix3fv("u_displayMat3",a===de.VIEWPORT?u.displayMat3:u.displayViewMat3),y.setUniform2fv("u_fillTranslation",i),y.setUniform1f("u_depth",n.z+et),y.setUniform1f("u_outline_width",O),P&&y.setUniform4fv("u_id",r);let x=-1;for(const T of o){if(!T.layerData.has(t))continue;T.key.level!==x&&(x=T.key.level,I.setDataUniforms(y,s,n,x,g));const b=T.layerData.get(t);if(b.prepareForRendering(c),!b.outlineIndexCount)continue;const A=b.outlineVertexArrayObject;G(A)||(c.bindVAO(A),y.setUniformMatrix3fv("u_dvsMat3",T.transforms.dvs),c.setStencilFunction(V.EQUAL,T.stencilRef,255),c.drawElements(R.TRIANGLES,b.outlineIndexCount,m.UNSIGNED_INT,Uint32Array.BYTES_PER_ELEMENT*b.outlineIndexStart),T.triangleCount+=b.outlineIndexCount/3)}}}class $n extends W{constructor(){super(...arguments),this._programOptions={id:!1,pattern:!1,sdf:!1}}dispose(){}drawMany(e,t){const{context:n,displayLevel:o,state:i,drawPhase:a,painter:r,pixelRatio:c,spriteMosaic:s,styleLayerUID:u,requestRender:f,allowDelayedRender:_}=e;if(!t.some(M=>{var F,z;return(z=(F=M.layerData.get(u))==null?void 0:F.lineIndexCount)!=null?z:!1}))return;const v=e.styleLayer,g=v.lineMaterial,p=r.vectorTilesMaterialManager,d=v.getPaintValue("line-translate",o),I=v.getPaintValue("line-translate-anchor",o),h=v.getPaintProperty("line-pattern"),O=h!==void 0,P=O&&h.isDataDriven;let S,y;if(O&&!P){const M=h.getValue(o);S=s.getMosaicItemPosition(M)}let x=!1;if(!O){const M=v.getPaintProperty("line-dasharray");if(y=M!==void 0,x=y&&M.isDataDriven,y&&!x){const F=M.getValue(o),z=v.getDashKey(F,v.getLayoutValue("line-cap",o));S=s.getMosaicItemPosition(z)}}const T=1/c,b=a===U.HITTEST,A=this._programOptions;A.id=b,A.pattern=O,A.sdf=y;const C=p.getMaterialProgram(n,g,A);if(_&&E(f)&&!C.isCompiled)return void f();if(n.useProgram(C),C.setUniformMatrix3fv("u_displayViewMat3",i.displayViewMat3),C.setUniformMatrix3fv("u_displayMat3",I===de.VIEWPORT?i.displayMat3:i.displayViewMat3),C.setUniform2fv("u_lineTranslation",d),C.setUniform1f("u_depth",v.z),C.setUniform1f("u_antialiasing",T),b){const M=xe(u+1);C.setUniform4fv("u_id",M)}if(S&&E(S)){const{page:M}=S,F=s.getPageSize(M);E(F)&&(s.bind(n,N.LINEAR,M,$),C.setUniform2fv("u_mosaicSize",F),C.setUniform1i("u_texture",$))}let L=-1;for(const M of t){if(!M.layerData.has(u))continue;M.key.level!==L&&(L=M.key.level,g.setDataUniforms(C,o,v,L,s));const F=2**(o-L)/c;C.setUniform1f("u_zoomFactor",F);const z=M.layerData.get(u);if(!z.lineIndexCount)continue;z.prepareForRendering(n);const ne=z.lineVertexArrayObject;if(!G(ne)){if(n.bindVAO(ne),C.setUniformMatrix3fv("u_dvsMat3",M.transforms.dvs),n.setStencilFunction(V.EQUAL,M.stencilRef,255),P||x){const ie=z.patternMap;if(!ie)continue;for(const[ve,w]of ie){const ue=s.getPageSize(ve);E(ue)&&(s.bind(n,N.LINEAR,ve,$),C.setUniform2fv("u_mosaicSize",ue),C.setUniform1i("u_texture",$),n.drawElements(R.TRIANGLES,w[1],m.UNSIGNED_INT,Uint32Array.BYTES_PER_ELEMENT*w[0]))}}else n.drawElements(R.TRIANGLES,z.lineIndexCount,m.UNSIGNED_INT,Uint32Array.BYTES_PER_ELEMENT*z.lineIndexStart);M.triangleCount+=z.lineIndexCount/3}}}}const Zn=1/65536;class qn extends W{constructor(){super(...arguments),this._iconProgramOptions={id:!1,sdf:!1},this._sdfProgramOptions={id:!1},this._spritesTextureSize=Ct()}dispose(){}drawMany(e,t){const{drawPhase:n,styleLayerUID:o}=e,i=e.styleLayer;let a;n===U.HITTEST&&(a=xe(o+1)),this._drawIcons(e,i,t,a),this._drawText(e,i,t,a)}_drawIcons(e,t,n,o){const{context:i,displayLevel:a,drawPhase:r,painter:c,spriteMosaic:s,state:u,styleLayerUID:f,requestRender:_,allowDelayedRender:v}=e,g=t.iconMaterial,p=c.vectorTilesMaterialManager;let d,I=!1;for(const L of n)if(L.layerData.has(f)&&(d=L.layerData.get(f),d.iconPerPageElementsMap.size>0)){I=!0;break}if(!I)return;const h=t.getPaintValue("icon-translate",a),O=t.getPaintValue("icon-translate-anchor",a);let P=t.getLayoutValue("icon-rotation-alignment",a);P===Z.AUTO&&(P=t.getLayoutValue("symbol-placement",a)===$e.POINT?Z.VIEWPORT:Z.MAP);const S=P===Z.MAP,y=t.getLayoutValue("icon-keep-upright",a)&&S,x=d.isIconSDF,T=r===U.HITTEST,b=this._iconProgramOptions;b.id=T,b.sdf=x;const A=p.getMaterialProgram(i,g,b);if(v&&E(_)&&!A.isCompiled)return void _();i.useProgram(A),A.setUniformMatrix3fv("u_displayViewMat3",P===Z.MAP?u.displayViewMat3:u.displayMat3),A.setUniformMatrix3fv("u_displayMat3",O===de.VIEWPORT?u.displayMat3:u.displayViewMat3),A.setUniform2fv("u_iconTranslation",h),A.setUniform1f("u_depth",t.z),A.setUniform1f("u_mapRotation",qe(u.rotation)),A.setUniform1f("u_keepUpright",y?1:0),A.setUniform1f("u_level",10*a),A.setUniform1i("u_texture",$),A.setUniform1f("u_fadeDuration",Ze/1e3),T&&A.setUniform4fv("u_id",o);let C=-1;for(const L of n){if(!L.layerData.has(f)||(L.key.level!==C&&(C=L.key.level,g.setDataUniforms(A,a,t,C,s)),d=L.layerData.get(f),d.iconPerPageElementsMap.size===0))continue;d.prepareForRendering(i),d.updateOpacityInfo();const M=d.iconVertexArrayObject;if(!G(M)){i.bindVAO(M),A.setUniformMatrix3fv("u_dvsMat3",L.transforms.dvs),A.setUniform1f("u_time",(performance.now()-d.lastOpacityUpdate)/1e3);for(const[F,z]of d.iconPerPageElementsMap)this._renderIconRange(e,A,z,F,L)}}}_renderIconRange(e,t,n,o,i){const{context:a,spriteMosaic:r}=e;this._spritesTextureSize[0]=r.getWidth(o)/4,this._spritesTextureSize[1]=r.getHeight(o)/4,t.setUniform2fv("u_mosaicSize",this._spritesTextureSize),r.bind(a,N.LINEAR,o,$),a.setStencilTestEnabled(!0),a.setStencilFunction(V.GREATER,255,255),a.setStencilWriteMask(0),a.drawElements(R.TRIANGLES,n[1],m.UNSIGNED_INT,Uint32Array.BYTES_PER_ELEMENT*n[0]),i.triangleCount+=n[1]/3}_drawText(e,t,n,o){const{context:i,displayLevel:a,drawPhase:r,glyphMosaic:c,painter:s,pixelRatio:u,spriteMosaic:f,state:_,styleLayerUID:v,requestRender:g,allowDelayedRender:p}=e,d=t.textMaterial,I=s.vectorTilesMaterialManager;let h,O=!1;for(const j of n)if(j.layerData.has(v)&&(h=j.layerData.get(v),h.glyphPerPageElementsMap.size>0)){O=!0;break}if(!O)return;const P=t.getPaintProperty("text-opacity");if(P&&!P.isDataDriven&&P.getValue(a)===0)return;const S=t.getPaintProperty("text-color"),y=!S||S.isDataDriven||S.getValue(a)[3]>0,x=t.getPaintProperty("text-halo-width"),T=t.getPaintProperty("text-halo-color"),b=(!x||x.isDataDriven||x.getValue(a)>0)&&(!T||T.isDataDriven||T.getValue(a)[3]>0);if(!y&&!b)return;const A=24/8;let C=t.getLayoutValue("text-rotation-alignment",a);C===Z.AUTO&&(C=t.getLayoutValue("symbol-placement",a)===$e.POINT?Z.VIEWPORT:Z.MAP);const L=C===Z.MAP,M=t.getLayoutValue("text-keep-upright",a)&&L,F=r===U.HITTEST,z=.8*A/u;this._glyphTextureSize||(this._glyphTextureSize=pe(c.width/4,c.height/4));const ne=t.getPaintValue("text-translate",a),ie=t.getPaintValue("text-translate-anchor",a),ve=this._sdfProgramOptions;ve.id=F;const w=I.getMaterialProgram(i,d,ve);if(p&&E(g)&&!w.isCompiled)return void g();i.useProgram(w),w.setUniformMatrix3fv("u_displayViewMat3",C===Z.MAP?_.displayViewMat3:_.displayMat3),w.setUniformMatrix3fv("u_displayMat3",ie===de.VIEWPORT?_.displayMat3:_.displayViewMat3),w.setUniform2fv("u_textTranslation",ne),w.setUniform1f("u_depth",t.z+Zn),w.setUniform2fv("u_mosaicSize",this._glyphTextureSize),w.setUniform1f("u_mapRotation",qe(_.rotation)),w.setUniform1f("u_keepUpright",M?1:0),w.setUniform1f("u_level",10*a),w.setUniform1i("u_texture",ke),w.setUniform1f("u_antialiasingWidth",z),w.setUniform1f("u_fadeDuration",Ze/1e3),F&&w.setUniform4fv("u_id",o);let ue=-1;for(const j of n){if(!j.layerData.has(v)||(j.key.level!==ue&&(ue=j.key.level,d.setDataUniforms(w,a,t,ue,f)),h=j.layerData.get(v),h.glyphPerPageElementsMap.size===0))continue;h.prepareForRendering(i),h.updateOpacityInfo();const Ue=h.textVertexArrayObject;if(G(Ue))continue;i.bindVAO(Ue),w.setUniformMatrix3fv("u_dvsMat3",j.transforms.dvs),i.setStencilTestEnabled(!0),i.setStencilFunction(V.GREATER,255,255),i.setStencilWriteMask(0);const gt=(performance.now()-h.lastOpacityUpdate)/1e3;w.setUniform1f("u_time",gt),h.glyphPerPageElementsMap.forEach((ht,xt)=>{this._renderGlyphRange(i,ht,xt,c,w,b,y,j)})}}_renderGlyphRange(e,t,n,o,i,a,r,c){o.bind(e,N.LINEAR,n,ke),a&&(i.setUniform1f("u_halo",1),e.drawElements(R.TRIANGLES,t[1],m.UNSIGNED_INT,Uint32Array.BYTES_PER_ELEMENT*t[0]),c.triangleCount+=t[1]/3),r&&(i.setUniform1f("u_halo",0),e.drawElements(R.TRIANGLES,t[1],m.UNSIGNED_INT,Uint32Array.BYTES_PER_ELEMENT*t[0]),c.triangleCount+=t[1]/3)}}const Kn=l=>ce(l.data,{geometry:[{location:0,name:"a_pos",count:2,type:m.SHORT},{location:1,name:"a_id",count:4,type:m.UNSIGNED_BYTE},{location:2,name:"a_color",count:4,type:m.UNSIGNED_BYTE,normalized:!0},{location:3,name:"a_haloColor",count:4,type:m.UNSIGNED_BYTE,normalized:!0},{location:4,name:"a_texAndSize",count:4,type:m.UNSIGNED_BYTE},{location:5,name:"a_refSymbolAndPlacementOffset",count:4,type:m.UNSIGNED_BYTE},{location:6,name:"a_glyphData",count:4,type:m.UNSIGNED_BYTE},{location:7,name:"a_vertexOffset",count:2,type:m.SHORT},{location:8,name:"a_texCoords",count:2,type:m.UNSIGNED_SHORT}]});class jn extends ye{dispose(){}getGeometryType(){return me.LABEL}supportsSymbology(e){return!0}drawGeometry(e,t,n,o){const{context:i,painter:a,state:r,rendererInfo:c,requestRender:s,allowDelayedRender:u}=e,f=Kt.load(n.materialKey),_=f.mapAligned?1:0;if(!_&&Math.abs(t.key.level-Math.round(100*e.displayLevel)/100)>=1)return;const{bufferLayouts:v,attributes:g}=Kn(f),p=a.materialManager.getMaterialProgram(e,f,"materials/label",g,o);if(u&&E(s)&&!p.isCompiled)return void s();e.context.setStencilFunction(V.EQUAL,0,255),i.useProgram(p),this._setSharedUniforms(p,e,t),a.textureManager.bindTextures(i,p,f);const d=_===1?r.displayViewMat3:r.displayMat3;this._setSizeVVUniforms(f,p,c,t),p.setUniform1f("u_mapRotation",Math.floor(r.rotation/360*254)),p.setUniform1f("u_mapAligned",_),p.setUniformMatrix3fv("u_displayMat3",d),p.setUniform1f("u_opacity",1),p.setUniform2fv("u_screenSize",e.state.size),p.setUniform1f("u_isHalo",1);const I=n.target.getVAO(i,v,g),h=n.indexFrom*Uint32Array.BYTES_PER_ELEMENT;i.bindVAO(I),i.drawElements(R.TRIANGLES,n.indexCount,m.UNSIGNED_INT,h),p.setUniform1f("u_isHalo",0),i.drawElements(R.TRIANGLES,n.indexCount,m.UNSIGNED_INT,h),i.setStencilTestEnabled(!0),i.setBlendingEnabled(!0)}}const Xn=l=>ce(l.data,{geometry:[{location:0,name:"a_pos",count:2,type:m.SHORT},{location:1,name:"a_id",count:4,type:m.UNSIGNED_BYTE},{location:2,name:"a_color",count:4,type:m.UNSIGNED_BYTE,normalized:!0},{location:3,name:"a_offsetAndNormal",count:4,type:m.BYTE},{location:4,name:"a_accumulatedDistanceAndHalfWidth",count:2,type:m.UNSIGNED_SHORT},{location:5,name:"a_tlbr",count:4,type:m.UNSIGNED_SHORT},{location:6,name:"a_segmentDirection",count:4,type:m.BYTE},{location:7,name:"a_aux",count:2,type:m.UNSIGNED_SHORT},{location:8,name:"a_zoomRange",count:2,type:m.UNSIGNED_SHORT}]});class Qn extends ye{dispose(){}getGeometryType(){return me.LINE}supportsSymbology(e){return!0}drawGeometry(e,t,n,o){const{context:i,painter:a,rendererInfo:r,displayLevel:c,passOptions:s,requestRender:u,allowDelayedRender:f}=e,_=jt.load(n.materialKey),v=E(s)&&s.type==="hittest";let g=Xn(_),p=R.TRIANGLES;v&&(g=this._getTriangleDesc(n.materialKey,g),p=R.POINTS);const{attributes:d,bufferLayouts:I}=g,h=a.materialManager.getMaterialProgram(e,_,"materials/line",d,o);if(f&&E(u)&&!h.isCompiled)return void u();const O=1/e.pixelRatio,P=0;i.useProgram(h),this._setSharedUniforms(h,e,t),_.textureBinding&&a.textureManager.bindTextures(i,h,_);const S=2**(c-t.key.level);h.setUniform1f("u_zoomFactor",S),h.setUniform1f("u_blur",P+O),h.setUniform1f("u_antialiasing",O),this._setSizeVVUniforms(_,h,r,t),this._setColorAndOpacityVVUniforms(_,h,r),i.setFaceCullingEnabled(!1);const y=n.target.getVAO(i,I,d,v);let x=n.indexCount,T=n.indexFrom*Uint32Array.BYTES_PER_ELEMENT;v&&(x/=3,T/=3),i.bindVAO(y),i.drawElements(p,x,m.UNSIGNED_INT,T)}}const Jn=l=>ce(l.data,{geometry:[{location:0,name:"a_pos",count:2,type:m.SHORT},{location:1,name:"a_id",count:4,type:m.UNSIGNED_BYTE},{location:2,name:"a_color",count:4,type:m.UNSIGNED_BYTE,normalized:!0},{location:3,name:"a_haloColor",count:4,type:m.UNSIGNED_BYTE,normalized:!0},{location:4,name:"a_texFontSize",count:4,type:m.UNSIGNED_BYTE},{location:5,name:"a_aux",count:4,type:m.BYTE},{location:6,name:"a_zoomRange",count:2,type:m.UNSIGNED_SHORT},{location:7,name:"a_vertexOffset",count:2,type:m.SHORT},{location:8,name:"a_texCoords",count:2,type:m.UNSIGNED_SHORT}]});class ei extends ye{dispose(){}getGeometryType(){return me.TEXT}supportsSymbology(e){return!0}drawGeometry(e,t,n,o){const{context:i,painter:a,rendererInfo:r,state:c,passOptions:s,requestRender:u,allowDelayedRender:f}=e,_=Xt.load(n.materialKey),v=E(s)&&s.type==="hittest",{bufferLayouts:g,attributes:p}=Jn(_),d=a.materialManager.getMaterialProgram(e,_,"materials/text",p,o);if(f&&E(u)&&!d.isCompiled)return void u();i.useProgram(d);let I=R.TRIANGLES;v&&(I=R.POINTS),this._setSharedUniforms(d,e,t),a.textureManager.bindTextures(i,d,_),d.setUniformMatrix3fv("u_displayMat3",c.displayMat3),d.setUniformMatrix3fv("u_displayViewMat3",c.displayViewMat3),this._setSizeVVUniforms(_,d,r,t),this._setColorAndOpacityVVUniforms(_,d,r),this._setRotationVVUniforms(_,d,r),d.setUniform1f("u_isHalo",1);const h=n.target.getVAO(i,g,p),O=n.indexFrom*Uint32Array.BYTES_PER_ELEMENT;i.bindVAO(h),i.drawElements(R.TRIANGLES,n.indexCount,m.UNSIGNED_INT,O),d.setUniform1f("u_isHalo",0),i.drawElements(I,n.indexCount,m.UNSIGNED_INT,O)}}const ti={marker:Fe,line:Qn,fill:pt,text:ei,label:jn,clip:Pn,stencil:Yn,bitmap:pn,overlay:Rn,raster:dn,rasterVF:mn,flow:Jt,tileInfo:Bn,vtlBackground:Hn,vtlFill:kn,vtlLine:$n,vtlCircle:Wn,vtlSymbol:qn,dotDensity:Mn,heatmap:Fn,pieChart:Gn},ni=l=>{switch(l.BYTES_PER_ELEMENT){case 1:return m.UNSIGNED_BYTE;case 2:return m.UNSIGNED_SHORT;case 4:return m.UNSIGNED_INT;default:throw new ae("Cannot get DataType of array")}},ii=(l,e,t,n)=>{let o=0;for(let i=1;i<t;i++){const a=l[2*(e+i-1)],r=l[2*(e+i-1)+1];o+=(l[2*(e+i)]-a)*(l[2*(e+i)+1]+r)}return n?o>0:o<0},tt=({coords:l,lengths:e},t)=>{const n=[];for(let o=0,i=0;o<e.length;i+=e[o],o+=1){const a=i,r=[];for(;o<e.length-1&&ii(l,i+e[o],e[o+1],t);o+=1,i+=e[o])r.push(i+e[o]-a);const c=l.slice(2*a,2*(i+e[o])),s=Qt(c,r,2);for(const u of s)n.push(u+a)}return n};class k{constructor(e,t,n,o=!1){this._cache={},this.vertices=e,this.indices=t,this.primitiveType=n,this.isMapSpace=o}static fromRect({x:e,y:t,width:n,height:o}){const i=e,a=t,r=i+n,c=a+o;return k.fromScreenExtent({xmin:i,ymin:a,xmax:r,ymax:c})}static fromPath(e){const t=Ot(new Ye,e.path,!1,!1),n=t.coords,o=new Uint32Array(tt(t,!0)),i=new Uint32Array(n.length/2);for(let a=0;a<i.length;a++)i[a]=H(Math.floor(n[2*a]),Math.floor(n[2*a+1]));return new k({geometry:i},o,R.TRIANGLES)}static fromGeometry(e,t){const n=t.geometry.type;switch(n){case"polygon":return k.fromPolygon(e,t.geometry);case"extent":return k.fromMapExtent(e,t.geometry);default:return ze.getLogger("esri.views.2d.engine.webgl.Mesh2D").error(new ae("mapview-bad-type",`Unable to create a mesh from type ${n}`,t)),k.fromRect({x:0,y:0,width:1,height:1})}}static fromPolygon(e,t){const n=At(new Ye,t,!1,!1),o=n.coords,i=new Uint32Array(tt(n,!1)),a=new Uint32Array(o.length/2),r=He(),c=He();for(let s=0;s<a.length;s++)Pt(r,o[2*s],o[2*s+1]),e.toScreen(c,r),a[s]=H(Math.floor(c[0]),Math.floor(c[1]));return new k({geometry:a},i,R.TRIANGLES,!0)}static fromScreenExtent({xmin:e,xmax:t,ymin:n,ymax:o}){const i={geometry:new Uint32Array([H(e,n),H(t,n),H(e,o),H(e,o),H(t,n),H(t,o)])},a=new Uint32Array([0,1,2,3,4,5]);return new k(i,a,R.TRIANGLES)}static fromMapExtent(e,t){const[n,o]=e.toScreen([0,0],[t.xmin,t.ymin]),[i,a]=e.toScreen([0,0],[t.xmax,t.ymax]),r={geometry:new Uint32Array([H(n,o),H(i,o),H(n,a),H(n,a),H(i,o),H(i,a)])},c=new Uint32Array([0,1,2,3,4,5]);return new k(r,c,R.TRIANGLES)}destroy(){E(this._cache.indexBuffer)&&this._cache.indexBuffer.dispose();for(const e in this._cache.vertexBuffers)E(this._cache.vertexBuffers[e])&&this._cache.vertexBuffers[e].dispose()}get elementType(){return ni(this.indices)}getIndexBuffer(e,t=J.STATIC_DRAW){return this._cache.indexBuffer||(this._cache.indexBuffer=ee.createIndex(e,t,this.indices)),this._cache.indexBuffer}getVertexBuffers(e,t=J.STATIC_DRAW){return this._cache.vertexBuffers||(this._cache.vertexBuffers=Object.keys(this.vertices).reduce((n,o)=>({...n,[o]:ee.createVertex(e,t,this.vertices[o])}),{})),this._cache.vertexBuffers}}const Ie=l=>parseFloat(l)/100;class Ve extends ot{constructor(e,t){super(),this._clip=t,this._cache={},this.stage=e,this._handle=Dt(()=>t.version,()=>this._invalidate()),this.ready()}static fromClipArea(e,t){return new Ve(e,t)}_destroyGL(){E(this._cache.mesh)&&(this._cache.mesh.destroy(),this._cache.mesh=null),E(this._cache.vao)&&(this._cache.vao.dispose(),this._cache.vao=null)}destroy(){this._destroyGL(),this._handle.remove()}getVAO(e,t,n,o){const[i,a]=t.size;if(this._clip.type!=="geometry"&&this._lastWidth===i&&this._lastHeight===a||(this._lastWidth=i,this._lastHeight=a,this._destroyGL()),G(this._cache.vao)){const r=this._createMesh(t,this._clip),c=r.getIndexBuffer(e),s=r.getVertexBuffers(e);this._cache.mesh=r,this._cache.vao=new le(e,n,o,s,c)}return this._cache.vao}_createTransforms(){return{dvs:_e()}}_invalidate(){this._destroyGL(),this.requestRender()}_createScreenRect(e,t){const[n,o]=e.size,i=typeof t.left=="string"?Ie(t.left)*n:t.left,a=typeof t.right=="string"?Ie(t.right)*n:t.right,r=typeof t.top=="string"?Ie(t.top)*o:t.top,c=typeof t.bottom=="string"?Ie(t.bottom)*o:t.bottom,s=i,u=r;return{x:s,y:u,width:Math.max(n-a-s,0),height:Math.max(o-c-u,0)}}_createMesh(e,t){switch(t.type){case"rect":return k.fromRect(this._createScreenRect(e,t));case"path":return k.fromPath(t);case"geometry":return k.fromGeometry(e,t);default:return ze.getLogger("esri.views.2d.engine.webgl.ClippingInfo").error(new ae("mapview-bad-type","Unable to create ClippingInfo mesh from clip of type: ${clip.type}")),k.fromRect({x:0,y:0,width:1,height:1})}}}class Ti extends zt{constructor(){super(...arguments),this.name=this.constructor.name}set clips(e){this._clips=e,this.children.forEach(t=>t.clips=e),this._updateClippingInfo()}beforeRender(e){super.beforeRender(e),this.updateTransforms(e.state)}_createTransforms(){return{dvs:_e()}}doRender(e){const t=this.createRenderParams(e),{painter:n,globalOpacity:o,profiler:i,drawPhase:a}=t,r=a===U.LABEL||a===U.HIGHLIGHT?1:o*this.computedOpacity;i.recordContainerStart(this.name),n.beforeRenderLayer(t,this._clippingInfos?255:0,r),this.renderChildren(t),n.compositeLayer(t,r),i.recordContainerEnd()}renderChildren(e){G(this._renderPasses)&&(this._renderPasses=this.prepareRenderPasses(e.painter));for(const t of this._renderPasses)try{t.render(e)}catch{}}createRenderParams(e){return e.requireFBO=this.requiresDedicatedFBO,e}prepareRenderPasses(e){return[e.registerRenderPass({name:"clip",brushes:[ti.clip],target:()=>this._clippingInfos,drawPhase:U.MAP|U.LABEL|U.LABEL_ALPHA|U.DEBUG|U.HIGHLIGHT})]}updateTransforms(e){for(const t of this.children)t.setTransform(e)}onAttach(){super.onAttach(),this._updateClippingInfo()}onDetach(){super.onDetach(),this._updateClippingInfo()}_updateClippingInfo(){if(E(this._clippingInfos)&&(this._clippingInfos.forEach(t=>t.destroy()),this._clippingInfos=null),!this.stage)return;const e=this._clips;E(e)&&e.length&&(this._clippingInfos=e.items.map(t=>Ve.fromClipArea(this.stage,t))),this.requestRender()}}export{we as a,zn as b,ti as c,mn as d,tn as e,Yn as h,Jt as i,Si as m,Pe as n,Ti as o,xi as p,yi as t,Bn as x};