// Software vertex shader generated by Wild Magic.
//
// var float2    kBaseTCoord    $vin.TEXCOORD0
// var float2    kDetailTCoord   $vin.TEXCOORD1
// var float     fFogFactor      $vin.TEXCOORD2
// var float4    kPixelColor     $vout.COLOR
// var float4    FogColorDensity c[0]
// var sampler2D BaseSampler     texunit 0
// var sampler2D DetailSampler   texunit 1

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

namespace Wm4
{

ColorRGBA p_BaseMulDetailFogExpSqr (const float* afRegister,
    SoftSampler** apkSampler, const float* afInPixel)
{
    // Get register values.
    const float* afFogColorDensity = &afRegister[0];

    // Get samplers.
    SoftSampler& rkBaseSampler = *apkSampler[0];
    SoftSampler& rkDetailSampler = *apkSampler[1];

    // Get input values.
    const float* afBaseTCoord = &afInPixel[0];
    const float* afDetailTCoord = &afInPixel[2];
    float fFogFactor = afInPixel[4];

    // *** program ***

    // Sample the texture images and multiply the results.
    ColorRGBA kBaseColor = rkBaseSampler(afBaseTCoord);
    ColorRGBA kDetailColor = rkDetailSampler(afDetailTCoord);
    ColorRGB kProduct(
        kBaseColor[0]*kDetailColor[0],
        kBaseColor[1]*kDetailColor[1],
        kBaseColor[2]*kDetailColor[2]);

    // Combine the base*detail color with the fog color.
    float fOmFogFactor = 1.0f - fFogFactor;
    ColorRGBA kPixelColor(
        fOmFogFactor*afFogColorDensity[0] + fFogFactor*kProduct[0],
        fOmFogFactor*afFogColorDensity[1] + fFogFactor*kProduct[1],
        fOmFogFactor*afFogColorDensity[2] + fFogFactor*kProduct[2],
        1.0f
    );
    return kPixelColor;
}

WM4_IMPLEMENT_PPROGRAM(BaseMulDetailFogExpSqr);
WM4_REGISTER_PPROGRAM(BaseMulDetailFogExpSqr);

}
