ader DX10DWMShaders.fx
    fxc /Ges /Gis /O1 /Tvs_4_0 /EGlassVertexShader DX10DWMShaders.fx
    fxc /Ges /Gis /O1 /Tps_4_0 /EGlassPixelShader DX10DWMShaders.fx
    
    Copyright (c) 2008 Microsoft Corporation
*/

//-----------------------------------------------------------------------------
// Shader input/output types
//-----------------------------------------------------------------------------

struct COMMON_VS_INPUT {
    float3   vPosition : POSITION;
    float4   vDiffuse  : COLOR;
    float2   vTexCoord : TEXCOORD0;
};

struct SIMPLE_VS_OUTPUT {
    float4   vPosition : SV_POSITION;
    float4   vDiffuse  : COLOR;
    float2   vTexCoord : TEXCOORD0;
};

struct GLASS_VS_OUTPUT {
    float4   vPosition        : SV_POSITION;
    float4   vDiffuse         : COLOR;
    float2   vTexCoord        : TEXCOORD0;
    float4   vBlurSamplesTLTR : TEXCOORD1;
    float4   vBlurSamplesBLBR : TEXCOORD2;
};

//-----------------------------------------------------------------------------
// Constant buffers, textures, and samplers
//-----------------------------------------------------------------------------

cbuffer cbGlassShaderConstants {
    // x,y contains the origin in clipspace of the glass texture
    // z,w contains the blur step size for the glass shader
    float4   g_vWindowOffsetAndBlurStepSize;
};

Texture2D g_texWindow;
Texture2D g_texBackground;

SamplerState g_sampWindow {
    Filter   = MIN_MAG_MIP_POINT;
    AddressU = Clamp;
    AddressV = Clamp;
    AddressW = Clamp;
};

SamplerState g_sampBackground {
    Filter   = MIN_MAG_MIP_LINEAR;
    AddressU = Clamp;
    AddressV = Clamp;
    AddressW = Clamp;
};

//------------------------------------------------------------------------------
// SimpleVertexShader
//------------------------------------------------------------------------------

SIMPLE_VS_OUTPUT SimpleVertexShader( COMMON_VS_INPUT sVIn )
{
    SIMPLE_VS_OUTPUT   sVOut;

    sVOut.vPosition = float4( sVIn.vPosition, 1.0 );
    sVOut.vDiffuse  = sVIn.vDiffuse.wxyz * 0.2;  // SetVertices assumes ARGB
    sVOut.vTexCoord = sVIn.vTexCoord;

    return sVOut;
}

//-----------------------------------------------------------------------------
// SimplePixelShader
//-----------------------------------------------------------------------------

float4 SimplePixelShader( SIMPLE_VS_OUTPUT sVIn ) : SV_Target
{
    float4   vRetVal;

    vRetVal = g_texWindow.Sample( g_sampWindow, sVIn.vTexCoord );
    //vRetVal = vRetVal * 0.8 + sVIn.vDiffuse;
    //vRetVal.a = sVIn.vDiffuse.a;

    return vRetVal;
}

//-----------------------------------------------------------------------------
// RTPixelShader
//-----------------------------------------------------------------------------

float4 RTPixelShader( SIMPLE_VS_OUTPUT sVIn ) : SV_Target
{
    return g_texWindow.Sample( g_sampWindow, sVIn.vTexCoord );
}

//------------------------------------------------------------------------------
// GlassVertexShader
//------------------------------------------------------------------------------

GLASS_VS_OUTPUT GlassVertexShader( COMMON_VS_INPUT sVIn )
{
    GLASS_VS_OUTPUT   sVOut;

    sVOut.vPosition = float4( sVIn.vPosition, 1.0 );
    sVOut.vDiffuse  = sVIn.vDiffuse.wxyz * 0.2;  // SetVertices assumes ARGB
    sVOut.vTexCoord = sVIn.vTexCoord;

    float2 vBgTextureOffset = ( sVIn.vPosition.xy - g_vWindowOffsetAndBlurStepSize.xy ) * float2( .5, -.5 );                                        
    
    sVOut.vBlurSamplesTLTR.x = vBgTextureOffset.x - g_vWindowOffsetAndBlurStepSize.z;
    sVOut.vBlurSamplesTLTR.y = vBgTextureOffset.y - g_vWindowOffsetAndBlurStepSize.w;
    
    sVOut.vBlurSamplesTLTR.z = vBgTextureOffset.x - g_vWindowOffsetAndBlurStepSize.z;
    sVOut.vBlurSamplesTLTR.w = vBgTextureOffset.y + g_vWindowOffsetAndBlurStepSize.w;   
    
    sVOut.vBlurSamplesBLBR.x = vBgTextureOffset.x + g_vWindowOffsetAndBlurStepSize.z;
    sVOut.vBlurSamplesBLBR.y = vBgTextureOffset.y - g_vWindowOffsetAndBlurStepSize.w;    
    
    sVOut.vBlurSamplesBLBR.z = vBgTextureOffset.x + g_vWindowOffsetAndBlurStepSize.z;
    sVOut.vBlurSamplesBLBR.w = vBgTextureOffset.y + g_vWindowOffsetAndBlurStepSize.w;
    
    return sVOut;
}

//-----------------------------------------------------------------------------
// GlassPixelShader
//-----------------------------------------------------------------------------

float4 GlassPixelShader( GLASS_VS_OUTPUT sVIn ) : SV_Target
{
    float4   vTexColor;
    float4   vGlass;

    vTexColor = g_texWindow.Sample( g_sampWindow, sVIn.vTexCoord );
    
    vGlass =   g_texBackground.Sample( g_sampBackground, sVIn.vBlurSamplesTLTR.xy )
             + g_texBackground.Sample( g_sampBackground, sVIn.vBlurSamplesTLTR.zw )
             + g_texBackground.Sample( g_sampBackground, sVIn.vBlurSamplesBLBR.xy )
             + g_texBackground.Sample( g_sampBackground, sVIn.vBlurSamplesBLBR.zw );
    vGlass /= 4;

    vTexColor *= sVIn.vDiffuse;

    return ( 1.0 - vTexColor.a ) * vGlass + vTexColor * vTexColor.a;
}

//-----------------------------------------------------------------------------
// END OF : DX10DWMShaders.fx
//+============================================================================


