- Home /
Two flat textures interfere with each other when both on z=0
Hi everyone, sorry if this has been posted before, I wasn't sure what to search for!
I have two flat game objects moving past each other both flat on the z-plane (z=0) but when they go past each other one texture is never in front of the other, they sort of merge and then snap from one texture to the other. Is there a way to fix this? I assume it's something with layers or tags?
Thanks!
Answer by Eric5h5 · Apr 13, 2011 at 11:01 PM
That's known as z-fighting. A good fix is to use two different shaders, where one is a copy of the other but has Offset -1, -1
in it somewhere. That way it's always drawn in front of the other object even when the surfaces are in the same plane.
Hi Eric, I'm using the "$$anonymous$$obile/Transparent/Vertex color" shader on two different GO's each with a different texture2d. I've put the first GO's material as -1,-1 offset in the inspector but it hasn't changed anything. Is that how I was supposed to do it or am I missing something? Thanks.
@jasonh: No, I'm talking about the shader, not the material. Change the actual shader so it has literally "Offset -1, -1" in the shader itself (put it in the subshader section). Not the offset in the material in the inspector, which is about offsetting UVs.
I duplicated the shader and added "Offset -1, -1" in the script in this section - Category { SubShader { Pass { Offset -1, -1 } } }
But it hasn't changed anything. Is that the right place to put it? And if so, what else could it be? Thanks.
@jasonh: Not sure if it makes any difference, but try putting it in the SubShader part rather than Pass. Also remember that you need two different materials.
Answer by Jean-Fabre · Apr 14, 2011 at 08:08 AM
Hi,
Eric5h5 suggestion is good. There is also another way out of this if you control the mesh themselves, by using having the center of each model apart. The one with the center closer to the camera will render first ( If I understand properly this thing...).
Also, if you plan on doing much work with flat textures in 3d, I suggest SM2 if you can afford it for your project, that will be a savvier and propose solutions for z fighting.
Bye,
Jean