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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Odd pixel stretching on face of mesh

Discussion in 'General Graphics' started by jaksalad, Apr 21, 2015.

  1. jaksalad

    jaksalad

    Joined:
    Apr 21, 2015
    Posts:
    4
    I'm trying to create a truncated pyramid in blender and UV map it so I can texture all 4 sides with rectangular textures.

    I've gotten the textures to fit and show correctly for the most part, but there is some strange stretching on the 2 parts of the triangles of the face that I can't quite explain or fix.

    Here is an image showcasing my problem.

    http://imgur.com/ClIqozI

    The right/upper side of the texture slants towards the right, while the left slants towards the left. Is there any way to fix this so the texture looks more normal? Or is what I am asking just impossible? Thanks.

    Edit: I've also found this visualization: http://www.xyzw.us/~cass/qcoord/

    It also explains a solution to the problem, but I have no idea on how it could be implemented.
     
    Last edited: Apr 22, 2015
  2. KingMatthew

    KingMatthew

    Joined:
    Jul 7, 2013
    Posts:
    166
    The UV map must be off. You might have to manually change the UV map to work correctly with the geometry.
     
  3. Findus

    Findus

    Joined:
    Jun 23, 2012
    Posts:
    111
    Try flipping that inner edge.
    However, like you already suspected, there are good chances you can't get an even distribution without slanting with UVs like that because ...math.
     
  4. jaksalad

    jaksalad

    Joined:
    Apr 21, 2015
    Posts:
    4
    What do you mean by flip the inner edge?
     
  5. Findus

    Findus

    Joined:
    Jun 23, 2012
    Posts:
    111
    Sorry, I meant you should try to turn it. (In case you exported quads and Unity solved the quad differently than your modeling application. But that doesn't seem to be the case, here.)
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    As far as I know, the only real way to fix this is to use more triangles.

    --Eric
     
  7. jaksalad

    jaksalad

    Joined:
    Apr 21, 2015
    Posts:
    4
    Thanks Eric!

    You are in so many threads I browse and solve so many of my issues, I'm honored to have you solve a problem of my own. :)
     
  8. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Actually I'm pretty sure this is a very common thing, and more triangles will only make the issue harder to spot.
    If I'm not misstaken this looks ALOT like the texture coordinates used to sample the color are NOT passed as such from vertex to fragment shader, and thereby not perspective corrected.
    If you post the shader you are using I could take a look at it.
     
  9. echo4papa

    echo4papa

    Joined:
    Mar 26, 2015
    Posts:
    158
    Your UVs need to match how you want the texture to lay on your mesh. What's basically happening in the scaling conversion used to go from vertex UV space to pixel space isn't lining up because each triangle is handled separately (last I remember they were anyway). Adding extra triangles (simple subdivide in Blender) will help. Turning the inner edge will help too(Unity does triangle clockwise), or making your UVs match the shape of your mesh will help too.

    I ran into this issue with a custom shader a little while ago and it's all because of how the UV coordinates get interpolated for the pixel between the vertices. It was caused by the order the verts and Tris were rendered.
     
  10. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Completly correct, HOWEVER if the vertex -> pixel shader parameter is tagged as a TEXTURE0 (or higher sequential number), and you do NOT use a hard edge, then the GPU should do the fixing of those co-ordinates for you...
    I don't know if the winding order could be relevant tho.
    One thing I AM sure of, adding more triangles will ONLY make the problem less apparent, it will NOT make it go away. And it's completly possible to make it go away.
     
  11. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    Okay, this is the expected behaviour, the post you linked only specifies a shader level workaround, but the reality is UV's are linear interpolated the workaround will add unnecessary overhead.

    What is cause the issue!

    You have a model with a trapezium side, which you have mapped to a square in your texture UV, so think about the math, where it's interpolating through the middle, the center will be exactly 50% between the two, this creates the distorted image. First thing to do it trangulate the face in blender then you will be able to see the texture incorrect in there too! You can't see it on the quads as it interpolates them differently, but GPUs prefer tris and so it gets converted in Unitys importer.

    Whats the solution?

    Easy, map your models trapezium to a UV trapezium rather than a square, this will waste a few pixels in you texture (although if you pack everything right it should be minimal) but will sort the issue. This will then interpolate correctly.