Here is something I worked on for the last few days, a cool 2d refractive
shader to mimic real 3d refraction. The idea come from the need I have to
produce some cool textures giving an object that special refractive
appearance yet without needing to compute real/traced refraction and also
without needing to pre-computing the refraction direction by tracing the
object ahead of time saving the refraction pattern in a texture. I wanted to
have a dynamic approach such that I could manipulate the properties or the
mapping at runtime producing different/distorted looks.
So I started with a sphere and tried to derive a formula which gives the
refraction direction for each visible pixel on the screen the sphere covers
computed solely from basic geometric optics. This direction is then used as
a look-up into a texture.
I also derived a formula for the specular reflection direction and also for
internal reflection (1 bounce), as can be seen in the animation above.
So there is no lengthy intersection computation needed. Depending on the
fidelity, three texture look-ups are needed at most when wanting to have
refraction, reflection and internal reflection combined.
Basically, it's a cool 2d screen distortion effect, mapping a 2d screen
pixel into a 2d texture, yet with some twisted computation in-between which
can all be pre-computed if the geometric specification and material properties
(like ior) of the object remain constant making it utterly fast.
However, there is a small caveat. To really cover all the reflection etc. one
needs a texture with a large fov. The fov produced from refraction could be
limited depending on the ior, reducing the need to project the wohle
environment (also depending on the object). However, it's best to have a full
cubemap or spherical one to really cover each direction. Usually one cubemap
of the environment would suffice for a couple of effects, but rendering local
cubemaps would allow for even more interesting effects.
Of course, all the distorted pixels seen in the animation above are fully
Fresnel weighted as well, producing the correct look for such a (water,
ior 1.33) sphere.
The idea now is to distort the formulas to produce other refractive shapes
etc. useful to either map onto objects or for some other screen effects like
water splashes whatsoever. CA could also be added with ease as well as color
filters.
Edit: