Lightmapping Tutorial Part 1 : Maya + Turtle Renderer

Moderator: BenChang

Lightmapping Tutorial Part 1 : Maya + Turtle Renderer

Postby BenChang » Sun Oct 13, 2013 5:45 am


In this tutorial we'll do the basic setup for lightmapping using the Turtle Renderer plugin in Maya. In part 2, we'll load the lightmaps into a scene in the Panda3D game engine.

Much of the visual quality of a scene depends on lighting. In "dynamic lighting", each light (point light, directional light, spotlight, etc) is calculated against every visible bit of geometry every frame. So adding more lights to a scene, and using more complex lighting features such as shadows, global illumination, or raytracing increases the computational cost and at a certain point will lower your framerate. "Static lighting", or Lightmapping, is a method of precalculating some or all of the lighting computations and baking them into either textures or vertex data. The advantage of lightmaps is that you can use as many lights as you want, including high-cost lights like Area lights, as well as complex shadows, ambient occlusion, raytracing, global illumination such as Final Gather or Radiosity, caustics, and other fancy techniques. The limitation, of course, is that the lights can't change in-game; or if they do change, you have to do it yourself through things like texture blending. In general,any light that stays still can be used with lightmapping, while any light that moves will need to be a dynamic light. You can use both together in the same scene.

For some general background on lightmapping, see this article on the Polycount wiki:

We'll set up a basic scene in Maya, use the Turtle Renderer plugin to create lightmaps, export the maya scene to Panda, and write some simple code in Panda to load and apply the lightmaps.

The complete project folder, with the Maya files and the Panda script, is attached to this post.
(9.12 MiB) Downloaded 184 times

Project setup

Create a folder called "lightmaptest". This will contain everything, both the maya files and the panda files. Another workflow option is to keep your maya files separate, but then you do have to take an extra step of copying over textures and lightmap data from your maya directory to your Panda project, so since I'm kind of lazy I'll just keep everything in one place.

In Maya, go to File->Set Project and select your "lightmaptest" folder. This will make it so that your scene file, your .egg file, and your lightmap textures will all get stored here.

Creating the Maya Scene


The scene is pretty simple, just some basic poly geometry. There's a directional light to create shadows, and a few point lights around the embers (those little cubes). I've given the directional light a little bit of a warm yellow hue, which will create an effect of warm sunlight contrasting against cool shadows in the final render. Here's what this looks like with a default Maya Software Render:

Setting up Turtle

Load the Turtle Plugin in Maya

1. Window->Settings and Preferences->Plugin Manager
2. Find Turtle.mll, and check the boxes for "Loaded" and "Auto Load".
3. Close the Plugin Manager window.

Turtle's render settings

Turtle can operate in two modes, Render and Bake. First we'll use the Render mode to set up the lighting and rendering the way we want, then switch to Bake mode to bake the lighting into textures.

1. Open the Render Settings window (Window->Rendering Editors->Render Settings)
rendersettingsbutton.JPG (8.01 KiB) Viewed 2277 times

2. Change "Render Using" from "Maya Software" to "TURTLE"
3. In the "Common" tab, scroll down to "Render Options", and uncheck "Enable Default Light".
4. Go to the "TURTLE" tab
5. Set the "Render Type" to "Rendering"
6. In the "Global Illumination" tab, check "Enable Global Illumination" and set Primary GI to "Final Gather"
7. In the "Environment" tab, set "Environment" and "GI Environment" to "Sky Light", and set the Sky Color to a blue-gray color.
8. Click the Render button
renderbutton.JPG (7.89 KiB) Viewed 2277 times

Here's a render showing only the effect of the sky light and Global Illumination and one with the lights enabled:



Preparing the scene for baking

Once you're happy with the lighting in the render, you can bake it into textures to use as lightmaps. First, you have to create UV maps for the objects in the scene. In this scene since almost everything is simple primitives they had UV maps that are usable to start with. The only object that needed to be mapped was the bowl; for this I did a planar mapping with the top faces selected, and another with the bottom faces selected.


It's also good to give all objects clean and readable names. The lightmap textures will all get saved with filenames based on the names of the objects, and we'll use those in the Panda code to relink the texture files with the right objects. So having object names in maya that will translate into sane filenames is good. You can use the batch rename feature in Maya to help this. In this scene, I had a lot of objects called pCube1, pCube2, etc, and when they were grouped and duplicated they got very complicated names. To clean that up:
1. Select all the objects you want to rename
2. In the Status Bar, set the Text Input Field mode to "Rename".
3. Enter the base name you want for the objects. I used "hengepiece".
4. Hit enter. The objects will be renamed hengepiece1, hengepiece2, etc.

7.jpg (9.34 KiB) Viewed 2277 times

Turtle Bake Settings

1. Bake Layers
Window->Rendering Editors->TURTLE->Bake Layer Editor

Bake layers are sets of objects in the scene that share baking settings. For now we'll just use the default bake layer. Select TurtleDefaultBakeLayer in the "Bake layers" list. Select all the objects in the scene, and click "Add Selected" to add them to the Target Surfaces list.

"Source Surfaces" and "Envelope Surfaces" can be used in more complex bakes where you want to bake surface data from one object onto another - for example, to bake data from a hi-res mesh onto a low-res one.

2. Render Settings

In the TURTLE tab in Render Settings, change "Render Type" to "Baking".
In the Baking tab, set the Bake layer to TurtleDefaultBakeLayer.
Set "Bake To" to "Texture"
Under "Targets" make sure all the objects are listed as target surfaces.

3. Texture Bake Settings

Set Width and Height to 1024x1024

For the "Directory" setting, click the folder icon to open the file dialog, go into the "lightmaptest" folder where you're storing your project, create a new folder called "lightmaps", and select it

Set file format to PNG


4. Outputs Settings

Under "Shader Outputs", uncheck "Full Shading" and check "Illumination" so that it'll only include the lighting information.

Click the Render button. This time it should bake all the lightmaps and save them as files, instead of doing a normal render.

What the lightmaps should look like

Improving your lightmaps

There are many things you can adjust with the lighting and baking process.
1. adjust sizes of the lightmaps
2. use different bake layers for different quality settings
3. In the Bake Layer Editor, use the Scale and Texture Sizes button to adjust lightmap texture sizes based on the size of the object, so small surfaces can use smaller textures
4. Combine objects together so they can share one lightmap (don't forget to layout the UV's, though!)
5. Create a different UV set for the lightmaps - you'll often want to layout those UV's differently than the way you lay out your UV's for regular textures.
6. Adjust global illumination settings, filter settings, and the depth-map shadow settings in the light attributes to remove jaggies and noise
7. You can also bake with low-quality settings and touch up textures if needed using Photoshop or Gimp.
User avatar
Posts: 176
Joined: Mon Jan 17, 2011 4:48 pm

Return to Art and Animation

Who is online

Users browsing this forum: No registered users and 1 guest