// Software pixel shader generated by Wild Magic.
//
// var float3    kLightDir     $vin.COLOR
// var float2    kBaseTCoord   $vin.TEXCOORD0
// var float2    kNormalTCoord $vin.TEXCOORD1
// var float4    kPixelColor   $vout.COLOR
// var sampler2D BaseSampler   texunit 0
// var sampler2D NormalSampler texunit 1

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

namespace Wm4
{

ColorRGBA p_SimpleBumpMap (const float*, SoftSampler** apkSampler,
    const float* afInPixel)
{
    // Get samplers.
    SoftSampler& rkBaseSampler = *apkSampler[0];
    SoftSampler& rkNormalSampler = *apkSampler[1];

    // Get input values.
    const Vector3f& rkLightDir = *(const Vector3f*)&afInPixel[0];
    const float* afBaseTCoord = &afInPixel[3];
    const float* afNormalTCoord = &afInPixel[5];

    // *** program ***

    ColorRGBA kBaseColor = rkBaseSampler(afBaseTCoord);
    ColorRGBA kNormalColor = rkNormalSampler(afNormalTCoord);
    
    Vector3f kNDir(kNormalColor[0],kNormalColor[1],kNormalColor[2]);
    kNDir = MapFromUnit(kNDir);
    float fDot = Saturate(rkLightDir.Dot(kNDir));

    ColorRGBA kPixelColor;
    kPixelColor[0] = fDot*kBaseColor[0];
    kPixelColor[1] = fDot*kBaseColor[1];
    kPixelColor[2] = fDot*kBaseColor[2];
    kPixelColor[3] = 1.0f;

    return kPixelColor;
}

WM4_IMPLEMENT_PPROGRAM(SimpleBumpMap);
WM4_REGISTER_PPROGRAM(SimpleBumpMap);

}
