// This shader remaps an image using a 2D source texture // where each channel of the texture holds a remap function // A and G are mapped horizontally // R and B are mapped vertically // This is so they match what is expected by texreg2ar and texreg2gb. xps.1.1 // c0 should contain the amount to desaturate by def c0, 0,0,0,0 def c1, 1,0,0,1 def c2, 0,1,1,0 def c3, 0.3, 0.59, 0.11, 0.0 //def c3, 0,1,1,0 tex t0 // holds the image to remap texreg2ar t1, t0 // holds the 2D remap texture texreg2gb t2, t0 // holds the 2D remap texture // now the remapping has been done, and the results are in t1 and t2. // all there is now is to extract and output them: // t1.a has our desired alpha // t1.r has our desired red // t2.g has our desired green // t2.b has our desired blue // use constants to extract the relevant channels xmma discard, discard, r0, t1, c1, t2, c2 // now desaturate dp3 r1, r0, c3 // and blend between full-color and desaturated color lrp r0, c0.a, r1, r0