/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as t,__param as e}from"tslib";import{tileSize as o}from"../../../definitions.js";import{location as s,uniform as i,texture as r,define as d,input as l,UniformGroup as n,TextureGroup as a,FragmentOutput as p}from"../../GraphShaderModule.js";import{Float as h,FixedArray as c,Vec4 as u,Sampler2D as m,Mat3 as y,Vec3 as v,texture2D as g,Mat4 as x,step as w,dot as f,max as T}from"../../graph/glsl.js";import{FeatureFragmentInput as A,FeatureVertexInput as D,AFeatureShader as b}from"../shaders/AFeatureShader.js";import{noHit as C}from"../shaders/constants.js";import{max4 as j}from"../shaders/utils.js";class V extends D{}t([s(3,h)],V.prototype,"inverseArea",void 0);class F extends A{}class O extends n{}t([i(c.ofType(u,2))],O.prototype,"isActive",void 0),t([i(c.ofType(u,8))],O.prototype,"colors",void 0),t([i(h)],O.prototype,"dotValue",void 0);class S extends n{}t([i(h)],S.prototype,"tileZoomFactor",void 0),t([i(h)],S.prototype,"pixelRatio",void 0),t([i(h)],S.prototype,"tileDotsOverArea",void 0);class _ extends a{}t([r(m)],_.prototype,"dotTexture0",void 0),t([r(m)],_.prototype,"dotTexture1",void 0);class P extends b{constructor(){super(...arguments),this.type="DotDensityPolygonShader"}_dotThreshold(t,e,o){return t.divide(e).divide(o)}vertex(t){const e=new y(2/o,0,0,0,-2/o,0,-1,1,1).multiply(new v(t.pos,1)),s=this.clip(t.id),i=new u(e.xy,s,1),r=this.getVVData(t.id).multiply(this.instance.isActive.get(0)).multiply(t.inverseArea),d=this.storageTextures.getDataDrivenData0(this.getAttributeDataCoords(t.id)).multiply(this.instance.isActive.get(1)).multiply(t.inverseArea),l=this.draw.tileZoomFactor.multiply(o).divide(this.draw.pixelRatio),n=this._dotThreshold(r,this.instance.dotValue,this.draw.tileDotsOverArea),a=this._dotThreshold(d,this.instance.dotValue,this.draw.tileDotsOverArea),p=t.pos.add(.5).divide(l);return{glPosition:i,color:new u(0,0,0,0),textureCoords:p,thresholds0:n,thresholds1:a}}fragment(t){const e=new p,o=g(this.drawTextures.dotTexture0,t.textureCoords),s=g(this.drawTextures.dotTexture1,t.textureCoords),i=t.thresholds0.subtract(o),r=t.thresholds1.subtract(s);let d;const l=x.fromColumns(this.instance.colors.get(0),this.instance.colors.get(1),this.instance.colors.get(2),this.instance.colors.get(3)),n=x.fromColumns(this.instance.colors.get(4),this.instance.colors.get(5),this.instance.colors.get(6),this.instance.colors.get(7));if(this.blending){const t=w(new h(0),i),e=w(new h(0),r),o=f(t,i).add(f(e,r)),s=w(o,new h(0)),a=new h(1).subtract(s),p=o.add(s),c=i.multiply(t).divide(p),u=r.multiply(e).divide(p),m=l.multiply(c).add(n.multiply(u));d=a.multiply(m)}else{const t=T(j(i),j(r)),e=w(t,new h(0)),o=new h(1).subtract(e),s=w(t,i),a=w(t,r),p=l.multiply(s).add(n.multiply(a));d=o.multiply(p)}return e.fragColor=d,e}hittest(t){return new h(C)}}t([d],P.prototype,"blending",void 0),t([i(O)],P.prototype,"instance",void 0),t([i(S)],P.prototype,"draw",void 0),t([r(_)],P.prototype,"drawTextures",void 0),t([e(0,l(V))],P.prototype,"vertex",null),t([e(0,l(A))],P.prototype,"fragment",null);export{_ as DotDensityPolygonDrawTextures,S as DotDensityPolygonDrawUniforms,F as DotDensityPolygonFragmentInput,O as DotDensityPolygonInstanceUniforms,P as DotDensityPolygonShader,V as DotDensityPolygonVertexInput};
