// actually not used HDR10 shader - kept only for future

uniform sampler2DRect Ytex;
uniform sampler2DRect Utex,Vtex;
uniform vec3 offset;
uniform vec4 cspace;
uniform vec3 Rcoeff;
uniform vec3 Gcoeff;
uniform vec3 Bcoeff;
uniform    float  imgHeight;

void main(void) {
    vec3 YUV, RGB;
    float nx,ny,nxuv,nyuv;
    float r,r1;
    nx=0.5 + gl_TexCoord[0].x;
    ny=imgHeight - gl_TexCoord[0].y;
    nxuv=nx / cspace.r;
    nyuv=ny / cspace.g;
    YUV.x=texture2DRect(Ytex,vec2(nx,ny)).r / cspace.b     + texture2DRect(Ytex,vec2(nx,ny)).g * cspace.a;
    YUV.y=texture2DRect(Utex,vec2(nxuv,nyuv)).r / cspace.b +  texture2DRect(Utex,vec2(nxuv,nyuv)).g * cspace.a;
    YUV.z=texture2DRect(Vtex,vec2(nxuv,nyuv)).r / cspace.b +  texture2DRect(Vtex,vec2(nxuv,nyuv)).g * cspace.a;

    YUV += offset;

    RGB.r = dot(YUV, Rcoeff);
    RGB.g = dot(YUV, Gcoeff);
    RGB.b = dot(YUV, Bcoeff);

    r1 = 18.8515625 - 18.6875 * pow( RGB.r, 1.0 / 78.84375);
    r = max( pow( RGB.r, 1.0 / 78.84375 ) - 0.8359375, 0.0 ) ;
    //if( r > 1.0 ) r = 0.0; else if( r < 0.0 ) r = 0.0;
    RGB.r =  1000.  * pow( r / r1, 1.0 / 0.1593017578 );

    r1 = 18.8515625 - 18.6875 * pow( RGB.g, 1.0 / 78.84375);
    r = max( pow( RGB.g, 1.0 / 78.84375 ) - 0.8359375, 0.0 ) ;
    //if( r > 1.0 ) r = 0.0; else if( r < 0.0 ) r = 0.0;
    RGB.g =  1000.  * pow( r / r1, 1.0 / 0.1593017578 );

    r1 = 18.8515625 - 18.6875 * pow( RGB.b, 1.0 / 78.84375);
    r = max( pow( RGB.b, 1.0 / 78.84375 ) - 0.8359375, 0.0 ) ;
    //if( r > 1.0 ) r = 0.0; else if( r < 0.0 ) r = 0.0;
    RGB.b =  1000.  * pow( r / r1, 1.0 / 0.1593017578 );

    gl_FragColor = vec4(RGB, 1.0);
}
;
