-
Source video: 第一次在美國直播(講解Gaussian Splatting的cuda code)- AI葵
-
Selected comments:
-
“3D Gaussian Mixture Model.” GMM?!
-
“EWA Splatting paper (2001) contains all the necessary derivations and math.” - Matias Turkulainen (gsplat contributor).
-
forward.cu
Trade-off:
-
The 2D-projections of 3D ellipsoids are circles rather than ellipses to reduce shading tiles.
-
Determine visibility of tiles instead of pixels (shaded by circle shadows) for fast rasterization.
Main steps:
-
Determine the radii of circles shadows (
preprocessCUDA)-
Project a 3D ellipsoid will yield a 2x2 covariance matrix
-
Solve the 2 Eigenvalues for the covariance matrix, and the bigger one is the length of the major axis.
-
Use the major axis as the radius of the circle.
-
-
Determine pixels covered by the projected circles.
If the distance betwen a pixel to the circle center is smaller than the circle radius, the pixel is visible to the circle (a disc corresponding to a 3D Gaussian in the ray space).
- GetRect
-
Sort 3D Gaussians (discs) by depths
-
Each tile is shaded by multiple ellipsoids, i.e., visible to multiple Gaussians.
-
Pair each pixel with each contributing ellipsoid, and form a 64-bit identifier for each pair.
i.e., stitching the index (32-bit) of a pixel and the depth (32-bit) of a ellipsoid.
-
Sort all the identifier, and obtain a sequence
For example:
- tile-0 has 2 pairs: 0-a, 0-c
- tile-1 has 3 pairs: 1-a, 1-b, 1-c
Suppose the depths of 3 Gaussians are b > a > c, the sequence of pairs is as follows:
1 2 3 4 50-c 0-a 1-c 1-a 1-b -
-
Alpha compositing for each pixel’s color (
renderCUDA)Implementation tricks:
- A tile is a Block, in which each pixel is a worker.
- Every pixel in a tile uses the same Gaussian distributions,
so those data are stored in
__share__memory. Docs
-
Calculate alpha, which is proportional to the probability in a Gaussian distribution.
-
The probability is calculated according to the expression of 2D Gaussian.
-
Blend alpha * color (SH) of each ellipsoid front-to-back.
backward.cu
| output | input |
|---|---|
| pixels’ color (p,3) | Gaussians’ color (g,3) |
| Gaussians’ alpha | |
| Gaussians’ position (g,3) | |
| Gaussians’ rotation (g,4) | |
| Gaussians’ length of axis (g,3) |
- p is number of pixels; g is number of 3D Gaussians
Loss = color + SSIM
- A full image is produced at once, so image metrics, like SSIM, can be added.
Write parital derivative for each input tensor.