• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Seith · Dec 08, 2012 at 04:19 PM · animationgrassvegetation

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?

Comment
frogsbo
asorbits
konsic

People who like this

3 Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image lil_billy · Dec 09, 2012 at 03:24 PM 0
Share

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.

avatar image Shgoedt · Dec 09, 2012 at 04:14 PM 0
Share

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.

avatar image lil_billy · Dec 09, 2012 at 04:49 PM 0
Share

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.

avatar image Seith · Dec 09, 2012 at 05:10 PM 0
Share

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?

avatar image lil_billy · Dec 09, 2012 at 05:27 PM 0
Share

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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

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:

alt text


screenshot059_small.jpg (228.7 kB)
Comment
frogsbo
WillNode
MattMurch
asorbits
konsic
jojue

People who like this

6 Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image AlwaysSunny · Mar 01, 2013 at 12:22 AM 0
Share

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? :)

avatar image Seith · Mar 03, 2013 at 01:37 PM 3
Share

@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.

Meanwhile, here's my simple shader solution:

 Shader "Custom/WavingDoublePass" {
 Properties {
     _WavingTint ("Fade Color", Color) = (.7,.6,.5, 0)
     _MainTex ("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
     ColorMask RGB
 
 CGPROGRAM
 #pragma surface surf Lambert vertex:WavingGrassVert addshadow alphatest:_Cutoff2
 #pragma exclude_renderers flash
 #include "TerrainEngine.cginc"
 
 sampler2D _MainTex;
 fixed _Cutoff;
 
 struct Input {
     float2 uv_MainTex;
     fixed4 color : COLOR;
 };
 
 void surf (Input IN, inout SurfaceOutput o) {
     fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
     fixed4 d = tex2D(_MainTex, IN.uv_MainTex);
     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
         ColorMask RGB
 
         Pass {
             Tags { "LightMode" = "Vertex" }
             Material {
                 Diffuse (1,1,1,1)
                 Ambient (1,1,1,1)
             }
             Lighting On
             ColorMaterial AmbientAndDiffuse
             AlphaTest Greater [_Cutoff]
             SetTexture [_MainTex] { combine texture * primary DOUBLE, texture }
         }
         Pass {
             Tags { "LightMode" = "VertexLMRGBM" }
             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_LightmapMatrix]
                 combine texture * texture alpha DOUBLE
             }
             SetTexture [_MainTex] { combine texture * previous QUAD, texture }
         }
     }
 
     Fallback Off
 }
avatar image Seith · Mar 19, 2013 at 10:01 AM 0
Share

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.

avatar image frogsbo · Feb 05, 2014 at 02:28 PM 0
Share

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?

avatar image Erisat · Jun 19, 2014 at 06:45 AM 0
Share

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)

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to import custom plants and grass into unity 1 Answer

How to optimize custom grass? 1 Answer

Can I make animations snap to a frame? 0 Answers

Better vegetation (mainly grass) with Unity 5 (and SpeedTree?) 1 Answer

How to select an animation clip by index number? 7 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges