Using the AO pass in the compositor (solved again ... hopefully)

I am currently participating at the lighting challenge #13 at cgtalk.
I want to use the AO pass in the compositor to add AO to my final image. The AO pass was rendered once and since the scene and camera angle is fixed, there is no more need to do this pass all over again.

And here comes my problem. I tried several approaches of mixing the AO-pass back in, but with no satisfying result.

So I went back to a basic scene with only a cube in it and tried again. First I tried to directly mix the non-ao image with the ao-pass with all obvious operation modes from the mix node, but to no avail.
Then I tried to mix the non-ao image with a fixed color (black, gray) and use the AO-pass as factor to the mixing node. Again, not the result as I get with the the internal renderer.

When I started to tweak the AO-pass with the RGB-Curves tool, I soon realized thtat this is leading nowhere. So I wondered what algorithm is actually used in the internal render. If it is some sort of compositing, then I should be able to get the same result.

Is there anybody here, who could give me some insight into this topic ?

Any help is highly appreciated.

Plz let me know or update the manual http://wiki.blender.org/index.php/Manual/Render_Passes when you find out. thx.

off the top of my head, it is grainy and needs to be blurred. Second, it should be used to darken the colors, so I would think you feed it in as the FAC socket to an RGB curve or now there is a Darken node i think.

You should be able to multiply pure AO with an image and get decent results. However it’s not clear what you mean when you say it isn’t working and what is your desired effect. Could you post some images?

Also if you post in the CGTalk forum Jeremy should be able to help you, at least in general terms that we could then translate into Blender.

If you are experiencing problems with nodes, you may want to read this thread.
http://blenderartists.org/forum/showthread.php?t=112480

I too have run into problems expecting nodes to work a certain way and discovering that they do not.

But this sketch rendering tutorial I went through used the AO pass and it worked perfectly!
http://matthieu3d.free.fr/TutoVira2/tut2en.html

Multiply was my choice too. Regarding to some sources from the internet, this would be the way to go.

I have attached an image showing the problem I have. You see there there the render with ao as blender internally processes it and next to them the ao pass and the render without ao.
The next 3 images show the effect of multiplying the ao-pass with different factors. What is immediately visible is that the composited image lacks contrast. This would hint at some additional processing inside blender, where some contrast is added. One could play around now until satisfied with the result, but I want to understand the process to be able to use it efficiently in my projects.

My goal in the end is the be able to get all the separate passes from the render engine and have fix rules of how to compose them to get the same result as the internal renderer is giving me. Only if this goal is reached I am free to divert from here in a puposeful way. Now only the ao-pass and the color pass is giving me headaches.

Actually this very question was already asked there, with an answer hinting at a multiply operation.

I hoped that someone here could tell me about how to do this, because if anyhow possible I would rather not look into the code itself.

Attachments


well, i can tell you there is no way to get from “no ao” to “with ao” by multiplying, since the no ao image is darker than the with ao…so anything medium gray times anything less than 1 will yield an even darker image. So, if indeed you didnt accidentally mess up your pics, then I would say to multiply (1-ao) and add that to the original.

Unfortunately, that did not work as desired.

But I think I’ve found out the basic principle how this ao pass is applied in blender. Analyzing the images, I found out that a simple add function had to be used. To get this additive I subtracted the non-ao image from the ao one and investigated how you would achieve this image from the ao-pass.
As it turns out there is a linear RGB-Curves operation involved. Instead of the RGB-Curve Tool (which is hard to exactly parametrize) you can also use the ColorRamp Node.

In the current example I had to choose the 2nd color to be a 40% gray (0% being black) and moved the slider for the first color to the middle. I have a screenshot attached to demonstrate the idea.

I will now further investigate if these empirically derived values are constants or are themselves dependent on some AO parameters ( I suspect the energy parameter to be a possible candidate).

Attachments


After some serious experimentation I dare to say that I have deciphered the algorithm behind the AO compositing. As you will see the results are consistent and allow several AO setings with only one AO-pass ever rendered.

Here is what I found. The basic AO compositing is done in two steps:

  • Brightness/Contrast adjust of the AO pass itself.
  • Adding of the adjusted AO-pass with a factor to the AO-less image.

Now what is really interesting, is that these two steps represent the settings of the AO-mode (Add,Sub,Both) and Energy, with the Brightness/Contrast setting controlling the mode and the factor for the Add operation controlling the Energy.

The translation is as follows:
AO modes:

  • Add: brightness 13, contrast 15
  • Sub: brightness -93, contrast 15
  • Both: brightness -20, contrast 60

Energy:
The Energy level from 0 to 3 is mapped to the add node factor from 0 0 to 1.0

All this holds true regardless of the other AO settings. And as mentioned above, with only once an AO-pass done you are free to try out different modes and energy levels without any rendering penalty.

I have attached a screenshot demonstrating this method using the node system.

Be warned though, that this is still a working hypothesis/theory based on the observed behaviour of the system. Being trained as a physicist I know that any theory holds true until falsified by new facts, or in this special case until a check into the source code gives a verdict.

But so far all my tests in various combinations gave me a maximum error of below 0.1% compared to the original blender render, which fits my needs quite nicely.

Attachments


You cannot add the AO pass as a color-it is a black/white gradient. It has to multiply the color intensity values. Use a colored image to start with and you will see what I mean. I will play if my cat lets me. and researvch the release notes - there was a noodle there that I thought used everythign. see http://www.blender.org/development/release-logs/blender-243/render-passes/

You are right . Color destroys my setup completely :(.

The information at the link you provided just states the following:

AO
The Ambient Occlusion pass. RGB floats. It is the ‘raw’ pass, not converted to ‘diffuse’ as used for the Combined pass (so it does not store options “Add”, “Sub” or “Both”). When this is the only pass active, no shading or shadow calculation happens.

But there is information on how to convert it to diffuse.

I give up experimenting and will have a look into the source code.

Use the source luke …

Well the source code is quite understandable and here is the result in terms of the compositor (see attached image).

In words:

1.Depending on the AO mode do the following:
Add: directly use the AO pass
Sub: Calculate AO - 1
Both: Calculate 2*AO - 1

  1. multiply step 1 with the AO energy level
  2. multiply step 2 with the material’s ambience value. ( When having different materials one would have to create an ambience map somehow … )
  3. multiply step3 with the color pass
  4. add step4 to the diffuse pass

If shadows are involved they have to be added to the diffuse pass before adding the converted ao pass.

Looks like if you are going to manually process teh AO pass you have also to handle all the other passes as well …

Attachments


Thanks loramel! wiki updated.