In addition to shadows, you can add cool glows and blurs to selected parts of the scene, or pull out all the stops and manipulate the whole scene, as the toon filter does.
The depth-of-field blur effect simulates how objects go in and out of focus when the human eye focuses near and far. The following screenshots focus first on the statue in the foreground, then on the houses in the background, and then on the façade of the building:
This filter needs update loop code to adjust properties depending on where the player is looking. To determine the player's line of sight, we use the familiar ray-casting algorithm.
The following example shows how you activate this cool blur effect:
Make a copy of
Main.java
and name the classDepthOfFieldBlur.java
. Remember to also refactor the first line of themain()
method toDepthOfFieldBlur app = new DepthOfFieldBlur()
.Add three class fields: one for the scene, one for
FilterPostProcessor
, and one for the depth-of-field blur filter...