// Software vertex shader generated by Wild Magic.
//
// var float3   kModelPosition   $vin.POSITION
// var float4   kClipPosition    $vout.POSITION
// var float    fDepth           $vout.TEXCOORD0
// var float4x4 WVPMatrix        c[0]

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

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

namespace Wm4
{

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

    // Get the input items.
    Vector4f kModelPosition(afInVertex[0],afInVertex[1],afInVertex[2],1.0f);

    // Access the output items.
    Vector4f& rkClipPosition = *(Vector4f*)&afOutVertex[0];
    float& rfDepth = afOutVertex[4];

    // *** program ***

    // Transform the position from model space to clip space.
    rkClipPosition = kModelPosition*rkWVPMatrix;
    
    // Save the normalized distance from the light source.
    rfDepth = rkClipPosition[2]/rkClipPosition[3];
}

WM4_IMPLEMENT_VPROGRAM(ProjectedDepth);
WM4_REGISTER_VPROGRAM(ProjectedDepth);

}
