Skip to content

Commit

Permalink
Merge pull request #7581 from AnalyticalGraphicsInc/dracoRgbVertexColor
Browse files Browse the repository at this point in the history
Fix vertex shader generation for draco-compressed RGB per-vertex color
  • Loading branch information
lilleyse authored Feb 18, 2019
2 parents d544964 + e4c54bb commit c648159
Show file tree
Hide file tree
Showing 5 changed files with 451 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Change Log
* Fixed an issue with `EllipsoidRhumbLines.findIntersectionWithLongitude` when longitude was IDL. [#7551](https://github.com/AnalyticalGraphicsInc/cesium/issues/7551)
* Fixed model silhouette colors when rendering with high dynamic range. [#7563](https://github.com/AnalyticalGraphicsInc/cesium/pull/7563)
* Fixed an issue with ground polylines on globes that use ellipsoids other than WGS84. [#7552](https://github.com/AnalyticalGraphicsInc/cesium/issues/7552)
* Fixed an issue where Draco compressed models with RGB per-vertex color would not load in Cesium. [#7576](https://github.com/AnalyticalGraphicsInc/cesium/issues/7576)

### 1.54 - 2019-02-01

Expand Down
9 changes: 8 additions & 1 deletion Source/Scene/ModelUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,12 @@ define([
}
shader = variableType + ' ' + decodedAttributeVarName + ';\n' + shader;

// The gltf 2.0 COLOR_0 vertex attribute can be VEC4 or VEC3
var vec3Color = size === 3 && attributeSemantic === 'COLOR_0';
if (vec3Color) {
shader = replaceAllButFirstInString(shader, decodedAttributeVarName, 'vec4(' + decodedAttributeVarName + ', 1.0)');
}

// splice decode function into the shader
var decode = '';
if (quantization.octEncoded) {
Expand All @@ -618,9 +624,10 @@ define([
var decodeUniformVarNameMin = decodeUniformVarName + '_min';
shader = 'uniform float ' + decodeUniformVarNameNormConstant + ';\n' +
'uniform ' + variableType + ' ' + decodeUniformVarNameMin + ';\n' + shader;
var attributeVarAccess = vec3Color ? '.xyz' : '';
decode = '\n' +
'void main() {\n' +
' ' + decodedAttributeVarName + ' = ' + decodeUniformVarNameMin + ' + ' + attributeVarName + ' * ' + decodeUniformVarNameNormConstant + ';\n' +
' ' + decodedAttributeVarName + ' = ' + decodeUniformVarNameMin + ' + ' + attributeVarName + attributeVarAccess + ' * ' + decodeUniformVarNameNormConstant + ';\n' +
' ' + newMain + '();\n' +
'}\n';
}
Expand Down
213 changes: 213 additions & 0 deletions Specs/Data/Models/DracoCompression/BoxVertexColorsDracoRGB.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
{
"accessors": [
{
"componentType": 5123,
"count": 36,
"type": "SCALAR"
},
{
"componentType": 5126,
"count": 24,
"type": "VEC3"
},
{
"componentType": 5126,
"count": 24,
"type": "VEC3"
},
{
"componentType": 5126,
"count": 24,
"max": [
0.5,
0.5,
0.5
],
"min": [
-0.5,
-0.5,
-0.5
],
"type": "VEC3"
},
{
"componentType": 5126,
"count": 24,
"type": "VEC2"
}
],
"asset": {
"generator": "FBX2glTF",
"version": "2.0"
},
"bufferViews": [
{
"buffer": 0,
"byteOffset": 0,
"byteLength": 291
}
],
"buffers": [
{
"name": "BoxVertexColorsDracoRGB",
"byteLength": 292,
"uri": "data:application/octet-stream;base64,RFJBQ08CAgEBAAAACAwDCwAAA2+rFAEBEP8CNUFVBEs7K0acBPS3XVcEAAAA/wAAAgEAAQEAAQIJAwAAAgEACQMAAgIBAwkCAAMCAQEJAwABAwEBAQAJDwEIBwEgARgEAHoAggE8LscrycxCBfwIQmx3gBQoA6BlYwAAAAD/AAAAHekGMAjDNTqgF+43Iv5/PwgBAQEAAgMBQAEAoAIIAAAAAP8/AAAAAAC/AAAAvwAAAL8AAIA/DgUBAQANA5UEG20b3RYDJQkFr5XCIE4AsKoACAAApJoqAFOtAqDqVKurAlDVKgCsApDq1KkApgIMAAAAAQLAQAAAAAD/DwAAAAAAAAAAAAAAAIA/DAYDAQEBAQFAAQD/AwAA/wEAAP8CoUEKAA=="
}
],
"materials": [
{
"name": "Default",
"pbrMetallicRoughness": {
"baseColorFactor": [
0.800000011920929,
0.800000011920929,
0.800000011920929,
1
],
"metallicFactor": 0.100000001490116,
"roughnessFactor": 0.990000005960464
},
"emissiveFactor": [
0,
0,
0
],
"alphaMode": "OPAQUE",
"doubleSided": false
}
],
"meshes": [
{
"name": "Cube",
"primitives": [
{
"attributes": {
"COLOR_0": 1,
"NORMAL": 2,
"POSITION": 3,
"TEXCOORD_0": 4
},
"indices": 0,
"material": 0,
"mode": 4,
"extensions": {
"KHR_draco_mesh_compression": {
"bufferView": 0,
"attributes": {
"COLOR_0": 0,
"NORMAL": 1,
"POSITION": 2,
"TEXCOORD_0": 3
}
}
}
}
]
}
],
"nodes": [
{
"children": [
1,
2,
3
],
"name": "RootNode",
"rotation": [
0,
0,
0,
1
],
"scale": [
1,
1,
1
],
"translation": [
0,
0,
0
]
},
{
"name": "Mesh",
"rotation": [
0,
0,
0,
1
],
"scale": [
1,
1,
1
],
"translation": [
0,
0,
0
]
},
{
"mesh": 0,
"name": "Cube",
"rotation": [
0,
0,
0,
1
],
"scale": [
1,
1,
1
],
"translation": [
0,
0,
0
]
},
{
"name": "Texture Group",
"rotation": [
0,
0,
0,
1
],
"scale": [
1,
1,
1
],
"translation": [
0,
0,
0
]
}
],
"samplers": [
{
"wrapS": 10497,
"wrapT": 10497
}
],
"scene": 0,
"scenes": [
{
"name": "Root Scene",
"nodes": [
0
]
}
],
"extensionsRequired": [
"KHR_draco_mesh_compression"
],
"extensionsUsed": [
"KHR_draco_mesh_compression"
]
}
Loading

0 comments on commit c648159

Please sign in to comment.