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

Add bindings and shaders for bent normals used in ambient occlusion #6301

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

devthenecro
Copy link

@devthenecro devthenecro commented Aug 15, 2024

As discussed in HL forums https://www.hard-light.net/forums/index.php?topic=99354.0

Example of production use: https://dev.epicgames.com/documentation/en-us/unreal-engine/bent-normal-maps?application_version=4.27

This feature is used to improve accuracy of ambient occlusion by using pre-generated normal maps that contain vectors pointing in least occluded direction.
Reflective light is handled by calculating dot product between the reflected vector and the normal, and then mixing this with ambient occlusion map.
Diffuse ambient lighting is simply shifted to this new vector.
Primary contribution of this feature is however direct lighting, as this allows AO to work with direct lighting without creating nasty artifact or looking like a decal.

Example
https://imgsli.com/Mjg4MTUy

@devthenecro devthenecro marked this pull request as draft August 15, 2024 21:36
@devthenecro devthenecro marked this pull request as ready for review August 16, 2024 00:06
@qazwsxal
Copy link
Contributor

Just had a little look at the shaders, my understanding of bent normals was that they were meant to be used for indirect lighting only as an approximation to GI, but it looks like you've applied them to the deferred/direct lights too? (deferred-f.sdr line 210)

@devthenecro
Copy link
Author

devthenecro commented Aug 16, 2024

Bent normals do hold occlusion directionality, while the AO map holds the scalar value of the occlusion. Together it can approximate a cone of visibility, so it should be possible to check this to create decent approximation of the direct light occlusion.

See for example https://github.com/GameTechDev/XeGTAO/blob/a5b1686c7ea37788eeb3576b5be47f7c03db532c/Source/Rendering/Shaders/Lighting/vaPointLight.hlsli#L33

EDIT: While it's excellent for direct diffuse lights, it introduces some over occlusion for glossy lights. The mentioned link produces very acceptable results, while there are techniques that produce even better image quality, at cost of less accurate glossy lighting.
See:
https://www.activision.com/cdn/research/siggraph_2018_opt.pdf
and
http://advances.realtimerendering.com/other/2016/naughty_dog/index.html.

@wookieejedi wookieejedi added the enhancement A new feature or upgrade of an existing feature to add additional functionality. label Aug 16, 2024
…mmer's microoshadowing for direct occlusion ( still use green channel from AO )

bugfixes
@Goober5000 Goober5000 added the Waiting for Stable Marks a pull request that is to be merged after the next stable release, due to a release cycle label Aug 27, 2024
@Goober5000 Goober5000 removed the Waiting for Stable Marks a pull request that is to be merged after the next stable release, due to a release cycle label Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or upgrade of an existing feature to add additional functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants