struct VertexToPixel
{
    float4 Position   	: POSITION0;    
    float4 Color		: COLOR0;
    float3 Normal		: TEXCOORD0;
    float2 TextureCoords: TEXCOORD1;
    float4 ShadowMapSamplingPos : TEXCOORD2;
};

struct PixelToFrame
{
    float4 Color : COLOR0;
};

struct SMapVertexToPixel
{
	float4 Position     : POSITION;
	float3 Position2D    : TEXCOORD0;
    float2 TextureCoords: TEXCOORD1;
};

struct SMapPixelToFrame
{
	float4 Color : COLOR0;
};

//------- Constants --------
float4x4 xView: VIEW;
float4x4 xProjection: PROJECTION;
float4x4 xWorld: WORLD;
float4x4 xLightWorldViewProjection;
float3 xLightDirection: Direction <  
	string UIName = "Light Direction"; 
	string Object = "TargetLight";
	>;
float xAmbient <string UIName = "ambient term";> = 0.2f;
float xDiffuse <string UIName = "diffuse term";> = 0.8f;
float3 xRight;
float3 xUp;
float xAlpha;

float3 xDiffuseColor: diffuse0 <string UIName = "Color";>;
bool xTextureEnabled = true;

float4 xSkyColor<string UIName = "Color Cielo"; string UIWidget = "color";>;
float4 xGroundColor<string UIName = "Color Suelo"; string UIWidget = "color";>;

float xMaxDepth;

float xMapSize = 512.0f;

const float ShadowMapSize = 2048.0f;

//------- Texture Samplers --------
Texture xShadowMap <string UIName = "xShadowMap";>;
sampler ShadowMapSampler = sampler_state { texture = <xShadowMap>;AddressU = clamp; AddressV = clamp;};// ; magfilter = CONSTANT; minfilter = NEAR; mipfilter=NEAR; AddressU = clamp; AddressV = clamp;};

Texture xTexture <string UIName = "Textura";>;
sampler TextureSampler = sampler_state { texture = <xTexture>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR;};// AddressU = mirror; AddressV = mirror;};

Texture Layer0;
sampler LayerSampler0 = sampler_state { texture = <Layer0>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR;};// AddressU = mirror; AddressV = mirror;};
Texture Layer1;
sampler LayerSampler1 = sampler_state { texture = <Layer1>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR;};// AddressU = mirror; AddressV = mirror;};
Texture Layer2;
sampler LayerSampler2 = sampler_state { texture = <Layer2>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR;};// AddressU = mirror; AddressV = mirror;};
Texture Layer3;
sampler LayerSampler3 = sampler_state { texture = <Layer3>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR;};// AddressU = mirror; AddressV = mirror;};
Texture Alpha;
sampler AlphaSampler = sampler_state { texture = <Alpha>; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR;};// AddressU = mirror; AddressV = mirror;};
float4 LayerScale;

//------- Technique: Pretransformed --------

VertexToPixel PretransformedVS( float4 inPos : POSITION, float4 inColor: COLOR)
{	
	VertexToPixel Output = (VertexToPixel)0;
	
	Output.Position = inPos;
	Output.Color = inColor;
    
	return Output;    
}

PixelToFrame PretransformedPS(VertexToPixel PSIn) 
{
	PixelToFrame Output = (PixelToFrame)0;		
	
	Output.Color = PSIn.Color;

	return Output;
}

technique Pretransformed
{
	pass Pass0
    {   
    	VertexShader = compile vs_1_1 PretransformedVS();
        PixelShader  = compile ps_1_1 PretransformedPS();
    }
}

//------- Technique: Explosion --------

VertexToPixel ExplosionVS( float4 inPos : POSITION, float3 inNormal : NORMAL)
{	
	VertexToPixel Output = (VertexToPixel)0;
	float4x4 preWorldView = mul (xWorld, xView);
	float4x4 preWorldViewProjection = mul (preWorldView, xProjection);
    
	Output.Position = mul(inPos, preWorldViewProjection);

	float3 normal = normalize(mul(inNormal, preWorldView));
	
	float alpha = abs(xAlpha * normal.z * normal.z);
	
	Output.Color = float4(1, 1, 1, alpha);
    
	return Output;    
}

PixelToFrame ExplosionPS(VertexToPixel PSIn) 
{
	PixelToFrame Output = (PixelToFrame)0;		
	
	Output.Color = PSIn.Color;

	return Output;
}

technique Explosion
{
	pass Pass0
    {   
    	VertexShader = compile vs_1_1 ExplosionVS();
        PixelShader  = compile ps_1_1 ExplosionPS();

        AlphaBlendEnable = true;
        SrcBlend = SrcAlpha;
        DestBlend = One;
        //DestBlend = InvSrcAlpha;

        ZEnable = true;
        ZWriteEnable = false;
    }
}
////////////

float GetShadowMapDepth(sampler shadowMapSampler, float4 ShadowMapSamplingPos)
{
	float2 ProjectedTexCoords;
	
	ShadowMapSamplingPos.w*= 2.0f;
	ProjectedTexCoords[0] = (ShadowMapSamplingPos.x)/ShadowMapSamplingPos.w +0.5f;
	ProjectedTexCoords[1] = -(ShadowMapSamplingPos.y)/ShadowMapSamplingPos.w +0.5f;

	return tex2D(shadowMapSampler, ProjectedTexCoords).x;
}

float4 GetShadow(sampler shadowMapSampler, float4 ShadowMapSamplingPos)
{
	float2 ProjectedTexCoords;
	
	ShadowMapSamplingPos.w*= 2.0f;
	
	ProjectedTexCoords[0] = (ShadowMapSamplingPos.x)/ShadowMapSamplingPos.w +0.5f;
	ProjectedTexCoords[1] = -(ShadowMapSamplingPos.y)/ShadowMapSamplingPos.w +0.5f;
	

	return tex2D(shadowMapSampler, ProjectedTexCoords);
}


//------- Technique: Colored --------

VertexToPixel ColoredVS(
	//VertexToPixel Input)
	float4 inPos : POSITION, float4 inColor: COLOR, float3 inNormal: NORMAL, float2 inTexCoords: TEXCOORD0)
{	
	VertexToPixel Output = (VertexToPixel)0;
	float4x4 preViewProjection = mul (xView, xProjection);
	float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
    
	Output.Position = mul(inPos, preWorldViewProjection);

	Output.Color = float4(xDiffuseColor, 1);
	Output.Normal = normalize(mul(normalize(inNormal), xWorld));
	Output.TextureCoords = inTexCoords;
	Output.ShadowMapSamplingPos = Output.Position;//mul(inPos, xLightWorldViewProjection);
	//Output.RealDistance = Output.ShadowMapSamplingPos.z;//xMaxDepth;
    
	return Output;    
}

PixelToFrame ColoredPS(VertexToPixel PSIn) 
{
	PixelToFrame Output = (PixelToFrame)0;

	float lightingFactor = 0;
	float d = dot(PSIn.Normal, -normalize(xLightDirection));

	float a = (1.0 + PSIn.Normal.y) * 0.5;

	float4 ambient = xAmbient * (xSkyColor * a + (1 - a) * xGroundColor);

	if(d > 0)
	{
		float4 shadow = GetShadowMapDepth(ShadowMapSampler, PSIn.ShadowMapSamplingPos);

		lightingFactor = d * shadow.r;
		lightingFactor = saturate(lightingFactor);
	}

	if(xTextureEnabled)
	{
		float4 tex = tex2D(TextureSampler, PSIn.TextureCoords);
		Output.Color = xDiffuse * tex * 
			(lightingFactor * PSIn.Color + ambient * PSIn.Color);
		Output.Color.a = tex.a;
	}
	else
	{
		Output.Color = xDiffuse * lightingFactor * PSIn.Color + ambient * PSIn.Color;
		Output.Color.a = PSIn.Color.a;
	}

	return Output;
}

technique Colored
{
	pass Pass0
    {   
    	VertexShader = compile vs_1_1 ColoredVS();
        PixelShader  = compile ps_2_0 ColoredPS();

		AlphaBlendEnable = false;
        AlphaTestEnable = true;
        AlphaFunc = NotEqual;
        AlphaRef = 0;

        CullMode = None;

        ZEnable = true;

//        ZFunc = Equal;

        ZWriteEnable = true;
    }
}

//------- Technique: Shadow --------

VertexToPixel ShadowVS(
	//VertexToPixel Input)
	float4 inPos : POSITION, float4 inColor: COLOR, float3 inNormal: NORMAL, float2 inTexCoords: TEXCOORD0)
{	
	VertexToPixel Output = (VertexToPixel)0;
	float4x4 preViewProjection = mul (xView, xProjection);
	float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
    
	Output.Position = mul(inPos, preWorldViewProjection);

	Output.Color = float4(xDiffuseColor, 1);
	Output.Normal = normalize(mul(normalize(inNormal), xWorld));
	Output.TextureCoords = inTexCoords;
	Output.ShadowMapSamplingPos = mul(inPos, xLightWorldViewProjection);
    
	return Output;    
}

PixelToFrame ShadowPS(VertexToPixel PSIn) 
{
	PixelToFrame Output = (PixelToFrame)0;		
        
	float d = dot(PSIn.Normal, -xLightDirection);

	Output.Color = 1;

	float shadow = 0.0f;

	if(d > 0)
	{
		float depth = PSIn.ShadowMapSamplingPos.z - 0.2f/100.0f;

		float StoredDepthInShadowMap = GetShadowMapDepth(ShadowMapSampler, PSIn.ShadowMapSamplingPos);

		if (depth <= StoredDepthInShadowMap)
			shadow+=1.0f/9;

		StoredDepthInShadowMap = GetShadowMapDepth(ShadowMapSampler, PSIn.ShadowMapSamplingPos + float4(-1.0f/ShadowMapSize, 1.0f/ShadowMapSize, 0, 0));
		if (depth <= StoredDepthInShadowMap)
			shadow+=1.0f/9;
		StoredDepthInShadowMap = GetShadowMapDepth(ShadowMapSampler, PSIn.ShadowMapSamplingPos + float4(1.0f/ShadowMapSize, 1.0f/ShadowMapSize, 0, 0));
		if ((PSIn.ShadowMapSamplingPos.z - 0.2f/100.0f) <= StoredDepthInShadowMap)
			shadow+=1.0f/9;

		StoredDepthInShadowMap = GetShadowMapDepth(ShadowMapSampler, PSIn.ShadowMapSamplingPos + float4(-1.0f/ShadowMapSize, -1.0f/ShadowMapSize, 0, 0));
		if ((PSIn.ShadowMapSamplingPos.z - 0.2f/100.0f) <= StoredDepthInShadowMap)
			shadow+=1.0f/9;
		StoredDepthInShadowMap = GetShadowMapDepth(ShadowMapSampler, PSIn.ShadowMapSamplingPos + float4(1.0f/ShadowMapSize, -1.0f/ShadowMapSize, 0, 0));
		if ((PSIn.ShadowMapSamplingPos.z - 0.2f/100.0f) <= StoredDepthInShadowMap)
			shadow+=1.0f/9;

		StoredDepthInShadowMap = GetShadowMapDepth(ShadowMapSampler, PSIn.ShadowMapSamplingPos + float4(0, 1.0f/ShadowMapSize, 0, 0));
		if (depth <= StoredDepthInShadowMap)
			shadow+=1.0f/9;
		StoredDepthInShadowMap = GetShadowMapDepth(ShadowMapSampler, PSIn.ShadowMapSamplingPos + float4(0, -1.0f/ShadowMapSize, 0, 0));
		if (depth <= StoredDepthInShadowMap)
			shadow+=1.0f/9;
		StoredDepthInShadowMap = GetShadowMapDepth(ShadowMapSampler, PSIn.ShadowMapSamplingPos + float4(1.0f/ShadowMapSize, 0, 0, 0));
		if (depth <= StoredDepthInShadowMap)
			shadow+=1.0f/9;
		StoredDepthInShadowMap = GetShadowMapDepth(ShadowMapSampler, PSIn.ShadowMapSamplingPos + float4(-1.0f/ShadowMapSize, 0, 0, 0));
		if (depth <= StoredDepthInShadowMap)
			shadow+=1.0f/9;

			
	}

	if(xTextureEnabled)
	{
		float a = tex2D(TextureSampler, PSIn.TextureCoords).a;
		if(a < 0.1f)
			clip(-1);
		Output.Color.a = a;
	}

	Output.Color.rgb = shadow;

	return Output;
}

technique Shadow
{
	pass Pass0
    {   
    	VertexShader = compile vs_1_1 ShadowVS();
        PixelShader  = compile ps_2_0 ShadowPS();

        AlphaTestEnable = true;
        AlphaFunc = NotEqual;
        AlphaRef = 0;

        CullMode = None;
        ZWriteEnable = true;
        ZFunc = LessEqual;
    }
}
//------- Technique: Textured --------

VertexToPixel TexturedVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float2 inTexCoords: TEXCOORD0)
{	
	VertexToPixel Output = (VertexToPixel)0;
	float4x4 preViewProjection = mul (xView, xProjection);
	float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
    
	Output.Position = mul(inPos, preWorldViewProjection);
	Output.Normal = mul(normalize(inNormal), xWorld);
	Output.TextureCoords = inTexCoords;
    
	return Output;    
}

PixelToFrame TexturedPS(VertexToPixel PSIn) 
{
	PixelToFrame Output = (PixelToFrame)0;		
    
	float lightingFactor;
	
	lightingFactor = saturate(saturate(dot(PSIn.Normal, -xLightDirection)) + xAmbient);

	Output.Color = tex2D(TextureSampler, PSIn.TextureCoords)*lightingFactor;

	return Output;
}

technique Textured
{
	pass Pass0
    {   
    	VertexShader = compile vs_1_1 TexturedVS();
        PixelShader  = compile ps_2_0 TexturedPS();
    }
}


//------- Technique: Layered --------

VertexToPixel LayeredVS( float4 inPos : POSITION, float3 inNormal: NORMAL, float2 inTexCoords: TEXCOORD0)
{	
	VertexToPixel Output = (VertexToPixel)0;
	float4x4 preViewProjection = mul (xView, xProjection);
	float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
    
	Output.Position = mul(inPos, preWorldViewProjection);
	Output.TextureCoords = inTexCoords;
	Output.Normal = normalize(mul(normalize(inNormal), xWorld));
	Output.ShadowMapSamplingPos = Output.Position;//mul(inPos, xLightWorldViewProjection);
	
	return Output;    
}

PixelToFrame LayeredPS(VertexToPixel PSIn) 
{
	PixelToFrame Output = (PixelToFrame)0;
	float4 alpha = tex2D(AlphaSampler, PSIn.TextureCoords / xMapSize);

	float lightingFactor = 0;

	float d = dot(PSIn.Normal, -xLightDirection);
	d = saturate(d);

	float a = (1.0 + PSIn.Normal.y) * 0.5;

	float4 ambient = xAmbient * xSkyColor * a;
	
	Output.Color = 
		(
		tex2D(LayerSampler0, PSIn.TextureCoords / LayerScale.x) * alpha.x +
		tex2D(LayerSampler1, PSIn.TextureCoords / LayerScale.y) * alpha.y +
		tex2D(LayerSampler2, PSIn.TextureCoords / LayerScale.z) * alpha.z +
		tex2D(LayerSampler3, PSIn.TextureCoords / LayerScale.w) * alpha.w
		);
//		* PSIn.Color;

	if(d > 0)
	{
		float4 shadow = GetShadowMapDepth(ShadowMapSampler, PSIn.ShadowMapSamplingPos);

		lightingFactor = d * shadow.r;
		lightingFactor = saturate(lightingFactor);
	}

	Output.Color = Output.Color * (lightingFactor + ambient);

	return Output;
}

technique Layered
{
	pass Pass0
    {   
    	VertexShader = compile vs_1_1 LayeredVS();
        PixelShader  = compile ps_2_0 LayeredPS();

        AlphaTestEnable = false;
        
        CullMode = None;//CW;
        ZFunc = LessEqual;

        ZWriteEnable = true;
    }
}
//------- Technique: ShadowMap --------

SMapVertexToPixel ShadowMapVertexShader( float4 inPos : POSITION, float2 inTexCoords : TEXCOORD0)
{
    SMapVertexToPixel Output = (SMapVertexToPixel)0;

    Output.Position = mul(inPos, xLightWorldViewProjection);
    Output.Position2D = Output.Position;
    Output.TextureCoords = inTexCoords;

    return Output;
}
 
SMapPixelToFrame ShadowMapPixelShader(SMapVertexToPixel PSIn)
{
    SMapPixelToFrame Output = (SMapPixelToFrame)0;
    Output.Color = PSIn.Position2D.z;//xMaxDepth;

	if(xTextureEnabled)
	{
		float4 tex = tex2D(TextureSampler, PSIn.TextureCoords);
		if(tex.a < 0.1f)
			clip(-1);		
	}
 

    return Output;
}
 
technique ShadowMap
{
    pass Pass0
	{
        VertexShader = compile vs_2_0 ShadowMapVertexShader();
        PixelShader = compile ps_2_0 ShadowMapPixelShader();

        AlphaTestEnable = true;
        AlphaFunc = NotEqual;
        AlphaRef = 0;

        CullMode = None;
    }
}
 
 //------- Technique: Decal --------

VertexToPixel DecalVS( float4 inPos : POSITION, float2 inTexCoords: TEXCOORD0)
{	
	VertexToPixel Output = (VertexToPixel)0;
	float4x4 preViewProjection = mul (xView, xProjection);
	float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
    
    inPos.y = inPos.y + 0.05;
    
	Output.Position = mul(inPos, preWorldViewProjection);
	Output.TextureCoords = inTexCoords;
	Output.Color = float4(1, 1, 1, 1);
    
	return Output;    
}

PixelToFrame DecalPS(VertexToPixel PSIn) 
{
	PixelToFrame Output = (PixelToFrame)0;
	float4 tex = tex2D(TextureSampler, PSIn.TextureCoords);
	
	Output.Color = 
		tex * 
		PSIn.Color;

	Output.Color.a*= xAlpha;

	//Output.Color.a = tex.a * 0.5;
	//Output.Color = tex.a;

	return Output;
}

technique Decal
{
	pass Pass0
    {   
    	VertexShader = compile vs_1_1 DecalVS();
        PixelShader  = compile ps_2_0 DecalPS();

        AlphaTestEnable = true;
        AlphaBlendEnable = true;
        SrcBlend = SrcAlpha;
        DestBlend = InvSrcAlpha;

        ZEnable = true;
        ZWriteEnable = false;

        CullMode = None;
    }
}

//------- Technique: Particle --------

VertexToPixel ParticleVS( float4 inPos : POSITION, float4 inColor: COLOR, float2 inTextureCoords: TEXCOORD0)
{	
	VertexToPixel Output = (VertexToPixel)0;
	float4x4 preWorldView = mul(xWorld, xView);
	float4x4 preViewProjection = mul (xView, xProjection);
	float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
	
	float3 right = mul(preWorldView, float3(1, 0, 0));
//    float3 view = xView._m02_m12_m22;
//    float3 right = normalize(cross(view, float3(0, -1, 0)));

    float4 pos = mul(inPos, preWorldView);
//    pos += float4((inTextureCoords.x - 0.5f) * right, 1.0f);
//    pos = pos + float4((inTextureCoords.y - 0.5f) * up, 1.0f);
    pos.x = pos.x + (inColor.x - 0.5f) * inTextureCoords.y;
    pos.y = pos.y + (inColor.y - 0.5f) * inTextureCoords.y;

	Output.Position = mul(pos, xProjection);
	Output.TextureCoords = inColor.xy;//inTextureCoords;
	Output.Color = float4(1, 1, 1, inTextureCoords.x);//inColor;
    
	return Output;    
}

PixelToFrame ParticlePS(VertexToPixel PSIn) 
{
	PixelToFrame Output = (PixelToFrame)0;
	float4 tex = tex2D(TextureSampler, PSIn.TextureCoords);		
    
	float lightingFactor;

	lightingFactor = saturate(saturate(dot(PSIn.Normal, -xLightDirection)) + xAmbient);

	Output.Color = PSIn.Color*tex;

	return Output;
}

technique Particle
{
	pass Pass0
    {   
    	VertexShader = compile vs_1_1 ParticleVS();
        PixelShader  = compile ps_2_0 ParticlePS();
        
        AlphaTestEnable = true;
        SrcBlend = SrcAlpha;
        DestBlend = InvSrcAlpha;

        ZEnable = true;
        ZWriteEnable = false;

        CullMode = None;
    }
}

technique ParticleAdd
{
	pass Pass0
    {   
    	VertexShader = compile vs_1_1 ParticleVS();
        PixelShader  = compile ps_2_0 ParticlePS();
        
        AlphaTestEnable = true;
        SrcBlend = SrcAlpha;
        DestBlend = One;

        ZEnable = true;
        ZWriteEnable = false;

        CullMode = None;
    }
}

//------- Technique: Tail --------

VertexToPixel TailVS( float4 inPos : POSITION, float4 inColor: COLOR, float2 inTextureCoords: TEXCOORD0)
{	
	VertexToPixel Output = (VertexToPixel)0;
	float4x4 preWorldView = mul(xWorld, xView);
	float4x4 preViewProjection = mul (xView, xProjection);
	float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
	
	float3 right = mul(preWorldView, float3(1, 0, 0));
//    float3 view = xView._m02_m12_m22;
//    float3 right = normalize(cross(view, float3(0, -1, 0)));

    float4 pos = mul(inPos, preWorldView);
//    pos += float4((inTextureCoords.x - 0.5f) * right, 1.0f);
//    pos = pos + float4((inTextureCoords.y - 0.5f) * up, 1.0f);
    pos.x = pos.x + (inColor.x - 0.5f) * inTextureCoords.y;
    pos.y = pos.y + (inColor.y - 0.5f) * inTextureCoords.y;

	Output.Position = mul(pos, xProjection);
	Output.TextureCoords = inColor.xy;//inTextureCoords;
	Output.Color = float4(1, 1, 1, inTextureCoords.x);//inColor;
    
	return Output;    
}

PixelToFrame TailPS(VertexToPixel PSIn) 
{
	PixelToFrame Output = (PixelToFrame)0;
	float4 tex = tex2D(TextureSampler, PSIn.TextureCoords);		
    
	float lightingFactor;

	lightingFactor = saturate(saturate(dot(PSIn.Normal, -xLightDirection)) + xAmbient);
	
	Output.Color = PSIn.Color*tex;

	return Output;
}

technique Tail
{
	pass Pass0
    {   
    	VertexShader = compile vs_1_1 TailVS();
        PixelShader  = compile ps_2_0 TailPS();
        
        AlphaTestEnable = true;
        SrcBlend = SrcAlpha;
        DestBlend = InvSrcAlpha;

        ZEnable = true;
        ZWriteEnable = false;

        CullMode = None;
    }
}

//------- Technique: PointSprites --------

struct SpritesVertexToPixel
{
    float4 Position   	: POSITION;
    float4 Color    	: COLOR0;
    float1 Size 		: PSIZE;
};

SpritesVertexToPixel PointSpritesVS (float4 Position : POSITION, float4 Color : COLOR0, float1 Size : PSIZE)
{
    SpritesVertexToPixel Output = (SpritesVertexToPixel)0;
     
    float4x4 preViewProjection = mul (xView, xProjection);
	float4x4 preWorldViewProjection = mul (xWorld, preViewProjection); 
    Output.Position = mul(Position, preWorldViewProjection);    
    Output.Color = Color;
    Output.Size = 1/(pow(Output.Position.z,2)+1	) * Size;
    
    return Output;    
}

PixelToFrame PointSpritesPS(SpritesVertexToPixel PSIn, float2 TexCoords  : TEXCOORD0)
{ 
    PixelToFrame Output = (PixelToFrame)0;

    Output.Color = tex2D(TextureSampler, TexCoords)*PSIn.Color;
    
    return Output;
}

technique PointSprites
{
	pass Pass0
    {   
    	PointSpriteEnable = true;
    	VertexShader = compile vs_1_1 PointSpritesVS();
        PixelShader  = compile ps_2_0 PointSpritesPS();
    }
}

//------- Technique: SkyBox --------

VertexToPixel SkyBoxVS(float4 Position : POSITION, float2 inTextureCoords: TEXCOORD0)
{
	VertexToPixel Out = (VertexToPixel)0;

	float4x4 preViewProjection = mul (xView, xProjection);
	float4x4 preWorldViewProjection = mul (xWorld, preViewProjection); 
	Out.Position = mul(Position, preWorldViewProjection);
	Out.TextureCoords = inTextureCoords;

	return Out;
}

PixelToFrame SkyBoxPS(VertexToPixel In)
{
    PixelToFrame Out;

    Out.Color = tex2D(TextureSampler, In.TextureCoords);

    return Out;
}

technique SkyBox
{
   pass Pass0
   {
        ZEnable = False;
        ZWriteEnable = False;

        CullMode = CCW;

        VertexShader = compile vs_1_1 SkyBoxVS();
        PixelShader = compile ps_1_1 SkyBoxPS();
        
   }
}