X-Plane 12 features rain simulation on designated surfaces. This article explains how to enable and tune rain effects, as well as what to look out for to get the best experience.

Enabling Rain

Enabling the base rain effect is extremely easy by going into Plane Maker’s objects panel and setting the lighting mode of the rain surface OBJ to “Outside Rain Glass”. With this enabled, X-Plane will start simulating raindrops on the OBJ and automatically tap into the flight model data to properly calculate forces acting on them. Additionally, X-Plane will also start simulating ice build up on the surface when encountering icing conditions.

General considerations

One “gotcha” with the rain system is the way that raindrops interact with multiple surfaces. If you have enabled “Outside Rain Glass” mode for multiple OBJs, they will each run their own simulation and don’t share results with each other. This means that each additional OBJ will consume additional resources and processing time. Our advice is to try to keep the number of “Outside Rain Glass” OBJs to a minimum, ideally 1. You can achieve this by putting all of your rain receiving surfaces into a single OBJ file.

When multiple surfaces are grouped together into a single OBJ, it’s important that each vertex has a unique UV mapping and that contiguous surfaces are also mapped contiguously in UV space. This is because the rain system actually runs the simulation in 2D UV space to reduce resource usage, so the lens through which it “sees” the world is the UV space of your OBJ.

Here is an example of the default Cessna windows in 3D and UV space. The rain system operates in the flat UV space on the right in order to reduce the computational complexity.

One side effect of this setup is that rain can cross surfaces in unexpected ways. Two objects that are far apart in 3D space might be close to each other in UV space. In this case, a raindrop can potentially migrate from one surface to the other. Similarly, surfaces might be at different orientations to each other, so when a droplet enters the next surface it suddenly is subject to entirely different forces. In those cases, rain drops can move in strange and unexpected ways. An example of this behaviour can be seen here:

If you look at the upper left part of the windshield, you can see streaks that seem to have moved weirdly. In this case the rain drops have entered from the left edge after hopping from a different surface. They carried their momentum with them which moved them further to the right across the windshield. At the same time, they are suddenly exposed to forces that try to push them upwards. As a result, they now arc weirdly.

The way to work around this is to use separate TRIS  commands in your OBJ for each distinct surface. X-Plane tracks draw calls and makes sure to extinguish droplets that hop distinct surfaces that it can track. One “gotcha” here is that X-Plane will also try to merge multiple TRIS  commands into one big command. It only does so if subsequent commands are also drawing subsequent patches of triangles, so a way to work around this is to have them backwards. For example, your original OBJ might look like this:

TRIS 0 1224

TRIS 1224 558

TRIS 1782 558

Because this describes a contiguous range of 2340 triangles, X-Plane will try to helpfully merge them together into one. You can prevent this from happening by reversing the lines like this:

TRIS 1782 558

TRIS 1224 558

TRIS 0 1224

Scaling rain

One general OBJ command that might come in handy is the RAIN_scale  command. If not specified, the default of 1.0 is assumed, but you can put any other parameter in there. If you find that the rain drops are too big or too small for your aircraft, you can use this to tune their size. During development, you can set this to 1 and then use the sim/private/controls/rain/scale  art control to dial this parameter in, in real time. Once you have arrived at a value, you can then bake it into your OBJ.

Combining inside and outside glass

If you have both an outside glass surface with rain, as well as an inside glass surface, you might find that you get draw order problems. In these cases, the inside glass will remove the outside rain effect. The way to make this set up work is to select the “Inside Reflector” lighting mode for the inside glass.

Wipers

A lot of aircraft come with wipers, which can be added to a rain system via the WIPER_texture and WIPER_param  OBJ commands. X-Plane supports up to 4 wipers per OBJ and one wiper texture. The wiper texture, specified with the WIPER_texture  command, describes the path for each wiper using the 4 channels red, green, blue and alpha. The intensity of the channel is  the percentage along the path of the wiper, going from 1 to 255 (0 is reserved to signal no wiper interaction), the wiper moves from 0% to 100% of its path.

The resulting gradient should be increasing at a uniform rate, and an example of this can be seen on the left.

The red channel describes the first wiper, whereas the green channel describes the second one. Note that you can have multiple wipers using the same channel, but you can’t individually drive them.

For each wiper in the wiper texture, you’ll need one WIPER_param  command in your OBJ. The general syntax for that command is:

WIPER_param

The dref  is the name of the dataref you want to use to drive the wiper. Start  and end  provide the values the dataref will have when the wiper is at its first and last position respectively. The nominal_width  parameter is a bit more complicated: It describes the width of the wiper as a fraction of the gradient in the wiper texture. To accurately calculate this parameter, you’ll need to know the pixel density per meter of your texture, as well as the space covered by the wiper gradient and the physical size of the wiper.

Putting it all together, you might end up with something like this to describe 2 wipers:

WIPER_texture    A330_glass_wiper_gradient.png

WIPER_param    sim/flightmodel2/misc/wiper_angle_deg[0]        0.0   70.0        0.02

WIPER_param    sim/flightmodel2/misc/wiper_angle_deg[1]        0.0   70.0        0.02

In this case the datarefs used describe the angle of the wiper, so the start and end are also in degrees. The nominal width is 2% of the gradient.

One method to generate the wiper texture as well as the parameters is to use the XPlane2Blender plugin. The plugin allows you to generate a wiper texture from your OBJ animations.

Thermal sources

Since the rain simulation includes ice build up as well, one common task is to provide deicing mechanisms for rain surfaces, which can be done using thermal sources. A thermal source can be anything applying heat to the surface, for example a vent blowing hot air or an electrical filament embedded into the glass. Thermal sources work very similarly to wipers, they provide THERMAL_texture  and THERMAL_source  OBJ commands and X-Plane supports up to 4 individual thermal sources per OBJ.

Note that thermal textures are only used to drive the visual ice accumulation system, it does not replace the flight models icing simulation. The goal of the thermal texture is to guide the visual system so it can properly show where the heater removes icing. As a result you will still have to setup a proper de-icing system according to Windshield ice and rain protection datarefs. If you don’t provide the underlying flight model simulation with this information, your windows will ice over regardless of the thermal texture and the datarefs driving it.

The THERMAL_texture  also uses per channel gradients to describe where to apply the effect and how strongly. The channel describes the thermal source in question (red is 1, green is 2, blue is 3 and alpha is 4). The intensity of the channel describes the percentage of how much of the heat is applied to that area as a percentage. For a hot air blower, this would most likely look like a dot with an intensity of 255, with a gradient falling off to 0 around it. The dot is where the hot air is concentrated, whereas the gradient around it is the fall off of the hot air.

The THERMAL_source  command has the following syntax:

THERMAL_source <on/off dref>

The first parameter describes the dataref to be used to read temperature of the thermal source, in degrees celsius. The second parameter describes the dataref to be used to check whether the thermal source is on or off (1 or 0 respectively).

A complete example describing 4 heat sources looks like this:

THERMAL_texture    A330_glass_thermal_gradient.png

THERMAL_source   A333/window_temp1  sim/cockpit2/ice/ice_window_heat_on_window[0]

THERMAL_source   A333/window_temp2  sim/cockpit2/ice/ice_window_heat_on_window[1]

THERMAL_source   A333/window_temp3  sim/cockpit2/ice/ice_window_heat_on_window[2]

THERMAL_source   A333/window_temp4  sim/cockpit2/ice/ice_window_heat_on_window[3]

6 comments on “3-D Rain Effects

    1. You might want to check the section above titled “Combining inside and outside glass”. That sounds like exactly what you’re seeing.

      1. Yep, either I was blind when I read that the first time or they added it more recently (along with the part about xplane2blender?). Thanks though!

  1. Hi!

    I am very new to aircraft design so I’m learning and figuring out things as I go along.

    I have an old aircraft that I’ve converted to X-Plane 12 using Plane Maker – it’s my favourite aircraft as I am training in it in RL. I’ve tweaked everything and she now flies beautifully and all I now need to do is as the rain effects. I’ve changed the OBJ to ‘Outside Rain Glass’ and the rain is working as expected. However the rain drops are HUGE. So I’ve set the scaling using the RAIN_scale command in an lua script to 0.1 but they are still way too big. I cannot seem to get them to the correct size and I assume that 0.1 is the smallest setting available. Is there anything else that I need to do to fix this please?

    DazzyB.

  2. Does XP calculates current window temperature? Or devs must do it in their plugins?
    And i’m having trouble getting ice on front windows. Rain is already set and wipers are working.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please do not report bugs in the blog comments.
Only bugs reported via the X-Plane Bug Reporter are tracked.

Meta

Topic:

  • Aircraft Development

Article type:

  • Guide

Version:

  • X-Plane 12