I need to trace the shadows of an object, like getting a red line around the shadow(shadow itself is not red). I know how to trace an object itself but not the shadows on that object. Is there a way I can do this?
You can pick out the edges of the shadows by using the compositor as follows :
The key is to enable the Shadow pass in the Render Layers (right-hand-side of the screenshot). In addition, enable the Object Index pass to give some control over which objects in the scene will have shadow edges highlighted - otherwise all objects will show highlights on all shadows, even where they are shadowing their own faces (presumably not desired).
This works by taking the Shadow pass (which just shows the shadows) and passes this through a Dilate/Erode filter to slightly shrink back the shadows, followed by a Subtract node to get the difference between the original shadows and the ‘shrunk’ shadows - this will pick out the edges. The ID Mask filters out only those objects with Object Index of '1' (which in this case is just the 'floor') and this is combined with the shadow edges using a Multiply maths node so as to only highlight shadows on the ‘floor’. The result is used to mix between the original render and a solid colour (red) which highlights the edges.
EDIT : To show all shadows (including 'self' shadows where an objects blocks its own light) you can use a simpler setup, not requiring the object ID :
Note that the 'background' also counts as a 'shadow' - hence the line on the outer edge of the floor plane.