Transparency or Opacity describes if something is visible (opaque), invisible (transparent), or partially visible ("partially transparent", "see-through", "translucent", etc.) There are many methods of rendering transparent objects in real time. Transparency is often expensive in terms of processing and rendering performance. Among the different methods, there are trade-offs between image quality and viewer performance. This article describes the transparency modes on Sketchfab and suggests when each option is most suitable.
This article was adapted from a tutorial on our blog.
Rendering transparent objects is done by blending colors. Objects are drawn one by one on top of each other, and depending on the blending mode and the order they are rendered, the result differs.
Here is a simple 2D example. On the left, the blue square is in front of the orange square, while on the right, the orange square is in front of the blue square. You can see why order matters:
Offline renderers like ray tracers and modeling tools favor quality over performance. They can afford to sort each triangle before rendering a frame, so blending order is not an issue.
When achieving realtime performance level there is a limitation due to raster algorithms; polygons are drawn in batches, and per batch the order in which polygons are drawn can't always be predicted.
Sketchfab makes a compromise between transparency quality and speed by sorting transparent objects and opaque polygons.
There are many different blending modes (or mixing modes) which determine how two layers of an image are blended into each other. Users of Photoshop and other image editing software will be familiar with blending modes in image layers. The same principle applies to 3D rendering. There are performance and quality tradeoffs between the different blending modes. Choosing the appropriate mode will depend on your needs.
Blending is the slowest method of rendering transparency. All visible objects in the scene must be rendered, sorted, and merged into the final image. This is an "expensive" calculation. It is usually defined using a grayscale (Luminance channel) or Alpha texture, or a solid gray value. Blending mode is useful for translucent materials like glass, or materials with varying transparency.
Sorting each individual polygon in a model would be very slow, so the Sketchfab viewer sorts for transparency by meshes. This can cause "popping" or "flickering" in complex or intersecting shapes. If you experience this kind of problem, try splitting up the transparent object into more separate meshes.
Refraction is the phenomenon that makes light bend when passing through different transparent materials due to the velocity of light changing in different media. It makes objects behind the refractive material look distorted. Refraction is useful for simulating glass, water, gemstones, and many other transparent materials.
You can use a texture with an alpha channel or simply a value between 0 (transparent) and 100 (opaque).
- Invert texture will reverse the alpha channel.
- Tint adds a color to the transparency.
- Use diffuse will use the colors of the material's Diffuse / Albedo / Base Color.
- Index of Refraction (IOR) controls how the material refracts light. The IOR of air is 1.0.
- Use normal offset uses the material's normal map / bump map to define IOR instead of a physical model of light. This is useful for large planes such as water.
- Refraction Roughness controls the blurriness of the refraction.
- Use Roughness/Glossiness texture applies your PBR Roughness/Glossiness texture for as the Refraction Roughness.
There are some limitations to Sketchfab's implementation of Refraction:
- Refraction works best in PBR rendering. In Classic rendering, roughness does nothing.
- A refractive object can not refract itself.
- A refractive object can not refract other refractive objects.
- There can be sorting issues when mixing refractive and transparent objects.
- There can be artifacts when the camera moves.
- Objects outside of the field of view are not refracted.
- Only opaque parts of a refractive object will cast shadows.
- Disable the emissive channel; it can have a bad effect on refraction.
- If you use a color in albedo/base color, set it to white instead of black.
- Using a normal map can help add details and variation to the refraction effect.
- The IOR should be just small enough to take into account the normal map.
- Check lists online such as this one for accurate IOR values for different materials.
Additive mode is almost as slow as Blending. It works by adding the transparent colors of objects together, so order does not matter in this case. Black will be rendered as transparent. It is similar to the Linear Dodge (Add) blend mode in Photoshop. Additive transparency is useful for special effects and emissive materials like fire, sparkles, and holograms.
If only additive materials are used in a scene, objects do not need to be sorted, so there can be no flickering issues.
Dithered mode is a faster method to achieve Blending, but it produces "noise" during navigation. The image quality improves when the camera is not moving. It is usually defined using a grayscale (Luminance channel) or Alpha texture, or a solid gray value. Dithered mode is useful for complex geometries with partial transparency, like fur and hair. Enable the dithering pattern option to use a noisier pattern, useful for models with lots of thin layers of hair, fur, etc.
Alpha Masking is the fastest transparency method. It works by setting visibility in a binary (on / off) way. It is usually defined using a grayscale (Luminance channel) or Alpha texture. You can use the slider to set an Alpha "Threshold". Masking is useful for materials that require a "cutout" effect like leaves and logos.
The texture format option enables you to set how colors are encoded. For the opacity channel you can choose between Alpha (A) and Luminance (R).