A few years back I worked on a Unity engine game for a school project, called “Distortion”. In this game, the player has a pair of scifi-magic gloves that allows him or her to bend space. I ended up writing some really neat visual effects for the game, but it never really went anywhere. This afternoon I found a question from a fellow Unity developer, asking how to make “heat ripple” effects for a jet engine, and I decided to clean up the visual effects and package them into a neat project so that others could use it too!
And so, Heatwave was born.
Heatwave is a post-processing effect for the Unity game engine that takes advantage of multi-camera rendering to make cool distortion effects easy! It does this by rendering a full-screen normal map in the scene using a specialized shader. This shader will render particle effects, UI elements, or overlay graphics together into a single map that is then used to calculate refractions!
The main render target is blitted to a fullscreen quad, and distorted by offsetting the UV coordinates during the copy based on the refraction vector calculated using the normal map, resulting in a nice realtime psuedo-refraction!
There are a few issues with this method, mainly that it doesn’t calculate “true” refractions. The effect is meant to look nice more than to make accurate calculations, so cool effects like refracting light around corners and computing caustics aren’t possible. The advantage however is that the effect operates in screen-space. The time required to render distortion is constant, and the cost of adding additional distortion sources is near zero, making it perfect for games, and situations where a large number of sources will be messing with light!
I’ve made a small asset-package so other Unity developers can download the sources and use them!
You can find the project on Github here!
Hey dude, after working for several hours to get things working in my game (hiding the second camera made things tricky), I think the Y position of the distortion effect is getting inverted (ie: moving the heat particle up in the scene view moves the visual effect down in the game view)
I’m using orthographic cameras, but even when I switched them back to perspective, I’m seeing the same thing. Any idea what’s going on?
Sorry about that! There’s a platform dependent bug where the rendered image is inverted on the Y axis. It should be fixed now! 🙂
There was a platform-dependent issue in the shaders that I didn’t see working on Mac. I’ve updated the Github, and the new version should work better on all platforms!