Jump to content

How to make Fog of war?


f13rce
 Share

Recommended Posts

Hi all,

 

So I'm currently making my RTS/MOBA game.. Now I'm kinda stuck at making Fog of War. Honestly I have no idea how to make it. I was thinking about making a plane make surfaces fully transparent whenever a friendly unit is near, but I'm sure some of you know a better way to do this.

 

The fog of war always needs to be a bit transparent so you know what's in that area (like trees and such). Basically like this:

post-358-0-53002600-1377048383.jpg

 

Any ideas how to make fog of war in Leadwerks 3?

Using Leadwerks Professional Edition (Beta), mainly using C++.

Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz

Previously known as Evayr.

Link to comment
Share on other sites

..well..you could have plane between your terrain and your camera then raycast from your player against the plane. Then lighten raycasted hit point area's vertices/texture alpha transparency UV based. If you want to avoid raycasting, you can then use bunch of bounding boxes, you have populated over whole surface of your world so, once triggered, lighten up vertices/texture alpha transparency UV based, on the top of triggered bounding box. So, entities (NPC's) outside of already triggered bounding boxes will not be rendered(hidden)..something along this line will do trick..

  • Upvote 2

 

Link to comment
Share on other sites

Agree with Naughty Alien.

Simplest way is mesh plane subdivided to control each vertex alpha (raycasting code).

But faster to render is big plane with 2 triangles and texture on it (here draw to buffer code needed).

"Better" is big enemy of "good"

Link to comment
Share on other sites

My method works but is not as professional as the ones provided above: I have the world divided in a grid. Every cell has a dark overlay depending on your style of fog of war. This could be a transparent plane or particles.

The cell holds a simple bool that tells objects to be hidden yes or no. When enemies collide with the AABB of the cell, they check this bool.

The material of these enemies is swapped with the invisible material.

Link to comment
Share on other sites

To improve performance don't do your LOS or FOG map updates every frame, every 0.5 seconds might be good enough.

 

If using a fog-map (a black texture on which you paint a fuzzy white blob around each player unit) you can use this fog map in a couple of ways.

 

As suggested above; paint it to a plane in front of the camera but above the landscape (ho hum simple but topography won't match unless you use a low res mesh version of your level topography).

 

A better method is to pass fog-map as a texture to a full screen post-processing shader. You compute the sample position of the fog-texture based on your camera position above the map and modulate the frag color ( using mix() ) output from the camera buffer with the fog-map.

 

For mobile you'll want to modulate the vertex output color for the scene.

 

If you only want it to mask singular entities, use a point sample from the fog texture to modulate the entities alpha color. OR simply use an array as a grid and for each unit update the value of surrounding cells and use that to set the alpha of enemy units.

 

So many choices.

  • Upvote 3

6600 2.4G / GTX 460 280.26 / 4GB Windows 7

Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT

Tricubic Studios Ltd. ~ Combat Helo

Link to comment
Share on other sites

You need to define the behavior more precisely. Does it just follow the player around and light the area around him, or does it illuminate areas the player has already been?

 

You could create a black texture, then write one pixel at a time based on where the player is. Just do something like this to calculate the tex coord:

Vec3 position = entity->GetPosition(true);
position.x = Math::Round((position.x + fogarea/2) / fog scale);
position.z = Math::Round((position.z + fogarea/2) / fog scale);
fogtexture->WritePixel(position.x,position.z,255,255,255,255)

  • Upvote 1

 

 

Link to comment
Share on other sites

Thanks for the comments so far, I really like seeing this topic evolve.

 

I'll take a good look into Flexman's advice with the shader. I've never made a shader before so this will be fun.

 

You need to define the behavior more precisely. Does it just follow the player around and light the area around him, or does it illuminate areas the player has already been?

Every area is ~50% bright by default because of the fog of war. The fog becomes invisible if the player (or a friendly unit) is near.

Using Leadwerks Professional Edition (Beta), mainly using C++.

Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz

Previously known as Evayr.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...