Precomputed Lighting

From VRwiki
Jump to: navigation, search

Precomputed lighting in 3D Studio Max and exporting to XVR

The AAM File Format

A screenshot of the 3DSMax AAM exporter plugin

AAM (once the acronym of Ascii Animated Mesh, now waiting for a better meaning) is the XVR native format for the description of triangular meshes. Its features are:

  • optimized for loading times in XVR
  • 1:1 correspondent to XVR data structures
  • available in ASCII (to easily allow inspection and manual modifications) or binary (for faster loading)
  • support to multitexturing, animation, smoothing groups, user properties, shaders, skinning
  • exporter plugins for 3DSMax, GMax, Maya, Blender

Creating precomputed lighing

Scenes created with modelers like 3DSMax may be provided with a highly realistic precomputed lighting, as off-line rendering can make use of lighting models much more sophisticated of those suitable for real-time.

a scene without lighting
a scene with lighting

It is anyway possible to export AAM models preserving these rendering information, by “rendering on textures”. Basically some textures are created which may be:

  • Complete maps (material + diffuse map + lighting map, combined in one single texture layer)
  • Lighting maps (which result in two texture layers, the “traditional” diffuse map + lighting map)

Rendering on texture in 3DSMax

  • Select the objects to be rendered (often the whole scene) and select the “Render to Texture” item from the Rendering menu.
Rendering menu

  • A panel appears where a number of parameters can be set. The list of selected objects appear in the frame “Objects to bake”.
Render to texture window

  • In the “Output” frame, select “Add…” and choose the type of the texture map you want to generate (a complete map on the diffuse channel, or a lighting map on a secondary channel).
Selecting elements
Selecting elements

The “Output” panel will change as follows (in this example we have supposedly chosen to generate lighting maps):

The output panel

  • Check that these boxes are ticked:
    • Enable
    • Target map slot: Self Illumination
    • Use Automatic Map Size (this option may create maps potentially large but “coherently” sized. If necessary, the generated maps may be resized with an external tool (XVR provides a convenient texture converter/resizer). It is possible to specify a maximum size. Alternatively,you can directly specify the size of your textures ignoring any correspondance with the size of the objects they map.
    • Shadows, Direct Light On e Indirect Light On
    • Unfortunately the Filename and type box can be selected only if objects are rendered one by one. Otherwise maps are generated in the default directory (usually <..>/3dsmax/Images) and in the last used format (the default being TIFF). A texture converter may afterwards be used.
  • Press the Render button.
The produced lighting maps (1)
The produced lighting maps (2)

For each selected object material, 3DSMax creates a “Baked material”, where the map slots contain the original Diffuse maps in the Diffuse channel and the just created lighting maps on the specified channel (in our case 5: self-illumination). Attention: 3DSMax5 places the lighting map on the Diffuse channel (channel 2) of the baked material. This will lead to different export options.

  • Now we’re ready to export in AAM:

select the menu item “File” -> “Export” e choose “AAM” as file format (if the AAM extension doesn’t appear, it’s likely that the exporter plugin “aamout.dle”, shipped together with XVR, has not been copied in the “Plugin” folder of 3DSMax)

The AAM exporter

  • In order to correctly export the AAM file supporting lighting maps, the parameters of the “Material settings” panel must be set as illustrated:
Export parameters
    • If using Max6 or later, the “Export Secondary Texture” listbox must contain the channel previously chosen as Target Map Slot while rendering on texture (by default it is "5: Self-illumination"). The Texture Rendering must be set to option "3: IN secondary map".
    • If using Max5 the Texture Rendering listbox must set to 2: Lighting Maps (exporter will try to automatically find the right channel).
    • In case of Complete Maps select Option 1.
  • Press OK to export the AAM file.
  • IMPORTANT: XVR natively supports only some image formats (JPG, PNG, DDS, and a few others). If 3DSMax produced images in other formats, they have to be converted. Images without transparency may be converted into JPG, while those with transparency into 32 bit PNG. Both can be converted into DDS.

If Max produced (or if the original materials already presented) files of extension XXX different from JPG/PNG/DDS, the AAM will contain, in the material section, texture filenames with extension XXX. In this case you have to manually edit the AAM file (e.g. with Notepad) and replace the extensions with the right one. The AAM exporter allows to automatize this job, if the desired extension is PNG or JPG, by selecting the option: “Export JPG and PNG extension”. NB: this option simply writes AAM files with known extensions (recognized by XVR) but the exporter DOES NOT actually perform any image conversion! The conversion must be performed with an external tool (XVR Texture Converter or any other image editing software).