I am designing a greenhouse scene for my portfolio (I stripped it down a few days ago), and have hit a pretty large issue graphically.
when I use any kind of object with a transparent material over another object with a transparent material, it appears the order gets mixed up and one is rendered over the other (in the wrong order).
Please ignore the fact that the screenshot is largely untextured, I have been trying to focus on this issue for a few hours now.
In this case, the Ivy is physically over the glass, infront of it, but is being rendered as if it were behind the glass, this is evident by looking at the solid frame versus the glass there the Ivy intersects the two.
Does anyone know how to fix this, it appears in scene and game view and is really limiting design?
Sorting order problems are a normal thing, unfortunately.
Use Cutout type of transparency for the leaves. It will be little difference visually. Cutout renders almost like a regular solid mesh, though, so no usual transparency problems.
This worked well, thanks.
Is this the only way to achieve this? What if I am placing objects that need transparency specifically? Is there any way to correct this?
I don’t know if there’s any way to influence sorting in Unity Editor.
In your own shader, you could use “Queue”=“Transparent+AMOUNT”.
Then use this shader for objects that need to be always in front of other transparents.
Normal code:
SubShader {
Tags {
"RenderType" = "Transparent"
"Queue" = "Transparent"
}
Fog { Mode Off }
Your modified sorting priority:
SubShader {
Tags {
"RenderType" = "Transparent"
"Queue" = "Transparent+10"
}
Fog { Mode Off }
You can change the sorting order (render queue) on a per-material basis. You can either do it through scripting, or by looking at the material with the inspector in debug mode, and changing the “custom render queue” value.
You get to debug mode by selecting the little drop-down in the inspector’s upper right corner, next to the lock symbol.
The render queue of objects influence how they’re rendered - objects on a queue with ID <= 2500 are rendered front-to-back, while objects with a higher queue are rendered back-to-front. AlphaTest is at 2450, while Transparent is 3000, so you’ll get different results between those two.
The problem is probably that, while Unity sorts transparent objects back to front, that doesn’t solve overlapping transparent objects.
What I’d suggest is splitting your plant into two meshes, and placing one mesh in front of the glass and one mesh behind, so it still looks the same, but unity can sort the two meshes for in front/behind.
Split it up us much as needed, such that the sorting of Unity can handle it.
I expect that the glass in the picture is one mesh. If it is split up into e.g. three parts, one on the left, one on the right and one below the plant, it becomes a lot easier to handle it. The plant itself should be split up as well depending on the positions from which it can be seen.
It is very annoying to do that, that’s out of question. But if a general solution is needed, this is the only way to handle it.