memoscan
← all memos

Memo 0xef90bbad…8931f8 on Ethereum

m]:J.int(4,4),[ut.md]:J.int(4,4),[ut.lg]:J.int(4,4),default:2});Ae=be(Ae,{margin:c*Be.scale,HVariance:{min:-r,max:r,threshold:1,mean:1,stdDev:1},VVariance:{min:-r,max:r,threshold:1,mean:1,stdDev:1},circles:{count:5,minRadius:5,maxRadius:18},wobble:{enabled:!0,count:1e10,minLength:2,layers:4,multiLayers:1,gridDivisions:1,warpFreq:{min:800,max:2e3},offsetMultiplier:.6},perspectiveBox:{enabled:!0,threshold:4,mean:2,stdDev:8,firstFull:!0,count:1}}),tt={...tt,cropToMargin:!1,margin:6*Be.scale}},vt=new e.OrthographicCamera(-1,1,1,-1,0,1);class Lt extends e.BufferGeometry{constructor(){super(),this.setAttribute("position",new e.Float32BufferAttribute([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute("uv",new e.Float32BufferAttribute([0,2,0,0,2,0],2))}}const St=new Lt;class Xt{_mesh;constructor(t){this._mesh=new e.Mesh(St,t)}dispose(){this._mesh.geometry.dispose()}render(e=X){e.render(this._mesh,vt)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}}let Ct="\n vec2 lookupWarpSample(const vec2 uv) {\n\n // vec2 offset = vec2(0.2);\n return ((texture(tWarpTex, uv).xy - 0.5) * 2.);\n }\n",Vt="\n float remap(float t, float a1, float b1, float a2, float b2) {\n return a2 + (b2 - a2) * ((t - a1) / (b1 - a1));\n }\n";function Kt(){return new e.ShaderMaterial({uniforms:{resolution:{value:new e.Vector2(Q,j)},noiseOffset:{value:new e.Vector2(ke[0],ke[1])},...ce(),wave:{value:{...$e}},uWarpEnabled:{value:!1},grid:{value:{...Be}}},depthWrite:!1,depthTest:!1,glslVersion:e.GLSL3,vertexShader:le,fragmentShader:`\n precision highp float;\n precision highp int;\n \n uniform vec2 resolution;\n uniform vec2 uTileOffset;\n uniform vec2 uTileSize;\n uniform vec2 noiseOffset;\n uniform bool uWarpEnabled;\n\n struct Wave {\n bool warpX;\n bool warpY;\n\n bool offAxisY;\n bool offAxisX;\n\n float warpXMult;\n float warpYMult;\n\n float displacementStrength;\n \n bool noiseMapEnabled;\n };\n \n uniform Wave wave;\n\n struct Grid {\n float countX;\n float countY;\n float marginX;\n float marginY;\n float w;\n float h;\n float scale;\n };\n\n uniform Grid grid;\n\n varying vec2 vUv;\n out vec4 outColor;\n\n // const float scale = 10.;\n\n #include <packing>\n\n ${ee}\n ${Vt}\n ${te}\n \n // Third compomnent is the intersection\n // const float PI2 = acos(-1.);\n \n float noiseLookup(vec2 uv, float freq) {\n float influence = fbm(uv + noiseOffset, 2, freq + 0.2, 0.8);\n return smoothstep(0., 1., abs(fbm(uv - influence, 2, freq, 0.5)));\n }\n\n// vec2 warpTextureSampleUv(const vec2 uv) {\n// // Center of the drop\n// vec2 center = vec2(0.5, 0.5);\n// // Spacing between each ripple (distance in UV space)\n// float ringSpacing = 0.1;\n\n// // Thickness of each ripple peak\n// float ringThickness = 0.01;\n\n// // Overall ripple strength\n// float amplitude = 0.05;\n\n// // Distance from UV to the center\n// float dist = distance(uv, center);\n\n// // We compute the ripple shape by creating rings around the center at multiples of ringSpacing\n// // - sector is how far dist is from the last multiple of ringSpacing\n// // - ringDist is how far we are from the center of that ring\n// float sector = mod(dist, ringSpacing);\n// float ringDist = abs(sector - (ringSpacing * 0.5));\n\n// // Create a peak shape at the ring center\n// // wave is 1.0 near the ring center and 0.0 outside\n// float wave = 1.0 - smoothstep(0.0, ringThickness, ringDist);\n\n// // Convert wave to displacement strength\n// float offsetStrength = wave * amplitude;\n\n// // Direction outward from the center\n// vec2 direction = normalize(uv - center);\n\n// return direction * offsetStrength;\n// }\n \n vec2 warpTextureSampleUv(const vec2 uv) {\n\n float PI = acos(-1.);\n float gridSize = grid.w / 1000.;\n float strength = gridSize * .2;\n float edgeFalloff = 1.;\n\n // strength *= 50.; \n\n vec2 warpSpread = vec2(1.) * .1;\n\n float aspectRatio = resolution.x / resolution.y;\n\n vec2 offsetUV = uv + (noiseOffset * 2.);\n\n offsetUV.x *= 1.;\n offsetUV.y *= 1.2;\n\n // float noiseMask = snoise2D(offsetUV / .2) ;\n // float noiseMask2 = snoise2D(offsetUV / .18);\n // float noiseWarped = snoise2D(vec2((offsetUV.x + 1.) / .1 * noiseMask2, uv.y / 1.2 * noiseMask));\n // float noiseWarped2 = snoise2D(vec2((offsetUV.x + .8) / .25 * noiseMask2, uv.y / 1.2 * noiseMask));\n \n float freq = 10.1;\n float warpedDivisor = .5;\n\n float noiseMaskMask = smoothstep(0.95, 1., fbm(offsetUV, 1, freq * 3., 0.5));\n float noiseMask = (fbm(offsetUV, 1, freq + 0.001, 0.5) + 0.01) - fbm(offsetUV, 1, freq, 0.5);\n noiseMask *= 50.;\n noiseMask *= clamp(abs(noiseMaskMask), .5, 1e6);\n // float direction = smoothstep(-1., 1., fbm(offsetUV, 2, freq * .1, 0.5));\n\n // float noiseY = fbm(offsetUV * .5, 2, freq, 0.1);\n // float noiseX = fbm(offsetUV * .5, 3, freq/2., 0.2);\n\n float epsilon = 0.01;\n\n\n\n\n float noiseWarpedCenter = noiseLookup(offsetUV , warpedDivisor);\n float noiseWarpedY = noiseLookup(offsetUV + vec2(epsilon, 0.), warpedDivisor);\n float noiseWarpedX = noiseLookup(offsetUV + vec2(0., epsilon), warpedDivisor);\n\n // float dFdx = (noiseWarpedX - noiseWarpedCenter) / epsilon;\n // float dFdy = (noiseWarpedY - noiseWarpedCenter) / epsilon;\n\n // vec2 gradient = vec2(dFdx, dFdy);\n // gradient = vec2(-gradient.y, gradient.x);\n \n // gradient = normalize(gradient);\n\n // float projection = dot(uv, gradient);\n // float wave = sin(projection * .1); \n // gradient = vec2(-gradient.y, gradient.x);\n // float noiseWarped2 = fbm(offsetUV + vec2(freq/2.) * vec2(1.) * warpedUV, 1, freq * .5, 0.1);\n \n\n // float nNoise = snoise2D(offsetUV * .5);\n // float result = ((noiseWarped * 1.f) * (noiseWarped2 * 1.f)) * noiseMask;\n // float noiseSwirl = noiseMask;\n // float result = noiseWarped1 * 2. * PI - (PI * .5);\n\n vec2 divergence = vec2(0.);\n // divergence += vec2(cos(result), sin(result));\n // divergence += (result * strength) * noiseMask;\n divergence += noiseWarpedCenter * strength * noiseMask;\n // divergence *= screenEdgeDist(uv, edgeFalloff);\n \n // float simpleWarp = fbm(offsetUV, 6, 600.6, .9);\n\n // divergence += simpleWarp * .0003;\n\n return vec2(divergence); \n }\n\n\n const float PI = acos(-1.);\n\n const float waveWarpDivisor = 1.;\n // const int waveNoiseMapEnabled = 0;\n\n \n\n vec2 waveUv(vec2 uv) {\n\n vec2 margins = vec2(grid.marginX / resolution.x, grid.marginY / resolution.y);\n float width = grid.w / resolution.x;\n\n float lookupRemap = noiseOffset.x;\n \n // float influence = clamp(snoise2D((uv + lookupRemap)), 0.f, 1.f);\n float influence = grid.countX * wave.displacementStrength;\n \n // if(wave.noiseMapEnabled == 1)\n // influence = .9f + (influence / 10.f);\n \n float strength = (width / (waveWarpDivisor * PI) - 2.f) * (width / grid.countX) * influence;\n float sinX = sin(wave.warpXMult * PI * ((uv.x / width) + margins.x) - PI /2.) * strength;\n float sinY = sin(wave.warpYMult * PI * ((uv.y / width) + margins.y) - PI /2.) * strength;\n \n vec2 result = vec2(0.);\n \n if(wave.warpX)\n result.x += sinX;\n \n if(wave.warpY)\n result.y += sinY;\n \n if(wave.offAxisY)\n result.y += sinX;\n \n if(wave.offAxisX)\n result.x += sinY;\n \n // result.y = sin(waveWarpXMult * PI * ((uv.x + margins.y) / width)) * strength;\n // result.x = sin(waveWarpYMult * PI * ((uv.x + margins.x) / width)) * strength;\n\n return result;\n }\n\n // vec2 calculatePerspectiveOffset(vec2 uv) {\n // // Store the original UV coordinates\n // vec2 originalUv = uv;\n \n // // Define perspective depth factors\n // float perspectiveStrength = .0; // Controls the overall perspective effect\n // float tiltX = -0.3; // Controls the leftward skew\n // float tiltY = 0.2; // Controls the backward tilt\n \n // // Shift UVs to the center of the texture\n // uv -= 0.5;\n \n // // Apply perspective transformation\n // float depth = 1.0 - perspectiveStrength * (tiltX * uv.x + tiltY * uv.y);\n // uv /= depth;\n \n // // Calculate the min and max bounds of the transformed UVs\n // vec2 minBounds = vec2(-0.5) / (1.0 - perspectiveStrength * vec2(-tiltX, -tiltY));\n // vec2 maxBounds = vec2(0.5) / (1.0 - perspectiveStrength * vec2(tiltX, tiltY));\n \n // // Normalize the UV coordinates to the [0, 1] range\n // uv = (uv - minBounds) / (maxBounds - minBounds);\n \n // // Apply scaling to fill the scene\n // uv = uv * (maxBounds - minBounds);\n \n // // Calculate the offset by subtracting the original UV from the transformed and normalized UV\n // vec2 offset = uv - originalUv;\n \n // return offset;\n // }\n\n vec4 render(vec2 uv, vec2 screenSpaceUV, vec2 msaaOffset) {\n vec2 offset = uWarpEnabled ? warpTextureSampleUv(uv) : vec2(0.);\n vec2 warpedUv = waveUv(uv);\n offset += warpedUv;\n // offset += calculatePerspectiveOffset(uv);\n return(vec4(offset * 0.5 + 0.5, 0., 1.0));\n }\n\n float randomNonDet(vec2 st) {\n return fract(sin(dot(st.xy, vec2(12.9898, 78.233))) * 43758.5453123);\n }\n\n void main() {\n const vec2 H2 = vec2(0.5698402909980532f, 0.7548776662466927f);\n vec2 px = 1.f / resolution;\n px *= 1.25;\n vec2 uv = vUv;\n\n \n // Check if this fragment is within the SDF\n // vec2 uvOffset = lookupWarpSample(uv).xy;\n // float texCheck = (texture(tPolyEdgeDistance, uv + uvOffset).r - 0.5) * 2.0;\n // if(texCheck < -0.1) {\n // discard;\n // }\n\n\n const float samples = 6.f;\n \n vec4 sumColour;\n vec2 d0 = vec2(randomNonDet(uv), randomNonDet(uv + 1.f));\n\n \n for(float i = 0.f; i < samples; i++) {\n vec2 d = (fract(i * H2 + d0) - .5f);\n\n vec2 localCoord = vUv + d * px; /* changed */\n vec2 screenCoord = uTileOffset + localCoord * uTileSize; /* changed */\n vec2 globalUV = screenCoord / resolution; /* changed */\n\n // vec4 sampleColor = render(globalUV, vUv, d * px);\n vec4 sampleColor = render(globalUV, vUv, d * px);\n // sampleColor.rgb *= sampleColor.a; // Convert to premultiplied alpha\n sumColour += sampleColor;\n }\n \n vec4 averageColor = clamp(sumColour / samples, 0., 1.);\n \n outColor = averageColor;\n }\n `})}let wt="\n\n vec3 sCurve(vec3 c, float contrast, float midpoint) {\n // c in [0, 1], midpoint could be 0.5 or 0.18\n // contrast is how steep the curve is\n // A simple logistic-based S-curve\n return 1.0 / (1.2 + exp(-(c - midpoint) * contrast)) ;\n }\n\n vec4 adjustContrast(vec4 color, float factor) {\n float midpoint = 0.3; // 0.18\n // Factor is effectively the steepness of the slope\n vec3 curved = sCurve(color.rgb, factor, midpoint);\n return vec4(curved, color.a);\n }\n",kt="\n const float l2p3alpha = 1.055;\n const float l2p3beta = 0.00304;\n const float l2p3gamma = 2.4;\n const float l2p3delta = 0.055;\n\n vec3 linear2P3(vec3 linearRgb) {\n vec3 a = l2p3alpha * pow(linearRgb, vec3(1.0 / l2p3gamma)) - l2p3delta;\n vec3 b = linearRgb / 12.92;\n vec3 mask = step(vec3(l2p3beta), linearRgb);\n\n return mix(b, a, mask);\n }\n";function Rt(){return new e.ShaderMaterial({uniforms:{tTex:{value:null}},colorWrite:!0,depthWrite:!1,depthTest:!1,glslVersion:e.GLSL3,vertexShader:le,fragmentShader:`\n precision highp float;\n precision highp int;\n \n uniform highp sampler2D tTex;\n in vec2 vUv;\n out vec4 outColor;\n\n ${kt}\n ${wt}\n\n // vec4 desaturateRGBA(vec4 color, float factor) {\n // float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));\n // vec3 desaturatedColor = mix(color.rgb, vec3(gray), factor);\n // return vec4(desaturatedColor, color.a);\n // }\n\n void main() {\n vec4 color = vec4(texture2D(tTex, vUv).rgb, 1.);\n // vec4 contrasty = adjustContrast(color, 12.);\n // color = mix(color, contrasty, 0.05);\n // color = adjustBrightness(color, 1.001);\n // color *= 0.95;\n // color = desaturateRGBA(color, 0.001);\n outColor = vec4(linear2P3(vec3(color)), 1.);\n }\n `})}const Tt=Rt(),Mt=new e.ShaderMaterial({uniforms:{tTex:{value:null},uChannel:{value:0}},colorWrite:!0,depthWrite:!1,depthTest:!1,glslVersion:e.GLSL3,vertexShader:le,fragmentShader:`\n precision highp float;\n precision highp int;\n \n uniform highp sampler2D tTex;\n uniform int uChannel;\n\n in vec2 vUv;\n out vec4 outColor;\n\n // ${kt}\n // ${wt}\n\n void main() {\n vec4 color = vec4(texture2D(tTex, vUv).rgba);\n if(uChannel == -1) {\n outColor = color;\n return;\n }\n float channelColor = color[ int(uChannel) ];\n outColor = vec4(vec3(channelColor), 1.0);\n }\n `}),zt=new Xt(Tt);function Yt(e,t){zt.material=Tt,Tt.uniforms.tTex.value=e,X.setRenderTarget(t||null),zt.render(X)}class Pt{width;height;bufferIdx=0;textureCount=1;renderBuffers=[];renderBufferProps;maskEnabled=!1;constructor(t=Q,n=j,l){this.width=t,this.height=n;let i=K?e.LinearFilter:e.NearestFilter;this.renderBufferProps={anisotropy:V,minFilter:i,magFilter:i,stencilBuffer:!1,premultipliedAlpha:!0,alpha:!0,depthBuffer:!1,colorSpace:e.LinearDisplayP3ColorSpace,generateMipmaps:!1,format:e.RGBAFormat,type:e.FloatType,internalFormat:"RGBA32F",...l},this.setupFrameBuffers(),this.clearFrameBuffers(),X.autoClear=!1}setupFrameBuffers(){for(let t=0;t<2;t++)this.renderBuffers.push(new e.WebGLRenderTarget(this.width,this.height,this.renderBufferProps))}clearFrameBuffers(e=!0,t=!0,n=!0){X.setClearColor(16777215,0);const{stencil:l,color:i,depth:a}=X.state.buffers;this.renderBuffers.forEach((s=>{X.setRenderTarget(s),e&&i.setLocked(!1),t&&a.setLocked(!1),n&&l.setLocked(!1),X.clear(e,t,n)}))}enableMask(e=1){this.maskEnabled=!0;const{stencil:t}=X.state.buffers,n=X.getContext();t.setLocked(!1),t.setTest(!0),t.setFunc(n.EQUAL,e,4294967295),t.setOp(n.KEEP,n.KEEP,n.KEEP),t.setLocked(!0)}disableMask(){this.maskEnabled=!1;const{stencil:e}=X.state.buffers;e.setLocked(!1),e.setTest(!1),e.setLocked(!0)}renderMaterialAsMask(e,t=1){if(!this.renderBufferProps.stencilBuffer)throw Error("Stencil buffer not enabled in render buffer properties");const n=X.getContext(),{color:l,depth:i,stencil:a}=X.state.buffers;i.setMask(!1),i.setLocked(!0),l.setMask(!1),l.setLocked(!0),a.setLocked(!1),a.setTest(!0),a.setOp(n.KEEP,n.KEEP,n.REPLACE),a.setFunc(n.ALWAYS,t,4294967295),a.setClear(0),a.setLocked(!0),zt.material=e,X.setRenderTarget(this.getReadBuffer()),zt.render(),X.setRenderTarget(this.getWriteBuffer()),zt.render(),l.setLocked(!1),l.setMask(!0),i.setLocked(!1),i.setMask(!0)}getWriteBuffer(){return this.renderBuffers[(this.bufferIdx+1)%2]}getReadBuffer(){return this.renderBuffers[this.bufferIdx%2]}copyBufferChannelToScreen(e=0,t=this.getReadBuffer()){let n=this.maskEnabled;n&&this.disableMask(),X.setRenderTarget(null),zt.material=Mt,Mt.uniforms.tTex.value=t.texture,Mt.uniforms.uChannel.value=e,zt.render(),n&&this.enableMask()}copyBufferToBuffer(e){let t=this.maskEnabled;t&&this.disableMask(),X.setRenderTarget(e),X.copyFramebufferToTexture(this.getReadBuffer().texture),t&&this.enableMask()}copyAndSwapBuffers(){this.copyBufferToBuffer(this.getWriteBuffer()),this.bufferIdx++}copyBufferToScreen(e=this.getReadBuffer()){let t=this.maskEnabled;t&&this.disableMask(),Yt(e.texture),t&&this.enableMask()}}let Ft,Ht={},It=new Xt(null),Nt=0;class Ut{x;y;id=Nt++;hedgelist=[];constructor(e=0,t=0){this.x=e,this.y=t}sortincident(){this.hedgelist&&this.hedgelist.sort(Dt)}subtract(e){return new Ut(this.x-e.x,this.y-e.y)}addPolar(e,t){return new Ut(this.x+t*i(e),this.y+t*l(e))}normalize(e=g){const t=d(this.x*this.x+this.y*this.y);return t<e?new Ut(0,0):new Ut(this.x/t,this.y/t)}multiply(e){return new Ut(this.x*e,this.y*e)}add(e){return new Ut(this.x+e.x,this.y+e.y)}toArray(){return[this.x,this.y]}fromArray(e){return this.x=e[0],this.y=e[1],this}distanceTo(e){return d(a(e.x-this.x,2)+a(e.y-this.y,2))}angleTo(e){return Math.atan2(e.y-this.y,e.x-this.x)}lerp(e,t){return new Ut(this.x+(e.x-this.x)*t,this.y+(e.y-this.y)*t)}translate(e,t){this.x+=t*i(e),this.y+=t*l(e)}clone(){return new Ut(this.x,this.y)}isEqualTo(e,t=g){const n=e.x-this.x,l=e.y-this.y;return n*n+l*l<=t*t}isCloseTo(e,t=g){return this.distanceTo(e)<t}dispose(){this.hedgelist.length=0}}function Dt(e,t){return t.angle-e.angle}function Ot(e,t=1){if(0===t)return e;let n=Be.w/t,l=Be.h/t,i=xe(e.x,n),a=xe(e.y,l);return new Ut(i,a)}function Bt(e,t=1){return function(e){return new Ut(e.x+Be.marginX,e.y+Be.marginY)}(Ot(new Ut(e.x,e.y),t))}function Qt(e){return[e[0],e[1],e[2]*Math.PI/180]}function jt(e){return(e%360+360)%360}function Jt(e){return[Ze(e[0],0,1),Ze(e[1],0,1),jt(e[2])]}let At="\n float getPaperTexture( const vec2 screenPosition ) {\n return texture(tPaperTexture, screenPosition).x;\n }\n\n vec3 calculateNormals(vec2 uv, float offsetScale, float scale) {\n // float offsetScale = .5;\n vec2 offset = vec2(offsetScale, offsetScale);\n // float scale = 1.;\n\n float left = getPaperTexture(vec2(uv.x + offset.x, uv.y));\n float right = getPaperTexture(vec2(uv.x - offset.x, uv.y));\n float up = getPaperTexture(vec2(uv.x, uv.y + offset.y));\n float down = getPaperTexture(vec2(uv.x, uv.y - offset.y));\n\n vec3 dx = vec3(1.0, 0.0, (left - right) * scale);\n vec3 dy = vec3(0.0, 1.0, (up - down) * scale);\n\n vec3 normal = normalize(cross(dy, dx));\n\n return -normal;\n }\n\n vec3 calculateDiffuse(vec3 normal, vec3 lightDir, vec3 lightColor) {\n // Calculate the diffuse component\n float diff = max(dot(normal, lightDir), 0.0);\n float angleAttenuation = pow(diff, 1.);\n return angleAttenuation * lightColor;\n }\n",Et="\n // Partially adapted from - https://github.com/yum-food/HLSL_OKLAB/blob/main/oklab.cginc\n const mat3 m1i = mat3(vec3(1.22700842, -0.5576564, 0.28111404), vec3(-0.04047048, 1.11219073, -0.07157255), vec3(-0.07643651, -0.42138367, 1.58625265));\n const mat3 m2i = mat3(vec3(1.00003964, 0.39638005, 0.21589049), vec3(0.99998945, -0.10553958, -0.06374665), vec3(0.99999105, -0.08946276, -1.291495));\n // XYZ -> linear RGB (p3) from colorjs.io - https://github.com/color-js/color.js/blob/main/src/spaces/p3-linear.js\n const mat3 xyz_to_rgb_p3 = mat3(vec3(2.493496911941425, -0.9313836179191239, -0.40271078445071684), vec3(-0.8294889695615747, 1.7626640603183463, 0.023624685841943577), vec3(0.03584583024378447, -0.07617238926804182, 0.9568845240076872));\n\n // Functions for matrix multiplication and power, as GLSL doesn't have built-in matrix multiplication for 3x3 matrices\n vec3 mat3_mul_vec3(mat3 m, vec3 v) {\n return vec3(dot(m[0], v), dot(m[1], v), dot(m[2], v));\n }\n\n vec3 vec3_pow(vec3 v, float p) {\n return vec3(pow(v.x, p), pow(v.y, p), pow(v.z, p));\n }\n\n // Converts OKLCH color to XYZ color space\n vec3 OKLCHtoXYZ(vec3 c) {\n // Convert OKLCH to OKLAB\n float a = c.y * cos(c.z);\n float b = c.y * sin(c.z);\n vec3 oklab = vec3(c.x, a, b);\n\n // Convert OKLAB to XYZ\n oklab = mat3_mul_vec3(m2i, oklab);\n oklab = vec3_pow(oklab, 3.0);\n return mat3_mul_vec3(m1i, oklab);\n }\n\n // Converts XYZ color to linear RGB color space (p3)\n vec3 XYZtoP3LRGB(vec3 c) {\n return mat3_mul_vec3(xyz_to_rgb_p3, c);\n }\n\n // Main function to convert OKLCH to Linear RGB\n vec3 OKLCHtoP3LRGB(vec3 oklchColor) {\n vec3 xyzColor = OKLCHtoXYZ(oklchColor);\n vec3 lrgbColor = XYZtoP3LRGB(xyzColor);\n return lrgbColor;\n }\n";const _t=e=>e.map((({x:e,y:t})=>[e*D,j-t*D]));class qt{width;height;format;type;channels;texture;gl;_glFormat;_glType;_glTexture;renderer;constructor(t,n,l,i,a){if(this.width=t,this.height=n,this.format=l,this.type=i,l===e.RGBAFormat)this.channels=4;else if(l===e.RGFormat)this.channels=2;else{if(l!==e.RedFormat)throw Error("Unsupported format for PartialDataTexture.");this.channels=1}const s=t*n*this.channels,o=a||new Float32Array(s);if(o.length!==s)throw Error("Initial data length does not match texture dimensions.");this.texture=new e.DataTexture(o,t,n,l,i),this.texture.needsUpdate=!0,this.gl=null,this._glFormat=null,this._glType=null,this._glTexture=null}setRenderer(t){this.renderer=t;const n=t.getContext();if(this.gl=n,this.format===e.RGBAFormat)this._glFormat=n.RGBA;else if(this.format===e.RGFormat)this._glFormat=n.RG;else{if(this.format!==e.RedFormat)throw Error("Unsupported format for PartialDataTexture.");this._glFormat=n.RED}if(this.type!==e.FloatType)throw Error("PartialDataTexture currently only supports Float32 data type.");this._glType=n.FLOAT,t.initTexture(this.texture);const l=t.properties.get(this.texture);this._glTexture=l.__webglTexture}uploadSubData(e){if(!this.gl||!this._glTexture)throw Error("Renderer not set or texture not initialized. Call setRenderer() before updating.");const t=this.gl,n=Math.floor(e/this.channels);if(n<=0)return;const l=this.width*this.height,i=Math.min(n,l),a=Math.floor(i/this.width),s=i%this.width,o=this.texture.image.data,r=t.getParameter(t.TEXTURE_BINDING_2D);if(t.bindTexture(t.TEXTURE_2D,this._glTexture),a>0){const e=o.subarray(0,a*this.width*this.channels);t.texSubImage2D(t.TEXTURE_2D,0,0,0,this.width,a,this._glFormat,this._glType,e)}if(s>0){const e=a*this.width*this.channels,n=o.subarray(e,e+s*this.channels);t.texSubImage2D(t.TEXTURE_2D,0,0,a,s,1,this._glFormat,this._glType,n)}t.bindTexture(t.TEXTURE_2D,r)}}function $t(e,t){const n=t[0]-e[0],l=t[1]-e[1];return d(n*n+l*l)}class en{polyLines=[];isClosed;cellSize;cellsWide;cellsHigh;_segmentRecords;_cellCounts;_cellOffsets;_indexData;segmentDataTexture;segmentIndexTexture;segmentMetaDataTexture;texturesInitialised=!1;constructor(e=1){this.cellSize=e}initializeTextures(){const n=o(C,2048);this.segmentDataTexture={texture:new qt(n,n,e.RGBAFormat,e.FloatType,new Float32Array(n*n*4)),width:n,height:n},this.segmentDataTexture.texture.setRenderer(X),t