Depth of field
The glow effect we used is pretty cool, but we can make things even cooler. Of course every one knows what depth of field is. Maybe not by the term depth of field, but everyone must have seen it. If you make a picture with a lot of depth in it, you’ll probably see that the objects closer to the camera are blurred, as well as the objects far away. The objects at middle range are looking normal though. We’re going to make a similar effect. We can’t calculate how blurred every pixel would have to be, since that requires a lot of calculation power, so we’ll try to fake it. We’re faking it with the build in depth of field shader of TV. This shader has a couple of fixed amounts of blur. You can adjust the number of layers, but it always has a fixed amount of blur for each layer.

What do we need?
We need the same as last tutorial, again we need a TVRenderSurface and the TVGraphicsEffects class. We’ll change the name of the render surface of course, but that’s not too important right now.
How do we set things up?
- The instantiation of the classes is exactly the same again.
- The initialisation of the depth of field effect is different though. You can initialize the effect by calling:
The first parameter specifies the number of layers with fixed amounts of blurs.
How do we render this?
- We can render this the same way as the glow effect, but we need to make a couple small changes. First of all FX.UpdateGlow() should be substituted by
And of course instead of FX.DrawGlow() you need to call
Things you can add/change yourself
- Try adding a couple meshes at different distances from the camera, that should give you an even better view of what the depth of field shader does.