/********************************************************************************
 Copyright (C) 2012 Hugh Bailey <obs.jim@gmail.com>

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program 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 General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
********************************************************************************/


uniform Texture2D diffuseTexture;
uniform float4 outputColor;
uniform float gamma;

SamplerState textureSampler
{
    AddressU  = Clamp;
    AddressV  = Clamp;
    Filter    = Linear;
};

struct VertData
{
    float4 pos      : SV_Position;
    float2 texCoord : TexCoord0;
};

float4 main(VertData input) : SV_Target
{
    const float4x4 yuvMat = {1.164384,  1.164384,  1.164384, 0.0,
                             0.000000, -0.391762,  2.017232, 0.0,
                             1.596027, -0.812968,  0.000000, 0.0,
                            -0.874202,  0.531668, -1.085631, 1.0};

    //a nice quick colorspace conversion
    float4 yuvx = diffuseTexture.Sample(textureSampler, input.texCoord).rgba;
    float4 rgbx = mul(float4(yuvx.xyz, 1.0), yuvMat);

	rgbx = saturate(rgbx);

	rgbx.rgb = pow(rgbx.rgb, gamma);

    return rgbx * outputColor;
}
