We propose a simple method to correct a large amount of spherical aberration caused by a refractive index mismatch. The method is based on inverse ray tracing and can generate correction phase patterns whose peak-to-valley values are minimized. We also demonstrated spherical aberration correction in a transparent acrylic block using a liquid-crystal-on-silicon spatial light modulator (LCOS-SLM). A distorted focal volume without correction was substantially improved with correction. This method is useful in cases where a large phase modulation is needed, such as when employing a high-NA lens or focusing a beam deep inside a sample.