A method for simulating latent image formation in a photoresist illuminated by an arbitrary imaging system is presented. A variational formulation for light scattering, which does not depend on a specific configuration of the imaging system, is derived and solved using the finite-element method. The perfectly matched layer absorbing boundary condition is applied to take wave propagation in the infinite region surrounding the photoresist into account. The validity of the method is examined by comparing the results with those made by the vertical propagation model and the previous two-dimensional models.