MeasurementArrow.glsl.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. See https://js.arcgis.com/4.25/esri/copyright.txt for details.
  4. */
  5. import{addProjViewLocalOrigin as e}from"../views/3d/webgl-engine/core/shaderLibrary/util/View.glsl.js";import{Float4PassUniform as o}from"../views/3d/webgl-engine/core/shaderModules/Float4PassUniform.js";import{FloatPassUniform as t}from"../views/3d/webgl-engine/core/shaderModules/FloatPassUniform.js";import{glsl as r}from"../views/3d/webgl-engine/core/shaderModules/interfaces.js";import{ShaderBuilder as i}from"../views/3d/webgl-engine/core/shaderModules/ShaderBuilder.js";import{VertexAttribute as d}from"../views/3d/webgl-engine/lib/VertexAttribute.js";function n(n){const s=new i,{vertex:a,fragment:l}=s;e(a,n),a.uniforms.add(new t("width",(e=>e.width))),s.attributes.add(d.POSITION,"vec3"),s.attributes.add(d.NORMAL,"vec3"),s.attributes.add(d.UV0,"vec2"),s.attributes.add(d.AUXPOS1,"float"),s.varyings.add("vtc","vec2"),s.varyings.add("vlength","float"),s.varyings.add("vradius","float"),a.code.add(r`void main(void) {
  6. vec3 bitangent = normal;
  7. vtc = uv0;
  8. vlength = auxpos1;
  9. vradius = 0.5 * width;
  10. vec4 pos = view * vec4(position + vradius * bitangent * uv0.y, 1.0);
  11. gl_Position = proj * pos;
  12. }`),l.uniforms.add([new t("outlineSize",(e=>e.outlineSize)),new o("outlineColor",(e=>e.outlineColor)),new t("stripeLength",(e=>e.stripeLength)),new o("stripeEvenColor",(e=>e.stripeEvenColor)),new o("stripeOddColor",(e=>e.stripeOddColor))]);const v=1/Math.sqrt(2);return l.code.add(r`
  13. const float INV_SQRT2 = ${r.float(v)};
  14. vec4 arrowColor(vec2 tc, float len) {
  15. float d = INV_SQRT2 * (tc.x - abs(tc.y));
  16. d = min(d, INV_SQRT2 * (len - tc.x - abs(tc.y)));
  17. d = min(d, 1.0 - abs(tc.y));
  18. if (d < 0.0) {
  19. return vec4(0.0);
  20. } else if (d < outlineSize) {
  21. return outlineColor;
  22. } else {
  23. return fract(0.5 / stripeLength * tc.x * vradius) >= 0.5 ? stripeOddColor : stripeEvenColor;
  24. }
  25. }
  26. void main(void) {
  27. vec2 ntc = vec2(vtc.x / vradius, vtc.y);
  28. vec4 color = arrowColor(ntc, vlength / vradius);
  29. if (color.a == 0.0) {
  30. discard;
  31. }
  32. gl_FragColor = color;
  33. }
  34. `),s}const s=Object.freeze(Object.defineProperty({__proto__:null,build:n},Symbol.toStringTag,{value:"Module"}));export{s as M,n as b};