🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Fog of War in C++ and OpenGL GLSL

Started by
0 comments, last by yaboiryan 1 year, 9 months ago
         landscape.Use();
        for (int i = 0; i < 256; i++) {
            for (int j = 0; j < 256; j++) {
                glUniform1f(glGetUniformLocation(landscape._program, "incrementedValuex"), i);
                glUniform1f(glGetUniformLocation(landscaper._program, "incrementedValuez"),j);
              if(i < 64)
               {
                glUniform1f(glGetUniformLocation(landscape._program, "isShown"), 0);
                }
               else
                glUniform1f(glGetUniformLocation(landscape._program, "isShown"), 1);
               }
            }
        } 

The above code is my main.cpp file.

	if(!(isShown == 1) && incrementedValuex / 256 == pass_textureCoords.x && incrementedValuez / 256 == pass_textureCoords.y)
	{
		backgroundTextureColor = texture(backgroundTexture, tiledCoords) * 0;

		rTextureColor = texture(rTexture, tiledCoords) * 0;
		gTextureColor = texture(gTexture, tiledCoords) * 0;
		bTextureColor = texture(bTexture, tiledCoords) * 0;
	}

The above code is my landscapeShader.frag file.

Ok so basically I want to program fog of war like that which is shown in Empire Earth or Civilization. Fog of war is basically where you have a landscape, and parts of the landscape are not shown to the player when they are playing the game, so that they have no real idea what the landscape looks like at that area. At the moment, I am just trying to make the landscape black out at some points, and I want the terrain to update every 2 seconds. To do this, as shown in the main.cpp file, I attempt to get all the points of the terrain, and I send them to the fragment shader.

If the isShown variable is 0, then it hides the terrain.

After doing this, I check the equality values with the pass_textureCoords variable, which is equal to roughly 1/256 of the incremented value. To finish up, I check to see if the value is even visible. However, this does not work, and the entirety of the terrain either shows up or does not show up, based on the isShown variable, indicating that the value is applied to each point of the terrain, which confuses me.

If anyone has any ideas to how I can fix this or a better way that I could do fog of war with GLSL, please let me know! If any information is vague, I will do my best to improve it for those parties which are confused.

Update:

It kind of works, but it only is a shadow which follows behind one : troop number 3. I want it to follow every troop. I want to be able to put an interval between the two troops and the shader put a shadow in between them based on their x values.

Here is what I have so far:

I am planning on having hundreds of troops on the battlefield at once, so I cannot just create a bunch of variables to manage the positions. I also cannot create a 2D array in the GLSL shader because it is not supported.

This topic is closed to new replies.

Advertisement