Skip to content

Commit

Permalink
Rename and add blend option to label collection.
Browse files Browse the repository at this point in the history
  • Loading branch information
bagnell committed Jan 26, 2017
1 parent 19720fa commit 54b87ab
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 54 deletions.
39 changes: 20 additions & 19 deletions Source/Scene/BillboardCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ define([
'../Shaders/BillboardCollectionFS',
'../Shaders/BillboardCollectionVS',
'./Billboard',
'./BillboardRenderTechnique',
'./BlendingState',
'./BlendOption',
'./HeightReference',
'./HorizontalOrigin',
'./SceneMode',
Expand Down Expand Up @@ -62,8 +62,8 @@ define([
BillboardCollectionFS,
BillboardCollectionVS,
Billboard,
BillboardRenderTechnique,
BlendingState,
BlendOption,
HeightReference,
HorizontalOrigin,
SceneMode,
Expand Down Expand Up @@ -135,9 +135,9 @@ define([
* @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms each billboard from model to world coordinates.
* @param {Boolean} [options.debugShowBoundingVolume=false] For debugging only. Determines if this primitive's commands' bounding spheres are shown.
* @param {Scene} [options.scene] Must be passed in for billboards that use the height reference property or will be depth tested against the globe.
* @param {BillboardRenderTechnique} [options.renderTechnique=BillboardRenderTechnique.OPAQUE_AND_TRANSLUCENT] The billboard rendering technique. The default
* @param {BlendOption} [options.blendOption=BlendOption.OPAQUE_AND_TRANSLUCENT] The billboard blending option. The default
* is used for rendering both opaque and translucent billboards. However, if either all of the billboards are completely opaque or all are completely translucent,
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve performance by 2x.
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve performance by up to 2x.
*
* @performance For best performance, prefer a few collections, each with many billboards, to
* many collections with only a few billboards each. Organize collections so that billboards
Expand Down Expand Up @@ -276,14 +276,15 @@ define([
this.debugShowBoundingVolume = defaultValue(options.debugShowBoundingVolume, false);

/**
* The billboard rendering technique. The default is used for rendering both opaque and translucent billboards.
* The billboard blending option. The default is used for rendering both opaque and translucent billboards.
* However, if either all of the billboards are completely opaque or all are completely translucent,
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve performance by 2x.
* @type {BillboardRenderTechnique}
* @default BillboardRenderTechnique.OPAQUE_AND_TRANSLUCENT
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve
* performance by up to 2x.
* @type {BlendOption}
* @default BlendOption.OPAQUE_AND_TRANSLUCENT
*/
this.renderTechnique = defaultValue(options.renderTechnique, BillboardRenderTechnique.OPAQUE_AND_TRANSLUCENT);
this._renderTechnique = undefined;
this.blendOption = defaultValue(options.blendOption, BlendOption.OPAQUE_AND_TRANSLUCENT);
this._blendOption = undefined;

this._mode = SceneMode.SCENE3D;

Expand Down Expand Up @@ -1444,10 +1445,10 @@ define([
}
updateBoundingVolume(this, frameState, boundingVolume);

var techniqueChanged = this._renderTechnique !== this.renderTechnique;
this._renderTechnique = this.renderTechnique;
var blendOptionChanged = this._blendOption !== this.blendOption;
this._blendOption = this.blendOption;

if (techniqueChanged) {
if (blendOptionChanged) {
this._rsOpaque = RenderState.fromCache({
depthTest : {
enabled : true,
Expand All @@ -1456,7 +1457,7 @@ define([
depthMask : true
});

if (this._renderTechnique === BillboardRenderTechnique.TRANSLUCENT || this._renderTechnique === BillboardRenderTechnique.OPAQUE_AND_TRANSLUCENT) {
if (this._blendOption === BlendOption.TRANSLUCENT || this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT) {
this._rsTranslucent = RenderState.fromCache({
depthTest : {
enabled : true,
Expand All @@ -1470,7 +1471,7 @@ define([
}
}

if (techniqueChanged ||
if (blendOptionChanged ||
(this._shaderRotation !== this._compiledShaderRotation) ||
(this._shaderAlignedAxis !== this._compiledShaderAlignedAxis) ||
(this._shaderScaleByDistance !== this._compiledShaderScaleByDistance) ||
Expand Down Expand Up @@ -1503,7 +1504,7 @@ define([
vs.defines.push('DISTANCE_DISPLAY_CONDITION');
}

if (this._renderTechnique === BillboardRenderTechnique.OPAQUE || this._renderTechnique === BillboardRenderTechnique.OPAQUE_AND_TRANSLUCENT) {
if (this._blendOption === BlendOption.OPAQUE || this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT) {
fs = new ShaderSource({
defines : ['OPAQUE'],
sources : [BillboardCollectionFS]
Expand All @@ -1520,7 +1521,7 @@ define([
this._sp = undefined;
}

if (this._renderTechnique === BillboardRenderTechnique.TRANSLUCENT || this._renderTechnique === BillboardRenderTechnique.OPAQUE_AND_TRANSLUCENT) {
if (this._blendOption === BlendOption.TRANSLUCENT || this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT) {
fs = new ShaderSource({
defines : ['TRANSLUCENT'],
sources : [BillboardCollectionFS]
Expand Down Expand Up @@ -1612,8 +1613,8 @@ define([
if (pass.render) {
var colorList = this._colorCommands;

var opaque = this._renderTechnique === BillboardRenderTechnique.OPAQUE;
var opaqueAndTranslucent = this._renderTechnique === BillboardRenderTechnique.OPAQUE_AND_TRANSLUCENT;
var opaque = this._blendOption === BlendOption.OPAQUE;
var opaqueAndTranslucent = this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT;

va = this._vaf.va;
vaLength = va.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@ define([
'use strict';

/**
* Determines how billboards and points are rendered.
* Determines how billboards, points, and labels are rendered.
*
* @exports BillboardRenderTechnique
*/
var BillboardRenderTechnique = {
var BlendOption = {
/**
* The billboards in the collection are completely opaque.
* The billboards, points, or labels in the collection are completely opaque.
* @type {Number}
* @constant
*/
OPAQUE : 0,

/**
* The billboards in the collection are completely translucent.
* The billboards, points, or labels in the collection are completely translucent.
* @type {Number}
* @constant
*/
TRANSLUCENT : 1,

/**
* The billboards in the collection are both opaque and translucent.
* The billboards, points, or labels in the collection are both opaque and translucent.
* @type {Number}
* @constant
*/
OPAQUE_AND_TRANSLUCENT : 2
};

return freezeObject(BillboardRenderTechnique);
return freezeObject(BlendOption);
});
17 changes: 17 additions & 0 deletions Source/Scene/LabelCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ define([
'../Core/Matrix4',
'../Core/writeTextToCanvas',
'./BillboardCollection',
'./BlendOption',
'./HorizontalOrigin',
'./Label',
'./LabelStyle',
Expand All @@ -28,6 +29,7 @@ define([
Matrix4,
writeTextToCanvas,
BillboardCollection,
BlendOption,
HorizontalOrigin,
Label,
LabelStyle,
Expand Down Expand Up @@ -440,6 +442,9 @@ define([
* @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms each label from model to world coordinates.
* @param {Boolean} [options.debugShowBoundingVolume=false] For debugging only. Determines if this primitive's commands' bounding spheres are shown.
* @param {Scene} [options.scene] Must be passed in for labels that use the height reference property or will be depth tested against the globe.
* @param {BlendOption} [options.blendOption=BlendOption.OPAQUE_AND_TRANSLUCENT] The label blending option. The default
* is used for rendering both opaque and translucent labels. However, if either all of the labels are completely opaque or all are completely translucent,
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve performance by up to 2x.
*
* @performance For best performance, prefer a few collections, each with many labels, to
* many collections with only a few labels each. Avoid having collections where some
Expand Down Expand Up @@ -533,6 +538,16 @@ define([
* @default false
*/
this.debugShowBoundingVolume = defaultValue(options.debugShowBoundingVolume, false);

/**
* The label blending option. The default is used for rendering both opaque and translucent labels.
* However, if either all of the labels are completely opaque or all are completely translucent,
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve
* performance by up to 2x.
* @type {BlendOption}
* @default BlendOption.OPAQUE_AND_TRANSLUCENT
*/
this.blendOption = defaultValue(options.blendOption, BlendOption.OPAQUE_AND_TRANSLUCENT);
}

defineProperties(LabelCollection.prototype, {
Expand Down Expand Up @@ -732,8 +747,10 @@ define([

billboardCollection.modelMatrix = this.modelMatrix;
billboardCollection.debugShowBoundingVolume = this.debugShowBoundingVolume;
billboardCollection.blendOption = this.blendOption;
backgroundBillboardCollection.modelMatrix = this.modelMatrix;
backgroundBillboardCollection.debugShowBoundingVolume = this.debugShowBoundingVolume;
backgroundBillboardCollection.blendOption = this.blendOption;

var context = frameState.context;

Expand Down
39 changes: 20 additions & 19 deletions Source/Scene/PointPrimitiveCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ define([
'../Renderer/VertexArrayFacade',
'../Shaders/PointPrimitiveCollectionFS',
'../Shaders/PointPrimitiveCollectionVS',
'./BillboardRenderTechnique',
'./BlendingState',
'./BlendOption',
'./PointPrimitive',
'./SceneMode'
], function(
Expand All @@ -51,8 +51,8 @@ define([
VertexArrayFacade,
PointPrimitiveCollectionFS,
PointPrimitiveCollectionVS,
BillboardRenderTechnique,
BlendingState,
BlendOption,
PointPrimitive,
SceneMode) {
'use strict';
Expand Down Expand Up @@ -89,9 +89,9 @@ define([
* @param {Object} [options] Object with the following properties:
* @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] The 4x4 transformation matrix that transforms each point from model to world coordinates.
* @param {Boolean} [options.debugShowBoundingVolume=false] For debugging only. Determines if this primitive's commands' bounding spheres are shown.
* @param {BillboardRenderTechnique} [options.renderTechnique=BillboardRenderTechnique.OPAQUE_AND_TRANSLUCENT] The billboard rendering technique. The default
* @param {BlendOption} [options.blendOption=BlendOption.OPAQUE_AND_TRANSLUCENT] The point blending option. The default
* is used for rendering both opaque and translucent points. However, if either all of the points are completely opaque or all are completely translucent,
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve performance by 2x.
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve performance by up to 2x.
*
* @performance For best performance, prefer a few collections, each with many points, to
* many collections with only a few points each. Organize collections so that points
Expand Down Expand Up @@ -205,14 +205,15 @@ define([
this.debugShowBoundingVolume = defaultValue(options.debugShowBoundingVolume, false);

/**
* The billboard rendering technique. The default is used for rendering both opaque and translucent points.
* The point blending option. The default is used for rendering both opaque and translucent points.
* However, if either all of the points are completely opaque or all are completely translucent,
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve performance by 2x.
* @type {BillboardRenderTechnique}
* @default BillboardRenderTechnique.OPAQUE_AND_TRANSLUCENT
* setting the technique to BillboardRenderTechnique.OPAQUE or BillboardRenderTechnique.TRANSLUCENT can improve
* performance by up to 2x.
* @type {BlendOption}
* @default BlendOption.OPAQUE_AND_TRANSLUCENT
*/
this.renderTechnique = defaultValue(options.renderTechnique, BillboardRenderTechnique.OPAQUE_AND_TRANSLUCENT);
this._renderTechnique = undefined;
this.blendOption = defaultValue(options.blendOption, BlendOption.OPAQUE_AND_TRANSLUCENT);
this._blendOption = undefined;

this._mode = SceneMode.SCENE3D;
this._maxTotalPointSize = 1;
Expand Down Expand Up @@ -852,10 +853,10 @@ define([
}
updateBoundingVolume(this, frameState, boundingVolume);

var techniqueChanged = this._renderTechnique !== this.renderTechnique;
this._renderTechnique = this.renderTechnique;
var blendOptionChanged = this._blendOption !== this.blendOption;
this._blendOption = this.blendOption;

if (techniqueChanged) {
if (blendOptionChanged) {
this._rsOpaque = RenderState.fromCache({
depthTest : {
enabled : true,
Expand All @@ -864,7 +865,7 @@ define([
depthMask : true
});

if (this._renderTechnique === BillboardRenderTechnique.TRANSLUCENT || this._renderTechnique === BillboardRenderTechnique.OPAQUE_AND_TRANSLUCENT) {
if (this._blendOption === BlendOption.TRANSLUCENT || this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT) {
this._rsTranslucent = RenderState.fromCache({
depthTest : {
enabled : true,
Expand All @@ -878,7 +879,7 @@ define([
}
}

if (techniqueChanged ||
if (blendOptionChanged ||
(this._shaderScaleByDistance && !this._compiledShaderScaleByDistance) ||
(this._shaderTranslucencyByDistance && !this._compiledShaderTranslucencyByDistance) ||
(this._shaderDistanceDisplayCondition && !this._compiledShaderDistanceDisplayCondition)) {
Expand All @@ -896,7 +897,7 @@ define([
vs.defines.push('DISTANCE_DISPLAY_CONDITION');
}

if (this._renderTechnique === BillboardRenderTechnique.OPAQUE || this._renderTechnique === BillboardRenderTechnique.OPAQUE_AND_TRANSLUCENT) {
if (this._blendOption === BlendOption.OPAQUE || this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT) {
fs = new ShaderSource({
defines : ['OPAQUE'],
sources : [PointPrimitiveCollectionFS]
Expand All @@ -913,7 +914,7 @@ define([
this._sp = undefined;
}

if (this._renderTechnique === BillboardRenderTechnique.TRANSLUCENT || this._renderTechnique === BillboardRenderTechnique.OPAQUE_AND_TRANSLUCENT) {
if (this._blendOption === BlendOption.TRANSLUCENT || this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT) {
fs = new ShaderSource({
defines : ['TRANSLUCENT'],
sources : [PointPrimitiveCollectionFS]
Expand Down Expand Up @@ -985,8 +986,8 @@ define([
if (pass.render) {
var colorList = this._colorCommands;

var opaque = this._renderTechnique === BillboardRenderTechnique.OPAQUE;
var opaqueAndTranslucent = this._renderTechnique === BillboardRenderTechnique.OPAQUE_AND_TRANSLUCENT;
var opaque = this._blendOption === BlendOption.OPAQUE;
var opaqueAndTranslucent = this._blendOption === BlendOption.OPAQUE_AND_TRANSLUCENT;

va = this._vaf.va;
vaLength = va.length;
Expand Down
10 changes: 5 additions & 5 deletions Specs/Scene/BillboardCollectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defineSuite([
'Core/NearFarScalar',
'Core/Rectangle',
'Scene/Billboard',
'Scene/BillboardRenderTechnique',
'Scene/BlendOption',
'Scene/HeightReference',
'Scene/HorizontalOrigin',
'Scene/OrthographicFrustum',
Expand All @@ -37,7 +37,7 @@ defineSuite([
NearFarScalar,
Rectangle,
Billboard,
BillboardRenderTechnique,
BlendOption,
HeightReference,
HorizontalOrigin,
OrthographicFrustum,
Expand Down Expand Up @@ -241,17 +241,17 @@ defineSuite([

var frameState = scene.frameState;
frameState.commandList.length = 0;
billboards.renderTechnique = BillboardRenderTechnique.OPAQUE_AND_TRANSLUCENT;
billboards.blendOption = BlendOption.OPAQUE_AND_TRANSLUCENT;
billboards.update(frameState);
expect(frameState.commandList.length).toEqual(2);

frameState.commandList.length = 0;
billboards.renderTechnique = BillboardRenderTechnique.OPAQUE;
billboards.blendOption = BlendOption.OPAQUE;
billboards.update(frameState);
expect(frameState.commandList.length).toEqual(1);

frameState.commandList.length = 0;
billboards.renderTechnique = BillboardRenderTechnique.TRANSLUCENT;
billboards.blendOption = BlendOption.TRANSLUCENT;
billboards.update(frameState);
expect(frameState.commandList.length).toEqual(1);
});
Expand Down
Loading

0 comments on commit 54b87ab

Please sign in to comment.