Fishy Eyes in Unreal Engine 5

Fish Eye Effect

Apparently, the secret to lifelike Unreal imagery is to apply a fish eye and a shaky camera to the scene.

The effect is actually relatively easy to implement. I'm sure there's an easier way to implement this, but below is what I went with.

Material View Image

The first trick is to take the longer of the two dimensions of the viewport and then divide that by the dimensions. The result is a float2 containing one component of 1.f and one component below that.

The float2 is used to scale the texture coordinate, but it can't scale it immediately. Doing so would scale away from the upper left corner rather than the centre. To fix that, the texture coordinate needs to be mapped to the range [-1, 1].

The scaled texture coordinate is then turned into a radial distortion effect by taking the length of the new coordinate, optionally powering it, and multiplying by a strength. There is a division by 1.42 here too that nominally acts to scale the length back to 0-1.

Finally, one is added to the distortion effect to make it an appliable modifier, then we divide the original, remapped texture coordinate by the modifier. The final node merely maps the texture coordinates back to the [0-1] space required for sampling the scene colour.