// Software pixel shader generated by Wild Magic.
//
// var float4 kDiffuseColor  $vin.COLOR
// var float2 kBaseTCoord    $vin.TEXCOORD0
// var float4 kPixelColor    $vout.COLOR
// var sampler2D BaseSampler texunit 0

#include "Wm4SoftRendererPCH.h"
#include "Wm4SoftRenderer.h"
#include "Wm4ColorRGBA.h"
#include "Wm4Vector2.h"

namespace Wm4
{

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

    // Get input values.
    const ColorRGBA& rkDiffuseColor = *(const ColorRGBA*)&afInPixel[0];
    const float* afBaseTCoord = &afInPixel[4];

    // *** program ***
    
    // Add the material and texture colors.
    ColorRGBA kBaseColor = rkBaseSampler(afBaseTCoord);
    
    ColorRGBA kPixelColor;
    kPixelColor[0] = kBaseColor[0] + rkDiffuseColor[0];
    kPixelColor[1] = kBaseColor[1] + rkDiffuseColor[1];
    kPixelColor[2] = kBaseColor[2] + rkDiffuseColor[2];
    
    // Multiply the material and texture alphas.
    kPixelColor[3] = kBaseColor[3]*rkDiffuseColor[3];

    return kPixelColor;
}

WM4_IMPLEMENT_PPROGRAM(MaterialTexture);

}
