Skip to content

Commit

Permalink
Merge pull request #9513 from CesiumGS/add-ktx2
Browse files Browse the repository at this point in the history
Add KTX2 support and remove KTX/CRN
  • Loading branch information
lilleyse authored and Janine Liu committed Jul 1, 2021
2 parents ec9422d + 5b45436 commit 13d5d8b
Show file tree
Hide file tree
Showing 118 changed files with 5,700 additions and 6,378 deletions.
Binary file not shown.
Binary file not shown.
14 changes: 14 additions & 0 deletions Apps/Sandcastle/gallery/3D Models.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@
);
},
},
{
text: "KTX2 Compressed Balloon",
onselect: function () {
if (!Cesium.FeatureDetection.supportsBasis(viewer.scene)) {
window.alert(
"This browser does not support Basis Universal compressed textures"
);
}
createModel(
"../../SampleData/models/CesiumBalloonKTX2/CesiumBalloonKTX2.glb",
1000.0
);
},
},
];

Sandcastle.addToolbarMenu(options);
Expand Down
64 changes: 34 additions & 30 deletions Apps/Sandcastle/gallery/Image-Based Lighting.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,58 +66,62 @@
}

var environmentMapURL =
"https://cesium.com/public/SandcastleSampleData/kiara_6_afternoon_2k_ibl.ktx";
"https://cesium.com/public/SandcastleSampleData/kiara_6_afternoon_2k_ibl.ktx2";
var modelURL = "../../SampleData/models/Pawns/Pawns.glb";

// This environment map was processed using Google's Filament project. To process your own:
// This environment map was processed using Khronos's glTF IBL Sampler. To process your own:
// 1 - Download and build the Khronos glTF IBL Sampler (https://github.com/KhronosGroup/glTF-IBL-Sampler).
// 2 - Run `cli -inputPath /path/to/image.hdr -outCubeMap /path/to/output.ktx2`. Run `cli -h` for all options.

// To generate the spherical harmonic coefficients below, use Google's Filament project:
// 1 - Download the Filament release (https://github.com/google/filament/releases).
// 2 - Run `cmgen --type=ktx --deploy=/path/to/output /path/to/image.hdr`. Other formats are also supported. Run `cmgen --help` for all options.
// 3 - Take the generated coefficients and the KTX file and load them in CesiumJS as shown below.
// 3 - Take the generated coefficients and load them in CesiumJS as shown below.

var L00 = new Cesium.Cartesian3(
0.170455150831422,
0.163151083190219,
0.196966760289763
1.234709620475769,
1.221461296081543,
1.273156881332397
);
var L1_1 = new Cesium.Cartesian3(
-0.066550267689383,
-0.022088055746048,
0.078835009246127
1.135921120643616,
1.171217799186707,
1.287644743919373
);
var L10 = new Cesium.Cartesian3(
0.038364097478591,
0.045714300098753,
0.063498904606215
1.245193719863892,
1.245591878890991,
1.282818794250488
);
var L11 = new Cesium.Cartesian3(
-0.01436536331281,
-0.026490613715151,
-0.05018940406602
-1.106930732727051,
-1.112522482872009,
-1.153198838233948
);
var L2_2 = new Cesium.Cartesian3(
-0.05153278691789,
-0.050777795729986,
-0.056449044453032
-1.086226940155029,
-1.079731941223145,
-1.101912498474121
);
var L2_1 = new Cesium.Cartesian3(
0.043454596136534,
0.046672590104157,
0.05753010764661
1.189834713935852,
1.185906887054443,
1.214385271072388
);
var L20 = new Cesium.Cartesian3(
-0.00164046627411,
0.001286638231156,
0.007228908989616
0.01778045296669,
0.02013735473156,
0.025313569232821
);
var L21 = new Cesium.Cartesian3(
-0.042260855700641,
-0.046394335094707,
-0.057562936365585
-1.086826920509338,
-1.084611177444458,
-1.111204028129578
);
var L22 = new Cesium.Cartesian3(
-0.004953478914091,
-0.000479681664876,
0.008508150106928
-0.05241484940052,
-0.048303380608559,
-0.041960217058659
);
var coefficients = [L00, L1_1, L10, L11, L2_2, L2_1, L20, L21, L22];

Expand Down
54 changes: 40 additions & 14 deletions Apps/Sandcastle/gallery/Materials.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,25 @@
});
}

function applyCompressedTextureMaterial(primitive, scene) {
Sandcastle.declare(applyCompressedTextureMaterial); // For highlighting in Sandcastle.

var compressedImageUrl;
if (scene.getCompressedTextureFormatSupported("s3tc")) {
compressedImageUrl = "../images/LogoDXT1.ktx";
} else if (scene.getCompressedTextureFormatSupported("etc1")) {
compressedImageUrl = "../images/LogoETC1.ktx";
} else if (scene.getCompressedTextureFormatSupported("pvrtc")) {
compressedImageUrl = "../images/LogoPVR.ktx";
}
function applyETC1SCompressedTextureMaterial(primitive, scene) {
Sandcastle.declare(applyETC1SCompressedTextureMaterial); // For highlighting in Sandcastle.

var compressedImageUrl = "../images/Cesium_Logo_ETC1S.ktx2";

primitive.appearance.material = new Cesium.Material({
fabric: {
type: "Image",
uniforms: {
image: compressedImageUrl,
},
},
});
}

function applyUASTCCompressedTextureMaterial(primitive, scene) {
Sandcastle.declare(applyUASTCCompressedTextureMaterial); // For highlighting in Sandcastle.

var compressedImageUrl = "../images/Cesium_Logo_UASTC.ktx2";

primitive.appearance.material = new Cesium.Material({
fabric: {
Expand Down Expand Up @@ -357,11 +365,29 @@
},
},
{
text: "Compressed Image",
text: "ETC1S Compressed Image",
onselect: function () {
if (!Cesium.FeatureDetection.supportsBasis(scene)) {
window.alert(
"This browser does not support Basis Universal compressed textures"
);
}
toggleRectangleVisibility();
applyETC1SCompressedTextureMaterial(rectangle, scene);
Sandcastle.highlight(applyETC1SCompressedTextureMaterial);
},
},
{
text: "UASTC Compressed Image",
onselect: function () {
if (!Cesium.FeatureDetection.supportsBasis(scene)) {
window.alert(
"This browser does not support Basis Universal compressed textures"
);
}
toggleRectangleVisibility();
applyCompressedTextureMaterial(rectangle, scene);
Sandcastle.highlight(applyCompressedTextureMaterial);
applyUASTCCompressedTextureMaterial(rectangle, scene);
Sandcastle.highlight(applyUASTCCompressedTextureMaterial);
},
},
]);
Expand Down
Binary file added Apps/Sandcastle/images/Cesium_Logo_ETC1S.ktx2
Binary file not shown.
Binary file added Apps/Sandcastle/images/Cesium_Logo_UASTC.ktx2
Binary file not shown.
Binary file removed Apps/Sandcastle/images/LogoDXT1.ktx
Binary file not shown.
Binary file removed Apps/Sandcastle/images/LogoETC1.ktx
Binary file not shown.
Binary file removed Apps/Sandcastle/images/LogoPVR.ktx
Binary file not shown.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### 1.83 - 2021-07-01

##### Breaking Changes :mega:

- Dropped support for KTX1 and Crunch textures; use the [`ktx2ktx2`](https://github.com/KhronosGroup/KTX-Software) converter tool to update existing KTX1 files.

##### Additions :tada:

- Added dynamic terrain exaggeration with `Globe.terrainExaggeration` and `Globe.terrainExaggerationRelativeHeight`. [#9603](https://github.com/CesiumGS/cesium/pull/9603)
Expand All @@ -10,6 +14,11 @@
- Added checks for supported 3D Tiles extensions. [#9552](https://github.com/CesiumGS/cesium/issues/9552)
- Added documentation clarifying that the `outlineWidth` property will be ignored on all major browsers on Windows platforms. [#9600](https://github.com/CesiumGS/cesium/pull/9600)
- Added documentation for `KmlTour`, `KmlTourFlyTo`, and `KmlTourWait`. Added documentation and a `kmlTours` getter to `KmlDataSource`. Removed references to `KmlTourSoundCues`. [#8073](https://github.com/CesiumGS/cesium/issues/8073)
- Added support for KTX2 and Basis Universal compressed textures. [#9513](https://github.com/CesiumGS/cesium/issues/9513)
- Added support for glTF models with the [`KHR_texture_basisu`](https://github.com/KhronosGroup/glTF/blob/master/extensions/2.0/Khronos/KHR_texture_basisu/README.md) extension.
- Added support for 8-bit, 16-bit float, and 32-bit float KTX2 specular environment maps.
- Added support for KTX2 images in `Material`.
- Added new `PixelFormat` and `WebGLConstants` enums from WebGL extensions `WEBGL_compressed_texture_etc`, `WEBGL_compressed_texture_astc`, and `EXT_texture_compression_bptc`.
- Added the ability to hide outlines on OSM Buildings and other tilesets and glTF models using the CESIUM_primitive_outline extension. [#8959](https://github.com/CesiumGS/cesium/issues/8959)
- Added option to ignore extraneous colorspace information in glTF textures and `ImageBitmap`. [#9624](https://github.com/CesiumGS/cesium/pull/9624)

Expand Down
73 changes: 31 additions & 42 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,58 +556,47 @@ https://github.com/mourner/quickselect
> TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
> THIS SOFTWARE.
### crunch
### basis_universal

https://github.com/BinomialLLC/crunch
https://github.com/BinomialLLC/basis_universal

> crunch/crnlib uses the ZLIB license:
> http://opensource.org/licenses/Zlib
>
> Copyright (c) 2010-2016 Richard Geldreich, Jr. and Binomial LLC
>
> This software is provided 'as-is', without any express or implied
> warranty. In no event will the authors be held liable for any damages
> arising from the use of this software.
>
> Permission is granted to anyone to use this software for any purpose,
> including commercial applications, and to alter it and redistribute it
> freely, subject to the following restrictions:
>
> 1. The origin of this software must not be misrepresented; you must not
> claim that you wrote the original software. If you use this software
> in a product, an acknowledgment in the product documentation would be
> appreciated but is not required.
> Licensed under the Apache License, Version 2.0 (the "License"); you may not
> use this file except in compliance with the License. You may obtain a copy of
> the License at
>
> 2. Altered source versions must be plainly marked as such, and must not be
> misrepresented as being the original software.
> <http://www.apache.org/licenses/LICENSE-2.0>
>
> 3. This notice may not be removed or altered from any source distribution.
> Unless required by applicable law or agreed to in writing, software
> distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
> WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
> License for the specific language governing permissions and limitations under
> the License.
### crunch_lib.cpp
### KTX-Parse

https://github.com/Apress/html5-game-dev-insights/blob/master/jones_ch21/crunch_webgl/crunch_js/crunch_lib.cpp
https://github.com/donmccurdy/KTX-Parse/

> Copyright (c) 2013, Evan Parker, Brandon Jones. All rights reserved.
> (The MIT License)
>
> Redistribution and use in source and binary forms, with or without modification,
> are permitted provided that the following conditions are met:
> Copyright (c) 2020 Don McCurdy
>
> - Redistributions of source code must retain the above copyright notice, this
> list of conditions and the following disclaimer.
> - Redistributions in binary form must reproduce the above copyright notice,
> this list of conditions and the following disclaimer in the documentation
> and/or other materials provided with the distribution.
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
> ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
> WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
> ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
> (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
> LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
> ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
> (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
> SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \*/
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
### texture-tester

Expand Down
22 changes: 21 additions & 1 deletion Source/Core/CompressedTextureBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ import defined from "./defined.js";
* @constructor
*
* @param {PixelFormat} internalFormat The pixel format of the compressed texture.
* @param {PixelDatatype} pixelDatatype The pixel datatype of the compressed texture.
* @param {Number} width The width of the texture.
* @param {Number} height The height of the texture.
* @param {Uint8Array} buffer The compressed texture buffer.
*/
function CompressedTextureBuffer(internalFormat, width, height, buffer) {
function CompressedTextureBuffer(
internalFormat,
pixelDatatype,
width,
height,
buffer
) {
this._format = internalFormat;
this._datatype = pixelDatatype;
this._width = width;
this._height = height;
this._buffer = buffer;
Expand All @@ -29,6 +37,17 @@ Object.defineProperties(CompressedTextureBuffer.prototype, {
return this._format;
},
},
/**
* The datatype of the compressed texture.
* @type PixelDatatype
* @readonly
* @memberof CompressedTextureBuffer.prototype
*/
pixelDatatype: {
get: function () {
return this._datatype;
},
},
/**
* The width of the texture.
* @type Number
Expand Down Expand Up @@ -77,6 +96,7 @@ CompressedTextureBuffer.clone = function (object) {

return new CompressedTextureBuffer(
object._format,
object._datatype,
object._width,
object._height,
object._buffer
Expand Down
10 changes: 10 additions & 0 deletions Source/Core/FeatureDetection.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,16 @@ var FeatureDetection = {
typedArrayTypes: typedArrayTypes,
};

/**
* Detects whether the current browser supports Basis Universal textures and the web assembly modules needed to transcode them.
*
* @param {Scene} scene
* @returns {Boolean} true if the browser supports web assembly modules and the scene supports Basis Universal textures, false if not.
*/
FeatureDetection.supportsBasis = function (scene) {
return FeatureDetection.supportsWebAssembly() && scene.context.supportsBasis;
};

/**
* Detects whether the current browser supports the full screen standard.
*
Expand Down
Loading

0 comments on commit 13d5d8b

Please sign in to comment.