NativeLine.glsl.js 4.0 KB

12345678910111213141516171819202122232425262728293031323334
  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{ShaderOutput as e}from"../views/3d/webgl-engine/core/shaderLibrary/ShaderOutput.js";import{SliceDraw as o}from"../views/3d/webgl-engine/core/shaderLibrary/Slice.glsl.js";import{Transform as i}from"../views/3d/webgl-engine/core/shaderLibrary/Transform.glsl.js";import{VertexColor as r}from"../views/3d/webgl-engine/core/shaderLibrary/attributes/VertexColor.glsl.js";import{OutputHighlight as t}from"../views/3d/webgl-engine/core/shaderLibrary/output/OutputHighlight.glsl.js";import{LineStipple as l,computePixelSize as s}from"../views/3d/webgl-engine/core/shaderLibrary/shading/LineStipple.glsl.js";import{symbolAlphaCutoff as n}from"../views/3d/webgl-engine/core/shaderLibrary/util/AlphaCutoff.js";import{addProjViewLocalOrigin as a}from"../views/3d/webgl-engine/core/shaderLibrary/util/View.glsl.js";import{Float4PassUniform as d}from"../views/3d/webgl-engine/core/shaderModules/Float4PassUniform.js";import{FloatPassUniform as p}from"../views/3d/webgl-engine/core/shaderModules/FloatPassUniform.js";import{glsl as c}from"../views/3d/webgl-engine/core/shaderModules/interfaces.js";import{ShaderBuilder as g}from"../views/3d/webgl-engine/core/shaderModules/ShaderBuilder.js";import{VertexAttribute as m}from"../views/3d/webgl-engine/lib/VertexAttribute.js";function u(u){const v=new g,{vertex:h,fragment:w}=v;return v.include(i,u),v.include(r,u),v.include(l,u),a(h,u),u.stippleEnabled&&(v.attributes.add(m.UV0,"vec2"),v.attributes.add(m.AUXPOS1,"vec3"),h.uniforms.add(new d("viewport",((e,o)=>o.camera.fullViewport)))),v.attributes.add(m.POSITION,"vec3"),v.varyings.add("vpos","vec3"),h.code.add(c`void main(void) {
  6. vpos = position;
  7. forwardNormalizedVertexColor();
  8. gl_Position = transformPosition(proj, view, vpos);`),u.stippleEnabled&&(h.code.add(c`vec4 vpos2 = transformPosition(proj, view, auxpos1);
  9. vec2 ndcToPixel = viewport.zw * 0.5;
  10. float lineSegmentPixelSize = length((vpos2.xy / vpos2.w - gl_Position.xy / gl_Position.w) * ndcToPixel);`),u.draped?h.uniforms.add(new p("worldToScreenRatio",((e,o)=>1/o.screenToPCSRatio))):h.code.add(c`vec3 segmentCenter = (position + auxpos1) * 0.5;
  11. float worldToScreenRatio = computeWorldToScreenRatio(segmentCenter);`),h.code.add(c`float discreteWorldToScreenRatio = discretizeWorldToScreenRatio(worldToScreenRatio);`),u.draped?h.code.add(c`float startPseudoScreen = uv0.y * discreteWorldToScreenRatio - mix(0.0, lineSegmentPixelSize, uv0.x);
  12. float segmentLengthPseudoScreen = lineSegmentPixelSize;`):h.code.add(c`float segmentLengthRender = length(position - auxpos1);
  13. float startPseudoScreen = mix(uv0.y, uv0.y - segmentLengthRender, uv0.x) * discreteWorldToScreenRatio;
  14. float segmentLengthPseudoScreen = segmentLengthRender * discreteWorldToScreenRatio;`),h.uniforms.add(new p("stipplePatternPixelSize",(e=>s(e)))),h.code.add(c`vec2 stippleDistanceLimits = computeStippleDistanceLimits(startPseudoScreen, segmentLengthPseudoScreen, lineSegmentPixelSize, stipplePatternPixelSize);
  15. vStippleDistance = mix(stippleDistanceLimits.x, stippleDistanceLimits.y, uv0.x);
  16. vStippleDistance *= gl_Position.w;`)),h.code.add(c`}`),u.output===e.Highlight&&v.include(t,u),v.include(o,u),w.uniforms.add(new p("alphaCoverage",((e,o)=>Math.min(1,e.width*o.camera.pixelRatio)))),u.hasVertexColors||w.uniforms.add(new d("constantColor",(e=>e.color))),w.code.add(c`
  17. void main() {
  18. discardBySlice(vpos);
  19. vec4 color = ${u.hasVertexColors?"vColor":"constantColor"};
  20. float stippleAlpha = getStippleAlpha();
  21. discardByStippleAlpha(stippleAlpha, stippleAlphaColorDiscard);
  22. vec4 finalColor = blendStipple(vec4(color.rgb, color.a * alphaCoverage), stippleAlpha);
  23. if (finalColor.a < ${c.float(n)}) {
  24. discard;
  25. }
  26. ${u.output===e.Color?c`gl_FragColor = highlightSlice(finalColor, vpos);`:""}
  27. ${u.output===e.Highlight?c`outputHighlight();`:""}
  28. }
  29. `),v}const v=Object.freeze(Object.defineProperty({__proto__:null,build:u},Symbol.toStringTag,{value:"Module"}));export{v as N,u as b};