Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement glTF extension KHR_materials_anisotropy #11988

Merged
merged 13 commits into from
May 29, 2024
400 changes: 400 additions & 0 deletions Apps/Sandcastle/gallery/development/glTF PBR Anisotropy.html

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
###### Additions :tada:

- Added support for glTF models with the [KHR_materials_specular extension](https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_specular). [#11970](https://github.com/CesiumGS/cesium/pull/11970)
- Added support for glTF models with the [KHR_materials_anisotropy extension](https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_anisotropy/README.md). [#11988](https://github.com/CesiumGS/cesium/pull/11988)

#### Fixes :wrench:

- Fixed a bug where `scene.pickPosition` returned incorrect results against the globe when `depthTestAgainstTerrain` is `false`. [#4368](https://github.com/CesiumGS/cesium/issues/4368)
- Fixed a bug where `TaskProcessor` worker loading would check the worker module ID rather than the absolute URL when determining if it is cross-origin. [#11833](https://github.com/CesiumGS/cesium/pull/11833)
- Fixed a bug where cross-origin workers would error when loaded with the CommonJS `importScripts` shim instead of an ESM `import`. [#11833](https://github.com/CesiumGS/cesium/pull/11833)
- Corrected the Typescript types for `Billboard.id` and `Label.id` to be `any` [#11973](https://github.com/CesiumGS/cesium/issues/11973)
- Fixed a normalization error in image-based lighting [#11994](https://github.com/CesiumGS/cesium/issues/11994)

### 1.117 - 2024-05-01

Expand Down
11 changes: 11 additions & 0 deletions Specs/Data/Models/glTF-2.0/BoxAnisotropy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Box Anisotropy

## Screenshot

![screenshot](screenshot/screenshot.png)

## License Information

Developed by Cesium for testing the KHR_materials_anisotropy extension. Please follow the [Cesium Trademark Terms and Conditions](https://github.com/AnalyticalGraphicsInc/cesium/wiki/CesiumTrademark.pdf).

This model is licensed under a [Creative Commons Attribution 4.0 International License](http://creativecommons.org/licenses/by/4.0/).
Binary file not shown.
201 changes: 201 additions & 0 deletions Specs/Data/Models/glTF-2.0/BoxAnisotropy/glTF/BoxAnisotropy.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
{
"asset": {
"generator": "COLLADA2GLTF",
"version": "2.0"
},
"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,
"TEXCOORD_0": 3
},
"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"
},
{
"bufferView": 2,
"byteOffset": 0,
"componentType": 5126,
"count": 24,
"max": [
6.0,
1.0
],
"min": [
0.0,
0.0
],
"type": "VEC2"
}
],
"materials": [
{
"pbrMetallicRoughness": {
"baseColorTexture": {
"index": 0
},
"metallicFactor": 0.0
},
"normalTexture": {
"index": 0
},
"name": "Texture",
"extensions": {
"KHR_materials_anisotropy": {
"anisotropyStrength": 0.5,
"anisotropyRotation": 0.349065850398866,
"anisotropyTexture": {
"index": 0
}
}
}
}
],
"textures": [
{
"sampler": 0,
"source": 0
}
],
"images": [
{
"uri": "CesiumLogoFlat.png"
}
],
"samplers": [
{
"magFilter": 9729,
"minFilter": 9986,
"wrapS": 10497,
"wrapT": 10497
}
],
"bufferViews": [
{
"buffer": 0,
"byteOffset": 768,
"byteLength": 72,
"target": 34963
},
{
"buffer": 0,
"byteOffset": 0,
"byteLength": 576,
"byteStride": 12,
"target": 34962
},
{
"buffer": 0,
"byteOffset": 576,
"byteLength": 192,
"byteStride": 8,
"target": 34962
}
],
"buffers": [
{
"byteLength": 840,
"uri": "BoxAnisotropy.bin"
}
],
"extensionsRequired": [
"KHR_draco_mesh_compression",
"KHR_materials_anisotropy"
],
"extensionsUsed": [
"KHR_draco_mesh_compression",
"KHR_materials_anisotropy"
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 27 additions & 1 deletion packages/engine/Source/Scene/GltfLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const {
MetallicRoughness,
SpecularGlossiness,
Specular,
Anisotropy,
Material,
} = ModelComponents;

Expand Down Expand Up @@ -1565,6 +1566,27 @@ function loadSpecular(loader, specularInfo, frameState) {
return specular;
}

function loadAnisotropy(loader, anisotropyInfo, frameState) {
const {
anisotropyStrength = Anisotropy.DEFAULT_ANISOTROPY_STRENGTH,
anisotropyRotation = Anisotropy.DEFAULT_ANISOTROPY_ROTATION,
anisotropyTexture,
} = anisotropyInfo;

const anisotropy = new Anisotropy();
if (defined(anisotropyTexture)) {
anisotropy.anisotropyTexture = loadTexture(
loader,
anisotropyTexture,
frameState
);
}
anisotropy.anisotropyStrength = anisotropyStrength;
anisotropy.anisotropyRotation = anisotropyRotation;

return anisotropy;
}

/**
* Load textures and parse factors and flags for a glTF material
*
Expand All @@ -1583,6 +1605,7 @@ function loadMaterial(loader, gltfMaterial, frameState) {
);
const pbrSpecularGlossiness = extensions.KHR_materials_pbrSpecularGlossiness;
const pbrSpecular = extensions.KHR_materials_specular;
const pbrAnisotropy = extensions.KHR_materials_anisotropy;
const pbrMetallicRoughness = gltfMaterial.pbrMetallicRoughness;

material.unlit = defined(extensions.KHR_materials_unlit);
Expand All @@ -1601,9 +1624,12 @@ function loadMaterial(loader, gltfMaterial, frameState) {
frameState
);
}
if (defined(pbrSpecular)) {
if (defined(pbrSpecular) && !material.unlit) {
material.specular = loadSpecular(loader, pbrSpecular, frameState);
}
if (defined(pbrAnisotropy) && !material.unlit) {
material.anisotropy = loadAnisotropy(loader, pbrAnisotropy, frameState);
}
}

// Top level textures
Expand Down
Loading