The effect of the surface roughness of optical elements, such as Be windows and reflection mirrors, in synchrotron radiation beamlines on the spatial coherence of the X-ray beam is investigated systematically by means of digital simulation, in which a new model for X-ray reflection from a rough surface is proposed. A universal factor is employed to evaluate the spatial coherence quantitatively, based on which critical values for surface roughness are reached. The results from simulation are consistent with those from experiments.