- Home /
Age of Empire Mini Map
If anyone played this game before, you know that the minimap starts out black, and only revealing areas the player has units at. Areas the player explored will maintain revealed, but a fog of war shadow will be casted over it.
Im trying to create a mini map like that, and the way Im planning to go about is to set up 3 layers of images. The bottom one being the actual map, then the fog in the middle, and a black texture on top.
If the player is colliding with a pixel, the black pixels will turn transparent permanently, while the fog pixels will stay transparent only if they are colliding.
My question is, how can I access the coordinate of the pixel that my player is colliding with? I know RaycastHit.textureCoord can locate a single pixel, but if my player is larger than one pixel (which it will obviously be), then I need all the pixels my player is colliding with, is there a way to do this?
If there is another to do the minimap, that will help too.
Assu$$anonymous$$g that the player clears FoW in a circular pattern, then you can just use a mathematic function to get all the pixels around the initial one your player hit.
@figghder adding screenshot of what you exactly want will help others to recognise your problem quickly
Answer by zach-r-d · Jun 14, 2015 at 08:46 AM
If you know the coordinate of the center of the player, and the distance from the player that you want to be revealed at all times (radius), you can iterate over all of the pixels that are currently within sight of the player with a double for loop; here's some pseudocode:
for (x = playerX - radius; x <= playerX + radius; x += 1/textureWidth) {
for (y = playerY - radius; y <= playerY + radius; y += 1/textureHeight) {
if (distance from (x,y) to (playerX,playerY) <= radius) {
/* the pixel at texture coordinate (x,y) has been uncovered */
}
}
}
Then you could clear the pixel at that location in the black texture and the fog pixels, and at the beginning of the next frame set the entire fog texture to the default color.
that will be one way to go about it, but I was wondering if this will be the most optimized way of going about it.
It's possible to only reset the previously revealed section of the fog pixels rather than the entire thing, and it may or may not be more performant to use the midpoint circle algorithm (ins$$anonymous$$d of iterating over the square containing the circle and checking the distance at every point). Additionally, the distance check can compare squared distances ins$$anonymous$$d of real distances, naturally, to save a square root. Beyond that, I don't know if it's possible to optimize further, apart from doing everything in shaders.
Regardless, unless these textures (and the player's sight radius) are really huge, I don't think performance will be a major problem.
Do you have any idea how I should do it if I were to do it on shaders?
Sure. Each of the images would be rendertextures ins$$anonymous$$d of images, and would be re-rendered every frame. In the fragment shader, the same distance check described above would be performed based on that, and would deter$$anonymous$$e whether the pixel would be transparent or not. Things like player position and sight radius would be properties passed to the shader through the material.
Your answer
Follow this Question
Related Questions
Trying to create 2D pixel art lighting 1 Answer
Pixelated Sprite Lighting 0 Answers
How to make 2D water like in Celeste 0 Answers
How to efficiently render a 2D grid? 1 Answer
Wheres the snap to pixel option in the shader/material editor? 1 Answer