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

Question Could you make this with a shader?

Discussion in 'Shader Graph' started by Fakkau, May 8, 2020.

  1. Fakkau

    Fakkau

    Joined:
    Mar 11, 2013
    Posts:
    22
    So imagine a stereotypical stealth game where the enemies have vision cones projected on the floor, like so:

    visionCone.png
    Top down view of a vision cone being rendered on the floor, taking obstacles into account

    I currently have a system that uses A LOT of raycasts to detect what shape the cone should be and then transforms a mesh to take on that shape. However, I was wondering if it's possible to do this with a shader. It would most likely be better for performance, as I currently see a slight dip in FPS if I have too many of these cones in my scene at the same time.

    Regardless of whether you know how to do this (that would be great!), could someone tell me whether they think it's even possible in the first place? (Preferably with Shader Graph,but I'd settle for a coded shader. :) ) The main thing I'm unsure about is whether it's possible to make obstacles cut into the cone. Couldn't find anything on Google

    Thanks!
     
  2. Fakkau

    Fakkau

    Joined:
    Mar 11, 2013
    Posts:
    22
    One last bump; anyone who can make an educated guess on whether this effect is even possible with a shader?
     
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,996
    Fakkau likes this.
  4. Fakkau

    Fakkau

    Joined:
    Mar 11, 2013
    Posts:
    22
    Hey thanks! I'll give those links a read, looks very promising!
     
  5. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    In addition to that distance field/raymarching technique, you could use polar to rect coordinate conversion, then do the pixel-level lighting/fading etc. there. There's a few articles out there and discussions on some forums. But that technique requires a few passes etc. so it's not probably possible (at least without customization) with shader graph.
     
    Last edited: May 15, 2020