Hollow Earth

Guide to Lightmapping

In getting back into Age making, I’ve been working on refining my Ages. Part of that is reworking my lighting. Up until now, I’ve been doing what I think most people do. That is: make an Age with only a few lights and let the engine do the lighting. I’ve learned a lot since then and I want to help people starting off with Ages or even people who are like me: experienced in Age writing but lost when it comes to lightmaps. This is going to be longer, but I will try to make things as simple as possible and add pictures. This is for Blender 2.49b and the PyPRP plugin. First, we need to go over the basics.

The Lights:

If you’re using Blender, the are five light types you can use. I’m not going to go into detail about them all, just the ones that you’ll usually use. I will link to an image showing all the settings for them and talk generally about them. Let’s begin.

Lamp: This is your staple light. A point omni-directional source of light. Like a firemarble. It shines light in all directions. For beginners, “Energy” sets how powerful the light is. You’ll learn more through experimenting but most of the time 1.0 energy is good for most things. More than 4.0 energy has few applications. It’s not terribly tricky and you likely will not be incrementing lights by tiny amounts. the R G and B settings control color. The Dist settings set the distance at which the light level gets halved. In the image, after 20 meters/feet, the light will go from 0.2 energy to 0.1 energy. There are three other useful settings. OnlyShadow makes the light only case shadows. This can be useful if you have a group of lights but only want one to cast shadows. Speaking of shadows RayShado makes the lamp cast shadows using ray tracing. For lightmaps, RayShadow means materials with the Traceable setting enabled will cast shadows. For Uru, it also means materials with the ShadBuf setting set will cast shadows in Uru. Finally, the Sphere button stops the light from affecting things outside the Dist value. Rather than Dist halving the light energy, it stops it and smooths the light as it gets closer to the Dist level.

Area: Area is one of those lights you probably won’t use. It acts like a Lamp but over an area. I’d recommend experimenting with this one a bit if you’re curious. I haven’t found a use for it.

Spot: See Spot illuminate. Illuminate, Spot, illuminate! Spot does just what it sounds, it makes a spotlight. This is incredibly useful and is another staple light. It is a unidirectional cone light source. SpotSi changes the “size” or, more accurately, the angle with which the light emanates from the spotlight. 45 makes it leave at a 45 degree angle. One thing to note is that a larger angle means the light won’t go as far in the direction the lamp is pointed at. SpotBl is the softness of the spotlight. I usually set mine to full softness

Sun: The Sun type is another common light source. It makes a constant unidirectional light source in the direction it’s pointing. Unlike the real sun, it only points in one direction. The light you use with this doesn’t have to be a sun, though. It can be lake light and you might even consider adding a couple weak suns to make cheap ambient lighting.

Hemi: Another one like Area that’s weird and I don’t know what you’d do with it. Experiment and see, it might be perfect!

The Cheat Sheets:

I’ll b referencing a lot of settings, so I took some shots of the relevant areas. When you start out, keep these open to easily find these settings.

Materials: Material:Shadeless, Links and Pipeline:ShadBuf, Traceable, Shaders:Amb, GR, Texture:Checkbox next to the texture, Map Input: UV, MapTo: Col, Amb, menu labeled “Mix”

Textures: UseAlpha, MipMap, Interpol

Edit: UVTexture: New

Object: Group (only visible after adding objects to a group)

Properties: Add Property, Menu labeled “Float”, Name, number after name.

 The Plugin:

Okay, so the next thing we need to understand is how Blender and Uru manage lights. Uru’s engine can only stand 8 lights per object. To make this problem worse, PyPRP defaults to export every light to every object. So if you just use the engine lighting and have more than 8 lights in the entire Age, one of them will go out and you’ll start crying. I recommend using lightmaps for big objects and vertex colors for smaller objects and to set everything except kickables and animated objects to Shadeless with Amb set all the way up. More on this later. Blender and Uru have irreconcilable differences when it comes to lights and, like in every good negotiation, the only way to resolve those is to fool the parties involved. (Note: I may or may not be a professional negotiator) It’s fair because we’ll be fooling both of them. First, let’s talk about fooling Uru.

Fooling Uru:

The core of the problem is that lights strong enough to look good in Blender’s light maps often look too strong in Uru. For example, a light with energy 1.0 is usually good for lighting the avvie in Uru while a light with energy 4.0 looks good in Blender but washes the avatar out in Uru. To fool Uru, we need to make a set of lights that we’ll use only for our lightmaps and then make Uru (via the PyPRP plugin) disregard them. We also need a set of lights to just effect kickables and animated objects, etc. To make lights invisible to the Uru lighting engine, add a string property named “page_num” and set it to “-1”. Because there can never be a page -1 in the files, PyPRP ignores it and Uru can’t see it. To make a set of lights for kickables, etc. you need to set up light groups. Simply select your lights and press Ctrl+G and select “Add to a new group”. You can rename the group by finding the group name in the objects panel and you apply the light group to a material in the object’s materials tab under Shaders by typing the lightgroup’s name in the box labeled “GR”.

Fooling Blender:

The problem with all these lights now set up just for Blender and not for Uru is that you still need lights to properly light the avatar in Uru. If you have a lantern on a desk, it’s going to look bad if it doesn’t illuminate you when you get close. So you need to make a series of lights that will not be used for lightmapping but will instead only be used to illuminate the avatar. To do that, you need a set of lights that will be on another layer. I recommend having a minimum of three layers in Blender with lights. The first layer of lights will have your lightgroup of lights that apply to your kickables, animated objects, etc. The second layer should be these avatar lights. They won’t affect your kickables, but they will affect your body. The third layer should be your lightmapping lights.

Tutorial 01:

This first lightmapping tutorial will just go over the motions. There is a longer tutorial under this one. This is just kind of the refresher list. It assumes that you have your lightmapping lights set up and their layer selected along with any objects you want to cast shadows, and that all materials have Traceable set when applicable, etc. Here we go!

  1. Select mesh
  2. Enter Edit Mode
  3. Select all vertices
  4. Go to edit panel
  5. Create New UVTex layer
  6. Select both boxes to the left of the new UVTex layer
  7. Rename layer to Lightmap (or name of your choice)
  8. Press U
  9. Select either “Lightmap UVPack or “Unwrap (smart projections)”
  10. Press OK on either resulting pop-up
  11. Open UV/Image Editor
  12. Press “Image” and select “New”
  13. Change to appropriate size (usually 256 and 256) and press OK
  14. Go to Material panel
  15. Make sure material is not used by other objects
  16. Turn Shadeless off and deselect any textures.
  17. Set Amb to 1.0 (full on)
  18. Go to Render tab
  19. Find Bake Panel and press Bake
  20. To to UV/Image Editor
  21. Press “Image” and select “Save”
  22. Give lightmap file a name.
  23. Press “Image” and select “Replace”
  24. Choose the file you just saved.
  25. Go to materials panel
  26. Turn Shadeless on and re-enable textures.
  27. Add new texture.
  28. In Map Input, select UV and type Lightmap (or the name of your lightmap UV texture) into the box.
  29. In Map To deselect Col, select Amb, and change from Mix to Multiply.
  30. Go to texture panel.
  31. deselect UseAlpha, MiMap, and Interpol
  32. select lightmap file from the pulldown menu
  33. Lightmap complete.

Now, to change a lightmap, follow these steps:

  1. Select object
  2. Go to materials panel and deselect Shadeless and disable all textures.
  3. Got to Render panel and click Bake
  4. Go to UV/Image Editor and click Image and then Save
  5. Go to Materials tab and re-select Shadeless and re-enable all textures.

Tutorial 02:

This is the longer tutorial with more explanation of the different steps. Personally, I find these hard to use, which is why I made the above tutorial. After using this tutorial for a bit, I would recommend you use the shorter tutorial just to go through a “mission checklist”. I only had to do it a couple of times before it essentially became muscle memory, but I know this isn’t typical. So, here’s a relatively complete tutorial of lightmapping, general lighting, etc. Enjoy!

So, to start off, we need a mesh and some lights. I’ll be using an old WIP Age called Veeshorahn.  At present, I have a basic sun-based lighting system with minimal lighting. The current system has a main primary sun pointing light in one direction with two weaker secondary suns directing light from other directions. One is beneath the Age and opposite the primary sun. That one simulates reflected light. Another one is directly above and points down. This simulates scattered ambient light. You can add more, that’s just the setup we’ll start with.

Here’s a shot of how to do basic vertex lighting . I have my lights on layer 2. You can move lights and objects to other layers by selecting them, pressing M on your keyboard, and clicking on the layer you want to move them to. You can select multiple layers by holding CTRL and clicking the layers. With both my object and my light layers selected, I go to my objects edit panel while looking at ti in Object mode. Then I click on the New button just above the Vertex Color section. This gives me at least a rough start. You can use this for small objects like small rocks  that you don’t want to lightmap. But it isn’t very accurate to how the object would be lit in the real world and it can’t render shadows.

So, get rid of that cruddy Vertex Painting layer and let’s begin actually lightmapping. It can seem like a daunting task, and I won’t lie, there’s a lot of steps and it was hard for me to get a handle on. I made a shorter checklist for more experienced blender users and people who just need a reminder of the steps without slogging through this giant tutorial!

The first step to lightmapping is to create a new blank UV Texture layer. I would do the lightmapping after you have all your texturing done just so you don’t have to worry about bouncing between your texture and your lightmap and messing one up. Once you have practice, this won’t be as devastating, but for starting off it feels like you could ruin your Age at any moment. Don’t let that paralyze you.

To make a new blank UV Texture layer, select your object that you’ll lightmap and hit Tab to enter Edit mode. Go to the edit panel and under mesh, click New to the right of “UV Texture”. Here’s what it will look like . Next, make sure both buttons on the new UV Texture layer are selected, and rename it to Lightmap or something you’ll remember later. This can be the same name as other lightmap UV Tex layers. Just remember it for later. Here’s what it looks like .

Next, you need to make a UV map for this new lightmap layer. Make sure all your object’s vertices are selected by pressing A until it all turns pink. Then, press U and select Lightmap UVPack. Here’s what that looks like. There are settings that pop up, but they’re not a big deal right now. You can experiment on those on your own. Just click OK. When it’s done, go to the UV/Image Editor. This is what it will look like.

Now we need an image to project our lightmap onto, much like a scapegoat to project our own inner failings. Click “Image” and then “New” and fill out the pop up window while contemplating your social life. In general, an image 256 by 256 will be big enough for most things. Cyan’s are sometimes as small as 64 by 64. The size dictates the level of detail you can render in your shadows and larger sized images are typically needed for larger spaces. This is what I set it to. Blender will make a nice big black image which we’ll use later. Black like your heart. You monster.

Before we can, we need to set up our material. This is what mine looked like before. This is an older Age, so it needs some conversion work. First off, the “6” next to the material tells me that 6 objects use this material. This won’t work for a lightmap. If you have this issue, just click the number to make a copy that just applies to that object. I then named it “rockmat_ltmp” because I’m unimaginative. Here is what you will want it to look like. Notice that “Shadeless” here is off and the textures and unchecked. In the preview window, it looks soft white. When Shadeless is on, it makes the material  ignore light and shadow. You will want this turned ON on everything other than kickables and animated objects when we’re done, but to make or change lightmaps, it needs to be off. Otherwise, Blender can’t apply use light or shadow on it. The textures are unchecked because if they were checked then Blender would read the texture as the lights, essentially, and your lightmap would look ugly.

While we’re still on the materials page, set Amb up to 1.0. This will mean that the resulting texture will be as bright as it can be with the lightmap attached. If this is too bright in Uru, just back it down a bit. You may also want to turn Spec and Hard down to their lowest settings as shown in the previous graphic. They can add an ugly shine sometimes. If you have a shiny material, though, you might want to use them.

I have good news, you’ve done most of the work and your object is ready to accept lightmaps into its life. Simply go to the Render panel and find the Bake tab. Then press the big button that says “bake”. This is what it will look like. You will probably want Full Render as the setting, bu the others might be useful if you want to experiment.

With our current setup, this is what it looks like. Next, go back to the UV/Image Editor and select Image and then Save as shown here. Next, you’ll want to give the file a name . Optionally, you can also love and care for the file while giving away 18 years of your life selflessly supporting it until it is strong enough to fend for itself and denounces you and only calls you on Christmas. It’s all up to you.

Next, select Image and then Replace as shown here . Use the same name you gave to your texture earlier.

Okay, so we can all agree that the bake is far too dark. This is because I’m using old settings for Uru live light rendering, which are usually too dark for lightmaps. Also, it was supposed to be a darker Age. Still, we need more like. So I added a spotlight . It’s a little small though, so let’s increase the Dist to 40, the Spot Si to 90, and the SpotBl to 1. This means the spotlight is larger, travels farther, and has nice blurry edges. It looks like this now.

Even more good news! We can quickly update the lightmap right now. As long as Shadeless is off and textures are unchecked, we can just hit the Bake button and it will make a lightmap of everything we have visible in the Blender window. Here’s what the lightmap looks like now. All I have to do afterwards is save the image again. If you’ve exported the Age before making the changes, you’ll want to go delete the Tex_Cache file for the lightmap texture so Blender makes a new one, but we haven’t exported yet, so instead let’s make that spotlight an ugly light green and add another lamp.

This new lamp is a Lamp lamp. It’s a single point of light. I made it purplish. The Lamp lamp is the most common lamp. It acts like a firemarble, sending light out in all directions. I placed that in my Age and baked again. After that, I increased the Energy of the light, which made it brighter. However, rebaking it showed an issue. The lightmap on the object now has strange borders. This happens, usually on more complex meshes, because the lightmap UVTex unwrapper isn’t perfect and doesn’t place mesh faces close to each other.

The way to fix this is to change the UV mapping style. The best one to use for this is one called “Unwrap (smart projections)”. Make sure you have the lightmap UV Texture selected and press U and select Unwrap on the bottom. Then, press OK on the popup that come up. After this finishes, your object will look strange. However, just bake the lightmap again and everything will be better.

This isn’t perfect, but it’s a very good start, and much better than we could get with Vertex painting. One way we can improve the lightmap is by restricting that Lamp lamp. On the lamp, click Sphere and set the Dist to the farthest you want the light to go. This is how I set it. When I rebaked the mesh, this is how it turned out. That was a little too small, so I made the Dist value go to 60. This is how that turned out. Much better!

After that, I wanted to fiddle with some more lights. Here’s what it looked like after I made the sun simulating reflective light brighter. Here is what it looked like when I made the sun simulating scatter light brighter.

Okay, that doesn’t look too great, but I think this covers the basics of manipulating the lightmap. There’s one thing we still have to do: actually apply the thing. You don’t have to wait till you’re happy with the lightmap to apply it, I just wanted to show a few things before getting to it. As long as you turn Shadeless off and disable the textures, you can bake the lightmap any time before or after this next step. Just save the image in the UV/Image Editor every time. Then, when you go to export to Uru, just remember to turn Shadeless and the textures back on.

The first thing you want to do to apply the lightmap to your material is to make a new texture layer in the materials tab and give it a name. From there, go to Map Input, click the button that says UV and then put in the name of your lightmap UV Tex layer (Lightmap, in my case) above it. Then, go to MapTo and disable the “Col” button and enable the “Amb” button. Then change the grey bar that says “Mix” to say “Multiply”. Here’s how I set it.

Finally, go to the Texture panel and, on your new texture layer, add the lightmap file as an image. De-select UseAlpha, MipMap, and Interpol and you’re all set. Here’s how I set things.

And that’s all there is to it. If you followed this tutorial, your Age looks like a dark, multi-colored pile of manure. So go fix that, you lazy bum!

Filed under: Resources, ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Share this blog

Bookmark and Share


Blog Archive

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 149 other followers


All posts are my opinion only and do not necessarily reflect the opinions of others.
%d bloggers like this: