Search Unity

2D Distortion Map (explosion / heat wave)

Discussion in '2D' started by Fariel, Jan 14, 2016.

  1. Fariel

    Fariel

    Joined:
    Feb 9, 2013
    Posts:
    29
    Shaders are still 9th level sorcery to me, and I think post processing effects are some kind of wizardry that only the divine can tap in to. That said, I have a goal in mind that I can't seem to reach.
    My end goal is to make an effect that I can pass a set of screen coordinates, speed, length, and size to and it will create a "heat ripple" or "distortion ring" or "refraction ring" in that spot on the screen and react accordingly. Obvious uses are for explosions and anything else that should have a "woosh" effect to it. Oh, and it has to work with sprites AND meshes.

    That last sentence is where I have the issue - deconstructing the "Detonator Explosion Framework" I've managed to figure out the basics of how to get the ripple effect, but the shader is still sorcery to me.

    So my question is in two parts - the first, which I can probably find elsewhere but would be easier to understand if I had someone actually walk me through it, is how does this distortion actually work? I know that it uses a map/mask/whatever to decide how to distort it, but I don't know HOW it actually distorts it.
    The second, and important question, how do I make distortion affect sprites?

    And, as a bonus question, is there any way to do this via a camera shader INSTEAD of doing it by instantiating a plane in front of the area that needs to be distorted?

    distortion1.png distortion2.png

    In picture 1, you'll see that there is a distinct distortion on the edge of the plane, and a sprite to the left.
    In picture 2, I've rotated the camera so that the distortion covers the sprite, and it isn't rendered. In fact, it doesn't render any sprites - only meshes.
     
  2. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    Do you have any progress on this? I'm trying to do this effect for some time now without success.
     
  3. vetasoft

    vetasoft

    Joined:
    Nov 15, 2013
    Posts:
    432
    sevensails likes this.
  4. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    Thanks @vetasoft ! Bought it, let's test! =)
     
    vetasoft likes this.
  5. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    @vetasoft It's almost perfect. But the effect grows until it fits the whole screen, it would possible to kills it earlier?
     
  6. vetasoft

    vetasoft

    Joined:
    Nov 15, 2013
    Posts:
    432
    @sevensails: not really it use the whole screen, you can change the size of the distortion.

    However, we plan a new updated and it's a great suggestion. We doesn't think about that.
     
  7. vetasoft

    vetasoft

    Joined:
    Nov 15, 2013
    Posts:
    432
    @sevensails : try this

    on the CameraPlay_DropWater.cs:

    at line 59:

    remplace this

    Code (CSharp):
    1. material.SetFloat("_Value4", Size);
    with this:

    Code (CSharp):
    1.  material.SetFloat("_Value4", Mathf.Lerp(Size, 0, Mathf.Min((Timer*0.66f)*4,1)));
    2.  
     
  8. felipenunesfob

    felipenunesfob

    Joined:
    Feb 28, 2019
    Posts:
    3
    Hi this works with the URP?
     
  9. vetasoft

    vetasoft

    Joined:
    Nov 15, 2013
    Posts:
    432
    Hi,

    Unfortunatly no, it's work for Standard only.
     
    felipenunesfob likes this.