- Home /
Change color of particles by distance from emitter
Hi!
I am trying to create a static grass area with particles and I've been researching how to change the color of the particles depending how far are from the emitter, but I had no luck. Because I need the grass to look yellow in the far edges of the grass area.
If you can point me in the right direction or have some similar shaders I will really appreciate it.
Thanks
PD: why I am doing grass with particles? Great question, I am experimenting in ways to make great performance grass area for Augmented Reality in mobile. If you know any other way, let me know!
Answer by richardkettlewell · Sep 04, 2018 at 08:06 PM
The only way to do this efficiently is to do it in the shader. You would need to write a custom shader to do it. Then you take the distance from each vertex to the Transform center, remap it to 0-1, and use that to blend the color towards your yellow color.
Thank you Richard! I will try to do it, I am a bit clumsy with shaders barely touch them but I am willing to try to do what you advise.
A tip: particles don’t set unity_LocalToWorld, so you must send Transform.position to the shader manually from a script. Good luck!
Answer by telecaster · Sep 04, 2018 at 08:52 PM
not sure if this helps: https://answers.unity.com/questions/1428669/color-of-vertex-based-on-player-distance.html
also there is a way to fake these things. https://assetstore.unity.com/packages/tools/utilities/amplify-impostors-beta-119877 allows hardware instancing which might help.
Thanks a lot! never used Amplify. Thanks for the suggestions.
Your answer
![](https://koobas.hobune.stream/wayback/20220612174048im_/https://answers.unity.com/themes/thub/images/avi.jpg)