Search Unity

Textures stretched or squashed on procedural mesh

Discussion in 'General Graphics' started by Quimby_RBG, Dec 3, 2020.

  1. Quimby_RBG

    Quimby_RBG

    Joined:
    Jun 5, 2011
    Posts:
    11
    Hi all.
    I am having troubles getting the textures to sit properly on my procedurally generated mesh (a terrain chunk, but not Unity terrain).
    On tris with a substantial slope, the texture is stretched or squashed (as you would expect) to fit the triangle.
    I have written an algorithm to adjust the UVs across a chunk to minimise this effect, but it can only go so far and many tris have obvious and awful texture issues.
    I'm wondering if anybody has good ideas about how to resolve this.

    The chunk is a grid of verts that are uniformly distanced on the X/Z plane, and vary in Y height, with 2 tris per square on the grid.
    I currently have divided the chunk into multiple submeshes for each texture applied and have the textures packed into a texture atlas for rendering optimisation.
    In case I haven't properly described the issue, imagine a flat mesh with a single vert in the middle being very high - the textures on the tris connecting to that high vert are stretched.

    One solution I have considered is using shader graph to texture the mesh at run time, but I am not at all familiar with shaders in general, let alone shader graph, so I would appreciate some feedback on if that were a practical solution.
    Any other potential solutions and ideas would be appreciated; I don't know how Unity terrain textures its mesh with the splat map, so if anyone has some insight into how to code that I'd love to learn.
    Thanks.
     
  2. Tartiflette

    Tartiflette

    Joined:
    Apr 10, 2015
    Posts:
    84
    Quimby_RBG likes this.
  3. Quimby_RBG

    Quimby_RBG

    Joined:
    Jun 5, 2011
    Posts:
    11
    Wonderful, thank you for the link.
    It looks like what I need and will read that article properly soon.
    I never would have stumbled onto that organically, I am very grateful for your help.