Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement indirect specular occlusion in StandardMaterial3D #50601

Closed

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Jul 19, 2021

master version of #50603.

Both sources of AO (SSAO and AO texture maps) are used for this effect. The difference is most noticeable when SSAO is enabled (especially with height maps), but this effect also helps when SSAO is disabled.

It is an approximate effect with a very low performance cost, but makes specular reflections more believable overall.

Testing project: test_ao_specular_occlusion_master.zip

Preview

SSAO intensity was doubled to make the difference more noticeable. In real world scenarios, the difference will be more subtle.
Light Affect is set to 0 (default) both in the SSAO and material settings.

Left: partially metallic material (0.5), right: fully metallic material (1.0)

SSAO and height enabled

Forward+

Before After
Screenshot_20230526_234722 webp Screenshot_20230526_234703 webp

Mobile1

Before After
Screenshot_20230526_234747 webp Screenshot_20230526_234735 webp

No SSAO and no height (only AO map in material)

Forward+

Before After
Screenshot_20230526_234445 webp Screenshot_20230526_234424 webp

Mobile1

Before After
Screenshot_20230526_234602 webp Screenshot_20230526_234549 webp

Footnotes

  1. This currently uses a faster, but supposedly more approximate approach to indirect specular occlusion. 2

Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great as a start!

However, I don't think we should force light_affect to 1.0 for specular lighting. Light_affect is already kind of a specific hack that will only be used by some, I don't think we should force it on all users with no way to turn off.

An alternative is to separate direct specular from indirect specular and then combine them after you have applied AO to specular_light. Separating the two will also probably be desirable as we polish other rendering features.

@Calinou

This comment has been minimized.

@Calinou Calinou closed this Aug 9, 2021
@Calinou Calinou removed the archived label Aug 20, 2021
@Calinou Calinou reopened this Aug 20, 2021
@Calinou Calinou force-pushed the 3d-add-specular-occlusion branch 2 times, most recently from 7f34736 to bcfd742 Compare February 7, 2022 19:34
@Calinou Calinou changed the title Implement specular occlusion in StandardMaterial3D Treat direct AO as specular occlusion in StandardMaterial3D Feb 7, 2022
@Calinou
Copy link
Member Author

Calinou commented Feb 7, 2022

Rebased and tested again, it works as expected. New screenshots were added to OP, along with a testing project.

Let me know if I should add an Environment property to adjust specular AO intensity, though I'd prefer the effect to be enabled by default. If the unused Ao Channel Affect Environment property is removed, this should free up some space in the Environment inspector anyway.

@clayjohn
Copy link
Member

clayjohn commented Feb 7, 2022

This PR still has the problem that it treats direct and indirect specular the same. It is darkening both direct and indirect by the full amount of ao regardless of the ao_light_effect setting. AO should only impact indirect light unless a user specifically sets it to impact direct lighting. The Filament docs have a very nice section explaining how specular occlusion can be derived from ambient occlusion: https://google.github.io/filament/Filament.html#lighting/occlusion/specularocclusion

@Calinou
Copy link
Member Author

Calinou commented Feb 7, 2022

This PR still has the problem that it treats direct and indirect specular the same. It is darkening both direct and indirect by the full amount of ao regardless of the ao_light_effect setting. AO should only impact indirect light unless a user specifically sets it to impact direct lighting. The Filament docs have a very nice section explaining how specular occlusion can be derived from ambient occlusion: google.github.io/filament/Filament.html#lighting/occlusion/specularocclusion

I managed to separate direct specular lighting from indirect specular lighting and use the Filament approximation. See OP for updated screenshots 🙂

However, this appears to have a significant performance cost (0.2 ms of added frame time in my test scene, with SSAO and height mapping disabled). I expected it to be cheaper, given the description on the Filament website. I've tried to move ndotv so it's only calculated once, but performance didn't get better.

If I remove the Filament approximation but keep the indirect specular multiplication based on original AO, I get the exact same result (but with better performance):

SSAO + height

2022-02-07_23 37 55_highend_after_ao_cheaper

No SSAO and height

2022-02-07_23 35 49_lowend_after_ao_cheaper

Difference with original "After" images

The images are bit-for-bit identical:

dssim 2022-02-07_23.20.15_highend_after_ao.png 2022-02-07_23.37.55_highend_after_ao_cheaper.png 
0.00000000      2022-02-07_23.37.55_highend_after_ao_cheaper.png

dssim 2022-02-07_23.20.38_lowend_after_ao.png 2022-02-07_23.35.49_lowend_after_ao_cheaper.png 
0.00000000      2022-02-07_23.35.49_lowend_after_ao_cheaper.png

Note that I still need to port the changes to the mobile renderer.

@Calinou Calinou changed the title Treat direct AO as specular occlusion in StandardMaterial3D Implement indirect specular occlusion in StandardMaterial3D Feb 7, 2022
@YuriSizov YuriSizov modified the milestones: 4.0, 4.1 Feb 9, 2023
@clayjohn clayjohn modified the milestones: 4.1, 4.x May 23, 2023
@Calinou Calinou force-pushed the 3d-add-specular-occlusion branch from 2a21625 to 087c774 Compare May 26, 2023 21:49
@Calinou
Copy link
Member Author

Calinou commented May 26, 2023

Rebased and tested again, it works as expected. I've updated screenshots in OP. Note that this comment still applies.

This uses the approximation from Filament. Direct specular lighting
(such as light specular lobes) are not affected.

Both sources of AO (SSAO and AO texture maps) are used for this effect.
The difference is most noticeable when SSAO is enabled (especially with
height maps), but this effect also helps when SSAO is disabled.

It is an approximate effect with a low performance cost, but it makes
specular reflections more believable overall.
@Calinou
Copy link
Member Author

Calinou commented Mar 29, 2024

@Calinou Calinou closed this Mar 29, 2024
@AThousandShips AThousandShips removed this from the 4.x milestone Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants