Search Unity

Question How to correctly implement distortion

Discussion in 'Shaders' started by Qriva, Nov 15, 2022.

  1. Qriva

    Qriva

    Joined:
    Jun 30, 2019
    Posts:
    1,307
    Hello, I try to implement simple distortion (like heat or shockwave) in URP, but there are two things I am struggling with:

    1. I want distortion to keep strength over distance - currently when it's far it gets stronger and stronger. I tried to multiply offset by distance to camera or depth difference, but it does not look like this works. What is the correct way to handle it?

    2. I use distortion offset on both X and Y at the same time
    screenUV.xy += distortion.xy * amount;
    and this works correctly for any angle and rotations, however I wanted to implement distortion based on normal map, but it works only when quad is aligned to camera plane, in other case the distortion is "twisted" and it's caused by ty the fact that vector is in tangent space. My question is: can this be fixed to make it work always, even if quad is rotated or it's supposed to work only when it's aligned correctly?
    Or rather, I guess it's mathematically possible, but is it worth it and good practice?