Lightmap Workflow, Part 2: Architectural Lighting
Previous article: Lightmap Workflow, Part 1: UV Generation
RedFrame is meant to be a highly atmospheric and immersive experience. To create this atmosphere, it was important for us to focus on lighting. Many games have compelling lighting, however they tend to be outdoor environments lit by a single directional source representing the sun. In comparison, we are creating a nighttime environment illuminated by lamps, sconces, and recessed lighting.
I struggled for many months to achieve a look that I really liked. Hopefully what I have learned can be helpful to anyone trying to create something similar. It is important to note that we are using a lot of precomputed lighting with Mental Ray, which is not a viable option for games that have highly dynamic environments (which, unfortunately, is most kinds of games).
This is a workflow for Maya and Mental Ray, but the concepts are universal. There are five concepts that I will cover:
- Correct falloff / Gamma Correction
- Physically accurate soft shadows
- Distribution / Photometry
- Color temperature
- Indirect light
Once you understand these concepts, you will have a non-software specific checklist to use in creating your interior setup.
Correct Falloff / Gamma Correction
For many years working in 3d, I was told that real-world light had a quadratic falloff. This is known as the inverse-square law. Any energy that radiates out from a source in 3d space has an intensity equal to 1/(the distance traveled)^2. However, many lighting tutorials that I had read glossed over this fact, and instead suggested using a linear falloff which looked better. I always thought that this was weird since the quadratic falloff was physically correct. Naturally I tried using quadratic falloff which, to my dismay, resulted in too much contrast compared to the linear method.
As you can see, quadratic light falls off much too quickly, and the light has extreme contrast. The linear option looked better, but it always seemed unnatural to me.
It also bugged me because I knew that light obeyed the inverse-square law in nature, but this was for some reason incorrect. I have learned that it is generally not a good idea to ignore things that bother you. If you are doing everything correctly you generally won’t have the uneasy feeling that I experienced when setting my lights to linear.
It turns out that the reason I was having this problem was that 3d software renders images mathematically correctly, but since it is displayed on a computer monitor, it is being viewed in Gamma Space. If you are unfamiliar with the concept of Linear Space vs. Gamma Space (as I was), I suggest watching this video. Because of the way in which a monitor displays images, an image needs to be adjusted before being output to the screen. This adjustment is often done automatically in many cases, like when a gamma correction value is embedded into a digital photograph. However, out-of-the box 3d rendering does not produce this correction for you by default.
To set the rendered image's gamma correction in Mental Ray, you must provide the inverse of the most common output gamma value of 2.2. This is calculated as 1/2.2 which is about .455. In your Mental Ray render settings, input .455 into the Gamma parameter under the Frame Buffer section.
As you can see, I am now able to use quadratic light falloff with less intensity and the light dissipates in a manner that is much more natural looking. Keep in mind that we are gamma correcting a final rendered image in Maya, but Unity is optionally able to render in linear space. In the future when we bake light maps, we will be able to render them in linear space and have Unity perform the gamma correction at runtime.
Physically Accurate Soft Shadows
Now that we have a correct light falloff, lets look at shadows. In the previous example the shadows were hard, meaning that any point on a surface is either completely inside or completely outside of a shadow. In the real world, light sources usually have a size, or diameter, which makes their shadows soft. If a light source has a diameter, the rays emanating from it will originate from different locations across its diameter. This will cause some of the rays to be occluded by the object casting the shadow, while others will not.
As you can see in the above image, the rays originating from the outermost area of the light source are able to wrap around the object casting the shadow. As you move towards the center of the source, the rays become more and more occluded by the object. This effect will not be as extreme with something the size of a light bulb, but it is still present. Giving any light source a diameter greater than zero will make the shadows look more realistic.
To set a light diameter in Maya, change the type of light to Area Light. Also, ensure that the decay rate is still set to quadratic as discussed in the section above. You will also need to check off a few Mental Ray settings: Open the Mental Ray Tab for your light object, then under the Area Light section, enable "Use Light Shape." I selected a sphere as my shape since that is a good approximation of a light bulb. You can also increase the number of samples for better quality shadows.
As you can see in the above image, the shadows now have a more realistic and familiar look to them.
Distribution & Photometry
So far, these examples have all used point lights which means that the light radiates outward equally in all directions. If we want to create effects that mimic the appearance of recessed lighting, we will need a more sophisticated distribution. Below you can see an example of recessed lighting that looks much more interesting than a standard point light.
This effect is known as photometric lighting. You can recreate this type of uneven light distribution using something called an IES file. These files are available all over the web and are commonly made available by different light manufacturers. IES files are frequently used by architects in pre-visualization renderings, so they are designed to accurately reproduce the appearance of commercially available bulbs and fixtures.
With a little bit of digging, you can locate some of these files to use as a profile for your light. I'm not sure about the legality of distributing them on this site, but a quick Google search should be productive. To hook up the IES file, open the "Custom Shaders" tab under the Mental Ray section of your light and click the checkerboard icon next to the "Light Shader." From there, click the Mental Ray Lights section and select the “mia_photometric_light” node. Under the node’s settings, set the intensity mode and distribution mode to 2. This will tell the light node to use the IES profile. Click the checkerboard icon next to the profile section, which will create a new IES profile node.
Once the profile is selected, render out an image. As you can see, the distribution looks like a recessed light that you would see in a house. There are many different IES profiles available online that can create a plethora of effects.
Note: Light Color section has been edited to use a blackbody node which doesn't need gamma-counter correction.
The behavior of the light is starting to look pretty good, however the color is wrong. Lights in a house tend to have more of an orange color. A quick way to emulate this is to plug in a Mental Ray Color temperature node called a mib_blackbody. Plug this node into the color of your light.
This node will let you select a temperature, which will generate a light color. I like values around 3,800 for indoor lighting. You can see a nice chart of color temperature here. Once set, you can render the image and see if the lighting looks more like an artificial light source. If it is too orange, try increasing the temperature.
If you are unfamiliar with indirect light, it is worth doing a little research before proceeding with this workflow. However, the basic idea is that when light hits a surface, it bounces off and reflects onto other surfaces, some of which are in shadow. This means that the areas in our rendering that are completely black and in shadow should potentially still be receiving some light from other nearby surfaces that have received direct illumination.
I use an incredibly simple setup for this. In your Mental Ray render settings, under “Indirect Lighting,” you can turn on "Final Gather." This is a method of simulating light bounce that works pretty well. Set the Accuracy to something like 500 and set the Point Interpolation up to 50. These are quick and dirty settings but should be sufficient for you to get the idea. Once it is set up, we can render to see the indirect lighting.
Getting our lighting workflow ironed out was a difficult process, but in retrospect the steps are pretty straightforward. Keep in mind that recreating this exact workflow is not nearly as important as internalizing the concepts that I have covered. Many developers will be using different 3d software and, even more commonly, baking light directly inside of their game engine. These differences in tools will likely require significant changes to the workflow. Also, using an article like this as a direct template will result in a homogenous look. It is much better to understand why we’ve used these techniques in RedFrame so that you have more knowledge to draw upon when you approach the visual design of your project.