From ccad16c02266c3a8ce3cf252d80b8972a1b31756 Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Thu, 30 Aug 2018 12:22:15 -0400 Subject: [PATCH 1/8] Add KHR_materials_unlit to list of supported extensions --- Source/Scene/ModelUtility.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Scene/ModelUtility.js b/Source/Scene/ModelUtility.js index 1e61a1a63eb2..b63a5e02ce0a 100644 --- a/Source/Scene/ModelUtility.js +++ b/Source/Scene/ModelUtility.js @@ -473,7 +473,8 @@ define([ 'KHR_draco_mesh_compression' : true, 'KHR_materials_common' : true, 'KHR_techniques_webgl' : true, - 'WEB3D_quantized_attributes' : true + 'WEB3D_quantized_attributes' : true, + 'KHR_materials_unlit' : true }; ModelUtility.checkSupportedExtensions = function(extensionsRequired) { From b1360528be6e6460f6ef5b1e317d4945ffa01a09 Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Thu, 30 Aug 2018 13:31:09 -0400 Subject: [PATCH 2/8] Turn off lighting when detects unlit extension --- Source/Scene/processPbrMetallicRoughness.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Scene/processPbrMetallicRoughness.js b/Source/Scene/processPbrMetallicRoughness.js index 1d98bd9b35b2..c74470f64d2b 100644 --- a/Source/Scene/processPbrMetallicRoughness.js +++ b/Source/Scene/processPbrMetallicRoughness.js @@ -181,6 +181,11 @@ define([ } }; + if (defined(material.extensions) && defined(material.extensions.KHR_materials_unlit)) { + hasNormals = false; + hasTangents = false; + } + if (hasNormals) { techniqueUniforms.u_normalMatrix = { semantic : 'MODELVIEWINVERSETRANSPOSE', From 7a9faa782bad59f1b7c66367f2fc4ab69c702933 Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Thu, 30 Aug 2018 13:50:31 -0400 Subject: [PATCH 3/8] Updated changes.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 4fe6de43324d..4fc804e6a82b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ Change Log * Improved support for polygon entities using `perPositionHeight`, including supporting vertical polygons. This also improves KML compatibility. [#6791](https://github.com/AnalyticalGraphicsInc/cesium/pull/6791) * Added `Cartesian3.midpoint` to compute the midpoint between two `Cartesian3` positions [#6836](https://github.com/AnalyticalGraphicsInc/cesium/pull/6836) * Added `equalsEpsilon` methods to `OrthographicFrustum`, `PerspectiveFrustum`, `OrthographicOffCenterFrustum` and `PerspectiveOffCenterFrustum`. +* Added support for glTF extension [KHR_materials_unlit](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit) [#6977](https://github.com/AnalyticalGraphicsInc/cesium/pull/6977). ##### Deprecated :hourglass_flowing_sand: * Support for 3D Tiles `content.url` is deprecated to reflect updates to the [3D Tiles spec](https://github.com/AnalyticalGraphicsInc/3d-tiles/pull/301). Use `content.uri instead`. Support for `content.url` will remain for backwards compatibility. [#6744](https://github.com/AnalyticalGraphicsInc/cesium/pull/6744) From c56a33969ec261bcb0614a3ae7a7e8719220693f Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Thu, 30 Aug 2018 16:59:06 -0400 Subject: [PATCH 4/8] Ignore unlit and occlusion when unlit --- Source/Scene/processPbrMetallicRoughness.js | 29 +++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Source/Scene/processPbrMetallicRoughness.js b/Source/Scene/processPbrMetallicRoughness.js index c74470f64d2b..df8f579d7fdb 100644 --- a/Source/Scene/processPbrMetallicRoughness.js +++ b/Source/Scene/processPbrMetallicRoughness.js @@ -143,6 +143,7 @@ define([ var hasNormals = false; var hasTangents = false; var hasTexCoords = false; + var isUnlit = false; if (defined(primitiveInfo)) { skinningInfo = primitiveInfo.skinning; @@ -182,6 +183,7 @@ define([ }; if (defined(material.extensions) && defined(material.extensions.KHR_materials_unlit)) { + isUnlit = true; hasNormals = false; hasTangents = false; } @@ -633,19 +635,22 @@ define([ fragmentShader += ' vec3 color = baseColor;\n'; } - if (defined(generatedMaterialValues.u_occlusionTexture)) { - fragmentShader += ' color *= texture2D(u_occlusionTexture, ' + v_texcoord + ').r;\n'; - } - if (defined(generatedMaterialValues.u_emissiveTexture)) { - fragmentShader += ' vec3 emissive = SRGBtoLINEAR3(texture2D(u_emissiveTexture, ' + v_texcoord + ').rgb);\n'; - if (defined(generatedMaterialValues.u_emissiveFactor)) { - fragmentShader += ' emissive *= u_emissiveFactor;\n'; + // Ignore occlusion and emissive when unlit + if (!isUnlit) { + if (defined(generatedMaterialValues.u_occlusionTexture)) { + fragmentShader += ' color *= texture2D(u_occlusionTexture, ' + v_texcoord + ').r;\n'; } - fragmentShader += ' color += emissive;\n'; - } - else if (defined(generatedMaterialValues.u_emissiveFactor)) { - fragmentShader += ' color += u_emissiveFactor;\n'; + if (defined(generatedMaterialValues.u_emissiveTexture)) { + fragmentShader += ' vec3 emissive = SRGBtoLINEAR3(texture2D(u_emissiveTexture, ' + v_texcoord + ').rgb);\n'; + if (defined(generatedMaterialValues.u_emissiveFactor)) { + fragmentShader += ' emissive *= u_emissiveFactor;\n'; + } + fragmentShader += ' color += emissive;\n'; } + else if (defined(generatedMaterialValues.u_emissiveFactor)) { + fragmentShader += ' color += u_emissiveFactor;\n'; + } + } // Final color fragmentShader += ' color = LINEARtoSRGB(color);\n'; @@ -665,6 +670,8 @@ define([ } fragmentShader += '}\n'; + console.log(fragmentShader); + // Add shaders var vertexShaderId = addToArray(shaders, { type : WebGLConstants.VERTEX_SHADER, From 21caa93e769eabb086dfc15b96ffbebdaf5af7c9 Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Fri, 31 Aug 2018 10:01:48 -0400 Subject: [PATCH 5/8] Remove log and fix formatting --- Source/Scene/processPbrMetallicRoughness.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Source/Scene/processPbrMetallicRoughness.js b/Source/Scene/processPbrMetallicRoughness.js index df8f579d7fdb..745b13f64a16 100644 --- a/Source/Scene/processPbrMetallicRoughness.js +++ b/Source/Scene/processPbrMetallicRoughness.js @@ -646,10 +646,9 @@ define([ fragmentShader += ' emissive *= u_emissiveFactor;\n'; } fragmentShader += ' color += emissive;\n'; + } else if (defined(generatedMaterialValues.u_emissiveFactor)) { + fragmentShader += ' color += u_emissiveFactor;\n'; } - else if (defined(generatedMaterialValues.u_emissiveFactor)) { - fragmentShader += ' color += u_emissiveFactor;\n'; - } } // Final color @@ -670,8 +669,6 @@ define([ } fragmentShader += '}\n'; - console.log(fragmentShader); - // Add shaders var vertexShaderId = addToArray(shaders, { type : WebGLConstants.VERTEX_SHADER, From 7c28d2a60958e34ae8b362482091d074046888d1 Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Fri, 31 Aug 2018 10:29:39 -0400 Subject: [PATCH 6/8] Added test for unlit --- Specs/Data/Models/PBR/Box/Box-Unlit.gltf | 151 +++++++++++++++++++++++ Specs/Data/Models/PBR/Box/ReadMe.txt | 1 + Specs/Scene/ModelSpec.js | 16 +++ 3 files changed, 168 insertions(+) create mode 100644 Specs/Data/Models/PBR/Box/Box-Unlit.gltf create mode 100644 Specs/Data/Models/PBR/Box/ReadMe.txt diff --git a/Specs/Data/Models/PBR/Box/Box-Unlit.gltf b/Specs/Data/Models/PBR/Box/Box-Unlit.gltf new file mode 100644 index 000000000000..f4bda300552c --- /dev/null +++ b/Specs/Data/Models/PBR/Box/Box-Unlit.gltf @@ -0,0 +1,151 @@ +{ + "asset": { + "generator": "COLLADA2GLTF", + "version": "2.0" + }, + "extensionsUsed": [ + "KHR_materials_unlit" + ], + "extensionsRequired": [ + "KHR_materials_unlit" + ], + "scene": 0, + "scenes": [ + { + "nodes": [ + 0 + ] + } + ], + "nodes": [ + { + "children": [ + 1 + ], + "matrix": [ + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + -1.0, + 0.0, + 0.0, + 1.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 1.0 + ] + }, + { + "mesh": 0 + } + ], + "meshes": [ + { + "primitives": [ + { + "attributes": { + "NORMAL": 1, + "POSITION": 2 + }, + "indices": 0, + "mode": 4, + "material": 0 + } + ], + "name": "Mesh" + } + ], + "accessors": [ + { + "bufferView": 0, + "byteOffset": 0, + "componentType": 5123, + "count": 36, + "max": [ + 23 + ], + "min": [ + 0 + ], + "type": "SCALAR" + }, + { + "bufferView": 1, + "byteOffset": 0, + "componentType": 5126, + "count": 24, + "max": [ + 1.0, + 1.0, + 1.0 + ], + "min": [ + -1.0, + -1.0, + -1.0 + ], + "type": "VEC3" + }, + { + "bufferView": 1, + "byteOffset": 288, + "componentType": 5126, + "count": 24, + "max": [ + 0.5, + 0.5, + 0.5 + ], + "min": [ + -0.5, + -0.5, + -0.5 + ], + "type": "VEC3" + } + ], + "materials": [ + { + "pbrMetallicRoughness": { + "baseColorFactor": [ + 0.0, + 1.0, + 0.0, + 1.0 + ], + "metallicFactor": 1.0 + }, + "name": "Unlit Green", + "extensions": { + "KHR_materials_unlit": {} + } + } + ], + "bufferViews": [ + { + "buffer": 0, + "byteOffset": 576, + "byteLength": 72, + "target": 34963 + }, + { + "buffer": 0, + "byteOffset": 0, + "byteLength": 576, + "byteStride": 12, + "target": 34962 + } + ], + "buffers": [ + { + "byteLength": 648, + "uri": "data:application/octet-stream;base64,AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAvwAAAL8AAAA/AAAAPwAAAL8AAAA/AAAAvwAAAD8AAAA/AAAAPwAAAD8AAAA/AAAAPwAAAL8AAAA/AAAAvwAAAL8AAAA/AAAAPwAAAL8AAAC/AAAAvwAAAL8AAAC/AAAAPwAAAD8AAAA/AAAAPwAAAL8AAAA/AAAAPwAAAD8AAAC/AAAAPwAAAL8AAAC/AAAAvwAAAD8AAAA/AAAAPwAAAD8AAAA/AAAAvwAAAD8AAAC/AAAAPwAAAD8AAAC/AAAAvwAAAL8AAAA/AAAAvwAAAD8AAAA/AAAAvwAAAL8AAAC/AAAAvwAAAD8AAAC/AAAAvwAAAL8AAAC/AAAAvwAAAD8AAAC/AAAAPwAAAL8AAAC/AAAAPwAAAD8AAAC/AAABAAIAAwACAAEABAAFAAYABwAGAAUACAAJAAoACwAKAAkADAANAA4ADwAOAA0AEAARABIAEwASABEAFAAVABYAFwAWABUA" + } + ] +} diff --git a/Specs/Data/Models/PBR/Box/ReadMe.txt b/Specs/Data/Models/PBR/Box/ReadMe.txt new file mode 100644 index 000000000000..75319c641f4c --- /dev/null +++ b/Specs/Data/Models/PBR/Box/ReadMe.txt @@ -0,0 +1 @@ +Box-Unlit.gltf is a modified glTF with the KHR_materials_unlit extension. \ No newline at end of file diff --git a/Specs/Scene/ModelSpec.js b/Specs/Scene/ModelSpec.js index 1b44abe81fb0..d4441dff8b19 100644 --- a/Specs/Scene/ModelSpec.js +++ b/Specs/Scene/ModelSpec.js @@ -120,6 +120,7 @@ defineSuite([ var boomBoxUrl = './Data/Models/PBR/BoomBox/BoomBox.gltf'; var boxPbrUrl = './Data/Models/PBR/Box/Box.gltf'; + var boxPbrUnlitUrl = './Data/Models/PBR/Box/Box-Unlit.gltf'; var boxAnimatedPbrUrl = './Data/Models/PBR/BoxAnimated/BoxAnimated.gltf'; var boxInterleavedPbrUrl = './Data/Models/PBR/BoxInterleaved/BoxInterleaved.gltf'; var riggedSimplePbrUrl = './Data/Models/PBR/RiggedSimple/RiggedSimple.gltf'; @@ -2692,6 +2693,21 @@ defineSuite([ }); }); + fit('renders with the unlit extension', function() { + return loadModel(boxPbrUnlitUrl).then(function(model) { + model.show = true; + model.zoomTo(); + // We expect to see the base color when unlit + expect(scene).toRenderAndCall(function(rgba) { + expect(rgba[0]).toEqual(0); + expect(rgba[1]).toEqual(255); + expect(rgba[2]).toEqual(0); + }); + + primitives.remove(model); + }); + }); + it('silhouetteSupported', function() { expect(Model.silhouetteSupported(scene)).toBe(true); scene.context._stencilBits = 0; From ba4d8404d9e8450851ae3932c12a557cfa94e2ba Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Fri, 31 Aug 2018 11:59:55 -0400 Subject: [PATCH 7/8] Moved BoxUnlit to its own folder --- Specs/Data/Models/PBR/Box/ReadMe.txt | 1 - .../Models/PBR/{Box/Box-Unlit.gltf => BoxUnlit/BoxUnlit.gltf} | 0 Specs/Scene/ModelSpec.js | 4 ++-- 3 files changed, 2 insertions(+), 3 deletions(-) delete mode 100644 Specs/Data/Models/PBR/Box/ReadMe.txt rename Specs/Data/Models/PBR/{Box/Box-Unlit.gltf => BoxUnlit/BoxUnlit.gltf} (100%) diff --git a/Specs/Data/Models/PBR/Box/ReadMe.txt b/Specs/Data/Models/PBR/Box/ReadMe.txt deleted file mode 100644 index 75319c641f4c..000000000000 --- a/Specs/Data/Models/PBR/Box/ReadMe.txt +++ /dev/null @@ -1 +0,0 @@ -Box-Unlit.gltf is a modified glTF with the KHR_materials_unlit extension. \ No newline at end of file diff --git a/Specs/Data/Models/PBR/Box/Box-Unlit.gltf b/Specs/Data/Models/PBR/BoxUnlit/BoxUnlit.gltf similarity index 100% rename from Specs/Data/Models/PBR/Box/Box-Unlit.gltf rename to Specs/Data/Models/PBR/BoxUnlit/BoxUnlit.gltf diff --git a/Specs/Scene/ModelSpec.js b/Specs/Scene/ModelSpec.js index d4441dff8b19..31417ac46e0e 100644 --- a/Specs/Scene/ModelSpec.js +++ b/Specs/Scene/ModelSpec.js @@ -120,7 +120,7 @@ defineSuite([ var boomBoxUrl = './Data/Models/PBR/BoomBox/BoomBox.gltf'; var boxPbrUrl = './Data/Models/PBR/Box/Box.gltf'; - var boxPbrUnlitUrl = './Data/Models/PBR/Box/Box-Unlit.gltf'; + var boxPbrUnlitUrl = './Data/Models/PBR/BoxUnlit/BoxUnlit.gltf'; var boxAnimatedPbrUrl = './Data/Models/PBR/BoxAnimated/BoxAnimated.gltf'; var boxInterleavedPbrUrl = './Data/Models/PBR/BoxInterleaved/BoxInterleaved.gltf'; var riggedSimplePbrUrl = './Data/Models/PBR/RiggedSimple/RiggedSimple.gltf'; @@ -2693,7 +2693,7 @@ defineSuite([ }); }); - fit('renders with the unlit extension', function() { + it('renders with the unlit extension', function() { return loadModel(boxPbrUnlitUrl).then(function(model) { model.show = true; model.zoomTo(); From f3afd0177cb5badd4abcd8f0d72868f2133ee404 Mon Sep 17 00:00:00 2001 From: Shehata Date: Wed, 5 Sep 2018 09:28:52 -0400 Subject: [PATCH 8/8] Moved changes.md text into October release --- CHANGES.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 4fc804e6a82b..89a710a88f0e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,11 @@ Change Log ========== +### 1.50 - 2018-10-01 + +##### Additions :tada: +* Added support for glTF extension [KHR_materials_unlit](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit) [#6977](https://github.com/AnalyticalGraphicsInc/cesium/pull/6977). + ### 1.48 - 2018-08-01 ##### Additions :tada: @@ -10,7 +15,6 @@ Change Log * Improved support for polygon entities using `perPositionHeight`, including supporting vertical polygons. This also improves KML compatibility. [#6791](https://github.com/AnalyticalGraphicsInc/cesium/pull/6791) * Added `Cartesian3.midpoint` to compute the midpoint between two `Cartesian3` positions [#6836](https://github.com/AnalyticalGraphicsInc/cesium/pull/6836) * Added `equalsEpsilon` methods to `OrthographicFrustum`, `PerspectiveFrustum`, `OrthographicOffCenterFrustum` and `PerspectiveOffCenterFrustum`. -* Added support for glTF extension [KHR_materials_unlit](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit) [#6977](https://github.com/AnalyticalGraphicsInc/cesium/pull/6977). ##### Deprecated :hourglass_flowing_sand: * Support for 3D Tiles `content.url` is deprecated to reflect updates to the [3D Tiles spec](https://github.com/AnalyticalGraphicsInc/3d-tiles/pull/301). Use `content.uri instead`. Support for `content.url` will remain for backwards compatibility. [#6744](https://github.com/AnalyticalGraphicsInc/cesium/pull/6744)