Help - Search - Members - Calendar
Full Version: Screen Based Ambient Occlusion
Hash, Inc. Forums > The A:M Exchange (Resources Center / Contributers Cue) > 3rd Party Programs, Utilities and Products > FakeAO / FastAO (CPU/GPU)
Pages: 1, 2
JohnArtbox
Click to view attachmentClick to view attachment
I discovered this on the weekend and thought it might be of interest. It's a 2d trick for faking ambient occlusion using the depth channel, running it through an unsharp mask and then subtracting that from the original. It takes a fraction of a second to render and is quite effective. Obviously not perfect, and there's a much better method that uses the depth map and a normal pass, but I don't have the knowledge to test it within AM or Fusion. I don't know if it could be implemented as a shader/material?

Info is from http://meshula.net/wordpress/?p=145 . This is the Blender technique from that page.
John Bigboote
I like this idea... great use for a depth matte , among many others. Another reason for me to start rendering to EXRs. Thanks!
robcat2075
That is very, very interesting. That technique would probably suffice for most of the things people want AO for.

Thanks!
robcat2075
I note that A:M's Composite feature has Blur and Subtract modes so it should be possible for some clever user to achieve this in some fashion in A:M as it is now.

But it would be cool if this were something that could be a final render option. Maybe it would be a Post Effect .
JohnArtbox
Tried to replicate the effect in AM composite without success. I'm sure that subtracting identical images should result in black (but it doesn't). Having said that i'm far from an expert at Composite and would love to be proved wrong smile.gif

The depth image was rendered the old fashioned way, 100% ambient white objects with black fog in a separate pass. The open exr depth passes still seem to give me a lot of trouble.
robcat2075
I mis read your original post and didn't notice the "unsharp mask" part. A:M composite doesn't have that, I suppose because we don't typically doctor fuzzy photographs in A:M.

It could be done I suppose.




robcat2075
When I do a "Difference" in A:M composite with identical images I get black.

What's the difference between "Difference" and "Subtract"?




There is somethign in EXR depth channels. Here's a result I got by doing a Merge>Difference on the depthmap and the depthmap blurred.

Not the AO result but at least I know there's something in there.

Click to view attachment
robcat2075
Here's an A:M Composite setup that brings the depth map image in humanly visible range.

Click to view attachment

EXR depthmaps tend to look all-white because they record a distance from the camera to the object in each pixel rather than the visual appearance of "fog" or a gradient shader you've put on a scene. That distance is almost always greater than 1.0 (cm I presume) which ceilings out at white when displayed. If your display could do greater than 1.0 you'd be looking at something like the brightness of the sun.

However, we don't have a depth based DOF blur filter in A:M so using depth maps for depth is really more something for a dedicated compositing app like After Effects.
NancyGormezano
QUOTE(robcat2075 @ Jun 7 2010, 07:59 AM) *
When I do a "Difference" in A:M composite with identical images I get black.

What's the difference between "Difference" and "Subtract"?


Do not know if definition is the same in A:M but from Adobe:

QUOTE
Difference For each color channel, subtracts the darker of the input values from the lighter. Painting with white inverts the backdrop color; painting with black produces no change.

If you have two layers with an identical visual element that you want to align, place one layer on top of the other and set the blending mode of the top layer to Difference. Then, you can move one layer or the other until the pixels of the visual element that you want to line up are all black—meaning that the differences between the pixels are zero and therefore the elements are stacked exactly on top of one another.


Exclusion Creates a result similar to but lower in contrast than the Difference mode. If the source color is white, the result color is the complement of the underlying color. If the source color is black, the result color is the underlying color.


Do not know what subtract is - other than perhaps subtract layer B (underlying) from layer A (source)? and truncate to black (integer)? or allow to go negative (floating point?). I obviously haven't tried it.

robcat2075
revised Depthmap extraction process...

http://www.hash.com/forums/index.php?s=&am...st&p=332106


"unsharp mask" is a fairly simple process. I bet someone could reproduce that in A:M composite.
robcat2075
Hey, John, what are the steps you used to get from the depth map to your AO result?

I haven't been able to get something that good from the explanation in the link.
detbear
This is a great topic. I know some productions actually texture a AO shadow into models. So creating some sort of "shader" or direct steps to get AO like shadows onto a model would be huge. Render times on true AO shadows is so time consuming.

John...I would also like to see the results you got from that method. Would you also be able to do something like that in post after render I wonder??

TheSpleen
I have no idea what you folks are talking about. LOL
But I read every post and can see that this program does a heck of alot more than I had thunk.
I am fascinated. smile.gif
John Bigboote
From what I understand... which is limited... you really need to 'pull and push' with the settings to get the depth's range spot-on to your character's Zdepth... it's a 64-bit image so the color depth is there... you need to experiment with the front and back ranges of the image until it visually encompasses your character(like John did in original post)...and from there... you keyframe it!
JohnArtbox
My computer's blown up(every two years...like clockwork) so I don't have access to the fusion flow file...this is what I remember.
I couldn't pull the required info from a depth map in the time that I had, so I generated the depth map the old fashioned way, turn off colour maps, bump colour to white and ambience to 100% then add black fog which starts at the beginning of the characters and goes back several metres.
Once I had the depth map I took it into Fusion(my compositor of choice) and added an unsharp mask blur operator(filter) I took the output of that into a boolean operator which subtracted it from the original depth map, playing with the blur and gain components of the unsharp mask until the boolean gave the result I wanted, I then composited this over a white image.
When I get Fusion working on the new machine I'll confirm the process.
Robcat: thanks for the info on extracting the depth layer, one I get a machine working I'll try it out. Hopefully the details above fill in the info, if not, more info will come in a few days.
detbear: this is a post process and the images above are the end result.
JohnBigboote: Someone on the forum kindly emailed me an script which converted AM depth buffers into industry standard depth format, but I have to pull it off backup. The white object/black fog method has the advantage of being very easy visualise.
robcat2075
I'm trying to convert this into Photoshop steps. The pdf article is rather vague on some terms, like "low pass" filter which could mean lots of things.

QUOTE(JohnArtbox @ Jun 12 2010, 05:10 AM) *
Once I had the depth map I took it into Fusion(my compositor of choice) and added an unsharp mask blur operator(filter)

so far so good...

QUOTE
I took the output of that into a boolean operator which subtracted it from the original depth map,


That part I don't understand. "Boolean" is things like AND, OR, NOT... while subtraction is none of those really. Can you tell me more about Boolean that subtracts?



QUOTE
playing with the blur and gain components of the unsharp mask until the boolean gave the result I wanted, I then composited this over a white image.


What compositing mode?

Yes, get your computer back together and tell us more!
NancyGormezano
QUOTE(robcat2075 @ Jun 12 2010, 07:21 AM) *
That part I don't understand. "Boolean" is things like AND, OR, NOT... while subtraction is none of those really. Can you tell me more about Boolean that subtracts?


Another WAG from WaggieWoman: Do not know what boolean subtract is but perhaps subtract is equivalent to inverting the blurred or unsharpened image and then ADDing the original with the modified image ?

I still don't get how distance, depth (from camera, either with depth map or via fog) can be an approximation for general shadowing/occlusion/reflection cast by surfaces on surrounding surfaces -

I would think it would have more to do with using normal maps.

Perhaps generating an image using A:M plugin for normal map, inverting that image, blur/unsharpening image, "adding (subtracting)" the 2, and desaturating - then multiplying/adding that image with flat color image?

Although I must admit I don't understand why blurring, unsharpening and using the "difference" has anything to do with generating an approximation to occulsion either. Does it just produce general noise?

I didn't really grok the article either.
NancyGormezano
here's image I did with normal maps, from chor with a ground plane, and a dome. The other is image ai=100, ao=100, 1 pass (but no dome unfortunately) -

perhaps you can play with the normal image to see if they can be combined somehow to produce something that approximates the AO render - I have yet to find/do something that I think is suitable
NancyGormezano
Another idea is to somehow use matcap shader. I did an AO render of a sphere and then used that as the image for the matcap shader applied to mouse (1 pass) . No lights, ai=0, ao =0
robcat2075
QUOTE(NancyGormezano @ Jun 12 2010, 01:55 PM) *
I still don't get how distance, depth (from camera, either with depth map or via fog) can be an approximation for general shadowing/occlusion/reflection cast by surfaces on surrounding surfaces


This is my bare understanding of it.

Suppose you have three block set up like on the left with lots of ambient illumination all around. If we were viewing it from above the corresponding depth map might look like the image on the right.

Click to view attachment

Th horizontal surface at b is shielded ( occluded) from the ambient illumjination by the block next to it so it will be somewhat darker there.

a and c are occluded by taller surfaces so they will be more dark. d is quite a ways away from any occluding shape so it might be only slightly darker.

e is not occluded by anything so it will not be darkened at all.

look at the same spots on the depth map and notice that there is a correlation between how much occlusion a spot will get and how close it is on the depth map to some area that is lighter and how much brighter that area is.

If you could make a filter that would darken areas just based on how close they were to light areas on the depth map you'd be getting something similar to occlusion lighting. An inexact cheat, but a fast cheat.




robcat2075
Hey... now that I thought it thru I may be getting it.

I blurred my depth map, then composited that with a regular copy of the depth map using lighten. This means the blur effect is omitted from any part that is lighter in the regular than in the blurrred. dark areas next to light areas get blurred but not vice-versa.


Then I combined that with another regular copy using difference. that gave an all black image except for the blurred parts that were lighter.

Inverting that got me this final result which looks a lot like an occlusion render.

Click to view attachment



I think all of these steps can be done in A:M composite.
NancyGormezano
Thanks for explanation.

heres my depth map (using black fog) - I haven't gotten anything yet to approximate the AO image to qualify as close enough - but I like the fog image just the way it is. That's probably the closest.

I tried what you just posted - but I wouldn't call any results I got as acceptable for the mouse, it seems to me to be less acceptable.

I will try more
NancyGormezano
best result (for me) so far seems to be combining matcap render (fast) with render done only with AI=100, AO=0 - also fast. Ground plane is another story - but could use klieg z buf shadows.
robcat2075
here's one attempt.

Click to view attachment
detbear
Nancy,

I've been thinking for some time now whether a mat cap shader might be created to stick onto characters as AO shadows. I wonder how that could be refined to get a little better result.
detbear
Seems like a shader could be produced to somehow darken creases in an AO fashion. Not sure if Mat Cap alone can do it.
robcat2075
Matcap will not be able to simulate AO. Matcap glues a single lighting scheme onto every shape without regard to how the shapes might block the light from one another. It's really closest to a render with shadows off which is very unlike AO.

Matcap works best in situations where occlusion is not significant in shading the object.
photoman
Random thought here... There should be an option (plugin shader perhaps?) to let an user override all materials with another material, so that you could render a pure AO scene without taking off all the materials on every model....

Just a thought, excuse the intrusion.

Photoman
NancyGormezano
QUOTE(detbear @ Jun 12 2010, 04:26 PM) *
Nancy,

I've been thinking for some time now whether a mat cap shader might be created to stick onto characters as AO shadows. I wonder how that could be refined to get a little better result.


I'm not sure what quality of AO you are looking for? These are all approximations, and my guess is that each situation should be handled differently. If you had a still image with what you are going for, then perhaps a quicker lighting scheme could be worked out, and maybe even using Matcap, and maybe not.

When I look at AO images - all I see is a lotta grainy noise, diffuse shadows, maybe some color spill. A still image gets studied for accuracy. An animation doesn't.

For another approximation, I gave all models a roughness (20%?) then I did an IBL render (with any ol' color image - you would use something suitable for the scene)- with AI=100, AO= 0, added a klieg light - directly overhead, made shadows 100% soft, 100% dark black. If you want darker shadows, or different direction, you would add lights, and maybe run a shadow pass? Combined in Photoshop with the flat shaded render using multiply. You could work brightness/contrast in post, along with other tweaks.

just another look -
robcat2075
QUOTE(photoman @ Jun 12 2010, 07:13 PM) *
There should be an option (plugin shader perhaps?) to let an user override all materials with another material, so that you could render a pure AO scene without taking off all the materials on every model....


OpenEXR renders do that. There's an ambient occlusion buffer is AO is on. Multi-pass has to be on for that I think.
robcat2075
The one area this process really falls short is where something is very far in back of something else. That makes the process create a very dark area whereas in a typical AO situation there wouldn't be any occlusion at all happening there.

The depth map contains this distance information so i wonder if there is some way to make large front to back distance cause the darkening to not happen?
robcat2075
Here's an all-AMComposite result

Click to view attachment

MattWBradbury
Sorry for getting to the party late. I just wanted to add some other uses of SSAO.

The video Game Crysis (to my knowledge) was the first game to actually implement SSAO. Here are some examples of the shading in the engine:




I wonder if there would be a way to find the rendering source code for this to see exactly how they were getting these results, especially the use of normal maps in non-lighted areas.
robcat2075
I hope someone who understands that paper would read that paper and figure out what they are doing. A:M can render us normal and depth buffers automatically so it's just waiting for us to use them right.
MattWBradbury
For those interested, I found an article explaining the algorithms used to calculate the SSAO.

A Simple and Practical Approach to SSAO

Apparently they are also using depth buffers, but I don't think rendering out an image would be necessary.
photoman
After reading that article the author basically states that all that is need for SSAO is a depth buffer and a normal buffer. Doesn't A:M have those options for OpenEXR buffers? Would it be possible to somehow use that shader model to render SSAO with A:M OpenEXR's?

Photoman
ypoissant
Basically, the depth and the normal buffers, together, can be viewed as representing a sort of "bas-relief" of the rendered scene. With the normal buffer, you know where the faces are pointing to, and with the depth buffer, you know which faces are in front of which. With this in hand, for every pixel, you determine how deep is the surface and how it is oriented. Then you query the pixels around, given a preset search radius, and compute how far and in which direction the queried pixels are relative to the shaded pixel. Like for normal AO, you accumulate the number of pixels around that are occluding relative to the pixels that are not occluding and this gives you the AO value. That is the basic idea. It gets trickyer when trying to get rid of artifacts though.

This is not an algorithm that can be implemented with the AM composite. This would require a special post plugin for that.

What is implementable with AM composite is the cheaper algorithm based on Unsharp mask with the depth buffer. This technique is actually very similar to how toon lines are computed except that the blur radius is quite larger and the blur operator is of much lower contrast.
detbear
I will dream of such a pluggin in hopes that it may be created someday. Rendering "AO-like" shadows in this manner would be incredible speed wise. Nothing replaces the real deal....but the time trade off would be huge.

I am seeing lately in the "Next-Gen" games that these type of "real time" workarounds are being developed for speed. I think it very wise to apply these to projects that can't afford the vast time/ resources needed for true AO renders at 24fps.
NancyGormezano
I was fooling around today with trying to fake this in photoshop and see how it compares with A:M's AO. I used both a fog based depth map with a normal map. I did not include any background. And for blurring I used gaussian - 4 pixel width.

I gaussed the depth map and differenced it with the original depth map and inverted.

Also gaussed the normal map and differenced it with the original normal and inverted

Combined the color layer (flat shaded render) (multiply) with the resultant depth map layer ( darken), and the resultant normal layer (luminosity)

The above produced the most satisfactory results - but its still a long way from AO renders

(EDIT- changed image - uploaded the wrong one)
robcat2075
QUOTE(ypoissant @ Jun 15 2010, 05:58 PM) *
Basically, the depth and the normal buffers, together, can be viewed as representing a sort of "bas-relief" of the rendered scene. With the normal buffer, you know where the faces are pointing to, and with the depth buffer, you know which faces are in front of which....


Yves, given the code examples in the paper, how hard would it be for a knowledgeable A:M programmer to create a such plugin for A:M? I'm guessing that since this is all done with the depth and normal buffers there's no polygon vs. spline problems involved, right? And is it possible to make this plugin write the AO effect to an EXR buffer?

QUOTE
What is implementable with AM composite is the cheaper algorithm based on Unsharp mask with the depth buffer. This technique is actually very similar to how toon lines are computed except that the blur radius is quite larger and the blur operator is of much lower contrast.


I'd say this one is less worth pursuing since there are so many situations where it gives a poor result.

JohnArtbox
Coming in late but I just resurrected my machine. Here is the original composite steps and settings from Fusion
Click to view attachment
ypoissant
QUOTE(robcat2075 @ Jun 15 2010, 09:53 PM) *
Yves, given the code examples in the paper, how hard would it be for a knowledgeable A:M programmer to create a such plugin for A:M? I'm guessing that since this is all done with the depth and normal buffers there's no polygon vs. spline problems involved, right? And is it possible to make this plugin write the AO effect to an EXR buffer?

The post plugin API is easy to figure and use. It does not require much knowledge of A:M. Just knowledge of what an image buffer is basically. In a post plugin, you read image buffers and output image bufers where image buffer are represented with floating point values per RGB components per pixel. There are no notion of EXR at this stage.

The whole job requires implementing the techniques described in the papers, articles, blogs and threads. In term of required knowledge, thus, a good grasp of vector math is essential. Some basic knowledge of sampling theory and monte carlo integration will help in understanding the techniques explained in the papers and will help in debugging because this is where the problems and artifacts will arise. A naive implementation that does not follow monte carlo integration rules for distribution of samples or properly weighting them will break down on every curve. Already knowing the theory for traditional AO and how it is implemented would provide a very good start.
MattWBradbury
I seem to remember a crackerjack programmer who had an awe-inspiring grasp of monte carlo simulations with a seemingly comprehensive understanding of A:M's ambient occlusion framework laugh.gif
rasikrodri
Check this out, techniques for very fast radiosity. http://www.uni-koblenz.de/~ritschel/
animas3D
Could someone tell me what a matcap shader is?
JohnArtbox
matcap thread
Written by willi, it basically shades the model using a spherical image. It's a simple way to get some quite complicated effects.
detbear
Click to view attachmentClick to view attachmentI got this result... Looks kind of similar to whatever the Crysis example showed.
robcat2075
QUOTE(detbear @ Jun 17 2010, 05:44 PM) *
Click to view attachmentClick to view attachmentI got this result... Looks kind of similar to whatever the Crysis example showed.


There's some directional light in that, right?

And what were the steps in that?
detbear
Click to view attachment

Here is another result... Yes...I used directional lights....However...it's all in the model setting in the choreography...This becomes a shadow onto a camera projection. I figure in video games ..cameras follow the characters around...Why not a light projection as well.

It's all in the characters choreography settings here.

1.Add a white image to the camera as a rotoscope.
2.Make sure your lights are Klieg and the shadow type is Z-buffer...or it won't work sad.gif
3.IMPORTANT....set the model to both front projection and flat shaded.....both to "ON"
4.Also make sure the cast shadows and receive shadows is set to on...

NancyGormezano
Ah yes - the melty look:

http://www.hash.com/forums/index.php?act=a...st&id=44608

I had done some experimenting with that here

The look becomes dependant on the angle of the klieg lights
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.