sampler texture0 : register(s0);
sampler texture1 : register(s1);

float4x4 WorldViewProjectionTransform  : WORLDVIEWPROJ;
float fStripMin;
float fStripMax;
float fAbsoluteTime;


struct VS_OUTPUT 
{
   float4 Position  : POSITION;
   float2 TexCoord  : TEXCOORD0;    
};

struct PS_OUTPUT
{
    float4 RGBColor : COLOR0;  // Pixel color    
};

VS_OUTPUT vertexMain(
				float4 vPosition : POSITION,
				float2 texCoord0 : TEXCOORD0)
{
	VS_OUTPUT Output; 

	Output.Position = mul(vPosition, WorldViewProjectionTransform);
	Output.TexCoord = texCoord0;   

	return Output;
}


PS_OUTPUT pixelMain(VS_OUTPUT In)
{
	PS_OUTPUT output;
	
	// create a bulb form ;)
	float pi = acos(0.f) * 2.f;
	float2 dirVec = In.TexCoord - float2(0.5, 0.5);
	float dist = length(dirVec);
	float fFactor = sin(dist/0.5f * pi) * 0.018;
	dirVec = normalize(dirVec) * fFactor;

	float4 color = tex2D(texture0, In.TexCoord - dirVec);
	// reduce contrast and add vignetting
	color = saturate(color * 0.8f + 0.2f);
	color *= 1.f - (dist * dist * 2.5f);

	// do a slight desaturation
	float fIntensity =  dot(color.rgb, float3(0.299f, 0.587f, 0.114f));
	float4 intensityColor = {fIntensity, fIntensity, fIntensity, color.a};
	float4 saturation = {0.5f, 0.5f, 0.5f, 0.0f};
	color = saturate(lerp(intensityColor, color, saturation));


	// add some perlin noise
	float2 move = float2(0.f, 4.f);
    float3 perlin = tex2D(texture1, In.TexCoord + fAbsoluteTime*move).rgb / 2;
    perlin += tex2D(texture1, In.TexCoord * 2 + fAbsoluteTime*move).rgb / 4;
    perlin += tex2D(texture1, In.TexCoord * 4 + fAbsoluteTime*move).rgb / 8;
    perlin += tex2D(texture1, In.TexCoord * 8 + fAbsoluteTime*move).rgb / 16;
    perlin += tex2D(texture1, In.TexCoord * 16 + fAbsoluteTime*move).rgb / 32;
    perlin += tex2D(texture1, In.TexCoord * 32 + fAbsoluteTime*move).rgb / 64; 

	color.rgb *= perlin;

	// paint strip
	if ((fStripMin < In.TexCoord.y) && (In.TexCoord.y < fStripMax))
		color.rgb *= 0.95;
	
	output.RGBColor = color;
	return output;
}