I’m working up a render target based fog of war system. I need to be able to calculate how much of the map the player has revealed, not distance traveled, amount revealed.
As it sits right now, my map reveal is based on a sphere pinned to the actor being dragged around. A blueprint in the level writes that to a persistent render target as a 1 where the sphere intersects the landscape.
The approach I’ve been chipping away has been to average down the render target to the lowest mip and then theoretically read that color value as a number. It is the reading the value of that texture as a number I’ve got no idea how to do.
I am confused what you mean by this. The render target is a fixed size. When I write to it what I am doing is a scene capture dropped in my level that sees just where the objects I’ve flagged with a stencil get close enough to the landscape.
your mip idea is the right shape, teh missing piece is just how you read it back. the built in read render target nodes force a sync gpu copy on the game thread, so even reading one pixel hitches. downsample the mask into a small rt like 32x32 first, then read that back on a timer (twice a second is plenty for fog) and average the red channel on cpu. revealed percent is just that average against your clear value.
you can also try Async Render Target Reader, a render target readback plugin for Unreal Engine that reads the downsampled mask back without stalling the game thread: https://www.fab.com/listings/1861543a-feda-4961-8b6c-6b50c6daaeef
You dont need to read anything. You do the math. Yourself.
You use a special stencil to write to it that is a known amount of pixels.
Every write operation is when you do math. You don’t constantly just write to it. You dont read from it.
If you are smart enough you don’t even need a render target since you have x/y coordinates and a 0/1 value of what is visible or not.
The render target comes in to affect the actual map/fog since it is easier to use over anything else. But it really isn’t a requirement for any similar system.
On the other hand, if you write to the RT you can also parse the image to read its pixels one time with no real hitch at the end of a match. Thats what lazy devs do…