- Home /
How do I change the color of a texture in a specific radius?
I am working on an idea where I have several colored characters moving around a white map, and as they move I want them to leave a trail of color behind them, however I cannot find anything about changing color of textures in real time.
I have though of other ways to achieve this effect, like placing a model with a proper colored texture on top of the surface.
A while back in XNA I used render targets to create a black overlay for a map and cleared a circular area around lights using alpha blending.
If any of these things are possible, any advice on how to proceed would be greatly appreciated.
Thank You.
Could you elaborate? What kind of map(is it just a flat plane, whats our perspective, is it 2d/3d).
Sounds like something that needs a solution very specific to what you want to do, since performance should be an issue.
ideas: -maybe you can do something with the trailrenderer -maybe you can use the unityterrain, and paint the spot the characters walk on -maybe you can solve it with something like spawning particles or semitransperent planes where the characters walk
Sure, it's 3D, I want to start with a flat plane, but eventually adapt the method into any type of texture, so for now I would like to focus on how it would work on a flat plane, 3rd person camera.
You can change the pixel values of a texture directly. Take a look at methods Texture2D. But mapping your world coordinates to specific places on the texture could be a real pain.
You could leave game objects at bread crumbs. As long as they all have the same material, and you don't change the material at runtime, they will be batched together into a single draw call. But if the path can be long, you end up with a bunch of game objects that could hurt performance.
The Vectrosity is a line drawing package in the AssetStore. They have API for both 2D and 3D lines (including dotted lines). For an array of 3D lines, Vectrosity builds a single mesh, so there will be only one game object and one draw call for the entire path. I don't know how they handle 2D.
Apart from Vectorsity you could take their approach and dynamically build and expand a mesh as the players walk around.
The trail render works as a tracer to deter$$anonymous$$e where things have been, but I was looking more for something that can actually change a texture.
Sorry if it was not too clear to start.
Answer by MountDoomTeam · Jan 30, 2013 at 11:40 AM
actually I have done a lot of this! And nice name!
Every time that you use another texture it uses a lot of processing power.
You're supposed to use one texture with lots of colours like a pallette, and use it like a texture Atlas. get whatever meshes you want texture, when you instantiate them, and change all their UV coordinates to a single point, for example if you wanted them to be white, change all the UVs to 1, 1, the corner of the pallet, and 0.5, 0.5 let's say would the blue.
You would need an image you know the colour coordinates of, but that's a very efficient way to do it in unity, there is even a code somewhere on this forum by someone Bentley I think to change mesh UVs into points.-that's the way I would do it because it's really convenient to know how to do, I should upload it to unify wiki actually. http://answers.unity3d.com/questions/13316/how-to-move-uvs-of-a-mesh-so-you-can-have-two-text.html
Another option is that you can change the colour in code of the material http://wiki.unity3d.com/index.php?title=Animated_Color_Procedural_Texture
Although I think that uses the same as a different texture for every texture, maybe it's okay if you use shared material, I don't think it's draw call efficient.
another thing to know about is there is a shader that allows you to use to textures with transparency on an object in the unity wiki.
Your answer
![](https://koobas.hobune.stream/wayback/20220613091824im_/https://answers.unity.com/themes/thub/images/avi.jpg)