PDA

View Full Version : Misc BF2 BundleMesh Transparency


Rhino
2016-01-05, 18:34
Really quick little info guide since some fellow devs are asking me about how and which way is best to do transparency :)

I'm only going to go into BundleMeshes for now since StaticMeshes is another story which I might go into another time but for now will just over complicate things.


Types of Transparency

Firstly there are two types of Transparency in BF2, "Alpha Blend" & "Alpha Test".


Alpha Blend
Alpha Blend is the most common type of transparency seen on Bundle Meshes and it allows for not only fully opaque or fully transparent, but also anything in between, which is what you need for things like dirt glass windows, that you can mostly see though, but isn't totally clear, like the rear passenger window on the Technical, where the driver window and windscreen are smashed but still bits of semi-transparent glass remain in them.
http://i.imgur.com/xZkfEHd.jpg


Alpha Test
Alpha Test is not that commonly seen on BundleMeshes but this is mainly because its not so known about, but also because it only allows for either fully opaque or fully transparent, transparency, and nothing in-between, so you can't do semi-transplant things like glass. On the plus side thou this can be what you want on some things like a wire mesh where you only want your texture to be fully opaque where the wire is, and fully transplant in-between the wire, like for example on this SideNet Radar:
http://i.imgur.com/eCeWlYr.jpg
http://i.imgur.com/JeNJVIT.jpg
In theroy it is also easier for GPUs to render this type of transparency (so better performance) than it is for "Alpha Blend", but I've got no solid evidence to support that.



Transparency Shader Techniques

"Shader Techniques" determine how the Shader will use the textures its being asked to load for each material, for example in which texture, and which channel of that texture, it needs to look for the opacity map and then how it will use that opacity map and so on. I'm only going to give examples/info of Shader Techniques related to Transparency here since there are lots of different combinations of Shader Technique and each behaves slightly differently.


Alpha Blend Shader Techniques

All the following Shader Techniques use the "Alpha Blend" type of opacity, meaning they are capable of having semi-transplant materials. Read the "Types of Transparency" segment above for more details.

Alpha
This is the most basic "Alpha Blend" Shader Technique and it loads the Opacity (Transparency) map from the "*_c.dds" alpha channel, and the Specularity (Spec) map from the "*_b.dds" alpha channel, if a "*_b.dds" texture is loaded and if not, no spec is used.
Best examples would be firstly the 1st Person Chinook Series Windows that use this Shader Technique:
http://i.imgur.com/9u0GH7p.jpg
http://i.imgur.com/fyhzh5i.jpghttp://i.imgur.com/L8H2fpo.jpg
Next best example would be pretty much all of PR's first person scopes have an inner shadow to them which has its opacity map in its "scopeinner_blackgradient.dds" ("*_c.dds") texture but it dose not load a normal map, so has no spec/shine.
http://i.imgur.com/6crbu1X.jpg

AlphaEnvMap
This Shader Technique is basically the same as the "Alpha" technique above, with the slight exception that it also allows for an ENV Reflection on it, which is really good to have on many types of glass as it makes it look more life like and many types of vehicle and scope glass textures use this material as a result.
The Best example again are the Chinook Windows, although its the 3rd person windows (outside) ones that use this rather than the first person which only use the "Alpha" Shader Technique. Overdone example in BFMeshView to show the reflections more clearly, ingame they are much more subtle and don't have the glowing edges:
http://i.imgur.com/exaj4wL.jpg
http://i.imgur.com/fyhzh5i.jpghttp://i.imgur.com/L8H2fpo.jpg



Alpha Test Shader Techniques

All the following Shader Techniques use the "Alpha Test" type of opacity, meaning they are NOT capable of having semi-transplant materials and can only be fully transparent, or fully opaque. Read the "Types of Transparency" segment above for more details.

Alpha_Test
This Shader Technique loads the Opacity Map from the "*_c.dds" Texture's Alpha Channel and if a "*_b.dds" texture is loaded, it loads the Spec Map from the "*_b.dds" Texture's Alpha Channel.
The Best example here is the SideNet Radar again as this has it set up with all Diffuse, Opacity, Normal and Spec maps, although it should be noted that the texture setup isn't very optimized and really the transparent radar should really be on its own sheet since 3/4 of the opacity map is wasted memory from the rest of the texture not needing one.
http://i.imgur.com/eCeWlYr.jpg
http://i.imgur.com/JeNJVIT.jpg
http://i.imgur.com/lzk6coE.jpg
http://i.imgur.com/iMRC9SW.jpg

Alpha_TestColorMapGloss
This is a really interesting Shader Technique since depending on what textures are loaded, it can behave very differently, so I'm going to split this one into two parts; with and without "*_b.dds".

Alpha_TestColorMapGloss - WITH "*_b.dds"
This Shader Technique, with it loading a "*_b.dds" Normal Map, loads its Opacity Map from the "*_b.dds" Normal Map's Alpha channel, and the Spec map from the "*_c.dds"
Best example would be the Scimitar/Scorpion's Exhaust Guard which loads its opacity for the holes in the guard from its "*_b.dds" Normal Map's Alpha Channel, and loads it's Spec map from its "*_c.dds" Alpha Channel.
http://i.imgur.com/xLnptsr.jpg
http://i.imgur.com/bFREtNy.jpg
http://i.imgur.com/Wu5yLvO.jpg

On a slight note, the Scimitar/Scorpion would probably be better off with the "Alpha_TestColorMapGloss - withOUT "*_b.dds"" setup since it would save more texture memory and wouldn't loose anything, in fact it would have better quality holes since the "*_c.dds" texture is saved at a higher resolution.

Alpha_TestColorMapGloss - withOUT "*_b.dds"
This Shader Technique, withOUT it loading a "*_b.dds" Normal Map, loads its opacity from the RGB channels of the "*_c.dds" texture. To be more specific, it looks for any areas on the texture that is on the faces of the material that have this material applied to it, for any 100% black areas and anything that is 100% black (or close to it), becomes fully transplant, where anything that has any other colour on it, is fully opaque. At the same time it loads the Spec Map from the "*_c.dds" Alpha channel. This material is really good for saving on texture memory since you do not need any specialised Opacity Map and its simply just integrated into the main Diffuse/Colour texture. On the down side however, you naturally can't have any Normal maps but that might not be so much of a big deal to have this material simply not load them even if the rest of your model loads a DXT1 normal map.
One simple example of this would be the Lee Enfield No.4 Rifle's Ammo Clip which has this type of material applied to it, to make the holes on its sides transparent, while saving it from having to potentially double its texture memory usage if it was to have its own specialised Opaque map, just for a few tiny holes.
http://i.imgur.com/PV3b0Bd.jpg
http://i.imgur.com/LxPHf5E.jpg
http://i.imgur.com/nqFupJD.jpg


Exporting with Transparent Materials

This section is really (mostly) covered in my "Working With Multi/Sub-Object Materials (https://www.realitymod.com/forum/f189-modding-tutorials/117705-working-multi-sub-object-materials.html)" Tutorial under the "Part 1. Multi/Sub-Object Material Setup" & "Part 3. Transparent Materials" section and it also only fully works if you totally use the Multi/Sub-Object Materials since only then can you name more than one (sub) material with the same name, if they are in the same Multi/Sub-Object Material so while you can do the rest of it outside of a Multi/Sub-Object Material, you can only have one material named "AlphaEnvMap" for example.
More info here: https://www.realitymod.com/forum/f189-modding-tutorials/117705-working-multi-sub-object-materials.html

Outlawz7
2016-01-05, 18:49
Please add info on StaticMeshes and Alpha. :(