#Visually Representing 3D Field of View at an Arbitrary Point in Space

1 messages · Page 1 of 1 (latest)

limpid wyvern
#

I need a way to visually represent the places in a map that can be seen from an arbitrary place with a given distance.

I currently have a system that generates these arcs in a straight line, drawing a wedge that covers the view from a position (in this case, a guard tower), at its current height. The code for doing so can be found here: https://paste.mod.gg/wrqtanydrxlt/0

What I need now is the ability to also include angles up and down from horizontal and to indicate anywhere that can be seen in that field of view. The math is actually fairly simple to detect the lines of sight, I'll just take this loop that raycasts in a fan and repeat it at several angle inclinations in either direction, but I don't know how to show the results. Drawing a fan worked here, but this would be a 3D object with potentially awkward geometry. I'm not sure how I would generate a 3D shape that does something similar to this, like how I would gather up all the vertices and wind them into a hull.

The ideal solution would be something like "tint this object a color if it's visible by this spot" but I don't even know how to begin working on that, especially since these objects all have radically different shaders (including MicroSplat whose shader code is so complicated that I'd probably just detonate if I looked at the shader file) and I don't know how I could manage that with any sort of VFX.

The project is in URP, and changing to HDRP for Volumetric Lighting is not an option, which is unfortunate because I think just a bright volumetric from this point would be done and dusted. Is there anything else I could do to potentially leverage the lighting system to do this for me? My options are open, I don't need to work with the system I currently have for drawing the fans, I could can the whole thing if a better solution is available.

limpid wyvern
#

Continuing experimentation:

Lights don't work. Falloff and overlap make it basically not useful for knowing what is visible, and the fact that these need to be at runtime and not baked means that I'm limited to some number of concurrent lights on the terrain and I need to be able to do this an arbitrary number of times.

#

Decal Projector:
Doesn't work on terrain because MicroSplat doesn't use the depth buffer so I can't do anything that involves depth testing. It just does not show up on the terrain which is kind of where I need it most.

#

What I think I need is to find a way to dynamically create a "shell" mesh for a point cloud. I can generate points with raycasts from a central location, and store the points they hit anything or the max distance if they don't, and basically turn that into a sort of ico-sphere

#

Can't do the Convex Hull algorithm since it's not gonna be convex if there's anything in the way so I'm going to have to reinvent one

north dagger
#

What can be in the way? Anything? Or just bumps in the terrain itself?

limpid wyvern
#

I've already got a layer mask of things that can occlude line of sight, and they all have colliders

#

But I can't bake the computations into the light map, it's all runtime generated or runtime loaded

north dagger
#

I think you can copy concepts from stencil shadows. It's a shadow rendering technique that generates shadow volume meshes to draw perfectly sharp shadows instead of using shadow map textures. Basically, it ends up with a 3D mesh that represents the volume of the shadow, which sounds like what you are trying to do.

Here's an implementation of stencil shadows in Unity URP.
https://github.com/rhedgeco/UnityShadowVolumeGenerator

GitHub

Library for generating sharp shadow volumes in Unity3D. - rhedgeco/UnityShadowVolumeGenerator

limpid wyvern
#

That does sound like what I want. I'm at home now, I'll have to try it tomorrow morning but I'll read up on it in the meantime

north dagger
#

It's technically the inverse of what you're trying to do. Instead of generating one mesh representing the visual field, it generates a separate shadow volume for each shadow caster. Whether that is still useful to you depends on how you want to visualize this. It should still be fine if you just want something like a decal or light with shadowed areas.

mint ivy
limpid wyvern
north dagger
#

Well, you're asking for more detail than just per-object, right? You want to highlight which parts of the objects are visible? If it just needs to be per-object, it makes more sense to do the occlusion checking on the CPU with raycasts and send that to the GPU.

mint ivy
north dagger
#

Sure, but I'm asking whether you want the whole object to become highlighted as soon as any part of it is considered visible, or if you want only the part that is visible to be highlighted.

mint ivy
#

Ahh yeah true

north dagger
#

For the terrain, it's almost certainly only supposed to highlight the visible portions instead of the whole thing or the whole chunk. For smaller objects you might get away with whole object highlighting, which you can easily achieve with the Render Objects renderer feature, but you'd still need a different approach for larger objects and terrain.

limpid wyvern
north dagger
limpid wyvern
north dagger
#

Does it matter what this visualization looks like? You've mentioned a few different approaches that would give different looking results, like decals and volumetric lights.

What about just displaying a dot for each raycast, similar to the terrain scanner in Death Stranding?

limpid wyvern
#

For full context: This is a simulation for designing security systems. There's a dynamically generated facility model from architectural drawings, and it's turned into a 3D environment. You can place security cameras and personnel, and run different scenarios (things like "What if it's a delivery day and there's a large truck in this area, how does that affect response times?).

I have cameras in place for everything so you can "inhabit" one unit and see what they can see, but it's not good for viewing data in aggregate. What I want is a system that just tags everywhere that can be seen by any guard or camera and you can fly around the scene and visually see any blindspots

limpid wyvern
# north dagger Does it matter what this visualization looks like? You've mentioned a few differ...

Decals have the problem of going through things and painting to all surfaces in range, as well as being orthographic-only. Lights have the problem that there's only so many that can affect one object, and the terrain is going to be visible from so many of these that it stops displaying anything after a while. There's also the problem that a spotlight cone is not actually a view frustum, but if that ends up being the last problem I can probably live with it

north dagger
#

I only mention those solutions because you mentioned them previously, and even if they were working nominally, they would still look different from each other. So it suggests it's not so important to you exactly how this looks, just that the information is delivered efficiently.

limpid wyvern
#

Yeah, I don't particularly care how it's represented as long as the data is accurate. Not going for a visual style here, just purely functional.

north dagger
#

Rendering a dot for each raycast hit would be easier than the approaches we've talked about before and would be easier to cache.

#

You can use VFX Graph to handle the rendering of the particles as dots or whatever you want and then easily control the look of it, movement, or whatever.

#

I would use RaycastCommand to fire a bunch of raycasts asynchronously, feed that into a GraphicsBuffer which is then read by your VFX Graph particle system to place the particles.

#

If VFX Graph is not an option, like if this needs to run on WebGL or other platforms without compute support, then you can render them manually with Graphics.RenderMeshInstanced, but then it's not as simple to control the visual look of them.

#

Or you can use 'ye old Particle System. It also has job support, so you can quickly copy the raycast hit results from the RaycastCommand job to the particle system.

limpid wyvern
#

Oh man I'm gonna need to learn jobs negativeman

north dagger
mint ivy
north dagger
#

Yes, they are inherently simple in design so that the safety system can understand what you're doing and stop you from adding race conditions.

limpid wyvern
#

Okay, I have the raycasts and did a proof-of-concept by slapping a sphere object where the rays hit. Now I just need to figure out how to use VFX Graph with this data...

jaunty merlin
#

I rather like using a camera to render a depth map and then VFX graph to place a dot at the reconstructed position

#

I've done the raycasted version before though, you just need a graphics buffer the size of your ray count