Howto:Aircraft reflection shader

From FlightGear wiki
Jump to navigation Jump to search
This article is a stub. You can help the wiki by expanding it.
Reflection Shader applied to the B-29. It shows a shiny, high-reflective blank metal.

Within Flightgear GIT and later, a reflection shader effect is available. A lot of aircraft make already use of it, but much more will be expected soon.

Reflection-Shaders - history and description

model-combined.eff and model-combined-deferred.eff

You have now: reflections, normalmap and specularity map, dirt, lightmaps with 4 simulated lights per object in Default and Rembrandt. In ALS you will get in addition also a grain/ rain effect and the darkmap. This shader works only on UVmapped surfaces! This shader inherits from model-combined.eff, an effect which should never be directly used, since it holds only the definition of the common parts of the two effects. The model-combined-transparent.eff has the same features but has the necessary changes to correctly support transparent objects which represents transparent surfaces like glass.

Example Aircraft: EC 130 B4, EC 135 P2

What will be reflected on the surfaces?

All of these effects use Cubemaps and Cubecrosses from data/Aircraft/Generic/Effects which contains the image of the environment which will be visible as Reflection. Depending on which you choose, the appearance of the model will later change dramatically.

How to implement the simple ReflectionShader:

The simple and quick method

Inside the Aircraft/AircraftName/Models folder, there should be a main xml file, which usually is AircraftName.xml. This file should be the one holding all information on visuals used in the aircraft. As such, we need to indicate which are to be reflectable!

Inside the aircraft model configuration file (AircraftName.xml), we need to put the following lines of code, shortly after or before other <animation> tag entries:

 <nowiki><!-- REFLECTION --></nowiki>

Note that for each <object-name> tag, you need to indicate the aircraft's objects. If you are not the original aircraft author and do not know which parts to enter, or how they are named, use the other animations tags object names which indicate the pieces you require to be reflected (such as <object-name>fuselage</object-name> is an obvious one). Obviously do not enter things which you don't want to be reflected!

This method has a few parameters to influence how the reflection appears which can be set for every livery configuration:

  • sim/model/civilian - a boolean to enable or disable the reflection.
    • Civilian aircraft are usually glossy but military aircraft are not.
  • sim/model/livery/shininess - a floating point value to specify the reflection factor.
    • The range is between -1.0 and 0.0
  • sim/model/livery/fresnel - a floating point value to specify the Fresnel factor.
    • The range is between 0.0 and 1.0

These parameters can all be defined within a livery configuration file:

       <civilian type="bool">true</civilian>
         <name type="string">Factory Demonstrator</name>
        <shininess type="float">-0.5</shininess>
        <fresnel type="float">0.7</fresnel>

Adding a normal-map

It is also quite simple to to add a normal-map texture by expanding the section in the aircraft model configuration file:

      <texture n="2">

To see them in sim, ensure your View > Rendering options > Effects & shaders options are checked.

As an example the C160 Transall by helijah makes use of this simple method.

Customizing the reflection shader

To further customize the reflection shader take a look at the ALS technical notes