Sometimes semi-transparent objects are sorted incorrectly and hence rendered in a unnatural order
Introduction
SynergyXR is implemented in the Unity Engine, and Unity renders 3D objects in two different ways:
- Solid objects have their depth sorted for each individual pixel, using something called a Z buffer (basically the nearest object for each pixel wins)
- Transparent objects are drawn one after another, so the one first drawn will be partially or completely overshadowed by the ones drawn later. All the transparent objects respect the z-buffer describing where the closest solid object is.
The problem
Sometimes it can be difficult to ensure that the order of drawing the transparent objects is correct. Let’s take an example:
In the image above, a problem is illustrated.
- In SynergyXR Images can be added by a user. They are all drawn in renderqueue 3000 (default transparent), and they will be sorted within that renderqueue, based on which of their centers has the closest “depth” to the camera
- If the water in the scene is also drawn in the default transparent renderqueue (3000), its “center” will be compared with the images. Since there is no good location to have that center for an object that stretches to the horizon, there is a chance that it is drawn in front of some of the images in the scene, showing half of the problem illustrated above.
- If the water in the scene is instead drawn in an earlier renderqueue, such as 2800, it will be drawn long before the images, and the problem seems to be solved.
However. The water now looks different, and more transparent than before, which was not what the 3D artist was looking for. It turns out that part of the sky with clouds is another transparent object, which is now drawn in front of the water, seemingly making bluish sky and clouds visible through the water.
The solution
To solve this problem, do the following in the SynergyXR Environment Builder when setting up the environment:
- Set the water render queue to 2995. The water is now behind any images added
- Either
- Set the water to have zWrite ON. This means that the water is interpreted as a “solid” object and is properly sorted. If you have the problem with a shader that doesn’t have this option, it may have an “opaque” option instead.
- Or make the skybox object opaque
- Or change the skybox object to be drawn in an earlier renderqueue than 2995, If the shader doesn’t have a direct option for this, it may have a relative “Priority” instead. Setting it to -10, should put it at renderqueue 2990
With one of the solutions above, you should have the effect that
- The sky is drawn behind the sea
- The sea is drawn behind later added images