UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

66 lines (65 loc) • 8.46 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{deg2rad as e}from"../core/mathUtils.js";import{set as i}from"../core/libs/gl-matrix-2/math/vec2.js";import{create as t}from"../core/libs/gl-matrix-2/factories/vec2f64.js";import{t as n,d as a,n as o,l as r,j as l,c as s,h as c,f as d}from"./vec32.js";import{create as f}from"../core/libs/gl-matrix-2/factories/vec3f64.js";import{t as p}from"./vec42.js";import{create as g}from"../core/libs/gl-matrix-2/factories/vec4f64.js";import{pointAt as h}from"../geometry/support/lineSegment.js";import{fromPositionAndNormal as m,create as u}from"../geometry/support/plane.js";import{a as w,c as x}from"./sphere.js";import{Laserline as v}from"../views/3d/webgl-engine/core/shaderLibrary/Laserline.glsl.js";import{ScreenSpacePass as P}from"../views/3d/webgl-engine/core/shaderLibrary/ScreenSpacePass.glsl.js";import{Float2PassUniform as b}from"../views/3d/webgl-engine/core/shaderModules/Float2PassUniform.js";import{Float3BindUniform as D}from"../views/3d/webgl-engine/core/shaderModules/Float3BindUniform.js";import{Float3PassUniform as M}from"../views/3d/webgl-engine/core/shaderModules/Float3PassUniform.js";import{Float4PassUniform as S}from"../views/3d/webgl-engine/core/shaderModules/Float4PassUniform.js";import{FloatBindUniform as C}from"../views/3d/webgl-engine/core/shaderModules/FloatBindUniform.js";import{FloatPassUniform as L}from"../views/3d/webgl-engine/core/shaderModules/FloatPassUniform.js";import{glsl as j}from"../views/3d/webgl-engine/core/shaderModules/glsl.js";import{ShaderBuilder as A}from"../views/webgl/ShaderBuilder.js";const V=e(6);function y(e){const i=new A;i.include(P),i.include(v,e);const t=i.fragment;if(e.lineVerticalPlaneEnabled||e.heightManifoldEnabled)if(t.uniforms.add(new L("maxPixelDistance",((i,t)=>e.heightManifoldEnabled?2*t.camera.computeScreenPixelSizeAt(i.heightManifoldTarget):2*t.camera.computeScreenPixelSizeAt(i.lineVerticalPlaneSegment.origin)))),t.code.add(j`float planeDistancePixels(vec4 plane, vec3 pos) { float dist = dot(plane.xyz, pos) + plane.w; float width = fwidth(dist); dist /= min(width, maxPixelDistance); return abs(dist); }`),e.spherical){const e=(e,i,t)=>n(e,i.heightManifoldTarget,t.camera.viewMatrix),i=(e,i)=>n(e,[0,0,0],i.camera.viewMatrix);t.uniforms.add(new S("heightManifoldOrigin",((t,n)=>(e(F,t,n),i(H,n),a(H,H,F),o(G,H),G[3]=r(H),G))),new D("globalOrigin",(e=>i(F,e))),new L("cosSphericalAngleThreshold",((e,i)=>1-Math.max(2,l(i.camera.eye,e.heightManifoldTarget)*i.camera.perRenderPixelRatio)/r(e.heightManifoldTarget)))),t.code.add(j`float globeDistancePixels(float posInGlobalOriginLength) { float dist = abs(posInGlobalOriginLength - heightManifoldOrigin.w); float width = fwidth(dist); dist /= min(width, maxPixelDistance); return abs(dist); } float heightManifoldDistancePixels(vec4 heightPlane, vec3 pos) { vec3 posInGlobalOriginNorm = normalize(globalOrigin - pos); float cosAngle = dot(posInGlobalOriginNorm, heightManifoldOrigin.xyz); vec3 posInGlobalOrigin = globalOrigin - pos; float posInGlobalOriginLength = length(posInGlobalOrigin); float sphericalDistance = globeDistancePixels(posInGlobalOriginLength); float planarDistance = planeDistancePixels(heightPlane, pos); return cosAngle < cosSphericalAngleThreshold ? sphericalDistance : planarDistance; }`)}else t.code.add(j`float heightManifoldDistancePixels(vec4 heightPlane, vec3 pos) { return planeDistancePixels(heightPlane, pos); }`);if(e.pointDistanceEnabled&&(t.uniforms.add(new L("maxPixelDistance",((e,i)=>2*i.camera.computeScreenPixelSizeAt(e.pointDistanceTarget)))),t.code.add(j`float sphereDistancePixels(vec4 sphere, vec3 pos) { float dist = distance(sphere.xyz, pos) - sphere.w; float width = fwidth(dist); dist /= min(width, maxPixelDistance); return abs(dist); }`)),e.intersectsLineEnabled&&t.uniforms.add(new C("perScreenPixelRatio",(e=>e.camera.perScreenPixelRatio))).code.add(j`float lineDistancePixels(vec3 start, vec3 dir, float radius, vec3 pos) { float dist = length(cross(dir, pos - start)) / (length(pos) * perScreenPixelRatio); return abs(dist) - radius; }`),(e.lineVerticalPlaneEnabled||e.intersectsLineEnabled)&&t.code.add(j`bool pointIsWithinLine(vec3 pos, vec3 start, vec3 end) { vec3 dir = end - start; float t2 = dot(dir, pos - start); float l2 = dot(dir, dir); return t2 >= 0.0 && t2 <= l2; }`),t.main.add(j`vec3 pos; vec3 normal; float angleCutoffAdjust; float depthDiscontinuityAlpha; if (!laserlineReconstructFromDepth(pos, normal, angleCutoffAdjust, depthDiscontinuityAlpha)) { fragColor = vec4(0.0); return; } vec4 color = vec4(0.0);`),e.heightManifoldEnabled){t.uniforms.add(new b("angleCutoff",(e=>O(e))),new S("heightPlane",((e,i)=>R(e.heightManifoldTarget,e.renderCoordsHelper.worldUpAtPosition(e.heightManifoldTarget,F),i.camera.viewMatrix))));const i=e.spherical?j`normalize(globalOrigin - pos)`:j`heightPlane.xyz`;t.main.add(j` vec2 angleCutoffAdjusted = angleCutoff - angleCutoffAdjust; // Fade out laserlines on flat surfaces float heightManifoldAlpha = 1.0 - smoothstep(angleCutoffAdjusted.x, angleCutoffAdjusted.y, abs(dot(normal, ${i}))); vec4 heightManifoldColor = laserlineProfile(heightManifoldDistancePixels(heightPlane, pos)); color = max(color, heightManifoldColor * heightManifoldAlpha);`)}return e.pointDistanceEnabled&&(t.uniforms.add(new b("angleCutoff",(e=>O(e))),new S("pointDistanceSphere",((e,i)=>E(e,i)))),t.main.add(j`float pointDistanceSphereDistance = sphereDistancePixels(pointDistanceSphere, pos); vec4 pointDistanceSphereColor = laserlineProfile(pointDistanceSphereDistance); float pointDistanceSphereAlpha = 1.0 - smoothstep(angleCutoff.x, angleCutoff.y, abs(dot(normal, normalize(pos - pointDistanceSphere.xyz)))); color = max(color, pointDistanceSphereColor * pointDistanceSphereAlpha);`)),e.lineVerticalPlaneEnabled&&(t.uniforms.add(new b("angleCutoff",(e=>O(e))),new S("lineVerticalPlane",((e,i)=>z(e,i))),new M("lineVerticalStart",((e,i)=>I(e,i))),new M("lineVerticalEnd",((e,i)=>T(e,i)))),t.main.add(j`if (pointIsWithinLine(pos, lineVerticalStart, lineVerticalEnd)) { float lineVerticalDistance = planeDistancePixels(lineVerticalPlane, pos); vec4 lineVerticalColor = laserlineProfile(lineVerticalDistance); float lineVerticalAlpha = 1.0 - smoothstep(angleCutoff.x, angleCutoff.y, abs(dot(normal, lineVerticalPlane.xyz))); color = max(color, lineVerticalColor * lineVerticalAlpha); }`)),e.intersectsLineEnabled&&(t.uniforms.add(new b("angleCutoff",(e=>O(e))),new M("intersectsLineStart",((e,i)=>n(F,e.lineStartWorld,i.camera.viewMatrix))),new M("intersectsLineEnd",((e,i)=>n(F,e.lineEndWorld,i.camera.viewMatrix))),new M("intersectsLineDirection",((e,i)=>(s(G,e.intersectsLineSegment.vector),G[3]=0,o(F,p(G,G,i.camera.viewMatrix))))),new L("intersectsLineRadius",(e=>e.intersectsLineRadius))),t.main.add(j`if (pointIsWithinLine(pos, intersectsLineStart, intersectsLineEnd)) { float intersectsLineDistance = lineDistancePixels(intersectsLineStart, intersectsLineDirection, intersectsLineRadius, pos); vec4 intersectsLineColor = laserlineProfile(intersectsLineDistance); float intersectsLineAlpha = 1.0 - smoothstep(angleCutoff.x, angleCutoff.y, 1.0 - abs(dot(normal, intersectsLineDirection))); color = max(color, intersectsLineColor * intersectsLineAlpha); }`)),t.main.add(j`fragColor = laserlineOutput(color * depthDiscontinuityAlpha);`),i}function O(t){return i(U,Math.cos(t.angleCutoff),Math.cos(Math.max(0,t.angleCutoff-e(2))))}function E(e,i){return n(w(N),e.pointDistanceOrigin,i.camera.viewMatrix),N[3]=l(e.pointDistanceOrigin,e.pointDistanceTarget),N}function z(e,i){const t=h(e.lineVerticalPlaneSegment,.5,F),n=e.renderCoordsHelper.worldUpAtPosition(t,W),a=o(H,e.lineVerticalPlaneSegment.vector),r=c(F,n,a);return o(r,r),R(e.lineVerticalPlaneSegment.origin,r,i.camera.viewMatrix)}function I(e,i){const t=s(F,e.lineVerticalPlaneSegment.origin);return e.renderCoordsHelper.setAltitude(t,0),n(t,t,i.camera.viewMatrix)}function T(e,i){const t=d(F,e.lineVerticalPlaneSegment.origin,e.lineVerticalPlaneSegment.vector);return e.renderCoordsHelper.setAltitude(t,0),n(t,t,i.camera.viewMatrix)}function R(e,i,t){return n(_,e,t),s(G,i),G[3]=0,p(G,G,t),m(_,G,B)}const U=t(),F=f(),G=g(),W=f(),H=f(),_=f(),B=u(),N=x(),$=Object.freeze(Object.defineProperty({__proto__:null,build:y,defaultAngleCutoff:V},Symbol.toStringTag,{value:"Module"}));export{$ as L,y as b,V as d};