/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{create as r}from"../../../../../../core/libs/gl-matrix-2/factories/mat3f64.js";import{create as o}from"../../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{DoublePrecision as e}from"../util/DoublePrecision.glsl.js";import{Float3DrawUniform as a}from"../../shaderModules/Float3DrawUniform.js";import{Float3PassUniform as t}from"../../shaderModules/Float3PassUniform.js";import{If as i,glsl as m}from"../../shaderModules/glsl.js";import{Matrix3DrawUniform as s}from"../../shaderModules/Matrix3DrawUniform.js";import{Matrix3PassUniform as d}from"../../shaderModules/Matrix3PassUniform.js";import{Matrix4BindUniform as l}from"../../shaderModules/Matrix4BindUniform.js";import{NoParameters as n}from"../../../../../webgl/NoParameters.js";function f(r,o){const{attributes:n,vertex:f,varyings:v,fragment:W}=r;f.include(e,o),n.add("position","vec3"),v.add("vPositionWorldCameraRelative","vec3"),v.add("vPosition_view","vec3",{invariant:!0}),f.uniforms.add(new t("transformWorldFromViewTH",r=>r.transformWorldFromViewTH),new t("transformWorldFromViewTL",r=>r.transformWorldFromViewTL),new d("transformViewFromCameraRelativeRS",r=>r.transformViewFromCameraRelativeRS),new l("transformProjFromView",r=>r.camera.projectionMatrix),new a("transformWorldFromModelTH",r=>r.transformWorldFromModelTH),new a("transformWorldFromModelTL",r=>r.transformWorldFromModelTL));const{hasModelRotationScale:c}=o;c&&f.uniforms.add(new s("transformWorldFromModelRS",r=>r.transformWorldFromModelRS)),f.code.add(m`
      vec3 positionWorldCameraRelative() {
      vec3 rotatedModelPosition = ${i(c,m`transformWorldFromModelRS * `)} position;

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

      return transform_CameraRelativeFromModel + rotatedModelPosition;
    }
  `),f.code.add(m`
    void forwardPosition(float fOffset) {
      vPositionWorldCameraRelative = positionWorldCameraRelative();
      if (fOffset != 0.0) {
        vPositionWorldCameraRelative += fOffset * ${o.spherical?m`normalize(transformWorldFromViewTL + vPositionWorldCameraRelative)`:m`vec3(0.0, 0.0, 1.0)`};
      }

      vPosition_view = transformViewFromCameraRelativeRS * vPositionWorldCameraRelative;
      gl_Position = transformProjFromView * vec4(vPosition_view, 1.0);
    }
  `),W.uniforms.add(new t("transformWorldFromViewTL",r=>r.transformWorldFromViewTL)),f.code.add(m`vec3 positionWorld() {
return transformWorldFromViewTL + vPositionWorldCameraRelative;
}`),W.code.add(m`vec3 positionWorld() {
return transformWorldFromViewTL + vPositionWorldCameraRelative;
}`)}class v extends n{constructor(){super(...arguments),this.transformWorldFromViewTH=o(),this.transformWorldFromViewTL=o(),this.transformViewFromCameraRelativeRS=r()}}class W extends n{constructor(){super(...arguments),this.transformWorldFromModelRS=r(),this.transformWorldFromModelTH=o(),this.transformWorldFromModelTL=o()}}export{f as VertexPosition,W as VertexPositionDrawParameters,v as VertexPositionPassParameters};
