Book Image

Libgdx Cross-platform Game Development Cookbook

Book Image

Libgdx Cross-platform Game Development Cookbook

Overview of this book

Table of Contents (20 chapters)
Libgdx Cross-platform Game Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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 effect:

Computer graphics are not affected by this constraint, yet they constantly try to emulate it; why? The answer is rather simple; it gives the impression that a scene is being shown by a real-life camera lens rather than rendered as a computer...