Swyter's Simple Waving

From Mount&Blade Modding Wiki
Jump to: navigation, search

I've created some simple functions for Star Wars Conquest, this can be used for almost anything, with some adjustments you can convert the code into a windy flora script or even waving cloth or water. Uses the passed time_var uniform from the game. I've tested it in Mount&Blade 1.011 but should work on any DirectX 3D game.


In definitive, it's a good start point for a complex effect or simply to start learning HLSL.

// vPosition, tc.y <-- Vertex + vertical texture coordinate as modulator
 float4 CalcVertexAnimationMaster(float4 Offset, float height)
 {   
     return float4(
 
     (cos( time_var + Offset.y ) * .05 ) + Offset.x,
     Offset.y,
     (sin( time_var + Offset.y ) * .05 ) + Offset.z,
     Offset.w
     );
 }


And then call that function from within any Vertex Shader you want using something like this:

vPosition = CalcVertexAnimationMaster(vPosition,tc.y);

[edit] These are variations of the same function:

This one is modulated by the UV map, higher the texture coordinate in the texture map, stronger the waving intensity... (Help by Vincenzo)

// vPosition, tc.y <-- Vertex + vertical texture coordinate as modulator
 float4 CalcVertexAnimationMaster(float4 Offset, float height)
 {
    static const float yeffect = 1.0f;
    float offsetx = (cos( time_var + Offset.y ) * 0.05f ) * (-height * yeffect);
    float offsetz = (sin( time_var + Offset.y ) * 0.05f ) * (-height * yeffect);
 
     return float4(
     Offset.x + offsetx,
     Offset.y,
     Offset.z + offsetz,
     Offset.w
     );
 }


This one animates only the vertices covered by the bottom part of the UV map.

float4 CalcVertexAnimationMaster(float4 Offset, float height)
 {   
    if (height >= .5)
    {
      return Offset;
    }
    else
    {
       return float4(
 
       (cos( time_var + Offset.y )  /*height*/*.05 ) + Offset.x,
       Offset.y,
       (sin( time_var + Offset.y )  /*height*/*.05 ) + Offset.z,
       Offset.w
       );
    }
 }

[edit] Source

I published it originally here: http://forums.taleworlds.com/index.php/topic,208694.msg5040943.html#msg5040943

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox