x


Using a shader to oscillate plant

Hi everyone.

I'm new in Unity and I trying to develop my first mini video game for Android.

I imported the BananaPlant prefab and its texture and its shader (its name is Nature/Tree Soft Occlusion Leaves) provide from the Island Demo projet and I use them in my game.

Now, I try to make a shader to oscillate the BananaPlant in my game. But unfortunly, my shader doesn't work.

I know I have to use the initial shader to keep the texture and its renders and make a vertex program using the sine finction to oscillate the plants. But I have no idea the correct way to do this.

currently, my shader looks like that :

Shader "Custom/MovePlants" {
Properties {
}
SubShader {

    UsePass "Nature/Tree Soft Occlusion Leaves"
    Pass {

       CGPROGRAM
       #pragma vertex vert
       #pragma fragment frag
       #include "UnityCG.cginc"

       struct v2f {
           float4 pos : SV_POSITION;
           float3 color : COLOR0;
       };

       v2f vert (appdata_base v){
           v2f o;
           o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
           v.vertex.y += sin(_Time * 2.2 + v.vertex.y);
           return o;
       }

       half4 frag (v2f i) : COLOR {
         return half4 (i.color, 1);
       }

       ENDCG
    }
} 
FallBack "Diffuse"

}

I using a fragment program because apparently I must a both of vertex and fragment program for a OpenGL ES 2.0 target but I really don't know what I can put in the body of this program.

Please Have anybody got a solution for my trouble ?

Thanks for your help.

more ▼

asked May 14 '12 at 08:25 AM

KyuubiLovin gravatar image

KyuubiLovin
1 3 3 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
v.vertex.y += sin(_Time * 2.2 + v.vertex.y);

should probably be

o.pos.y += sin(_Time * 2.2 + v.vertex.y);

Also it doesn't work for me unless I comment UsePass away. Maybe it has something to do with the properties that Tree Soft Occlusion Leaves uses aren't available and that you didn't specify a pass in the shader that you want to use.

You can get the shader sources from here and mod them to suit your needs if you want to.

more ▼

answered May 14 '12 at 04:38 PM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

Hi!

Thanks for your answer. I pick up the source code shader via the link you gave and now, I try to add the vertex program to animate the plants.

I will tell you if I success to do this.

May 16 '12 at 08:38 AM KyuubiLovin
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3774
x2460
x1651
x6
x4

asked: May 14 '12 at 08:25 AM

Seen: 888 times

Last Updated: May 16 '12 at 08:40 AM