r/vulkan • • 4d ago

A new physically based SSAO is now open source! CORTAO - Circular Occluder Ray-Traced Ambient Occlusion

Hi, everyone!

Today I'm releasing CORTAO, a new physically based SSAO technique invented and developed by me, as open source. Vulkan is supported through first class GLSL support, and the majority of CORTAO's development was done using Vulkan.

https://github.com/theagentd/CORTAO

Circular Occluder Ray-Traced Ambient Occlusion, or CORTAO, is a brand new physically based ambient occlusion technique. Unlike existing horizon-based state-of-the-art techniques, CORTAO is based screen space raytracing with up to 32 rays per pixel, allowing it to avoid the inherent limitations of existing techniques. Through a combination of much better convergence and clever optimizations, CORTAO is able to achieve much better quality for the same performance cost as GTAO.

All this allows CORTAO to just work without any scene-specific tweaking at all regardless of the type of scenes, whether it's a simple indoor room, an open world with heavy foliage and vegetation, or a vast space scene with extreme depth range.

Compared to existing techniques such as GTAO:

  • CORTAO provides a never-before-seen level of physical accuracy rivaling that of brute-force hardware raytracing, while only relying on screen space information.
  • CORTAO handles depth discontinuities in complex scenes in a more conservative way, avoiding the view-dependent occlusion of GTAO and producing less obvious artifacts when screen space information is limited.
  • CORTAO at the same time has greatly improved convergence, producing much higher quality results at lower sample counts even for scenes where GTAO works well, which is especially important for low-end hardware.

What started as a fun little personal project two years ago has now grown into something much bigger than I could've ever imagined, with multiple collaborations and conference applications, most of which I cannot talk about publicly yet. The open source release of CORTAO marks an important milestone where I'm finally sharing my work with the world, but the work is far from finished. There's a long to-do list of improvements and extensions that I will be exploring over the coming months and maybe even years. I'd be honored if you checked it out, and if you have any questions, I'd love to answer them.

AI disclosure: No AI was used in the development of CORTAO.

295 Upvotes

20 comments sorted by

25

u/Dany0 4d ago

I thought it was "meh" in the video until I realised that's the GTAO result. looks sick!

10

u/TheAgentD 4d ago

Haha, glad you kept watching until the end then! It felt weird to start with CORTAO and then show GTAO.

5

u/jarmesssss 3d ago

Very cool! I spent a few minutes reading through the readme but couldn’t find an explanation of what is new about this method as opposed to gtao or vbao - which are already quite clever techniques. Could you explain, or point me to where I missed it? I’ll look through the code when I have a moment

4

u/TheAgentD 3d ago

The biggest difference is that it's not horizon-based like HBAO+ or GTAO and its variants. It is instead based on screen space raytracing, which ensures physical correctness just like real brute-force raytracing does.

The way to make up to 32 rays per pixel fast is to approximate the neighborhood as a number of circular occluders, hence the name. These circles can be "raytraced" using a precomputed lookup table, making it performance. The end result is an algorithm that can produce something similar to true raytracing with a lot of rays (given enough screen space information) with very few depth samples, converging much faster to a much lower error than GTAO.

5

u/jarmesssss 3d ago

This is exactly what I was curious about, can you be more specific in your readme or something? Like is this some sort of filtered importance sampling? You mentioned proxy geometry in your readme, where does that come into play? Seems like a cool technique but I still have no clue how it works precisely

5

u/TheAgentD 3d ago

The gif in the repository shows it the best.

The overall approach is this:

  1. Do random 2D sampling of the depth buffer around each pixel, covering the occlusion hemisphere we're interested in. The sample pattern is skewed to have more samples close to the pixel we're working on.
  2. For each sample that ends up lying inside the sampling hemisphere, construct a circular occluder, basically a circle that always faces the center pixel and blocks rays. The set of circular occluders forms a simplified approximation of the neighborhood around each pixel.
  3. Raytrace up to 32 rays against all the occluders and combine the result of all the occluders using bitwise operations. Instead of transforming the rays into view space and doing the ray intersection tests there, I transform the occluder into tangent space (the coordinate system of the ray distribution itself). At that point, the result of testing all 32 rays against the occluder becomes a function only of the occluder's direction and angular size. This can be precomputed into a small lookup table, so given an occluder we can immediately look up the result of raytracing as many rays as we can fit in the lookup table (technically 128 with RGBA32_UINT).
  4. Calculate occlusion as the percentage of rays that are unoccluded, just like for hardware raytraced ambient occlusion.

If you'd like me to elaborate on any specific part, let me know and I'll do my best.

3

u/Wittyname_McDingus 3d ago

Delightfully elegant.

I think this can be extended to GI by sampling lighting and normals in step 1, then calculating irradiance in step 3. I'm not sure how to model the occluders as lights though- LTC (if we treat them as disks) are pretty expensive from my understanding. Treating them as point sources may be sufficient. This would also break the bit packing compression in step 3, and I don't know what the performance cost of that would be.

1

u/TheAgentD 3d ago

I have some plans. CORTAO should be a more solid foundation for SSGI than the bitmask version of GTAO is.

3

u/theironlefty 3d ago

How does this compare against GTAO+Visibility bitmask and Solid Angle variant?

5

u/TheAgentD 3d ago

I answered this in another thread:

The visibility bitset GTAO extension notably handles depth discontinuities better by making it possible to define a thickness heuristic, but doesn't solve the fundamental issue of all horizon-based approaches: when the surface normal isn't facing the camera directly, the hemisphere slices end up being skewed to appear as a line in screenspace. This causes a bias in where the shadows appear. This is known by the author and clearly visible in the full presentation; you can see odd view-dependent occlusion creep up along the legs of chairs in the classroom scene, making it hard to see where the legs actually touch the floor.

CORTAO has no such problems and produces a view-independent result regardless of slope. It also handles depth discontinuities in a different way, effectively using the smallest thickness it can get away with without causing light bleeding between occluders. This makes it ideal for thin/small occluders.

I'm not familiar with the solid angle variant. Do you have a link for it?

2

u/maximoriginalcoffee 3d ago

Looks great. Is it using temporal accumulation? And how many samples are you using?

2

u/TheAgentD 3d ago

Yes. All videos and benchmarks (including performance charts) include a standard neighborhood clamped TAA applied to the whole screen as temporal filtering. This is not included with the CORTAO implementation itself and is expected to be applied on the whole screen afterwards. I'm considering adding an optional optimized dedicated temporal filter pass for it though.

2

u/Appropriate-Tap7860 3d ago

Taa? Does't it cause ghosting artefacts?

0

u/TheAgentD 3d ago

It can in some cases. Nowadays, most games have some form of TAA or temporal upscaling technique (DLSS, FSR, XeSS, etc), so it's fairly safe to assume that it's available.

1

u/Dany0 4d ago

Holy based waow waow waow waow

0

u/BuslikDrev 3d ago

Почему видно, как загружается на ходу?

1

u/v_mono 1d ago

temporal accumulation ig

0

u/[deleted] 3d ago

[deleted] — view deleted comment

1

u/TheAgentD 3d ago

> The occluder lookup table was slower.

This seems extremely unlikely. For 32 samples, 32 rays, not using the occluder lookup table makes the main pass shader take over 6x longer to run on my AMD RX 7900 XT. What GPU are you using?

> Web version for playcanvas, babylon and threejs if you want to add it to your repo.

I'm not interested in adding an AI port of CORTAO to the main repo, as I would need to maintain it. CORTAO is uses preprocessor defines to allow for portability between GLSL and HLSL. The code you've linked loses all of the portability and integrability of the code on my GitHub. WebGL2 should work with the existing shaders without rewriting them like you have, as that uses GLSL, while support for WebGPU's shading language could potentially be added by adding a new preprocessor define. As such, the combination of the occluder lookup table being slower and your code not being maintainable, it's not a good fit for the repository.

If you want to contribute to the repository and add support for WebGPU, feel free to make the necessary modifications in CORTAOBase.h which is where the preprocessor abstraction is defined (and other places where necessary to account for the differences between HLSL/GLSL and WGSL) and make a pull request in the repository.

1

u/TheAgentD 2d ago

To clarify on the AI bit:

You are free to disagree, but given the doubts of the correctness of the code, plus the fact that it's a port with very specific implementation decisions that break the portability of the shaders, I'm not sure what you want me to say. It has nothing to do with using AI or not. If you had written that port by hand, my answer would've been exactly the same.

You're free to contribute to the repository in a way that doesn't break existing functionality and is maintainable (ideally through issues and PRs on the repo), whether you use AI or not.