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
  4. Dismiss Notice

Making borderline with Shader

Discussion in 'Shaders' started by drunk3n_p1nky, Feb 17, 2022.

  1. drunk3n_p1nky

    drunk3n_p1nky

    Joined:
    May 20, 2021
    Posts:
    11
    Hello! I'm sort of new to shaders in general. But exploring them for a bit gave me a thought that they are exactly what I need. My project is turn-based strategy. Let's say I have a soldier. By pressing on the unit I would like to show where it can go for one turn. Right now I have this borderline as LineRenderer object. But it's not a perfect solution as it doesn't lie on surface ideally. So, I have a bunch of world positions of points to connect in one line. Is there a way how I can draw a line within these vector3 positions on the surface of terrain with help of a shader? As a reference I would like it to look similar to Total War Rome 2 highlighting system. But just line would be also perfect. Any thought provoking info is very much appreciated! изображение_2022-02-17_154641.png
     
  2. comettailz

    comettailz

    Joined:
    Feb 1, 2022
    Posts:
    14
    If you have a list of points for the areas border, you could use them to generate a strip of quads (for example, using LineRenderer, or with your own script for lofting a strip of quads along a spline)

    Another idea, for a shader-focused approach, assuming you have a mesh corresponding to the highlighted area - is to transform/deform it slightly so it hovers a bit above the terrain - with the borders intersecting the terrain.
    Using a depth-based shader, you could highlight the intersection points.
    This shader would be similar to a force field, or water fog shader:
    • You will first render the terrain into the depth buffer.
    • When drawing the effect's mesh, you will be reading the terrain's depth value - and compare to the effect's - in order to drive the highlight.
     
  3. drunk3n_p1nky

    drunk3n_p1nky

    Joined:
    May 20, 2021
    Posts:
    11
    Thank you very much for your reply and your time! So, basically for doing such stuff I need to have some mesh object (like plane), change height of its vertices according to terrain heights and add some additional float value to y axis to make it hover the terrain and then do the precedure which you've described?
    But there's no way how I can repaint curtain arrea (which looks like some polygon) of terrain itself without creating mesh object? I'm looking forward to optimising the project in general. I thought shader is the only way for me.