Hide: Playing with shaders

A desaturated image is calculated and applied to output at 50%. I have a few commented lines where an average brightness for a frame would weight desaturation toward darker frames, but calculating the average brightness for a frame is turning out to be challenging. I will need to use a uniform to store passing fragments, then calculate the average based on the last frame worth of fragments. I tried calculating a frame's lightness via mipmapping, but it didn't work because I don't have access to the full frame.I get this sinking feeling that there's a better solution out there, but it's over my head at the moment. Maybe some more reading will help clear it up.