/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as e}from"tslib";import{translate as s}from"../../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as i}from"../../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{add as a,transformMat4 as l,subtract as o,set as c}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as n,create as r}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{InstancedDoubleConfiguration as t}from"./attributes/InstancedDoubleConfiguration.js";import{Float3DrawUniform as f}from"../shaderModules/Float3DrawUniform.js";import{Float3PassUniform as d}from"../shaderModules/Float3PassUniform.js";import{glsl as u}from"../shaderModules/glsl.js";import{parameter as p}from"../shaderTechnique/ShaderTechniqueConfiguration.js";import{NoParameters as P}from"../../../../webgl/NoParameters.js";class m extends t{constructor(){super(...arguments),this.hasSlicePlane=!1,this.hasSliceTranslatedView=!1}}e([p()],m.prototype,"hasSlicePlane",void 0);class b extends P{constructor(e){super(),this.slicePlaneLocalOrigin=e}}function v(e,s){g(e,s,new d("slicePlaneOrigin",(e,i)=>x(s,e,i)),new d("slicePlaneBasis1",(e,i)=>O(s,e,i,i.slicePlane?.basis1)),new d("slicePlaneBasis2",(e,i)=>O(s,e,i,i.slicePlane?.basis2)))}function h(e,s){g(e,s,new f("slicePlaneOrigin",(e,i)=>x(s,e,i)),new f("slicePlaneBasis1",(e,i)=>O(s,e,i,i.slicePlane?.basis1)),new f("slicePlaneBasis2",(e,i)=>O(s,e,i,i.slicePlane?.basis2)))}function w(e,s){B(e,s,new f("slicePlaneOrigin",(e,i)=>x(s,e,i)),new f("slicePlaneBasis1",(e,i)=>O(s,e,i,i.slicePlane?.basis1)),new f("slicePlaneBasis2",(e,i)=>O(s,e,i,i.slicePlane?.basis2)))}const S=u`struct SliceFactors {
float front;
float side0;
float side1;
float side2;
float side3;
};
SliceFactors calculateSliceFactors(vec3 pos) {
vec3 rel = pos - slicePlaneOrigin;
vec3 slicePlaneNormal = -cross(slicePlaneBasis1, slicePlaneBasis2);
float slicePlaneW = -dot(slicePlaneNormal, slicePlaneOrigin);
float basis1Len2 = dot(slicePlaneBasis1, slicePlaneBasis1);
float basis2Len2 = dot(slicePlaneBasis2, slicePlaneBasis2);
float basis1Dot = dot(slicePlaneBasis1, rel);
float basis2Dot = dot(slicePlaneBasis2, rel);
return SliceFactors(
dot(slicePlaneNormal, pos) + slicePlaneW,
-basis1Dot - basis1Len2,
basis1Dot - basis1Len2,
-basis2Dot - basis2Len2,
basis2Dot - basis2Len2
);
}
bool sliceByFactors(SliceFactors factors) {
return factors.front < 0.0
&& factors.side0 < 0.0
&& factors.side1 < 0.0
&& factors.side2 < 0.0
&& factors.side3 < 0.0;
}
bool sliceEnabled() {
return dot(slicePlaneBasis1, slicePlaneBasis1) != 0.0;
}
bool rejectBySlice(vec3 pos) {
return sliceEnabled() && sliceByFactors(calculateSliceFactors(pos));
}`;function B(e,s,...i){s.hasSlicePlane?(e.uniforms.add(...i),e.code.add(S)):e.code.add("bool rejectBySlice(vec3 pos) { return false; }")}function g(e,s,...i){e.constants.add("groundSliceOpacity","float",.2),B(e,s,...i),s.hasSlicePlane?e.code.add("\n    void discardBySlice(vec3 pos) {\n      if (rejectBySlice(pos)) {\n        discard;\n      }\n    }\n\n    vec4 applySliceOutline(vec4 color, vec3 pos) {\n      SliceFactors factors = calculateSliceFactors(pos);\n\n      factors.front /= 2.0 * fwidth(factors.front);\n      factors.side0 /= 2.0 * fwidth(factors.side0);\n      factors.side1 /= 2.0 * fwidth(factors.side1);\n      factors.side2 /= 2.0 * fwidth(factors.side2);\n      factors.side3 /= 2.0 * fwidth(factors.side3);\n\n      // return after calling fwidth, to avoid aliasing caused by discontinuities in the input to fwidth\n      if (sliceByFactors(factors)) {\n        return color;\n      }\n\n      float outlineFactor = (1.0 - step(0.5, factors.front))\n        * (1.0 - step(0.5, factors.side0))\n        * (1.0 - step(0.5, factors.side1))\n        * (1.0 - step(0.5, factors.side2))\n        * (1.0 - step(0.5, factors.side3));\n\n      return mix(color, vec4(vec3(0.0), color.a), outlineFactor * 0.3);\n    }\n\n    vec4 applySlice(vec4 color, vec3 pos) {\n      return sliceEnabled() ? applySliceOutline(color, pos) : color;\n    }\n  "):e.code.add(u`void discardBySlice(vec3 pos) { }
vec4 applySlice(vec4 color, vec3 pos) { return color; }`)}function y(e,s,i){return e.instancedDoublePrecision?c(D,i.camera.viewInverseTransposeMatrix[3],i.camera.viewInverseTransposeMatrix[7],i.camera.viewInverseTransposeMatrix[11]):s.slicePlaneLocalOrigin}function F(e,s){return null!=e?o(L,s.origin,e):s.origin}function j(e,i,a){return e.hasSliceTranslatedView?null!=i?s(T,a.camera.viewMatrix,i):a.camera.viewMatrix:null}function x(e,s,i){if(null==i.slicePlane)return n;const a=y(e,s,i),o=F(a,i.slicePlane),c=j(e,a,i);return null!=c?l(L,o,c):o}function O(e,s,i,c){if(null==c||null==i.slicePlane)return n;const r=y(e,s,i),t=F(r,i.slicePlane),f=j(e,r,i);return null!=f?(a(M,c,t),l(L,t,f),l(M,M,f),o(M,M,L)):c}const D=r(),L=r(),M=r(),T=i();export{w as RejectBySlice,m as SliceConfiguration,h as SliceDraw,v as SlicePass,b as SlicePlaneParameters};
