< previous page next page >

In this tutorial, we are going to use RapidCompact CLI to process and optimize assets with transparent parts and/or materials. In the following we will use the term opaque for all completely non-transparent materials, and transparent for all materials with any kinds of transparency, be it stored in materials descriptions or texture maps. In order to provide the best possible result according to the needs of your application, RapidCompact provides different Flattening Modes, which give the option to do a more selective merge of data (mesh, textures, materials) instead of exclusively merging all content to achieve the best performance possible (e.g., 1 drawcall per asset). We will see that it is still possible to reduce opaque meshes to one single drawcall, and why optimized assets with transparent parts or materials will always have a minimum number of two or more drawcalls, depending on the meshes and materials involved. In section Handling Transparency we go more into detail on why this is the case.

Table of Contents
The FlightHelmet model contains a transparent material and we will see what that means for the optimization process later.

Handling Transparency

 back to top

As an example file we will use the FlightHelmet asset which is shown above. You can download the glTF file here.

Let's see what RapidCompact does if we optimize the asset to 25% of the original polygons and use flattening mode "full". This can be done either directly in the command line by changing the "flattening:mode" setting, or by altering the config file under "flattening:mode". On the command line it will look like this:

     rpdx -i .\FlightHelmet.gltf -s flattening:mode full -c f:25% -e FlightHelmet-compact-full.glb

The resulting file will have only one drawcall, and all meshes and materials will be merged to use only a single, compact UV atlas. However, as you can see in the resulting model, the transparency of the glasses will not preserved:

The reason why RapidCompact does not preserve the transparency in this "full flattening" case is due to the real-time rendering pipeline not being able to deal with a mix of transparent and non-transparent parts within a single drawcall. Instead, the transparent parts must usually be rendered separately, one-by-one, and sorted back-to-front.

With RapidCompact, we are able to produce a different version that contains multiple meshes and nodes, and that will render properly in a real-time setting. The standard setting for flattening is "auto", which lets RapidCompact decide about the flattening mode - version 3 will simply flatten the asset "byOpacity". Let us simply recreate the last command, but without the --flatten command, to see the effect of the "auto" / "byOpacity" flattening mode in practice:

     rpdx -i FlightHelmet.gltf -c f:25% -e FlightHelmet-compact-auto.glb

As you may see when inspecting the resulting file, it will now have the exact same amount of faces and vertices as the previously optimized version, but it now has two drawcalls. Also, the transparency is now preserved and your rendered result should look similar to this version:

There are basically two different ways of storing transparency in the optimized models. Mostly this is dependent on how the input file's transparency is stored. If an input FBX or glTF file contains a transparency value in a material (or an OBJ file with Tr in the .mtl file), RapidCompact also preserves that material and its transparency. In many cases, however, the transparency is stored in an alpha channel of a texture map.

< previous page next page >