Search Unity

[FREE] GPU Line of Sight / Field of View

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

  1. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,135
    I just picked this up on sale and I've so far been able to make a rough prototype of a game idea that's been eluding me for some time, which is pretty great, but I have a few questions:
    1. Is there a way to preserve the visibility of the skybox?
    2. I notice when two LOS views overlap, they increase the brightness of the object. Is there a way to clamp this somehow so it never goes above the light level of the scene?
    3. I don't suppose you've used Amplify Shader Editor and have any pointers for creating custom image effects with it? I'm sure I can stumble around and find something but any guidance would be great.
    edit: Nevermind number 2! I just found the HDR mask option!
     
  2. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Hey, thanks for your purchase ;)

    To answer your questions:
    1. It's possible, but not without changing some of the code. I can look into the specifics if you want.
    2. The HDR mask option does indeed fix this
    3. I've only used ASE briefly, but any image effect should work with this asset.
     
  3. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,135
    Any help with the skybox thing would be great! The game I'm working on doesn't look right without skyboxes, I'm afraid.

    edit: Here's a video of what I've accomplished so far that should give an idea of what I'm going for with the skybox thing, just so I'm clear.



    Basically, I want the line effect to be on the line of sight areas while areas without geometry will still show the skybox. Thanks for all your help.
     
    Last edited: May 1, 2018
  4. ModSimTeam

    ModSimTeam

    Joined:
    Sep 9, 2012
    Posts:
    7
    We are using the 360 prefab.
    We were using the 360 LOS prefab and are using default settings. The “zebra” stripes appear to be permanent, event when the LOS object is right above them. It seems to occur when dealing with very small slope to the surface.

    In the scene below we have a small unity terrain and a large plane. Things seem to be fine when the plane has no rotation or slop to it. As soon as we rotate the plane to add a bit of slope the banning occurs. To the right are the current properties but we’re just using defaults.



    Below is a mesh terrain with very little slope to it.
     
    Last edited: May 1, 2018
  5. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    I'll look into a solution for the skybox once I'm back in the office next week ;)
     
  6. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    There's a couple of things you could try to reduce the banding:
    • Reduce the far clip plane of the cameras used by the LOS sources. The smaller the far clip plane is, the greater the accuracy.
    • Increase the Min Variance setting on the LOS source components.
    • Move the 360 prefab up farther from the ground, to increase the angle between the surface.
    Let me know if this helps to reduce the issue.
     
  7. Ryuk47

    Ryuk47

    Joined:
    May 29, 2018
    Posts:
    1
    Hello there!

    I am fairly new here, but I got a question to ask concerning the usability of that asset of yours in a 2.5D context. We are creating a 3D sidescrolling spying game, and would like to utilize your work in creating camera and "peeping-through-the-key-hole" cones.
    The demo material is limited to a top-down view, so I would like to know whether it would be possible to achieve a look similar to the attached image, but with the cones considering the depth of the 3D space and thereby blocking out vision in areas no reachable directly from the camera position.

    Have a nice day!


     
  8. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Hey,

    The asset would be suited for achieving a similar effect, but then more accurately with depth.

    The only drawback is that my asset uses the camera frustum as a shape, so getting a cone shape (like on the bottom floor in the example image), would require making some modifications to the code.

    Let me know if you any other questions ;)
     
  9. jiannis_hs

    jiannis_hs

    Joined:
    Apr 26, 2016
    Posts:
    12
    the plugin looks great, thanks! I'd like to try out following things:

    1. if there are places in the scene that are dark (e.g. a room without lights) the LOS shouldn't be visible there. It should only be visible if there is light in the scene
    2. I'd like to have low objects, which don't completely block the LOS but the player can cross if she crouches.
    3. I'd like to add textures in the LOS

    are these possible?
     
  10. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Hi robojiannis,

    I'll do my best to answer your questions:
    1. Do you mean the area revealed by the LOS should not be visible in dark areas, or the LOS itself?
    2. That's possible. You can also exclude objects from the LOS if needed.
    3. Not possible out of the box, but if you have some shader knowledge you can add it yourself.
     
  11. jiannis_hs

    jiannis_hs

    Joined:
    Apr 26, 2016
    Posts:
    12
    thanks for the prompt reply. Here's an ugly screenshot to help visualize what i mean: https://unsee.cc/d08e17eb/
    1. I basically don't want the NPC to be able to see in part (A) of the screenshot and therefore shouldn't visualize the LOS there.
    2. In part (B) of the screenshot i want to be hidden only if crouching
    3. In part (C) LOS should work as usual. I want to be able to texture (A), (B) and (C) different.

    is this possible?
     
  12. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    None of these are possible "out of the box", but with some hacking might be possible:
    • (A) Add geometry that blocks the LOS and is visible only to the LOS sources, but not the main camera
    • (B) Add a class which uses the LOSCuller script to determine the visibility, but also keeps into account the position and crouch state of the character, or does some additional raycasting
    • (C) Adding different textures or colors should be possible if you first render the different zones into a stencil buffer and then reference the stencil buffer value in the LOSMask shader
     
  13. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    There shouldn't be any different between the 2 camera modes. Could you post a screenshot of how you have configured both cameras in the inspector?
     
  14. UnityGISTech

    UnityGISTech

    Joined:
    May 6, 2015
    Posts:
    193
    Here MainCamera and Source with unity 2018.1
     

    Attached Files:

  15. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Can you try changing the camera's clear flag from Depth Only to either solid color or skybox?

    I tried replicating the issue with another recent version of Unity, but was unable to get the same result.

    I'll try to replicate the issue with version 2018.1 later. Are you using Unity 2018.1.0 or another version?
     
  16. UnityGISTech

    UnityGISTech

    Joined:
    May 6, 2015
    Posts:
    193
    i changed the camera flag to skybox and solid color---- > but not work .
    Player LOS Camera to the same flag as MainCamera --> not work

    i think there is something that not work well here

    float4 OrthoGraphicDepthToWorldPosition(VertexOut i)
    {
    float depthSample = tex2D(_CameraDepthTexture,i.uv);
    float depth = UNITY_SAMPLE_DEPTH(depthSample);
    depth = depth * (_ProjectionParams.z - _ProjectionParams.y) + _ProjectionParams.y;
    return DepthToWorldPosition(depth, i);
    }

    im using unity 2018.1.0f2
    i lost more then 24h to make it work but i ... not things work well .
    its very importante for my last years on the unitversity.
     
    Last edited: Aug 16, 2018
  17. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    I just tested the asset with the same Unity version as you (2018.1.0f2) and orthographic cameras seems to work fine in the example scene.

    Could you send me a Unity project which I can use to reproduce the issue locally? You can mail it to support (at) entropi-games (dot) com
     
  18. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    @sisocano

    Thanks for sending me the project.

    It looks like you're using an outdated version of the LOS asset, which had some bugs in it when using the orthographic camera.

    To fix the problem, simply download the latest version from the Unity Asset Store ;)
     
  19. slik

    slik

    Joined:
    May 29, 2013
    Posts:
    6
    @Tycho
    Does it work in 2018.3?
     
    Last edited: Nov 1, 2018
  20. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    10,135
    In my tests it does. They weren't extensive by any means, but if you're using the built-in renderer you should be good.
     
    Tycho likes this.
  21. brmusic

    brmusic

    Joined:
    Sep 18, 2013
    Posts:
    9
    Hi! Love the package. Quick question. I am having trouble getting my 3d LOS to look like you have in the picture at the top of this thread. I get a lot of clipping and black shadows on objects. Any suggestions on what I might be missing to get the 3d LOS visualization? Or, documentation to support that?

    Thanks!
    Charles
     
  22. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Hi,

    Have you tried tweaking the Exclude Backfaces and Backfaces Fade properties on the LOS source components?

    If that doesn't fix the artifacts, could you post a screenshot of your scene?

    BTW, the documentation is included with the asset pacakage ;)
     
  23. brmusic

    brmusic

    Joined:
    Sep 18, 2013
    Posts:
    9
    I have tried messing with the backfaces, but haven't had much luck. I have used the documentation extensively, which is awesome, by the way. I am using the 360 prefab that is included in the package...

    I wonder if it is a camera placement thing or something about the layer masking. I have tried a bunch of combinations at this point so I may have changed something else...

    Capture_LOS.PNG
     
  24. brmusic

    brmusic

    Joined:
    Sep 18, 2013
    Posts:
    9
    I think I figured it out. It has to do with the directional light. Of course right when I asked. Let me play around with it more and if I have issues I'll get back to you.

    Thank you so much for your quick response!!
     
  25. brmusic

    brmusic

    Joined:
    Sep 18, 2013
    Posts:
    9
    OK - Separate question - do you know of a performant way to mimic the functionality in LosVisibilityInfo? I have many LOS sources and like to check if a character is within the bounds of the camera. I don't believe I can use renderer.isVisible because the object is always visible to one camera or another...
     
  26. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    What part of functionality would you like to mimic?

    You can retrieve the VisibleSources property of the LosVisibilityInfo component, and iterate over the list of sources to check for certain conditions (ex: a certain tag) to determine if it's visible to a selection of sources.

    BTW, did you figure out the problem with the directional light? The screenshot was a bit too dark to see what's going on.
     
  27. brmusic

    brmusic

    Joined:
    Sep 18, 2013
    Posts:
    9
    First, I figured out what was wrong with the directional light. I forgot that the LOS was sitting on top of the scene and that the directional light was just facing the wrong direction. One of those things you figure out the minute you try to ask someone how to help you. Lol. Thank you for asking.

    Iterating over the list and checking the tag is a great way of making sure it is apart of the sources I want to check. Thank you for that suggestion! I wanted to also ask that in your documentation you wrote that this is not great for performance. As I have a lot of LOS sources I'm concerned about this. Is this something that I shouldn't be too concerned about?
     
  28. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Sorry for the late reply, but performance should be find with quite a large number of LOS sources, as long as you're only using one (or a few) LOS Visibility Info components.
     
  29. qqqbbb

    qqqbbb

    Joined:
    Jan 13, 2016
    Posts:
    113
    Does it work with tilemaps?
     
  30. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    No, this asset only works with 3D environments and does NOT support 2D :)
     
  31. qqqbbb

    qqqbbb

    Joined:
    Jan 13, 2016
    Posts:
    113
    What gameobject component is required for it to work with this asset?
     
  32. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    What do you mean exactly? This asset is not designed to work with tilemaps or other 2D components.
     
  33. qqqbbb

    qqqbbb

    Joined:
    Jan 13, 2016
    Posts:
    113
    I'm not trying to make it work with 2D. I'm just curious. Is mesh renderer required for this asset to work?
     
  34. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I wonder if this asset can also be used to do fog of war effect along with the sight effect.
    So the area not seen is completely hidden, then once revealed , it can be viewed (maybe in some style) even if it is outside the sight. ?
     
  35. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Yes, a Mesh Renderer component is required for this asset to work, but colliders are not.
     
  36. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    This asset can't be used as a fog of war effect out of the box, and I think it would take a lot of effort to make it work.
     
  37. Reticulatas

    Reticulatas

    Joined:
    Jul 31, 2012
    Posts:
    25
    Looks like the sample scene demo is no longer working on 2019.1, any change of getting a tip on how to get it up and running again?

    The objects are being occluded properly, but no field of view cones are being rendered, nor is the screen being darkened.

    EDIT: Only under HDRP, investigating...
     
    Last edited: Dec 24, 2018
  38. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    This asset hasn't been updated yet to work with the new scriptable render pipelines, so it will only work with the default renderer.
     
  39. Kamil-Sobierajski

    Kamil-Sobierajski

    Joined:
    Dec 14, 2016
    Posts:
    44
    Hello.
    Really nice asset.
    But I have 2 questions.
    1. First is about trees. They have a transparent or cutout leafs mesh so this shows badly. Is some solution, or tips for these problems?
    2. Second is about multi meshes characters. If I make different characters parts, like different cloths set or equipment it shows and disappears little glitchy. The characters loose pants od shirts or heads before disappear. And when it shows in LOS it randomly appears. Can you make some kind of character grups or contenders, what makes all characters parts appears at once?
     
  40. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    1. I think the best solution is to exclude all transparent objects from the Line of sight
    2. You could create a custom script based on the LOSCuller script component, which combines all the bounds of the individual character meshes and calls the CustomCull function only once.
     
  41. Kamil-Sobierajski

    Kamil-Sobierajski

    Joined:
    Dec 14, 2016
    Posts:
    44
    1. Hmm. With unity trees, is a little hard to separate leaves from woods it shares material and his own generator. This system keeps all in one place.

    2. Hmm. I need a coder then.
     
  42. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Can you assign a different material to the leaves? If you assign a material that has depth write disabled (ex: most alpha blended materials) the leaves should not influence the line of sight.
     
  43. Kamil-Sobierajski

    Kamil-Sobierajski

    Joined:
    Dec 14, 2016
    Posts:
    44
    I have on the mind simple Unity trees. When you click on a Hierarchy window and go Create>3D Object>Tree.
    This is a system that let you create trees with a simply creator. You can add branches and leaves, and form the tree as you need. But this system keeps everything inside, and make one material, half for Leafs and half for the wood parts.
     
  44. bitHussar

    bitHussar

    Joined:
    Jan 9, 2016
    Posts:
    33
    Hi!

    I need something like this in my game, however before purchasing I'd like to make sure that what I need can be done using this asset:
    - It's a top down game but with perspective camera with about 70 degrees rotation, so not completely top-view
    - I'd like to display everything inside the player FoV normally.
    - Outside the player FoV I would llike to have some image effects (darken, desaturation) while also hiding dynamic objects like enemies. I've seen it is done in the demo, however I'd like to be able to hide objects partially (still displaying parts inside player FoV), like in Darkwood (see attached image).
     

    Attached Files:

  45. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Hi,

    All of this can be done with the asset.
     
  46. Juaprebo

    Juaprebo

    Joined:
    Nov 15, 2014
    Posts:
    19
    Hi! It is possible to make FOV similar to Shadow Tactics?
     
  47. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    No, that would not work with this asset, since their FOV isn't completely 3D.
     
  48. Juaprebo

    Juaprebo

    Joined:
    Nov 15, 2014
    Posts:
    19
    OK, thanks
     
  49. bitHussar

    bitHussar

    Joined:
    Jan 9, 2016
    Posts:
    33
    Hi!

    I just purchased the asset, and all seems to be working just fine except I cant seem to figure out how to partially render objects (render only parts that are inside FoV, see the sheep north to player on the attached screenshot). Can you point me to the right direction?
    Thanks
     

    Attached Files:

  50. Tycho

    Tycho

    Joined:
    Nov 24, 2012
    Posts:
    205
    Sorry, but I didn't notice the sheep the first time you posted the screenshot, I thought you meant desaturating dynamic objects partially outside of the LOS.

    With this asset you can hide objects completely once they leave the LOS, but not partially. Adding functionality like this would also be a lot of work I'm afraid.