Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to define clipping regions with polygons #11750

Merged
merged 31 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
77bb0d1
ClippingPolygonCollection
ggetz Jan 9, 2024
eab1d19
Fix TS
ggetz Jan 9, 2024
0140ce0
Update CHANGES.md
ggetz Jan 9, 2024
15cad35
Draft
ggetz Mar 12, 2024
5079310
Merge branch 'main' into clip-region
ggetz Mar 12, 2024
7a789fd
Draft 2
ggetz Mar 13, 2024
70f1170
Merge branch 'main' into clip-region
ggetz Mar 15, 2024
b5ba48d
Draft
ggetz Mar 18, 2024
c185b7b
Merge branch 'main' into clip-region
ggetz Mar 18, 2024
fe5704e
Start cleanup
ggetz Mar 19, 2024
f42b7db
Update Specs
ggetz Mar 22, 2024
be45ded
Update clipping plane performance, wire through terrain clipping
ggetz Mar 25, 2024
c624775
Merge branch 'main' into clip-region
ggetz Mar 25, 2024
aca4f14
cleanup doc
ggetz Mar 25, 2024
3158943
Cleanup private classes
ggetz Mar 25, 2024
e87589d
Fix jagged edges
ggetz Apr 3, 2024
7305ce1
Specs cleanup
ggetz Apr 5, 2024
1b24f93
More specs
ggetz Apr 5, 2024
3cf00dc
More specs
ggetz Apr 5, 2024
58b5a42
Cleanup AEC example for tutorial
ggetz Apr 10, 2024
73cf3e2
Fix typos and whitespace
Apr 10, 2024
a43d78f
Fix typos and whitespace
Apr 11, 2024
dc84c67
Feedback from PR
ggetz Apr 12, 2024
3ac081f
Fix issue with terrain when zoomed out
ggetz Apr 15, 2024
38a2b9d
Update tests
ggetz Apr 16, 2024
e69d21f
Fix P3DT not clipping when zoomed out
ggetz Apr 16, 2024
b32fa28
Cleanup:
ggetz Apr 17, 2024
0f5c0a3
Cleanup
ggetz Apr 17, 2024
859abb9
Fix minor docs typos
Apr 22, 2024
71f7197
Fix sandcastle angle, too agressive simplification
ggetz Apr 23, 2024
620a0ec
Adjust clip polygon region combining
ggetz Apr 26, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup:
  • Loading branch information
ggetz committed Apr 17, 2024
commit b32fa283c138fc4d86850640191e746ab567c2b9
3 changes: 0 additions & 3 deletions packages/engine/Source/Scene/ClippingPolygonCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,6 @@ ClippingPolygonCollection.prototype.remove = function (polygon) {
polygons.splice(index, 1);

this.polygonRemoved.raiseEvent(polygon, index);
this._dirty = true;

return true;
};

Expand Down Expand Up @@ -394,7 +392,6 @@ ClippingPolygonCollection.prototype.removeAll = function () {
const polygon = polygons[i];
this.polygonRemoved.raiseEvent(polygon, i);
}
this._dirty = true;
this._polygons = [];
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ float getSignedDistance(vec2 uv, highp sampler2D clippingDistance) {
return (signedDistance - 0.5) * 2.0;
}

void czm_clipPolygons(highp sampler2D clippingDistance, int polygonsLength, vec2 clippingPosition, int regionIndex) {
void czm_clipPolygons(highp sampler2D clippingDistance, int extentsLength, vec2 clippingPosition, int regionIndex) {
// Position is completely outside of polygons bounds
vec2 rectUv = clippingPosition;
if (regionIndex < 0 || rectUv.x <= 0.0 || rectUv.y <= 0.0 || rectUv.x >= 1.0 || rectUv.y >= 1.0) {
Expand All @@ -15,8 +15,10 @@ void czm_clipPolygons(highp sampler2D clippingDistance, int polygonsLength, vec2

vec2 clippingDistanceTextureDimensions = vec2(textureSize(clippingDistance, 0));
vec2 sampleOffset = max(1.0 / clippingDistanceTextureDimensions, vec2(0.005));
float dimension = max(ceil(log2(float(polygonsLength))), float(polygonsLength));
vec2 polygonTextureSize = clippingDistanceTextureDimensions / dimension;
float dimension = float(extentsLength);
if (extentsLength > 2) {
dimension = ceil(log2(float(extentsLength)));
}

vec2 textureOffset = vec2(mod(float(regionIndex), dimension), floor(float(regionIndex) / dimension)) / dimension;
vec2 uv = textureOffset + rectUv / dimension;
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/Source/Shaders/GlobeVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void main()
vec4 extents = unpackClippingExtents(u_clippingExtents, regionIndex);

vec2 rectUv = (sphericalLatLong.yx - extents.yx) * extents.wz;
float padding = 5000.0 * czm_geometricToleranceOverMeter;
float padding = 0.1;
if (rectUv.x > -padding && rectUv.y > -padding && rectUv.x < 1.0 + padding && rectUv.y < 1.0 + padding) {
v_clippingPosition = rectUv;
v_regionIndex = regionIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ void modelClippingPolygonsStage()
{
vec2 clippingPosition = v_clippingPosition;
int regionIndex = v_regionIndex;

czm_clipPolygons(model_clippingDistance, CLIPPING_POLYGON_REGIONS_LENGTH, clippingPosition, regionIndex);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ void modelClippingPolygonsStage(ProcessedAttributes attributes)
vec2 sphericalLatLong = czm_approximateSphericalCoordinates(v_positionWC);
sphericalLatLong.y = czm_branchFreeTernary(sphericalLatLong.y < czm_pi, sphericalLatLong.y, sphericalLatLong.y - czm_twoPi);

vec3 radii = czm_ellipsoidRadii;
float maxRadii = max(radii.x, max(radii.y, radii.z));

for (int regionIndex = 0; regionIndex < CLIPPING_POLYGON_REGIONS_LENGTH; regionIndex++) {
vec4 extents = czm_unpackClippingExtents(model_clippingExtents, regionIndex);

vec2 rectUv = (sphericalLatLong.yx - extents.yx) * extents.wz;
float padding = 2500.0 * czm_geometricToleranceOverMeter;
float padding = 0.1;
if (rectUv.x > -padding && rectUv.y > -padding && rectUv.x < 1.0 + padding && rectUv.y < 1.0 + padding) {
v_clippingPosition = rectUv;
v_regionIndex = regionIndex;
Expand Down
9 changes: 6 additions & 3 deletions packages/engine/Source/Shaders/PolygonSignedDistanceFS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ void main() {
out_FragColor = vec4(1.0);

// Get the relevant region of the texture
float dimension = max(ceil(log2(float(u_extentsLength))), float(u_extentsLength));
float dimension = float(u_extentsLength);
if (u_extentsLength > 2) {
dimension = ceil(log2(float(u_extentsLength)));
}
int regionIndex = getPolygonIndex(dimension, v_textureCoordinates);

for (int polygonIndex = 0; polygonIndex < u_polygonsLength; polygonIndex++) {
Expand All @@ -59,8 +62,8 @@ void main() {
if (polygonExtentsIndex == regionIndex) {
float clipAmount = czm_infinity;
vec4 extents = getExtents(polygonExtentsIndex);
vec2 textureOffset = vec2(mod(float(polygonExtentsIndex), dimension), floor(float(polygonExtentsIndex) / dimension));
vec2 p = getCoordinates(v_textureCoordinates * dimension - textureOffset, extents);
vec2 textureOffset = vec2(mod(float(polygonExtentsIndex), dimension), floor(float(polygonExtentsIndex) / dimension)) / dimension;
vec2 p = getCoordinates((v_textureCoordinates - textureOffset) * dimension, extents);
float s = 1.0;

// Check each edge for absolute distance
Expand Down
4 changes: 2 additions & 2 deletions packages/engine/Specs/Scene/ClippingPolygonCollectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,11 @@ describe("Scene/ClippingPolygonCollection", function () {
expect(arrayBufferView[2]).toEqualEpsilon(
10111.67578125,
CesiumMath.EPSILON10
); // north - south
); // 1 / (north - south)
expect(arrayBufferView[3]).toEqualEpsilon(
15428.873046875,
CesiumMath.EPSILON10
); // east - west
); // 1 / (east - west)
expect(arrayBufferView[4]).toBe(0); // padding
expect(arrayBufferView[5]).toBe(0); // padding
expect(arrayBufferView[6]).toBe(0); // padding
Expand Down