How rendering works
A Gaussian Splatting image is millions of soft, translucent blobs, painted from nearest to farthest. That idea is simple. Doing it in a millisecond is what shapes all of the code.

This guide follows one image through MojoSplat's renderer, based on Faster-GS. It is written for someone who knows the usual 3DGS CUDA rasterizer, but you can follow it without that. The animations play on a small example scene and run the real steps on it; press Pause or drag the slider to go at your own pace.
1. Project
A Gaussian is described in 3D by a mean, a rotation, three scales and an opacity.
To draw it, we need its 2D shape on the image. The mean projects like any point.
For the covariance, we use the camera's Jacobian at the mean: the local linear
approximation of the projection, J Σ Jᵀ.
In the code, QuatScale turns the raw parameters into a 3D covariance, and
PinholeEWA does the projection.
2. Keep only what is visible
One GPU thread handles each Gaussian. Most Gaussians aren't visible in a given view, so this stage's most important job is to throw them away early and pack the rest together.
Three things happen for each survivor:
- Its 2D covariance is inverted to a conic, so a pixel's distance is cheap to compute.
- It gets a screen rectangle that holds exactly the pixels where alpha can reach 1/255, and the tiles under that ellipse are counted with an exact test, not just the rectangle.
- It takes a slot. The k-th visible Gaussian writes slot k of every output.
Each slot is one 32-byte record holding position, conic, opacity and the rectangle, which is a single memory access for the later stages.


In that view, 1.59 million of 4.2 million Gaussians are visible, and together they produce 3.7 million tile entries across 5,740 tiles.
3. Put everything in order
To blend, each tile needs a list of the Gaussians touching it, nearest first. A Gaussian that touches several tiles appears in several lists.
The usual approach makes one entry per Gaussian-tile pair and sorts them all by a wide (tile, depth) key. Here, the same result comes from two cheap sorts.
The trick is in the last step. A stable sort keeps the existing order of entries with equal keys, and the entries were already in depth order. So sorting by tile alone leaves each tile nearest first, with no depth in the key. With about 5,700 tiles, the key fits in 16 bits, which is two radix passes.
4. Blend, one tile at a time
Now the image is painted. A usual rasterizer loops over each pixel's Gaussians. Here, a tile (16×12 pixels on NVIDIA, one block of 192 threads) is divided into six sub-tiles of 8×4 pixels, and each one belongs to one warp of 32 threads, one thread per pixel.
A warp walks the tile's list on its own, 32 Gaussians at a time. Its lanes fetch one record each and vote on which ones overlap its sub-tile. The overlapping ones go into a small shared-memory slab, and every lane composites them at its own pixel. This has two benefits: a Gaussian that misses a sub-tile costs that warp nothing per pixel, and a warp stops as soon as its pixels are opaque, without waiting for the others.
Compositing a fragment is one multiply and one exp2:
alpha = opacity * exp2(min(power, 0))
As in 3DGS, fragments with alpha below 1/255 are skipped, and a pixel stops after the fragment that brings its transmittance below 1e-4.
5. What training saves
A plain render ends here. Training needs gradients, and for that the backward needs the state of each pixel partway through the tile. So a training forward also saves:
- each pixel's accumulated color and transmittance before every group of 32 Gaussians, called a snapshot,
- each pixel's final transmittance, and the last Gaussian that affected it.
The snapshots let the backward start at any group of 32 without replaying the
tile. All of this is described by ForwardState, which holds only sizes and
pointers.
6. Blend backward
This is the stage least like a per-pixel backward. One warp takes one group of 32 consecutive Gaussians (a bucket), and each lane owns one Gaussian. The tile's pixels stream through the lanes.
Each lane keeps its Gaussian's gradient in registers across all pixels, then does one set of atomic additions at the end. That's the point of the design: atomics are expensive, and here there are 32 sets per bucket instead of one per pixel per Gaussian.
For one pixel, with T the transmittance before this Gaussian, c its color,
after the color contributed by Gaussians behind it, and g the loss gradient at
that pixel:
dL/dalpha = sum over channels of g * (T * c - after / (1 - alpha))
- T_final * dot(g, background) / (1 - alpha)
The gradients of position, conic and opacity all follow from that value.
7. Back to the parameters
The last stage turns each slot's gradients into gradients of the raw parameters, one thread per Gaussian. It writes in Gaussian order, so memory writes are contiguous, and it recomputes the forward from the parameters instead of storing it. Culled Gaussians simply get zero gradients.
The blocks in the code work exactly like this figure: a block's constructor runs
its forward and stores what its backward needs, then backward walks it in
reverse.
var shape = QuatScale[dt](log_scales, rotations) # forward, top to bottom
var place = P(mean, shape, cam)
var resp = R(place.mean2d(), place.cov2d(), GaussianGeometry.of(mean, shape), cam)
var grad = resp.backward(slot_gradients, place, shape, cam) # backward, bottom to top
# Gaussian2D.backward: its own pullback to screen gradients, then
# place.backward(shape, screen.mean2d, screen.cov2d)
Fields the backward doesn't use are removed by the compiler, so this costs what the same expressions would cost written out flat.
For training, the higher-order SH gradients aren't even written. Adam recomputes them per element, which avoids writing and reading the largest gradient buffer.
Where each stage lives
| Stage | File |
|---|---|
| Stage order, scratch buffers | mojosplat/render/rasterizer.mojo |
| Preprocess | mojosplat/render/preprocess.mojo |
| Sorting and tile lists | mojosplat/render/instances.mojo, mojosplat/gpu/sort.mojo |
| Blend | mojosplat/render/blend.mojo |
| Backward | mojosplat/render/blend_backward.mojo, preprocess_backward.mojo |
| 3D shape math | mojosplat/render/blocks/shape.mojo |
| Projection and Jacobian | mojosplat/render/blocks/placement/pinhole_ewa.mojo |
| Footprint: coverage, pixel alpha, gradients | mojosplat/render/blocks/response/gaussian2d.mojo |
| Spherical harmonics | mojosplat/render/blocks/appearance/sh.mojo |
rasterizer.mojo is mostly plumbing: buffers and pointer arguments. To read the
algorithm, start at _raster there, then read the kernels in the order of this
guide.
Reading Mojo if you know CUDA
| CUDA | Mojo |
|---|---|
__global__ void kernel(...) | a plain def kernel(...) |
kernel<<<grid, block>>>(args) | stream.enqueue_function(ctx.compile_function[kernel](), args, grid_dim=, block_dim=) |
blockIdx.x, threadIdx.x | block_idx.x, thread_idx.x |
ptr[i] | ptr[unsafe_offset=i] |
__shared__ float s[N] | stack_allocation[N, Float32, address_space=AddressSpace.SHARED]() |
__ballot_sync(mask, pred) | warp.vote[...](pred) |
__shfl_sync(mask, v, lane) | warp.shuffle_idx(v, lane) |
__syncwarp() | syncwarp() |
atomicAdd(&p, v) | Atomic[...].fetch_add[...](p, v) |
template<...> | parameters in [...], and comptime if for compile-time branches |