There are three depth of field looks you'll want to learn to achieve. The first is when the background is out of focus and the foreground is sharp, which is fairly easy, and the second, which is somewhat more difficult, is the opposite, where the background is sharp while the foreground is blurred. The third case is where both foreground and background are blurry but a telephoto style patch of the middle distance is sharp.
UDK gives us two ways to create Depth of Field, and these handle two of the above goals well. A Position based blur , being locked to a world location, is good for the third case, middle ground focus, but isn't dynamic. A Distance based blur method defocuses the background far better than it handles the foreground.
DOF can be applied in the scene based on a BSP volume created by the designer. If you use these, only the volume you are in yields a result to the screen draw, and if you are outside a volume you won't see its effects. On top of that, post-processing volumes compete with each other if they overlap, and only one DOF setting will win out, so having multiple DOF volumes layered on each to get near and far focus will not work. It is possible to successively expose volumes with different settings through Kismet, which is demonstrated at the end of the recipe. In the meanwhile, we'll go through the three basic settings needed to make Depth of Field work within a volume.
Open the scene Packt_08_DOF_START.UDK. The view is set to a locked Matinee camera and player movement is constrained. This is so we can compare DOF values from an exact position. When we're done, the Matinee and Cinematic Mode can be released.
If you aren't sure which PostProcessChain is set for UDK, this is defined in C:UDK~UDKGameConfigDefaultEngine.INI
, in the [Engine.Engine]
section. An example would be: DefaultPostProcessName=Packt.PostProcessChain
. This way you can set DOF in the PostProcessChain for all your maps. We covered this earlier in the recipe on Accessing the main PostProcessChain.
The next image shows the DOF properties for A, B, C, D:
Open the scene Packt_08_DOF_ENABLINGTEST.UDK, which provides a quick example of how to animate a rack focus (animating a change in the target plane of the DOF focus) using PostProcessVolumes. It is easy to do, but a little repetitive. There are 10 volumes placed over the Matinee controlled Camera Actor in the scene, and in each one their DOF Focus Inner Radius steps down by 100 respectively. These are controlled in Kismet using the Modify Property action to enable and disable them in series through a loop back through a Switch action, such that, over a few seconds there's a transition from background to foreground focus.
3.147.193.3