MODA: A new algorithm to compute optical depths in multidimensional hydrodynamic simulations