Code optimizations for when there is relfection and refraction