[FREE] GPU Line of Sight / Field of View

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.

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!

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.

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.

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:

1725450--108816--LOS-360-example.jpg

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

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!

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

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 =)

Different colors will be available in this update :wink:

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

Yes that helps. Thank you. I appreciate you being honest about it :slight_smile:

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:

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

Version 1.1 is now live on the Asset Store!

I’m also in need of mobile support. I will purchase this over the weekend and take a look.

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

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?

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?

Bump?

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.

Hi there!
It´s worth taking a look at LOSCuller script for that.
Cheers