//+---------------------------------------------------------------------+
//|Technicolor EFFECT                                   		|
//+---------------------------------------------------------------------+
//|FOR ENBSeries Indonesian Group                             		|
//+---------------------------------------------------------------------+
//|CODES AND SHADERS DECOMPILED BY DKT70                		| 
//|MODIFIER BY J3SMOOVE              					|
//+---------------------------------------------------------------------+

// Soften Resolution - Use multiples of your native resolution, higher for sharper image, balance with sharp filter to help aliasing.
float xres = 1920;  //Multiples of your Horizontal-Res (e.g. 2x or 3x), higher = less blur.
float yres = 1200;  //Multiples of your Vertical-Res (e.g. 2x or 3x), higher = less blur.

// Technicolor Color Effects, use these settings like a color map, center values are more sensitive.
float4 redfilter : COLOR       = {1.0, 0.0, 0.0, 0.0};
float4 bluegreenfilter : COLOR = {0.0, 1.0, 1.0, 0.0};
float4 cyanfilter : COLOR      = {0.0, 1.0, 0.5, 0.0};
float4 magentafilter : COLOR   = {1.0, 0.0, 0.25, 0.0};

// Strength of Technicolor effect, 0.0 = Off,  Higher = stronger Technicolor effect.
float amount = 0.25;

// Sharpen effect settings.
float sharps = 1.00; // Sharpen Strength.
float offsetv = 0.2; // Offset value, higher = more offset from center.
float sxres = 1920; // Horizontal Resolution setting.
float syres = 1200; // Vertical Resolution setting.
float aspect = 1.6; // Aspect Ratio.

//--------------------------------------------------------------------------------------
// Textures
//--------------------------------------------------------------------------------------
texture2D texColor;

//--------------------------------------------------------------------------------------
// Sampler Inputs
//--------------------------------------------------------------------------------------
sampler2D InputSampler = sampler_state
{
     Texture = (texColor);
     MinFilter = Linear;
     MagFilter = Linear;
     MipFilter = None;
     AddressU  = Clamp;
     AddressV  = Clamp;
     SRGBTexture=FALSE;
     MaxMipLevel=0;
     MipMapLodBias=0;
};

//--------------------------------------------------------------------------------------
// Global Variables, non tweakable.
//--------------------------------------------------------------------------------------
float ScreenSize;
float ScreenScaleY;

//--------------------------------------------------------------------------------------
// Struct Definitions
//--------------------------------------------------------------------------------------
struct VS_OUTPUT_POST {
 float4 vpos  : POSITION;
 float2 txcoord : TEXCOORD0;
};

struct VS_INPUT_POST {
 float3 pos  : POSITION;
 float2 txcoord : TEXCOORD0;
};

//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
VS_OUTPUT_POST VS_PostProcess(VS_INPUT_POST IN)
{
 VS_OUTPUT_POST OUT;

 float4 pos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);

 OUT.vpos=pos;
 OUT.txcoord.xy=IN.txcoord.xy;

 return OUT;
}

//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------

float4 main(float2 technicolor : TEXCOORD) : COLOR

{
    float4 col0 = tex2D(InputSampler, technicolor);
    
	float4 redrecord = col0 * redfilter;
	float4 bluegreenrecord = col0 * bluegreenfilter;
	
	float4 rednegative = float(redrecord.r);
	float4 bluegreennegative = float((bluegreenrecord.g + bluegreenrecord.b)/2.0);

	float4 redoutput = rednegative + cyanfilter;
	float4 bluegreenoutput = bluegreennegative + magentafilter;

	float4 result = redoutput * bluegreenoutput;
	
	// TOP ROW
    float4 s11 = tex2D(InputSampler, technicolor + float2(-1.0f / xres, -1.0f / yres));	// LEFT
    float4 s12 = tex2D(InputSampler, technicolor + float2(0, -1.0f / yres));				// MIDDLE
    float4 s13 = tex2D(InputSampler, technicolor + float2(1.0f / xres, -1.0f / yres));	    // RIGHT

    // MIDDLE ROW
    float4 s21 = tex2D(InputSampler, technicolor + float2(-1.0f / xres, 0));				// LEFT
    float4 s23 = tex2D(InputSampler, technicolor + float2(-1.0f / xres, 0)); 				// RIGHT

    // LAST ROW
    float4 s31 = tex2D(InputSampler, technicolor + float2(-1.0f / xres, 1.0f / yres));	    // LEFT
    float4 s32 = tex2D(InputSampler, technicolor + float2(0, 1.0f / yres));				// MIDDLE
    float4 s33 = tex2D(InputSampler, technicolor + float2(1.0f / xres, 1.0f / yres));	    // RIGHT

    // Average the color with surrounding samples
    col0 = (col0 + s11 + s12 + s13 + s21 + s23 + s31 + s32 + s33) / 9;
	
    float2 InputSize =float2(sxres, syres/aspect);
    float Amount = sharps; // Strength of sharpen, higher values = more sharp images
    float2 offset = offsetv / InputSize; // Offset value for sharp effect, lower value if images looks slightly off-centre. 
    col0 = tex2D(InputSampler, technicolor);
    col0 += tex2D(InputSampler, technicolor - offset) * Amount;
    col0 -= tex2D(InputSampler, technicolor + offset) * Amount;

    return lerp(col0, result, amount);
}

//--------------------------------------------------------------------------------------
// Compiler 1
//--------------------------------------------------------------------------------------

technique PostProcess
{
    pass P0
    {
#ifdef E_SHADER_3_0
 VertexShader = compile vs_3_0 VS_PostProcess();
 PixelShader  = compile ps_3_0 main();
#else
 VertexShader = compile vs_2_0 VS_PostProcess();
 PixelShader  = compile ps_2_0 main();
#endif

 ZEnable=FALSE;
 CullMode=NONE;
 ALPHATESTENABLE=FALSE;
 SEPARATEALPHABLENDENABLE=FALSE;
 AlphaBlendEnable=FALSE;
 FogEnable=FALSE;
 SRGBWRITEENABLE=FALSE;
 }
}


