The formation of the cardiac mesoderm begins with the process known as gastrulation. During gastrulation, cells from the epiblast migrate inward to form the three germ layers: ectoderm, mesoderm, and endoderm. The cardiac mesoderm originates from the mesodermal layer, specifically from an area called the heart field, which is divided into the primary and secondary heart fields.