The optical morphologies of galaxies in the IllustrisTNG simulation: a comparison to Pan-STARRS observations