- Home /
How to apply a gradient to a 2D mesh?
I'm creating procedurally generated 2D terrain and want to apply a simple vertical gradient to it, I've tried to use an image of a gradient as a material on the mesh (just an unlit/texture shader with the image), but for some reason it's always a solid color. I've attached an image of what I'm trying to achieve. Any suggestions?
PS the terrain is made by randomizing top points on a quad and then putting those randomized quads next to eachother.
Thanks in advance!
I've usually seen this done with a shader. The shader bases the color upon the vertical coordinate of each point it draws. Alternatively, you could use a colored vertex mesh (colors are optional in meshes, and require a color vertex shader to work.) This would look more "blocky" that the first method, which would be able to provide a smooth gradient. e.g. http://answers.unity3d.com/questions/882134/shader-based-on-vertex-height.html