Hey guys, i have been following this thread for some time, trying to implement the fog of war in an already existing project running UE4 ver 4.11.2, my project already has dynamic textures working, so the RHI Core and the Materials are working, but i can´t manage to compile the project with the code from this tutorial, the errors displayed in VSC are:
Error C2084 function 'AFogOfWarManager::AFogOfWarManager(const FObjectInitializer &)' **already has a body **ThirdPersonDef C:\Users\Milo\Documents\Unreal Projects\ThirdPersonDef\Source\ThirdPersonDef\FogOfWarManager.cpp 6
Error C2664 'double modf(double,double *)': **cannot convert argument 2 from 'float *' to 'double ***' ThirdPersonDef C:\Users\Milo\Documents\Unreal Projects\ThirdPersonDef\Source\ThirdPersonDef\FogOfWarWorker.cpp 73
Ok i got the project files working, and now i upgraded the project to 4.12.4.
Any one can download the project from here: FOW
I will try to keep the project up to date with the latest release of UE4.
Good evening lads. I’m trying to implement this to work in a 2.5 D platformer I’m creating. What logic would you approach this with if you only wanted this to work within buildings or certain areas basically in order to hide the contents of the rooms you’re not in, but still be able to maintain view distance outside of buildings or through house windows?
The FOW-effect is applied through a post-process-volume. In the tutorial it says you should apply to an unbounded PP-volume, but there’s nothing keeping you from using bounded volumes. The main obstacle to use this FOW-solution for a platformer is that it’s written to to visibility checks and render the effect in the Z-plane. Assuming your platformer is some kind of side-scroller you’d have to rewrite the solution to be axis-independent in order for it to work outside the Z-plane.
Ok, imagine you have two objects. One of them is transparent and second is opaque. Transparent object is between camera and opaque object. Absolute World Position returns the position of pixel that belongs to opaque object (not transparent that is closer to camera) and it will cause issue. Do you understand what I mean?
Ahh, now I understand. I’ve never really thought about that particular use case, but I imagine it won’t work at all. If you’ve already rendered the transparent actor over the opaque one the pixels affected will remain affected and there is no way to undo it in the PP-mat. You could maybe get around it with some clever use of custom depth, or you’d have to disable rendering the transparent actor if it’s in the fog.
You might want to check the file FogOfWarWorker.cpp
There is a part of the code that checks with a line trace if there is a hit found, the command needs a starting and a ending point, in the code they are: position and currentWorldSpacePos
if (!Manager->GetWorld()->LineTraceTestByChannel(position, currentWorldSpacePos, ECC_WorldStatic, queryParams)) {
if you look some lines above this command, the code is inside a nested loop, which i assume is the responsible for iterating around the surrounding texels/positions of the character.
this nested loop iterates in X and Y but the Z component is not changed.
FVector currentWorldSpacePos = FVector(((x - (int)halfTextureSize)) * dividend, ((y - (int)halfTextureSize)) * dividend, position.Z);//<---see the position.Z, this part is not changed inside the loop
in fact the position.Z comes from a call outside the loop some lines above
FVector position = (*Itr)->GetActorLocation();
Playing with this Z value (adding some vector or scalar) to make the line traces above the Actor Location could give you the a change in height of sight.
I hope this can be of help, is not a solution but a starting point.
Also, i have been making some modifications to the code, adding some new features:
A new component called RegisterToFOWManager: this new component is added to every actor that needs to affect the dynamic texture
The component has the following features
A dropdown selection for choosing the FOW manager
3 Boolean variables
Write Unfog : Check if the the actor able to reveal areas of the terrain
Write FOW: Check if the actor able to affect the Fog of war
Write Terra Incognita: Check if is the actor able to affect the terra incognita area
1 Boolean variable that reports if the actor is currently in the Terra Incognita
Also, the FOWManager can now load images or masks that represent the Fog of war, white for FOW, black for Terra Incognita, some info on how it is done here
when loading images, it is very important to set the texture to No MipMaps and Compression to DisplacementMap, otherwise the editor will crash. This will be addressed soon.
Hi, flash7, unfortunately i did not implement the new features inside the part of the code that performs the blurring for reducing the roughness when unveiling, partially because i still don’t understand how the blurring is performed in the code
But i am still working on it, so i think soon i will upload a project with the blurring working.
@Milotron. This is some pretty cool stuff. I just had to reply that I like the first post with the mission reports as an old fan of the 40K and WH tabletop games. Looks pretty slick and you actually use threads (programming, not forum threads). A lot of “tutorials” don’t, so It is nice to see some more “advanced” features used.