They are made mostly from lycra/spandex, and their primary function is to reduce friction with the saddle while you pedal. There is usually some form of padding built in as well. Seams and stitching are located away from friction points.
The fabric and seams of regular shorts and underwear will rub you raw in some very sensitive areas if you ride more than a few miles at a time.