|
Space Sim
|
The system for n-body updates and rendering. More...
Files | |
| file | src/particles/bounds.comp |
| Computes the bounds over all particles in the sim. | |
| file | src/particles/com22.comp |
| Propagates mass back up to the root while computing the center of mass and bounds for each node along the way. | |
| file | src/particles/main.comp |
| Traverses the LBVH per Particle and computes acceleration based on forces. | |
| file | src/particles/morton.comp |
| Computes mortons over each particle in the simulation for LBVH construction. | |
| file | src/particles/next.comp |
| Traverses the LBVH top-down and assigns stackless pointers on its way down. | |
| file | src/particles/pos.comp |
| Integrates positions after velocity is computed. | |
| file | src/particles/radix_global.comp |
| Step two of radix sort. | |
| file | src/particles/radix_new.comp |
| Step one of radix sort. | |
| file | src/particles/radix_scatter.comp |
| Step three of radix sort. | |
| file | src/particles/spawn.comp |
| Spawns new particles from accretion - unused. | |
| file | src/particles/tree.comp |
| Constructs an LBVH over the radix sorted mortons. | |
| file | src/particles/zero.comp |
| Zeros out the min and the max before computing the bounds over all particles. | |
| file | src/render/main.frag |
| Shades particles based on lighting and particle material makeup. | |
| file | src/render/main.vert |
| Projects particles as a circle quad. | |
Functions | |
| void | sim_step () |
| A single simulation step for the particle sim. | |
The system for n-body updates and rendering.
| void sim_step | ( | ) |
A single simulation step for the particle sim.
\begin{align} & \text{DEF: } \\ & \quad P = \text{Particles} \\ & \quad N = \text{Nodes} \\ & \quad N_{lr} = \text{Node Children} \\ & \quad N_{m} = \text{Node Mass} \\ & \quad N_{\text{com}} = \text{Node Center of Mass} \\ & \quad N_{\text{n}} = \text{Node Next} \\ M(D) &= \underset{x \in D}{\max} x_{\text{xyz}} \\ m(D) &= \underset{x \in D}{\min} x_{\text{xyz}} \\ \mathit{max} &= M(P) \\ \mathit{min} &= m(P) \\ \Delta &= \mathit{max} - \mathit{min} \\ \mathcal B &= \max(\max(\Delta_x, \Delta_y), \Delta_z) \\ f(p) &= \begin{cases} c = \frac{p_{xyz} - \mathit{min}}{\mathcal B}\\ \text{Morton}(c) \end{cases} \\ M &= \lbrack f(p) | p \in P \rbrack \\ M\prime &= M \to M_1, M_2, ... M_n \\ o(x, y) &= \begin{cases} n = 31 \\ \text{while } x[n] = y[n] \text{ and } n \ge 0: \\ \quad n = n - 1 \\ n \end{cases} \\ & \text{Where each index into x and y is a bit.} \\ r(x, y) &= \begin{cases} -1, &\text{if } y \lt 0 \text{ or } y \ge P_{\text{count}} - 1 \\ o(M\prime_x, M\prime_y), &\text{otherwise} \end{cases} \\ S(i) &= \begin{cases} l_p = \begin{cases} o(M\prime_i, M\prime_{i-1}), & \text{if }i \gt 0 \\ -1, & \text{otherwise} \end{cases} \\ r_p = \begin{cases} o(M\prime_i, M\prime_{i+1}), & \text{if }i \lt P_{\text{count}}-1 \\ -1, & \text{otherwise} \end{cases} \\ \vec d = \begin{cases} 1, & \text{if } r_p > l_p \\ -1, & \text{otherwise} \\ \end{cases} \\ \Delta_{\text{min}} = r(i, i - \vec{d}) \\ h = 2 \\ k = i + h \vec{d} \\ \text{while } k \ge 0 \text{ and } g \lt P_{\text{count}}: \\ \quad \text{break}, & \text{if } o(M\prime_i, M\prime_k) \le \Delta_{\text{min}} \\ \quad h = h * 2 \\ \quad k = i + h \vec{d} \\ l = 0 \\ t = \frac{h}{2} \\ k = i + (l + t) \vec{d} \\ \text{while } t \ge 1 \text{ and } k \ge 0 \text{ and } k \lt P_{\text{count}}: \\ \quad l = l + t, & \text{if } o(M\prime_i, M\prime_k) \gt \Delta_{\text{min}} \\ j = i + l \vec{d} \\ v = \min(i, j) \\ z = \max(i, j) \\ s_\perp = v \\ s = z - v \\ \delta = r(v, z) \\ \text{while } s \gt 1: \\ \quad s = \lfloor (s + 1) \ 2 \rfloor \\ \quad s_{\perp 1} = s_\perp + s \\ \quad \left. \begin{aligned} e = r(v, s_{\perp 1}) \\ s_\perp = s{\perp 1}a \end{aligned} \right\rbrace, & \text{if } e \gt \delta\\ n_i = P_{\text{count}} + i \\ \begin{cases} N[n_i]_l = v, & \text{if } s_\perp = v \\ N[n_i]_l = P_{\text{count}} + s, & \text{otherwise} \end{cases} \\ \begin{cases} N[n_i]_r = s_\perp + 1, & \text{if } s_\perp + 1 = z \\ N[n_i]_r = s_\perp + 1 + P_{\text{count}}, & \text{otherwise} \end{cases} \\ \end{cases} \\ & (S(i) | i \in [0, P_{\text{count}})) \\ Q(i) &= \begin{cases} Q(N[i]_l) \\ Q(N[i]_r) \\ l = N[N[i]_l] \\ r = N[N[i]_r] \\ N[i]_{\text{com}} = \frac{l_{\text{com}} l_m + r_{\text{com}} r_m}{l_m + r_m} \\ N[i]_{\text{min}} = \min(l_{\text{min}}, r_{\text{min}}) \\ N[i]_{\text{max}} = \min(l_{\text{max}}, r_{\text{max}}) \\ d = N[i]_{\text{max}} - N[i]_{\text{min}} \\ N[i]_r = \max(\max(d_x, d_y), d_z)^2 \\ \end{cases} \\ & Q(P_{\text{count}}) \\ & \text{Where } P_{\text{count}} \text{ is the root node.} \\ & \text{Each node stores the node to continue with if its branch is skipped.} \\ U(i) &= \begin{cases} a = 0 \\ n = 0 \\ \text{While }n \ge 0: \\ \quad \left. \begin{aligned} n = N[n]_n \\ \text{continue} \end{aligned} \right\}, \text{if } N[n]_m = 0 \\ r = (N[n]_{\text{com}} - P[i]_{\text{pos}}) \\ d = r^2 + \beta \\ \quad \begin{cases} \left. \begin{aligned} a = a + r \cdot (N[n]_m \cdot (\frac{1}{\sqrt{d}})^3) \\ n = N[n]_n \\ \text{continue} \end{aligned} \right\}, \text{if n is a leaf}\\ \begin{cases} \left. \begin{aligned} a = a + r \cdot (N[n]_m \cdot (\frac{1}{\sqrt{d}})^3) \\ n = N[n]_n \\ \text{continue} \end{aligned} \right\}, \text{if } \frac{N[n]_r}{d} \lt \theta^2 \\ n = N[n]_l, \text{otherwise} \end{cases} \\ \end{cases} \\ P[i]_{\text{vel}} = P[i]_{\text{vel}} + a \Delta t \\ P[i]_{\text{pos}} = P[i]_{\text{pos}} + P[i]_{\text{vel}} \Delta t \\ \end{cases} \\ & (U(i) | i \in [0, P_{\text{count}})) \end{align}
Definition at line 440 of file main.c.
References BODY_COUNT, BOUNDS_COMPUTE_SHADER, bounds_queries, COM_COMPUTE_SHADER, com_queries, current_query_frame, DT, MAIN_COMPUTE_SHADER, main_queries, MAX_DEPTH, MAX_NODES, MORTON_COMPUTE_SHADER, morton_queries, NEXT_COMPUTE_SHADER, NODE_SSBO, NUM_WORKGROUPS, POS_COMPUTE_SHADER, RADIX_COMPUTE_SHADER, RADIX_FINAL_COMPUTE_SHADER, RADIX_GLOBAL_COMPUTE_SHADER, radix_queries, sim_step(), TREE_COMPUTE_SHADER, TREE_COUNT_COMPUTE_SHADER, tree_queries, treecount_queries, and ZERO_COMPUTE_SHADER.
Referenced by main(), and sim_step().