Drawing order problems with transparent textures

Introduction

Maybe you started making sceneries before Fs2000 was there? Then you will surely remember how much time it could take to get rid of all those irritating bleed through problems that occurred when making a complex object. With the introduction of Fs2000 this problem was solved because the scenery engine now eliminates these bleed through for you. But a side effect of this nice new feature is that you sometimes run into trouble when using transparent textures. You expect to see polygons through your transparent polygon, but you look right into nothing. This problem appears relatively often in the scenery design forums and I have the feeling that a lot of people do not understand the underlaying principles that cause it. In this tutorial I'll try to explain where these problems come from and how you can solve them.

The problem

OK, before we start talking about how to solve the problem, let's first get clear what the problem actually is. Assume you want to make a cube. You have painted the inside with a nice red colour and for the outside you have used a green transparent texture. Then you would expect the result to be as the left picture in Figure 1, but too often the result looks more like the right one. How can this happen?

Buffeting of the scenery engine

To understand where the problem comes from we have to look at how the scenery engine draws the different polygons. The order in which the different polygons are drawn is the order in which they are placed in the BGL File. So the scenery engine just reads through the BGL and displays the polygons in the order they are found. So assume we have two polygons in our File. One is 50 meter ahead of us and the other is 100 meter ahead of us. Let's also assume that the code of the the polygon closest to us is in the BGL File before the code of the other polygon.

In that case the polygon closest to us is drawn First. The polygon further away is drawn after that and this gives a conflict. Before Fs2000 this would give a bleed through problem, because a polygon further away is drawn over a polygon closer to us and therefore the order on the screen is wrong.

Since Fs2000 a new feature has been build into the scenery engine that check for these sort of problems and that hides the part of polygon that is further away if it would display over a polygon closer to us. Therefore we don't have those bleed through problems anymore.

Drawing order

Let's assume we have a cube. I'll only consider the four side polygons here. We will call them polygon A, B, C and D from now on. All these polygons are drawn double sides, so they all have an inner and an outer face. I'll call them Ai, Ao, Bi, Bo, Ci, Co, Di and Do. A top-down view of the situation is given in Figure 2.

Now let's assume that the order of the polygons in the source code is like this: Ai, Ao, Bi, Bo, Ci, Co, Di, Do. This is an order that is often used by scenery design programs. If we look from viewpoint 1 (see the arrow) at the cube the scenery engine will hide some polygons for us, to prevent bleedthroughs. The polygon Ci for example is drawn after Ao has been drawn to the screen. So Ci will be hidden to prevent problems.

But when we look from viewpoint 2 you'll see that there are no problems, as Ai is drawn before Co, so there is no problem here. If we consider another option for the order like Ai, Bi, Ci, Di, Ao, Bo, Co, Do, then you will see that there are no conflicts in this case and no polygon is hidden for us. But when we would use Ao, Bo, Co, Do, Ai, Bi, Ci, Di then there is a conflict from each drawing angle and all inner polygons are hidden.

Transparent textures

I hope you understand the principle of the polygon hiding by the scenery engine by now. But you will probably think: What has this to do with my transparent texture? Well, actually the scenery engine does not know what kind of texture is applied to your polygon and it will still hide polygons to prevent bleed through problems. Let go back to the cube from the previous section and assume we apply a transparent texture to the outside polygons, while the inside polygons are solid.

If the drawing order is like the last example we considered there (Ao, Bo,Co, Do, Ai, Bi, Ci, Di) then you will see that the scenery engine hides all the inner polygon and through your transparent texture on the outer ones you see absolutely nothing. On the order hand if we use the second drawing order (Ai, Bi, Ci, Di, Ao, Bo, Co, Do) then everything is fine and it looks like you intended.

For the ¯first drawing order (Ai, Ao, Bi, Bo, Ci, Co, Di, Do) you should by now understand that from viewpoint 2 everything looks like you intended, but from viewpoint 1 you look into nothing again. This shows that the drawing order is really important to prevent problems when you use transparent textures. The general rule is:

Draw to polygons of the inside before you draw the polygons of the outside

For most simple objects this works ¯fine. Although it is not always very easy to achieve in scenery design programs. Unfortunately most do not have an option to control the drawing order directly (I believe NOVA is an exception there). So it might require some hand editing of the SCASM (or BGLC) source to get the required results. I will not discuss it in great detail here, but assume you have a really complex object like the terminal of Schiphol I have made. A top down view of a piece of one of the piers is given in ¯Figure 3.

In the current version of the Schiphol scenery this terminal has been made with transparent windows, so you can look at the interior of the pier (see the passengers waiting for your °flight for example) and you can look through it and see what happens on the other side of it. Let's have a closer look at the head of the pier. We will only look at the four polygons named A, B, C and D. And just like the cube before they have an inner and an outer side (Ai, Ao, Bi, Bo, Ci, Co, Di, Do). If we look from direction 1 (see the arrow) then the optimal drawing order would be: Do, Di, Ci, Co, Bo, Bi, Ai, Ao. But if we look from direction 2 then the optimal order is: Ao, Ai, Bi, Bo, Co, Ci, Di, Do. It is clear that it is not possible to create one drawing order that can satisfy both of these conditions. In this case we would need to make the drawing order dependant on the viewing angle. The SCASM command VectorJump can be used to do this. I will not give more details about how this has been done here1. But I just wanted to indicate with this example that for complex objects it is not always possible to ¯nd one certain correct drawing order.

Texture types

The theory above is always valid, but it has been reported that the different texture types that can be used in Fs2002 sometimes give different results. This will be discussed in this section.

To see this effect I have applied two different textures to a cube with a wrong drawing order, one has a semi transparant piece, while the other has a completely transparant piece. The result for the di®erent formats that can be found in ImageTool and support an alpha channel have been given in Figure 4 and Figure 5.

It is interesting to see that for all textures with a 1 bit alpha channel the problem doesn't appear anymore. So it seems that Fs2002 has an extra feature compared to Fs2000 that prevents the transparancy problem. But for a semi-transparant texture the problem happens all the time. It should be noted that having the correct drawing order will prevent the problem in any case, althought for a 1 bit alpha channel choosing the correct texture format might be a faster way to solve the problem.

Notes: ² For the 8 bit image ImageTool corrupted the alpha channel for the fully transparant texture, this caused it to have also some gray tints and should probably explain the results for it. ² For the DXT 1 image the semi transparant texture is equivalant to the transparant one, because that format only has a 1 bit alpha channel. Therefore the results are also the same. ² For the DXT 3 texture with a 1 bit alpha channel something really strange happens, here the complete texture isn't visible anymore. At the moment I have no clue what is the cause of this e®ect. ² The 555 also has a 1 bit alpha channel like the DXT 1 format, but at DXT 1 my gray color for the semi transparant texture became black, where at 555 one dot became white and the neighbour became black. This explains the di®erent look, but also that the result is still rather OK.