// Software vertex shader generated by Wild Magic.
//
// var float3   kModelPosition    $vin.POSITION
// var float2   kInGroundTCoord   $vin.TEXCOORD0
// var float    kInBlendTCoord    $vin.TEXCOORD1
// var float2   kInCloudTCoord    $vin.TEXCOORD2
// var float4   kClipPosition     $vout.POSITION
// var float2   kOutGroundTCoord  $vout.TEXCOORD0
// var float    kOutBlendTCoord   $vout.TEXCOORD1
// var float2   kOutCloudTCoord   $vout.TEXCOORD2
// var float2   kOutFlowDirection $vout.TEXCOORD3
// var float4x4 WVPMatrix         c[0]
// var float2   FlowDirection     c[4]

#include "Wm4SoftRenderer.h"
#include "Wm4Matrix4.h"
#include "Wm4Vector3.h"

namespace Wm4
{

void v_BlendedTerrain (const float* afRegister, const float* afInVertex,
    float* afOutVertex)
{
    // Get the register items.
    const Matrix4f& rkWVPMatrix = *(const Matrix4f*)&afRegister[0];
    const Vector2f& rkFlowDirection = *(const Vector2f*)&afRegister[16];

    // Get the input items.
    Vector4f kModelPosition(afInVertex[0],afInVertex[1],afInVertex[2],1.0f);
    const Vector2f& rkInGroundTCoord = *(const Vector2f*)&afInVertex[3];
    float fInBlendTCoord = afInVertex[5];
    const Vector2f& rkInCloudTCoord = *(const Vector2f*)&afInVertex[6];

    // Access the output items.
    Vector4f& rkClipPosition = *(Vector4f*)&afOutVertex[0];
    Vector2f& rkOutGroundTCoord = *(Vector2f*)&afOutVertex[4];
    float& rfOutBlendTCoord = afOutVertex[6];
    Vector2f& rkOutCloudTCoord = *(Vector2f*)&afOutVertex[7];
    Vector2f& rkOutFlowDirection = *(Vector2f*)&afOutVertex[9];

    // *** program ***

    // Transform the position from model space to clip space.
    rkClipPosition = kModelPosition*rkWVPMatrix;
    
    // Pass through the texture coordinates.
    rkOutGroundTCoord = rkInGroundTCoord;
    rfOutBlendTCoord = fInBlendTCoord;
    rkOutCloudTCoord = rkInCloudTCoord;
    
    // Pass through the flow direction, to be used as an offset in the pixel
    // program.
    rkOutFlowDirection = rkFlowDirection;
}

WM4_IMPLEMENT_VPROGRAM(BlendedTerrain);
WM4_REGISTER_VPROGRAM(BlendedTerrain);

}
