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

3D Tiles - Point Cloud color compression #4315

Merged
merged 1 commit into from
Sep 20, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
55 changes: 45 additions & 10 deletions Source/Scene/PointCloud3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,16 @@ define([
// Get the colors
var colors;
var isTranslucent = false;
var isRGB565 = false;

if (defined(featureTableJson.RGBA)) {
colors = featureTable.getPropertyArray('RGBA', ComponentDatatype.UNSIGNED_BYTE, 4);
isTranslucent = true;
} else if (defined(featureTableJson.RGB)) {
colors = featureTable.getPropertyArray('RGB', ComponentDatatype.UNSIGNED_BYTE, 3);
} else if (defined(featureTableJson.RGB565)) {
colors = featureTable.getPropertyArray('RGB565', ComponentDatatype.UNSIGNED_SHORT, 1);
isRGB565 = true;
} else if (defined(featureTableJson.CONSTANT_RGBA)) {
var constantRGBA = featureTable.getGlobalProperty('CONSTANT_RGBA');
this._constantColor = Color.fromBytes(constantRGBA[0], constantRGBA[1], constantRGBA[2], constantRGBA[3], this._constantColor);
Expand Down Expand Up @@ -421,6 +425,7 @@ define([
normals : normals,
batchIds : batchIds,
isQuantized : isQuantized,
isRGB565 : isRGB565,
isOctEncoded16P : isOctEncoded16P,
styleableProperties : styleableProperties
};
Expand All @@ -438,6 +443,7 @@ define([
var normals = parsedContent.normals;
var batchIds = parsedContent.batchIds;
var isQuantized = parsedContent.isQuantized;
var isRGB565 = parsedContent.isRGB565;
var isOctEncoded16P = parsedContent.isOctEncoded16P;
var styleableProperties = parsedContent.styleableProperties;
var isTranslucent = content._isTranslucent;
Expand Down Expand Up @@ -520,6 +526,14 @@ define([
if (hasColors) {
if (isTranslucent) {
vs += 'attribute vec4 a_color; \n';
} else if (isRGB565) {
vs += 'attribute float a_color; \n' +
'const float SHIFT_RIGHT_11 = 1.0 / 2048.0; \n' +
Copy link
Contributor

Choose a reason for hiding this comment

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

@lilleyse @bagnell should we introduce built-in czm_ GLSL functions for shifts to basically extract a set of bits from a float?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like passing on this for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, added to the roadmap. Good beginner low-hanging fruit.

'const float SHIFT_RIGHT_5 = 1.0 / 32.0; \n' +
'const float SHIFT_LEFT_11 = 2048.0; \n' +
'const float SHIFT_LEFT_5 = 32.0; \n' +
'const float NORMALIZE_6 = 1.0 / 64.0; \n' +
'const float NORMALIZE_5 = 1.0 / 32.0; \n';
} else {
vs += 'attribute vec3 a_color; \n';
}
Expand Down Expand Up @@ -550,6 +564,15 @@ define([
if (hasColors) {
if (isTranslucent) {
vs += ' vec4 color = a_color * u_highlightColor; \n';
} else if (isRGB565) {
vs += ' float compressed = a_color; \n' +
' float r = floor(compressed * SHIFT_RIGHT_11); \n' +
' compressed -= r * SHIFT_LEFT_11; \n' +
' float g = floor(compressed * SHIFT_RIGHT_5); \n' +
' compressed -= g * SHIFT_LEFT_5; \n' +
' float b = compressed; \n' +
' vec3 rgb = vec3(r * NORMALIZE_5, g * NORMALIZE_6, b * NORMALIZE_5); \n' +
' vec4 color = vec4(rgb * u_highlightColor.rgb, u_highlightColor.a); \n';
} else {
vs += ' vec4 color = vec4(a_color * u_highlightColor.rgb, u_highlightColor.a); \n';
}
Expand Down Expand Up @@ -667,16 +690,28 @@ define([
}

if (hasColors) {
var colorComponentsPerAttribute = isTranslucent ? 4 : 3;
attributes.push({
index : colorAttributeLocation,
vertexBuffer : colorsVertexBuffer,
componentsPerAttribute : colorComponentsPerAttribute,
componentDatatype : ComponentDatatype.UNSIGNED_BYTE,
normalize : true,
offsetInBytes : 0,
strideInBytes : 0
});
if (isRGB565) {
attributes.push({
index : colorAttributeLocation,
vertexBuffer : colorsVertexBuffer,
componentsPerAttribute : 1,
componentDatatype : ComponentDatatype.UNSIGNED_SHORT,
normalize : false,
offsetInBytes : 0,
strideInBytes : 0
});
} else {
var colorComponentsPerAttribute = isTranslucent ? 4 : 3;
attributes.push({
index : colorAttributeLocation,
vertexBuffer : colorsVertexBuffer,
componentsPerAttribute : colorComponentsPerAttribute,
componentDatatype : ComponentDatatype.UNSIGNED_BYTE,
normalize : true,
offsetInBytes : 0,
strideInBytes : 0
});
}
}

if (hasNormals) {
Expand Down
Binary file not shown.
21 changes: 21 additions & 0 deletions Specs/Data/Cesium3DTiles/PointCloud/PointCloudRGB565/tileset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"asset": {
"version": "0.0"
},
"geometricError": 17.32,
"root": {
"refine": "add",
"boundingVolume": {
"sphere": [
1215012.8828876738,
-4736313.051199594,
4081605.22126042,
5
]
},
"geometricError": 0,
"content": {
"url": "pointCloudRGB565.pnts"
}
}
}
5 changes: 5 additions & 0 deletions Specs/Scene/PointCloud3DTileContentSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ defineSuite([

var pointCloudRGBUrl = './Data/Cesium3DTiles/PointCloud/PointCloudRGB';
var pointCloudRGBAUrl = './Data/Cesium3DTiles/PointCloud/PointCloudRGBA';
var pointCloudRGB565Url = './Data/Cesium3DTiles/PointCloud/PointCloudRGB565';
var pointCloudNoColorUrl = './Data/Cesium3DTiles/PointCloud/PointCloudNoColor';
var pointCloudConstantColorUrl = './Data/Cesium3DTiles/PointCloud/PointCloudConstantColor';
var pointCloudNormalsUrl = './Data/Cesium3DTiles/PointCloud/PointCloudNormals';
Expand Down Expand Up @@ -179,6 +180,10 @@ defineSuite([
return Cesium3DTilesTester.loadTileset(scene, pointCloudRGBAUrl).then(expectRenderPointCloud);
});

it('renders point cloud with rgb565 colors', function() {
return Cesium3DTilesTester.loadTileset(scene, pointCloudRGB565Url).then(expectRenderPointCloud);
});

it('renders point cloud with no colors', function() {
return Cesium3DTilesTester.loadTileset(scene, pointCloudNoColorUrl).then(expectRenderPointCloud);
});
Expand Down