O'Reilly logo

Libgdx Cross-platform Game Development Cookbook by Alberto Cejas Sánchez, David Saltares Márquez

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2D depth of field shader

Shaders can help us achieve a huge amount of visually interesting effects and give your games the extra something to impress users. This recipe will tackle a very basic implementation of a depth of field postprocessing effect, which will reinforce a cinematic feeling.

The term depth of field comes from film and photography and refers to the distance between the nearest and furthest objects in a scene that appear reasonably sharp. Lenses can focus at a single distance, and the sharpness of objects will decrease as they are positioned away from the point. The human eye itself also works in a similar manner, although it can dynamically adjust the focus point much more easily.

The following diagram illustrates the depth of field ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required