Influence of out-of-plane response of optical properties of two-dimensional materials: first principles approach