Skip to content

Commit

Permalink
Support rgb565
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Sep 19, 2016
1 parent a458bc6 commit d40a3b9
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 10 deletions.
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' +
'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

0 comments on commit d40a3b9

Please sign in to comment.