// Software pixel shader generated by Wild Magic.
//
// var float4 kVertexColor        $vin.COLOR
// var float3 kReflectTCoord      $vin.TEXCOORD0
// var float4 kPixelColor         $vout.COLOR
// var float  Reflectivity        c[0]
// var samplerCUBE CubeMapSampler texunit 0

#include "Wm4SoftRenderer.h"
#include "Wm4ColorRGBA.h"
#include "Wm4Vector3.h"

namespace Wm4
{

ColorRGBA p_CubeMap (const float* afRegister, SoftSampler** apkSampler,
    const float* afInPixel)
{
    // Get the register items.
    float fReflectivity = afRegister[0];

    // Get samplers.
    SoftSampler& rkCubeMapSampler = *apkSampler[0];

    // Get the input items.
    const ColorRGBA& rkVertexColor = *(const ColorRGBA*)&afInPixel[0];
    const Vector3f& rkReflectTCoord = *(const Vector3f*)&afInPixel[4];
    
    // *** program ***
    ColorRGBA kReflectedColor = rkCubeMapSampler(rkReflectTCoord);
    ColorRGBA kPixelColor = Lerp(rkVertexColor,kReflectedColor,fReflectivity);

    return kPixelColor;
}

WM4_IMPLEMENT_PPROGRAM(CubeMap);
WM4_REGISTER_PPROGRAM(CubeMap);

}
