Download

Hide items in the shadow

I’m trying to implement an effect where objects not in the line of sight of the player are hidden, but so far without luck. Here’s what I considered:

  • My main approach was to render the scene twice (once with lights in a render target, once with less lights in the screen render), then generate a line-of-sight mesh with a material that would use the render target texture using the screen coordinates as uv. A few drawbacks:
    [LIST]
  • I can’t find how to hide the lights in the render target. I tried both the Hide Actors feature, and to call SetVisibility before and after CaptureScreen, but in both cases the light I wanted to hide was still there. I suspect it only hides primitive components, and perhaps lights aren’t one?
  • The mesh I generate is currently flat, and it doesn’t play very well with walls: only parts of the walls are lightened, since the mesh is roughly mid-body. I could move it to be at the top of the walls, but then it wouldn’t play well with windows.
  • It won’t play well with perspective, since I’ll be able to see objects that are behind my mesh (rather than just “inside”).

I also considered using the regular dynamic light system and access the light buffer (to then apply a material to the objects I want to hide, setting them transparent based on the amount of shadow they receive). However it seems like the light buffer cannot be accessed, even at the cost of a second render (which is what I already do in the previous experiment anyway), is this correct?
If everything else fails, I’ll likely have to setup collision boxes around each light, then trace to each object I want to hide, and show them based on whether there’s a hit or not. The problem I foresee is that the shadows seem hard to control, so there’s no guarantee that they will correctly match my collision boxes, contrary to the previous approach. There’s also a fair bit of bookkeeping to do, which I’d have enjoyed avoiding.
[/LIST]
I’m also struggling a bit to use the light system to make decent lights (points lights seem super bright at the center, whereas I’d like them to be average where they spread), but that can be for another time