Samarium
2D physics simulation and rendering library in modern C++, with GPU acceleration
Install / Use
/learn @jjbel/SamariumREADME
See installation instructions below
<!-- TODO make a script to merge these into 2x2 grid, loop them -->$10^4$ particles interacting gravitationally in realtime, using a hashgrid:
$10^5$ particles moving in a velocity field of perlin noise:
Softbody, interact with a mouse:
An ideal gas's velocity distribution approaching the Maxwell-Boltzmann Distribution:
Graphics:
Animating levels of the Hilbert Curve:
Animating levels of the Fourier transform of a shape:
Samarium
<!-- [](https://github.com/jjbel/samarium/actions/workflows/gcc.yml) [](https://github.com/jjbel/samarium/actions/workflows/clang.yml) [](https://github.com/jjbel/samarium/actions/workflows/msvc.yml) [](https://sonarcloud.io/summary/new_code?id=jjbel_samarium) --> <!-- [](https://github.com/jjbel/samarium/blob/main/LICENSE.md) --> <!--  [](https://github.com/jjbel/samarium/tags) -->Samarium is a 2d physics simulation and rendering library written in C++20, with a focus on high performance using GPU acceleration (CUDA and compute shaders), and by using the CPU and memory better (multithreading, data-oriented-design).
I am actively working on adding 3D support and more simulation domains: chemical reactions, phase change, cloth etc.
<!-- Rendering is done directly with OpenGL. --> <!-- Offload more work to the GPU --> <!-- SIMD for increasing, CPU performance --> <!-- ## Contents --> <!-- TODO use vscode markdown auto TOC --> <!-- - [Examples](#examples) --> <!-- - [Quickstart](#quickstart) --> <!-- - [Prerequistes](#prerequistes) - [Installation](#installation) - [Example](#example) - [Tools](#tools) - [Documentation](#documentation) - [License](#license) -->Quickstart
git clone --depth 1 https://github.com/jjbel/samarium.git
python samarium/bootstrap.py
<!-- TODO make sure bootstrap works -->
<!-- TODO make it easy to run examples, easier than copy pasting the code into a source file? -->
Installation
<!-- | Dependency | URL | Documentation | | ---------- | ----------------------------------- | --------------------------- | | python | <https://www.python.org/downloads/> | | | git | <https://git-scm.com/downloads/> | <https://git-scm.com/docs/> | --> <!-- | cmake | <https://cmake.org/download/> | <https://cmake.org/cmake/help/latest/> | --> <!-- | conan | <https://conan.io/downloads.html/> | <https://docs.conan.io/en/latest/> | -->A compiler supporting C++20 is required, namely Visual C++ 2019 on Windows, or GCC-11/Clang-13 on Linux.
To install, do the following, or just run python samarium/boostrap.py
git clone https://github.com/jjbel/samarium.git
- build the library for your machine:
conan create ./samarium/ -b missing
<!-- ## Installation
To install the library locally:
```
conan download samarium/1.1.0@
```
or for the latest version
```sh
git clone --depth 1 https://github.com/jjbel/samarium.git
conan create ./samarium/ -b missing
``` -->
<!-- ## Example -->
For a fully-featured and self-contained example, run:
<!-- is depth 1 rly faster? -->git clone --depth 1 https://github.com/jjbel/samarium_example.git .
cmake --preset default
cmake --build --preset default
Now try the examples/ directory!
Documentation
View the docs at Github Pages: https://jjbel.github.io/samarium/
License
Samarium is distributed under the MIT License.
Libraries Used
Many thanks to the following wonderful libraries:
- GLFW, glad and glm for OpenGL support
- fmtlib to completely replace
iostream - range-v3
- BS::thread_pool
- PCG RNG for simple and fast randomness
- tl::function_ref and tl::expected
- znone/call_thunk for using with GLFW's C callback
- itlib-static-vector
- unordered-dense for faster
unordered_map - stb for image reading and writing
- FreeType for text rendering
Related Skills
node-connect
349.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.7kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
