pub fn main<R: JitRuntime, F: FloatElement, I: IntElement, B: BoolElement>(
arguments: Arguments,
inputs: Inputs<R>,
) -> Outputs<R>
Expand description
Transforming the points.
For each one of the $ p $ points, do the following steps:
-
Transform the 3D position $ P $ from world space to view space: $$ P_v = R_v P + T_v \in \mathbb{R}^3 $$
-
Perform viewing-frustum culling: $$ \text{Exit if } P_v.z \notin \text{frustum.} $$
-
Convert the rotation from quaternion $ R $ to matrix $ R_s $: $$ R = [x\ y\ z\ w] $$ $$ R_s = 2 \cdot \begin{bmatrix} - y^2 - z^2 + \frac{1}{2} & x y - w z & x z + w y \\ x y + w z & - x^2 - z^2 + \frac{1}{2} & y z - w x \\ x z - w y & y z + w x & - x^2 - y^2 + \frac{1}{2} \end{bmatrix} $$
-
Compute the 3D covariance matrix from the rotation and scaling $ S $ using inverse single value decomposition (SVD): $$ S_s = \begin{bmatrix} S.x & 0 & 0 \\ 0 & S.y & 0 \\ 0 & 0 & S.z \end{bmatrix} $$ $$ \Sigma = R_s S_s^2 R_s^T = (R_s S_s) (R_s S_s)^T \in \mathbb{R}^{3 \times 3} $$
-
Project the 3D position $ P $ from view space onto screen space using focal length $ \text{fl} $ and image size $ \text{im} $: $$ P_v^’ = \begin{bmatrix} \frac{P_v.x}{P_v.z} \cdot \text{fl}_x \\ \frac{P_v.y}{P_v.z} \cdot \text{fl}_y \end{bmatrix} + \begin{bmatrix} \frac{\text{im}_x - 1}{2} \\ \frac{\text{im}_y - 1}{2} \end{bmatrix} $$
-
Project the 3D covariance matrix from world space onto screen space: $$ J = d P_v^’ / d P_v = \begin{bmatrix} \frac{\text{fl}_x}{P_v.z} & 0 & - \frac{P_v.x}{P_v.z^2} \cdot \text{fl}_x \\ 0 & \frac{\text{fl}_y}{P_v.z} & - \frac{P_v.y}{P_v.z^2} \cdot \text{fl}_y \end{bmatrix} $$ $$ C = \begin{bmatrix} c_f & 0 \\ 0 & c_f \end{bmatrix} $$ $$ \Sigma^’ = J R_v \Sigma (J R_v)^T + C \in \mathbb{R}^{2 \times 2} $$
-
Estimate the maximum radius $ r $ from the 2D covariance using eigenvalue decomposition: $$ |\Sigma^’ - \lambda I| = 0 $$ $$ \lambda = \frac{\Sigma_{11}^’ + \Sigma_{22}^‘}{2} \pm \sqrt{(\frac{\Sigma_{11}^’ + \Sigma_{22}^‘}{2})^2 - |\Sigma^’|} $$ $$ 0.9973 = \int_{-k}^{k} \exp(-\frac{x^2}{2}) dx $$ $$ r = k \sqrt{\lambda_{\max}} $$
-
Compute the tile bounds and touched tile count $ T $ using tile size $ t $: $$ [x_{\max}\ x_{\min}] = \text{clamp}(\frac{[(P_v^‘.x - r)\ (P_v^’.x + r)]}{t_x}) $$ $$ [y_{\max}\ y_{\min}] = \text{clamp}(\frac{[(P_v^‘.y - r)\ (P_v^’.y + r)]}{t_y}) $$ $$ T = (x_{\max} - x_{\min}) \cdot (y_{\max} - y_{\min}) $$
-
Compute the viewing direction in world space using view position $ V_p $: $$ D_v = \frac{P - V_p}{| P - V_p |} \in \mathbb{R}^3 $$
-
Transform the color from SH to RGB space: $$ D = f(D_v) \in \mathbb{R}^m $$ $$ C_{rgb} = D \cdot C_{sh} \in \mathbb{R}^3 $$