- Home /
How to apply gradient to sprite at runtime?
Hi there!
I am trying to achieve an effect whereby a flat 2D sprite has a gradient applied to it at runtime, so it can be reused with different colours different times.
This ugly star is a good example. Is this possible?
Answer by tanoshimi · Nov 05, 2016 at 01:31 PM
Sure - you can lerp between two colours based on the UV coordinates assigned to the vertices.
Hey, thanks for the reply. So I understand lerping, and I understand UV coordinates, but the one (probably obvious) thing I'm still unclear on is how would I then apply the lerp-calculated colours to the sprite?
Is it all getPixel and setPixel? Would that be painfully slow?
Yes, that would be horribly slow :) Do it in the shader ins$$anonymous$$d - lightning fast!
Your answer
![](https://koobas.hobune.stream/wayback/20220612100055im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Sprite Mask that affects only the childrens of a GameObject 5 Answers
Shaders to show damage? 1 Answer
Masking with Mesh Renderer (2d) 1 Answer
Cut out sprite alpha using other textures 1 Answer
Why is my picture distorted? 0 Answers