Skip to content

Blender bake normal maps for tiny renderer

Christian Weihsbach edited this page Jan 12, 2021 · 2 revisions

How to bake normal maps from blender for tinyrenderer

Prerequisites:

Wavefront .obj file was exported using coordinate system: -Z forward Y Up

Bake out normal maps in blender for tinyrenderer

  • Deselect application of all modifiers in render view (ensures high quality output)
  • Add image in image editor(blank, 32bit float can be unchecked)
  • Add alpha, specify size

For every object to be baked:

Select correct UV map in Object data properties -> UV Maps

For every material of the object:

  • Add image texture node in Shader editor (not connected to anything)
  • Select created image where the normal map is baked to

Select all objects to be baked

Render properties -> Bake

Settings to bake global, world space normal maps:

  • Blender does not support baking world space normal maps out of the box. But you can change axis in baking runs to get all the X,Y,Z axis info you need.

Bake Type normal, Space object, margin 3px, clear image yes. Bake 3 times and after each run save the output image (should be grayscale as all color channels have the same axis selected: Save image as Targa RGBA (loss less RLE compression), use descriptive name like +X.tga Swizzle R, G, B = +X, +X, +X Swizzle R, G, B = -Y, -Y, -Y Swizzle R, G, B = +Z, +Z, +Z

Open each image in Gimp. Duplicate one of the opened images. Use Colors-> Decompose to split channels into layers. Remove the red, green, blue layer (but keep alpha) and add the contents of the 3 images to the new image. Rename the layers:

Layer of +X image: red Layer of -Y image: blue Layer of +Z image: green

This is necessary because of the different coordinate systems in OpenGL and blender

Use Colors -> Compose to generate a new image. You should see the correct normal map now. Export as targa (origin = bottom left) BLE compression.

Settings to bake tangent space normal maps:

Swizzle R, G, B = -X, -Y, Z

Ambient occlusion maps

No special thing here. Use image without alpha channel and set image mode to grayscale (with gimp)