/* COPYRIGHT Esri - https://js.arcgis.com/5.1.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{transformMat4 as a,add as o,subtract as l,set as n}from"../../../../../core/libs/gl-matrix-2/math/vec3.js";import{ZEROS as c,create as t}from"../../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{InstancedDoubleConfiguration as r}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 m}from"../../../../webgl/NoParameters.js";class P extends r{constructor(){super(...arguments),this.hasSlicePlane=!1,this.hasSliceTranslatedView=!1}}e([p()],P.prototype,"hasSlicePlane",void 0);class b extends m{constructor(e=null){super(),this.slicePlaneLocalOrigin=e}}function v(e,s){y(e,s,...F(s))}function h(e,s){y(e,s,...j(s))}function S(e,s){g(e,s,...j(s))}function w(e,s){g(e,s,...F(s))}const B=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 g(e,s,...i){s.hasSlicePlane?(e.uniforms.add(...i),e.code.add(B)):e.code.add("bool rejectBySlice(vec3 pos) { return false; }")}function y(e,s,...i){e.constants.add("groundSliceOpacity","float",.2),g(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 F(e){return[new d("slicePlaneOrigin",(s,i)=>L(e,s,i)),new d("slicePlaneBasis1",(s,i)=>M(e,s,i,i.slicePlane?.basis1)),new d("slicePlaneBasis2",(s,i)=>M(e,s,i,i.slicePlane?.basis2))]}function j(e){return[new f("slicePlaneOrigin",(s,i)=>L(e,s,i)),new f("slicePlaneBasis1",(s,i)=>M(e,s,i,i.slicePlane?.basis1)),new f("slicePlaneBasis2",(s,i)=>M(e,s,i,i.slicePlane?.basis2))]}function x(e,s,i){return e.instancedDoublePrecision?n(T,i.camera.viewInverseTransposeMatrix[3],i.camera.viewInverseTransposeMatrix[7],i.camera.viewInverseTransposeMatrix[11]):s.slicePlaneLocalOrigin}function D(e,s){return null!=e?l(I,s.origin,e):s.origin}function O(e,i,a){return e.hasSliceTranslatedView?null!=i?s(E,a.camera.viewMatrix,i):a.camera.viewMatrix:null}function L(e,s,i){if(null==i.slicePlane)return c;const o=x(e,s,i),l=D(o,i.slicePlane),n=O(e,o,i);return null!=n?a(I,l,n):l}function M(e,s,i,n){if(null==n||null==i.slicePlane)return c;const t=x(e,s,i),r=D(t,i.slicePlane),f=O(e,t,i);return null!=f?(o(N,n,r),a(I,r,f),a(N,N,f),l(N,N,I)):n}const T=t(),I=t(),N=t(),E=i();export{S as RejectBySliceDraw,w as RejectBySlicePass,P as SliceConfiguration,h as SliceDraw,v as SlicePass,b as SlicePlaneParameters};
