Depth of field

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.

Getting ready

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.

How to do it...

  1. Let's start with the easiest method, where the background is blurred out. You should check that your UberPostProcessEffect in the assigned PostProcessChain asset has Use World Properties ticked on.

    Tip

    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.

  2. We're just going to effect the current level. Open the View | World Properties menu and expand World Info. DOF settings are under the Default Post Process Settings category.
  3. Turn on the unchecked tick box in the channel for Enable DOF (the one to the right-hand side, not the one on the left that is ticked by default). For now make sure the DOF Focus Type is set to FOCUS_Distance.
  4. Set all the values for DOF to 0.0, from DOF Blur Bloom Kernel Size down to DOF Interpolation Duration. This removes all chance of seeing DOF from the world settings. The first value to ramp up is the DOF Blur Kernel Size (which affects the radius of the DOF/Bokeh effect, and how blurry the scene gets). Set a value of 10.0.
  5. If you want to blur the entire image (which is useful if your scene is just the backdrop for some kind of game menu overlay) set the Min value to 1.0.
  6. Having done so, put it back to 0.0 as apart from total blurry vision, there's not much use in raising it. Instead, set the MaxFar value to 1.0. You will see that, again, the entire image is blurred. This is because the start distance for the blur is 0.0 units from the camera, and everything past that distance gets blurred. So, we also need to set a distance for the focal point (or a target distance), and a radius of effect, or a focal range.
  7. Set the DOF Focus Distance to 512, and the DOF Focus Inner Radius to 256. The camera will focus 512 units ahead of itself, and all around it for 256 units outwards will be in focus, with a Falloff set by the DOF Falloff Exponent, which you can set from 0.5 to 1.0.
    How to do it...
  8. In the previous screenshot we see a background blur and foreground focus. In the examples coming up next, we can add middle distance blur just by shifting the settings, as in A, and reverse the focus, as in B, and also have a focus only in the middle distance, as in C. Example D shows that foreground blur, when it is ramped up high, cause an edge detection artifact where the surface is blurred but the edge is not.
    How to do it...

The next image shows the DOF properties for A, B, C, D:

How to do it...

There's more...

Animating DOF with a Modify Property switching series

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.193.3