Search Unity

[FREE] GPU Line of Sight / Field of View

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

  1. f3mt0

    f3mt0

    Joined:
    Jun 12, 2014
    Posts:
    4
    Hello Tycho,

    I've been asking about that some time ago, but I guess you were busy. I bought the asset to find out how you have achieved the effect as in the demo: https://dl.dropboxusercontent.com/u/12467343/LOS/index.html

    Unfortunately asset does not contain code for this.

    Would it be possible for you to share the code for the effect from your demo?

    Thanks!
     
  2. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Hi,

    Are you talking about the image effects applied to the area outside of the line of sight in that demo?

    That was achieved using a combination of the included desaturate image effect and unity's standard depth of field image effect.
     
  3. soxroxr

    soxroxr

    Joined:
    Jul 17, 2012
    Posts:
    60
    Is it complicated to detect if something is in the line of sight? I read that it can't detect what is in the line of sight, but that's easy enough to deal with.
     
  4. Riscvul

    Riscvul

    Joined:
    Dec 18, 2012
    Posts:
    5
    Hello Tycho,

    I'm having an issue with the plugin that I can't figure out. I'm planning on having several LOS Source objects in my scene, but when they overlap they have an additive effect making a really bright area.



    Something similar was brought up on this thread earlier and it was suggested that turning off HDR would solve the problem, however it seems HDR is off by default and none of my source objects have HDR on.

    Do you have any suggestions on how I can fix this?

    Also how well does it scale? As in how many Source objects could I reasonably support?
     
  5. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    There is a script included to check if objects are inside the line of sight. You can use this script as a starting point to build a more complex system if needed.
     
  6. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    You need to turn of the HDR mask option on the LOSMask component (attached to the main camera). Turning off HDR on the camera component attached to the LOSSources isn't going to affect the line of sight rendering.
     
  7. Riscvul

    Riscvul

    Joined:
    Dec 18, 2012
    Posts:
    5
    I forgot to say thank you. This is exactly what I was doing wrong.
     
    Tycho likes this.
  8. gamedevluuk

    gamedevluuk

    Joined:
    Jun 23, 2014
    Posts:
    12
    Hiya Tycho,

    Lovely asset, just bought it. Any ETA on Unity 5 version?
     
  9. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Hi,

    The Unity 5 version has been available for some time.
     
  10. ironbelly

    ironbelly

    Joined:
    Dec 26, 2011
    Posts:
    597
    Make a mobile version and take my money already!
     
  11. Funder75

    Funder75

    Joined:
    Jan 24, 2012
    Posts:
    7
    Before I buy this I want to make sure this runs properly on Mac computers. The demo scene that is referred to on the AssetStore does not work as some have already pointed out, but this demo seems to work just fine:
    https://dl.dropboxusercontent.com/u/12467343/LOS/index.html

    In the description it says it supports DX11 - could it be some DX specific feature that causes the weird visual behaviour?

    Also, is source code included?

    Really hope this is working on OSX as it seems perfect for the project I'm working on.
     
  12. HopelessSoldier

    HopelessSoldier

    Joined:
    Jul 23, 2014
    Posts:
    1
    Does your GPU Line of Sight / Field of View asset work with the personal version of unity 5 since unity 5 now gives access to render-to-texture and full-screen post-process effects?
     
  13. hwills

    hwills

    Joined:
    Feb 28, 2015
    Posts:
    11
    Hi, I'm having a similar issue as I think has been reported before for Macs, but just wanted to add that the 360 High Precision and Basic LOS prefab work fine, it's only the 360 Fast prefab (with the LOS Source Cube script) that does not. Unfortunately, this is the reason I bought the asset, and was wondering if there would be an update in the future fixing it. If there's not an update, any ideas on how to fix it would be greatly appreciated! Thanks!

    Screen Shot 2015-08-28 at 10.39.24 PM.png
     
  14. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Hi,

    Sorry for the late reply, but I didn't receive any email notifications about new replies to this thread :confused:

    As far is I know, there's only one component which doesn't work on mac at the moment, and that's the LOSSourceCube component which was added in the latest version.

    The LOSSourceCube component provides a faster way to render 360 degrees line of sight, by using cubemaps instead of regular render textures. It doesn't use any DX11 specific stuff, but does use some rendering magic which might not be supported on certain platforms.
    The 360 degrees line of sight can also be achieved without using this component, and a prefab is included to do exactly that (360 LOS Source High Precision), so you have the same functionality as on the windows platform, but it might not be as optimized.

    The full source code is included.

    Hope this helps!
     
  15. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    I have just tested it, and it does work with the Unity 5 personal edition!
     
  16. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    I'll try to look into this issue as soon as possible, but I'm not sure if I'll be able to fix it.
     
  17. Animatronic

    Animatronic

    Joined:
    Aug 31, 2013
    Posts:
    5
    Hey,

    Thanks for the great plugin.

    I am getting the following errors after updating to Unity 5.2:

    1.
    Setting mipmap mode of already created render texture is not supported!
    UnityEngine.RenderTexture:set_useMipMap(Boolean)
    LOS.LOSMask:RenderSourceCubeToMask(LOSSourceCube, RenderTexture&) (at Assets/Line Of Sight/Scripts/LOSMask.cs:240)
    LOS.LOSMask:OnRenderImage(RenderTexture, RenderTexture) (at Assets/Line Of Sight/Scripts/LOSMask.cs:154)

    2.
    Setting dimension of already created render texture is not supported!
    UnityEngine.RenderTexture:set_isCubemap(Boolean)
    LOS.LOSMask:RenderSourceCubeToMask(LOSSourceCube, RenderTexture&) (at Assets/Line Of Sight/Scripts/LOSMask.cs:241)
    LOS.LOSMask:OnRenderImage(RenderTexture, RenderTexture) (at Assets/Line Of Sight/Scripts/LOSMask.cs:154)

    3.
    Render texture must be a cubemap
    UnityEngine.Camera:RenderToCubemap(RenderTexture)
    LOS.LOSMask:RenderSourceCubeToMask(LOSSourceCube, RenderTexture&) (at Assets/Line Of Sight/Scripts/LOSMask.cs:251)
    LOS.LOSMask:OnRenderImage(RenderTexture, RenderTexture) (at Assets/Line Of Sight/Scripts/LOSMask.cs:154)

    Any idea what would be causing these and if these are fixable on your end?

    Thanks!
     
  18. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Hi,

    I haven't tested it with the latest version of Unity, but I'll do it tonight. Which OS are you using?
     
  19. Animatronic

    Animatronic

    Joined:
    Aug 31, 2013
    Posts:
    5
    I'm using Windows 10.
     
    Tycho likes this.
  20. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    I tried importing the latest version of my asset in Unity 5.2 and I'm getting the same errors. It seems to be caused by creating the cube map render texture for the LOSSourceCube component.

    There's an easy temporary fix tho:
    • Open the example scene
    • Delete the LOS Source 360 component attached to the player gameobject
    • Replace it with the 360 LOS Source High Precision prefab (drag the prefab from the Line of sight/prefabs folder onto the player gameobject in the hierachy)
    I'll go through the release notes and see what's changed and hopefully come up with a permanent solution quickly. I'll keep you posted!
     
    Animatronic likes this.
  21. FuzzyShan

    FuzzyShan

    Joined:
    Jul 30, 2012
    Posts:
    182
    mobile and take my money too.
     
  22. ashley

    ashley

    Joined:
    Nov 5, 2011
    Posts:
    84
    Just wondering if there are any plans to make this compatible with 2D at any point? Looks interesting but I'm working on a sprite-based project at the moment.

    Cheers!
     
  23. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    I currently have no plans to support sprite-based projects, because I would basically have to rewrite everything :p
     
    ashley likes this.
  24. ashley

    ashley

    Joined:
    Nov 5, 2011
    Posts:
    84
    Can't argue with that!
     
  25. reky

    reky

    Joined:
    Jan 7, 2014
    Posts:
    5
    Hi Tycho,


    I have been trying to implement a fog of war system that integrates with your line of sight. What I want to do is if there has been no line of sight before then it uses a different effect (aka completely dark) but otherwise uses your in LOS or out of LOS system.

    Last night I was looking inside the Method “RenderSourceToMask” to see if I could try and extract the data you’re using in your process and replicate it into a new render. However I am not having too much luck understanding the significant of the settings that pushes LOS Source specific parameters onto the Mask and in particular what IndexedGraphicsBlitz() is doing versus what Materials.Mask.SetPass() does. Furthermore I have a sneaky suspicion that the render the LOS obtains is for the screen at that point of time and trying to transcode it onto a Mask layer which can extend beyond the screen is going to be tricky.

    Do you have any opinions on the best way to tackle implementation of a FOW System like I want? Or alternatively do you have any plans to extend your plugin to incorporate this as it seems a natural extension of this asset.



    Cheers

    Reky
     
  26. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Hi,

    This is a screen space effect, so you're correct in assuming that the data stored in the mask is limited to what is visible on the screen and changes every frame.
    I'm afraid it would be hard to extract that data in an efficient way and convert it to a format that would be usable for a fog of war system. Even though line of sight and fog of war might seem related (because they sort of share the same purpose), these systems are actually implemented in very different ways. So at the moment I don't have any plans on extending this asset to incorporate FOW.

    IndexedGraphicsBlit is used for rendering an image effect in which I reconstruct world position based on the depth buffer.
    SetPass sets the pass of the shader I want to use for rendering that mask.

    I hope this helps!
     
  27. reky

    reky

    Joined:
    Jan 7, 2014
    Posts:
    5
    Ah that's a shame, however I understand the reasoning. I must say that your code and plugin is very elegantly written and I am using it as pointers for laying out my code. Do you have any plans in the near future to write another plugin for some form of fog of war that could implemented alongside this plugin?

    Reky
     
  28. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Thanks for the nice comments about my code :)

    I currently don't have any plans to create a FOW system, because I think there are already a couple of FOW systems on the asset store.
     
  29. reky

    reky

    Joined:
    Jan 7, 2014
    Posts:
    5
    One feature that I would like to see is an option for fade in on the out of bounds area when you have it set to exclude. Because at the moment when you have edge fade and distance fade, there is no gradient. Let me know if you need a screenshot

    Also in regards to the fog of war, the ones on the market are poor quality and most are out of date. So it should be worth looking into it :)
     
  30. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    A screenshot would be nice :)
     
  31. reky

    reky

    Joined:
    Jan 7, 2014
    Posts:
    5
    Hi here is the screenshots:

    The first one shows the example of out of bound area being set to exclude. Notice how it looks odd without any edge fade.
    Could you possibly add in a new option to the out of bounds setting for it to fade in. Screenshot_1.jpg



    This second screenshot, shows some problems with the edge fade and distance fade screwing up some of the shadows created (look at the grey corridor) without any edge fade or distance fade this does not happen so I know that it is this.

    Screenshot_2.jpg
     
  32. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Could you sent me a screenshot of the second set-up without edge and distance fades enabled?

    I think what you're seeing in the second screenshot is just the overlap between different LOS "shadows", each with a different intensity (caused by the distance fade).

    I'll look into if it's possible to add a fade for the situation in the first screenshot.
     
  33. reky

    reky

    Joined:
    Jan 7, 2014
    Posts:
    5
    Hi there here you go,

    Sorry for the delay in getting back to you
     

    Attached Files:

  34. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    I've submitted version 1.2.3 to the Asset store, and it should be available some time next week.

    It contains the following changes:
    • Added LOS Visibility Info component
    • Improved LOS Culler component accuracy
    • Fixed issues with Unity version 5.3.2f
    • Updated the example scene
     
  35. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Version 1.2.3 has been approved and is now available on the Asset Store!
     
  36. Digi366

    Digi366

    Joined:
    Mar 8, 2016
    Posts:
    1
    I was wondering with the code provided in your asset, if it's possible to detect a player that walks into the Line of Sight to Reset. I'm suuuper new to Unity and coding, so I'm not sure if this allows it or not. Any help would be unbelievably helpfull!
     
  37. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    There's a couple of scripts included that allow you to check if a GameObject is inside a line of sight or not.
    The example scene included with this asset also shows you how to use these scripts.
     
  38. SimStm

    SimStm

    Joined:
    May 24, 2013
    Posts:
    44
    Hi. I have a question. I haven't acquired your asset yet, because I want to know first if he can do what I need.

    Well, I'm thinking about a game (maybe with an ortographic camera like Fallout games) where the player have a flashlight to help him to explore the place and solve puzzles. The place is very dark (mostly), so, as an ortographic game, the player will be allowed to barely see the environment surrounding him, but will not be allowed to see if there are enemies or not out of his vision (the "light range"), only if he eventually point his flashlight or some kind of light in the direction of the enemies.

    Is it "easy" to do something like that with the help of your asset? (Of course, I don't mind if I need to code something extra for your asset to do it, I'm just thinking if I can do this without the need to write my own code for all of this)

    Thanks! :)
     
  39. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Hi,

    Creating a game like you've described would be really easy with my asset. There's a script included that hides objects which are outside the line of sight, which you could also easily make changes to if you need a more complex system.

    You can try out a demo on the asset's website, which showcases this feature. The NPC's (blue sphere's) will become totally invisible once they are completely outside of the line of sight.

    Let me know if you have any more questions ;)
     
  40. Milo_del_mal

    Milo_del_mal

    Joined:
    Jan 27, 2013
    Posts:
    43
    I am considering on buying this... However, I am working on a 2D toolkit based project. It seems weird that you say the project would not work with 2D toolkit, since it uses meshes (technically 3D) and you can assign basically any material you want to your spritesheet (as I have tested with normals and speculars on "2D" sprites).

    My only question, do you think your system is suitable of a sidescroller? If not, Do you think it would be feasible if I try rewrite it to a different axis? I am not a novice by any means, but I think that it would be better in this case, for me, to build upon a proven LOS solution. (I already have a working LOS prototype, but it is not something too fancy)

    That said, thank you for your time.
     
  41. atduskgreg

    atduskgreg

    Joined:
    Sep 29, 2013
    Posts:
    2
    I just bought this asset today, but for some reason the Asset Store is still giving me version 1.2.1 rather than 1.2.3. This is a particular problem for me since I specifically wanted to use the LOSVisibility component. Is there something I can do on my end to download the right version or is this something screwy with the store?
     
  42. wheelbarrow

    wheelbarrow

    Joined:
    Sep 12, 2011
    Posts:
    177
    I bought this asset this morning, and it seems I can't use any particle effects or decals in the LOS without getting artifacts/ weird shadows, which is a shame, since it adds to the appeal of a game if a toon sprays blood when shot, and leaves a blood puddle on the ground when the body disappears - unfortunately, the blood spray casts the weird shadows, and the decal plane shows up under the blood puddle in the LOS. Is there any way around this, or is the zwriteon(?) the only option? Currently using it in Unity Pro 4.6.8.

    Cheers.
     
  43. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    The problem with using my asset in sprite based games is not that they don't use meshes, but that the quads don't have any thickness and so don't write any depth data when viewed from the Line of Sight source's perspective. This Line of Sight system uses the depth buffer to calculate the visibilty of every pixel on screen, so it only works properly in an actual 3D scene.

    I think your best option would be to use a 2D shadow asset as a starting point for writing your own 2D LOS system.
     
  44. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    The version of the asset Unity downloads depends on which version of Unity you are using.

    To use the latest version of the GPU Line of Sight asset (1.2.3) you need to be using Unity version 5.3.2 or up.
     
  45. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Could you send me a screenshot showing the actual problem?

    How are your decals being rendered? I'm guessing it's indeed a problem with not writing to the depth buffer.
     
  46. wheelbarrow

    wheelbarrow

    Joined:
    Sep 12, 2011
    Posts:
    177
    Here are 2 screenshots, one showing the bloodsplat on the ground as it should, when the los source is close, and the second pic shows what happens when I move the los source away from the same bloodsplat. Sorry the screenies are so dark, but the decal is clearly visible in both shots.
    I tried getting a screenshot of the particle spray shadows, but it's just too fast.
    Cheers.
    Blood splat 1.png Blood splat 2.png
     
  47. mkgame

    mkgame

    Joined:
    Feb 24, 2014
    Posts:
    592
    Could it work for an RTS game, each unit would have this feature, Max 200 Units? I would need 2 areas, one which looking forward (all your pictures show this behavior) and one which looking in each direction (Sphere) but with shorter radius (minimal reveal radius).
    May it works also as a non expensive spotlight?
    What do you mean with GPU solution? Maybe a kind of inexpensive light source, or a shader? Is the work done with Shader Forge, so that we can adapt the shader/light source?
     
  48. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    It would be technically possible to achieve what you're describing, but adding line of sight to 200 units would have a serious impact on performance.

    It's a GPU solution because most of the computations are handled by the GPU. The algorithm is similar to shadow mapping. The shader is not made with shaderforge, but the effect is completely customizable.
     
  49. krisz-konya

    krisz-konya

    Joined:
    Aug 28, 2015
    Posts:
    5
    Hi,

    I am trying to use the LOSVisibilityInfo script but I have no success. In your example scene when the player is being moved (or just rotated only) it continuously invokes the Enter and Exit methods (in the starting room where none of the CCTV cameras see the player). The VisibleSources list always contains four of the six player LOSSources, I think they should be excluded.

    Thank you.
     
  50. krisz-konya

    krisz-konya

    Joined:
    Aug 28, 2015
    Posts:
    5
    Oh, I forget to mention, I use the latest Unity Pro 5.3.5p1.