Just remember that the material that a surface refers to will be the material that comes after the surface.
Now, we just need to gather all this information together.