We receive a lot of questions about how to optimize transparency on Sketchfab, so here is a blog post to give you some tips! Although they are several ways to handle it, the easiest way to go is usually as follow:
- Make sure to separate the geometry of transparent objects from non transparent ones
- Use a png with alpha in the diffuse slot and a jpeg greyscale in the opacity slot.
And here is a great model summarising this post with examples:
A little story about order, and why it matters
Rendering transparent objects is done by blending colors. Objects are drawn one by one on top of each other and depending on the order they are rendered, the blending result differs.
- Left: Green square is in front of the red one.
- Right: Red square is in front of the green one.
Offline renderers like raytracers and modeling tools favour quality over performance. They can afford to sort each triangle before rendering a frame, so blending is not an issue.
When achieving realtime performance level there is a limitation due to raster algorithms; polygons are drawn by batches, and per batch the order in which polygons are drawn can’t be predicted.
That’s why Sketchfab makes a compromise between transparency quality and speed by sorting transparent objects and not transparent polygons.
How to improve transparency on models
For better results you want to avoid merging your transparent objects in only one geometry. You should also avoid objects that overlap much over themselves, and split theses objects into smaller objects as needed.
For instance, bellow is a full sphere which does not give great transparency because the front and back faces are drawn in the same batch.
But the more the sphere is split into smaller objects, the nicer the results are.
Alpha textures are subject to the same difficulties so you have to avoid overlapping meshes and split into smaller parts if necessary.
You can place alpha textures on a material by either placing a transparent png (RGB+alpha) on the diffuse channel or placing a grayscale image on the opacity channel.
The texture format option enables you to set how colors are encoded : RGB for color texture only, RGBA for color + alpha transparency, and LUMINANCE for alpha transparency only. For instance, opacity in textures can be encoded either as alpha channel, or grayscale levels.
You’ll find a use case below:
Finally, a few tips from one of our users, Dan, who has recently been making a lot of experiments with that!
- If you get white fringes around the edges of the transparency, you can eliminate it by plugging the same opacity .jpg into the lightmap as rgb. This way the outside transparent areas get no light and don’t show up at all.
- Sometimes transparent objects look good from one side, but the back side gets a harsh shadow that is hard to eliminate. This can be eliminated by turning off double sided, but that isn’t always what you need.
- In this case, you can solve the problem by duplicating the polygon planes, reversing the normals on the duplicate and then sandwiching it back together with the original, thus creating a double sided plane with the normals pointing out on both sides. This way you can turn of double sided in Sketchfab while still having a double sided plane.
In any case, always feel free to reach out to the team at email@example.com if you struggle with that!