Skip to content

Commit

Permalink
refactor: simplify isClipped (#4661)
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonflatval-cognite authored Aug 12, 2024
1 parent d079752 commit a13b608
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 40 deletions.
2 changes: 1 addition & 1 deletion viewer/packages/rendering/src/glsl/base/isClipped.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
uniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];
#endif

bool isClipped(NodeAppearance nodeAppearance, vec3 point) {
bool isClipped(vec3 point) {
#if NUM_CLIPPING_PLANES > 0
vec3 pointFlipped = -point;
vec4 plane;
Expand Down
26 changes: 1 addition & 25 deletions viewer/packages/rendering/src/glsl/pointcloud/pointcloud.vert
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ precision highp float;
precision highp int;

#pragma glslify: import('../base/pointSizeRelativeToScreen.glsl');
#pragma glslify: import('../base/isClipped.glsl');

#define max_clip_boxes 30

Expand Down Expand Up @@ -45,31 +46,6 @@ uniform sampler2D gradient;
uniform sampler2D classificationLUT;
uniform sampler2D objectIdLUT;

#if NUM_CLIPPING_PLANES > 0
uniform vec4 clippingPlanes[NUM_CLIPPING_PLANES];
#endif

bool isClipped(vec3 point) {
#if NUM_CLIPPING_PLANES > 0
vec3 pointFlipped = -point;
vec4 plane;

for (int i = 0; i < UNION_CLIPPING_PLANES; i++) {
plane = clippingPlanes[i];
if (dot(pointFlipped, plane.xyz) > plane.w) return true;
}
#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES
bool clipped = true;
for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {
plane = clippingPlanes[ i ];
clipped = (dot(pointFlipped, plane.xyz) > plane.w) && clipped;
}
if ( clipped ) return true;
#endif
#endif
return false;
}

out vec3 vColor;

#if defined(weighted_splats)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main()
{
highp float treeIndex = unpackTreeIndex(v_treeIndexPacked);
NodeAppearance appearance = nodeAppearanceFromTexel(v_nodeAppearanceTexel);
if (isClipped(appearance, v_viewPosition)) {
if (isClipped(v_viewPosition)) {
discard;
}

Expand Down
2 changes: 1 addition & 1 deletion viewer/packages/rendering/src/glsl/sector/mesh.frag
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void main()
{
highp float v_treeIndex = unpackTreeIndex(v_treeIndexPacked);
NodeAppearance appearance = nodeAppearanceFromTexel(v_nodeAppearanceTexel);
if (isClipped(appearance, v_viewPosition)) {
if (isClipped(v_viewPosition)) {
discard;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void main()
discard;

NodeAppearance appearance = nodeAppearanceFromTexel(v_nodeAppearanceTexel);
if (isClipped(appearance, vViewPosition)) {
if (isClipped(vViewPosition)) {
discard;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void main()
if (intersectionPoint.z <= 0.0 ||
intersectionPoint.z > height ||
theta > v_angle + v_arcAngle ||
isClipped(appearance, p) ||
isClipped(p) ||
rayTargetDist + dist < 0.0
) {
// Missed the first point, check the other point
Expand All @@ -124,7 +124,7 @@ void main()
if (intersectionPoint.z <= 0.0 ||
intersectionPoint.z > height ||
theta > v_angle + v_arcAngle ||
isClipped(appearance, p) ||
isClipped(p) ||
rayTargetDist + dist < 0.0
) {
// Missed the other point too
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void main()

if (intersectionPointZ <= 0.0 ||
intersectionPointZ >= L ||
isClipped(appearance, p) ||
isClipped(p) ||
rayTargetDist + dist < 0.0
) {
// Either intersection point is behind starting point (happens inside the cone),
Expand All @@ -115,7 +115,7 @@ void main()

if (intersectionPointZ <= 0.0 ||
intersectionPointZ >= L ||
isClipped(appearance, p) ||
isClipped(p) ||
rayTargetDist + dist < 0.0
) {
// Missed the other point too
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void main()

if (intersectionPointZ <= vRadius - height ||
intersectionPointZ > vRadius ||
isClipped(appearance, p)
isClipped(p)
) {
// Missed the first point, check the other point

Expand All @@ -90,7 +90,7 @@ void main()
p = rayTarget + dist * rayDirection;
if (intersectionPointZ <= vRadius - height ||
intersectionPointZ > vRadius ||
isClipped(appearance, p)
isClipped(p)
) {
// Missed the other point too
discard;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void main()
if (dot(intersectionPoint - planeACenter, planeANormal) > 0.0 ||
dot(intersectionPoint - planeBCenter, planeBNormal) > 0.0 ||
theta > v_angles[1] + v_angles[0] ||
isClipped(appearance, p) ||
isClipped(p) ||
rayTargetDist + dist < 0.0
) {
// Missed the first point, check the other point
Expand All @@ -102,7 +102,7 @@ void main()
p = rayTarget + dist*rayDirection;
if (dot(intersectionPoint - planeACenter, planeANormal) > 0.0 ||
dot(intersectionPoint - planeBCenter, planeBNormal) > 0.0 ||
theta > v_angles[1] + v_angles[0] || isClipped(appearance, p) ||
theta > v_angles[1] + v_angles[0] || isClipped(p) ||
rayTargetDist + dist < 0.0
) {
// Missed the other point too
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void main()
// Redo appearance texture lookup from vertex shader due to limit in transferable attributes
NodeAppearance appearance = determineNodeAppearance(colorDataTexture, treeIndexTextureSize, v_treeIndex);

if (isClipped(appearance, vViewPosition)) {
if (isClipped(vViewPosition)) {
discard;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main()
{
highp float v_treeIndex = unpackTreeIndex(v_treeIndexPacked);
NodeAppearance appearance = nodeAppearanceFromTexel(v_nodeAppearanceTexel);
if (isClipped(appearance, vViewPosition)) {
if (isClipped(vViewPosition)) {
discard;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main()
{
highp float v_treeIndex = unpackTreeIndex(v_treeIndexPacked);
NodeAppearance appearance = nodeAppearanceFromTexel(v_nodeAppearanceTexel);
if (isClipped(appearance, vViewPosition)) {
if (isClipped(vViewPosition)) {
discard;
}

Expand Down

0 comments on commit a13b608

Please sign in to comment.