Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by Vosheck · Apr 15, 2019 at 10:42 AM · shadermapcolor changeoverlaymaps

What is the best way I could recolor all the pixels of a certain country on a texture of a political map(for achieving a map mode system such as in a grand strategy game)?

I'm using a texture of a political map where all the countries are painted with a unique color. I can assign data and know what the pointer is clicking/hovering over. So an example of an overlay would be:

Germany is color coded gray and has a high GDP. The shader draws dark blue where all the gray colored pixels are in the texture to show a high average GDP in the area of Germany. Moldova is color coded green and has a low GDP. The shader draws light blue where all the green colored pixels are in the texture to show a low average GDP in the area of Moldova. The darkness of the blue is determined by a dynamic GDP value from the data of a country. It would be very preferable if the texture of the map remains in 1 piece due to the normal map(hills and depressions) An answer to this would be to have a conditional in the shader per color of the color coded countries, but it would be extremely slow. Another answer would be to somehow flood fill all the countries and recolor them in order to create a new texture, but it would also be slow.

Looking to achieve such an effect as demonstrated in this video about Crusader Kings 2 map modes https://www.youtube.com/watch?v=hllUdi73h70

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Pangamini · Apr 15, 2019 at 12:45 PM

The problem with color coding (Eg. using the exact numeric value to mark a country) means you cannot use any kind of filtering (like bilinear) or mipmaps. The interpoloation would generate invalid IDs. But IF you are OK with that (which I doubt), you could use an array of colors instead of conditionals (pick the color from the texture, calculate the array index, pick the color from the array). But you still have to implement the filtering in the shader (or have no filtering), which may be slow too.

I think the best option here would be to have separate single-channel texture for every country (also this doesn't have to mean that each country texture covers the whole world, you'd just map it to the correct position). Your reason for not splitting the map is "due to the normal map". Can you elaborate on that?

Comment
Add comment · Show 6 · 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 Pangamini · Apr 15, 2019 at 12:46 PM 0
Share

Also, have you considered using a geometry (mesh) ins$$anonymous$$d of the texture to represent the country shape?

avatar image Vosheck · Apr 15, 2019 at 02:21 PM 0
Share

What I mean by "normal map" is https://eu4.paradoxwikis.com/$$anonymous$$ap_modding#Normal_map Figured it would be the best to use large world maps representing various things like in the aforementioned link for greater flexibility. I'm trying to make a grand-strategy game, so why not try to emulate how the pros are doing it.

avatar image Pangamini Vosheck · Apr 15, 2019 at 02:24 PM 0
Share

I understand what a normal map is, but I don't see why is it relevant in your question?

avatar image Vosheck Pangamini · Apr 15, 2019 at 02:33 PM 0
Share

It is relevant to my question because I would like to find a way to do the aforementioned map modes, without sacrificing the flexibility of the system being able to dynamically piece together the political map, the normal map, rainfall map... and others from images.

I could of course do it more manually with single channel textures, but I'm just trying to find out if anyone has an idea about the less manual way.

Show more comments
avatar image Bunny83 Vosheck · Apr 15, 2019 at 04:18 PM 0
Share

Hopefully you have your own texture maps and you do not use those copyrighted images ^^

avatar image
0

Answer by Bunny83 · Apr 15, 2019 at 04:05 PM

Actually recoloring your map isn't that expensive. You can use my Floodfill extension, however since you want to fill in several regions at once a slightly modified version would be better so you don't have to use GetPixels / SetPixels for each area you want to fill. You usually don't have to update this texture that often, only when you change the settings


It is possible to do this completely with shaders, however this requires that your color codes are an actual encoding of some sort of country index. There was a similar question some years ago about creating a selectable map. To do the overlay you just have to encode the desired tint color in a lookup texture where each pixel in that texture corresponds to one country. So in the shader you can use the color encoded index of a pixel of your map to lookup the desired tint color in the lookup texture. This would be done in the fragment shader for each pixel. All you have to do when you want to change the tinting, is to replace / edit the lookup texture. The texture could be a 1 pixel high and x pixel wide texture where x is the number of countries / destinct regions you have. However it's usually better to create a square texture and just encode the indices row by row. With a 32x32 texture you can encode 1024 distinct areas. So a 256x256 is enough for 64k.


Since we don't know how you actually have color coded your countries / area it's up to you to implement this for your data.

Comment
Add comment · 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

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

167 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 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 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 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 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 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 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

Apply Shader to overlay GUI 0 Answers

How to curve country meshes based upon a flat projection, into a sphere? 2 Answers

Two shaders for one model 3 Answers

Google API in unity? 0 Answers

Modifying my shader to overlay rather than blend. 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