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

Scene cleanup in preparation for sampling height #6957

Merged
merged 24 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
99daeb0
Centralize log depth state
lilleyse Jul 11, 2018
1a1e29d
Move WebVR commands to its own function
lilleyse Jul 11, 2018
2570d13
Removed unneeded Cesium3DTileBatchTable code
lilleyse Jul 12, 2018
992ac93
Renamed shadowHints to shadowState
lilleyse Jul 12, 2018
4221992
Separate depth pass from renderTranslucentDepthForPick
lilleyse Jul 12, 2018
059d724
Move useWebVR to environment state
lilleyse Jul 12, 2018
e7e3a63
Check derivedCommands existence in clearer way
lilleyse Jul 12, 2018
4633ea6
Reuse derived commands when switching between log depth and not log d…
lilleyse Jul 14, 2018
ae0a4c1
Compute frustum splits for orthographic uniformly
lilleyse Jul 14, 2018
259c314
Render translucent commands unsorted for pick pass
lilleyse Jul 16, 2018
d392250
Slightly cleanup for stencil commands
lilleyse Jul 17, 2018
4f0cb2f
Added getDepth to PickDepth
lilleyse Jul 19, 2018
505a7d2
Hide individual 3D Tiles features during drill pick
lilleyse Jul 24, 2018
811cfa3
Move PickFramebuffer to scene
lilleyse Aug 1, 2018
991871c
Fix typos
lilleyse Aug 15, 2018
dd6fe0f
Move PickDepthFramebuffer to its own function
lilleyse Aug 5, 2018
e5afdec
Fix eslint
lilleyse Aug 27, 2018
40533dd
Multiple views
lilleyse Aug 15, 2018
51f2b9b
Reorganization
lilleyse Sep 2, 2018
3a3d059
Merge pull request #6958 from AnalyticalGraphicsInc/multiple-views
bagnell Sep 4, 2018
904f683
Custom pick command fix
lilleyse Sep 4, 2018
7c1a5b0
Recreate log depth or regular derived commands if they are needed or …
lilleyse Sep 5, 2018
bef6284
Improve shadow derived command creation. Split up receive from cast
lilleyse Sep 5, 2018
9324cbb
Merge branch 'master' into scene-cleanup
lilleyse Sep 5, 2018
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
2 changes: 1 addition & 1 deletion Source/Core/ApproximateTerrainHeights.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ define([

/**
* Computes the minimum and maximum terrain heights for a given rectangle
* @param {Rectangle} rectangle THe bounding rectangle
* @param {Rectangle} rectangle The bounding rectangle
* @param {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid
* @return {{minimumTerrainHeight: Number, maximumTerrainHeight: Number}}
*/
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/IonGeocoderService.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ define([

var defaultTokenCredit = Ion.getDefaultTokenCredit(accessToken);
if (defined(defaultTokenCredit)) {
options.scene._frameState.creditDisplay.addDefaultCredit(defaultTokenCredit);
options.scene.frameState.creditDisplay.addDefaultCredit(defaultTokenCredit);
}

var searchEndpoint = server.getDerivedResource({
Expand Down
8 changes: 1 addition & 7 deletions Source/Renderer/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ define([
'./CubeMap',
'./DrawCommand',
'./PassState',
'./PickFramebuffer',
'./PixelDatatype',
'./RenderState',
'./ShaderCache',
Expand Down Expand Up @@ -56,7 +55,6 @@ define([
CubeMap,
DrawCommand,
PassState,
PickFramebuffer,
PixelDatatype,
RenderState,
ShaderCache,
Expand Down Expand Up @@ -824,7 +822,7 @@ define([
/**
* Gets an object representing the currently bound framebuffer. While this instance is not an actual
* {@link Framebuffer}, it is used to represent the default framebuffer in calls to
* {@link Texture.FromFramebuffer}.
* {@link Texture.fromFramebuffer}.
* @memberof Context.prototype
* @type {Object}
*/
Expand Down Expand Up @@ -1158,10 +1156,6 @@ define([
});
};

Context.prototype.createPickFramebuffer = function() {
return new PickFramebuffer(this);
};

/**
* Gets the object associated with a pick color.
*
Expand Down
15 changes: 15 additions & 0 deletions Source/Renderer/DrawCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ define([
this._castShadows = defaultValue(options.castShadows, false);
this._receiveShadows = defaultValue(options.receiveShadows, false);
this._pickId = options.pickId;
this._pickOnly = defaultValue(options.pickOnly, false);

this.dirty = true;
this.lastDirtyTime = 0;
Expand Down Expand Up @@ -471,6 +472,19 @@ define([
this.dirty = true;
}
}
},
/**
* Whether this command should be executed in the pick pass only.
*
* @memberof DrawCommand.prototype
* @type {Boolean}
* @default false
* @readonly
*/
pickOnly : {
get : function() {
return this._pickOnly;
}
}
});

Expand Down Expand Up @@ -506,6 +520,7 @@ define([
result._castShadows = command._castShadows;
result._receiveShadows = command._receiveShadows;
result._pickId = command._pickId;
result._pickOnly = command._pickOnly;

result.dirty = true;
result.lastDirtyTime = 0;
Expand Down
2 changes: 1 addition & 1 deletion Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ define([
}

var scene = this._scene;
var globe = scene._globe;
var globe = scene.globe;
var rayIntersection;
var depthIntersection;

Expand Down
11 changes: 0 additions & 11 deletions Source/Scene/Cesium3DTileBatchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1253,21 +1253,17 @@ define([
for (var i = commandStart; i < commandEnd; ++i) {
var command = commandList[i];
var derivedCommands = command.derivedCommands.tileset;
// Command may be marked dirty from Model shader recompilation for clipping planes
if (!defined(derivedCommands) || command.dirty) {
derivedCommands = {};
command.derivedCommands.tileset = derivedCommands;
derivedCommands.originalCommand = deriveCommand(command);
command.dirty = false;
}

updateDerivedCommand(derivedCommands.originalCommand, command);

if (styleCommandsNeeded !== StyleCommandsNeeded.ALL_OPAQUE) {
if (!defined(derivedCommands.translucent)) {
derivedCommands.translucent = deriveTranslucentCommand(derivedCommands.originalCommand);
}
updateDerivedCommand(derivedCommands.translucent, command);
}

if (bivariateVisibilityTest) {
Expand All @@ -1280,7 +1276,6 @@ define([
if (!defined(derivedCommands.stencil) || tile._selectionDepth !== getLastSelectionDepth(derivedCommands.stencil)) {
derivedCommands.stencil = deriveStencilCommand(derivedCommands.originalCommand, tile._selectionDepth);
}
updateDerivedCommand(derivedCommands.stencil, command);
}

var opaqueCommand = bivariateVisibilityTest ? derivedCommands.stencil : derivedCommands.originalCommand;
Expand Down Expand Up @@ -1316,12 +1311,6 @@ define([
}
};

function updateDerivedCommand(derivedCommand, command) {
derivedCommand.castShadows = command.castShadows;
derivedCommand.receiveShadows = command.receiveShadows;
derivedCommand.primitiveType = command.primitiveType;
}

function getStyleCommandsNeeded(batchTable) {
var translucentFeaturesLength = batchTable._translucentFeaturesLength;

Expand Down
9 changes: 6 additions & 3 deletions Source/Scene/ClassificationPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,8 @@ define([
if (!defined(command)) {
command = pickCommands[j] = new DrawCommand({
owner : classificationPrimitive,
primitiveType : primitive._primitiveType
primitiveType : primitive._primitiveType,
pickOnly : true
});
}

Expand All @@ -820,7 +821,8 @@ define([
if (!defined(command)) {
command = pickCommands[j + 1] = new DrawCommand({
owner : classificationPrimitive,
primitiveType : primitive._primitiveType
primitiveType : primitive._primitiveType,
pickOnly : true
});
}

Expand All @@ -838,7 +840,8 @@ define([
if (!defined(command)) {
command = pickCommands[j + 2] = new DrawCommand({
owner : classificationPrimitive,
primitiveType : primitive._primitiveType
primitiveType : primitive._primitiveType,
pickOnly : true
});
}

Expand Down
3 changes: 2 additions & 1 deletion Source/Scene/DepthPlane.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,15 @@ define([
return depthQuadScratch;
}

DepthPlane.prototype.update = function(frameState, useLogDepth) {
DepthPlane.prototype.update = function(frameState) {
this._mode = frameState.mode;
if (frameState.mode !== SceneMode.SCENE3D) {
return;
}

var context = frameState.context;
var ellipsoid = frameState.mapProjection.ellipsoid;
var useLogDepth = frameState.useLogDepth;

if (!defined(this._command)) {
this._rs = RenderState.fromCache({ // Write depth, not color
Expand Down
10 changes: 3 additions & 7 deletions Source/Scene/EllipsoidPrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ define([
'../Core/destroyObject',
'../Core/DeveloperError',
'../Core/Matrix4',
'../Core/OrthographicFrustum',
'../Core/OrthographicOffCenterFrustum',
'../Core/VertexFormat',
'../Renderer/BufferUsage',
'../Renderer/DrawCommand',
Expand All @@ -34,8 +32,6 @@ define([
destroyObject,
DeveloperError,
Matrix4,
OrthographicFrustum,
OrthographicOffCenterFrustum,
VertexFormat,
BufferUsage,
DrawCommand,
Expand Down Expand Up @@ -213,7 +209,8 @@ define([
owner : defaultValue(options._owner, this)
});
this._pickCommand = new DrawCommand({
owner : defaultValue(options._owner, this)
owner : defaultValue(options._owner, this),
pickOnly : true
});

var that = this;
Expand Down Expand Up @@ -354,8 +351,7 @@ define([
var lightingChanged = this.onlySunLighting !== this._onlySunLighting;
this._onlySunLighting = this.onlySunLighting;

var frustum = frameState.camera.frustum;
var useLogDepth = context.fragmentDepth && !(frustum instanceof OrthographicFrustum || frustum instanceof OrthographicOffCenterFrustum);
var useLogDepth = frameState.useLogDepth;
var useLogDepthChanged = this._useLogDepth !== useLogDepth;
this._useLogDepth = useLogDepth;

Expand Down
19 changes: 18 additions & 1 deletion Source/Scene/FrameState.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ define([
* @default false
*/
render : false,

/**
* <code>true</code> if the primitive should update for a picking pass, <code>false</code> otherwise.
*
Expand Down Expand Up @@ -232,7 +233,7 @@ define([
*/
this.terrainExaggeration = 1.0;

this.shadowHints = {
this.shadowState = {
/**
* Whether there are any active shadow maps this frame.
* @type {Boolean}
Expand Down Expand Up @@ -330,6 +331,22 @@ define([
* @type {Color}
*/
this.invertClassificationColor = undefined;

/**
* Whether or not the scene uses a logarithmic depth buffer.
*
* @type {Boolean}
* @default false
*/
this.useLogDepth = false;

/**
* Whether or not the scene's logarithmic depth buffer usage changed since last frame.
*
* @type {Boolean}
* @default false
*/
this.useLogDepthDirty = false;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Source/Scene/GlobeDepth.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ define([
executeDebugGlobeDepth(this, context, passState, useLogDepth);
};

GlobeDepth.prototype.update = function(context, passState) {
var width = context.drawingBufferWidth;
var height = context.drawingBufferHeight;
GlobeDepth.prototype.update = function(context, passState, viewport) {
var width = viewport.width;
var height = viewport.height;

updateFramebuffers(this, context, width, height);
updateCopyCommands(this, context, width, height, passState);
Expand Down
4 changes: 2 additions & 2 deletions Source/Scene/OIT.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ define([
var framebuffer = passState.framebuffer;
var length = commands.length;

var lightShadowsEnabled = scene.frameState.shadowHints.lightShadowsEnabled;
var lightShadowsEnabled = scene.frameState.shadowState.lightShadowsEnabled;

passState.framebuffer = oit._adjustTranslucentFBO;
oit._adjustTranslucentCommand.execute(context, passState);
Expand Down Expand Up @@ -588,7 +588,7 @@ define([
var framebuffer = passState.framebuffer;
var length = commands.length;

var lightShadowsEnabled = scene.frameState.shadowHints.lightShadowsEnabled;
var lightShadowsEnabled = scene.frameState.shadowState.lightShadowsEnabled;

passState.framebuffer = oit._adjustTranslucentFBO;
oit._adjustTranslucentCommand.execute(context, passState);
Expand Down
29 changes: 24 additions & 5 deletions Source/Scene/PickDepth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
define([
'../Core/Cartesian4',
'../Core/defined',
'../Core/destroyObject',
'../Core/PixelFormat',
Expand All @@ -8,6 +9,7 @@ define([
'../Renderer/ShaderSource',
'../Renderer/Texture'
], function(
Cartesian4,
defined,
destroyObject,
PixelFormat,
Expand All @@ -22,7 +24,7 @@ define([
* @private
*/
function PickDepth() {
this.framebuffer = undefined;
this._framebuffer = undefined;

this._depthTexture = undefined;
this._textureToCopy = undefined;
Expand Down Expand Up @@ -73,7 +75,7 @@ define([
}

function destroyFramebuffers(pickDepth) {
pickDepth.framebuffer = pickDepth.framebuffer && !pickDepth.framebuffer.isDestroyed() && pickDepth.framebuffer.destroy();
pickDepth._framebuffer = pickDepth._framebuffer && !pickDepth._framebuffer.isDestroyed() && pickDepth._framebuffer.destroy();
}

function createTextures(pickDepth, context, width, height) {
Expand All @@ -92,7 +94,7 @@ define([

createTextures(pickDepth, context, width, height);

pickDepth.framebuffer = new Framebuffer({
pickDepth._framebuffer = new Framebuffer({
context : context,
colorTextures : [pickDepth._depthTexture],
destroyAttachments : false
Expand All @@ -105,7 +107,7 @@ define([

var texture = pickDepth._depthTexture;
var textureChanged = !defined(texture) || texture.width !== width || texture.height !== height;
if (!defined(pickDepth.framebuffer) || textureChanged) {
if (!defined(pickDepth._framebuffer) || textureChanged) {
createFramebuffers(pickDepth, context, width, height);
}
}
Expand All @@ -131,7 +133,7 @@ define([
}

pickDepth._textureToCopy = depthTexture;
pickDepth._copyDepthCommand.framebuffer = pickDepth.framebuffer;
pickDepth._copyDepthCommand.framebuffer = pickDepth._framebuffer;
}

PickDepth.prototype.executeDebugPickDepth = function(context, passState, useLogDepth) {
Expand All @@ -143,6 +145,23 @@ define([
updateCopyCommands(this, context, depthTexture);
};

var scratchPackedDepth = new Cartesian4();
var packedDepthScale = new Cartesian4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 16581375.0);

PickDepth.prototype.getDepth = function(context, x, y) {
var pixels = context.readPixels({
x : x,
y : y,
width : 1,
height : 1,
framebuffer : this._framebuffer
});

var packedDepth = Cartesian4.unpack(pixels, 0, scratchPackedDepth);
Cartesian4.divideByScalar(packedDepth, 255.0, packedDepth);
return Cartesian4.dot(packedDepth, packedDepthScale);
};

PickDepth.prototype.executeCopyDepth = function(context, passState) {
this._copyDepthCommand.execute(context, passState);
};
Expand Down
Loading