Howto:Lightmap

From FlightGear wiki
Revision as of 16:41, 4 October 2014 by IAHM-COL (talk | contribs) (→‎The xml)
Jump to navigation Jump to search
Boeing 744 cockpit with several lightmapped panels.
Boeing 744 exterior with lightmapped fuselage and tail.

A lightmap is a texture that contains the brightness of surfaces in a computer graphic. The darker a pixel on the lightmap, the less emissive the correpsonding pixel will be on the color/photo texture.

Some reasons why lightmaps are useful:

  • they allow us to light surfaces without the need for creating alpha layers (like formerly used on many aircraft).
  • we can edit the colors of a texture, without interfering with the lighting. Useful if you want to add some dirt to your panels, later on.
  • lights look realistic at all times of day. Unlike a textranslate animation, where you change between day/night textures (often being too dark during dawn/dusk).

Lightmaps in FlightGear

FlightGear 2.6.0 and onwards

See FlightGear Newsletter December 2011#Shaders.

/Effects/lightmap in the .xml must be replaced by /Effects/model-combined-deferred (or /Effects/Building for buildings), see $FGDATA/Docs/model-combined.eff/ for some explanations

FlightGear 2.4.0

Note: material shaders must be enabled in the View > Rendering options dialog for lightmaps to work.

The lightmap

You'll have to create a lightmap for every single texture that is meant to be lightmapped. This can be done by hand, or via some 3D Software, like Blender (which will be used in the example on this page).

  1. Open/import your model in Blender.
  2. Go to Add > Lamp, and select on of the lamp types. The light will be created in the model's origin.
    • Lamp: spreads light in all directions. Can be used for anti-collision lights, navigation lights etc.
    • Area: long/large lamp areas, like instrument panel lighting where fluorescent lamps are used.
    • Spotlight: for lights in a specific area/direction. Used for landing lights.
  3. Move/rotate the lamp to the prefered location/orientation. Note: leave the scale tools untouched, scaling the lamp does NOT affect the lightmap.
  4. Select the lamp (right mouse click) and open the Shading menu (F5). This is where we can edit the lamp. Some of the more important settings:
    • Dist: the distance (in meter) at which the light intensity is half as intense as at the source.
    • Energy: intensity of the light.
    • R/G/B: the color of the light. Yes, lightmaps support colors!
    • SpotSi: width of the spotlight beam in degrees.
    • SpotBl: softness of the spotlight edge. Softer edges create a more natural look for most aircraft lights.
  5. Select the object you'd like to create the lightmap for. Go into editing mode and then back to object mode (to load the object's texture).
  6. Go to the Scene menu (F10) and open the Bake tab. Select Full render and click the big Bake button. Blender will now start generating your lightmap.
  7. Change your mainwindow (or add an extra window) to UV/Image editor. You will see the lightmap being created bit by bit.
  8. When the lightmap is finished, click Image > Save as... and save the image in your aircraft's directory.

That's it! Now, you probably want to see how it looks on your aircraft, which is explaind in the next paragraph. If you are not yet satisfied with the result, you can edit your lamp's settings (step 4) and add more lamps to see what effect that has on the result.

The xml

In your model's .xml file, add the following block of code:

<effect>
	<inherits-from>/Effects/lightmap</inherits-from>
	<parameters>
		<texture n="1">
			<image>Aircraft/747-400/Models/Effects/lightmap.png</image>
		</texture>
		<condition><use>/controls/lighting/logo-lights</use></condition>
		<factor><use>/controls/lighting/panel-norm</use></factor>
	</parameters>
 	<object-name>fuselage</object-name> 
</effect>

In which:

  • image: the lightmap itself
  • condition: when this property is greater than or equal to 1, the lightmap will be enabled.
  • factor: can be used to control the intensity of the light, on a 0-1 scale.

Remember that such a block is required for each single texture that you want to lightmap. You can have multiple objects per effect, but not multiple effects per object.

Known problems

  • FlightGear does not support multiple shaders per object. Therefore, you'll have to choose between the reflection or normalmap shaders and the lightmap.
  • There is no flexible way to (de)select lightmaps on a per-object base. Currently it only listens to one per-object defineable property.