ndix UR

TPC compressed texture transparency: alpha blending

Recommended Posts

The TPC texture format contains a floating point number in its header that we refer to as 'alpha blending'. It appears to be critical when used with DXT5 compression. This tutorial will try to help you use this feature properly.

 

What is alpha blending?

 

Alpha blending is not a direct 'opacity' or 'transparency' factor. It is only relevant for non-environment mapped textures that contain alpha-channel image-based transparency. For example, semi-transparent signage, mostly transparent windows, ghosts, etc.

 

The best description I can give you for what alpha blending is:

 

TLDR: alpha blending is not object opacity. It hides any mesh behind the textured object that has opacity less than tpc alpha blending number. Set it to 0.0 when using texture alpha channel as transparency.

 

The meshes that will be hidden include any mesh that may be using alpha channel solely for environment mapping. Let's see how this plays out in practice with some visual aids. Each figure uses a TPC encoded version of the K1 Manaan Overhaul semi-transparent texture for the Sith Embassy signage. Transparency of the sign is right around 50%.

 

Figure 1. TPC with alphaBlending set to 1.0

 

post-25787-0-37508500-1515890233_thumb.jpg

 

With alphaBlending set to 1.0 the only thing that shows through the sign is the skybox itself. This may be some kind of depth buffer test to make sure that something always blends through, which, in the 1.0 case, leaves just the most distant mesh, the skybox.

 

Figure 2. TPC with alphaBlending set to 0.9

 

post-25787-0-30703800-1515890242_thumb.jpg

 

This seems to be the critical shot. With alphaBlending set to 0.9, lma_wall11 is showing, while lma_wall09 is hidden. lma_wall11 is 100% opaque, 0% transparent. lma_wall09 is 85% opaque, 15% transparent.  So because lma_wall11 opacity > alphaBlending, it is shown, while, for lma_wall09, opacity < alphaBlending, so it is hidden.

 

Figure 3. TPC with alphaBlending set to 0.5

 

post-25787-0-42935600-1515890254_thumb.jpg

 

In figure 3 we can see that both lma_wall09 and lma_wall11 are showing because their opacities are both greater than 50%.

 

Figure 4. TPC with alphaBlending set to 0.0

 

post-25787-0-60201400-1515890263_thumb.jpg

 

This looks exactly the same as figure 3. Wait, isn't that weird though? Why can't we see the other sign through the first sign? It's opacity is 50%, which is greater than 0.0...

 

Figure 5. TPC with alphaBlending set to 0.5, reverse viewing angle

 

post-25787-0-74486500-1515890270_thumb.jpg

 

Just by looking through the sign in the opposite direction, the signs in the background now are blended through. This is showing a couple things. First, it seems that alphaBlending doesn't actually control instances where the same texture is behind itself. Instead, it appears that there is some kind of directionality at play. I haven't figured out what determines the direction of blending. I investigated whether it was the faces that appear earlier or later, but that didn't necessarily seem true.

 

Using alpha blending

 

The game's vanilla textures use all kinds of different values from 0.0 - 1.0 here. I do not fully understand why or how they have come up with a lot of their alpha blending values. In my testing, it seems like if you have a semi-transparent object, you set this to a low value, 0.0 or 0.1, and if you have a non-transparent object, you set this to 1.0.

 

The important thing is that you do not think of alpha blending as the transparency or opacity of the object itself.

 

If anyone comes up with better guidelines for setting this value through scientific testing, I will be happy to update this post to reflect the improved guidance.

  • Like 3

Share this post


Link to post
Share on other sites

I want to add something to this in that alpha blending seems to be related to the "background geometry" setting in models. I think this setting is responsible for why the skybox is still visible in Figure 1 of the original post but I'm not quite sure, so I'll describe my situation:

I had basically several flat meshes behind each other with textures A, B and C. They were ordered A B A B C with C being the skybox with no alpha channel and A and B both having semi-transparent parts in their alpha channel. In my original setup, neither of these meshes had the "background geometry" flag enabled (not even the skybox C).

In that case the skybox would always render in the background behind the semi-transparent parts of A and B. If A and B occluded each other however, only the one with the higher alpha blending would render through the semi-transparent parts of the other. So if let's say A has an alpha blending of 1.0 and B one of 0.9, then I can see A through B but not vice-versa. If they both have the same alpha blending, it would still favor one of them. This seems to be related to the model hierarchy as described by JC here. Basically, they have to be linked to the base from back to front for the semi-transparency to work properly.

Things changed however, when I changed the "background geometry" setting. I originally activated that only for A and B as I assumed that C already had it enabled which turned out not to be the case. Once I did that, the alpha blending for A and B no longer mattered. Both A and B would now be rendered through the semi-transparent parts of each other. But now C would no longer render behind them. Once I enabled "background geometry" on C as well everything worked as intended. Now all meshes are rendered behind semi-transparent parts of all other meshes with their alpha blending all set to 1.0.

So maybe "background geometry" is some kind of override for alpha blending in that meshes with that setting enabled are always rendered behind semi-transparent textures but if they themselves are semi-transparent, no non-background-geometry-mesh is rendered behind them.

Maybe this can help in some instances where only changing the alpha blending value doesn't work.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.