When exposed to the sun, your body produces vitamin D, which may affect your mood.