/*********************************************************************NVMH3****

******************************************************************************/

float4x4 worldViewProj : WorldViewProjection;
float4x4 Proj : Projection;

float3 campos : CAMERAPOS;

float fFocalDistance = 100.0f;
float3 vFocalPoint : FOCALPOINT;
float  fHyperfocalDistance = 0.4f;

texture diffuseTexture : DiffuseTexture;
sampler DiffuseTextureSampler = sampler_state 
{
    texture = <diffuseTexture>;
    AddressU  = WRAP;        
    AddressV  = WRAP;
    AddressW  = WRAP;
    MIPFILTER = LINEAR;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
};


texture depthTexture : Custom0;
sampler DepthTextureSampler = sampler_state 
{
    texture = <depthTexture>;
};


texture halfSampleTexture : Custom1;
sampler HalfTextureSampler = sampler_state 
{
    texture = <halfSampleTexture>;
    AddressU  = WRAP;        
    AddressV  = WRAP;
    AddressW  = WRAP;
    MIPFILTER = LINEAR;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
};

struct vertexInput {
    float4 position				: POSITION;
    float2 texCoordDiffuse		: TEXCOORD0;
};

struct vertexOutput {
    float4 hPosition		: POSITION;
    float2 texCoordDiffuse	: TEXCOORD0;
};


float WorkingSaturate(float x)
{
    if (x<0)
        x = 0;
    else if (x>1)
        x = 1;
    return x;
}


vertexOutput VS_Screen(vertexInput IN) 
{
    vertexOutput OUT;
    
    OUT.hPosition = mul( IN.position, Proj );
    
    OUT.texCoordDiffuse = IN.texCoordDiffuse;
    return OUT;
}


//-----------------------------------
float4 PS_Textured( vertexOutput IN): COLOR
{
	float green;
    float3 sampled = tex2D( DiffuseTextureSampler, IN.texCoordDiffuse ).xyz;  		
	
	 float3 light = float3(1,1.0,1.0);
  	//float3 dark = float3(0.2,0.05,0);
  	float3 dark = float3(0.0,0.0,0);

  	float3 sceneColor = light * sampled;
  	
    float3 grayXfer = float3(0.3,0.59,0.11);
    float gray = dot(grayXfer,sceneColor);
    float3 muted = lerp(sceneColor,gray.xxx, 0.5 ); // Desat
    float3 sepia = lerp(dark,light,gray);  //dark, light
    float3 result = lerp(muted,sepia, 1.0); //Toned    		
	return float4( result, 1 );
}



//-----------------------------------
technique basic
{
    pass p0 
    {		
		VertexShader = compile vs_2_0 VS_Screen();
		PixelShader  = compile ps_2_0 PS_Textured();
		cullmode = none;
    }
}
