/* COMPATIBILITY 
   - HLSL compilers
   - Cg   compilers
*/



/*
   Super-res shader - Shiandow

   Ported from Shiandow's code by Hyllian, 2016.

   This file is a part of MPDN Extensions.
   https://github.com/zachsaw/MPDN_Extensions
  
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 3.0 of the License, or (at your option) any later version.
   
   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.
   
   You should have received a copy of the GNU Lesser General Public
   License along with this library.
*/   



const static float3 Y = float3(.2126, .7152, .0722);


float RGBtoYUV(float3 color)
{
  return dot(color, Y);
}


    struct orig
    {
	uniform float2 video_size;
	uniform float2 texture_size;
	uniform sampler2D texture;
    };

     
    struct input
    {
        float2 video_size;
        float2 texture_size;
        float2 output_size;
        float  frame_count;
        float  frame_direction;
        float frame_rotation;
    };
     
     
    struct out_vertex {
        float4 position : POSITION;
        float4 color    : COLOR;
        float2 texCoord : TEXCOORD0;
    };
     
    /*    VERTEX_SHADER    */
    out_vertex main_vertex
    (
        float4 position    : POSITION,
        float4 color    : COLOR,
        float2 texCoord1   : TEXCOORD0,
     
        uniform float4x4 modelViewProj,
	orig ORIG,
        uniform input IN
    )
    {

	// This line fix a bug in ATI cards.
	float2 tex = texCoord1;

        out_vertex OUT = {
            mul(modelViewProj, position),
            color,
            tex
        };
     
        return OUT;
    }
     
     
float4 main_fragment(in out_vertex VAR, uniform sampler2D s0 : TEXUNIT0, orig ORIG, uniform input IN) : COLOR
{
    float2 tex = VAR.texCoord;

    float4 c0 = tex2D(s0, tex);
    float4 c1 = tex2D(ORIG.texture, tex);

    return float4(c0.xyz - c1.xyz, RGBtoYUV(c0.rgb));
}

