I was using the standard shader just for testing when I noticed that(Image 1):
The wall and the floor overlap each other in a weird way… it is also seen in-game view…
However when I made them opaque(Image 2):
It was all perfectly fine…
However, due to my need to change the colors’ alpha values, I have to keep them transparent…
My question is: Why is this happening and how can I fix it?
Correct and efficient sorting of real-time transparency is an unsolved problem.
When sorting multiple transparent objects, Unity is sorting the entire object based on that object’s bounds center to camera distance. When you have a large floor, it’s not uncommon for its center to be closer to the camera than an object placed somewhere on it, causing it to render on top when it should be rendering behind.
For this specific case, you will probably want to carefully control the material queue of your floor and wall so that the floor is always an early queue than the wall. If you have multiple walls, try to keep them broken up into individual segments that don’t intersect and are no longer than the biggest distance between them, otherwise you’ll have the same sorting problem you’re having here.
Alternatively you can look into more advanced techniques for doing alpha, which I talk a little about here:
Or you can use dithered opacity instead of alpha blending which keeps the walls technically opaque so they always sort correctly.