Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Mesh drawing over itself

Discussion in 'General Graphics' started by Marscaleb, Oct 25, 2020.

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    971
    So I have this odd error where a mesh is drawing over itself. It's a simple wall with a lip running around on the floor. But that floor-lip is being drawn over the wall, and although it doesn't show in this pic, the wall will draw over the capstone on the top of the wall.


    So here's how I got to this point:
    This wall comes from a package I bought, and everything in said package is working perfectly. But I was trying to figure out how to get the walls on the bottom of the screen to not block the view of the player. Since the camera doesn't rotate, I decided to just make a copy of the wall where I delete the edges I don't want to see, keeping faces like the trim around the floor. But for some reason my version of Maya crashes when I try to load the fbx file.
    So instead I thought: why not change the material so the bits I don't want are transparent? So I made a copy of the texture with some transparency. And I decided to make the corner edges fade out, since I thought that would look like a nice touch.



    The original material used on the walls was a mobile-diffuse. It didn't seem to support transparency so I just changed it to the standard (specular setup) shader instead. I set the rendering mode to transparent and set the specular to pure black. That's it; that's all I did for this material.

    What's going on here, and how do I fix it?
     
  2. BrandyStarbrite

    BrandyStarbrite

    Joined:
    Aug 4, 2013
    Posts:
    2,067
    Is everything on the same layer?
     
  3. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    971
    Yes, in fact this is just one object, just one mesh.
    It can't be on a different layer from itself.
     
  4. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,750
    So, the entire mesh is using a material with translucency enabled? If so, that explains what you are seeing.

    What makes opaque geometry be drawn in the correct order is called "depth buffer". Opaque geometry uses this to know if the pixel it is trying to draw is going to end up behind something that was draw before, skipping that pixel if so.

    Translucent geometry does not normally writes to the depth buffer, because that would prevent anything else that is drawn later from being drawn behind it. Translucent meshes are sorted based on the distance from their centers to the camera and drawn back to front, after all opaque geometry is rendered, to try to make they look correct.

    Individual triangles in a translucent mesh are not sorted, so if the mesh isn't convex and has overlapping triangles, they can be drawn on top of each other like that.

    Also, it doesn't matter that only part of your texture is actually translucent, the entire mesh is considered translucent.