godot icon indicating copy to clipboard operation
godot copied to clipboard

Add specular occlusion term from AO and Bent Normals and use Bent Normals for indirect lighting

Open LunaCapra opened this issue 1 year ago • 11 comments

Closes https://github.com/godotengine/godot-proposals/issues/9401

Based on #50601

This implements approximate specular occlusion either from just ambient occlusion (from a texture, SSAO or otherwise) or ambient occlusion and cosine weighted bent normals. When bent normals are provided they will also be used for indirect lighting.

Forward+ implements the full complex implementation while mobile has a simpler calculation.

Examples (SSAO is enabled, SSR are not):

Forward+ Mobile
forward mobile

Comparison with master (Forward+, SSR and SSAO enabled) For clarification: "Inaccurate shader" in this case is a shader that calculates the bent normal occlusion but wrongly applies it as a multiplier for the AO and SPECULAR constant. grafik grafik

Test project:

BentNormalTest.zip

LunaCapra avatar Mar 28 '24 18:03 LunaCapra

Applied all the review notes

LunaCapra avatar Mar 28 '24 19:03 LunaCapra

You ignored quite a bit of those notes, they were relevant details like comment style and code formatting, it's important to pay attention to the details

AThousandShips avatar Mar 28 '24 19:03 AThousandShips

That's my bad, I'll go over them again

LunaCapra avatar Mar 28 '24 19:03 LunaCapra

Realized you had used mixed indentation in your code so updated my suggestion to fix that

AThousandShips avatar Mar 28 '24 19:03 AThousandShips

Apologies about all the issues with the shader file formatting This is my first time working on these

LunaCapra avatar Mar 28 '24 19:03 LunaCapra

It's understandable, that's what we're here for :)

AThousandShips avatar Mar 28 '24 19:03 AThousandShips

Why the effect is so different in mobile than forward?

jcostello avatar Mar 28 '24 20:03 jcostello

Why the effect is so different in mobile than forward?

It's a simpler calculation than forward+ I wouldn't mind putting the same calculation as forward+ into the mobile shader but it might perform badly with the cos and acos calls

LunaCapra avatar Mar 28 '24 20:03 LunaCapra

I fixed an error in using the direct light affect slider modified AO in the bent normal specular occlusion calculation instead of the baseline AO. This is now accurate to the paper referenced in the code.

This does not affect the previous test, as the approximation with AO only is still the same.

Before After
image image

LunaCapra avatar Apr 01 '24 20:04 LunaCapra

I added a comment linking a PDF of the paper mentioned for spherical cap intersections. This paper was only briefly mentioned in the main paper so I thought it'd be a good addition.

LunaCapra avatar Apr 18 '24 13:04 LunaCapra

I created a small scene with CC0 models from polyhaven that I also generated bent normals for. This should make testing this PR easier.

The project has TAA, SSAO, SSIL and SDFGI enabled by default.

image

LunaCapra avatar Apr 29 '24 13:04 LunaCapra