Problems with Transparency

Transparency rendering is no easy problem to handle. So far have all game engines I have tested have used object sorting and rendering back to front to handle the general case with transparency and then maybe used fixes for special cases when possible. Here Comes some of the problems discovered so far in stingray.  All the bottles are marked as transparent but with an opacity of 1.

Rendering Order
Object sorting errors
This images shows the rendering order problem, in the left image the bottle is drawn in front and in the right it is drawn behind. Here the objects are sorted on distance to the camera (the object’s position to the cameras position) so only by moving the camera it’s possible to change the rendering order. This problem can be even more complex when the object itself needs a internal rendering order to look correct.

Shadows for Transparent Objects
In this image the fully transparent¬†(opacity 0) bottles¬† cast shadows that are too dark. The reason for this is the shadow maps only store a single depth for each pixel which means that there is only a “cast shadow” or “not cast shadow” for each object, while it here should cast a softer shadow since some of the light is passing through.

Distance Fog and Transparency
Here is the distance fog calculation not calculated correctly making the transparent object get more fog applied than the surroundings. This problem should be easily solvable but it’s a general problem for transparent objects in fog that the fog needs to be calculated for different depths of the same pixel.

Clouds and Transparency

The left image is the bottles seen from above and in the right image the camera is placed on the left side of first image, viewing the bottles from the front.

Instancing and Transparency

To increase performance, objects of the same type are often instanced so they are all drawn in the same time. It can be seen as many objects are combined into a single object which means the objects needs to be sorted internally to be drawn in the correct order.

Depth of Field
A shader technique which requires the depth of the objects to work is Depth of Field. As can be seen here the bottle, even at the same depth in the scene as the barrel, looks blurry, the reason is that the transparent objects don’t write any depth so the bottle uses the same depth as the background.