KhronosGroup / glTF-Sample-Viewer

Physically-Based Rendering in glTF 2.0 using WebGL
Apache License 2.0
1.26k stars 231 forks source link

Clearcoat renders Fresnel reflectance on both coat and base layer. #546

Open rsahlin opened 3 months ago

rsahlin commented 3 months ago

As clearcoat is an additional layer (with IOR 1.5) that light interacts with prior to interaction with the base-layer, there shall be no Fresnel reflection in the base-layer (unless material uses IOR extension).

The below image is from ClearCoatTest.glb in the sample asset repo: image

Compare 'Base layer' and 'Coated' columns and you will see that the reflection from the 'Base layer' are still present when using clearcoat.

Instead it should look like this - here you can see that the reflection from the 'Base layer' is not present in the coated versions.

image

rsahlin commented 2 months ago

I created a new version of the clearcoat test model, adding a column where the base material uses IOR = 2.0 This is to show that we can get the fresnel reflection from both the clearcoat and base layer using glTF extensions.

Now we just need to adapt the ior extension to allow setting the refractive index on metals as well. I really see no reason why not.

image

rsahlin commented 2 months ago

And here is the adapted clearcoattest glb with an added column using the ior extension.

ClearCoatTestIOR.zip

proog128 commented 2 months ago

The sample viewer probably is following the (non-normative) implementation recommendations in KHR_materials_clearcoat. This implementation has some limitations, in particular:

The index of refraction of clearcoat and base layer do not influence each other. The Fresnel terms are computed independently. source

The implementation details described in ADOBE_materials_clearcoat_specular will not solve this issue right away, because it only affects the clearcoat Fresnel. However, we would require the base layer Fresnel to take the clearcoat IOR into account (clearcoat/base interface). As you explained, this is actually the more physically correct behavior.

The downside of this approach is that it is comptutationally more expensive: it requires the base Fresnel to be evaluated twice, because we now have to blend between a base layer with clearcoat on top and a base layer without clearcoat on top, based on the clearcoat strength.

rsahlin commented 2 months ago

Well, either way it is a material property that is only calculated once per material based on IOR values.

The reflectivity factor is calculated using the Schlick approximation and is really fast, fixing this will not have an impact on performance. It is important that the sample-viewer is using physically correct calculations!

UX3D-haertl commented 2 weeks ago

Currently we always follow the spec implementation sections. If we want to use a more sophisticated version we need to clarify that this is not following the spec description. From my point of view it would make more sense to first add the described method as an alternative implementation in the clearcoat readme and updated sample viewer afterwards accordingly.