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

SDF Text Labels! #7730

Merged
merged 54 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
3baedfb
Added tiny-sdf
jasonbeverage Apr 8, 2019
3a5c4d8
Added debugTextureAtlas property to BillboardCollection to help
jasonbeverage Apr 8, 2019
6ecbc24
Initial commit of SDF text support!
jasonbeverage Apr 8, 2019
4424679
Better support for LabelStyle
jasonbeverage Apr 8, 2019
255edf0
Added SDF label demo
jasonbeverage Apr 8, 2019
df20174
Updated CHANGES.md
jasonbeverage Apr 9, 2019
9a9e3bc
Fix newlines in Labels SDF example
jasonbeverage Apr 9, 2019
254c541
eslint fixes for Labels SDF example
jasonbeverage Apr 10, 2019
96a0050
Fixed relative scaling in Label.
jasonbeverage Apr 10, 2019
d91a299
Trying a dynamic scale in sdf shaders
jasonbeverage Apr 10, 2019
8f8566c
Fixed getScreenSpaceBoundingBox by taking into account the relative s…
jasonbeverage Apr 17, 2019
b7ad776
Reduced glyphBuffer setting to fix unit tests
jasonbeverage Apr 17, 2019
3a2de30
Commented out some unit tests, will fix one at a time
jasonbeverage Apr 17, 2019
32d3561
Not adding spaces to the texture atlas in LabelCollection
jasonbeverage Apr 17, 2019
ceef901
Passing in fontInfo instead of font to getSDF
jasonbeverage Apr 24, 2019
e71d3cb
Added back in label unit test
jasonbeverage Apr 25, 2019
fe52af3
Fixed Label.getScreenSpaceBoundingBox by using the glyph dimensions
jasonbeverage Apr 26, 2019
dc4d16f
Merge branch 'master' into sdf-labels
lilleyse Apr 30, 2019
56ca95a
Style tweaks
lilleyse Apr 30, 2019
fdfc89e
Fixed typo in LabelCollection to use maxx instead of maxy for width
jasonbeverage May 1, 2019
4ef2780
Remove writeTextToCanvas import
jasonbeverage May 2, 2019
04b60a9
Packing outline color and width into a compressed attribute so we can…
jasonbeverage May 2, 2019
deb651d
Multisampling in sdf shader to try to get rid of artifacts
jasonbeverage May 6, 2019
14d44cb
Much improved multisampling of the SDF text
jasonbeverage May 6, 2019
150fb93
Fixed writeTextToCanvas to properly position the text with padding above
jasonbeverage May 14, 2019
ee6082f
Added bitmap-sdf library
jasonbeverage May 14, 2019
1794ab2
Added SDFSettings class to hold info about how SDF fonts are generated.
jasonbeverage May 14, 2019
a95fe74
Simplified sdf shaders to push edge computation to the CPU.
jasonbeverage May 14, 2019
0211c22
saving vertical origin in texture cache id
jasonbeverage May 14, 2019
501d4d7
Updated unit tests
jasonbeverage May 14, 2019
efb0691
Documented totalScale in Label and using it in few places in LabelCol…
jasonbeverage May 14, 2019
e6d3aa1
Merge branch 'master' into sdf-labels
jasonbeverage May 14, 2019
6ab62c2
Updated Labels SDF gallery image
jasonbeverage May 14, 2019
795fcbb
Merge branch 'master' into sdf-labels
lilleyse May 16, 2019
47ae48c
Removed unnecessary comments in Label.js
jasonbeverage May 17, 2019
f774acc
Fixed background padding size computation in LabelCollection so that the
jasonbeverage May 17, 2019
ffb52ed
Merge branch 'master' into sdf-labels
lilleyse May 28, 2019
827a45b
Formatting
lilleyse May 28, 2019
3338a7f
Marked SDFSettings as private
jasonbeverage May 29, 2019
ecbcbd3
Added comment to bitmap-sdf explaining what it is and what it does
jasonbeverage May 29, 2019
952093c
Remove commented code
jasonbeverage May 29, 2019
e16817c
Added a fallback for when GL_OES_standard_derivatives isn't available…
jasonbeverage May 30, 2019
3e0c68d
Merge branch 'master' into sdf-labels
jasonbeverage May 30, 2019
2209bd8
Merge branch 'master' into sdf-labels
jasonbeverage Jun 19, 2019
d533960
Removed debugging info from Labels SDF sandcastle demo
jasonbeverage Jun 19, 2019
51d99f4
Changed SDF vertex attributed to be a vec2 instead of a vec4 since th…
jasonbeverage Jun 19, 2019
b898685
Storing canvas width and height in local variables in LabelCollection
jasonbeverage Jun 19, 2019
ea1ae8f
Remove blank line in BillboardCollectionFS.glsl
jasonbeverage Jun 19, 2019
75f1da1
Added bitmap-sdf to third party section of LICENSE.md
jasonbeverage Jun 19, 2019
514b567
Renamed SDF to SDF_INDEX to match other index location naming
jasonbeverage Jun 19, 2019
c2c88d4
Added table closing tag in Labels SDF example
jasonbeverage Jun 19, 2019
eb84929
Merge branch 'master' into sdf-labels
lilleyse Jul 1, 2019
ab2fec5
Added link to Labels SDF sandcastle example to CHANGES.md
jasonbeverage Jul 1, 2019
07b7d89
Changed getFontInfo function to be parseFont and moved it to Label.
jasonbeverage Jul 1, 2019
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
175 changes: 175 additions & 0 deletions Apps/Sandcastle/gallery/Labels SDF.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Create and style textual labels.">
<meta name="cesium-sandcastle-labels" content="Showcases">
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
<script type="text/javascript">
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
@import url(../templates/bucket.css);

#toolbar {
background: rgba(42, 42, 42, 0.8);
padding: 4px;
border-radius: 4px;
}

</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar">
<table><tbody>
<tr>
<td>Outline</td>
<td>
<input type="range" min="0.0" max="8.0" step="0.01" data-bind="value: outlineWidth, valueUpdate: 'input'">
<input type="text" size="5" data-bind="value: outlineWidth">
</td>
</tr>

<tr>
<td>Scale</td>
<td>
<input type="range" min="0.1" max="20.0" step="0.01" data-bind="value: scale, valueUpdate: 'input'">
<input type="text" size="5" data-bind="value: scale">
</td>
</tr>

<tr>
<td class="header">Outline Color</td>
</tr>
<tr>
<td>Color</td>
<td><select data-bind="options: outlineColors, value: outlineColor"></select></td>
</tr>

<tr>
<td class="header">Texture Atlas Stats</td>
</tr>
<tr>
<td>
<div id="atlasStats">
</div>
</td>
</tr>
</tbody>
</div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin

function getColor(colorName, alpha) {
var color = Cesium.Color[colorName.toUpperCase()];
return Cesium.Color.fromAlpha(color, parseFloat(alpha));
}

var viewer = new Cesium.Viewer('cesiumContainer');

// The viewModel tracks the state of our mini application.
var viewModel = {
outlineWidth: 0.75,
scale: 1.0,
outlineColor : 'Red',
outlineColors : ['Red', 'Green', 'Blue', 'Yellow', 'Gray', 'Black']
};

// Convert the viewModel members into knockout observables.
Cesium.knockout.track(viewModel);
// Bind the viewModel to the DOM elements of the UI that call for it.
var toolbar = document.getElementById('toolbar');
Cesium.knockout.applyBindings(viewModel, toolbar);

// Create a label collection with two labels
var labels = viewer.scene.primitives.add(new Cesium.LabelCollection());
var label = labels.add({
position : Cesium.Cartesian3.fromDegrees(-75.1641667, 39.9522222),
text : 'Philadelphia',
fillColor: Cesium.Color.WHITE,
backgroundColor: Cesium.Color.BLACK,
font : '48px Calibri',
style: Cesium.LabelStyle.FILL_AND_OUTLINE
});

var morgantown = labels.add({
position : Cesium.Cartesian3.fromDegrees(-79.9559, 39.6295),
text : 'Morgantown',
fillColor: Cesium.Color.YELLOW,
font : '24px Calibri',
outlineColor: Cesium.Color.BLUE,
outlineWidth: 2.0,
style: Cesium.LabelStyle.FILL_AND_OUTLINE
});

var atlasStats = document.getElementById("atlasStats");

Cesium.knockout.getObservable(viewModel, 'outlineWidth').subscribe(
function(newValue) {
label.outlineWidth = parseFloat(newValue);
}
);

Cesium.knockout.getObservable(viewModel, 'scale').subscribe(
function(newValue) {
label.scale = parseFloat(newValue);
}
);

Cesium.knockout.getObservable(viewModel, 'outlineColor').subscribe(
function(newValue) {
label.outlineColor = getColor(newValue, 1.0);
}
);

Sandcastle.addToggleButton('Debug Atlas', labels._billboardCollection.debugTextureAtlas, function(checked) {
labels._billboardCollection.debugTextureAtlas = checked;
});

var outlineDelta = 0.1;

var fontDelta = -1.0;
var fontSize = 48.0;
var minFontSize = 1.0;
var maxFontSize = 48.0;

viewer.scene.preUpdate.addEventListener(function(scene, time) {
if (labels._textureAtlas) {
var info = 'Number Of Images=' + labels._textureAtlas.numberOfImages + '<br/>';
jasonbeverage marked this conversation as resolved.
Show resolved Hide resolved
info += 'Dimensions ' + labels._textureAtlas._texture.width + ' x ' + labels._textureAtlas._texture.height;
atlasStats.innerHTML = info;
}

morgantown.outlineWidth += outlineDelta;
if (morgantown.outlineWidth >= 4.0 || morgantown.outlineWidth <= 0.0) {
outlineDelta *= -1.0;
}

fontSize += fontDelta;
if (fontSize >= maxFontSize || fontSize <= minFontSize) {
fontDelta *= -1.0;
}
morgantown.font = fontSize + "px Calibri";
});
//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== 'undefined') {
startup(Cesium);
} else if (typeof require === 'function') {
require(['Cesium'], startup);
}
</script>
</body>
</html>
Binary file added Apps/Sandcastle/gallery/Labels SDF.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Change Log

##### Additions :tada:
* Added support for the `KHR_texture_transform` glTF extension. [#7549](https://github.com/AnalyticalGraphicsInc/cesium/pull/7549)
* Reworked label rendering to use signed distance fields for crisper text.

##### Fixes :wrench:
* Fixed an error where `clampToHeightMostDetailed` or `sampleHeightMostDetailed` would crash if entities were created when the promise resolved. [#7690](https://github.com/AnalyticalGraphicsInc/cesium/pull/7690)
Expand Down
48 changes: 47 additions & 1 deletion Source/Scene/Billboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ define([
this._mode = SceneMode.SCENE3D;

this._clusterShow = true;
this._outlineColor = Color.clone(defaultValue(options.outlineColor, Color.BLACK));
this._outlineWidth = defaultValue(options.outlineWidth, 0.0);

this._updateClamping();
}
Expand All @@ -216,7 +218,8 @@ define([
var DISTANCE_DISPLAY_CONDITION = Billboard.DISTANCE_DISPLAY_CONDITION = 14;
var DISABLE_DEPTH_DISTANCE = Billboard.DISABLE_DEPTH_DISTANCE = 15;
Billboard.TEXTURE_COORDINATE_BOUNDS = 16;
Billboard.NUMBER_OF_PROPERTIES = 17;
var SDF = Billboard.SDF = 17;
jasonbeverage marked this conversation as resolved.
Show resolved Hide resolved
Billboard.NUMBER_OF_PROPERTIES = 18;

function makeDirty(billboard, propertyChanged) {
var billboardCollection = billboard._billboardCollection;
Expand Down Expand Up @@ -944,6 +947,49 @@ define([
makeDirty(this, SHOW_INDEX);
}
}
},

/**
* The outline color of this Billboard. Effective only for SDF billboards like Label glyphs.
* @memberof Billboard.prototype
* @type {Color}
* @private
*/
outlineColor : {
get : function() {
return this._outlineColor;
},
set : function(value) {
//>>includeStart('debug', pragmas.debug);
if (!defined(value)) {
throw new DeveloperError('value is required.');
}
//>>includeEnd('debug');

var outlineColor = this._outlineColor;
if (!Color.equals(outlineColor, value)) {
Color.clone(value, outlineColor);
makeDirty(this, SDF);
}
}
},

/**
* The outline width of this Billboard. Effective only for SDF billboards like Label glyphs.
* @memberof Billboard.prototype
* @type {Number}
* @private
*/
outlineWidth : {
get : function() {
return this._outlineWidth;
},
set : function(value) {
if (this._outlineWidth !== value) {
this._outlineWidth = value;
makeDirty(this, SDF);
}
}
}
});

Expand Down
Loading