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
0
Question by Happy-Zomby · Jun 18, 2021 at 05:18 PM · lightingscript.colorspritescolorpicker

Get "on screen" color of a texture to use in a legend

Hello all,

as you can see in the below, I'm trying to set up a legend for my generated map.

Problem is that the colors of my sprites in the legend are not impacted by the scene lighting and therefore do not match the actual in-game colors. Eg. the mountain is much darker in the legend than in the lighted scene.

I could copy the colors and manually modify the sprite but my colors come from a generator and, to help accessibility, I would like to give the user the possibility to change them... e.g. make mountains Black in the settings, rivers - magenta. Or to change the lighting intensity.

Any suggestion on how to get the actual game colors and map them to my legend sprites - in run time / after the map generation?

I was thinking of taking a printscreen - after generation - and trying to read colors from that but I'm wondering if there is an easier way.

Is this the way to go, or should I approach this in a different way?

Thanks a lot,

alt text

legend-and-colors.png (107.3 kB)
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
2
Best Answer

Answer by tuinal · Jun 18, 2021 at 11:25 PM

Use an unlit shader for the map? As I understand it I don't think you're trying to light the map, it's more that the fact it's lit is undesirable?

There is a default unlit shader in the default and URP pipelines. Just changing the material of your map tiles to this shader would fix the problem if my above understanding is correct.

Comment
Add comment · Show 1 · 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 Happy-Zomby · Jun 19, 2021 at 09:29 AM 0
Share

mmm - I was thinking the give the users the possibility to adjust the lighting... but your comment gets me thinking that they could achieve the same results by selecting the colors in the menu. I'm - like often - overcomplicating. I'm guessing also that an unlit shader will help performance. In fact I already use it on some elements, just not the map tiles. I may find a reason why I need the lighted textures but nothing pop ups for the time being. THANKS for helping me keep it simple.

avatar image
1

Answer by Sinterklaas · Jun 18, 2021 at 08:07 PM

If I understand correctly, you have a map texture on a quad in the scene, that receives light. You want to be able to change the colors in the source sprite before lighting is applied?

If that's what you're trying to do, I think there are two ways to do it.


  1. Make a copy of the source sprite in your game object's Awake function, and whenever the player changes one of the target colors, find all pixels with the current color and replace them. You'll want to look into the Texture2D.GetPixels and Texture2D.SetPixels functions for this. Don't forget to call Texture2D.Apply after calling SetPixels or the changes won't be visible. This might be very slow however, depending on how often you expect these colors to change, and you'll have to keep the texture in memory twice (I don't think you can modify the source texture directly at run-time, but I might be wrong there, definitely look into that if you go this route).


  2. Use a shader, where all your colors are float properties. For every fragment, figure out what the fragment represents, and replace it with the desired color. Then apply lighting. This is probably the more performant way to do this, but will likely take you longer to implement if you are unfamiliar with shaders.


Does that help you?

Comment
Add comment · Show 1 · 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 Happy-Zomby · Jun 18, 2021 at 10:54 PM 0
Share

Hi, Thanks but that is not my issue.

Sorry if I wasn't clear - what I'm trying to do is a legend for my map. My legend is a UI and use sprites. My map tiles are planes or cubes and use textures. For example, my mountain tile is by default the color #5B504C but user will be able to override this color in the game settings. My problem is that the UI/sprite color #5B504C displayed in the legend does not look the same color as the actual tile in the game even if its texture color is #5B504C - due to the lighting. I'm trying to find a way to have these 2 visually match - meaning the color displayed in the legend for the mountain is the same as the color of the mountain on the map. See attached picture. Neither the colors nor the lighting will change once the game is launched and the map is generated.

Thanks a lot for your help and any pointers you may have, alt text

picture1.png (126.6 kB)

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

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

Why change the light color so fast? 2 Answers

Using URP how to make sprites lit by 3D Lights again? 6 Answers

My game is too dark... 3 Answers

How to edit this shader to use diffuse lighting (2D) 0 Answers

White sprites with normals/light, its possible? 0 Answers


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