Illumination simulation codes for the Moon's surface have been thoroughly developed during the last years. Despite works done for the Moon, no studies have investigated the relation between sunlight illumination and the Martian surface applying those codes done for the Moon to Mars. The objective of this work is to describe the development of a surface illumination simulation code, called MarsLux, which allows users to make a detailed investigation of the illumination conditions on Mars, based on its topography and the relative position of the Sun. Our code can derive accurate illumination maps, form topographic data, showing areas that are fully illuminated, areas in total shadow, and areas with partial shade, in short computational times. Although the code does not take into account any atmospheric effect, the results proved to be of high accuracy. The maps generated are useful for geomorphological studies, to study gullies, thermal weathering, or mass wasting processes as well as for producing energy budget maps for future exploration missions.