bryanedds / Nu

Repository hosting the open-source Nu Game Engine and related projects.
MIT License
1.05k stars 152 forks source link

SSAO Improvements (reduce haloing) #691

Open bryanedds opened 7 months ago

bryanedds commented 7 months ago

From discord, then from cat-gpt:

your ssao technique - does it help with halos around objects like so? - image those are my biggest issue with current SSAO impl Equivoraptorrr — Today at 8:19 PM I think some amount of that is inevitable It's a little hard to see exactly what's going on, but is that particular artifact caused by the convolution or the culling of occluders too far away? It almost looks like a sharpening filter bryanedds — Today at 8:22 PM the artifact is due to the box blending if I didn't do a blend on the ssao texture, it wouldn't appear but, of course, the ssao would then look much more banded or actually, speckly i think it needs some blurring to look smooth otherwise it looks like a bunch of dots but because 0 ssao is blended with 1 ssao, it creates the halo effect Equivoraptorrr — Today at 8:24 PM In the case of the convolution, you can improve the sharpness quite a lot by discarding samples that aren't roughly along the same plane as the center pixel. bryanedds — Today at 8:24 PM and conversely, an outlining effect bryanedds — Today at 8:25 PM is that what HBAO does? Equivoraptorrr — Today at 8:25 PM I've never heard of HBAO After a quick google it looks like a very similar technique to GTAO bryanedds — Today at 8:27 PM i'm using deferred rendering, so I have a g-buffer to sample from Equivoraptorrr — Today at 8:28 PM In any case, AFAIK every technique employs some kind of convolution What I'm talking about is a way to use the screen-space geometry to cull samples in your kernel depending on whether they're on the same plane as the center, which results in sharp corners and does away with the halo effect you have there. I didn't see any tutorials mention anything of the sort, so I've had people asking me to write one 😅 bryanedds — Today at 8:31 PM so i guess add a dot here to detect that and filter - https://github.com/bryanedds/Nu/blob/master/Nu/Nu.Gaia/Assets/Default/PhysicallyBasedDeferredSsao.glsl#L136 er no, maybe earlier Equivoraptorrr — Today at 8:32 PM In your blurring pass is where you do this bryanedds — Today at 8:32 PM perhaps on line 120 all i have in my blur shader is - https://github.com/bryanedds/Nu/blob/master/Nu/Nu.Gaia/Assets/Default/PhysicallyBasedBlur.glsl i guess I'd need to pass along additional information, like the normal? Equivoraptorrr — Today at 8:34 PM Yup, normal and position. bryanedds — Today at 8:34 PM hmmmmmmmmmm

be me - Explain what Equivoraptor is describing to bryanedds

ChatGPT In the conversation, Equivoraptor is discussing with bryanedds the artifacts and issues related to screen-space ambient occlusion (SSAO) in a rendering pipeline. Specifically, bryanedds is experiencing halos around objects, and Equivoraptor suggests a possible improvement to address this.

Here's a summary:

Artifact Cause: The artifacts, in this case, seem to be caused by the box blending in the SSAO technique, resulting in halos around objects.

Blurring and Halo Effect: Bryanedds mentions that without blending, the SSAO would look more banded or speckly, and adding blending causes the halo effect.

Convolution and Sharpness: Equivoraptor suggests improving sharpness by discarding samples that aren't roughly along the same plane as the center pixel during the convolution step. This could help with sharp corners and reduce the halo effect.

Screen-Space Geometry Culling: Equivoraptor mentions using screen-space geometry to cull samples in the kernel based on whether they are on the same plane as the center. This approach can help eliminate halos and create sharp corners. The idea is to pass additional information like normal and position during the blurring pass to achieve this.

Deferred Rendering: Bryanedds mentions using deferred rendering with a G-buffer to sample from.

Blur Shader Modification: The discussion touches on modifying the blur shader (PhysicallyBasedBlur.glsl) to incorporate additional information like normal and position for better handling of the halo effect.

Need for Additional Information: Equivoraptor confirms that passing additional information, such as normal and position, is necessary for the suggested improvement.

HBAO Comparison: There's a brief mention of HBAO (Horizon-Based Ambient Occlusion), but Equivoraptor hasn't heard of it, and it's noted that it looks similar to GTAO (Ground Truth Ambient Occlusion).

Overall, the conversation revolves around addressing artifacts and halos in SSAO by considering modifications to the convolution and blurring steps, incorporating screen-space geometry, and passing additional information for better culling during the blur pass.

bryanedds commented 7 months ago

What might be simpler would be using a Gaussian blur. This might decrease haloing without much fuss.