How and why objects in a denser medium appear raised.
When light travels from a denser medium (water, glass) into a rarer one (air), it bends away from the normal. The refracted rays reaching the eye seem to come from a point higher than the object — the virtual image. The depth of this image below the surface is the apparent depth.
$$d_{\text{apparent}} = \dfrac{d_{\text{real}}}{\mu}$$Because μ > 1, the apparent depth is always smaller than the real depth — the image rises by an amount called the shift.
$$\text{Shift} = d_{\text{real}} - d_{\text{apparent}} = d_{\text{real}}\left(1 - \dfrac{1}{\mu}\right)$$Both formulas assume nearly vertical viewing (paraxial approximation).
Shift grows monotonically with μ. A denser medium bends light more strongly, so the virtual image appears higher above its real location. Glass (μ ≈ 1.52) therefore produces a larger shift than water (μ ≈ 1.33) for the same depth.
For a fixed μ, shift is a linear function of the real depth:
$$\text{Shift} \propto t$$Doubling the depth doubles the shift. This is why a deep pool looks muchshallower than a shallow puddle of the same liquid.
The refractive index itself depends on wavelength — a relation captured by Cauchy's equation $\mu(\lambda) = A + B/\lambda^2$. Violet light has the shortest wavelength and the highest μ, so it bends the most and produces the largest shift. Red light bends the least and shifts the least. This is why white light through a prism splits into colors.
When a pencil is dipped obliquely into water, the part above water and the part below appear misaligned. Each underwater point produces a virtual image raised toward the surface, so the submerged segment looks bent upward at the boundary.
Everything above is for viewing from a rarer medium (air) into a denser one (water/glass). When you look from inside water at an object in air, the situation reverses: the object appears farther away than its true position, because rays now bend toward the normal as they enter the denser medium.