Coherence dynamics in microcavities and polariton lasers