Search Unity

Question Distortion Shader bug

Discussion in 'Shaders' started by If_Jay, Jan 21, 2022.

  1. If_Jay

    If_Jay

    Joined:
    Nov 4, 2020
    Posts:
    2
    Hi, im trying to make a distortion effect like

    But i have these problems at the edge of the screen.
    I attached also the shader graph and the properties
     

    Attached Files:

  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Yep, that's unavoidable. There's a reason that tutorial video never shows the distortion object close to the edge of the screen, because the same issue would be visible.

    You're taking the image that's already been rendered and distorting it. If you distort the image so that you're trying to "see" something that's not already on screen, you'll see what you're seeing as there's nothing in the render texture you're sampling from beyond what was already visible. Unity defaults the opaque texture used by the Scene Color node to use the Clamp wrap mode which repeats the edge color outside of the 0.0 to 1.0 range of the UVs.

    The possible "solutions" are:
    1. Do nothing and live with the weird stretched image near the edges.
    2. Use less distortion so the artifact is less obvious.
    3. Scale down the distortion when close to the edge of the screen.
    4. Scale the Screen UVs before modifying them so it's zoomed in by the max distortion amount.
     
    Ruchir and If_Jay like this.
  3. If_Jay

    If_Jay

    Joined:
    Nov 4, 2020
    Posts:
    2
    Solution 4 worked for me, Thanks
     
  4. HamCha87

    HamCha87

    Joined:
    Jan 4, 2019
    Posts:
    7
    For those who find this in the future, this is the aforementioned solution inside the shader graph editor (where UvScale is a vector2' Its values range between 0 - 1; 0.95 is like the value you want)
     

    Attached Files:

    Last edited: Sep 16, 2022
  5. PowerTower-Studios

    PowerTower-Studios

    Joined:
    Nov 17, 2017
    Posts:
    1
    Hello where do I place the values.. Is it in the node setting => default