Skip to content

Commit

Permalink
Support rgb565 and ycocg
Browse files Browse the repository at this point in the history
  • Loading branch information
lilleyse committed Sep 13, 2016
1 parent a458bc6 commit e5f61d8
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 10 deletions.
75 changes: 65 additions & 10 deletions Source/Scene/PointCloud3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,20 @@ define([
// Get the colors
var colors;
var isTranslucent = false;
var isYCoCg = 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.YCOCG)) {
colors = featureTable.getPropertyArray('YCOCG', ComponentDatatype.UNSIGNED_SHORT, 1);
isYCoCg = 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 +429,8 @@ define([
normals : normals,
batchIds : batchIds,
isQuantized : isQuantized,
isRGB565 : isRGB565,
isYCoCg : isYCoCg,
isOctEncoded16P : isOctEncoded16P,
styleableProperties : styleableProperties
};
Expand All @@ -438,6 +448,8 @@ define([
var normals = parsedContent.normals;
var batchIds = parsedContent.batchIds;
var isQuantized = parsedContent.isQuantized;
var isRGB565 = parsedContent.isRGB565;
var isYCoCg = parsedContent.isYCoCg;
var isOctEncoded16P = parsedContent.isOctEncoded16P;
var styleableProperties = parsedContent.styleableProperties;
var isTranslucent = content._isTranslucent;
Expand Down Expand Up @@ -520,6 +532,16 @@ define([
if (hasColors) {
if (isTranslucent) {
vs += 'attribute vec4 a_color; \n';
} else if (isYCoCg || isRGB565) {
vs += 'attribute float a_color; \n' +
'const float SHIFT_RIGHT_11 = 1.0 / 2048.0; \n' +
'const float SHIFT_RIGHT_10 = 1.0 / 1024.0; \n' +
'const float SHIFT_RIGHT_5 = 1.0 / 32.0; \n' +
'const float SHIFT_LEFT_11 = 2048.0; \n' +
'const float SHIFT_LEFT_10 = 1024.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 +572,27 @@ 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 if (isYCoCg) {
vs += ' float compressed = a_color; \n' +
' float y = floor(compressed * SHIFT_RIGHT_10); \n' +
' compressed -= y * SHIFT_LEFT_10; \n' +
' float co = floor(compressed * SHIFT_RIGHT_5); \n' +
' compressed -= co * SHIFT_LEFT_5; \n' +
' float cg = compressed; \n' +
' y = y * NORMALIZE_6; \n' +
' co = co * NORMALIZE_5 - 0.5; \n' +
' cg = cg * NORMALIZE_5 - 0.5; \n' +
' vec3 rgb = vec3(y + co - cg, y + cg, y - co - cg); \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 +710,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 (isYCoCg || 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.
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": "pointCloudRGBTest.pnts"
}
}
}
Binary file not shown.
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"
}
}
}
Binary file not shown.
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": "pointCloudYCoCg.pnts"
}
}
}

0 comments on commit e5f61d8

Please sign in to comment.