Gaussian Splats (native)¶
The acron.gsplat module is the native half of Gaussian-splat
rendering: everything that touches every splat on the CPU. A scan is millions
of splats; reading one, packing it into GPU planes, decoding it for tools and
sorting it every time the view changes are array work with no business in an
interpreter – and Android, web and C++-only programs have no numpy to lean on
anyway. The renderer itself (the work-buffer pass that decodes the planes on
the GPU, the instanced draw, the modifier hook that lets a program deform the
splats) lives in the Python tier, acron.splats, over public engine API; this
module is what it calls, and what a C++ program uses directly.
The bundle¶
GSplatBundleA scan in the SOG v2 layout (“Spatially Ordered Gaussians”, PlayCanvas
splat-transform’s format), whatever it was read from. Every attribute is an RGBA8 plane with splatiat texel(i % width, i / width): 16-bit log-space positions (means_l/means_u), smallest-three quaternions (quats), codebook indices for the log scales (scales) and the DC colour plus opacity (sh0), and optionally the higher-band spherical-harmonic palette (shN_labels/shN_centroids).read_sog()reads a.sog(a ZIP, throughZipArchive, or a directory of the same files);read_ply()reads a 3DGS training.ply(binary of either endianness, or ASCII) or a compressed one (PlayCanvas’s: achunkelement of bounds, four packed integers per splat and optionally anshelement of bytes; recognised by itspacked_positionproperty) andread_splat()a.splatfile (the web viewers’ flat format: 32 bytes per splat, no header, no higher bands), each packed into the same planes;read()picks by extension (anything that is not a.plyor a.splatis read as a.sog).with_shkeeps the higher spherical-harmonic bands and is on by default in every reader, as in the viewers of these formats: colour is then view-dependent as the scan was trained. Passfalseto load without them (a.sogsaves its label plane and a palette of at most 4 MB; a large.plysaves 15 texels per splat).from_arrays()packs flat float arrays (positions, quaternions, linear scales, colours, SH coefficients);write_sog()andwrite_ply()are the inverse, for tools and tests.get_plane()hands a plane out as aPTA_uchar(RGBA, row 0 first),make_plane_texture()andmake_codebook_texture()as nearest-filtered textures already in the engine’s BGRA RAM order – uploaded undecoded; the GPU decodes.get_count,get_sh_bands,get_bounds_min/get_bounds_max(the splats’ centres;get_means_min/maxare the log-space range the positions are quantised over) andget_meta_json(the bundle’smeta.json) describe it.decode_positions/decode_quaternions/decode_scales/decode_log_scales/decode_colors/decode_share the CPU mirror of the shader’s decode (PTA_float, one row per splat);select/decimate/headrepack a subset. Aquatstexel whose mode byte names no component (under 252) decodes as no rotation, here and in the shader.release_planes()drops the planes once their textures are made, for a program that keeps the bundle only for its count, bounds and codebook: the decode methods then return zeros and the bundle can no longer be written, selected from or turned into textures.eval_sh()evaluates the real SH basis (bands 1-3) for per-splat view directions – the CPU twin of the shader’sevalSH.
Failures return a null bundle (or
false) and leave a message inget_last_error().The readers treat a file as untrusted, and refuse rather than repair:
meta.jsonis at most 8 MiB and 100 000 JSON values, nested at most 64 deep; the means range and every codebook entry must be finite (entry 0 may benull, as older tools wrote it), the range not inverted and within ±88 (it is of log-transformed positions;from_arraysand the.ply/.splatreaders refuse positions past that range too, so what is packed can be written and read back); a plane file is at most the raw size of the largest image the WebP decoder takes. Of a plane taller than the splat count needs, only the rows in use are decoded – straight into the plane’s own array – soget_height, the plane textures and the memory a load takes follow the count, not the size a file declares (rows below those are not read, so damage there goes unnoticed); the SH palette is bounded the same way, at the 65 536 entries a label can name. Members of a zipped.sogare read withZipArchive’s bounded read: a member over its limit, with a damaged header, with a stream that is not the length its directory records, or failing its CRC-32 is a reader error like any other (a null bundle and a message), never an engine assertion. A.plywith more than 2^24 splats is read without its higher SH bands (with a warning): a direct palette holds no more.write_sog()writes theshNsection only for a bundle that holds its palette (one read withoutwith_shis written as a bundle without higher bands).
WebP¶
Every SOG plane is a lossless webp, and neither the engine’s image readers nor
its thirdparty libraries include libwebp. The module therefore carries
its own codec (gsplatWebP.cxx, after RFC 9649): the decoder reads the whole
lossless (VP8L) format – all four transforms, meta prefix codes, the colour
cache and LZ77 references – and is checked against libwebp’s output; the
encoder writes a simple valid lossless stream (no transforms, per-channel
Huffman codes). Lossy webp is refused: a lossy plane would corrupt the
quantised attributes. decode_webp() and
encode_webp() expose it for any PNMImage, and
encode_webp_rgba() for raw RGBA bytes.
The sorter¶
GSplatSorterOwns three arrays sized to the splat count.
depthsholds one view-space depth per splat andvisibleone byte per splat (1 = draw); the caller fills both – from Python, where the three arrays are writable, fixed-sizememoryviewobjects (they cannot be resized, so nothing can reallocate them under a sort running on another thread), or from a GPU depth plane withload_depths()(or a copy of its RAM image withload_depth_image()). A depth plane is a float texture with one texel per splat: R32F, holding the view depth of a splat worth drawing and 0 (or less) for the others – what the Python tier’s work buffer writes, 4 bytes a splat on the way back to the CPU – or RGBA32F, with the depth in red and a draw flag in green.sort()then fillsorderwith the indices of the visible splats, farthest first, as float32 (the format an R32F order texture takes), and returns how many (a splat whose depth is NaN or infinite is left out, like an invisible one);write_order()copies them into such a texture’s RAM image in one step (it returns false for a texture that is not single-channel float), andmake_order_texture()makes one holding the identity order. The sort quantises the depth range to2^bitsbuckets (bits= clamp(log2(n / 4), 10, 20) unless set) and counting-sorts on the key, stable, so ties keep index order: O(n), andBLOCKING, so a worker thread can run it while the frame loop draws. The buckets span the bulk of the depths – the central 80% of a sample, widened by twice its width on each side – not their extremes: depths beyond that share the first and the last bucket, which are then ordered exactly, so a stray splat at 1e30 costs the rest of the scene no precision. Fewer than 64 splats are simply sorted.depth_along()gives the plain undeformed depth of a centre array along a direction. A sorter is not synchronised: fill, sort and read it from one thread at a time (the PythonSplatSorterdoes this under its own lock).
#include "gsplatBundle.h"
#include "gsplatSorter.h"
PT(GSplatBundle) bundle = GSplatBundle::read("scan.ply");
if (bundle == nullptr) {
nout << GSplatBundle::get_last_error() << "\n";
return;
}
PT(Texture) means_l = bundle->make_plane_texture("means_l");
// ... means_u, quats, scales, sh0, and make_codebook_texture()
PT(GSplatSorter) sorter = new GSplatSorter(bundle->get_count());
PT(Texture) order = GSplatSorter::make_order_texture("order", 2048, 2048);
sorter->load_depths(depth_plane); // the work pass's depth plane
int n = sorter->sort(false); // farthest first
sorter->write_order(order);
A C++ program gets the decode and draw shaders from the Python package’s
splats/shaders (see Gaussian Splats for what each pass
does) or writes its own against the plane layout above.