Suggestions for producing rewind distortion effect with sprite

Discussion in 'Programming' started by bacteriaman, Oct 8, 2019.

  1. bacteriaman

    bacteriaman Member

    Joined:
    Jun 20, 2016
    Posts:
    23
    I have an sprite with a series of frames. At some point the sprite animation sequence is reversed and restarted from the beginning.

    I already have the "rewind" functionality working. The sprite_index is incrementally decreased rapidly until reaching zero.

    I'm now looking to visually distort the sprite, like when rewinding a VHS tape.

    I'm looking for suggestions on how to achieve this effect. Can this be accomplished with shaders? I have never used shaders before, but this might be a great opportunity.

    All comments welcome.
     
  2. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,964
    Yes, a shader would do the job. Basically, for each row of pixels, you'd randomly offset the sprite read position to visually move it some amount to left and right. Shaders do not have any randomizers so you'd need to add a function to your shader that outpus pseudorandom values based on input. The good thing about pseudorandom generators is, for a specific input value you always get the same output value (but when you change input in linear fashion, the output appears to change randomly). It is good because it lets you control how the random noise changes. For the input value, you'd send some seed value to the shader (simply start with a value of zero) and inside the shader you send the seed plus pixel's vertical offset to the pseudorandom generator. This means if you don't change the seed value, the random horizontal offsets look the same every step, and if you change the seed value you can make the effect traverse across the sprite.

    A good tutorial for using shaders with GMS can be found here.
     
  3. bacteriaman

    bacteriaman Member

    Joined:
    Jun 20, 2016
    Posts:
    23
    @NightFrost, wow, this is great information--thank you! Thanks also for the tutorial link. I'm looking forward to working with shaders!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice