The idea is to make the grass move aside as you move through it and then return to it's normal blowing in the wind.
Altering the Ingame.fx to this, note that I did not really do much I just collected pieces of information from Peachykeen & Liztail and put this together:
GrassVertOut OUT;
OUT.texcoords = IN.texcoords;
//Animate grass
float proxydist = distance(posv.xy, EyePos.xy);
if (proxydist < 30)
{
//Insert fun Trigonometry! (Push verts away from camera)
}
float4 worldpos = mul(IN.pos, world);
float height = clamp(IN.pos.z, 0, 100) / 100;
float2 wind = WindVec * 2.5 + 0.25;
float2 pos_ticks1 = worldpos.xy / 1000 + ticks;
float2 pos_ticks2 = worldpos.xy / 750 + ticks * 2;
float2 pos_ticks3 = worldpos.xy / 500 + ticks * 3;
float2 pos_ticks4 = worldpos.xy / 200 + ticks * 4;
worldpos.xy += ( sin(pos_ticks1) + cos(pos_ticks2) + sin(pos_ticks3) + cos(pos_ticks4) ) * height * wind * 10;
//Define % to Fog
float dist = length(worldpos.xyz - EyePos.xyz);
OUT.fog = saturate( (FogRange - dist) / (FogRange-FogStart) );
//Define % to Blend
OUT.blend = saturate( (BlendEnd - dist) / (BlendEnd-BlendStart) );
//Projection
OUT.pos = mul(worldpos, view);
OUT.pos = mul(OUT.pos, proj);
//Texture Projection
OUT.screenpos = mul( worldpos, TexProj );
//Lighting
OUT.color = (SunCol * 0.25) + SunAmb;
return OUT;
}
This is what Liztail has to say about it:
I think the main problem with what you're trying to do is that the EyePos constant contains the position of the camera, not the player. So while this might kinda work in first person view, it would look really weird in 3rd person view because the invisible camera would be rustling the grass somewhere where there isn't anything. You might want to try to ask the people working on MGE and MSE whether there's some way that they can get you the actual position of the player's feet.
As far as the math, I think you'd just need to create a vector that goes from the center of the player's feet to the worldpos of the current vertex using subtraction, and then push the vertex in that direction by an amount that varies with distance. I can't remember what posv is, but the local position of the vertex is stored in IN.pos. It's not in world coordinates until it's multiplied by world in the next line to create the worldpos vector. To make it vary with distance, you would then calculate the length of that vector before normalizing it. Then you'd use a mathematical function that starts at one when the input is zero and goes down to zero when the input is 30. A linear function would probably be fine. At this point, multiplying the normalized vetor with this scaling factor so that the vertices that are close would cause them to get pushed one unit away from the player's feet while the ones that are far wouldn't get moved at all. You could then multiply that result by some constant scaling factor like 20 so that the vertices close to the player move by 20 units instead of one unit, which would have a more visible result.
Good luck,
--LizTail
I still have no idea what variable to use. I know that Eyepos works as a temporary hack as long as you are in 1st person... It's sad that not even the camera position is really of any use.
Player position is direly needed. I recall that Timeslip had an old mod for Mw that got the player position from MGE for distant land. Later the function was made faster by moving it to MGE completely. It should still be in use, perhaps internal to MGE code. This is my next step I guess, trying to delve into MGE code...
Also looking at liztails explanation now, I can understand more then the first time I looked at it. I will continue trying until something comes out of this =)