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

Turn on dynamicScreenSpaceError by default #11718

Merged
merged 28 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5f35393
Enable dynamicScreenSpaceError, document parameters
ptrgags Dec 21, 2023
642c7a3
Update CHANGES.md
ptrgags Dec 21, 2023
5a0679d
Add missing defaultValue() calls
ptrgags Dec 21, 2023
fde33ff
Turn down dynamicSSE to fix picking tests
ptrgags Dec 21, 2023
b309cbf
Turn off dynamic SSE instead
ptrgags Dec 21, 2023
6dad6f6
Fix inspector dynamicScreenSpaceErrorDensity slider
ptrgags Dec 21, 2023
12f226f
Update changelog for inspector fix
ptrgags Dec 21, 2023
236f8d6
Add PR number to the changelog
ptrgags Dec 21, 2023
c1d4c90
Merge branch 'main' into 11715-dyn-sse-by-default
ptrgags Jan 2, 2024
e6e8179
PR feedback
ptrgags Jan 2, 2024
e6bb5f5
The fog was unrealistically close to the camera
ptrgags Jan 2, 2024
1127926
Put changelog entry in breaking changes section
ptrgags Jan 2, 2024
1604f8e
PR feedback
ptrgags Jan 2, 2024
bddb6cc
Increase SSE Factor slider maximum
ptrgags Jan 2, 2024
ff58d6f
Merge branch 'main' into 11715-dyn-sse-by-default
ptrgags Jan 2, 2024
bb93b35
Revise the parameter documentation
ptrgags Jan 2, 2024
f40a357
Merge branch 'main' into 11715-dyn-sse-by-default
ptrgags Jan 2, 2024
f5e6101
Add a changelog entry for fixing the ignored parameters
ptrgags Jan 2, 2024
f36c303
Reorganize changelog
ptrgags Jan 2, 2024
75dde94
Update default setting for SSE factor to 24
ptrgags Jan 2, 2024
71157a0
Add spec for ensuring the constructor options work
ptrgags Jan 3, 2024
0a1a80d
Turn off dynamicSSE for debugging test
ptrgags Jan 3, 2024
d85bcaf
Disable dynamicSSE for picking tests, mention issue
ptrgags Jan 3, 2024
dcc5a61
Negative SSE wasn't the issue
ptrgags Jan 3, 2024
91da8ea
Merge branch 'main' into 11715-dyn-sse-by-default
ptrgags Jan 3, 2024
1ce0e5a
Merge branch 'main' into 11715-dyn-sse-by-default
ptrgags Jan 4, 2024
e4dc646
Use async function for new tests
ptrgags Jan 4, 2024
a28e701
Add spec for density slider
ptrgags Jan 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@

#### @cesium/engine

##### Additions :tada:

- The `Cesium3DTileset.dynamicScreenSpaceError` optimization is now enabled by default, as this improves performance for street-level horizon views. [#11718](https://github.com/CesiumGS/cesium/pull/11718)
ptrgags marked this conversation as resolved.
Show resolved Hide resolved

##### Fixes :wrench:

- Changes the default `RequestScheduler.maximumRequestsPerServer` from 6 to 18. This should improve performance on HTTP/2 servers and above [#11627](https://github.com/CesiumGS/cesium/issues/11627)
- Corrected JSDoc and Typescript definitions that marked optional arguments as required in `ImageryProvider` constructor [#11625](https://github.com/CesiumGS/cesium/issues/11625)
- The `Quaternion.computeAxis` function created an axis that was `(0,0,0)` for the unit quaternion, and an axis that was `(NaN,NaN,NaN)` for the quaternion `(0,0,0,-1)` (which describes a rotation about 360 degrees). Now, it returns the x-axis `(1,0,0)` in both of these cases.
- Fixed a bug where the 3D Tiles Inspector's `dynamicScreenSpaceErrorDensity` slider did not update the tileset [#6143](https://github.com/CesiumGS/cesium/issues/6143)

### 1.112 - 2023-12-01

Expand Down
96 changes: 64 additions & 32 deletions packages/engine/Source/Scene/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import IonResource from "../Core/IonResource.js";
import JulianDate from "../Core/JulianDate.js";
import ManagedArray from "../Core/ManagedArray.js";
import CesiumMath from "../Core/Math.js";
import Matrix3 from "../Core/Matrix3.js";
import Matrix4 from "../Core/Matrix4.js";
import Resource from "../Core/Resource.js";
import RuntimeError from "../Core/RuntimeError.js";
Expand Down Expand Up @@ -75,10 +76,10 @@ import Cesium3DTilesetSkipTraversal from "./Cesium3DTilesetSkipTraversal.js";
* @property {boolean} [preloadWhenHidden=false] Preload tiles when <code>tileset.show</code> is <code>false</code>. Loads tiles as if the tileset is visible but does not render them.
* @property {boolean} [preloadFlightDestinations=true] Optimization option. Preload tiles at the camera's flight destination while the camera is in flight.
* @property {boolean} [preferLeaves=false] Optimization option. Prefer loading of leaves first.
* @property {boolean} [dynamicScreenSpaceError=false] Optimization option. Reduce the screen space error for tiles that are further away from the camera.
* @property {number} [dynamicScreenSpaceErrorDensity=0.00278] Density used to adjust the dynamic screen space error, similar to fog density.
* @property {number} [dynamicScreenSpaceErrorFactor=4.0] A factor used to increase the computed dynamic screen space error.
* @property {number} [dynamicScreenSpaceErrorHeightFalloff=0.25] A ratio of the tileset's height at which the density starts to falloff.
* @property {boolean} [dynamicScreenSpaceError=true] Optimization option. Reduce the screen space error for tiles that are further away from the camera so that lower resolution tiles are used.
ptrgags marked this conversation as resolved.
Show resolved Hide resolved
* @property {number} [dynamicScreenSpaceErrorDensity=0.00278] Similar to fog density, this value determines how far away from the camera that screen space error falls off. Larger values will cause tiles closer to the camera to be affected by dynamicScreenSpaceError.
* @property {number} [dynamicScreenSpaceErrorFactor=4.0] The maximum screen space error adjustment in px to apply to a tile for tiles far away on the horizon. Increase this value to make the SSE adjustment stronger, which in turn will select lower LOD tiles near the horizon.
ptrgags marked this conversation as resolved.
Show resolved Hide resolved
* @property {number} [dynamicScreenSpaceErrorHeightFalloff=0.25] A ratio of the tileset's height above which the density decreases for dynamic screen space error. This way, dynamicScreenSpaceError has the strongest effect when the camera is close to street level.
* @property {number} [progressiveResolutionHeightFraction=0.3] Optimization option. If between (0.0, 0.5], tiles at or above the screen space error for the reduced screen resolution of <code>progressiveResolutionHeightFraction*screenHeight</code> will be prioritized first. This can help get a quick layer of tiles down while full resolution tiles continue to load.
* @property {boolean} [foveatedScreenSpaceError=true] Optimization option. Prioritize loading tiles in the center of the screen by temporarily raising the screen space error for tiles around the edge of the screen. Screen space error returns to normal once all the tiles in the center of the screen as determined by the {@link Cesium3DTileset#foveatedConeSize} are loaded.
* @property {number} [foveatedConeSize=0.1] Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control the cone size that determines which tiles are deferred. Tiles that are inside this cone are loaded immediately. Tiles outside the cone are potentially deferred based on how far outside the cone they are and their screen space error. This is controlled by {@link Cesium3DTileset#foveatedInterpolationCallback} and {@link Cesium3DTileset#foveatedMinimumScreenSpaceErrorRelaxation}. Setting this to 0.0 means the cone will be the line formed by the camera position and its view direction. Setting this to 1.0 means the cone encompasses the entire field of view of the camera, disabling the effect.
Expand Down Expand Up @@ -361,18 +362,18 @@ function Cesium3DTileset(options) {
this._pass = undefined; // Cesium3DTilePass

/**
* Optimization option. Whether the tileset should refine based on a dynamic screen space error. Tiles that are further
* away will be rendered with lower detail than closer tiles. This improves performance by rendering fewer
* tiles and making less requests, but may result in a slight drop in visual quality for tiles in the distance.
* The algorithm is biased towards "street views" where the camera is close to the ground plane of the tileset and looking
* at the horizon. In addition results are more accurate for tightly fitting bounding volumes like box and region.
* Optimization option. Whether the tileset should adjust the screen space error for tiles on the horizon. Tiles that
* are far away will be adjusted to render at lower detail than tiles closer at the camera. This improves performance
* by loading and rendering fewer tiles, but may result in a slight drop in visual quality in the distance. This
* optimization is strongest when the camera is close to the ground plane of the tileset and looking at the horizon.
* Furthermore, the results are more accurate for tightly fitting bounding volumes like box and region.
*
* @type {boolean}
* @default false
ptrgags marked this conversation as resolved.
Show resolved Hide resolved
*/
this.dynamicScreenSpaceError = defaultValue(
options.dynamicScreenSpaceError,
false
true
);

/**
Expand Down Expand Up @@ -416,48 +417,73 @@ function Cesium3DTileset(options) {
this.foveatedTimeDelay = defaultValue(options.foveatedTimeDelay, 0.2);

/**
* A scalar that determines the density used to adjust the dynamic screen space error, similar to {@link Fog}. Increasing this
* value has the effect of increasing the maximum screen space error for all tiles, but in a non-linear fashion.
* The error starts at 0.0 and increases exponentially until a midpoint is reached, and then approaches 1.0 asymptotically.
* This has the effect of keeping high detail in the closer tiles and lower detail in the further tiles, with all tiles
* beyond a certain distance all roughly having an error of 1.0.
* A parameter that controls how far away from the camera screen space error (SSE) falls off when
* <code>dynamicScreenSpaceError</code> is enabled. This is similar to the <code>density</code> parameter of
* {@link Fog}. This value must be non-negative.
* <p>
* <code>dynamicScreenSpaceError</code> causes the tile SSE to fall off with distance from the camera like a bell
* curve. At the camera, no adjustment is made (peak of bell curve). For tiles further away, the SSE is reduced
* up to a limit for tiles on the horizon. The maximum reduction is determined by the
* <code>dynamicScreenSpaceErrorFactor</code>. Reducing the SSE allows the rendering algorithm to select
* lower-resolution tiles.
* </p>
* <p>
* The dynamic error is in the range [0.0, 1.0) and is multiplied by <code>dynamicScreenSpaceErrorFactor</code> to produce the
* final dynamic error. This dynamic error is then subtracted from the tile's actual screen space error.
* Increasing the density makes the bell curve narrower. This means that the SSE adjustment will start happening
* closer to the camera. This is analgous to moving fog closer to the camera.
* </p>
* <p>
* Increasing <code>dynamicScreenSpaceErrorDensity</code> has the effect of moving the error midpoint closer to the camera.
* It is analogous to moving fog closer to the camera.
* When the density is 0, no tiles will have their SSE adjusted.
* </p>
*
* @type {number}
* @default 0.00278
*/
this.dynamicScreenSpaceErrorDensity = 0.00278;
this.dynamicScreenSpaceErrorDensity = defaultValue(
options.dynamicScreenSpaceErrorDensity,
0.00278
);

/**
* A factor used to increase the screen space error of tiles for dynamic screen space error. As this value increases less tiles
* are requested for rendering and tiles in the distance will have lower detail. If set to zero, the feature will be disabled.
* The maximum screen space error (SSE) reduction when {@link Cesium3DTileset#dynamicScreenSpaceError} is used. The
* value must be non-negative.
* <p>
* Increasing the SSE factor increases the maximum amount to reduce a tile's SSE. This maximum reduction happens
* for tiles near the horizon. For tiles closer to the camera, the SSE adjustment can be small as 0 (at the camera).
* In between, the SSE falls off like a bell curve. See {@link Cesium3DTileset#dynamicScreenSpaceErrorDensity}
* </p>
* <p>
* When the SSE factor is set to 0, the adjustment will be 0 for all tiles.
* </p>
* A factor used to increase the screen space error of tiles for dynamic screen space error. As this value increases
* less tiles are requested for rendering and tiles in the distance will have lower detail. If set to zero, the
* feature will be disabled.
ptrgags marked this conversation as resolved.
Show resolved Hide resolved
*
* @type {number}
* @default 4.0
*/
this.dynamicScreenSpaceErrorFactor = 4.0;
this.dynamicScreenSpaceErrorFactor = defaultValue(
options.dynamicScreenSpaceErrorFactor,
4.0
);

/**
* A ratio of the tileset's height at which the density starts to falloff. If the camera is below this height the
* full computed density is applied, otherwise the density falls off. This has the effect of higher density at
* street level views.
* A ratio of the tileset's height above which the effects of {@link Cesium3DTileset#dynamicScreenSpaceError} begin
* to fall off. This determines what is considered "street level" for the tileset. The dynamic screen space error
* optimization is intended for when the camera is at street level and pointed at the horizon.
* <p>
* Valid values are between 0.0 and 1.0.
* </p>
*
* @type {number}
* @default 0.25
*/
this.dynamicScreenSpaceErrorHeightFalloff = 0.25;
this.dynamicScreenSpaceErrorHeightFalloff = defaultValue(
options.dynamicScreenSpaceErrorHeightFalloff,
0.25
);

this._dynamicScreenSpaceErrorComputedDensity = 0.0; // Updated based on the camera position and direction
// Updated based on the camera position and direction
this._dynamicScreenSpaceErrorComputedDensity = 0.0;

/**
* Determines whether the tileset casts or receives shadows from light sources.
Expand Down Expand Up @@ -2266,6 +2292,7 @@ const scratchMatrix = new Matrix4();
const scratchCenter = new Cartesian3();
const scratchPosition = new Cartesian3();
const scratchDirection = new Cartesian3();
const scratchHalfHeight = new Cartesian3();

/**
* @private
Expand Down Expand Up @@ -2330,10 +2357,15 @@ function updateDynamicScreenSpaceError(tileset, frameState) {
direction = Cartesian3.normalize(direction, direction);
height = positionLocal.z;
if (tileBoundingVolume instanceof TileOrientedBoundingBox) {
// Assuming z-up, the last component stores the half-height of the box
const boxHeight = root._header.boundingVolume.box[11];
minimumHeight = centerLocal.z - boxHeight;
maximumHeight = centerLocal.z + boxHeight;
// Assuming z-up, the last column
ptrgags marked this conversation as resolved.
Show resolved Hide resolved
const halfHeightVector = Matrix3.getColumn(
boundingVolume.halfAxes,
2,
scratchHalfHeight
);
const halfHeight = Cartesian3.magnitude(halfHeightVector);
minimumHeight = centerLocal.z - halfHeight;
maximumHeight = centerLocal.z + halfHeight;
} else if (tileBoundingVolume instanceof TileBoundingSphere) {
const radius = boundingVolume.radius;
minimumHeight = centerLocal.z - radius;
Expand Down
4 changes: 4 additions & 0 deletions packages/engine/Specs/Scene/PickingSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ describe(
function createTileset(url) {
const options = {
maximumScreenSpaceError: 0,
// The camera is zoomed pretty far out for these tests, so
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I wouldn't expect this to be needed. Why is this needed for 3D Tiles but not terrain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem seemed to be a race condition when waiting for the tileset to load in this particular test setup. I opened #11732 for this since it only seems to affect the unit tests, not the rendering itself.

// turn off dynamicScreenSpaceError so tiles don't get culled
// unintentionally.
dynamicScreenSpaceError: false,
};
return Cesium3DTilesTester.loadTileset(scene, url, options).then(
function (tileset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,11 @@ function Cesium3DTilesInspectorViewModel(scene, performanceContainer) {
return Math.pow(dynamicScreenSpaceErrorDensity(), 1 / 6);
},
set: function (value) {
dynamicScreenSpaceErrorDensity(Math.pow(value, 6));
const scaledValue = Math.pow(value, 6);
ptrgags marked this conversation as resolved.
Show resolved Hide resolved
dynamicScreenSpaceErrorDensity(scaledValue);
if (defined(that._tileset)) {
that._tileset.dynamicScreenSpaceErrorDensity = scaledValue;
}
},
});

Expand Down