I want to animate some trees/ foliage. I need them to all move in the same direction despite their rotation. It seems the vertices are moving in local object space not in world space so when a tree is rotated, the wind blows it in a different direction. Is this possible? I am looking at the docs and seeing ways to convert to different spaces like i.vertex = mul(_Object2World, i.vertex); but I am not sure what to use here. Thanks for any help. Code (csharp): void vert( inout appdata_full i, out Input o ) { float speed = _Time.y * _Speed; i.vertex.x += _Bend * i.color.x * ((sin(speed)+.5)*.75); }
You'll need to take the vertex position into world space, apply the movement to the vertex position, then take it back into object space and apply it to the v.vertex attribute. Or - what's probably easier - calculate the movement then transform that from world space to object space and then apply it to the vertex attribute.
Thank you! Don't get how to apply your second method but the first one proved easy. Code (csharp): i.vertex = mul(_Object2World, i.vertex); i.vertex.x += _Bend * i.color.x * ((sin(speed)+.5)*.75); i.vertex = mul(_World2Object, i.vertex);
Code (csharp): float4 offset = float4(0,0,0,1); offset.x += _Bend * i.color.x * ((sin(speed)+.5)*.75); v.vertex.xyz += mul(_World2Object, offset).xyz; I think? Edit: Actually, as it's just a vector before you apply it to your vertex position you can simplify that a little. Code (csharp): float3 offset = float3(0,0,0); offset.x += _Bend * i.color.x * ((sin(speed)+.5)*.75); v.vertex.xyz += mul((float3x3)_World2Object, offset);
Sorry to be reviving an old thread, but this method makes it so that the vertices all move in a certain direction. I've tried to change this direction but I'm not being able to. Any ideas?
I think a naive modification like that should work somehow. (I haven’t tested this at all and I really haven’t read the thread – lol) _direction should be a float3 Code (CSharp): amount = _Bend * i.color.x * ((sin(speed)+.5)*.75); float3 offset = lerp(float3(0,0,0), float3(amount, amount, amount), _direction); v.vertex.xyz += mul((float3x3)_World2Object, offset);
What's the purpose of the lerp? It looks like an expensive way of doing this: float3 offset = _direction * amount;