Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to achieve point hit shader effect

Discussion in 'Shaders' started by eitanbariboa, Sep 27, 2022.

  1. eitanbariboa

    eitanbariboa

    Joined:
    Mar 19, 2020
    Posts:
    26
    Hello i've been trying to achieve
    The same as in this video





    I am trying to ripple between to colors so i got into this shader graph. it starts from the middle of the time and doesn't work correctly and it doesn't ripple right between two colors.

    Screenshot 2022-09-27 195917.png
     
  2. kruskal21

    kruskal21

    Joined:
    May 17, 2022
    Posts:
    68
    I've whipped up a basic ripple effect shader for you. Attached is a screenshot and a package containing the shader.
    RippleShaderGraph.png

    The basic logic of this effect is this:
    1. Take time, speed, and ripple size, and use this to calculate the min and max distance from the start point for the ripple to show.
    2. Is the distance between min and max calculated in step 1? If yes, show ripple color, if not, show base color.

    There are a couple things you can do to modify the shader further, such as using smoothstep to blend between the colors. But I will leave that up to you.
     

    Attached Files:

  3. eitanbariboa

    eitanbariboa

    Joined:
    Mar 19, 2020
    Posts:
    26
    It works, Thanks just one problem is when you click on the center any side. it will work on all sides as a wave but only on the opposite side it will recreate it.

    The second issue is if you click two times on the mesh it will reset
     

    Attached Files:

    Last edited: Sep 28, 2022
  4. kruskal21

    kruskal21

    Joined:
    May 17, 2022
    Posts:
    68
    The "recreation" of the ripple on the opposite side is because the way distance is calculated. The effect area of the ripple is essentially an expanding sphere from a point. If this point is on the centre of one of cube's sides, then the centre of the opposite side will get covered by the sphere first, before its corners. This limitation is far less obvious for more complex meshes that have fewer completely flat surfaces.

    If you want to "fix" this, I think you could potentially do something like calculating custom distance coordinates that follow the surface of the mesh. Though I need to think about exactly how to do that...

    About supporting more that one ripple, I can think of three options:
    1. The simplest, which is to create more copies of the _RippleStartPoint property - like _RippleStartPoint1, _RippleStartPoint2, _RippleStartPoint3... etc., calculate the min and max distance for each of these points, and show ripple color if distance is between any of these ranges.

    2. Create small 2D texture that stores ripple start point coordinates as colors, and access this information by sampling this texture in the shader. This is basically the same as 1, but will allow you to have an arbitary amount of start points if you write a for loop in a Custom Function in shader graph.

    3. Create an array of vectors that stores ripple start point coordinates. Shader graph currently doesn't support arrays, so much of your shader will have to be written in HLSL.

    Hope that helps. Let me know if you want more help in implementing this in shader graph.
     
    eitanbariboa likes this.