/*********************************************************************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;  		
	//return float4( sampled, 1 );
	float3 sampledHalf = tex2D( HalfTextureSampler, IN.texCoordDiffuse ).xyz;  		
	
	float avg = dot(sampled, sampled);
	
	float3 outcolor;
	if( avg < 0.5f )
		outcolor = float3( 0.4, 0.4, 0.4 );
	else
		outcolor = float3( 0.8, 0.8, 0.8 );
		
	return float4( outcolor, 1 );
}



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