Search Unity

How to avoid stretching of projected texture? - shaderforge

Discussion in 'Shaders' started by Deleted User, Apr 8, 2015.

  1. Deleted User

    Deleted User

    Guest

    I want to project a texture accross the y axis without blurring, I have tried using triplanar mapping rather than just y projection (pic bellow) but I still get some stretching in a few places.

    It is for a snow/moss type shader.
     
  2. Deleted User

    Deleted User

    Guest

  3. echo4papa

    echo4papa

    Joined:
    Mar 26, 2015
    Posts:
    158
    You'll always get stretching with projected UVs. The only way to avoid this is to manually UV map your mesh, and not project the texture in the shader.
     
  4. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    The only thing I can suggest to minimize the obviousness of the stretching would be to angle the projection, but that won't work very well on terrain that is rounded and not mainly a single slope facing a single direction.

    Only real way to avoid it is to make sure you don't have edges that go downwards to fast.
     
  5. Deleted User

    Deleted User

    Guest

    That is my conclusion aswell.
    Situation: I want textured objects that don't have prominent seams where they intersect with each-other.
     
  6. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Throw on some SSAO and the seam will nicely be hidden then ?
    The only theoretically flawless solution I can think of would be to use 3d textures. But how would you create one for this?! And considering the amount of "objects" in the texture it could easily cause other issues.
     
  7. Plutoman

    Plutoman

    Joined:
    May 24, 2013
    Posts:
    257
    Most likely, the tangents aren't being calculated entirely correctly, and the normals on the object are too sharp.

    The mesh should have split vertices, with normals pointing in opposite directions, disconnected, or you will have to deal with stretching on some level or another (I did not want to rewrite Marching Cubes to solve this). You can mitigate it by subdividing and blending the vertexes a little more finely, and/or by calculating the tangents more accurately.

    Been dealing with this for a little while. If you examine the normals on the object, the normal will point say, 'up', and when triplanar goes across that, it uses the normal to blend. Since the normal is pointing more along the direction the far side of the mesh is using, it goes along the XZ axis (like it does on the top side).

    That's why you'll only ever have stretching on one side or another. If you're using marching cubes, try smoothing the density values. a bit before generation. If it is a manually made mesh, split the vertexes and separate the normals along that edge (best solution generally). Or, smooth the edge with subdivision.