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_clearcoat #12006

Merged
merged 24 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
73393f5
Add Sandcastle for testing KHR_Materials_clearcoat
May 18, 2024
f65ad0c
Load data for KHR_materials_clearcoat
May 18, 2024
8f21b06
Process KHR_materials_clearcoat data in shader (WIP)
May 19, 2024
c4da3f4
Simplify PBR lighting shaders
May 21, 2024
d03bb1a
Refactor LightingStageFS and related functions
May 25, 2024
3b6ca76
Simplify light color handling in PBR rendering
May 25, 2024
ebfe3bd
Refactor LightingStageFS
May 26, 2024
038fbc8
Partial implementation of clearcoat for direct lighting
May 28, 2024
52ed2c7
Fix bug in image-based lighting, and apply IBL to clearcoat
May 28, 2024
4e3c5f7
Compute IBL sampling transform on CPU
May 28, 2024
2b1639f
Decouple diffuse and specular in procedural IBL
May 28, 2024
fc027d6
Merge branch 'gltf-pbr-anisotropy' into gltf-pbr-clearcoat
May 29, 2024
3897c5d
Apply procedural IBL to clearcoat
May 29, 2024
d17af9a
Fix light color for procedural IBL on clearcoat
May 29, 2024
4cbeb61
Use clearcoat normal map when supplied
May 29, 2024
cca3ddb
Address TODO comments
May 30, 2024
6eb7cd0
Update MaterialPipelineStageSpec to ES6
May 30, 2024
ce128c7
Add rendering test for KHR_materials_clearcoat
May 30, 2024
aecf606
Merge branch 'main' into gltf-pbr-clearcoat
May 30, 2024
61bb866
Update CHANGES.md, PR feedback
May 30, 2024
b00d937
Merge branch 'main' into gltf-pbr-clearcoat
May 30, 2024
f1ef109
Clarify argument cleaning in smithVisibilityGGX
May 31, 2024
424d6a4
Fix bug for models with no IBL
May 31, 2024
bd92351
Fix shader compilation problem
May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
418 changes: 418 additions & 0 deletions Apps/Sandcastle/gallery/development/glTF PBR Clearcoat.html

Large diffs are not rendered by default.

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

## Screenshot

![screenshot](screenshot/screenshot.png)

## License Information

Developed by Cesium for testing the KHR_materials_clearcoat 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.
204 changes: 204 additions & 0 deletions Specs/Data/Models/glTF-2.0/BoxClearcoat/glTF/BoxClearcoat.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
{
"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
},
"name": "Texture",
"extensions": {
"KHR_materials_clearcoat": {
"clearcoatFactor": 0.5,
"clearcoatRoughnessFactor": 0.2,
"clearcoatTexture": {
"index": 0
},
"clearcoatRoughnessTexture": {
"index": 0
},
"clearcoatNormalTexture": {
"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": "BoxClearcoat.bin"
}
],
"extensionsRequired": [
"KHR_draco_mesh_compression",
"KHR_materials_clearcoat"
],
"extensionsUsed": [
"KHR_draco_mesh_compression",
"KHR_materials_clearcoat"
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions packages/engine/Source/Scene/GltfLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const {
SpecularGlossiness,
Specular,
Anisotropy,
Clearcoat,
Material,
} = ModelComponents;

Expand Down Expand Up @@ -1587,6 +1588,43 @@ function loadAnisotropy(loader, anisotropyInfo, frameState) {
return anisotropy;
}

function loadClearcoat(loader, clearcoatInfo, frameState) {
const {
clearcoatFactor = Clearcoat.DEFAULT_CLEARCOAT_FACTOR,
clearcoatTexture,
clearcoatRoughnessFactor = Clearcoat.DEFAULT_CLEARCOAT_ROUGHNESS_FACTOR,
clearcoatRoughnessTexture,
clearcoatNormalTexture,
} = clearcoatInfo;

const clearcoat = new Clearcoat();
if (defined(clearcoatTexture)) {
clearcoat.clearcoatTexture = loadTexture(
loader,
clearcoatTexture,
frameState
);
}
if (defined(clearcoatRoughnessTexture)) {
clearcoat.clearcoatRoughnessTexture = loadTexture(
loader,
clearcoatRoughnessTexture,
frameState
);
}
if (defined(clearcoatNormalTexture)) {
clearcoat.clearcoatNormalTexture = loadTexture(
loader,
clearcoatNormalTexture,
frameState
);
}
clearcoat.clearcoatFactor = clearcoatFactor;
clearcoat.clearcoatRoughnessFactor = clearcoatRoughnessFactor;

return clearcoat;
}

/**
* Load textures and parse factors and flags for a glTF material
*
Expand All @@ -1606,6 +1644,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 pbrClearcoat = extensions.KHR_materials_clearcoat;
const pbrMetallicRoughness = gltfMaterial.pbrMetallicRoughness;

material.unlit = defined(extensions.KHR_materials_unlit);
Expand All @@ -1630,6 +1669,9 @@ function loadMaterial(loader, gltfMaterial, frameState) {
if (defined(pbrAnisotropy) && !material.unlit) {
material.anisotropy = loadAnisotropy(loader, pbrAnisotropy, frameState);
}
if (defined(pbrClearcoat) && material.unlit === false) {
jjhembd marked this conversation as resolved.
Show resolved Hide resolved
material.clearcoat = loadClearcoat(loader, pbrClearcoat, frameState);
}
}

// Top level textures
Expand Down
6 changes: 2 additions & 4 deletions packages/engine/Source/Scene/Model/LightingPipelineStage.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ const LightingPipelineStage = {
* @private
*/
LightingPipelineStage.process = function (renderResources, primitive) {
const model = renderResources.model;
const lightingOptions = renderResources.lightingOptions;
const shaderBuilder = renderResources.shaderBuilder;
const { model, lightingOptions, shaderBuilder } = renderResources;

if (defined(model.lightColor)) {
shaderBuilder.addDefine(
Expand All @@ -53,7 +51,7 @@ LightingPipelineStage.process = function (renderResources, primitive) {

// The lighting model is always set by the material. However, custom shaders
// can override this.
const lightingModel = lightingOptions.lightingModel;
const { lightingModel } = lightingOptions;

if (lightingModel === LightingModel.PBR) {
shaderBuilder.addDefine(
Expand Down
Loading
Loading