Search Unity

Question Why does my sampled texture have a thick, inconsistent border?

Discussion in 'Shader Graph' started by DoubleUU, Apr 4, 2022.

  1. DoubleUU

    DoubleUU

    Joined:
    Dec 29, 2018
    Posts:
    46
    I'm just starting with Shader Graph and I'm following a tutorial. I have this sprite:
    upload_2022-4-3_18-23-20.png

    Which I'm using as the _MainTex in a brand new URP shader graph, but it's coming out with a messed up border around it when sampled and I can't figure out why:
    upload_2022-4-3_18-22-11.png

    I've swapped in several other textures with the same result. What am I doing wrong?
     
    Last edited: Apr 4, 2022
  2. DoubleUU

    DoubleUU

    Joined:
    Dec 29, 2018
    Posts:
    46
    Here's another example:
    upload_2022-4-3_18-54-4.png
    upload_2022-4-3_18-53-50.png
     
  3. DoubleUU

    DoubleUU

    Joined:
    Dec 29, 2018
    Posts:
    46
    Any suggestions on how I can troubleshoot this? It's not project specific. I created an empty project and it's doing the same thing. Shader graph is basically impossible for me to use at the moment. This is my first time trying to use it, so that's upsetting.
     
  4. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    You are not doing anything wrong. This texture has additional extruded margin and it does not break anything by default. This is visible because node preview does not take alpha into account and what you see is only RGB, so if you take RGB and multiply it by Alpha you should get your original image. Sometimes you might want to premultiply alpha into texture, but I don't think this is the case if you are new to SG.
     
    VuyX likes this.
  5. DoubleUU

    DoubleUU

    Joined:
    Dec 29, 2018
    Posts:
    46
    Thanks, I think I understand that... But in the tutorial I'm following, it doesn't do that.

    Edit: Although, maybe it wasn't clear, those borders show up in the main window preview and in game view. I was just snipping them from there. It looks the same all the way out.



    I'm trying to recreate that SG but it always has these weird thick borders and they show up in game view. Is that because I need to add a multiply in there somewhere? That tutorial is using an older version before they split up the last node, so I'm sure I'm just doing something dumb.
     
    Last edited: Apr 7, 2022
  6. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,314
    If you take a good look you might notice he has exactly the same types of artifacts in preview of
    Sample Texture 2D
    node (red and brown squares and line next to sword). Nevertheless as you said it's not visible in main preview and the reason for that is you don't provide alpha. In old version there is color Vector4 for RGBA, but in new versions there will be base color Vector3 and alpha separately.
     
  7. VuyX

    VuyX

    Joined:
    Jul 19, 2023
    Posts:
    1
    Thank you very much (even 4 years later). I was looking for such advise for few hours now. It worked perfectly.
     
    BenCloward likes this.