HLSL: UV swap
This shader swaps the U and V channels in the YUV color space with a single matrix multiplication. The constants in the matrix are calculated based on wikipedia's RGB -> YUV matrix, the corresponding YUV -> RGB matrix, and the simple reversing matrix R obtained by:
- Take the 4x4 identity matrix I
- Swap the second and third rows (corresponding to U and V).
Multiply the three matrices RGB->YUV, R, and YUV->RGB. Get a computer to do it because the math is boring.
sampler s0 : register(s0);
float4 main(float2 tex : TEXCOORD0) : COLOR
{
float4x4 matUVshiftRGB = {
-0.00029999999999998084, 0.00013179999999999513, 1.0041311, 0,
-0.0010000000000000286, 1.004206, 0.00014329999999999492, 0,
1, -.00002499999999975368, 0.00002220000000001008, 0,
0, 0, 0, 0};
// matrix math!
return mul(tex2D( s0, tex), matUVshiftRGB);
}
This shader was made to use with Media Player Classic.
