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

SSE Independent from Resolution Density & Cesium Renders at Screen Res #8083

Merged
merged 15 commits into from
Aug 23, 2019
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ Change Log

##### Additions :tada:
* Added optional `index` parameter to `PrimitiveCollection.add`. [#8041](https://github.com/AnalyticalGraphicsInc/cesium/pull/8041)
* Updated to render at the browser max resolution. Set `viewer.resolutionScale = 1.0 / window.devicePixelRatio` to render at lower pixel density. [#8082](https://github.com/AnalyticalGraphicsInc/cesium/issues/8082)
ProjectBarks marked this conversation as resolved.
Show resolved Hide resolved

##### Fixes :wrench:
* Fixed a crash when a glTF model used `KHR_texture_transform` without a sampler defined. [#7916](https://github.com/AnalyticalGraphicsInc/cesium/issues/7916)
* Fixed post-processing selection filtering to work for bloom. [#7984](https://github.com/AnalyticalGraphicsInc/cesium/issues/7984)
* Disabled HDR by default to improve visual quality in most standard use cases. Set `viewer.scene.highDynamicRange = true` to re-enable. [#7966](https://github.com/AnalyticalGraphicsInc/cesium/issues/7966)
* Fixed a bug that causes hidden point primitives to still appear on some operating systems. [#8043](https://github.com/AnalyticalGraphicsInc/cesium/issues/8043)
* Fixed issue where KTX or CRN files would not be properly identified. [#7979](https://github.com/AnalyticalGraphicsInc/cesium/issues/7979)
* Fixed loading Cesium 3DTiles at different resolutions. [#8082](https://github.com/AnalyticalGraphicsInc/cesium/issues/8082)
ProjectBarks marked this conversation as resolved.
Show resolved Hide resolved

### 1.60 - 2019-08-01

Expand Down
3 changes: 3 additions & 0 deletions Source/Scene/Cesium3DTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,9 @@ define([
error -= dynamicError;
}
}

error /= frameState.screenSpaceErrorPixelRatio;

return error;
};

Expand Down
9 changes: 9 additions & 0 deletions Source/Scene/FrameState.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ define([
*/
this.maximumScreenSpaceError = undefined;

/**
* The factor at which all Screen Space Error is scaled. This accounts for a difference in screen
* density to decouple SSE from effective resolution.
*
* @type {Number}
* @default 1.0
*/
this.screenSpaceErrorPixelRatio = 1.0;

this.passes = {
/**
* <code>true</code> if the primitive should update for a render pass, <code>false</code> otherwise.
Expand Down
8 changes: 5 additions & 3 deletions Source/Scene/QuadtreePrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -994,10 +994,10 @@ define([
var error = (maxGeometricError * height) / (distance * sseDenominator);

if (frameState.fog.enabled) {
error = error - CesiumMath.fog(distance, frameState.fog.density) * frameState.fog.sse;
error -= CesiumMath.fog(distance, frameState.fog.density) * frameState.fog.sse;
}

return error;
return error /= frameState.screenSpaceErrorPixelRatio;
ProjectBarks marked this conversation as resolved.
Show resolved Hide resolved
}

function screenSpaceError2D(primitive, frameState, tile) {
Expand All @@ -1016,9 +1016,11 @@ define([
var error = maxGeometricError / pixelSize;

if (frameState.fog.enabled && frameState.mode !== SceneMode.SCENE2D) {
error = error - CesiumMath.fog(tile._distance, frameState.fog.density) * frameState.fog.sse;
error -= CesiumMath.fog(tile._distance, frameState.fog.density) * frameState.fog.sse;
}

error /= frameState.screenSpaceErrorPixelRatio;

return error;
}

Expand Down
12 changes: 12 additions & 0 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,16 @@ define([
*/
this.cameraEventWaitTime = 500.0;

/**
* The factor at which all Screen Space Error is scaled. This accounts for a difference in screen
* density to decouple SSE from effective resolution.
*
* @type {Number}
* @default 1.0
* @private
*/
this.screenSpaceErrorPixelRatio = 1.0;

/**
* Blends the atmosphere to geometry far from the camera for horizon views. Allows for additional
* performance improvements by rendering less geometry and dispatching less terrain requests.
Expand Down Expand Up @@ -1805,6 +1815,8 @@ define([
frameState.maximumScreenSpaceError = 2;
}

frameState.screenSpaceErrorPixelRatio = scene.screenSpaceErrorPixelRatio;

clearPasses(frameState.passes);

frameState.tilesetPassState = undefined;
Expand Down
22 changes: 16 additions & 6 deletions Source/Widgets/CesiumWidget/CesiumWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,21 @@ define([
requestAnimationFrame(render);
}

function configureSceneResolution(widget) {
var devicePixelRatio = window.devicePixelRatio;
var resolutionScale = widget._resolutionScale * devicePixelRatio;
if (defined(widget._scene)) {
widget._scene.screenSpaceErrorPixelRatio = resolutionScale;
}

return resolutionScale;
}

function configureCanvasSize(widget) {
var canvas = widget._canvas;
var width = canvas.clientWidth;
var height = canvas.clientHeight;
var resolutionScale = widget._resolutionScale;
if (!widget._supportsImageRenderingPixelated) {
resolutionScale *= defaultValue(window.devicePixelRatio, 1.0);
}
var resolutionScale = configureSceneResolution(widget);

widget._canvasWidth = width;
widget._canvasHeight = height;
Expand All @@ -114,6 +121,7 @@ define([
canvas.height = height;

widget._canRender = width !== 0 && height !== 0;
widget._lastDevicePixelRatio = devicePixelRatio;
}

function configureCameraFrustum(widget) {
Expand Down Expand Up @@ -240,6 +248,7 @@ define([
this._canvas = canvas;
this._canvasWidth = 0;
this._canvasHeight = 0;
this._lastDevicePixelRatio = 0;
this._creditViewport = creditViewport;
this._creditContainer = creditContainer;
this._innerCreditContainer = innerCreditContainer;
Expand Down Expand Up @@ -271,6 +280,7 @@ define([

scene.camera.constrainedAxis = Cartesian3.UNIT_Z;

configureSceneResolution(this);
configureCameraFrustum(this);

var ellipsoid = defaultValue(scene.mapProjection.ellipsoid, Ellipsoid.WGS84);
Expand Down Expand Up @@ -562,8 +572,8 @@ define([
throw new DeveloperError('resolutionScale must be greater than 0.');
}
//>>includeEnd('debug');
this._resolutionScale = value;
this._forceResize = true;
this._resolutionScale = value;
}
}
});
Expand Down Expand Up @@ -672,7 +682,7 @@ define([
var canvas = this._canvas;
var width = canvas.clientWidth;
var height = canvas.clientHeight;
if (!this._forceResize && this._canvasWidth === width && this._canvasHeight === height) {
if (!this._forceResize && this._canvasWidth === width && this._canvasHeight === height && this._lastDevicePixelRatio === window.devicePixelRatio) {
return;
}
this._forceResize = false;
Expand Down
8 changes: 3 additions & 5 deletions Source/Widgets/Viewer/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,6 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
this._needTrackedEntityUpdate = false;
this._selectedEntity = undefined;
this._clockTrackedDataSource = undefined;
this._forceResize = false;
this._zoomIsFlight = false;
this._zoomTarget = undefined;
this._zoomPromise = undefined;
Expand Down Expand Up @@ -1195,7 +1194,6 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
},
set : function(value) {
this._cesiumWidget.resolutionScale = value;
this._forceResize = true;
}
},

Expand Down Expand Up @@ -1359,12 +1357,12 @@ Either specify options.terrainProvider instead or set options.baseLayerPicker to
var animationExists = defined(this._animation);
var timelineExists = defined(this._timeline);

if (!this._forceResize && width === this._lastWidth && height === this._lastHeight) {
cesiumWidget.resize();
ProjectBarks marked this conversation as resolved.
Show resolved Hide resolved

if (width === this._lastWidth && height === this._lastHeight) {
return;
}

cesiumWidget.resize();
this._forceResize = false;
var panelMaxHeight = height - 125;
var baseLayerPickerDropDown = this._baseLayerPickerDropDown;

Expand Down
4 changes: 3 additions & 1 deletion Specs/Scene/Cesium3DTilesetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2228,12 +2228,14 @@ defineSuite([

// Check that the feature is red
var sourceRed;
var sourceGreen;
var renderOptions = {
scene : scene,
time : new JulianDate(2457522.154792)
};
expect(renderOptions).toRenderAndCall(function(rgba) {
sourceRed = rgba[0];
sourceGreen = rgba[1];
});

expect(renderOptions).toRenderAndCall(function(rgba) {
Expand Down Expand Up @@ -2318,7 +2320,7 @@ defineSuite([
mixGreen = rgba[1];
expect(rgba[0]).toBeGreaterThan(replaceRed);
expect(rgba[0]).toBeLessThan(sourceRed);
expect(rgba[1]).toBeGreaterThan(50);
expect(rgba[1]).toBeGreaterThan(sourceGreen);
expect(rgba[1]).toBeLessThan(replaceGreen);
expect(rgba[2]).toBeLessThan(25);
expect(rgba[3]).toEqual(255);
Expand Down
3 changes: 2 additions & 1 deletion Specs/Scene/QuadtreePrimitiveSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ defineSuite([
mode: SceneMode.SCENE3D,
commandList: [],
cullingVolume: jasmine.createSpyObj('CullingVolume', ['computeVisibility']),
afterRender: []
afterRender: [],
screenSpaceErrorPixelRatio: 1.0
ProjectBarks marked this conversation as resolved.
Show resolved Hide resolved
};

frameState.cullingVolume.computeVisibility.and.returnValue(Intersect.INTERSECTING);
Expand Down