Search code examples
windowshlslwindows-terminal

Is there a way to save an output texture to be used as input for the next iteration of that pixel in HLSL?


I'm thinking of writing a pixel shader for Windows Terminal and I'd love to add phosphor persistence. For that, I'd need to save a couple previous results of the shader output and keep them across multiple pixel calls. Is there a way to declare a texture map that is preserved across multiple frames in time?


Solution

  • There is no easy way to accomplish this in the windows terminal.

    Shaders are usually called per frame, with no access to the parameters used in the call before or after. Normally, because nothing is preserved within the shader inbetween frames, you would accomplish this using the following:

    1. Save the result of each shader call outside of the shader at the end of each frame
    2. Send it to the shader in a Texture2D on the next call.
    3. Sample the texture to find the previous pixel value.

    This is exactly what implementations of TAA do.

    Without the ability to control the call to the shader, this is impossible. BUT the terminal src is here and you can give yourself that functionality.