/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../collections/Component/Material/shader/ComponentData.glsl","../../../core/shaderLibrary/util/DoublePrecision.glsl","../../../core/shaderLibrary/util/RgbaFloatEncoding.glsl","../../../core/shaderModules/Float2Uniform","../../../core/shaderModules/Float3DrawUniform","../../../core/shaderModules/Float3PassUniform","../../../core/shaderModules/FloatPassUniform","../../../core/shaderModules/interfaces","../../../core/shaderModules/Matrix3DrawUniform","../../../core/shaderModules/Matrix3PassUniform","../../../core/shaderModules/Matrix4PassUniform","../../../core/shaderModules/Texture2DUniform","../../../lib/VertexAttribute"],(function(o,e,t,r,a,l,n,d,i,s,c,m,f,u){"use strict";function v(o,v){const x=o.vertex;x.include(r.RgbaFloatEncoding),x.uniforms.add(new d.FloatPassUniform("distanceFalloffFactor",(o=>o.distanceFalloffFactor))),x.code.add(i.glsl`float distanceBasedPerspectiveFactor(float distance) {
return clamp(sqrt(distanceFalloffFactor / distance), 0.0, 1.0);
}`),x.uniforms.add(new f.Texture2DUniform("componentDataTex")),x.uniforms.add(new a.Float2Uniform("componentDataTexInvDim")),o.attributes.add(u.VertexAttribute.COMPONENTINDEX,"float"),x.constants.add("componentColorFieldOffset","float",0),x.constants.add("componentOtherFieldOffset","float",1),x.constants.add("componentVerticalOffsetFieldOffset","float",2),x.constants.add("componentFieldCount","float",3),x.constants.add("lineWidthFractionFactor","float",8),x.constants.add("extensionLengthOffset","float",128),x.constants.add("componentTexWidth","float",4096),x.constants.add("verticalOffsetScale","float",2*e.MAX_ELEVATION_OFFSET),x.code.add(i.glsl`vec2 _componentTextureCoords(float componentIndex, float fieldOffset) {
float fieldIndex = componentFieldCount * componentIndex + fieldOffset;
float rowIndex = floor(fieldIndex / componentTexWidth);
float colIndex = mod(fieldIndex, componentTexWidth);
vec2 linearIndex = vec2(
(colIndex + 0.5) / componentTexWidth,
(rowIndex + 0.5) * componentDataTexInvDim.y
);
return linearIndex;
}
struct ComponentData {
vec4 color;
float lineWidth;
float extensionLength;
float type;
float verticalOffset;
};
ComponentData readComponentData() {
vec2 colorIndex = _componentTextureCoords(componentIndex, componentColorFieldOffset);
vec2 otherIndex = _componentTextureCoords(componentIndex, componentOtherFieldOffset);
vec2 verticalOffsetIndex = _componentTextureCoords(componentIndex, componentVerticalOffsetFieldOffset);
vec4 colorValue = texture2D(componentDataTex, colorIndex);
vec4 otherValue = texture2D(componentDataTex, otherIndex);
float verticalOffset = (rgba2float(texture2D(componentDataTex, verticalOffsetIndex)) - 0.5) * verticalOffsetScale;
return ComponentData(
vec4(colorValue.rgb, colorValue.a * otherValue.w),
otherValue.x * (255.0 / lineWidthFractionFactor),
otherValue.y * 255.0 - extensionLengthOffset,
-(otherValue.z * 255.0) + 0.5,
verticalOffset
);
}`),v.legacy?x.code.add(i.glsl`vec3 _modelToWorldNormal(vec3 normal) {
return (model * vec4(normal, 0.0)).xyz;
}
vec3 _modelToViewNormal(vec3 normal) {
return (localView * model * vec4(normal, 0.0)).xyz;
}`):(x.uniforms.add(new s.Matrix3DrawUniform("transformNormalGlobalFromModel",(o=>o.transformNormalGlobalFromModel))),x.code.add(i.glsl`vec3 _modelToWorldNormal(vec3 normal) {
return transformNormalGlobalFromModel * normal;
}`)),v.silhouette?(o.attributes.add(u.VertexAttribute.NORMALA,"vec3"),o.attributes.add(u.VertexAttribute.NORMALB,"vec3"),x.code.add(i.glsl`vec3 worldNormal() {
return _modelToWorldNormal(normalize(normalA + normalB));
}`)):(o.attributes.add(u.VertexAttribute.NORMAL,"vec3"),x.code.add(i.glsl`vec3 worldNormal() {
return _modelToWorldNormal(normal);
}`)),v.legacy?x.code.add(i.glsl`void worldAndViewFromModelPosition(vec3 modelPos, float verticalOffset, out vec3 worldPos, out vec3 viewPos) {
worldPos = (model * vec4(modelPos, 1.0)).xyz;
viewPos = (localView * vec4(worldPos, 1.0)).xyz;
}`):(x.include(t.DoublePrecision,v),x.include(t.DoublePrecision,v),x.uniforms.add([new c.Matrix3PassUniform("transformViewFromCameraRelativeRS",(o=>o.transformViewFromCameraRelativeRS)),new s.Matrix3DrawUniform("transformWorldFromModelRS",(o=>o.transformWorldFromModelRS)),new l.Float3DrawUniform("transformWorldFromModelTL",(o=>o.transformWorldFromModelTL)),new l.Float3DrawUniform("transformWorldFromModelTH",(o=>o.transformWorldFromModelTH)),new n.Float3PassUniform("transformWorldFromViewTL",(o=>o.transformWorldFromViewTL)),new n.Float3PassUniform("transformWorldFromViewTH",(o=>o.transformWorldFromViewTH))]),x.code.add(i.glsl`
      void worldAndViewFromModelPosition(vec3 modelPos, float verticalOffset, out vec3 worldPos, out vec3 viewPos) {
        vec3 rotatedModelPosition = transformWorldFromModelRS * modelPos;

        vec3 transformCameraRelativeFromModel = dpAdd(
          transformWorldFromModelTL,
          transformWorldFromModelTH,
          -transformWorldFromViewTL,
          -transformWorldFromViewTH
        );

        worldPos = transformCameraRelativeFromModel + rotatedModelPosition;

        if (verticalOffset != 0.0) {
          vec3 vUp = ${v.spherical?i.glsl`normalize(transformWorldFromModelTL + rotatedModelPosition);`:i.glsl`vec3(0.0, 0.0, 1.0);`}
          worldPos += verticalOffset * vUp;
        }

        viewPos = transformViewFromCameraRelativeRS * worldPos;
      }
    `)),x.uniforms.add(new m.Matrix4PassUniform("transformProjFromView",((o,e)=>e.camera.projectionMatrix))),x.code.add(i.glsl`vec4 projFromViewPosition(vec3 position) {
return transformProjFromView * vec4(position, 1.0);
}`),x.code.add(i.glsl`float calculateExtensionLength(float extensionLength, float lineLength) {
return extensionLength / (log2(max(1.0, 256.0 / lineLength)) * 0.2 + 1.0);
}`)}function x(e){return e.mode===o.EdgeUtilMode.SKETCH||e.mode===o.EdgeUtilMode.MIXED}function F(e){return e.mode===o.EdgeUtilMode.SOLID||e.mode===o.EdgeUtilMode.MIXED}var M;o.EdgeUtilMode=void 0,(M=o.EdgeUtilMode||(o.EdgeUtilMode={}))[M.SOLID=0]="SOLID",M[M.SKETCH=1]="SKETCH",M[M.MIXED=2]="MIXED",M[M.COUNT=3]="COUNT",o.EdgeUtil=v,o.usesSketchLogic=x,o.usesSolidLogic=F,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
