• Hey! Guest! The 37th GMC Jam will take place between May 28th, 12:00 UTC and June 1st, 12:00 UTC. Why not join in! Click here to find out more!

Suggestions for producing rewind distortion effect with sprite

bacteriaman

Member
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.
 

NightFrost

Member
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.
 
Top