Blender Raytrace Baker

From Unify Community Wiki
Revision as of 19:26, 19 October 2009 by NCarter (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search



This tutorial will show you one way how to bake textures with Blender to create lightmaps. Lightmaps are use to generate static shadows at e.g. terrains or buildings.


Gettings Started

First lets get the Python Script which will help you to bake better than the procedural Texure Baker shipped with Blender.

Visit this site and download the Blender Raytrace Baker 3.4. For now you can ignore the rest of the content of the alienhelpdesk site. I'll explain all important settings later.

After you downloaded the script copy it to the 'scripts' folder of Blender.

If you don't know how to access this folder do the following:

  • Use the Finder's "Go" menu from the menu bar on the top of your screen. Here you enter the name of the folder in "Go to Folder" . On my system it is here: /Applications/Blender/

Now start Blender and lets begin.

How to bake

Create Meshes and UVmaps

  • Create a Cube with Add -> Mesh -> Cube. (If there isn't already a cube created in the new file.)
  • Create a Plane with Add -> Mesh -> Plane and place it (Key G then Key Z then move the mouse) below the Cube and Scale it (Key S then move the mouse). The result should look like this:

Blend RB cubePlane1.jpg

(Perspective View)

  • Select the Plane and switch to the Edit Mode. Press the key W and click 'Subdivide Multi', set the number of cuts to 3 and click 'OK'. -We want to keep the example as simple as possible but it is useful to use a plane with more than 2 faces because this is the typical setup of e.g. a terrain.
  • Press the Space Key and convert the quads into triangles like shown here:

Blend RB convertToTriangles.jpg

Or just press the Keys Ctrl+T.

  • Now switch to View -> Orthographic if it isn't already set. Then to View -> Top.
  • We should now create the UVmap of the plane. Split the window with your 3D objects that you have two windows. Let's use the right window for the UVmap by changing the window type to 'UV/Image Editor'.
  • Switch from the 'Edit Mode' to 'UV Face Select' in the left window. Press the key U and click 'Project from View' (left window). You can see the UVmap in the right window. Mouse over the right window, press the key A to select the whole map and press the key S and scale the UVmap that it is a little bit smaller than the squared grey grid. Press the key G to move the UVmap if you have to. The result should look like this:

Blend RB PlaneUV.jpg

  • In the left window switch to Object Mode and select the cube. Switch to Edit mode. Enable the 'Edge Select Mode'.

Now (multi-)select (LMB + Shift) the following edges (shown yellow):

Blend RB cubeEdges.jpg

(Perspective View)

  • Press Space in the left window (mouse over) and select Mark Seam:

Blend RB spacePressed.jpg

or just press Ctrl + E and click 'Mark Seam'. These Seams help Blender to know where you want to cut the UVmap to get it from 3D to 2D. The Seams should now appear orange.

  • Press the Space Key and convert the quads into triangles like shown here:

Blend RB convertToTriangles2.jpg

Or just press the Keys Ctrl+T.

  • Switch to the 'UV Face Select Mode' in the left window. Press A to select all faces if they aren't already selected.
  • Press the key U and click 'Unwrap' in the left window. Select the whole UVmap in the right window by pressing the key A if it isn't already selected. Scale, change the position and rotate (key R) it that it looks like this:

Blend RB cubeUV.jpg

Set up the lights

  • Now it's time to set up some lights. One light should already exist in the scene by default so lets add another.

Click Add -> Lamp -> Area to add an area light which is able to cast soft shadows. Manipulate the 2 lights like shown here:

Blend RB lightLocation.jpg

(Perspective View)

  • Now we have to change some settings of the Arealight to get a soft shadow effect so select the Arealight. Change to the Shading Panel by pressing the Key F5 and select the Lamp Buttons.

Blend RB lightConfig.jpg

  • Next to the red dots all important setting are marked:

Blend RB lightConfig2.jpg

Rendering Settings

  • Switch to the Scene Panel with Key F10 and click Image Buttons.

Blend RB renderSettingsPanel.jpg

  • Make sure that all your settings are the same as shown here:

Blend RB renderSettings.jpg

Prepare Baking

First save your project... (Have a look at Important Notes if you want to know why.)

  • Go back to Object Mode and select the plane.
  • In the right window switch to Scripts Window Type.

Blend RB scriptBaker.jpg

  • You don't have to make big changes. The only thing you have to do is to activate 'to UV coords'.

Blend RB scriptWindow.jpg

  • Fill in something useful as 'path' - the location to which your baked texture will be saved.

If you're using Blender on Windows, and you have installed Blender on (for example) drive E: and you fill in /bakedTextures/letsTest then the baked texture is saved to E:/bakedTextures with the filename letsTest.png (if you selected .png as filetype).

  • Let's save the baked texture as .PNG.


  • Hit RUN SCRIPT... and lounge back (if your chair has a back rest^^).
  • After it has finished, click EXIT in the Raytrace Baker window.

You should get a result like this:

Blend RB testPlane.jpg

It's not finished yet... so be cool. ;)

  • Now let's do the same for the cube. Select the cube in Object Mode, open the Raytrace Baker script, change the settings and click RUN SCRIPT again to create the lightmap of the cube.

You should get this result:

Blend RB testCube.jpg

Polish the Result

The shadows don't look very convincing yet.

  • Open the pane texture with a picture editor of your choice. I'll use The Gimp in this tutorial.
  • Now use Filter -> Blur -> Gaussian Blur. Set the value to 15 or so and click OK. Now the shadow should look softer than before.
  • Open the Cubetexture and with a close look you will find one pixel wide lines between the sides of the cube.

It's a pity, but I really don't know how to fix this. Even a talk with macouno, the creator of the script, didn't help... So we have to fix this by hand. (This can also happen for the plane texture... but only as very rare 1x1 pixel impurities if you did nothing wrong.) Just paint out the one pixel lines using an appropriate color.

See a result here. It uses Unity's built in Lightmapped/BumpedSpecular Shader.

Important Notes

  • Re-open the Raytrace Baker script every time after you change the next object you want to bake.
  • The Raytrace Baker script will change some things in the project that you won't be able to bake the same object 2 or more times without to change back some settings. If you bake the same object twice without changing the settings, the result will be pretty crappy.
  • Scale all textures in your picture editor to have power of two dimension, or Unity won't import them.
Personal tools