[FREE] GPU Line of Sight / Field of View

Since I no longer have the time to maintain this asset myself, I’ve decided to open source it and make it available on GitHub!




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 GitHub!

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

2 Likes

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?

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.

Ahh I see, cool.

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 :slight_smile:

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.

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? :slight_smile:
Sorry for the amount of questions!

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 :slight_smile:

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 :wink:

This asset was approved and is now available on the Asset Store!

Full link: www.assetstore.unity3d.com/#/content/19764

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?

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.

1704477--107236--Screen05.jpg

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!

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

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.

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!

Glad I could help, and thanks for the compliments on my portfolio :slight_smile:

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.

Great to hear that! =D

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!

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