Lacuna Passage - Devlog #52.5 - Lightmapping with Emission in Unity 5

Light mapping is a technique where you can bake the light from a scene into objects so that they self-illuminate based on a generated lightmap texture that usually is mapped to a second UV channel. This is a great solution to reduce the number of light calculations needed on static objects. But what if you have an object in the scene that needs to appear as if it is projecting light and casting shadows on other objects - and you also want to control the color and intensity of the light ingame? Well that’s where emissive lighting comes in handy.

Emissive lighting is typically used to self-illuminate objects in a scene and make them appear as the light source. A texture specifies the areas of the object that you want to emit light and global Illumination bounces this light onto other objects in the scene. Below is an example of a typical emissive object with global illumination affecting the scene around it.

But when you want precise shadows and lighting that matches the emission produced you need to get a little more complex. Baking the light casted from the emission source in your modeling software can achieve this effect with only a little extra effort. So, in effect, we want to produce our own lightmapping outside of Unity and apply it to the emissive channel in our Unity material.

First things first, we need to get a demo scene started in our modeling software. I’m going to be using 3ds Max along with the Mental Ray renderer. Below is the basic scene in 3ds max (top) and our desired look using a spotlight in Unity (bottom).

The hemisphere in the corner is the lamp of our scene and its bulb will illuminate our objects. To emulate this lighting in 3ds Max we need to place a light source in the center of the bulb. I used a Photometric Free Light and set the shadows to “Ray Traced” and the emit shape to “Sphere.”

Because I am using Photometric lights, I made sure my scene units match that of real-world objects. In this case I used 4 cm for the lamp bulb and made the radius of the emit shape also 4 cm.

After tweaking some of the light and shadow settings, I made a new Arch & Design material to place on our objects. In the diffuse color map slot I placed my diffuse map.  In the glossiness map slot under the reflection rollout I placed my gloss map. I made sure the diffuse and reflection colors are set to pure white, and the reflectivity is set to 1.0. I also checked the “Highlights+FG only” option because bounced light will be taken care of by global illumination in Unity.

Finally, I added a Normal Bump under the Special Maps rollout with the normal map of our projected high poly (Make sure you flip the green channel). After a couple quick render tests I decided to increase the gloss output to 2.0 to make the highlights tighter.

Now that we have our light and materials setup, we just need to render the light to a texture map. To do this, we open the Render to Texture dialog (Rendering > Render to Texture…). With our all our objects attached into one mesh we can easily render the entire texture at once. With our single object selected we can set our render to texture properties accordingly.

Scroll down to the Output rollout and add a “CompleteMap.” Complete maps incorporate all light information including normal, gloss, and diffuse maps into our bake. Set the texture size and save location accordingly and make sure “Shadows” is checked. Then hit “Render.”

Once the render is complete, decide if you need to increase the quality of the shadows before going to Photoshop to tweak any errors. You can do that by going to Rendering > Render Setup and opening the “Renderer” tab. Here you can tweak things like light sampling and noise thresholds. You could also go back to your light source and tweak its settings.

The end result is a custom emission map that reflects the lighting in your 3ds Max scene:

Then you just bring all your assets and textures into Unity and plug them into the Standard shader (I used the specular version). Here’s a quick video of how the emission lighting method compares to a spotlight within Unity:

In the example at the end of the video you can see some of the benefits of this method. Instead of lightmapping the entire hallway we can simulate lightmapping on a single asset that looks reasonably good even when duplicated in several places around the scene. This works particularly well when the light source is attached to the object that you want to have simulated direct lighting. The lighting never needs to be rebuilt and the resolution of the emission map can be scaled smaller than your other texture maps if needed. The emissive properties can also be easily changed at runtime to create effects like flickering or colored lights. The emission coming from our transmissive plastic also contributes to the scene's lighting via Unity's precomputed realtime Global Illumination.

Lacuna Passage - Devlog #6 - Using highly detailed 3D components in your first-person HUD

This week’s devlog is a bit more of a tutorial where we cover our method for creating dynamic, highly detailed 3D HUD elements. The basis for our pipeline involves rendering complex high-poly models onto flat, single polygon planes with a normal map for light interactions.


Pros of this method

  • You effectively have an unlimited polycount for your HUD. By rendering your high poly model to a flat plane you will have no noticeable polygonal curves or sharp edges (if you don’t want them, that is)
  • Extremely low poly count in relation to the quality of the illusion

Cons of this method

  • A change in HUD design requires re-rendering of all your texture bakes
  • The HUD cannot move in relation to the camera or the illusion breaks

So, let’s get started:

1. Setting up your camera angle

In order to model your HUD components you need to setup a camera in your modeling software that is exactly the same field of view as your first-person camera in your game engine. This will help you preview what your HUD will look like in game. It’s also going to be very important later when we need to render out a normal map.

2. Build your model according to the view you want in game

This part just comes down to whatever style you are looking to have with your particular game. In our case we are creating a small visible portion on the inside of a space helmet.


3. Create a plane to project your model onto

Once your model is finished (no need to texture it yet) you need to create a plane that completely encompasses your model from the point of view of your first-person camera.


4. Orient the plane to your camera angle

Make sure that the plane is exactly perpendicular to the origin point of the camera. Check the image to see a visual.

5. Quickly unwrap your plane

No frills here. Just unwrap the plane however you like.


6. Render your normal map

Use Render to Texture with a projection modifier on your plane that encompasses your model to create a normal map of the original model. If you’ve never done a normal map bake from a high poly model before check out this guide.


7. Create your textures

You can create your textures in Photoshop or texture your original model and do another render to texture for the diffuse instead of the normal map.

8. Create an alpha mask for the model’s texture

Since our projection shape does not perfectly match our plane we need to have an alpha channel somewhere that determines areas of transparency.


9. Import your plane and your textures

Bring everything into your game engine and align the plane exactly as you had it in your camera preview in your modeling software. In our case we are using Unity so here are some tips to help you out.

Unity specific directions:

  • Have your plane parented to a HUD camera that is distinct from your scene camera
  • Have the HUD camera render last and mask only the HUD elements
  • Make sure the clear flags are set to Depth Only to preserve your depth buffer
  • Use the same HDR settings on all cameras if you are using image effects
So, there you have it. If you have any questions feel free to leave them in the comments.

Lacuna Passage - Devlog #2 - Building Mars Part 2

Continued from Devlog #1 – Building Mars

Since the terrain in Lacuna Passage is essentially its own character in the game I decided to drop the composite Photoshop method and look into generating higher fidelity terrain directly from the Mars HiRISE digital terrain IMG files.


As it turns out, there is an add-on for Blender that allows you to import the large IMG files to generate a mesh. Huzzah! Exactly what we need.  There are others who have already documented precisely how to utilize this add-on so rather than reiterate their instructions I will simply link to a tutorial video that explains the process very well.

While Blender is great (and free) I preferred to export the final mesh to 3ds max to create our heightmaps. Once in 3ds max you will likely need to flip your normals so that we can unwrap the mesh correctly and generate a heightmap.


As we already know, a heightmap consists of a black to white gradient to convey height, so we need to devise a material for this mesh that will render that gradient. The easiest way to do this is to apply an unwrap modifier to your mesh and planar map the entire thing from either side (doesn’t matter which side, just NOT a top down plane). Then we can apply a black to white gradient material with 100% self-illumination. These steps are probably easier to follow in video tutorial format, so once again I will link you to someone who has already explained the process quite well.


Once you have your gradient material applied to your mesh you can effectively render out whatever sized heightmap you want. Obviously you will have diminishing returns at a certain point where the resolution of the mesh itself limits the resolution of the heightmaps you can render, but these are still much higher quality than the jpeg images provided via HiRISE.


Now you might be asking, “But how do I ‘customize’ my terrain? It seems like I’m limited to only the geometric features provided in a single HiRISE IMG file.” This is true; however, this is where we can implement a new method for compositing. If you have access to Mudbox you can create sculpting stamps from individual components of your rendered heightmaps. For a third and final time in this devlog I will defer to other skilled artists and link you to an example of how this could be used to create some of the most realistic custom terrains you will find anywhere.


During the development of Lacuna Passage we will be using a combination of nearly all the methods described in this post and the post from last week. The game will have an expansive open-world terrain and the goal is to make every inch of it worthy of exploration. Make sure to follow us on twitter and facebook for more updates.