Foam comes in various levels of firmness....firmer foam will hold its shape longer and is better for furniture that gets used every day, but will also make a firm bed. The batting that ScottG mentions is also important to help distribute weight over the foam's surface and also helps the fabric keep its shape.
You can get foam at an upholstery shop, or if you take out the existing pieces and measure them, you can order customer cut from websites like
this one.