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

Primitive picking #1524

Merged
merged 6 commits into from
Mar 4, 2014
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Change Log
Beta Releases
-------------

### b27 - 2014-04-01

* Breaking changes:
* ...
* Fixed Primitive picking that have a closed appearance drawn on the surface. [#1333](https://github.com/AnalyticalGraphicsInc/cesium/issues/1333)

### b26 - 2014-03-03

* Breaking changes:
Expand Down
52 changes: 38 additions & 14 deletions Source/Scene/Primitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ define([
this._backFaceRS = undefined;
this._sp = undefined;

this._pickRS = undefined;
this._pickBackFaceRS = undefined;
this._pickFrontFaceRS= undefined;
this._pickSP = undefined;
this._pickIds = [];

Expand Down Expand Up @@ -764,9 +765,10 @@ define([

if (createRS) {
var renderState = appearance.getRenderState();
var rs;

if (twoPasses) {
var rs = clone(renderState, false);
rs = clone(renderState, false);
rs.cull = {
enabled : true,
face : CullFace.BACK
Expand All @@ -781,18 +783,30 @@ define([
}

if (allowPicking) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It was probably my idea, but another problem with the old approach is that if another object occluded the backfaces but not the front, this object would not get picked (or picked first with drill picking).

// Only need backface pass for picking when two-pass rendering is used.
this._pickRS = this._backFaceRS;
this._pickBackFaceRS = this._backFaceRS;
this._pickFrontFaceRS = this._frontFaceRS;
} else {
// Still occlude if not pickable.
var pickRS = clone(renderState, false);
pickRS.colorMask = {
rs = clone(renderState, false);
renderState.colorMask = {
red : false,
green : false,
blue : false,
alpha : false
};
this._pickRS = context.createRenderState(pickRS);

if (twoPasses) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry - one more idea here that is closer to your original fix.

If twoPasses is true, why not just render the pick pass in a single pass with no culling? If it is false, render the pick pass without changing the culling state. The multi-pass technique used here is only useful to get blending right, which doesn't matter when picking.

rs.cull = {
enabled : true,
face : CullFace.BACK
};
this._pickFrontFaceRS = context.createRenderState(rs);

rs.cull.face = CullFace.FRONT;
this._pickBackFaceRS = context.createRenderState(rs);
} else {
this._pickFrontFaceRS = context.createRenderState(renderState);
this._pickBackFaceRS = this._pickFrontFaceRS;
}
}
}

Expand Down Expand Up @@ -823,11 +837,10 @@ define([
var pass = translucent ? Pass.TRANSLUCENT : Pass.OPAQUE;

colorCommands.length = this._va.length * (twoPasses ? 2 : 1);
pickCommands.length = this._va.length;
pickCommands.length = this._va.length * (twoPasses ? 2 : 1);

length = colorCommands.length;
var vaIndex = 0;
var m = 0;
for (i = 0; i < length; ++i) {
if (twoPasses) {
colorCommand = colorCommands[i];
Expand All @@ -842,6 +855,18 @@ define([
colorCommand.uniformMap = uniforms;
colorCommand.pass = pass;

pickCommand = pickCommands[i];
if (!defined(pickCommand)) {
pickCommand = pickCommands[i] = new DrawCommand();
}
pickCommand.owner = this;
pickCommand.primitiveType = this._primitiveType;
pickCommand.vertexArray = this._va[vaIndex];
pickCommand.renderState = this._pickBackFaceRS;
pickCommand.shaderProgram = this._pickSP;
pickCommand.uniformMap = uniforms;
pickCommand.pass = pass;

++i;
}

Expand All @@ -857,18 +882,17 @@ define([
colorCommand.uniformMap = uniforms;
colorCommand.pass = pass;

pickCommand = pickCommands[m];
pickCommand = pickCommands[i];
if (!defined(pickCommand)) {
pickCommand = pickCommands[m] = new DrawCommand();
pickCommand = pickCommands[i] = new DrawCommand();
}
pickCommand.owner = this;
pickCommand.primitiveType = this._primitiveType;
pickCommand.vertexArray = this._va[vaIndex];
pickCommand.renderState = this._pickRS;
pickCommand.renderState = this._pickFrontFaceRS;
pickCommand.shaderProgram = this._pickSP;
pickCommand.uniformMap = uniforms;
pickCommand.pass = pass;
++m;

++vaIndex;
}
Expand Down