#include "../../compat_includes.inc"
uniform COMPAT_Texture2D(decal) : TEXUNIT0;
uniform float4x4 modelViewProj;

#include "ntsc-pass2-vertex.inc"
#include "ntsc-decode-filter-3phase.inc"
#include "ntsc-rgbyuv.inc"

#define fetch_offset(offset, one_x) \
   COMPAT_SamplePoint(s0, tex + float2((offset) * (one_x), 0.0)).xyz

#pragma parameter NTSC_CRT_GAMMA "NTSC CRT Gamma" 2.5 0.0 10.0 0.1
#pragma parameter NTSC_MONITOR_GAMMA "NTSC Monitor Gamma" 2.0 0.0 10.0 0.1

#ifdef PARAMETER_UNIFORM
uniform float NTSC_CRT_GAMMA;
uniform float NTSC_MONITOR_GAMMA;
#else
#define NTSC_CRT_GAMMA 2.5
#define NTSC_MONITOR_GAMMA 2.0
#endif

float4 ntsc_pass2_3phase_gamma(float2 texture_size, float2 tex, COMPAT_Texture2D(s0))
{
#include "ntsc-pass2-decode.inc"
   float3 rgb = yiq2rgb(signal);
   float3 gamma_mod = float3(NTSC_CRT_GAMMA / NTSC_MONITOR_GAMMA, NTSC_CRT_GAMMA / NTSC_MONITOR_GAMMA, NTSC_CRT_GAMMA / NTSC_MONITOR_GAMMA);
   return float4(pow(rgb, gamma_mod), 1.0);
}

float4 main_fragment(COMPAT_IN_FRAGMENT) : COMPAT_Output
{
	return ntsc_pass2_3phase_gamma(COMPAT_texture_size, VOUT.texCoord, decal);
}
COMPAT_END
