Skip to content
  • Niklas Haas's avatar
    shaders: add AV1 film grain shader · 1d635def
    Niklas Haas authored
    This is can be used to apply AV1 film grain onto planes directly on the
    GPU. Eventually, the pl_renderer will be able to take this grain params
    struct and do it automatically - but for now, we need the basic shader
    implemntation first.
    
    We make some amount of effort to follow the AV1 spec exactly, even down
    to reproducing the (terrible) PRNG, awkward corner blending and rounding
    (where possible).
    
    Some things are not currently preserved: In particular, the blending of
    pixels is not correctly rounded. (We continue calculating on the
    un-rounded floating point values) In practice this does not produce any
    significant deviation (bounded by +/- 1) - especially if you don't round
    but instead continue calculating with floating point precision, in which
    case the true error is only the difference between the un-rounded value
    and its correctly rounded counterpart (bounded by +/- 0.5).
    
    The generated shader can be used as both a compute shader and a fragment
    shader, but a compute shader is preferred (slightly faster).
    
    We upload the weights and grain tables using an SSBO (which we need
    anyway to store the integer offset table). In theory we could try
    replacing these by LUTs, but the existing sh_lut mechanism does not lend
    itself well to frequent updates, and we will want to be updating this
    texture constantly (especially for parallel streaming).
    
    But more testing is warranted here. For now, this should be a working v1
    implementation.
    1d635def