// Software vertex shader generated by Wild Magic.
//
// var float3    kEADColor      $vin.COLOR
// var float2    kTCoord        $vin.TEXCOORD0
// var float3    kSpecularColor $vin.TEXCOORD1
// var float4    kPixelColor    $vout.COLOR
// var sampler2D BaseSampler    texunit 0

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

namespace Wm4
{

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

    // Get input values.
    const ColorRGB& rkEADColor = *(const ColorRGB*)&afInPixel[0];
    const float* afTCoord = &afInPixel[3];
    const Vector3f& rkSpecularColor = *(const Vector3f*)&afInPixel[5];

    // *** program ***

    // The blending equation is
    //   (rf,gf,bf) = (rt,gt,bt)*(re,ge,be) + at*(rs,gs,bs)
    // where (rf,gf,bf) is the final color, (rt,gt,bt) is the texture color,
    // (re,ge,be) is the emissive-ambient-diffuse color, and (rs,gs,bs) is
    // the specular color.

    ColorRGBA kTextureColor = rkBaseSampler(afTCoord);
    ColorRGBA kPixelColor;
    for (int i = 0; i < 3; i++)
    {
        kPixelColor[i] = kTextureColor[i]*rkEADColor[i] +
            kTextureColor[3]*rkSpecularColor[i];
    }
    kPixelColor[3] = 1.0f;
    
    return kPixelColor;
}

WM4_IMPLEMENT_PPROGRAM(GlossMap);
WM4_REGISTER_PPROGRAM(GlossMap);

}
