Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Line Of Sight / Field of View

Discussion in 'Works In Progress' started by Arac, Feb 9, 2014.

  1. Arac

    Arac

    Joined:
    Feb 9, 2014
    Posts:
    12
    EDIT: Because this system is now available in the Asset Store, I have created a new thread in the Asset Store forum: http://forum.unity3d.com/threads/released-gpu-line-of-sight.257324/

    $LOS.jpg

    As a challenge I started working on a 3D line of sight / field of view system.

    It relies mostly on the GPU and uses a technique very similar to (deferred) shadow mapping in addition to some custom post processing effects, shaders and scripts. It's a lot faster than most other techniques which are CPU intensive and use dynamic meshes and raycasting to determine which area is in view.

    This system works in both deferred and forward rendering, supports an unlimited amount of sources (technically atleast) and allows you to easily change and control the image effects applied to the area outside of the line of sight.

    Things I still want to add are support for othographic projection and culling of the line of sight sources when they're off screen.

    Webplayer version: https://dl.dropboxusercontent.com/u/12467343/LOS/index.html

    Controls:
    • Move with arrows or wasd
    • Look by orbiting mouse around character
    • Place a camera with LMB

    Let me know what you think!
     
    Last edited: Jul 21, 2014
  2. softwizz

    softwizz

    Joined:
    Mar 12, 2011
    Posts:
    793
    Looks interesting as an alternative.
    The method I use at the moment uses dynamic meshes and raycasting so I will watch how this develops.
     
  3. SEG.Veenstra

    SEG.Veenstra

    Joined:
    Sep 3, 2010
    Posts:
    324
    Looks pretty interresting! good luck!
     
  4. Arac

    Arac

    Joined:
    Feb 9, 2014
    Posts:
    12
    $LOS2.jpg

    Thx for the feedback guys!

    Did a small update:
    • Added a fall-off to the view cone
    • Blurred the mask for softer edges
    • Fixed some deferred rendering issues
    • Tweaked the image effects applied to the none visible area
    You can try the changes here: Webplayer
     
  5. SEG.Veenstra

    SEG.Veenstra

    Joined:
    Sep 3, 2010
    Posts:
    324
    Tried the webplayer. Think it's just amazing, a while ago I was thinking about how to create FoV or FoW. I really like it!
     
  6. Katalyst

    Katalyst

    Joined:
    Nov 19, 2012
    Posts:
    16
    I've actually been working on a top-down shooter the last couple months and we were just starting to implement a vision system for when it gets dark and this is simply amazing and perfect! I spammed like 100 cameras on there and performance seemed solid as well. Any idea if/when you'll be releasing this to the public for use?
     
  7. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,729
    I like it. If you can make some fairly good optimisations and explain the process and put it up as an asset I'd probably buy it just to play around sometime when I get time! Does it absolutely require colliders?
     
  8. Arac

    Arac

    Joined:
    Feb 9, 2014
    Posts:
    12
    Glad you guys like it :)

    I wasn't planning on releasing this, it started out more as a personal project. But if there's enough interest, I might consider putting it out there.

    It doesn't require any colliders, just meshes.
     
  9. SiegfriedCroes

    SiegfriedCroes

    Joined:
    Oct 19, 2013
    Posts:
    565
    Really cool effect :D Especially with the softer edges in the new version ;) I might not have any use for it myself but I do think it's a good idea to release it in the Asset Store :)
     
  10. Adrianis

    Adrianis

    Joined:
    Apr 20, 2013
    Posts:
    109
    That's looks really impressive Arac, nice work!

    If you do decide to release it, I'm definitely interested
     
  11. Arac

    Arac

    Joined:
    Feb 9, 2014
    Posts:
    12
    Made a small update to the webplayer

    In this update I focused mostly on optimization, for example making sure that (line of sight) cameras which are of screen aren't rendered, and some profiling.
    I've also added basics NPC's which move around the map randomly and fade in and out of the visible area.

    I'm considering turning this into a small stealth game, if I can design some nice gameplay mechanics for this type of game.
     
  12. Ekibyou

    Ekibyou

    Joined:
    Feb 19, 2014
    Posts:
    10
    I'd love to see how you did this as well :).
     
  13. Arac

    Arac

    Joined:
    Feb 9, 2014
    Posts:
    12
    Here's a quick explanation of how the main effect works:

    • Use a custom image effect to store the back buffer after the scene has finished rendering
    • Apply all Image effects to main camera
    Then in a loop for each LOS ( line of sight ) camera:
    • Render scene again from this camera's position using a linear depth replacement shader to a render texture
    • Each camera reuses the same render texture to keep memory usage constant regardless of number of LOS camera's
    • Run another custom image effect which for each pixel reconstructs the world position using the main camera's depth texture and compares the distance from the LOS camera to the depth / distance stored in the depth texture we just rendered (very similar approach as shadow mapping) and creates a mask.
    After all the cameras have been added to the mask:
    • Blur this mask using image effects (optional)
    • Use this mask to blend the original back buffer we stored before with the result of all the image effects applied.
     
  14. Ethaninja

    Ethaninja

    Joined:
    Jan 7, 2013
    Posts:
    276
    Looks pretty great! Except perhaps instead of a straight edged cone, have it slightly blurry to simulate peripheral vision, so the further back things get the blurrier they get until blackness, rather then just a straight BAM. And perhaps the further into the blurriness the less likely detection.
     
  15. thienhaflash

    thienhaflash

    Joined:
    Jun 16, 2012
    Posts:
    509
    Very cool indeed ! And looks like it's very fast, too
     
  16. Yanneyanen

    Yanneyanen

    Joined:
    Jan 18, 2012
    Posts:
    55
    This looks really good. Yeah, more blur on the edges or farther in the distance could be nice depending on what kind of look you're trying to achieve, but seems pretty solid to me :)
     
  17. jason-fisher

    jason-fisher

    Joined:
    Mar 19, 2014
    Posts:
    133
    Very cool! Would love to play around with this.
     
  18. hmiao

    hmiao

    Joined:
    Jan 20, 2014
    Posts:
    2
    I'd be interested too. I don't see any other tool on the asset store that's as well implemented as yours.
     
    Last edited: Apr 2, 2014
  19. CaptainKiyaku

    CaptainKiyaku

    Joined:
    Feb 8, 2009
    Posts:
    324
    I would love to get a copy of this :)
     
  20. ZFarago

    ZFarago

    Joined:
    Aug 13, 2012
    Posts:
    150
    Impressive work, and nice demo! Very fast and the fog-of-war effect looks cool!
     
  21. Dubious-Drewski

    Dubious-Drewski

    Joined:
    Aug 19, 2012
    Posts:
    51
    This effect is fantastic! I also really love your fog of war blur effect - it reminds me of the visuals in the spider lair section of Metro: Last Light - it looks fantastic! Damn, what will it take for me to have this kind of understanding of shaders?!
     
  22. Arac

    Arac

    Joined:
    Feb 9, 2014
    Posts:
    12
    Thanks everyone for the feedback, glad people are digging it.

    I haven't had a lot of time recently to work on this, but I want to eventually finish this and make it available. The system is fully functional now, but I still need to clean-up my code, write documentation and create some example scenes.
     
  23. c-Row

    c-Row

    Joined:
    Nov 10, 2009
    Posts:
    799
    Would your system work from another viewing angle than top down, say, a more Diablo-like setup but still be limited to only what the controlled character can see?

    Hope this will be available soon. :)
     
  24. Arac

    Arac

    Joined:
    Feb 9, 2014
    Posts:
    12
    Yes, this would work from any angle (with both perspective and orthographic cameras).
     
  25. Arac

    Arac

    Joined:
    Feb 9, 2014
    Posts:
    12
    I'm close to finishing this system and am now preparing it for release on the asset store. I hope to have everything done in 2 weeks.

    Before I release it, I would like some people to test it and help me find potential problems or things missing in the documentation. So if anyone is interested in being a beta tester (you'll need the PRO version of Unity), feel free to send me a PM!
     
    Last edited: Jun 25, 2014
  26. Johny100

    Johny100

    Joined:
    Sep 16, 2013
    Posts:
    5
    Looking forward to the release!:)
     
  27. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,699
    Cool. Ahh render textures :D
     
  28. Arac

    Arac

    Joined:
    Feb 9, 2014
    Posts:
    12
  29. Arac

    Arac

    Joined:
    Feb 9, 2014
    Posts:
    12
    My line of sight system has been approved and is now available in the Asset Store!
     
    Last edited: Jul 21, 2014
  30. byunghwl

    byunghwl

    Joined:
    Jun 13, 2018
    Posts:
    3

    Hi Tycho, It is a really great plug-in and I purchased your plugin. I tried to use your website QA form for my question but it seems not working.

    I am trying to implement a feature like Shadow tactics view cone.

    Can you guide me how to make a mutliple layer viewcone like a picture above?
    I am not sure my current implementation is in a right direction to implement this. Currently, I spawned two LOS Source objects and a cube which has LOS stencil renderer. I set the first LOS camera without any culling flag and the other LOS camera has the box layer culling flag. So it seems like making similar effect but I am not sure about this.
    upload_2018-6-12_23-18-36.png

    In addition to this, Is there way to apply texture like that within the viewcone?

    Best,
     
unityunity