f13rce Posted August 21, 2013 Share Posted August 21, 2013 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: Any ideas how to make fog of war in Leadwerks 3? Quote 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 More sharing options...
Naughty Alien Posted August 21, 2013 Share Posted August 21, 2013 ..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.. 2 Quote Link to comment Share on other sites More sharing options...
Aily Posted August 21, 2013 Share Posted August 21, 2013 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). Quote "Better" is big enemy of "good" Link to comment Share on other sites More sharing options...
AggrorJorn Posted August 21, 2013 Share Posted August 21, 2013 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. Quote Link to comment Share on other sites More sharing options...
Flexman Posted August 21, 2013 Share Posted August 21, 2013 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. 3 Quote 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 More sharing options...
Daimour Posted August 22, 2013 Share Posted August 22, 2013 Just a picture for Flexman's method (with shader one). Fog of War.pptx.rar 2 Quote Link to comment Share on other sites More sharing options...
Admin Posted August 22, 2013 Share Posted August 22, 2013 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) 1 Quote Link to comment Share on other sites More sharing options...
shadmar Posted August 24, 2013 Share Posted August 24, 2013 Oh I like this, writepixel, neat. Maybe I can splat blood now Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
shadmar Posted August 25, 2013 Share Posted August 25, 2013 Seems commented i Texture.h //virtual void WritePixel(const int x, const int y, const char r, const char g, const char b, const char a, const int miplevel=0, const int framenumber=0)=0; Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
f13rce Posted August 27, 2013 Author Share Posted August 27, 2013 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. Quote 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 More sharing options...
Recommended Posts
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.