Advertisement

Calculate AO on the fly?

Started by May 11, 2021 09:21 AM
6 comments, last by Shem_Namo 3 years, 4 months ago

Hey guys, how's it going?

Is it possible to calculate Ambient Occlusion without having to render the Z and Normals data to a texture?

I have access to the Depth and Normals information inside the fragment shader, so is there a way to just calculate AO inside the fragment shader?

I know the most common way to calculate AO is in Screen Space, but are there any other ways that it can be done?

Thanks in Advance, Shem

Consider the neighboring texels. I'm by no means an expert on fragment shaders, but isn't the point that you're writing to several pixels in parallel, so it wouldn't know the depth values of its neighbors? That's why you use a texture AFAIK.

If you know the model and can make some assumptions, you could fake it; but it wouldn't be a one-size fits all.
For instance, if the model already represents a depth map or has a point where stuff gets naturally darker, you could just darken the fragment as you went along.

But for some proper, general AO, I think you'll be sampling a texture anyhow.

Advertisement

Shem_Namo said:
I know the most common way to calculate AO is in Screen Space, but are there any other ways that it can be done?

Option 1: Bake AO to textures. But that's per object then, so multiple objects won't occlude each other.

Option 2: Calculate AO in world space, e.g. using raytracing, voxel cone tracing, SDF sphere tracing, etc.
But if you do this expensive stuff in pixel shader, chances are a triangle drawn later overwrites those results, so that's a total waste and redundant work for opaque geometry. Would make sense only for transparent stuff.

So even if traced AO is used, you'll do it only after all (or a certain layer of) geometry has been drawn and final visibility is known.

Another option would be to do depth pre pass and use resulting depth in the next pass to calc SSAO in pixel shader. But you don't want this for the same reason.

Thanks for the suggestions guys!!

I have another question, is it possible to calculate ray traced AO in a fragment shader?

Thanks again,

Shem Namo

Shem_Namo said:
is it possible to calculate ray traced AO in a fragment shader?

Should be possible with DXR 1.1 inline tracing, which allows to trace rays from any shader stage.

But as said above, it's not efficient, because you calculate very expensive RT AO for fragments which might be overdrawn later with other triangles.

I guess you could use depth prepass to avoid this form happening (too often). Though, if you have that and it contains all geometry, you could just do a RT AO pass with resulting depth, and combine AO result with a later forward shading pass. Surely faster than adding RT to various pixel shaders lowering occupancy on all ends.

Nowadays you almost always have this scene information in a texture somewhere. If you want “soft particles” you need the depth information of the scene. And tons of other screen space techniques.

Without them you simply know a pixel that is being rendered and it's depth. Nothing about the pixels around it. You could be operating on the first pixel being written in a scene, so you have no other information on the depth around it. There are other techniques to store neighboring objects etc though. Data about the scene stored in tiny information for global illumination.

NBA2K, Madden, Maneater, Killing Floor, Sims

Advertisement

Thanks guys!! I really appreciate your help!!

This topic is closed to new replies.

Advertisement