Skip to content

KleaSCM/tika

Repository files navigation

Tika: Real-Time General Relativistic Raytracer

Black Hole

Tika is a high-performance, GPU-accelerated raytracer that simulates the visual and physical properties of a Kerr (Rotating) Black Hole. Unlike traditional Euclidean renderers that assume light travels in straight lines, Tika solves the Geodesic Equations of Motion for every pixel in real-time, integrating photon trajectories through the warped spacetime described by Einstein's Field Equations.

It is not a pre-rendered video. It is an interactive, physically accurate simulation running on your GPU.


Simulation Features

Relativistic Physics

  • Kerr Metric Geodesics: Supports partial spin ($a < M$) and extremal ($a = M$) black holes.
  • Frame Dragging (Lense-Thirring Effect): Visualizes the "wrapping" of spacetime near the event horizon caused by the hole's rotation.
  • Gravitational Lensing: Simulates extreme light bending, including the formation of Einstein Rings and Photon Spheres.
  • Event Horizon Shadow: accurate rendering of the black hole shadow, which is larger than the event horizon due to photon capture orbits.

Accretion Disk Model

  • Relativistic Doppler Beaming: The "approaching" side of the disk appears brighter and bluer (blueshift), while the "receding" side appears dimmer and redder (redshift).
  • Gravitational Redshift: Light climbing out of the gravity well loses energy, shifting visible light into the infrared (visualized as dimming/reddening).
  • Volumetric Density: Pseudo-volumetric noise-based density for a "cloud-like" accretion disk appearance.
  • Blackbody Radiation: Temperature gradient simulation where inner rings are hotter (blue/white) and outer rings are cooler (red/orange).

Engine Capabilities

  • Hamiltonian Integration: Uses a symplectic Hamiltonian formulation instead of the standard Lagrangian approach to avoid computing computationally expensive Christoffel symbols.
  • RK4 Integrator: 4th-Order Runge-Kutta numerical integration for high-precision trajectories.
  • Adaptive Step Sizing: Dynamically adjusts integration step size based on spacetime curvature ($R$) to maintain performance without sacrificing accuracy near the horizon.
  • GLSL Compute: Entire physics pipeline runs in a massive parallel Fragment Shader.

Gallery

Gravitational Lensing Accretion Disk Physics
Light from background stars is bent around the hole, creating double images and Einstein rings. Notice the left side is brighter (approaching) and the right side is dimmer (receding) due to Doppler beaming.
The Ergosphere Extreme Redshift
The region where spacetime spins faster than the speed of light, forcing co-rotation. Photons barely escaping the photon sphere, redshifted into invisibility.

Note

Visual Artifacts: The vertical "rope" artifact at the poles is a Coordinate Singularity ($\theta \to 0$). It could be fixed by switching coordinate charts or applying a tighter clamp, but I haven't gotten around to it yet. Consider it a testament to the raw math (and my laziness).


Theoretical Foundation

1. The Kerr Metric

Tika operates in Boyer-Lindquist coordinates $(t, r, \theta, \phi)$. The metric tensor $g_{\mu\nu}$ defines the geometry of spacetime:

$$ ds^2 = -\left(1 - \frac{2Mr}{\Sigma}\right)dt^2 - \frac{4Mar \sin^2\theta}{\Sigma} dt d\phi + \frac{\Sigma}{\Delta} dr^2 + \Sigma d\theta^2 + \left(r^2 + a^2 + \frac{2Ma^2r \sin^2\theta}{\Sigma}\right) \sin^2\theta d\phi^2 $$

Where the auxiliary functions are: $$ \Sigma = r^2 + a^2 \cos^2\theta $$ $$ \Delta = r^2 - 2Mr + a^2 $$

2. Hamiltonian Dynamics

Solving the geodesic equation $\nabla_u u = 0$ directly requires calculating connection coefficients ($\Gamma^\lambda_{\mu\nu}$), which is $O(N^3)$ and expensive. Tika instead uses the Super-Hamiltonian formalism:

$$ H(x^\mu, p_\mu) = \frac{1}{2} g^{\mu\nu}(x) p_\mu p_\nu = 0 $$

The equations of motion are derived from Hamilton's canonical equations:

$$ \frac{dx^\mu}{d\lambda} = \frac{\partial H}{\partial p_\mu} = g^{\mu\nu} p_\nu $$ $$ \frac{dp_\mu}{d\lambda} = -\frac{\partial H}{\partial x^\mu} = -\frac{1}{2} \frac{\partial g^{\alpha\beta}}{\partial x^\mu} p_\alpha p_\beta $$

This reduces the problem to calculating partial derivatives of the inverse metric $\partial g^{\mu\nu} / \partial x^\alpha$, which we derived analytically and implemented directly in the shader.

3. Flux Transport & Liouville's Theorem

To determine the color of a pixel, we trace the ray backwards from the camera to the accretion disk. The intensity $I_{\nu}$ along the ray is transformed by the Redshift Factor $g$:

$$ g = \frac{\nu_{obs}}{\nu_{emit}} = \frac{k_\mu u^\mu_{obs}}{k_\nu u^\nu_{emit}} $$

By Liouville's Theorem, the invariant intensity is $I_{\nu}/\nu^3$. Thus, the observed bolometric magnitude is:

$$ I_{obs} = g^4 I_{emit} $$

We approximate the emitted spectra as a Blackbody function $B_\nu(T)$, allowing us to simulate realistic color shifts.


Controls & Interaction

Key / Input Action Description
W, A, S, D Boost Accelerate the camera relative to the local frame (Lorentz Boost).
Mouse Look Rotate the camera's local sky frame.
Scroll Up Increase Spin Increase the black hole's angular momentum parameter ($a \to M$).
Scroll Down Decrease Spin Decrease spin towards Schwarzschild limit ($a \to 0$).
R Reset Return to initial position and metric state.
SPACE Pause Freeze integration time (useful for screenshots).

Project Structure

Tika/
├── assets/
│   ├── shaders/     
│   │   ├── schwarzschild.frag  # The heavy lifter: RK4 Integrator & Metric Solver
│   │   └── quad.vert           # Full-screen quad pass
│   └── textures/               # Noise maps for accretion disk
├── src/
│   ├── Core/                   # Windowing & Input (GLFW)
│   ├── Renderer/               # OpenGL State Management
│   └── Math/                   # 4-Vector & Matrix helpers
├── build/                      # Build artifacts
└── CMakeLists.txt              # Build configuration

Installation

Prerequisites

  • Operating System: Linux (recommended) or Windows
  • GPU: OpenGL 4.6 compliant (NVIDIA GTX 10-series or newer recommended for >60 FPS)
  • Tools: CMake 3.20+, GCC/Clang (C++23 support)

Build Instructions

# 1. Clone the repository
git clone https://github.com/KleaSCM/tika.git
cd tika

# 2. Configure project
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release

# 3. Compile
make -j$(nproc)

# 4. Run
./Tika

Roadmap

  • Volumetric Clouds: Implement full volumetric raymarching for a nebula surrounding the hole.
  • Kerr-Newman Metric: Add electric charge ($Q$) to the simulation.
  • Wormholes: Implement the Ellis drainhole metric for visualising traverseable wormholes.
  • VR Support: OpenXR integration for immersive event horizon experience.

References

  1. Gravitation - Misner, Thorne, Wheeler (1973). The "Bible" of GR.
  2. High-speed rendering of Kerr black holes - T. Müller (2014).
  3. Image of a spherical black hole with thin accretion disk - J.P. Luminet (1979).

License

MIT License. See LICENSE for details.

Author: KleaSCM (KleaSCM@gmail.com)

About

A real-time Kerr metric black hole raytracer written in C++23 and GLSL, implementing Hamiltonian geodesic integration via RK4 for photon trajectories in curved spacetime. Features relativistic flux transport using Liouville's theorem, accretion disk rendering with blackbody radiation, gravitational redshift, frame dragging and ergosphere effects.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors