- Home /
Vegetation animation on non-terrain mesh? [YES]
Hello, I'm going to have to use vegetation on a non-terrain custom mesh. And I understand (but correct me if I'm wrong) that Unity's automatic grass animation (softly blowing in the wind) wouldn't work in that case.
So my question is: what would be the best way (and hopefully the most efficient one) to still get grass/bushes procedurally animating, so they don't look like they're made out of concrete?
ouch, create your own procedural animator, i know the terrain system does it by a masterful use of multiple textures and pro use of texture bending and manipulation/distortion.
because im not that BA, id sadly say you would just create a set of 2D textures which you could then animate in Unity, like a gif animation.
other option, if you are trully Bad Ass with unity you can turn your custom mesh into a unity terrain. Ive dont this before, its a painful process, its worth it simply for all the functionality and optimizations afforded by terrain, but a true nightmare simply because its the bowls of unity terrain which is indescribably a beast to work with, its really different from anything in unity.
What are you trying to do? Can you post any screenshots or ideas?
If I'm right, you want some kind of vegatation to let's say, crawl up a wall, right? I'd say check out the options with UV Scrolling. I can't thank of anything easier.
huh, thats a smart trick, ill have to remember that one, though he did mention wind being involved so im guessing like wheat bending in the wind.
Thanks for your replies, guys. I'm basically looking to have the normal grass animation that happens when you paint grass patches (as in real poly-plane models, not texture) on Unity terrain. But on a normal mesh (not a terrain).
The interesting thing though is that I started doing some research with trees (using the Tree Creator) and believe it or not the bending-in-the-wind behavior is present, even when the trees are just dragged and dropped in the scene view. Provided a wind object lives nearby of course.
So in other words, if I can get grass to gently flow in the wind in the same way, then my original question becomes a moot point! Now does anyone know where I can access some Unity grass example models, so I can see how things are setup, please?
so I definitely have a very uncommon knowledge of unity's terrain system. It is unlike anything else in unity. The terrain system takes a grass texture and somehow turns it into what you see on terrain. How this is done is not known because its done in the terrain system. additionally the terrain system does hundreds of crazy optimizations just to make it all possible. including calculations based on player position, rendering and so on.
the reason i said all this is to illustrate the magnitude of what you are asking when you say you want to emulate something that the terrain system does. What you are asking essentially is to recreate that system which is nuts if you arent committed to that.
You are not going to be able to do this to the extent of unity grass. I would do this by animating the texture of the crop on a plane and just having the plane lookAt the player
but i can tell you right now, NO ONE is going to give you an answer that resembles the unity grass. Simply because i have asked easier questions
Answer by Seith · Jan 14, 2013 at 11:13 AM
Well, I finally got around to tackling this issue and I'm happy indeed to report that yes, it is possible to benefit from Unity's grass/wind bending system even on custom terrain meshes!
@Lil_billy: Well, it took me about an hour of hard thinking to come up with a simple system. But that's because I'm still fairly new to Unity shaders, I guess.
For those interested, I basically tweaked the hidden "WavingDoublePass" Unity shader (used by the engine for grass/foliage waving) so that it actually supports standard textures with alpha.
Then I just applied a material based on this shader on my custom bush model. And I simply animate the built-in waving frequencies of the material over time and voila! Again, this is no complex new system, but rather a simple extension of the built-in system.
The goal being that I can now put procedurally animated vegetation on any mesh, not just official Unity terrains.
And a picture of my WIP project, since we're at it:
This is really great! I've been looking for and experimenting with shaders to achieve this exact effect. All. Day. Long.
Would you consider sharing a sample project or exported package that includes your modified shader and an example material and test scene? It would be a truly tremendous resource for me, and likely for other Unity shader newbies, to learn from! Pretty please? :)
@AlwaysSunny: Well I've just discovered a package that seems to do the same thing and then some: http://forum.unity3d.com/threads/133398-Advanced-foliage-shader-released. The only thing I'm not sure about is if it's compatible with Unity 4 and DX11. I have asked the question but haven't heard back from the author yet.
$$anonymous$$eanwhile, here's my simple shader solution:
Shader "Custom/WavingDoublePass" {
Properties {
_WavingTint ("Fade Color", Color) = (.7,.6,.5, 0)
_$$anonymous$$ainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
_WaveAndDistance ("Wave and distance", Vector) = (12, 3.6, 1, 1)
_Cutoff ("Cutoff", float) = 0.5
_Cutoff2 ("Cutoff2", float) = 0.5
}
SubShader {
Tags {
"Queue" = "Geometry+200"
"IgnoreProjector"="True"
"RenderType"="Grass"
}
Cull Off
LOD 200
Color$$anonymous$$ask RGB
CGPROGRA$$anonymous$$
#pragma surface surf Lambert vertex:WavingGrassVert addshadow alphatest:_Cutoff2
#pragma exclude_renderers flash
#include "TerrainEngine.cginc"
sampler2D _$$anonymous$$ainTex;
fixed _Cutoff;
struct Input {
float2 uv_$$anonymous$$ainTex;
fixed4 color : COLOR;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_$$anonymous$$ainTex, IN.uv_$$anonymous$$ainTex) * IN.color;
fixed4 d = tex2D(_$$anonymous$$ainTex, IN.uv_$$anonymous$$ainTex);
o.Albedo = c.rgb;
// o.Alpha = c.a;
o.Alpha = d.a;
clip (o.Alpha - _Cutoff);
// o.Alpha *= IN.color.a;
}
ENDCG
}
SubShader {
Tags {
"Queue" = "Geometry+200"
"IgnoreProjector"="True"
"RenderType"="Grass"
}
Cull Off
LOD 200
Color$$anonymous$$ask RGB
Pass {
Tags { "Light$$anonymous$$ode" = "Vertex" }
$$anonymous$$aterial {
Diffuse (1,1,1,1)
Ambient (1,1,1,1)
}
Lighting On
Color$$anonymous$$aterial AmbientAndDiffuse
AlphaTest Greater [_Cutoff]
SetTexture [_$$anonymous$$ainTex] { combine texture * primary DOUBLE, texture }
}
Pass {
Tags { "Light$$anonymous$$ode" = "VertexL$$anonymous$$RGB$$anonymous$$" }
AlphaTest Greater [_Cutoff]
BindChannels {
Bind "Vertex", vertex
Bind "texcoord1", texcoord0 // lightmap uses 2nd uv
Bind "texcoord", texcoord1 // main uses 1st uv
}
SetTexture [unity_Lightmap] {
matrix [unity_Lightmap$$anonymous$$atrix]
combine texture * texture alpha DOUBLE
}
SetTexture [_$$anonymous$$ainTex] { combine texture * previous QUAD, texture }
}
}
Fallback Off
}
Just to confirm that the page I linked to indeed offers a very nice solution for manually placing vegetation by hand and still have leaves/branches waving in the wind. It's 10 bucks, but in my opinion it's well worth it.
Thankyou Seith for all the informations.
Please can you you explain how to use the above code? I copy it to a shader, set the sader on a custom mesh, and then i just see a texture. what assets and steps do i need to make foliage on above texture? does it work automatically with terrain assets loaded into Unity?
i was looking around for more information on this subject, as im not familiar with using shaders or anything and i have a landscape that is not an official "terrain". i found on the asset store these nice palm trees that wave, and after just reading this i decided to look at the code for the shaders and see if i could figure it out (i cant). but anyway it looks like the shader hes using is based off yours (or the other way around, idk) with an added bump map and specular, and has two different versions with backface culling and no culling, and also the prefabs that come with the asset are preconfigured to work out of the box, so it really helps to understand how to apply this to a mesh. the link to the asset is this : https://www.assetstore.unity3d.com/en/#!/content/13540
(really nice looking palm trees he has there btw, the shader must work well lol)
Your answer
Follow this Question
Related Questions
Vegetation problem 1 Answer
grass animation changing color 2 Answers
Is is possible to place vegetation on a custom mesh? 4 Answers
how to import custom plants and grass into unity 1 Answer
How to optimize custom grass? 1 Answer