Skip to content

Commit

Permalink
If command is not pickable, write depth.
Browse files Browse the repository at this point in the history
  • Loading branch information
bagnell committed Apr 10, 2018
1 parent bca8eda commit 1599d31
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 110 deletions.
48 changes: 0 additions & 48 deletions Source/Scene/GlobeSurfaceShaderSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ define([
this.baseFragmentShaderSource = undefined;

this._shadersByTexturesFlags = [];
this._pickShaderPrograms = [];

this.material = undefined;
}
Expand Down Expand Up @@ -229,45 +228,6 @@ define([
return surfaceShader.shaderProgram;
};

GlobeSurfaceShaderSet.prototype.getPickShaderProgram = function(frameState, surfaceTile, useWebMercatorProjection) {
var quantization = 0;
var quantizationDefine = '';

var terrainEncoding = surfaceTile.pickTerrain.mesh.encoding;
var quantizationMode = terrainEncoding.quantization;
if (quantizationMode === TerrainQuantization.BITS12) {
quantization = 1;
quantizationDefine = 'QUANTIZATION_BITS12';
}

var sceneMode = frameState.mode;
var flags = sceneMode | (useWebMercatorProjection << 2) | (quantization << 3);
var pickShader = this._pickShaderPrograms[flags];

if (!defined(pickShader)) {
var vs = this.baseVertexShaderSource.clone();
vs.defines.push(quantizationDefine);
vs.sources.push(getPositionMode(sceneMode));
vs.sources.push(get2DYPositionFraction(useWebMercatorProjection));

// pass through fragment shader. only depth is rendered for the globe on a pick pass
var fs =
'void main()\n' +
'{\n' +
' gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);\n' +
'}\n';

pickShader = this._pickShaderPrograms[flags] = ShaderProgram.fromCache({
context : frameState.context,
vertexShaderSource : vs,
fragmentShaderSource : fs,
attributeLocations : terrainEncoding.getAttributeLocations()
});
}

return pickShader;
};

GlobeSurfaceShaderSet.prototype.destroy = function() {
var flags;
var shader;
Expand All @@ -291,14 +251,6 @@ define([
}
}

var pickShaderPrograms = this._pickShaderPrograms;
for (flags in pickShaderPrograms) {
if (pickShaderPrograms.hasOwnProperty(flags)) {
shader = pickShaderPrograms[flags];
shader.destroy();
}
}

return destroyObject(this);
};

Expand Down
53 changes: 2 additions & 51 deletions Source/Scene/GlobeSurfaceTileProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ define([

this._renderState = undefined;
this._blendRenderState = undefined;
this._pickRenderState = undefined;

this._errorEvent = new Event();

Expand All @@ -152,9 +151,7 @@ define([
this._tilesToRenderByTextureCount = [];
this._drawCommands = [];
this._uniformMaps = [];
this._pickCommands = [];
this._usedDrawCommands = 0;
this._usedPickCommands = 0;

this._vertexArraysToDestroy = [];

Expand Down Expand Up @@ -469,26 +466,10 @@ define([
* @param {FrameState} frameState The frame state.
*/
GlobeSurfaceTileProvider.prototype.updateForPick = function(frameState) {
if (!defined(this._pickRenderState)) {
this._pickRenderState = RenderState.fromCache({
colorMask : {
red : false,
green : false,
blue : false,
alpha : false
},
depthTest : {
enabled : true
}
});
}

this._usedPickCommands = 0;
var drawCommands = this._drawCommands;

// Add the tile pick commands from the tiles drawn last frame.
var drawCommands = this._drawCommands;
for (var i = 0, length = this._usedDrawCommands; i < length; ++i) {
addPickCommandsForTile(this, drawCommands[i], frameState);
frameState.commandList.push(drawCommands[i]);
}
};

Expand Down Expand Up @@ -1417,35 +1398,5 @@ define([
} while (imageryIndex < imageryLen);
}

function addPickCommandsForTile(tileProvider, drawCommand, frameState) {
var pickCommand;
if (tileProvider._pickCommands.length <= tileProvider._usedPickCommands) {
pickCommand = new DrawCommand();
pickCommand.cull = false;

tileProvider._pickCommands.push(pickCommand);
} else {
pickCommand = tileProvider._pickCommands[tileProvider._usedPickCommands];
}

++tileProvider._usedPickCommands;

var surfaceTile = drawCommand.owner.data;
var useWebMercatorProjection = frameState.projection instanceof WebMercatorProjection;

pickCommand.shaderProgram = tileProvider._surfaceShaderSet.getPickShaderProgram(frameState, surfaceTile, useWebMercatorProjection);
pickCommand.renderState = tileProvider._pickRenderState;

pickCommand.owner = drawCommand.owner;
pickCommand.primitiveType = drawCommand.primitiveType;
pickCommand.vertexArray = drawCommand.vertexArray;
pickCommand.uniformMap = drawCommand.uniformMap;
pickCommand.boundingVolume = drawCommand.boundingVolume;
pickCommand.orientedBoundingBox = drawCommand.orientedBoundingBox;
pickCommand.pass = drawCommand.pass;

frameState.commandList.push(pickCommand);
}

return GlobeSurfaceTileProvider;
});
39 changes: 28 additions & 11 deletions Source/Scene/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -1513,7 +1513,9 @@ define([
derivedCommands = logDepthDerivedCommands;
}

derivedCommands.picking = createPickDerivedCommand(command, context, derivedCommands.picking);
if (defined(command.pickId)) {
derivedCommands.picking = createPickDerivedCommand(command, context, derivedCommands.picking);
}

var oit = scene._oit;
if (command.pass === Pass.TRANSLUCENT && defined(oit) && oit.isSupported()) {
Expand Down Expand Up @@ -2023,20 +2025,24 @@ define([
command = command.derivedCommands.logDepth.logDepthCommand;
}

if (frameState.passes.pick && defined(command.derivedCommands.picking)) {
command = command.derivedCommands.picking.pickCommand;
var passes = frameState.passes;
if (passes.pick || passes.depth) {
if (passes.pick && defined(command.derivedCommands.picking)) {
command = command.derivedCommands.picking.pickCommand;
command.execute(context, passState);
return;
} else if (defined(command.derivedCommands.depth)) {
command = command.derivedCommands.depth.depthOnlyCommand;
command.execute(context, passState);
return;
}
}

if (scene.debugShowCommands || scene.debugShowFrustums) {
executeDebugCommand(command, scene, passState);
return;
}

if (frameState.passes.depth && defined(command.derivedCommands.depth)) {
command.derivedCommands.depth.depthOnlyCommand.execute(context, passState);
return;
}

var shadowsEnabled = scene.frameState.shadowHints.shadowsEnabled;
var lightShadowsEnabled = shadowsEnabled && (scene.frameState.shadowHints.lightShadowMaps.length > 0);

Expand Down Expand Up @@ -2421,10 +2427,21 @@ define([
commands = frustumCommands.commands[j];
length = frustumCommands.indices[j];
for (var k = 0; k < length; ++k) {
// PER ENTITY TODO
var command = commands[k];
if (defined(command.derivedCommands.pickCommand)) {
command.derivedCommands.pickCommand.execute(context, passState);
if (!defined(command.derivedCommands)) {
continue;
}

if (scene._logDepthBuffer && defined(command.derivedCommands.logDepth)) {
command = command.derivedCommands.logDepth.logDepthCommand;
}

if (defined(command.derivedCommands.picking)) {
command = command.derivedCommands.picking.pickCommand;
command.execute(context, passState);
} else if (defined(command.derivedCommands.depth)) {
command = command.derivedCommands.depth.depthOnlyCommand;
command.execute(context, passState);
}
}
}
Expand Down

0 comments on commit 1599d31

Please sign in to comment.