A special feature of Mg solidification is the anisotropy of the hexagonal closed packed lattice, which under directional growth conditions causes a strong crystallographic texture. Although this primary growth texture is in technical processes masked by subsequent solid state processes, its understanding can be helpful for efficient microstructure optimization. The aim of the present work is to study the fundamental orientation selection mechanisms by numerical simulation. For this pur-pose, a phase-field model has been extended to allow for complex 3D anisotropic interfacial ener-gies and interfacial mobilities, calibrated by data from molecular dynamics studies. The model is first applied in 3D to Mg-6%Al, revealing two major stages of texture formation. Directly after nuc-leation, all grains with basal plane parallel to the gradient direction are selected. During further competitive growth, grains with <1120> closely aligned to the temperature gradient commonly pre-vail, but process dependent also other orientations of the basal plane (between <1120> and <1010>) may coexist. The latter phenomenon is investigated in detail in 2D for the ternary alloy AZ31.