/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../../../chunks/_rollupPluginBabelHelpers","../../../../../../chunks/vec4f64","../../../../../../geometry/support/aaBoundingRect","../../../../terrain/interfaces","../../renderPasses/AllRenderPasses","../shading/PhysicallyBasedRenderingParameters.glsl","../shading/Water.glsl","../../shaderModules/Float3PassUniform","../../shaderModules/Float4DrawUniform","../../shaderModules/Float4Uniform","../../shaderModules/FloatPassUniform","../../shaderModules/interfaces","../../shaderModules/Texture2DPassUniform"],(function(e,o,r,a,t,n,l,i,s,d,v,c,u,y){"use strict";var f;e.OverlayMode=void 0,(f=e.OverlayMode||(e.OverlayMode={}))[f.Disabled=0]="Disabled",f[f.Enabled=1]="Enabled",f[f.EnabledWithWater=2]="EnabledWithWater",f[f.COUNT=3]="COUNT";let g=function(e){function r(){var o;return(o=e.apply(this,arguments)||this).overlayOpacity=1,o}return o._inheritsLoose(r,e),r}(u.NoParameters);function x(e,o){e.vertex.uniforms.add([new v.Float4Uniform("overlayTexOffset"),new v.Float4Uniform("overlayTexScale")]),e.fragment.uniforms.add([new c.FloatPassUniform("overlayOpacity",(e=>e.overlayOpacity)),new y.Texture2DPassUniform("ovColorTex",((e,o)=>0===o.overlays.length?null:o.overlays[t.OverlayIndex.INNER].getColorTexture(e.overlaySource)))]),p(e,o)}function h(e,o){const{vertex:r,fragment:a}=e;r.uniforms.add([new d.Float4DrawUniform("overlayTexOffset",((e,o)=>M(e,o))),new d.Float4DrawUniform("overlayTexScale",((e,o)=>O(e,o)))]),a.constants.add("overlayOpacity","float",1),a.uniforms.add(new y.Texture2DPassUniform("ovColorTex",((e,o)=>m(e,o)))),p(e,o)}function p(e,o){e.extensions.add("GL_OES_standard_derivatives"),o.pbrMode!==l.PBRMode.Water&&o.pbrMode!==l.PBRMode.WaterOnIntegratedMesh||e.include(i.Water,o);const{vertex:r,fragment:a}=e;e.varyings.add("vtcOverlay","vec4"),r.code.add(u.glsl`void setOverlayVTC(in vec2 uv) {
vtcOverlay = vec4(uv, uv) * overlayTexScale + overlayTexOffset;
}`),a.code.add(u.glsl`bool isValid(vec2 uv, vec2 dxdy) {
return (uv.x >= 0.0 + dxdy.x) && (uv.x <= 1.0 - dxdy.x) && (uv.y >= 0.0 + dxdy.y) && (uv.y <= 1.0 - dxdy.y);
}
vec4 getOverlayColor(sampler2D ov0Tex, vec4 texCoords) {
vec4 color0 = texture2D(ov0Tex, vec2(texCoords.x * 0.5, texCoords.y));
vec4 color1 = texture2D(ov0Tex, vec2(texCoords.z * 0.5 + 0.5, texCoords.w));
bool isValid0 = isValid(texCoords.xy, fwidth(texCoords.xy));
bool isValid1 = isValid(texCoords.zw, vec2(0.0, 0.0));
return mix(color1 * float(isValid1), color0, float(isValid0));
}`),a.code.add(u.glsl`vec4 getCombinedOverlayColor() {
return overlayOpacity * getOverlayColor(ovColorTex, vtcOverlay);
}`),o.pbrMode!==l.PBRMode.Water&&o.pbrMode!==l.PBRMode.WaterOnIntegratedMesh||(a.uniforms.add([new s.Float3PassUniform("lightingMainDirection",((e,o)=>o.lighting.lightingMainDirection)),new s.Float3PassUniform("lightingMainIntensity",((e,o)=>o.lighting.mainLight.intensity))]),a.code.add(u.glsl`vec4 getOverlayWaterColor(vec4 maskInput, vec4 colorInput, vec3 vposEyeDir,
float shadow, vec3 localUp, mat3 tbn, vec3 position, vec3 positionWorld) {
vec3 n = normalize(tbn *  (2.0 * maskInput.rgb - vec3(1.0)));
vec3 v = vposEyeDir;
vec3 final = getSeaColor(n, v, lightingMainDirection, colorInput.rgb, lightingMainIntensity, localUp, 1.0 - shadow, maskInput.w, position, positionWorld);
return vec4(final, colorInput.w);
}`))}function m(e,o){return 0===o.overlays.length?null:e.identifier===n.RenderPassIdentifier.Material&&e.subPass===n.MaterialSubPass.Color?o.overlays[t.OverlayIndex.INNER].getColorTextureNoRasterImage():e.identifier===n.RenderPassIdentifier.Highlight?o.overlays[t.OverlayIndex.INNER].getValidTexture(t.RenderTargetType.Highlight):null}function M(e,o){for(const r of o.overlays){const{index:o,extent:t}=r;a.area(t)>0&&(T[2*o]=e.toMapSpace[0]/a.width(t)-t[0]/a.width(t),T[2*o+1]=e.toMapSpace[1]/a.height(t)-t[1]/a.height(t))}return T}function O(e,o){for(const r of o.overlays){const{index:o,extent:t}=r;a.area(t)>0&&(T[2*o]=e.toMapSpace[2]/a.width(t),T[2*o+1]=e.toMapSpace[3]/a.height(t))}return T}const T=r.create();e.OverlayIM=h,e.OverlayTerrain=x,e.OverlayTerrainPassParameters=g,e.getColorTexture=m,e.overlay=p,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
