How to make everything inside a 3D box visible and outside of 3D box invisible

Hi everybody,

for my game I need an effect where everything inside a 3D bounding box area is visible (any actor that is inside it, even partially) and every actor that lies outside this box is invisible. I need this to be in real time so I can basically move/drag this box around to reveal “hidden” actors once they come in contact/are inside my box.
A hard cut for visibility (binary: inside/outside) is ok, what would be awesome is a gradual fade to transparent or an actual cut for a mesh that lies half in hlaf out (though I doubt that is possible).

Think about it like the darkness reveal effect from the Mario ghost houses but in 3D and with a box instead of a circle:

Just for context what I want to use this for is a 3D minimap that should ony reveal the stuff around a player, cutting off everything outside of the currently visible area, similar to this:
image

Does anybody have an idea how I could achieve such a thing? Maybe some tutorial I could follow or some tutorial that might do something similar?

Thx everybody for hearing me out :slight_smile:

What you’re looking for is a version of what’s called “fog of war”. You can do this using a post process volume.

This video introduces the concepts surrounding it, but you’ll need to change it to get the exact effect you’re looking for:

This is a good starting point thank you!
Now I am asking myself how can I make the PostProcessing only apply to certain things inside my scene?
Because for example this 3D minimap I was talking about should basically be a physical object/actor inside my scene, so I want this “cutoff” to only happen for that actor itself…

To do that, just make sure to use a new post process volume that is manually scaled to encompass the minimap, and put the material on there. Make sure infinite bounds is not enabled on that volume.

I have tried this the way you said, the problem is: with a scale down PostProcessVolume I can only see the effect while I am inside of it.

If I am lookin at the Volume (and the Minimap inside of it) from outside, no effect is visible…

Take a look at this video to understand what I mean:

Would it not be visible through whatever means you’re using to capture the minimap and place it on screen?

If not, what you can do is use a mask based on the physical location of the mini-map such that anything outside is unaffected.

No because I don’t want to have the minimap in some different scene, I want to have it like a sort of miniature model inside my scene like this.

How could I do the mask thingy you mentioned?

Hmmm. If you want it to be a physical object visible in your scene with only a portion of it revealed, post-processing is not a great option.

Knowing what you’re doing, I’d recommend a material directly on the minimap mesh. Assuming you’re fine with actually invisible and not just black. Make it masked- we can still get the full benefits of transparency through dithering but without the performance overhead. Here’s a material that I threw together:

The result:




This is the effect with the opacity mask shoved into emissive just to show what’s happening.

The mesh moves so the visible part is always in the same location

Though this can’t be rotated with how it’s setup currently, it can be scaled.




To hook this up to the player, you have to first change the material to a dynamic one at runtime like so:

Next, update the parameters every frame. You can likely optimize this by only doing so if the minimap is in view and if the player has moved since last check, but I’ll leave that to you. This is how you can update the parameters:


Make sure the parameter names match exactly with what you’ve named the parameters in the material itself.

The “Get -1->1 progress in bounds” macro is a custom one that takes the position as well as the highest and lowest possible values. This should be the highest and lowest possible position (X,Y,Z ignoring the Z since it’s height). And this is the macro itself that uses said values:

2 Likes

Holy moly this phenomenal! You really invested your time to actually built a working product that I can follow, how awesome! :smiley:

This looks incredibly interesting and I will definitely try this out asap, this is exactly what I was trying to achieve! :slight_smile:
Thank you very very much sir!

1 Like

Did you ever get this to work? I’m trying to create a hologram table effect where the landscape moves through the hologram and I don’t know where to start. I was thinking some kind of decal projection on a transparent surface maybe…

Follow my comment- I detailed the process and it would work for that use-case.

I managed to get this working! Thanks. My boss wants to recreate the following image with an ability to show various water activity (Dams, floods,etc) on the surface. I have no idea where to start and thought maybe some kind of render volume that only renders what’s inside it would be something I could do. However, if I can make this same effect apply to things on the land surface, then I should be good. Any pointers? Is a render volume even possible? Thanks for your help.

Here is what I was able to do following your instructions:

1 Like