Search Unity

Question Fragment Shader Alpha gradient looks pixelated

Discussion in 'Shaders' started by slushieboy99, Apr 14, 2022.

  1. slushieboy99

    slushieboy99

    Joined:
    Aug 29, 2014
    Posts:
    88
    Hi all,
    I'm trying to make my first fragment shader which I want to highlight sharp edges of my model. I have done this by assigning an alpha value to every vertex in the uv channel based on how sharp that vertex is. However, in my fragment shader this looks very unsmooth as seen in the picture. I'm currently just assigning my alpha values to the alpha channel of my shaders color in the fragment portion of the shader. Is there a better way to do this which will make it smoother?
    Thanks! jags.png
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    You're seeing the results of barycentric interpolation. The short version is no, there's no way to make that smoother, because you're interpolating the vertices of each triangle, and when you do that you'll start up see that triangular structure.

    The "solution" is to not use vertex data. Instead use a texture to store the data, as bilinear interpolation isn't quite as obvious. You'll need unique UVs for the entire mesh, and for special care in hiding seams, but that's the "best" option.
     
    slushieboy99 likes this.
  3. slushieboy99

    slushieboy99

    Joined:
    Aug 29, 2014
    Posts:
    88
    Do you have any suggestions on how to start going about this? Would this be done in a pixel shader or would I have to use something like Texture2D.SetPixel with my own biliniear interpolation algorithm?