pex-gl / pex-renderer

Physically based renderer (PBR) and scene graph for PEX.
https://pex-gl.github.io/pex-renderer/examples/index.html
MIT License
236 stars 16 forks source link

Revert brdf #226

Closed vorg closed 5 years ago

vorg commented 5 years ago

While adding clear coat big restructuring happened in parallel. This commit cleans up and simplifies the clear coat code:

vorg commented 5 years ago

Screenshot 2019-08-06 at 13 21 43

vorg commented 5 years ago

After removing specularColor some materials got darker

Screenshot 2019-08-06 at 15 43 15

Investigating:

lightColor = same exposure = same diffuseColor = same f0 = same directColor color = is different directColor lightColor = is darker -> old tested version had double light intensity bug, once fixed they are the same

indirectDiffuse = same indirectSpecular = is darker specularReflectance = is darker prefilteredRadiance = same f0 = same

Here is the reason. We use new reflectance based formula for f0 but old f0 mixing for specularColor.

data.f0 = 0.16 * uReflectance * uReflectance * (1.0 - data.metallic) + data.baseColor.rgb * data.metallic;
data.specularColor = mix(data.f0, data.baseColor, data.metallic);

But is it? For default reflectance of 0.5 it should produce identical result. Hmm. Another clue only mid values for metallic and clearCoat examples are impacted Replacing F0 formulate with specularColor mix based one, fixed metallic material but not clearCoat.

Fixed: as specularColor is based on f0 that already takes metallic ratio into account, blending it again using metallic moves it even closer to 1. The solution is to use uncorrelated version of F0. So new version is corect and old version was too bright. This confirms yet another reason to keep only F0

data.specularColor = mix(vec3(0.16 * uReflectance * uReflectance), data.baseColor, data.metallic);