float4x4 worldViewProj : WorldViewProjection;
float4x4 view : ViewInverse;
float4x4 world : World;

#define BONEMODE_4x3 1

#include "generic.fx"

float alphaInUse : ALPHA_TEST;
float timer : TIMER_6;
float timer2 : TIMER_10;

struct vertexInputUnboned {
    float4 position				: POSITION;
    float2 texCoordDiffuse      : TEXCOORD0;
    float  side                 : TEXCOORD1;
    float  sway                 : TEXCOORD2;
};

struct vertexOutput {
    float4 hPosition		: POSITION;
    float2 texCoordDiffuse	: TEXCOORD0;
};

texture diffuseTexture : DiffuseTexture;

sampler DiffuseTextureSampler = sampler_state 
{
    texture = <diffuseTexture>;
    AddressU  = CLAMP;        
    AddressV  = CLAMP;
    AddressW  = WRAP;
    MIPFILTER = LINEAR;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
};

vertexOutput VS_TransformUnboned(vertexInputUnboned IN) 
{
    vertexOutput OUT;
    
    float4 pos = IN.position;
    float4 posw = mul(pos, world);
    float3 side = mul(float3(1,0,0), view);
    float sway = cos(timer*3.1415926535*2+posw.x);
    side.y = 0;
    pos.xyz += side * IN.side;
    pos.xyz += side * sway * 0.1 * IN.sway.x;
    
    side = mul(float3(0,0,1), view);
    sway = cos(timer2*3.1415926535*2+posw.z);
    pos.xyz += side * sway * 0.1 * IN.sway.x;
    
    OUT.hPosition = mul(pos, worldViewProj);
    OUT.texCoordDiffuse = IN.texCoordDiffuse;
    return OUT;
}

float4 PS_Textured(vertexOutput IN) : COLOR
{
    float4 color = tex2D(DiffuseTextureSampler, IN.texCoordDiffuse);
    return color;
}


//-----------------------------------

technique unboned
{
    pass p0 
    {		
		VertexShader = compile vs_1_1 VS_TransformUnboned();
		PixelShader  = compile ps_1_1 PS_Textured();
		alphatestenable = true;
		alpharef = 160;
		alphafunc = greaterequal;
    }
}
