I found a youtube video (https://www.youtube.com/watch?v=msX1ypCjkK4) that should give you an idea of what I'm describing actually looks like. Specifically it introduces the concept of a multi-leaf collimator which serves as the main collimating device in modern radiotherapy. The other degree of freedom is the angle of the gantry you see rotating around the patient.
Typically for every gantry angle, the treatment planning software would split up an open field (no collimation) into a bunch of 1x1 cm^2 "beamlets" and would simulate what kind of dose distribution you would get inside the patient from each beamlet (you turn the patient CT into a big 3D grid of voxels to simulate dose in).
You then throw all those dose distributions into an optimiser, and you do what's called a fluence map optimisation which gives you the amount of radiation you want to deliver out of each beamlet. This is the optimisation step I described earlier where the cost function is basically a square difference between the dose in each organ from a given set of beamlet weights and what you want the dose to actually be. Healthy tissue is the limiting factor so you give as much as you can to the tumour while making sure that less than X% of the volume of a nearby organ gets more than Y units of radiation. There's a final step at the end that turns the fluence maps into actual deliverable apertures shaped by the multi leaf collimator.
There's a huge amount of work that goes into the simulation aspect. You can't just model the radiation beam as pure light sources that attenuate in the body via some exponential decay because the high energy photons scatter off electrons which themselves scatter around while depositing energy (radiation dose) away from the point of interaction. The gold standard is Monte Carlo simulations (which is my area of research) since you can model the actual physics of particle transport but in practice most clinics will use a faster engine to generate dose distributions. The faster engines typically superpose a primary component (a pure exponential decay) convolved with a kernel representing the energy that gets deposited away from the point of interaction.
That's probably way more information than you wanted ;)
But when you stop and think about what collimation actually is, it's just a manner of focusing a projected beam, either with masking, and obstructing the path of a beam (as with x-rays which are high energey photon beams), or also possibly by bending and focusing a beam, using magnets to direct a beam of charged particles (such as positrons).
So, if working in three dimensions, you might wish to control depth of penetration, but honestly, with X-rays you'll only have so much success, so it's really about how many beams converge upon a region, and the shape they create as they cross over each other, while intersecting, when projected from different angles.
There are a number of ways to approach this strategy, of creating three dimensional shapes, by drawing cross-sections in modern 3D animation programs, like Maya and 3D Studio Max.
The easiest way is to draw a spline or a bezier curve, along one axis, then apply a "lathing" function, which duplicates the spline, rotating about the axis, and then connecting the splines at each control point on the spline/curve. Then you get a crude vase-like shape.
So, take that idea, and apply it to a light source with an articulated aperture. The aperture can create a shadow in the shape of a spline. It might strobe exposures, with small, discrete doses, effectively pixelating or rasterizing the dose with many small exposures, or continuously emit radiation while in motion.
Then, if you attach this beam source to a motorized system, that can rotate the source about an axis on a system of rails, and trigger exposures with different aperture shapes while being positioned around a target at the center of the axis of rotation, hey presto! The software-defined shape has guided the beam, using the same sort of motion control that translates coordinates to a set of motors, as has been done with stop-motion animation cameras in movies for decades!
So, it's like the reverse of a camera, and yes, radiation sources are like flash-bulbs, and you selectively cast shadows, by controlling a gate or shutter, and possibly the shape of the opening in a barrier that stands between the source of the target. (scanline, round dot, square...)
EDIT: As loarake mentions, the actual behavior of a radiation beam is not the same as light. When radiation penetrates a medium, each type of radiation may scatter, reflect, refract differently when interacting with the medium, depending on the material, if it's bone, flesh, metal dental fillings or implanted appliances or something else. Many materials may absorb the radiation and express the interaction by radiating heat, or the radiation will ionize the matter, triggering electrical interactions, and chemical decomposition and reactions. This aspect of radiation is truly the pure random factor (hence monte carlo simulations), the unknowable Schroedinger's cat in a box, but it's real and for every dosage, some radiation will ionize some matter eventually. This along with the conversion to heat is the part that kills tumors, causes burns, and exposes film.
There's a word for programming languages like this, I forget what it is, though.
Declarative. As opposed to telling it how to get what you want, which would be imperative.
Treatment planning software then simulates dose distributions from a bunch of possible radiation beam collimations and adjusts the amount of radiation coming out of each radiation "field" to minimize a cost function penalizing overdosing healthy tissue and underdosing the tumour(s).