struct prev
{
   uniform float2 video_size;
   uniform float2 texture_size;
   uniform sampler2D texture;
   float2 tex_coord;
};

struct input
{
   float2 video_size;
   float2 texture_size;
};

struct VertexData
{
   float2 tex;
   float2 prev;
};

#define CRT_PASS PASSPREV4

void main_vertex
(
	float4 position : POSITION,
	float2 texCoord : TEXCOORD0,
   prev CRT_PASS,

   uniform float4x4 modelViewProj,

	out float4 oPosition : POSITION,
   out VertexData vert
)
{
	oPosition = mul(modelViewProj, position);

   vert.tex = texCoord;
   vert.prev = CRT_PASS.tex_coord;
}

// For debugging
#define BLOOM_ONLY 0

#pragma parameter BLOOM_STRENGTH "Glow Strength" 0.45 0.0 0.8 0.05
#pragma parameter OUTPUT_GAMMA "Monitor Gamma" 2.2 1.8 2.6 0.02
#ifdef PARAMETER_UNIFORM
uniform float BLOOM_STRENGTH;
uniform float OUTPUT_GAMMA;
#else
#define BLOOM_STRENGTH 0.45
#define OUTPUT_GAMMA 2.2
#endif

float4 main_fragment(in VertexData vert, uniform sampler2D s0 : TEXUNIT0, uniform input IN, prev CRT_PASS) : COLOR
{
#if BLOOM_ONLY
   float3 source = BLOOM_STRENGTH * tex2D(s0, vert.tex).rgb;
#else
   float3 source = 1.15 * tex2D(CRT_PASS.texture, vert.prev).rgb;
   float3 bloom = tex2D(s0, vert.tex).rgb;
   source += BLOOM_STRENGTH * bloom;
#endif
   return float4(pow(saturate(source), 1.0 / OUTPUT_GAMMA), 1.0);
}

