Search Unity

URP texture array creating ribbon artefacts?

Discussion in 'Shaders' started by sangolemango, Jan 6, 2021.

  1. sangolemango

    sangolemango

    Joined:
    Jul 22, 2018
    Posts:
    7
    I have been working on a terrain system and for the textures, everything is sampled by calculating an index and a texture array.

    For some reason the shader is creating wierd ribbons. It seems that it has nothing to do with the index part of the calculation and maybe something todo with hlsl or the triplanar shader.

    Here is an image: upload_2021-1-6_20-8-1.png

    This is the shader: https://pastebin.com/kkFZfsA3

    Ive also tested this out with different textures to see if it was a texture issue, they are all 2048 x 2048 but when i switch them out i get the same error. upload_2021-1-6_20-8-1.png
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Your problem is being caused by this line:
    Code (csharp):
    1. int index = ((int)floor(input.uv.x) & 1) | (((int)floor(input.uv.y) & 1) << 1) | (((int)floor(input.color.r) & 1) << 2);
    The specific problem is interpolation is noisy due to floating point precision. If you have a triangle with a UV value of 2.0 on all 3 vertices, the interpolated value is not guaranteed to be exactly 2.0. Some places it will be 1.99999, others 2.000001, and yes, some spots will be 2.0. The solution is don't use
    floor()
    , use
    round()
    on interpolated whole integer float values.
     
    sangolemango likes this.