Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by fighder · Jun 14, 2015 at 08:12 AM · 2dshaderpixelminimap

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.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image idurvesh · Jun 14, 2015 at 08:27 AM 0
Share

good question

avatar image Cherno · Jun 14, 2015 at 08:42 AM 0
Share

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.

avatar image idurvesh · Jun 14, 2015 at 08:44 AM 0
Share

@figghder adding screenshot of what you exactly want will help others to recognise your problem quickly

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fighder · Jun 14, 2015 at 07:09 PM 0
Share

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.

avatar image zach-r-d · Jun 14, 2015 at 07:24 PM 0
Share

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.

avatar image fighder · Jun 14, 2015 at 07:31 PM 0
Share

Do you have any idea how I should do it if I were to do it on shaders?

avatar image zach-r-d · Jun 14, 2015 at 07:38 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges