/*
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/vec3","../../../../../../chunks/vec3f64","../ShaderOutputOptions","../util/DoublePrecision.glsl","../../shaderModules/Float3DrawUniform","../../shaderModules/interfaces","../../shaderModules/Matrix4PassUniform","../../../lib/VertexAttribute","../../../../../webgl/doublePrecisionUtils"],(function(e,r,i,n,a,t,o,s,l,c){"use strict";function d(e,i){i.instanced&&i.instancedDoublePrecision&&(e.attributes.add(l.VertexAttribute.MODELORIGINHI,"vec3"),e.attributes.add(l.VertexAttribute.MODELORIGINLO,"vec3"),e.attributes.add(l.VertexAttribute.MODEL,"mat3"),e.attributes.add(l.VertexAttribute.MODELNORMAL,"mat3"));const d=e.vertex;i.instancedDoublePrecision&&(d.include(a.DoublePrecision,i),d.uniforms.add(new t.Float3DrawUniform("viewOriginHi",((e,i)=>c.encodeDoubleHi(r.set(u,i.camera.viewInverseTransposeMatrix[3],i.camera.viewInverseTransposeMatrix[7],i.camera.viewInverseTransposeMatrix[11]),u)))),d.uniforms.add(new t.Float3DrawUniform("viewOriginLo",((e,i)=>c.encodeDoubleLo(r.set(u,i.camera.viewInverseTransposeMatrix[3],i.camera.viewInverseTransposeMatrix[7],i.camera.viewInverseTransposeMatrix[11]),u))))),d.code.add(o.glsl`
    vec3 calculateVPos() {
      ${i.instancedDoublePrecision?"return model * localPosition().xyz;":"return localPosition().xyz;"}
    }
    `),d.code.add(o.glsl`
    vec3 subtractOrigin(vec3 _pos) {
      ${i.instancedDoublePrecision?o.glsl`
          vec3 originDelta = dpAdd(viewOriginHi, viewOriginLo, -modelOriginHi, -modelOriginLo);
          return _pos - originDelta;`:"return vpos;"}
    }
    `),d.code.add(o.glsl`
    vec3 dpNormal(vec4 _normal) {
      ${i.instancedDoublePrecision?"return normalize(modelNormal * _normal.xyz);":"return normalize(_normal.xyz);"}
    }
    `),i.output===n.ShaderOutput.Normal&&(d.uniforms.add(new s.Matrix4PassUniform("viewNormal",((e,r)=>r.camera.viewInverseTransposeMatrix))),d.code.add(o.glsl`
    vec3 dpNormalView(vec4 _normal) {
      ${i.instancedDoublePrecision?"return normalize((viewNormal * vec4(modelNormal * _normal.xyz, 1.0)).xyz);":"return normalize((viewNormal * _normal).xyz);"}
    }
    `)),i.hasVertexTangents&&d.code.add(o.glsl`
    vec4 dpTransformVertexTangent(vec4 _tangent) {
      ${i.instancedDoublePrecision?"return vec4(modelNormal * _tangent.xyz, _tangent.w);":"return _tangent;"}

    }
    `)}const u=i.create();e.InstancedDoublePrecision=d,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
