model-viewer icon indicating copy to clipboard operation
model-viewer copied to clipboard

KHR Materials ClearCoat implementation is incomplete (only clearcoatFactor is taken into account)

Open thibaud-be opened this issue 5 years ago • 11 comments

Description

I have 2 samples:

  1. ClearcoatTexture.r=1.gltf uses clearcoatFactor=1 and a white clearcoatTexture
  2. 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

thibaud-be avatar Nov 08 '21 21:11 thibaud-be

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 avatar Nov 09 '21 01:11 samaneh-kazemi

@samaneh-kazemi yes the problem occurs in the latest version of the editor as well

thibaud-be avatar Nov 09 '21 09:11 thibaud-be

@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

samaneh-kazemi avatar Nov 09 '21 23:11 samaneh-kazemi

@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 avatar Nov 09 '21 23:11 samaneh-kazemi

@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 avatar Nov 10 '21 01:11 thibaud-be

@thibaud-be ah my bad. I lost the scope as I was looking into the file.

samaneh-kazemi avatar Nov 10 '21 22:11 samaneh-kazemi

This is likely a shader implementation detail in Three.js. @mrdoob might have some insight here?

ghost avatar Nov 11 '21 23:11 ghost

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).

elalish avatar Dec 01 '21 00:12 elalish

This is either not fixed or there has been a regression

thibaud-be avatar Jun 21 '23 09:06 thibaud-be

@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.

elalish avatar Jun 26 '23 19:06 elalish

Screenshot 2023-09-22 at 2 52 21 PM

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.

diegoteran avatar Sep 22 '23 21:09 diegoteran