Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

RTS range rings on map

Discussion in 'General Graphics' started by wjessup123, Dec 27, 2015.

  1. wjessup123

    wjessup123

    Joined:
    Dec 27, 2015
    Posts:
    5
    Hello, I'm trying to make an effect like supreme commander where selection of a unit shows range rings that follow terrain height and overlapping ranges are not shown.

    For example: https://i.ytimg.com/vi/8rPQzr11tcI/maxresdefault.jpg

    I've been googling this for a few hours and haven't found a good solution - I don't think a projector is right because the rings become pixelated.

    My game also has the strategic zoom so you can zoom out pretty far and the lines drawn should still be sharp.

    Any help would be great!
    Thanks.
     
  2. wjessup123

    wjessup123

    Joined:
    Dec 27, 2015
    Posts:
    5
    I also went back to supreme commander to check out how it works - and the range rings follow the terrain exactly. It follows all the elevation changes in an area no matter how small they are, so it's not just putting a fixed number of lines in a circle.
     
  3. AkiraWong89

    AkiraWong89

    Joined:
    Oct 30, 2015
    Posts:
    662
    I wanna to know too. Would be some masking shader technique I think.
    The hidden floor effect started since 4:20 solved too if your case is solved.
    I think they are similar technique?:p
     
  4. wjessup123

    wjessup123

    Joined:
    Dec 27, 2015
    Posts:
    5
    I'm working on a shader and got this going:

    It works fine for a cube that i've squished flat and tall. it follows whatever outline of any objects terrain, etc.
    And I even got the circular version going with a cutout in the middle:

    The middle is another cylendar that has a shader that just cuts it out of the previous object.

    But its not perfect, the BACK of the cylendar remains transparent no matter what I'm doing so far. I changed the colors around and offset the inner cylendar for clarity:

    If anyone knows a bit more about shaders please ping me!
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    The way it was done in Supreme Commander was 2d distance fields, one texture for each range, at a relatively low resolution. You render circles with a consistent falloff with a max blend mode. I'm not sure if they render the terrain again for each ring pass or as one "super shader".

    For Planetary Annihilation we did something similar but we did it in screen space and projected rings onto the depth map as a full screen post process rather than rerendering the geometry. If you're using the deferred rendering path or real time directional shadows it should be possible to do.
     
  6. kokichi88

    kokichi88

    Joined:
    Mar 3, 2014
    Posts:
    13
    I think it can achieve by using stencil buffer.
     
  7. wjessup123

    wjessup123

    Joined:
    Dec 27, 2015
    Posts:
    5
    Yea, my stencil buffer was wrong. I didn't understand how the colorbuffer worked and that you can do the stencilOps without writing pixels.

    Anyway once I understood it the solution came together quickly. Here's a couple range low poly range rings just for example:




    What's nice is they follow the terrain perfectly. But its still not perfect, rotating the camera beyond certain degree's makes everything blow up:



    I've tried changing the Queue tag but nothing seems to work. Any ideas why changing the camera direction changes everything?

    I'm attaching the shaders below. To use this just have two shapes you want to draw on the ground - a larger outer one and a smaller inner one. For example:



    Use this shader on the inner shape:

    Code (CSharp):
    1. Shader "Custom/NODRAW-stencil-minus-one" {
    2.     Properties {
    3.     }
    4.     SubShader {
    5.           Lighting Off
    6.  
    7.         //FRONT
    8.         Pass {
    9.             Tags {"Queue"="Transparent-100"}
    10.             Stencil {
    11.                 Ref 1
    12.                 Comp always
    13.                 Pass replace
    14.             }
    15.             Zwrite Off
    16.             ColorMask 0
    17.         }
    18.  
    19.         //BACK PIXELS ONLY
    20.         Pass {
    21.             Tags {"Queue"="Transparent-100"}
    22.             Stencil {
    23.                 Ref 1
    24.                 Comp always
    25.                 Pass incrWrap
    26.             }
    27.  
    28.             Zwrite Off
    29.             Cull Front
    30.             ColorMask 0
    31.         }
    32.     }
    33. }
    34.  

    And this shader on the outer shape:
    Code (CSharp):
    1. Shader "Custom/reveal backfaces" {
    2.     Properties {
    3.     }
    4.  
    5.     SubShader {
    6.         Lighting Off
    7.  
    8.         //BACK PIXELS ONLY
    9.         Pass {
    10.             Tags {"Queue"="Transparent"}
    11.             Stencil {
    12.                 Ref 1
    13.                 Comp always
    14.                 Pass replace
    15.             }
    16.             Zwrite Off
    17.             Cull Front
    18.             ColorMask 0
    19.         }
    20.  
    21.         //FRONT
    22.         Pass {
    23.             Tags {"Queue"="Transparent"}
    24.             Stencil {
    25.                 Ref 1
    26.                 Comp notequal
    27.                 Pass replace
    28.             }
    29.             Zwrite Off
    30.             Color (1,1,0,1)
    31.         }
    32.     }
    33. }
    34.  
    Again, any help on why this doesn't work at all camera angles would be great.