/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../core/mathUtils","../core/maybe","./vec2","./vec2f64","../views/3d/webgl-engine/core/shaderLibrary/Laserline.glsl","../views/3d/webgl-engine/core/shaderLibrary/ScreenSpacePass","../views/3d/webgl-engine/core/shaderModules/Float2PassUniform","../views/3d/webgl-engine/core/shaderModules/Float3Uniform","../views/3d/webgl-engine/core/shaderModules/Float4Uniform","../views/3d/webgl-engine/core/shaderModules/FloatPassUniform","../views/3d/webgl-engine/core/shaderModules/FloatUniform","../views/3d/webgl-engine/core/shaderModules/interfaces","../views/3d/webgl-engine/core/shaderModules/ShaderBuilder"],(function(e,n,i,t,a,l,o,s,r,d,c,f,h,p){"use strict";const u=n.deg2rad(6);function g(e){const n=new p.ShaderBuilder;n.extensions.add("GL_OES_standard_derivatives"),n.include(o.ScreenSpacePass),n.include(l.Laserline,e);const i=n.fragment;return e.heightManifoldEnabled&&i.uniforms.add(new d.Float4Uniform("heightPlane")),e.pointDistanceEnabled&&i.uniforms.add(new d.Float4Uniform("pointDistanceSphere")),e.lineVerticalPlaneEnabled&&(i.uniforms.add(new d.Float4Uniform("lineVerticalPlane")),i.uniforms.add(new r.Float3Uniform("lineVerticalStart")),i.uniforms.add(new r.Float3Uniform("lineVerticalEnd"))),(e.heightManifoldEnabled||e.pointDistanceEnabled||e.lineVerticalPlaneEnabled)&&i.uniforms.add(new f.FloatUniform("maxPixelDistance")),(e.lineVerticalPlaneEnabled||e.heightManifoldEnabled)&&i.code.add(h.glsl`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.pointDistanceEnabled&&i.code.add(h.glsl`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&&(i.uniforms.add(new r.Float3Uniform("intersectsLineStart")),i.uniforms.add(new r.Float3Uniform("intersectsLineEnd")),i.uniforms.add(new r.Float3Uniform("intersectsLineDirection")),i.uniforms.add(new f.FloatUniform("intersectsLineRadius")),i.uniforms.add(new c.FloatPassUniform("perScreenPixelRatio",((e,n)=>n.camera.perScreenPixelRatio))),i.code.add(h.glsl`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)&&i.code.add(h.glsl`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;
}`),i.code.add(h.glsl`void main() {
vec3 pos;
vec3 normal;
float depthDiscontinuityAlpha;
if (!laserlineReconstructFromDepth(pos, normal, depthDiscontinuityAlpha)) {
discard;
}
vec4 color = vec4(0, 0, 0, 0);`),e.heightManifoldEnabled&&(i.uniforms.add(new s.Float2PassUniform("angleCutoff",(e=>m(e)))),i.code.add(h.glsl`{
float heightManifoldAlpha = 1.0 - smoothstep(angleCutoff.x, angleCutoff.y, abs(dot(normal, heightPlane.xyz)));
vec4 heightManifoldColor = laserlineProfile(planeDistancePixels(heightPlane, pos));
color = max(color, heightManifoldColor * heightManifoldAlpha);
}`)),e.pointDistanceEnabled&&(i.uniforms.add(new s.Float2PassUniform("angleCutoff",(e=>m(e)))),i.code.add(h.glsl`{
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&&(i.uniforms.add(new s.Float2PassUniform("angleCutoff",(e=>m(e)))),i.code.add(h.glsl`{
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&&(i.uniforms.add(new s.Float2PassUniform("angleCutoff",(e=>m(e)))),i.code.add(h.glsl`{
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);
}
}`)),i.code.add(h.glsl`gl_FragColor = laserlineOutput(color * depthDiscontinuityAlpha);
}`),n}function m(e){const a=i.isSome(e.angleCutoff)?e.angleCutoff:u;return t.set(w,Math.cos(a),Math.cos(Math.max(0,a-n.deg2rad(2))))}const w=a.create(),b=Object.freeze(Object.defineProperty({__proto__:null,defaultAngleCutoff:u,build:g},Symbol.toStringTag,{value:"Module"}));e.LaserlinesShader=b,e.build=g,e.defaultAngleCutoff=u}));
