Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Procedural Mesh - Lines Between Faces

Discussion in 'Scripting' started by Velcrohead, Jul 23, 2015.

  1. Velcrohead

    Velcrohead

    Joined:
    Apr 26, 2014
    Posts:
    78
    Hi all,

    I've created a tile based mesh through code, with each 'tile' being composed of it's own 4 vertices / UVS etc. Nearly everything is running perfectly, apart from getting these weird lines displayed between the tiles.

    Does anyone have any idea what they are, and if so, how the hell to get rid of them? We have tried playing around with all the texture import options, and the texture itself is pixel perfect. Pictures in the spoiler below.




    Thanks in advance.

    EDIT : More research, more info.

    Have called .RecalculateNormals() but to no avail. The mesh does not share any vertices between tiles.

    Am I right in saying the mesh needs to share normals? If so, how would I go about doing this?

    Edit 2 : tried manually setting the normals. Absolutely no idea what I'm doing. Is it possible to just set them all to one shared value, as they're all facing the same direction?

    Thanks again.
     
    Last edited: Jul 23, 2015
  2. Velcrohead

    Velcrohead

    Joined:
    Apr 26, 2014
    Posts:
    78
    Hate to bump but still struggling.

    Have disabled mipmaps, which kinda helped. It removed the problem from the scene view, and when I did a build it was less noticeable, but still there when you zoom the camera in and out.

    Anyone?
     
  3. 1Piotrek1

    1Piotrek1

    Joined:
    Mar 14, 2014
    Posts:
    130
    I have this problem with my voxel terrain and I solve it by setting texture as clamp.
     
  4. Velcrohead

    Velcrohead

    Joined:
    Apr 26, 2014
    Posts:
    78
    Thanks for your response.

    I've tried setting the Wrap mode to clamp (and repeat, just to see) and that unfortunately has had no effect. I think I've tried just about every texture import setting there is!
     
  5. Velcrohead

    Velcrohead

    Joined:
    Apr 26, 2014
    Posts:
    78
  6. Velcrohead

    Velcrohead

    Joined:
    Apr 26, 2014
    Posts:
    78
  7. savlon

    savlon

    Joined:
    Jan 4, 2013
    Posts:
    7
    I had a problem like this and it took me a little to figure out... My issue was, I presume, due to floating point errors in the uv coordinates. The lines between tiles was actually the next section of the texture being included into the wrong tile.

    So to clarify, I had a texture that I was using as a sprite sheet. This texture had a bunch of different tiles set out in a grid format and I would obtain the tiles texture based on a uv coordinate system. The way I fixed the lines was to slightly reduce the uv coordinates so the actual square box was smaller than the tile image.

    For example:
    lowerRightCornerUV.x = (uvCoordX * tileWidth) - 0.01f

    Understand? So you are just subtracting a small value so the floating point precision error isn't noticable... I had to play around a bit to find the magic numbers to subtract... If anyone has a different way, I'd be happy to hear it too though. FYI: that code is for demonstration purposes only.

    I'm on my phone so I cannot format the code, sorry.
     
    GlacieredPyro likes this.
  8. 1Piotrek1

    1Piotrek1

    Joined:
    Mar 14, 2014
    Posts:
    130
    I had lines on my mesh second time and now i fixed it by setting max texture size as 32.
     
  9. GlacieredPyro

    GlacieredPyro

    Joined:
    Jun 23, 2013
    Posts:
    2
    Seems dodge, but thanks. It helped solve my problem.