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?
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.
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.
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).
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.