Take a look at the example scene here. https://forums.cgsociety.org/showthread.php?t=87094 But usually it is done in composite.