turanszkij / WickedEngine

3D engine with modern graphics
https://wickedengine.net
Other
5.78k stars 606 forks source link

Incorrect BRDF rendering of rough materials #736

Closed Nolram12345 closed 1 year ago

Nolram12345 commented 1 year ago

There seems to be some incorrect rendering of rough materials in WickedEngine. Continuing from the discussions on the Discord, rough materials are still rendered with specularity, resulting in incorrect lighting them, which is noticeable especially when validating against other renderers. See footage below, where I compare rendering of this tree 3D model in this HDRI in WI vs Blender (Cycles and Eevee), and also a comparison of a simple fully black cube. It's probably worth a further investigation.

https://github.com/turanszkij/WickedEngine/assets/37701550/71a915f6-0121-4de2-8672-392bab1cbeb2

https://github.com/turanszkij/WickedEngine/assets/37701550/c6ab8452-a18d-4ee6-824e-c2c3e68531fa

https://github.com/turanszkij/WickedEngine/assets/37701550/52581f49-f951-4dae-9b38-178f3adf5247

Nolram12345 commented 1 year ago

Here is another white furnace example with the tree model illustrating the issue. https://github.com/turanszkij/WickedEngine/assets/37701550/f8d5de59-0e4b-4ff6-919b-b5cf7857c24c

turanszkij commented 1 year ago

Right now it mostly matches Windows 3D Viewer result

Windows 10 3D Viewer: image

Wicked Engine: sc_25-08-2023 06-58-59

(I had to remove vertex colors from the model, otherwise it's mostly balck)

turanszkij commented 1 year ago

I'm having problems with Blender, I couldn't really find a way to adjust roughness easily. But I agree that Blender renders it differently, as if it doesn't have fresnel effect.

turanszkij commented 1 year ago

Gestaltor reference GLTF viewer: image

Wicked Engine: sc_25-08-2023 08-22-14

I think it's pretty close.

LVutner commented 1 year ago

Seems like a plain Schlick is being used for IBL reflection, instead of DFG term. https://github.com/turanszkij/WickedEngine/blob/19280fc45e868bebde31489684457e3e2266ecea/WickedEngine/shaders/surfaceHF.hlsli#L244

I suggest to bake DFG lookup table for IBL, or use approximations (ie. https://www.unrealengine.com/en-US/blog/physically-based-shading-on-mobile).

Nolram12345 commented 1 year ago

Right now it mostly matches Windows 3D Viewer result

Windows 10 3D Viewer: image

Wicked Engine: sc_25-08-2023 06-58-59

(I had to remove vertex colors from the model, otherwise it's mostly balck)

I see that, however the visual output here is definitely wrong. A bark material with those rough properties should have that metallic sheen. Therefore I would say that the PBR model in the windows 3D viewer is probably flawed as well (which isn't terribly surprising considering its a very basic viewer that isn't designed for accuracy or production rendering). I therefore think taking orientation against both other renderers who don't exude this behaviour and real-life reference is probably better.

LVutner may be onto something with the usage of Schlick for IBL reflection.

brakhane commented 1 year ago

I'm having problems with Blender, I couldn't really find a way to adjust roughness easily. But I agree that Blender renders it differently, as if it doesn't have fresnel effect.

The model has a roughness map, if you go on the material settings, and click on the dot at roughness ("separate color") you can then choose "remove link" in the menu. After that you can modify the roughness value globally. Wicked and Blender are close for low values, but begin to differ after 0.4 or so.

turanszkij commented 1 year ago

Seems like a plain Schlick is being used for IBL reflection, instead of DFG term.

https://github.com/turanszkij/WickedEngine/blob/19280fc45e868bebde31489684457e3e2266ecea/WickedEngine/shaders/surfaceHF.hlsli#L244

I suggest to bake DFG lookup table for IBL, or use approximations (ie. https://www.unrealengine.com/en-US/blog/physically-based-shading-on-mobile).

After replacing the Schlick with the EnvBRDFApprox in the article you linked:

Wicked Roughness 1: sc_25-08-2023 20-20-59

Blender roughness 1: image

Wicked Rougness 0: sc_25-08-2023 20-20-53

Blender roughness 0: image

LVutner commented 1 year ago

Cool. The minor differences comes from DFG itself.

Nolram12345 commented 1 year ago

That looks a lot better! Can't wait to try it and see if it improves things :)

turanszkij commented 1 year ago

Some more notes on IBL DFG terms: https://knarkowicz.wordpress.com/2014/12/27/analytical-dfg-term-for-ibl/ https://github.com/TheRealMJP/DXRPathTracer/blob/master/SampleFramework12/v1.02/Shaders/BRDF.hlsl#L209

turanszkij commented 1 year ago

Added this in the PR: https://github.com/turanszkij/WickedEngine/pull/737 Let me know if this is matching expectations.

turanszkij commented 1 year ago

The following fixes were made since this issue was opened: