You can paint on a terrain in real time, but it takes time to develop such a script, since it is not the easiest thing to do. there are people who have made shadow mappers for terrain, which works in a similar way.
here is a link to a terrain shadow mapper I made some time ago, it could help you out