Hi, I have a Sprite that is a plant, and I want to make it wave when the character passes through it.
It basically works, but now I want to make it work with vertex colors, so the branches move more than the base and that.
Since it’s a sprite and not a mesh, I thought about sending a texture with the colors and mapping it in Vert with tex2Dlod.
I’ve tried several things, but I realized the uv is very difficult to determine in order to map the color of the passed texture.
This is the sprite:
And the sprite I use as vertex colors:
The problem is that texcoord.y and texcoord.x correspond to each of the vertices, but it’s impossible for me to determine which one is which one. First I thought texcoord was just coordinates of the image, from 0 to 1, but then I discovered is not true, they are the vertices, and the positions are kinda random, or at least I don’t know how they work.
If I do this in the vertex shader:
//Plant waving
#if defined( _WAVE_ON )
fixed4 v_color = tex2Dlod (_VertexColor, v.texcoord);
float factor = (1 - _ShakeDisplacement - v_color.r) * 0.5;
const float _WindSpeed = (_ShakeWindspeed + v_color.g );
const float _WaveScale = _ShakeDisplacement;
const float4 _waveXSize = float4(0.048, 0.06, 0.24, 0.096);
const float4 waveSpeed = float4 (1.2, 2, 1.6, 4.8);
float4 _waveXmove = float4(0.024, 0.04, -0.12, 0.096);
float4 waves;
waves = v.vertex.x * _waveXSize;
waves += _Time.x * (1 - _ShakeTime * 2 - v_color.b ) * waveSpeed *_WindSpeed;
float4 s, c;
waves = frac (waves);
FastSinCos (waves, s,c);
float waveAmount = v.texcoord.y * (v_color.a + _ShakeBending);
s *= waveAmount;
s *= normalize (waveSpeed);
s = s * s;
float fade = dot (s, 1.3);
s = s * s;
float3 waveMove = float3 (0,0,0);
waveMove.x = dot (s, _waveXmove);
v.vertex.x += mul ((float3x3)_World2Object, waveMove).x * _ShakeAmount;
#endif
the v_color, gotten from tex2Dlod using texcoord and the Colors texture coordinates don’t correspond at all. For example, with the colors texture I send, which has only white in the top, then the wave is going to be random, accumulating points in the center, so the center waves a lot, and there is no way in the sides. That’s how I discovered uv is not sorted as I thought.
How can I map the texture colors property with the texcoord to use the colors in order to apply more or less waves depending on the colors?
if I shouldn’t use a texture, but the vertex colors of the sprite, it would be nice to know how, since I have no idea how to do that without a mesh.
please let me know if I didn’t explain properly.
Thanks a lot in advance.