PRELIGHTING FOR REAL TIME RENDERING

Note: this example illustrates the process of creating lightmaps on the primary texture maps of the models. It is also possible to apply lightmaps to an object with a separate set of UV coordinates and blend the lightmaps with the primary texture. The process shown here would still be used, although additional steps of creating new UV maps would be necessary, and is discussed in a separate tutorial.

Here is how the scene looks in maya with the default light (no lighting has been added to the scene.) The shading on the objects are fairly typical of how things look in a real time rendering - after all, what we are looking at in the maya perspective view is a real time rendering in openGL.

 

Here is what the scene looks like using maya's software renderer when some shadow-casting lights are added. The following steps will show how the scene can be texture-mapped to look like this in a real time renderer. If you want to see an example, follow this link to view the scene running in the virtools web player.

 

Here is the maya scene file if you want to experiment with it.
cube_room.mb (102kb)

This scene has twelve lights.
There is a main spot light outside the window. It casts a depth map shadow with a dmap resolution of 1024 and dmap filter size of 4.
The remaining eleven lights are point lights with intensity set very low. The dmap resolution on these are set quite low to 64 with a dmap filter setting of 3 which makes nice soft shadows on the walls. The idea here is the light coming from the point lights are scattered light bouncing off the floor from the sunlight, which is casting sharp shadows of the window frames and cubes in its path. If there were not point lights the room would be black except where the spot light hits the floor.

Note that we are using dmap shadows. The convert to solid texture feature we are going to use in maya does not support ray traced shadows.

There are "bake texture" features for the Mental Ray renderer also, but for now we will stick with the maya renderer.

Before the texture is baked on the room's walls, we have to make sure the texture coordinates are appropriate.

This room model was created with a polygon primitive cube. One face was selected and subdivided. The subdivisions were then manipulated to form the window frame and faces were deleted to form the openings. The edges of the openings were then extruded to give the window frame thickness.

Open "windows > UV Texture Editor" to see how the polygon cubes faces are "unwrapped" onto UV space. Press the "a" key to view the whole object. The UVs are arranged so that a texture which fits in the 0-1 texture space (the highlighted upper right section of the grid) will be repeated on each of the other faces.
This means that the same image area will appear on each of the faces. This is not what we want because if we cast a shadow on one face it will show up on all the faces!

The easiest way to quickly redistribute the UVs of the room is to use "Edit Polygons > Texture > Automatic Mapping". The default setting will project from six sides (good for our cube shaped room) and distribute all the faces into the 0-1 texture space.

This image of the UV Texture Editor shows the result. All the faces are now contained within the 0-1 texture space. If a file texture were connected to the color on this shader it would show up filling the light gray area of the grid and be spread across the object's faces accordingly. Note now how the side with the window is arranged based on actual sizes of the faces, and the extruded edges of the window have been arranged in the upper right area of the grid. The default settings of the Automatic Mapping does a pretty good job of spreading everything out.

Note we can assign the UV mapping without actually having a texture assigned. In this case the shader on the room is just a simple white color.

Now for the baking of the lighting into a texture map. Select BOTH the object in the scene AND the shader which is assigned to it in the hypergraph.

In the hypergraph menu, select "Edit > Convert to File Texture > [ ]". Be sure to open the options box.

In the options, turn on "Bake Shading Group Lighting", which then allows you to turn on "Bake Shadows".

Set the X and Y resolution to an appropriate size for the object in the scene. In this case 512x512 was used for the room. For the cubes, a size of 128x128 was used. Either get this the optimal size now or scale them down in photoshop later, but be sure not to overdo the sizes because in real time rendering textures use up precious video ram.

If the plan is to export the final results to virtools, don't use maya .iff as the file format. Instead use .bmp, .tif, .tga., .jpg, or .png.

Select "convert".

The result will appear in the hypershade. A new surfaceShader node is created and the texture with the baked shadows is connected to it. This surfaceShader is automatically assigned to the selected object in the scene, replacing the original shader. Note the original shader is still left in the scene in case it is assigned to other things.

The reason a surfaceShader is assigned is for the software renderer in maya: if you render now the lights in the scene will not affect the baked object.

 

Before exporting for the real time renderer, create a new material and connect the newly created texture to the color input. Assign this new material to the object instead of the surfaceShader.

This can be done quickly by using the right mouse menu over the surfaceShader, select "select objects with material" and then right mouse over the new material and select "assign material to selected objects".

Before exporting to virtools, you might also set the incandescence all the way up on the material. This will have the result of setting the "emissive" value up in virtools so that the object is "self lit".

For the cubes in the scene, the first cube was created and the same Texture Automapping projection was done in order to unwrap the UV space. Then every new cube was duplicated from that.

The material on the cube has a procedural fractal on the color. This will get baked into the new texture along with the shadows. Any applied texture will get baked into the new texture.

Multiple objects can be selected at once - but only one shader node can be selected. Since all the cubes use the same original shader you can do this. A new surfaceShader with baked texture will be created for every cube.

Here is the final prelit scene in maya's perspective window. In the window's "shading" menu select "no lights". There are no lights in the scene now and we can move about the room in real time.

To view the scene running in the virtools web player click here. (256kb)

Of course this process of prelighting with baked shadows only works with static objects - since the shadows won't update if the object or light source moves.
However it can make very effective environments for other objects to be moving around i in.

Virtools has the ability to calculate shadow effects in real time, but this is cpu intensive. You could have a character casting a shadow while everything else is prelit.

Prelighting has its benefits for software rendering, too. By baking time-consuming shadows into the shaders, the render time for each frame can be drastically reduced.