Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# CMake build directory
build/

# CMake generated files
CMakeCache.txt
CMakeFiles/
cmake_install.cmake
Makefile
*.cmake

# Executables
*.out
*.exe
black_hole_3d
black_hole_2d
cpu_geodesic

# Object files
*.o
*.obj
*.o.d

# IDE-specific files
.vscode/

# Temporary files
*~
*.swp
70 changes: 70 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Set the minimum required version of CMake and define the project
cmake_minimum_required(VERSION 3.10)
project(BlackHoleSim)

# Set the C++ standard to C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Set the OpenGL policy to prefer modern GLVND
cmake_policy(SET CMP0072 NEW)

# Find required packages
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(glfw3 3.3 REQUIRED)
find_package(glm REQUIRED)

# --- Define the main 3D simulation executable ---
add_executable(black_hole_3d src/black_hole.cpp)

# Link libraries to the 3D simulation
target_link_libraries(black_hole_3d PRIVATE
GLEW::GLEW
glfw
OpenGL::GL
glm::glm
)

# --- Define the 2D lensing executable ---
add_executable(black_hole_2d src/2D_lensing.cpp)
target_link_libraries(black_hole_2d PRIVATE
GLEW::GLEW
glfw
OpenGL::GL
glm::glm
)

# --- Define the CPU geodesic executable ---
add_executable(cpu_geodesic src/CPU-geodesic.cpp)
target_link_libraries(cpu_geodesic PRIVATE
GLEW::GLEW
glfw
OpenGL::GL
glm::glm
)

# --- Copy shader files to the build directory ---
# This ensures the executable can find them at runtime.
add_custom_command(
TARGET black_hole_3d POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/geodesic.comp
${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/grid.vert
${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/grid.frag
# The destination must be the LAST argument
$<TARGET_FILE_DIR:black_hole_3d>
)

# --- Installation ---
# This section is optional but good practice.
install(TARGETS black_hole_3d black_hole_2d cpu_geodesic
RUNTIME DESTINATION bin)

set(SHADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/geodesic.comp
${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/grid.vert
${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/grid.frag
)
install(FILES ${SHADER_FILES}
DESTINATION bin)
Binary file removed Gravity_Sim.zip
Binary file not shown.
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,86 @@
# Black Hole Simulation

This project is a C++ and OpenGL-based simulation of a black hole. It visually demonstrates gravitational lensing, spacetime curvature, and accretion disks. The simulation is accelerated using GPU compute shaders for real-time performance.

## Features

* **3D Black Hole Simulation**: A real-time 3D simulation of a black hole with a compute shader for calculating geodesics.
* **2D Gravitational Lensing**: A 2D demonstration of how a black hole bends light.
* **CPU-based Geodesic Calculation**: A CPU implementation for calculating null geodesics.
* **Spacetime Grid Visualization**: Visualizes the curvature of spacetime around the black hole.

## Getting Started

### Prerequisites

Here's the requirements btw:
* A C++17 compatible compiler (like GCC or Clang)
* CMake (version 3.10 or higher)
* OpenGL
* The following libraries:
* GLEW (The OpenGL Extension Wrangler Library)
* GLFW (A multi-platform library for OpenGL, OpenGL ES and Vulkan)
* GLM (OpenGL Mathematics)

On many Linux distributions, you can install these with your package manager. For example, on Ubuntu (debian based distross):
```bash
sudo apt-get update
sudo apt-get install build-essential cmake libglew-dev libglfw3-dev libglm-dev
```

### Building the Project

1. Clone the repository:
```bash
git clone <repository-url>
cd black_hole
```
2. Create a build directory and navigate into it:
```bash
mkdir build
cd build
```
3. Run CMake to configure the project:
```bash
cmake ..
```
4. Compile the project using Make:
```bash
make
```
This will create three executables in the `build` directory: `black_hole_3d`, `black_hole_2d`, and `cpu_geodesic`.

## Usage

After building the project, you can run the simulations from the `build` directory.

* **3D Simulation**: `./black_hole_3d`
* **2D Lensing Demo**: `./black_hole_2d`
* **CPU Geodesic Demo**: `./cpu_geodesic`
(the Geodesic and 2D lensing does not work somehow)

### 3D Simulation Controls

* **Orbit**: Click and drag the left mouse button to orbit the camera around the black hole.
* **Pan**: Click and drag the right mouse button to pan the camera.
* **Zoom**: Use the mouse scroll wheel to zoom in and out.
* **Toggle Gravity info**: Press the `G` key to print velocity data about gravity.

## How it Works

The simulation uses different techniques to visualize the black hole.

* **2D Lensing (`black_hole_2d`)**: This is a simplified 2D simulation that shows how light rays are bent by the black hole's gravity. It uses a 4th-order Runge-Kutta (RK4) integrator to solve the geodesic equations.

* **3D Simulation (`black_hole_3d`)**: This is the main simulation. It uses a compute shader (`geodesic.comp`) to trace a large number of light rays in parallel on the GPU. This allows for real-time rendering of gravitational lensing effects in 3D. The camera and object data are passed to the GPU using Uniform Buffer Objects (UBOs).

* **CPU Geodesic (`cpu_geodesic`)**: This provides a CPU-based implementation for calculating the paths of light rays (null geodesics) in 3D space around the black hole. It serves as a reference and educational tool for understanding the underlying physics calculations.

---
*Original README*

---

# black_hole
Black hole simulation project
Here is the black hole raw code, everything will be inside a src bin incase you want to copy the files
Expand Down
Binary file removed black_hole.exe
Binary file not shown.
Loading