Hello. I’ve been struggling to reproduce a specific effect in Unity originally done on the SNES and Genesis. Namely, I’d like to be able to offset rows of pixels of a texture independently of each other. On the SNES and Genesis, this effect was achieved using horizontal interrupts, changing the position of the sprites between each scan line, which allowed for effects like zig-zags and sine waves and more with great amounts of control and customization. To my knowledge, the original method of achieving these effects cannot be implemented on modern hardware for many reasons. I’ve searched for a more contemporary means of reproducing the effect, but my searches have yielded little.
I found a useful shader online which uses a grabpass to distort the image of what’s behind it, and here’s what that looks like when I apply it:
The problem I’m having with this is that the grabpass grabs the background as well as the foreground element as a natural result of the rendering order. I’d like to distort only the foreground element. Is there any way I can do something like store the image data of the distorted foreground element before rendering the background and then re-applying the image over the background? Is there a different way to achieve the effect I’m after without the use of grabpass?
But if you could use UI as the foreground element, then they wouldn’t be affected. That would be an easy hack. Anyway I don’t know what you are going to have on the screen so I’m just guessing.
Yes post processing should not be applied to the canvas, unless you use World Space canvas Render Mode. i.e. like this (my old tilt-shift blur effect for HDRP, but you get the idea):
Wait, so would this actually work as an alternative method to achieving the same effect? I have the foreground distorted but the background is not effected, but with your example, it seems that the opposite is true. Would doing it this way mean rendering the UI at a lower depth to keep the background behind the distorted texture?
You want to get the foreground distorted? Sorry I think I’ve misread now too many times. I guess I’m a bit too tired - Your image was a bit unclear so I’m not sure what you were after, either. So do you want an object which would perform a sine wave distortion for anything that shows through it, or what.
But if you want to distort some 2D element, then it would be quite easy to create a shader that just distorts a texture, for example? But it depends a lot on the use case. Of course you can’t use such simple approach if you want to capture something from the game scene, for example… And if you got something already working, maybe you just use the approach that was already suggested above.
I should’ve tried to supply an image now that I have the effect working. Yes, I was trying to distort the foreground element without distorting the background.
The way I have it set up now has the sine wave shift with respect to time, but I’m looking into changing it to work based on the pivot of the GameObject with the material which has the applied shader.