Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by alessandro_88 · Oct 17, 2013 at 10:38 PM · shadergrasswind

making grass move at different speeds

Hi! I'm using the atsGrass-Unlit-Wind Shader for making grassplanes move as in the wind. The planes are being instantiated as I press play, every plane has it's WindShader script where I set a random Value to the windforces and set that value to the shader. If I select any plane, the values will therefore be different, but the planes still move all at the same speed. Does anybody know, why that could be?

Here is the shadercode:

 // - Unlit
 
 Shader "GrassShader" {
 Properties {
     _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" {}
     _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
 }
 
 SubShader {
     Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "LightMode"="ForwardBase"}
     LOD 100
     Cull Off
     ZWrite Off
     Blend SrcAlpha OneMinusSrcAlpha 
     
     
     CGINCLUDE
     #include "UnityCG.cginc"
     sampler2D _MainTex;
     half4 _MainTex_ST;
     
     float4 _GrassWind; //is not defined in terrainengine.cginc
 
     struct v2f {
         float4 pos : SV_POSITION;
         float2 uv : TEXCOORD0;
     };
 
 inline float4 AnimateGrass(float4 pos, float3 normal, float animParams)
 {    
     // animParams stored in color
     // animParams = primary factor = blue
     // Primary bending
     // Displace position
     pos.xyz += animParams * _GrassWind.xyz * _GrassWind.w; // controlled by vertex color blue
     return pos;
 }
 
 
     
     v2f vert (appdata_full v)
     {
         v2f o;
         float4    windParams    = float(v.color.b);        
         // call vertex animation
         float4 mdlPos = AnimateGrass(v.vertex, v.normal, windParams);
         o.pos = mul(UNITY_MATRIX_MVP,mdlPos);
         o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
         return o;
     }
     ENDCG
 
     Pass {
         CGPROGRAM
         #pragma debug
         #pragma vertex vert
         #pragma fragment frag
         #pragma fragmentoption ARB_precision_hint_fastest        
         fixed4 frag (v2f i) : COLOR
         {
             fixed4 tex = tex2D (_MainTex, i.uv);
             
             fixed4 c;
             c.rgb = tex.rgb;
             c.a = tex.a;
             
             return c;
         }
         ENDCG
     }    
 }
 }

and here is the script:

 using UnityEngine;
 using System.Collections;
 
 public class WindShader : MonoBehaviour 
 {
     public Color VertexLitTranslucencyColor;
     public Vector4 Wind;
     public float GrassWindFrequency;    
     
     void Start ()
     {
         Wind = new Vector4 (UnityEngine.Random.Range (0.5f, 1.5f), 0, 0, UnityEngine.Random.Range (0.5f, 1.5f));
         VertexLitTranslucencyColor = new Color (UnityEngine.Random.Range (0, 1), UnityEngine.Random.Range (0, 1), UnityEngine.Random.Range (0, 1), UnityEngine.Random.Range (0, 1));
         GrassWindFrequency = UnityEngine.Random.Range (1, 2);
         
         Application.targetFrameRate = 100;
         
         Shader.SetGlobalColor("_TranslucencyColor", VertexLitTranslucencyColor);
         Shader.SetGlobalFloat("_TranslucencyViewDependency;", 0.65f);
         Shader.SetGlobalFloat("_ShadowOffsetScale;", 1.0f);    
     }
     
     
     void Update ()
     {
         Shader.SetGlobalColor("_GrassWind", Wind);
         Color GrassWindRGBA = Wind *  ( (Mathf.Sin(Time.realtimeSinceStartup * GrassWindFrequency)));
         GrassWindRGBA.a = Wind.w;
         Shader.SetGlobalColor("_GrassWind", GrassWindRGBA);
     }
 }
Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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.

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

grass on objects 0 Answers

Replacing built-in shaders for terrain billboard grass. 2 Answers

how to get the color of the ground on which the object lies 0 Answers

How can I give an object realistic wind? 0 Answers

Wind Effect On GameObject 0 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