//----------------------------------------------------------------------------
void v_BaseMulDetailFogExpSqr
(
    in float3        kModelPosition : POSITION,
    in float2        kInBaseTCoord : TEXCOORD0,
    in float2        kInDetailTCoord : TEXCOORD1,
    out float4       kClipPosition : POSITION,
    out float2       kOutBaseTCoord : TEXCOORD0,
    out float2       kOutDetailTCoord : TEXCOORD1,
    out float        fFogFactor : TEXCOORD2,
    uniform float4x4 WVPMatrix,
    uniform float4x4 WVMatrix,
    uniform float4   FogColorDensity)
{
    // Transform the position from model space to clip space.
    float4 kHModelPosition = float4(kModelPosition,1.0f);
    kClipPosition = mul(kHModelPosition,WVPMatrix);

    // Transform the position from model space to view space.  This is the
    // vector from the view-space eye position (the origin) to the view-space
    // vertex position.  The fog factor uses the z-component of this vector,
    // which is z-based depth, not range-based depth.
    float3 kViewPosition = mul(kHModelPosition,WVMatrix).xyz;
    float fFogSqrDistance = dot(kViewPosition,kViewPosition);
    float fFogExpArg = -FogColorDensity.w*FogColorDensity.w*fFogSqrDistance;
    fFogFactor = exp(fFogExpArg);

    // Pass through the texture coordinates.
    kOutBaseTCoord = kInBaseTCoord;
    kOutDetailTCoord = kInDetailTCoord;
}
//----------------------------------------------------------------------------
void p_BaseMulDetailFogExpSqr
(
    in float2         kBaseTCoord : TEXCOORD0,
    in float2         kDetailTCoord : TEXCOORD1,
    in float          fFogFactor : TEXCOORD2,
    out float4        kPixelColor : COLOR,
    uniform float4    FogColorDensity,
    uniform sampler2D BaseSampler,
    uniform sampler2D DetailSampler)
{
    // Sample the texture images and multiply the results.
    float3 kBaseColor = tex2D(BaseSampler,kBaseTCoord).xyz;
    float3 kDetailColor = tex2D(DetailSampler,kDetailTCoord).xyz;
    float3 kProduct = kBaseColor*kDetailColor;

    // Combine the base*detail color with the fog color.
    kPixelColor.rgb = lerp(FogColorDensity.rgb,kProduct,fFogFactor);
    kPixelColor.a = 1.0f;
}
//----------------------------------------------------------------------------
