Friday, September 18, 2009

Shadow/AOMaps

How to make Shadow Maps in Blender
-aka Ambient Occlusion(AO) maps. 
 This tutorial assumes you already have a working knowledge of Blender.

Ok, so I've got my sculpt made, in this case a new pair of boots containing many prim sculpties. All parts have 3 levels of multires. 

Step 1: Duplicate your object(s)!
Why? Because there's something buggy when you try to bake the ambient occlusion when there are multires levels.
-To duplicate first select your objects(b key+click & drag), then press shift+d and move over the new object.

Step 2: Hit the "Apply Multires" button for the duplicated objects-or all the objects you wish to bake an AO texture for. Apply it at the highest level you've got.


Step 3: Add subsurf modifiers
One thing to note, for shadow maps in Second Life it doesn't matter how many polygons you put on your model in blender. The higher the number the smoother the map will be, so I'm going to add a subsurf modifier on top of the already applied lvl 3 multires to get the best results.

So click on one of your objects and hit "Add Modifier" in the buttons panel and choose Subsurf. Give it at least 2 levels. Also do this for each object you're baking the AO map.


*When you're done with all the steps here and have successfully made AO maps, you should just for the hell of it see what it looks like if you do not apply a SubSurf modifier. You generally end up with a lot of sharp polygonish edges in the shading. Of course if your object is small and the polygons are compact enough, this might not be a problem at all :)




Step 4: Apply a texture to each object 

Click the object, go into edit mode(tab), select all vertices(A), Click on Image in the UV editor menu, New, then type in the size for the AO map you want and hit ok.
*Note the size should be square and a multiple of 2 such as: 64, 128, 256, 512, 1024. Best to go high, you can always downsize the image in your 2D program. Although the higher the longer it takes to bake.





Step5: Setup for Ambient Occlusion baking

You do not need to put any lights in your scene, or a material on your object to bake AO properly. What you do need however is to position other objects close or away from the objects you're baking. When you bake AO what it does is it takes into consideration the distance between all visible objects on your screen. So objects that are closer to the one you are baking are going to create a darker shadow on the baked map than those farther away-and of course you can move some very far to have no influence. So I first hid my original boot model(select all, hit m and then put it on another layer).Next I created a new square object and put it below the boot-because I want the bottom of the boot to have a darker shadow on it. Note I didn't put the block too close-if I did the bottom of the boot would be too black.

Step 6: Bake the Ambient Occlusion map
In the Buttons panel hit the Shading button(f5), then go to the World Buttons. In there you'll find the Amb Occ tab. The default settings will work, but you can also play with and try different things. I increased the energy a little to make the AO map a bit brighter. Of course make sure the big "Ambient Occlusion" button is checked :)




Now for the big moment...
Click the object you want to bake, then at the top of the screen go to the Render menu->Bake Render Meshes->Ambient Occlusion.

Now it should have started baking! It will take a little bit so be patient...when done you should get something that looks like this:

*If your image is ALL black, that is because your normals are flipped!(it's baking the inside of the mesh). So what to do is click the object, go to edit mode(tab), select all (a), hit w then Flip Normals. Now try baking again :)



Step 7: Save your image
You really should know how to do this ;p But if not... in the UV editor go to Image, Save As.. and save! Ok I'm not explaining the rest you better know that :D




When you are done baking everything take a look at what the maps look like on your model(Draw type->Textured in the 3d view)


Step 8: Post Process
If you've baked these maps at the default-Samples 5- then you'll notice a lot of noise in them. You can make them smoother by upping the Samples, but that takes more time to render that way. I prefer not to wait and instead apply a Guassian Blur filter in Photoshop or Gimp, or whatever 2D program you have that has it :)


Ok so that's it! Hope this helps some people. If you've got any questions or I missed something you can post below.
 

4 comments:

  1. Finally a good tutorial for AO maps :) been looking quite a while to find it :) thanks

    ReplyDelete
  2. Hi Krystal, you can deselect the big Ambient Occlusion button after doing the settings. If you leave it enabled then AO is included with a Full Render bake. With it disabled, a Full Render doesn't do AO. In this case it doesn't matter, but usually you do the AO bake (which uses the settings but doesn't care about the big button), then include the image in the materials as a multiply on the color. This way you get faster bakes on a full render as the AO part is only done once.

    ReplyDelete
  3. I followed this to the letter and still didn't end up with a shadow map that looked anything like this,I ended up with a lot of black and white lines

    ReplyDelete
  4. Absolutely perfect explanation for how to do a perfect AO bake! Worked fantastic for me using Blender 2.49/Jass magic 1.1
    Thank you so much Krystal :) your a legend!

    ReplyDelete