Transparency z-roder

I have this three (unity default) cubes that do not overlap each other, all using the built-in Transparent/Diffuse shader with the alpha set to 100%.

Depending on the view position, the z-order is wrong. I can’t put them in different renders queues cause the user can rotate around them.

What am I doing wrong and what can I do to fix it?


all shaders not from opaque render queue (and transparency too) are sorted from far to near. so closer object renders later. objects are sorted by whole meshes. transparency shaders not (and can not) writes to z-buffer so objects can be overlapped as well independent of it’s z-position

so… in your case 3 meshes are sorted by z-order from far to near and renders in that order… unity renderer did everything correct.

  • solution 1: if you use shader for opaque geometry - use opaque shader.
  • solution 2: shift an object’s pivots so that it will sort correct - you can programmaticaly detect correct order but you need some calculations
  • solution 3: same as (2) use some calculations and sort object to 2 (3,4) render queue sets, then just change shaders to ones with a shifted render queue - this will change render order correct
  • solution 4: combine the whole geometry of cubes into one mesh. this can cause a strange overlaps, but usually works fine - need to be tested in your case
  • solution 5: split cubes into planes by each side - this will solve all overlaps in your case and if flat planes will no intersect, it also solves all other issues with transparency overlaps