Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  3. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

[RELEASED] GPU Line of Sight / Field of View

Discussion in 'Assets and Asset Store' started by Tycho, Jul 16, 2014.

  1. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    The first version of my GPU based line of sight / field of view visualization is now available on the Asset Store!

    Screen06.jpg
    Screen01.jpg
    Screen02.jpg
    Screen03.jpg

    A line of sight system visualizes which parts of the game world can be seen from the standpoint of for example a 3rd person in-game character. The area outside of the line of sight is obscured and remains hidden from the player.

    This system was developed as an alternative to CPU based line of sight visualizations. CPU based systems use a combination of ray casting and dynamic meshes to compute the line of sight and are often CPU intensive, causing a serious impact on performance.

    This new GPU based line of sight system uses a technique very similar to shadow mapping and is significantly faster than any CPU based system, freeing up valuable CPU time. It has been designed from the ground up with performance, ease-of-use and customizability in mind. The effect can be tweaked to achieve any desired visual style. The user can control the look of the effect by selecting which image effects are applied to the area outside of the line of sight. It is perfectly suited for top-down stealth or action games, but also works from other viewpoints and in other type of games.

    This system is compatible with both the forward and deferred rendering pipelines and supports DX11. Because this system makes heavy use of render textures, it is currently not supported on mobile platforms.

    Now available on the Asset Store!

    Try out the demo!

    Main Features:
    • Fast: designed with performance in mind, zero allocation during run-time
    • Fully customizable effect: match the style of your project seamlessly
    • Works with both perspective and orthographic cameras
    • Includes scripts to check if objects are inside line of sight
    • Includes full documentation + example scene
    Supports:
    • Forward and deferred rendering pipelines
    • DX11
    Not Supported:
    • Sprite or 2D toolkit based projects
    • Mobile and WebGL platforms
    * Works with Unity 5 Personal Edition
    * Requires Pro license for Unity 4.x
     
    Last edited: Mar 16, 2016
    jpthek9 and AnomalusUndrdog like this.
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,565
    Nice. I wish Unity Free had the render textures. Besides line of sight, which is really a lighting/shadowing thing, do you have other types of lights like point lights etc?
     
  3. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    What do you mean exactly by point lights?

    If you mean a 360 degree line of sight, it's very easy to create using this system.
     
  4. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,565
    Ahh I see, cool.
     
  5. FernandoRibeiro

    FernandoRibeiro

    Joined:
    Sep 23, 2009
    Posts:
    1,362
    Hi there!

    It looks really nice! =) How complex is the process of setting up the scene and FOV´s?
    Is it possible to combine the FOV of different agents together?
    Does your solution handle 3d environments / height variation?

    Thanks in advance :)
     
  6. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Thanks!

    Setting up the scene and getting the system up and running is really easy and should only take a few minutes.

    This system technically allows an unlimited amount of agents / line of sight sources (you can add more agents in the webplayer demo by pressing space bar). Even low spec systems should be able to handle more than 10 agents on the screen at once (my PC can handle a 100+). As an optimization, agents which are off screen are also not rendered.

    Yes, 3D environments with height variations work. It will also work from for example a first person perspective.
     
  7. FernandoRibeiro

    FernandoRibeiro

    Joined:
    Sep 23, 2009
    Posts:
    1,362
    Great top hear that!
    The visual effect is separated from the FOV calculation itself? Would it be possible to access the raw data from the "visible" objects while avoiding any visual output?
    PS: It´s planned to work on skinned meshes as well? :)
    Sorry for the amount of questions!
     
  8. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Yes, the visual effect is separated from the calculations. The system basically let's you chose which image effects to apply to the area that's outside of the line of sight, giving you complete freedom to change the style.

    You could avoid any visual output by simply not adding any image effects. I'm not sure why you would want to do that, but it would work :)

    I'm not sure what you mean by raw data, but this system includes a script component that you can attach to an object to check if it's inside the line of sight. The "NPCs" walking around in the webplayer demo use this script to hide themselves when not inside the line of sight.

    This effect works on skinned meshes work without a problem ;)
     
  9. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Last edited: Jul 21, 2014
  10. JaviElMago

    JaviElMago

    Joined:
    Feb 21, 2014
    Posts:
    2
    This asset looks pretty nice, I've looking for something like this for weeks, my game use a isometric cam not a top down cam, do you think this effect would works for me?
     
  11. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Yes, this effect can work from any perspective, it doesn't require your game to be top down.

    Here's a quick example of this effect being used with an isometric camera and 2 line of sight sources.

    Screen05.jpg
     
  12. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Here's a list of things I want to add in the next version:
    • Add color groups: line of sight cones can be rendered in different colors
    • Add invert mask option: apply effects to area inside of line of sight
    • Improve bias accuracy
    If you guys have any suggestions or feature requests for the next version, be sure to let me know!
     
  13. FernandoRibeiro

    FernandoRibeiro

    Joined:
    Sep 23, 2009
    Posts:
    1,362
    Mobile support would be essential in my case and is what is holding me on buying this.
    I was looking for accessing the raw data so that I can use this for both FOV and LOF without the visual feedback itself.
    Cheers
     
  14. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    I would love to support mobile in the future. I'm pretty sure this version should technically run on mobile, but I'll make a test build for android to make sure. Because this system makes heavy use of render textures, I'm just not sure about its performance on older mobile devices which makes it impractical to support.

    That being said, this system doesn't require render textures, to check if an object is inside the line of sight. So if you don't want any of the visuals, but just need to know if an object is visible, this could definitely run on mobile.
    But this system was primarily designed for the visual effect, so using it just for that might not be the most efficient or practical solution.
     
  15. FernandoRibeiro

    FernandoRibeiro

    Joined:
    Sep 23, 2009
    Posts:
    1,362
    Humm, got it!
    If I manage to get some free time I´ll buy and work on it in the next week! =) Thanks a lot for all the answers.
    Btw, you have an amazing portifolio!
     
  16. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Glad I could help, and thanks for the compliments on my portfolio :)
     
  17. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    After making some changes I've managed to get my line of sight system working on Android, so mobile support will probably be included it in the next update as well!

    I still need to do more testing to see if I can get the performance to an acceptable level on mobile devices, but I'm hopeful.
     
  18. FernandoRibeiro

    FernandoRibeiro

    Joined:
    Sep 23, 2009
    Posts:
    1,362
    Great to hear that! =D
     
  19. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    I rewrote a big part of my system to make it compatible with mobile devices, but it still has some major issues I need to solve. Most of the issues are related to Unity bugs I need to circumvent, so they are rather tricky.
    Because of this I will probably delay mobile support until version 1.2.

    For version 1.1 I'll be adding these features:
    • Ability to render Line of Sight sources in different colors
    • HDR mode (more info soon)
    • Some fixes and optimizations

    I hope to be able to submit version 1.1 this weekend, so ti should be available some time next week!
     
  20. FernandoRibeiro

    FernandoRibeiro

    Joined:
    Sep 23, 2009
    Posts:
    1,362
    Btw, let me ask: Do you need to use a camera for each FOV calculation? In that case does rendering all those extra cameras generate an overhead on render passes / poly count?
    I ´ll buy it this weekend. Great work
     
  21. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Yes, you need a camera for every line of sight source, but this camera only renders a part of the scene using a fast depth only replacement shader.

    So adding an extra line of sight source adds a bit of overhead, but only if the source is visible on screen. You can minimize this overhead by keeping the camera's (attached to the source) far clipping plane as small as possible.
     
  22. FernandoRibeiro

    FernandoRibeiro

    Joined:
    Sep 23, 2009
    Posts:
    1,362
    Hi there! I just bought GPU LoS =)
    This asset is great! I managed to do a fast test integrating it with Manufactura K4 Top-Down Interiors. Here´s my early result:

    In this case I didn´t excluded the furniture from the calculation process, so I´ll have better results later.

    One thing that I still didn´t figured out is that I´m getting some artifacts on walls at the demo scene:
    Edit: Following pdf manual, antialias solved it.


    Great work on this asset! =D I´m eager to see what will be available next.
    Cheers!
     
    Last edited: Aug 6, 2014
  23. FernandoRibeiro

    FernandoRibeiro

    Joined:
    Sep 23, 2009
    Posts:
    1,362
    Hi there!
    I´ve managed to get some interesting results for a 360* FOV using a single camera.

    In this case the camera is over the character and is pointing down. I had to adjust far clipping plane until it reaches this circular volume. As this requires the camera to use a wide FOV, it messes with frustum calculation and raycasts but it´s worth considering this approach for some specific situations. In that case a distance check might handle the false positive.
     
    Last edited: Aug 7, 2014
  24. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,193
    Hi Tycho,

    I'm considering purchasing this asset, but I'm still not sure if it will be useful for my type/genre of game. I'm building a real-time strategy game (think StarCraft 2 or Command and Conquer style) that is "third person" top-down basically.

    All I'm looking for is a fast way to calculate whether or not a ranged unit can see its enemy target without anything blocking its line of attack (such as a building between the unit/agent and it's enemy target or a large hill).

    I need ranged units to be able to detect if they do not have line of sight to their target, and if they don't, then re-path to their enemy target until they do. I also would need to integrate the line of sight checks with my own scripts, so is there a Boolean variable or something that would say "yes this unit has line of sight" that I could then relay to my own script?

    I'm going to have about 150 units for each player max, so each game might have about 300 total units maximum. Of course, not all of them will be on screen at the same time. A typical scenario would be about 40 - 60 units on screen at one time. Would your system still be peformant under these use-cases?

    Thanks for any info.
     
  25. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Glad you like the asset and thanks for the purchase! The screenshot with the manufactura assets looks really promising!

    I've found another solution to the artifact problem you show in your second screenshot, which doesn't require enabling anti-aliasing. If you set the clear flags property of the first camera to depth only, this will also fix the issue without any performance impact. This won't allow you to set a clear color though, but that will probably not be a problem for a top down game.

    The proper way to do a 360 degree line of sight, would be to combine 4 cameras, each with an FOV of 90 degrees. This way the frustum calculations still work correctly, and tweaking the line of sight cone becomes a lot easier! Here's a quick screenshot showing my technique:

    LOS-360-example.jpg

    I'll make sure to include a 360 prefab in the next update (which I'm planning to submit today).
     
  26. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    To be honest, I don't think this system would be very suitable for your needs.

    It does include a script to check if an object is inside the line of sight (which sets a boolean value you can check from other scripts), but it does that for all line of sight sources / agents at the same time. This would make it impractical to check if one unit is inside the line of sight of another unit, and would require quite a few code changes.

    I hope this helps!
     
  27. FernandoRibeiro

    FernandoRibeiro

    Joined:
    Sep 23, 2009
    Posts:
    1,362
    Yep, I first tried using 4 cameras for the 360, but wanted to check if I could have better performance with a single one.
    It will be really useful being able to render Line of Sight sources in different colors =)
    I would recommend including a mask for the raycast, there can be situations where devs have an invisible wall that shouldn´t break LoS check.
    Cheers
     
  28. FernandoRibeiro

    FernandoRibeiro

    Joined:
    Sep 23, 2009
    Posts:
    1,362
    Concerning that subject, do you guys know how Warcraft 3 handled their Fog of war and FOV? It was very efficient. Never found any reference to the technical details of their magic =)
     
  29. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Different colors will be available in this update ;)

    Good point about the raycast mask, I'll check if I can still include it in this update, but if it's too much work it will be for 1.2
     
  30. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,193
    Yes that helps. Thank you. I appreciate you being honest about it :)
     
  31. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    I've submitted version 1.1 and it's now awaiting approval!

    Here's the changelog for version 1.1:
    • Added HDR mode to LOS Mask
    • Added Color Mask property to LOS Source
    • Added Intensity property to LOS Source
    • Added Out of Bound Area property to LOS Source
    • Added Invert Mask option to LOS Source
    • Added Layer Mask property to LOS Culler
    • Added example prefabs
    • Added LOS Layer Excluder script component
    • Simplified setup process for multiple cameras
    • Improved performance
    Here's an image showing the effect of the HDR mask in combination with colored LOS sources:

    HDR-Mask.jpg
     
  32. Aldo

    Aldo

    Joined:
    Aug 10, 2012
    Posts:
    173
    I am planning to buy this asset once it reaches mobile optimization, still I was reading the forum and got an answer for Velo222

    Velo222 just make a mesh collider for your units, if you can have the mesh with less than 100 tris it will be great to handle "OnTriggerStay" collisions ;)
     
  33. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Version 1.1 is now live on the Asset Store!
     
  34. Creepgin

    Creepgin

    Joined:
    Dec 14, 2010
    Posts:
    91
    I'm also in need of mobile support. I will purchase this over the weekend and take a look.
     
  35. Simie

    Simie

    Joined:
    Oct 26, 2012
    Posts:
    346
    Hey Tycho, this looks great! I'm considering using this in a prototype I'm working on, but I have a few questions.

    1) Is this suitable for lighting? I'd like to have dynamic lighting simulated in my game, and this looks perfect if the performance is good enough for 20+ lights at once.

    2) I'd also like to use this for a field-of-view system. Can I layer this effect, once for lighting then again for player FOV?

    Thanks
     
  36. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Hey Simie,

    1: This system works with any kind of lighting ( static / dynamic, forward / deferred ). The amount of lights doesn't influence the performance of the LOS effect, so if it runs smoothly before, it should run fine with this effect enabled.

    2: What do you mean exactly with layering?
     
  37. Simie

    Simie

    Joined:
    Oct 26, 2012
    Posts:
    346
    Hi Tycho,

    I was referring to using this effect as the actual lighting - ie the scene is rendered without any lighting (fullbright) and this effect simulates light sources.

    By layering I meant that after that lighting pass of this effect is applied, can I then apply another pass for player vision?
     
  38. Simie

    Simie

    Joined:
    Oct 26, 2012
    Posts:
    346
    Bump?
     
  39. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,717
    Hey I just picked up this asset is it possible to see if one of the players is actually visible in the LOS? For example I was working on a stealth game and I wanted to be to know if the enemy actually saw the player or not.
     
  40. FernandoRibeiro

    FernandoRibeiro

    Joined:
    Sep 23, 2009
    Posts:
    1,362
    Hi there!
    It´s worth taking a look at LOSCuller script for that.
    Cheers
     
  41. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,282
    Ok I am also interested with this solution but I have few questions.

    It mentions that it doesn't work with sprite or 2dtoolkit. I am guessing here, but I think it is because this tool requires the camera to render a depth map from the source and uses that to calculate / decide if a given pixel is seen or not. This raises few questions.

    1. Is this mean it is technically possible to make it work with 2dtoolkit , if I provide some extra geometry that is only being rendered by the source camera that simulates the depth for the 2d sprites?

    2. If it is actually using the depth map and does extra rendering using camera etc.. how is it different than using normal light source from Unity? Is it differ by performance? I can understand that it may detect the object inside FOV , but as far as underlying systems and performance goes , how does it compare to the other usual Unity rendering system? If I simulate light source by using this system, will it run faster than the Unity deferred lighting system? If so why?

    Thanks advance for your reply!
     
  42. angelodelvecchio

    angelodelvecchio

    Joined:
    Nov 15, 2012
    Posts:
    170
    Hello!

    I would like to implement this kind of solution for a zombie game, instead of raycasts and colliders, is possible to not use the image effects stuff? this solution is aplicable to what i need? its a third person game, i would like to have precise character detection, and this looks great

    Many thanks
     
  43. angelodelvecchio

    angelodelvecchio

    Joined:
    Nov 15, 2012
    Posts:
    170
    I saw other assets like cone visions and somethings like that, but i found out that this one has GPU support,
     
  44. silvadiablo

    silvadiablo

    Joined:
    Feb 11, 2014
    Posts:
    2
    I would like to buy this product, but first i have a question:

    - Can i make it raycast 360 degrees all around the character instead of just making a narrow cone?

    Also, in the isometric image you posted, is the blue cube floating? Cause im making an isometric game and the light seems to be below the cube, it looks wrong, as if the cube is floating.
     
    Last edited: Nov 25, 2014
  45. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Sorry for not replying to any of your questions, but for some reason I stopped getting notifications for this thread :confused:

    Let me catch up by answering all your questions ;)
     
  46. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Yes, it should be possible to mask a dark and light version of your scene using this system to simulate lighting and performance should be faster than using dynamic lights.

    And yes, you can layer this effect.
     
  47. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Yes, your assumptions are correct.

    1: Yes, that would be a possible work around, but might be tricky to set-up.
    2: It is different from normal lighting, since I doesn't affect the lighting on objects, it just creates a mask which you can use to blend 2 different versions of your scene, for example the original one, and one altered using post processing or even rendered from a different camera.
     
  48. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Yes, you're not required to use image effects.
     
  49. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    139
    Yes, this asset includes a prefab which you can use for a 360 field of view.

    And yes the blue cube is floating in that screenshot, and the light is indeed beneath it ;)
     
  50. silvadiablo

    silvadiablo

    Joined:
    Feb 11, 2014
    Posts:
    2
    Can i define a Y height as to where i want the raycast? What i mean is... How does the script choose what is a solid object or not? Does it raycast from the ground up, or just a specific height? A good example could be: what if i have a window at a certain height on the wall, and another at another height. How can i decide what should obstruct the view in this three dimensional case? Or, better yet, if i have a wall thats not too tall and i want it to obstruct the view, as its an isometric game, it might be chopped in half and still block it.

    Also, i would like to know if it comes with that blur effect, along with the black and white. Can i choose just one or another? I dont want the light cones on stuff with line of sight, just the blur and maybe the black/white where they cant see. Cause the objects wont be light sources, ill have another light sources of my own. So they had to not emit any colors/light.

    In your previous answer, is the cube at a greater height from the ground or the light is not matching the exact cube place? Its confusing.

    Could you provide a much more complete DEMO with the options to tweak this kind of stuff and some that others have suggested too?
     
    Last edited: Nov 30, 2014