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

Evenly distributed circles in expanding ring

Discussion in 'Shaders' started by SUBZERO8K, Jun 30, 2015.

  1. SUBZERO8K

    SUBZERO8K

    Joined:
    Jan 15, 2013
    Posts:
    36
    Hi there,

    I was originally attempting to do this with the Shuriken particle system, but it seems you can not guarantee to emit a single particle from each vertex per shot. I am now wondering if a shader would be the correct approach.



    I am trying to create an expanding ring effect (that would appear on the ground beneath a player in the center (as a sort of means of highlighting the player). It would shoot a ring that expands until its opacity is 0 and thus disappears from view. I need each circle in this ring to be spaced evenly. How would this be done with a shader, or is there a better way to tackle this problem?

    Thanks!
     
  2. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Have you considered a (flat) circular mesh? Just scale that up?
    One mesh per ring, problem would be the scaling of the dots.
    And in your image it seems to add dots the further out it goes to keep the distance between dots the same?
     
  3. SUBZERO8K

    SUBZERO8K

    Joined:
    Jan 15, 2013
    Posts:
    36
    Yeah sorry, it doesn't need to add dots as it goes further out. I just want their scale to remain the same with an even distance between them.
     
  4. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    A shader would work, and I think I have an idea that will hopefully solve your problem.
    Keeping the size of them is the tricky part, as simple scaling would break that.
    However a single mesh, (for all rings!) I think would work.
    You use the UV of it to determine where in the square you are, (evenly distrubuted 0-1 UV on a sqaure, say unity's).
    Then you calculate the position of the pixel relative to the center, (not hard at all), and based on a modulo time you decide on if you should sample the "dot" texture, and at what UV. (The dot texture only needs to contain a single dot!)
    Using the angle to the middle to keep track of the dot.
    As for the fading out further away, that can be done simply by distance to center.

    A different perhaps simpler, perhaps harder approach is to use scaling and signed distance fields. (Or unsigned should work for you), and counter the scale when drawing.
     
    SUBZERO8K likes this.
  5. SUBZERO8K

    SUBZERO8K

    Joined:
    Jan 15, 2013
    Posts:
    36
    Thank you, I will give this a try.