Search Unity

How is an overlay effect done

Discussion in 'Shaders' started by Farol, May 23, 2020.

  1. Farol

    Farol

    Joined:
    Mar 9, 2017
    Posts:
    16
    I am interested in drawing the radius of the unit on top of the terrain (blue and green lines). How to make such an effect, I mean it is done using shaders or something else? I can’t find the information, I don’t even know what it is called.
     
  2. FlyingOreos

    FlyingOreos

    Joined:
    Mar 24, 2014
    Posts:
    12
    Multiple ways off the top of my head:
    - Have it built into your terrain shader, with a global position and color for each circle, as well as a texture for it. Sample the circle texture with the world XZ position, relative to each circle center (Maybe triplanar mapping will look a bit better, look it up).
    - Projectors: https://docs.unity3d.com/Manual/class-Projector.html (Although this requires the objects that it hits to render again, so might be performance unfriendly)
    - As simply quads on top of the world with a separate shader, but like the first method. Instead it samples the depth texture and convert that to a world space position, and then sample the circle texture based on world XZ.
     
  3. Pangamini

    Pangamini

    Joined:
    Aug 8, 2012
    Posts:
    54
    I usually write a custom projector that takes the screenspace depth and use that to project textures on complex geometry that I don't want to render twice (or many times possibly). The downside here is that your depth buffer contains other things than your terrain (so lines would get projected on buildings as well) and I have yet to find a way how to end up with a depth buffer that only contains the terrain (without rendering the terrain twice). You could also use stencil for masking, provided that all your opaque shaders write to stencil...