An N-body gravitational simulation that uses smooth particle hydrodynamics(SPH) to compute gravitational interaction forces in a particle system containing 2000 to 65,536 particles. SPH is a technique commonly used to simulate fluids by using many, many particles in close proximity to each other in order to compute the density and interaction forces between the particles in the system.

- 3D Spatial Hash Data Structure
- FPS Camera to move around world
- Particle Billboarding
- Phong lighting
- SPH Solver using Leapfrog Integration Scheme (Eulerian Symplectic Integrator)
- Simulated in water-like fluid (Similar to properties of interstellar medium)
- 3D Mesh version rendering in real time with Phong shading.
- Particle Billboarding version to display computation speed. Billboards are textures used for alphamapping.
- Instancing (not demoed because it slowed performance too much)

- Due to large number of particles, it is hard to tell that particles are moving inward -- this is due to the interaction radius of these particles and the pipeline culling out many billboards that are overlapping.
- Spatial hash using 8000 cubes to be used for local force calculations.

- Due to the smaller number of particles, the resolution of the spatial has is reduced to 1000 cubes so that particles will not be isolated.

- Notice that this system tears itself apart quickly, this is partially due to the increased number of interactions and also partially caused by imbalanced forces between gravity and viscous drag.

- Learn C++ because by the end of the project I really wanted easier Object Orientation than C can offer. This noticeably slowed down my ability to navigate my code and make small changes to tune the system parameters, etc.

- Use git!! Being able to have multiple branches holding different optimization ideas saved me lots of time. It also allowed me make changes without fear of losing my working implementation because I mangled my code beyond recovery.

- Due to the SPH algorithms have O(n^2), I wanted to try using OpenCL to accelerate my computations by moving this computations onto . I spent 2 days trying to get my OpenCL to cooperate with my hardware but I had to give up this effort for my sanity. This was really unfortunate because OpenCL was the ticket to my target number of 1Million particles :( But I learned a great deal about parrallel computing and will be trying to get OpenCL to cooperate with me in my free time.

- I also tried to implement a KD tree (similar to octree) for my spatial data structure. I was unable to get the open source KD-tree libraries to build with my existing codebase. Even though I was not able to implement the tree in time, exploring spatial data structures and their range of utility is my biggest lesson from this project.

- At one point I implemented Transform Feeback in order to export computations from my CPU into the geometry shader on the GPU, but I did not manage to implement a solution that made any noticeble difference. This solution is also eclipsed by the far superior alternative, OpenCL or CUDA.

- Implement Barnes-Hut Algorithm
- Utilize OpenCL framework to speed up calculations
- Implement KD tree and compare with Spatial Hash

- Smooth Particle Hydrodynamics Detailed discussion of SPH Simulation and Leapfrog Integration
- Billboarding and Instancing Billboarding tutorial before I had access to Lab10
- Original Inspiration
- Transform Feedback
- More references that I did not end up using in the final implementation available upon request - cgels@calpoly.edu