CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
12.89k stars 3.48k forks source link

Errors with large ellipses #7065

Open dakotalraymond opened 6 years ago

dakotalraymond commented 6 years ago

When drawing very large ellipses, there are visual errors, particularly in 2d mode. Some areas are missing and others get drawn twice. You can see this by visiting the Circles and Ellipses sandcastle and setting a semiMinorAxis and semiMajorAxis to 5000000 or greater. It seems to make it worse if they are very far north. (see screenshots). You can fix the 3d by adding a little height to it, but it doesn't help the 2d projection.

Here is code to reproduce the error:

var viewer = new Cesium.Viewer('cesiumContainer');

var redEllipse = viewer.entities.add({ position: Cesium.Cartesian3.fromDegrees(-103.0, 80.0), name : 'Red ellipse on surface', ellipse : { semiMinorAxis : 6000000.0, semiMajorAxis : 6000000.0, material : Cesium.Color.RED.withAlpha(0.5) } });

3d 2d

hpinkos commented 6 years ago

@dakotalraymond can you please paste some sample code to reproduce this? Thanks!

dakotalraymond commented 6 years ago

@dakotalraymond can you please paste some sample code to reproduce this? Thanks!

Sure thing

GatorScott commented 6 years ago

Here's a visually interesting example


var redEllipse = viewer.entities.add({
    position: Cesium.Cartesian3.fromDegrees(0.0, 0.0),
    name : 'Red ellipse on surface',
    ellipse : {
        semiMajorAxis : 40000000.0,
        semiMinorAxis : 4000000.0,
        material : Cesium.Color.RED.withAlpha(0.5)
    }
});

viewer.zoomTo(viewer.entities);
hpinkos commented 6 years ago

Thanks @dakotalraymond, @GatorScott

There are a few different problems here

  1. splitLongitude is causing artifacts across the north pole
  2. The shadow volume isn't high enough for the ground primigive, causing the diamondy look
  3. If the semiMajorAxis is too wide, the end points are incorrect
JosiahAllen commented 5 years ago

Thanks for the height tip @dakotalraymond

For 3D mode I tried to see how much globe I could cover with an ellipse before undesirable effects started to occur.

This is what I got to:

var viewer = new Cesium.Viewer('cesiumContainer');

var redEllipse = viewer.entities.add({ position: Cesium.Cartesian3.fromDegrees(3.0, 50.0), name : 'Red ellipse on surface', ellipse : { semiMinorAxis : 9100000.0, semiMajorAxis : 9100000.0, material : Cesium.Color.RED.withAlpha(0.5), height:1, granularity:((Math.PI / 180.0)/32)

} });

viewer.zoomTo(viewer.entities);

Near 10000000.0 meters it breaks down completely even with the height trick, I assume because it's crossed the halfway point of the ellipsoid.

If you set the material to 0 alpha though the outline will still draw as expected, it's the fill that fails.

benwiles1 commented 3 years ago

I believe the error is in CircleGeometry.createShadowVolume and EllipseGeometry.createShadowVolume

Those take a granularity option documented as

* @param {Number} [options.granularity=0.02] The angular distance between points on the circle in radians.

but the other geometry types specify granularity as

* @param {Number} [options.granularity=CesiumMath.RADIANS_PER_DEGREE] The distance, in radians, between each latitude and longitude. Determines the number of positions in the buffer.

The getMinHeight and getMaxHeight are expecting the latter, but CircleGeometry.createShadowVolume and EllipseGeometry.createShadowVolume don't do anything to convert.

ggetz commented 1 year ago

Also reported in https://github.com/CesiumGS/cesium/issues/11438

ggetz commented 1 year ago

Shadow volume rendering artifacts also reported for Rectangles in https://github.com/CesiumGS/cesium/issues/11537.