Rendering order shifts with transparent cubes (3D perspective camera, Standard shader)
I've made a scene full of half transparent cubes. On the inside of each cube, there is another (slightly smaller) cube with the mesh flipped so the walls of the cube are visible from both the inside as well as the outside. My problem is that the ordering of the cubes isn't correct. If I look around with the camera while the game is running, the order of the cubes starts to jump around. As you can see in the images, the gray cube in the top left is jumping back and forth.
I'm using the 3rd Person Controller + Fly Mode as my player controller. All cubes are using the Standard shader. Also worth mentioning is that the cubes and corresponding materials are generated from a C# script.
This is done for each cube to enable transparency: material.SetFloat("_Mode", 3f); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); material.DisableKeyword("_ALPHATEST_ON"); material.DisableKeyword("_ALPHABLEND_ON"); material.EnableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = 3000;
I've tried setting the camera to Camera.transparencySortMode = TransparencySortMode.Orthographic
because I found this as a tip in the forums, but this made the matter worse.
Actually I was expecting this to just work out of the box. But it seems I have to do something special to get my use case to work. But what? :)