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

Sky
******************************************************************************/
#include "..\mrt.fx"

float4x4 viewProj : ViewProjection;
float4x4 world : World;
float3 campos : CAMERAPOS;

float TaggedBloom : TaggedBloom;
float FinalColorModulate : FinalColorModulate;
float4 ColorModulate : ColorModulate;
float InnerOpacity : InnerOpacity;
float OuterOpacity : OuterOpacity;

texture MyDiffuseTexture : MyDiffuseTexture;
sampler DiffuseTextureSampler = sampler_state 
{
    texture = <MyDiffuseTexture>;
    AddressU  = CLAMP;        
    AddressV  = CLAMP;
    AddressW  = CLAMP;
    MIPFILTER = LINEAR;
    MINFILTER = LINEAR;
    MAGFILTER = LINEAR;
};

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

struct vertexOutput {
    float4 hPosition		: POSITION;
    float2 texCoordDiffuse	: TEXCOORD0;
    float2 texCoordDiffuse2	: TEXCOORD1;
    float3 posWorld         : TEXCOORD2;
};

vertexOutput VS_Transform(vertexInput IN) 
{
    float4 pos;
    vertexOutput OUT;
    
    pos = mul(IN.position, world);    
    OUT.posWorld = pos;
    OUT.hPosition = mul( pos , viewProj);       
     
    OUT.texCoordDiffuse = IN.texCoordDiffuse;
    OUT.texCoordDiffuse2 = IN.texCoordDiffuse2;
    return OUT;
}


//-----------------------------------
PS_OUTPUT PS_Textured( vertexOutput IN)
{    
    float4 diffuseTexture = tex2D( DiffuseTextureSampler, IN.texCoordDiffuse );
	
	float alpha = lerp( OuterOpacity, InnerOpacity, IN.texCoordDiffuse2.x );	
	diffuseTexture.xyz *= ColorModulate.xyz;
	diffuseTexture.xyz *= FinalColorModulate;
	diffuseTexture.a *= alpha;
	
	PS_OUTPUT Out;
	SetPSOutput( Out, diffuseTexture, float4( campos - IN.posWorld.xyz, 1) );
	return Out;
}


//-----------------------------------
technique textured
{
    pass p0 
    {		
		VertexShader = compile vs_2_0 VS_Transform();
		PixelShader  = compile ps_2_0 PS_Textured();
    }
}
