Baking Models

From Decentraland
Jump to: navigation, search

Baking models

Flat-shaded low poly models like people can generate in google blocks or sketchup look pretty bad with just lambertian shading + shadows. Baking lighting into these models can improve their realism hugely. Baking full global illumination isn't ideal because textures applied as lightmaps don't have enough resolution for sharp shadows, and means that you can't rotate or reposition your models without rebaking.

Ambient occlusion (AO) is great here, because it adds a layer of realism, and the baked AO works regardless of the rotation or scale of the model.

Baking AO

Using blender, you need to:

  • Import model
  • Merge geometry (if necessary)
  • Triangulate the model (if necessary)
  • Lightmap pack the model
  • Create a destination image (say 512x512 or 1024x1024 resolution)
  • Add the destination image as a node for each material in the model
  • Switch to 'ambient occlusion' in the baking settings
  • Hit bake
  • Save the image
  • Export the model with normals

It's a hard technique to learn, but can be taught. It is also possible to do all these steps from a blender python script, so we could provide it as a server-side service.

Using imagemagick

You can use imagemagick to despeckle, reduce size and brighten the map.

   convert lightmap.png -despeckle -gamma 2.2 -quality 95 lightmap.jpg

Applying the map

On your scene:

   <a-obj-model src="house.obj" material="ambientOcclusionMap: lightmap.jpg" />