Light enters a cut stone, bends, bounces off the facets inside and comes back out split into colours. Every pixel here is traced through the real facet planes.
Refraction. Light slows down in the stone, so it bends at each facet. Snell's law gives the angle. Diamond has a high index n, so it bends light more than glass does.
Total internal reflection. Inside the stone, a ray that meets a facet at more than the critical angle cannot leave. All of it reflects. For diamond the critical angle is 24.4°; for glass it is 41°. A good cut makes the pavilion facets steep enough that the light reflects twice and goes back up through the crown.
Reflection. At each facet, some light reflects and the rest passes through. The Fresnel equations give the split. Straight on, diamond reflects 17% and glass 4%. That is the hard lustre of diamond.
Dispersion (fire). The index is a little larger for blue light than for red. So each colour takes its own path, and a white spark leaves the stone as a spectrum. The Abbe number ν tells how small the spread is. This page traces up to twelve wavelengths per pixel.
Colour. A coloured stone absorbs some wavelengths along the path (Beer–Lambert). Long paths give deep colour, so the colour is strongest where the light bounces most.
The tracer. The stone is a convex set: the intersection of one half-space per facet. A ray enters at the latest entry plane and leaves at the earliest exit plane, so each bounce tests every facet once. The cost is pixels × wavelengths × bounces × facets.