Changing the Fog of War to look like clouds (Civ5 style)

tomekum

Chieftain
Joined
Oct 23, 2016
Messages
91
I am trying to add clouds effect to fog of war for my Civ4 Remaster Mod. Similar effect to this in Civilization 5. I was inspired by the
f1rpo idea posted here https://forums.civfanatics.com/threads/rescaling-resource-bubbles-through-shader.669162/.

So after investigating the shader files I discovered that the shader responsible for drawing terrain and fog of war is located in Terrain_splatTile.fx file.

Here is what I did so far:

Link to video.

Here is what I changed in Terrain_splatTile.fx:
- I added fFrameTime variable which is responsible for scrolling the UV of the texture
- when Fog of War texture is 0 (so when it is black) then I replace the FOW texture with the base terrain texture

shader.png


The problem is that I don't know how to inject external texture of the cloud. AFAIK it is not possible in HSLS language, so it needs to be injected by the C++ code of the application which we don't have source code to.

Another problem is that when the fog of war is not black we can see other objects in fog such as trees and rivers which are probably handled in other shaders or even in EXE code.

Does anyone know HSLS language or know how to hack EXE file to inject texture to the shader? Anyone tried to change fog of war in Civ4?

I have attached the modified shader source code + compiled FXO. If you want to try it out, you should copy it to your Beyond the Sword shader folder i.e. D:\SteamLibrary\steamapps\common\Sid Meier's Civilization IV Beyond the Sword\Beyond the Sword\Shaders\FXO
 

Attachments

  • FX.7z
    6.4 KB · Views: 23
Ok, I fiddled with the shader code and now it looks like this:


Link to video.

I used terrain textures in shades of gray as cloud textures for now. I also added infinite texture scrolling and smooth transition between cloud and terrain textures.

Now the biggest problem will be to hide the other objects in the fog of war, i.e. trees or rivers.

For those interested, a fragment of the shader code:

C++:
    float4 f4CloudColor = 1.0f;
    float fCloudSpeed = fFrameTime * 0.05f;

    float2 cloudUV = float2(Input.f2BaseTex.x, Input.f2BaseTex.y);
    float2 cloudOffset = float2(fCloudSpeed, fCloudSpeed);

    float2 scroll = cloudUV + cloudOffset;
    float3 res = tex2D(TerrainClouds, frac(scroll));

    f4CloudColor.r = res.r;
    f4CloudColor.g = res.g;
    f4CloudColor.b = res.b;
    f4CloudColor.rgb *= 1.5f;

    if (f3FOWTex.r == 0) {
        f4FinalColor = f4CloudColor;
    } else {
        f4FinalColor = lerp(f4CloudColor, f4FinalColor, f3FOWTex.r);
    }

Oraz skompilowany shader z załączniku.
 

Attachments

  • Terrain_splatTile.7z
    3.6 KB · Views: 19
Ok. I am getting there I guess. I managed to hide trees and rivers from the clouds. Now its time to deal with the rest of the visible land on the outskirts of the for. This could be tricky cause I don't know which shader is responsible.

Here is how the clouds look now:

Link to video.
 
Wow, this is making swift progress. I can't really contribute anything on the shader/ texture front. Was going to suggest destroying the river and feature "symbols" on unrevealed plots through the DLL, but I see that you've already found a way, and I don't see how the DLL could manipulate the coastlines. (Assuming that this is indeed the problem now; looks like the clouds only appear above land in the video.)
 
The only thing I want to suggest is trying to make the clouds tile better. Right now you can really see the seams.
 
To anyone interested in beta testing the shader. You can download it with new 1.4.0 beta version of Civ 4 Remaster Mod on https://forums.civfanatics.com/thre...-tileset-new-look-and-city-bar-update.671590/


Link to video.

I will continue development progress there too keep things in order. Also if you are interested in development you could check the github repo on https://github.com/tomekumb/civ4remaster.

Wow, this is making swift progress. I can't really contribute anything on the shader/ texture front. Was going to suggest destroying the river and feature "symbols" on unrevealed plots through the DLL, but I see that you've already found a way, and I don't see how the DLL could manipulate the coastlines. (Assuming that this is indeed the problem now; looks like the clouds only appear above land in the video.)
It got me hooked all day. But it wasn't easy. Many trial and errors and I finally learned something about shaders. It was a mystery to me.

As for the clouds. Well, now the clouds texture is fetched from detail texture of specific tile beneath the fog. So for every tile type (desert, grassland etc.) i takes different detail texture from terrain/textures folder. In my texture pack most of the detail textures are the same except for desert. So it would be nice to get specific texture in the future. Although I have no idea how to hack EXE.
The only thing I want to suggest is trying to make the clouds tile better. Right now you can really see the seams.
Yes, as I mentioned. The texture is fetched from detail texture of specific tile. This texture is then scrolled within specific tile and wrapped on both ends. I really don't know how to deal with this issue. Maybe there is a way to make the cloud texture more seamless or other magic trick with the shaders. I will try my best.
 
Generally when ever I have issues with tiling it's because the texture it self does not tile nicely. As in, the left corner is not the same as the right etc. And I deal with that by manually tiling the texture, flipping it around and making a 2x2 square that I than resize down to the original size.
 
Generally when ever I have issues with tiling it's because the texture it self does not tile nicely. As in, the left corner is not the same as the right etc. And I deal with that by manually tiling the texture, flipping it around and making a 2x2 square that I than resize down to the original size.
Thanks for help. The actual problem was that I used terrain texture UV instead of fog of war UV and thus the cloud texture was distorted. Now the clouds look almost good. There is a minor issue with cloud over desert tile but I will try to fix it in near future.


Link to video.
 
Last edited:
@tomekum
Since the "Shaders" folder is not part of "/Assets", can it still use normal mod mechanics to simply override Vanilla?
Or is it really necessary to change the files of Vanilla directly? (Which is something I would rather not do for our mod.)
 
@tomekum
Since the "Shaders" folder is not part of "/Assets", can it still use normal mod mechanics to simply override Vanilla?
Or is it really necessary to change the files of Vanilla directly? (Which is something I would rather not do for our mod.)
The /Shaders folder contains FXO folder, which are responsible for the clouds effect. But unfortunately the game engine ignores shaders in the Assets folder of the mod. So if you want the clouds effect to work you must override the shaders folder in the base (vanilla?) game. So you must copy the FXO folder from the mod and override the FXO folder in the base game (in steam its usually C:\SteamLibrary\steamapps\common\Sid Meier's Civilization IV Beyond the Sword\Beyond the Sword\Shaders). Don't forget to backup FXO folder in the base game, so you can always go back to standard fog of war.
 
But unfortunately the game engine ignores shaders in the Assets folder of the mod.
Thanks, that is what I wanted to know. :thumbsup:

I will discuss it with the rest of the WTP team if we want to change shader files in the Vanilla folder by our mod installer. :think:
(Since with the next release we plan to install files in Vanilla folders for our multitthreading anyways me might also change shaders.)

But since we would be changing files on installations of thousands of our players ... it needs to be well considered. :dunno:
(I would strongly prefer that players just install the mod and then do not need to worry about any manual steps anymore.)
 
Last edited:
Have you tried using the custom assets folder?
 
Top Bottom