A high-performance physics simulation and ray tracing engine for Morris-Thorne wormholes. This project visualizes the spacetime geometry and light-ray trajectories (geodesics) in the vicinity of a traversable wormhole.
The simulations are based on the Morris-Thorne metric, which describes a traversable wormhole. The spacetime metric in Schwarzschild-like coordinates
For a simple wormhole with a constant throat radius
Geodesics describe the paths of light rays. By extremizing the Lagrangian:
$\frac{d^2l}{d\tau^2} = r(l) (\dot{\theta}^2 + \sin^2\theta \dot{\phi}^2)$ $\frac{d^2\phi}{d\tau^2} = -\frac{2}{r} \frac{dr}{dl} \dot{l} \dot{\phi}$
In the code, these are reduced to a system of first-order ODEs and integrated using the 4th-order Runge-Kutta (RK4) method for high stability and precision near the high-curvature throat region.
-
wormhole_2d.py: A top-down 2D visualization of light rays being deflected or transmitted through the wormhole. It uses PyGame for rendering and RK4 for physics integration. -
wormhole_cinema_final.py: The flagship 3D cinematic visualizer. It implements a GPU-accelerated ray tracer using OpenGL shaders to render the wormhole in real-time. -
Explantion_scripts/:-
wormhole_embedding.py: Visualizes the "flamm's paraboloid" style embedding diagram in 3D. -
wormhole_physics.py: Demonstrates the exotic matter and tension requirements ($10^{34}$ Pa) to keep the throat open. -
shaders.py: A pedagogical tool comparing CPU vs GPU parallel processing performance.
-
The engine uses Relativistic Ray Tracing. Unlike standard Euclidean ray tracers:
- Every pixel on the screen spawns a ray.
- The initial state is defined by the camera's position and orientation in the curved spacetime.
- The ray position is integrated step-by-step using the geodesic equations.
- If the ray reaches
$l < 0$ , it is sampling the "Other" universe (Universe B). - Background stars and nebulae are generated using Fractal Brownian Motion (FBM) noise directly in the fragment shader.
We utilize ModernGL to interface with OpenGL 3.3+. The heavy lifting is done in the FRAGMENT_SHADER, where each thread calculates a single geodesic integration for its corresponding pixel. This allows for real-time interaction at 60 FPS, which would be impossible on a sequential CPU-based integrator.
- Python 3.8+
- OpenGL 3.3 compatible hardware
- Clone the repository.
- Install dependencies using the provided
requirements.txt:
pip install -r requirements.txtpython wormhole_cinema_final.py- W/S: Move Forward/Backward
- A/D: Orbit Left/Right
- Mouse: Look around
- Scroll: Zoom In/Out (FOV)
- C: Start Cinematic Fly-through
- R: Reset Camera
- Z: Toggle Volumetric Glow
- H: Toggle HUD
python wormhole_2d.py- Mouse: Move the light source.
-
Scroll: Adjust the throat radius
$(b)$ in real-time.