I’m thinking of solutions for a Fog of War system using blueprints on UE4.
Does anyone know if it’s possible to render a custom Z depth map that considers a world location (vector) as the starting point, instead of the actual camera, and “goes from there”?
My idea is rendering that and adding it to a post-process material, and make everything that is occluded by the custom z depth map black, thus creating a nice fog of war effect with occlusion.
Definitely worth trying the Depth-based approach, though I’d personally go about it by writing my own GBuffer, then having that buffer read from a globally-mapped volume texture of some kind. The volume texture could be fairly low-density and you could interpolate data between points, making it pretty resource-friendly.
Then simply create an Actor Component of some description that writes to that volume texture to reveal or hide parts of the world. Bonus points available for making Actors work out if they’re visible or not, and automatically hiding / enabling themselves so you’re not rendering all those triangles and textures when actually they’re just going to be masks out by the GBuffer anyway! I guess you’ll want that anyway since Fog of War systems typically employ that kind of thing.
You could make it fairly self-contained too. Create a custom volume that level designers can place around the world area, and have the GameInstance figure out the bounds of that volume at runtime and work out how large the texture needs to be. There are a few tutorials out there already for storing data in textures and reading from it in Materials too, which would be good for a post-process based approach. The best example I can think of off the top of my head is the Bouyancy system that Handkor worked on: https://www.youtube.com/watch?v=PBWLfpm0K0o
brunogruber said “solutions for a Fog of War system using blueprints on UE4”, and I think the GBuffer approach does not work with pure blueprint, right?
I am myself searching for a nice way to use fog of war with only blueprints.
Yeah GBuffer would have to be a code solution, and an Engine-based one at that (Possibly Plugin… would have to investigate that). My bad, I missed the Blueprint part.
I’ve seen a FOW system on Marketplace that I think is BP-powered, but it just looks like a lot of dynamic lights, so not fog of war at all really… I can’t think of any nice way to do something like this in Blueprints right now. You just have to have some kind of influence map or data structure stored somewhere.
Create a UMG widget which you use as a “Texture” to draw on using the DrawBox node in the OnPaint function. So you draw lets say 512x512 pixels which represent your whole world, actors which “enlighten” the FOW would for example just say that their world position in a radius of 2000 world units would get visible, which would be ~20 pixels on the widget, totally dependend on your world size. So here you have something like a “Texture”.
Create a SceneCapture2D which points down onto a WidgetComponent which shows your widget and saves the image into a RenderTarget2D with a size of 512x512.
Use a post process material to create the fog based on your RenderTarget.
I actually tried this out and it works, I did not set up a correct way of converting world position to “PixelArray” (Widget) Position, but using the way to create a “Dynamic Texture” you can “draw” on from blueprint works really great, since it’s very smooth. My knowledge about PostProcessMaterials is just very limited so actually setting up that the correct world location gets visible is not really what I can do, but maybe someone else here could try to get it to work?
Hey guys thanks for the input so far. I’m still trying to achieve this, but no luck yet. John, would you mind uploading an example of what you did? I’m not sure I understand.
Note that the camera is actually pointing down. There you have a widget component inside, so the camera points down to the widget. Then the camera saves the image it captures to a RenderTarget.
So here at the left you see the blueprint with the camera (camera is not visible in game) and on the right you see the RenderTarget I draw on the UI (just to see how it looks):
After applying this to a post process volume and adjusting the center and size with a material instance, I actually get the level darkened in the pretty much correct location: