KHR Materials ClearCoat implementation is incomplete (only clearcoatFactor is taken into account)
Description
I have 2 samples:
- ClearcoatTexture.r=1.gltf uses clearcoatFactor=1 and a white clearcoatTexture
- ClearcoatTexture.r=0.gltf uses clearcoatFactor=1 and a black clearcoatTexture
According to the KHR_materials_clearcoat specs the clearcoat effect is controlled by:
clearcoat = clearcoatFactor * clearcoatTexture.r
Sample#1 should be rendered with a clearcoat Sample#2 should be rendered without a clearcoat
Both samples render properly in https://github.khronos.org/glTF-Sample-Viewer-Release/
But they are rendered identically in model-viewer.
as if only clearcoatFactor was taken into account.
Live Demo
https://glitch.com/edit/#!/versed-magnetic-trouble
Note
2 months ago I started filling this very same issue because my test conducted in the editor https://modelviewer.dev/editor/ exposed the issue. I then proceeded to present it in a glitch and noticed the issue wasn't reproductible. (both samples were rendered properly) I concluded that the editor version was perhaps behind in terms of versions and that the issue was fixed in the newer version. So I didn't submitted the issue report. Today It appears that there perhaps was a regression... so here I am again.
Version
- model-viewer: vX.X.X
Hi @thibaud-be, thanks for letting us know. Do you see the same issue with the latest version of Editor as well or it's only happening in your demo?
@samaneh-kazemi yes the problem occurs in the latest version of the editor as well
@thibaud-be Thanks for sharing. This sounds like a three.js problem. Have you also tried it in a simple three.js project? Make sure to sync to the latest version of three.js
@thibaud-be Actually, I just checked your gltf files, and I noticed that in both files clear factor is set to 1. It seems to work once I update the factor to 0 in your gltf file and upload it in the editor.
"materials": [
{
"extensions": {
"KHR_materials_clearcoat": {
"clearcoatFactor": 1,
@samaneh-kazemi yes you're right, but that is precisely the point of this issue.
The specs are clearcoatfactor * clearcoattexture.r so sample1 is 1*1=1(full clear coat) and sample2 is 1*0=0 (no clear coat)
@thibaud-be ah my bad. I lost the scope as I was looking into the file.
This is likely a shader implementation detail in Three.js. @mrdoob might have some insight here?
Actually, I just noticed a fix for this in three.js r135 which I pulled in here: https://github.com/google/model-viewer/pull/3004
I had to update the ClearCoat test image, and I believe it fixed this exactly. Please comment if you can still repro on master (aka the current editor).
This is either not fixed or there has been a regression
@diegoteran Would you mind taking a look at this since you're in the midst of expanding related APIs? The above Glitch repros the problem and includes helpful GLBs.
I did a small test with clearcoatFactor=1 and a gradient for the clearcoatTexture and it seems to be working fine now. Probably ThreeJS fixed something on their side during our latest release.