Ambient occlusion is a technique for achieving realstic ambient lighting that’s growing in popularity all the time. While most AO algorithms use raytracing, there is a way to fake AO very successfuly using only conventional shadow-mapping. I’m using Blender for my example, but this method should work (with small adaptations) in all major 3D applications.
We’ll start with a very simple scene containing a camera, one mesh object (which has a closed volume), no lights and no animation. We are going to approach the ambient occlusion as a separate rendering pass that will need to be composited later with the other passes (for example using the Sequence Editor), so have in mind that a little additional work will be needed if you want to incorporate the AO in a single pass rendering.
After you have your mesh object modeled/imported and the camera set, add (shift+a) a spotlight lamp and an icosphere (set Subdivision to 3), both at the centre of the mesh object (or as close to it as possible).
Scale (s) the icosphere so it’s approximately 20 to 30 times larger then the mesh object. Go to Edit mode (tab), select all vertices (a) and invert the normals of the icosphere, so that they point inside it (ctrl+shift+n). Go to the Shading/Material buttons, create a new material for the icosphere and set Alpha to 0. Finaly, go to the Object buttons and set the draw type of the icosphere to Wire (this last step isn’t necessary, but since the icosphere is only a helper object and won’t be included in the rendering; this increases the visibility of the scene in the 3D windows).
Select the spotlight, then holding shift select the icosphere and make the icosphere a parent object of the spotlight (ctrl+p). Now, with the icosphere as the active object go to the Object buttons and turn on DupliVerts and Rot. We have created instances of the spotlight on every vertex of the icosphere, oriented along the icosphere’s normals, which in turn are oriented toward the mesh object.
Select the spotlight, go to the Shading/Lamp buttons and set SpotSi, so that the instanced spots’ cones at the point of the mesh object are slightly larger then the mesh (you may have to scale the spotlight to make the cones reach the mesh; this doesn’t affect the rendering). The SpotSi setting should be somewhere between 10 and 20 degrees. After this is done, set the ClipStart and ClipEnd values, so that the star-like thing around the mesh object is slightly larger then the mesh (I’m sorry that I can’t explain this better, the point is to have the clipping planes of the shadow-maps as close to the object as possible without cutting into it). At last, turn on OnlyShad to make the spots shadow-only lights and set Energy to 0.02 (this may need to be adjusted depending on the situation, but 0.02 should be a good start; decrease the number if the AO is too dark, increase it if opposite).
Select the mesh object and go to the Shading/Material buttons. Create a new material with the default settings, set the basic color to white (with Col and RGB active move the R, G and B sliders to 1), set Emit to 1 and, finaly, set Amb to 0 as a precaution (this is not necessary if no world is present, or the Ambient Color sliders in the active world are set to 0).
Press Render (F12) and be ready to wait a little, since AO is computationally intensive, raytracing or not.
This is approximately how the whole setup should look like in the 3D window. The white object in the middle is the mesh object, the whiteish dotted line is the spotlight, the pink object is the icosphere, the black cones are the instanced spots and the black lines in the middle that make a star-like thing are their clipping distances.
The final rendering.
I hope you find this technique as useful and fun as I did. Also, have in mind that this is my first tutorial, so if you find any problems with it, please let me know and I’ll try to correct them in the future.
Do the spotlights not have to be longer, the ‘cones’ seem to be a little short? They look as though they are not covering the whole area inside the icosphere. The shadow clip distances are correct though.
I use this method all the time for stills. It has been documented many times as well. But always glad to see it pop up again.
One thisng you should also do is add a hemilight, set with no shadows and a slight blue colour to it. Set the power to about 0.2 - 0.4 to get a little bit of blue ambient light in the render.
I don’t think so. I usually do not even change the cone settings at all. I just play with the clip values. Also remember to play with the SOFT, Bias and sample values on the spot lamps as well. Always make your SOFT value 2X your SAMPLES value, (I find that works best IMO).
No, the length of the cones has no influence on the spotlights. It’s importance in this case is only as a visual helper in the 3D window. I mentioned this in the tutorial: “you may have to scale the spotlight to make the cones reach the mesh; this doesn’t affect the rendering”.
I’ve never encountered a tutorial or any other kind of text that mentioned this method, so I thought that I invented it. Oops
That could be helpful for a single pass rendering, but not if you want to render the AO as a separate pass.
Yup. Changing these settings could make a significant difference in the final output. I didn’t want to overburden the tutorial, so I didn’t mention these, but I guess I should have. Thanks for correcting my error.
This technique is very similar to the fake GI method lots of people use in blender. Of course the fake GI method only uses a hemisphere and is used in the final render. Excellent idea using this method for ambient occlusion. 8)
EDIT ----
Just tried this method out.
AO pass
Four regular lamps only
Now you just multiply the two images in your favorite image compositor (blender sequence editor) 8) and you get this
i just tried it out, but without radiosity, just using the spots as spots,
and it looks REALLY cool, it sorta has that signature X-warrior look
and looks kool, even though its only a cube!
hehe, no problem. Your method is actually a little different, as you stated, this is for getting the OA only. But it is very similar to doing the fake GI lighting.
Good point. I usually just do the single pass render anyway, so that is why I add the Hemi Light. I will try your method and see what results I can get.
Yeah, this is a good lighting technique, but with white lamps… not good for me. Maybe the developers implement a “color lamp from vertex color” into the duplivert method… We can paint the lights in vertexpaint mode!