There does seem to be a correlation between increasing levels of economic prosperity and decreasing levels of religious attendance. One of the things that religion can provide is a psychological solace in the face of great loss or danger, but modern technology and civilization is every day more capable of keeping humans safe and relatively happy.
However, just because religion is on the decline does not mean that it is on the way out. Three-quarters of the world's population considers religion important. Furthermore, those that are giving up organized religion are not all becoming atheists. Many are also changing to more free-form spirituality, making their metaphysical beliefs a personal and inquisitive journey, rather than just accepting a particular set doctrine.