Dynamic Texture Swapping
How to use multiple textures and get your model to repaint itself in flight.

When stock CFS2 aircraft models lose parts, the only ones that actually separate from the model and flutter away are ... the nose, the tail, wing tips, and the wings themselves.

I've seen a lot of combat camera footage and it's rare to see an airplane lose an entire wing, its entire tail section, or its entire nose section as a single chunk. It's more common to see large areas of skin shot away, or aircraft parts getting shredded into small pieces, leaving a jagged tear at the point of separation.

Let's say you want your model to shed large chunks of the nose cowling to reveal the engine and other internal parts in that area. You're going to add complexity to your model by doing this, but the resulting effect is pretty impressive.

Create and set in place the internal parts you want to see when the skin comes off, e.g. engine, oil tank, hydraulic reservoir, engine mount ... whatever. Give them textures if you choose or simply apply a material color.

Now, when you create your damage texture bitmap, make sure the transparent areas, or "holes in the skin," are placed to maximize the visibility of your internal parts.

DESIGN

TIP
Texturing a part, say the fuselage, with a transparent hole makes it possible to see completely through your model. If there is no visible part between the transparent hole and the other side of your model, you will see "blue sky" peeking through the aircraft. That may not be what you had in mind.

To avoid this outcome, either eliminate the transparency in the hole, or put a visible part or other textured polygon inside the model that will become visible through the transparent hole.

NOTE
Build your model correctly in the first place

In order for dynamic texture swapping to work, your model and damage profile must be properly set up for disappearing parts!

Dynamic texture swapping also works for break away parts, but the point is to leave them in place and repaint them with a damage texture.

Here's how it gets done ...

The visibility tests, texture assignment and rendering of the part are all SCASM coded commands within the model file.

When CFS2 processes your MDL file to render the model, which it does for every frame displayed in the simulation, it first tests any pre-process condition assigned to a part to determine how, or if, it will be rendered.

If you assign the appropriate parts_visible to each part, e.g. "right_wing_visible," tail_visible," etc., that part will then fall away from the main model when triggered by the "BREAK" command from the DP file.

If the "parts_visible" test shows the part is visible, CFS2 applies the assigned texture and renders the part.

If the test shows the part is not visible, CFS2 applies the assigned texture, spawns a break away model with only the "broken" part visible and renders the rest of the main model with that part missing.

If you assign the parts_visible test "fuselage_visible" to every textured part in your model, you guarantee two things:

  • The part will always be rendered on the main model, and
  • The part will never be rendered on the break away model.

DESIGN

TIP
Here's the secret!

In the object source code file (.sca), modify the result of every visibility test to assign a damage texture to the part instead of its normal texture.

Now, when CFS2 tests a part's visibility and determines the part is not visible, CFS2 will apply a damage texture to that part and render the part instead of skipping it.

The result? When the DP file commands a break away part to "BREAK," the part remains visible on the main model, but instantly shows a different texture, one that reflects any surface condition you want to impose!

You can still make the part "disappear" by painting it transparent on your damage texture, in which case you will simply not see it ... only the parts hidden beneath. However, by carefully creating the damage texture, you can texture a part with large gapping holes that display the interior of your model.

If you want a real challenge ... use dynamic texture swapping to display bullet holes and damage that increases as the aircraft is hit in combat.

NOTE
Bullet holes are the result of an interaction between the model file (.mdl), the introduction of some special SCASM code in the object source code file (.sca), and a properly set up damage profile (.dp). All three of these files have to work together to bring this effect off successfully.

There are actually two ways of adding bullet holes to your model:  the polygon method, which places texture"decals" on small polygons strategically placed on your model, and the use of dynamic texture swapping using a set of different texture bitmaps.

Dynamic texture swapping requires SCASM editing, editing the [BOXES] section of your damage profile, and adding a lot of new texture files, but as you'll see, the results are pretty impressive

Tests on each of the CFS2 16-bit flag variables bullets0 ... bullets7 are used as event triggers to determine when to swap textures.

These variables can each track up to sixteen hits, which means that each of sixteen possible bullet strikes can be tested to determine if a hit has occurred or not. These flags tell you nothing about where the bullet hit the damage box, just that it hit either the upper, lower, left or right side of the box.

So just what can you do with this information? ...

Dynamic Bullet Holes