Software•26 de noviembre, 2026

Relativistic Physics in the Browser: How a developer recreated a black hole using Three.js and GLSL

Tobias Teles transformed his portfolio into an interactive gravitational lensing simulation, calculating light trajectories in real-time with 140 iterations per pixel.

Relativistic Physics in the Browser: How a developer recreated a black hole using Three.js and GLSL

On November 14, 2026, developer Tobias Teles published a complete overhaul of his personal portfolio (accessible at https://tobiasteles.dev/). Instead of a traditional project gallery, the homepage was transformed into an interactive black hole simulation. Using the Three.js library and the GLSL shader language, the project renders gravitational lensing effects based on the Schwarzschild metric in real-time within the browser. The initiative illustrates a growing trend in the computer graphics community: the application of complex general relativity equations in highly accessible web environments.

Context and background

The physically accurate rendering of black holes gained popularity in pop culture following the movie Interstellar (2014), which utilized render clusters to calculate light trajectories. In the following years, the evolution of web graphics APIs, such as WebGL, allowed calculations once restricted to supercomputers or native game engines to be executed directly on the user's GPU via the browser.

Developers began exploring raymarching techniques—where light rays are traced step-by-step from the camera—to simulate the curvature of spacetime. Tobias Teles's project fits into this timeline as a proof of concept that it is possible to balance the mathematical rigor of relativistic physics with the performance required for a consumer-facing web application. During development, Teles focused on simplifying the mathematical implementation of gravitational lensing and orbital mechanics, resulting in lean code that runs directly in the fragment shader.

The mathematics of light: concrete simulation data

To create the black hole's visual effect, the project does not use conventional 3D models. Each pixel on the screen represents a light ray fired by the camera. The path of this ray is curved step-by-step by the black hole's gravity.

Teles adopted a unit system where the Schwarzschild radius (the event horizon) has a value equal to 1. The acceleration that curves the light ray is calculated by the exact formula -1.5 · h² · r̂ / r⁴, where h represents the ray's angular momentum. This mathematical approach positions the photon sphere—the region where light orbits the black hole in perfect circles—exactly at 1.5 radii.

The algorithm runs a loop of 140 calculation steps (iterations) for each pixel. If the squared distance (r2) is less than 1.0, the ray has crossed the event horizon and the pixel is colored black. The arc of visible light above and below the black hole is not explicitly drawn; it emerges naturally from the equations, as rays passing behind the accretion disk are bent by gravity and cross the disk's plane again toward the observer.

Orbital mechanics and relativistic effects

In addition to gravitational lensing, the portfolio features three main projects that orbit the black hole in elliptical trajectories. To calculate the exact position of these elements over time, Teles used Kepler's equation. Solving this transcendental equation is done through the Newton-Raphson method, implemented with six iterations in the JavaScript code to ensure the accuracy of the eccentric anomaly. Each orbit's period obeys Kepler's third law (T² ∝ a³), and the second law (equal areas in equal times) was numerically validated by the author.

The accretion disk around the black hole also simulates physical effects. The disk's rotation speed is proportional to r^(-3/2), spinning faster near the center. Teles implemented an approximation of the Doppler effect: the side of the disk rotating toward the observer becomes brighter (golden-white), while the side moving away acquires reddish hues.

Time dilation is also present. The site calculates and displays the difference in the passage of time based on the distance r from the observer, using the relation 1 / √(1 − 1/r). However, the author notes that in the "falling" animation, the camera stops before crossing the event horizon, making the numbers displayed on the dark screen a visual "enactment."

Implementation divergences in the community

Teles's approach to integrating light trajectories is direct, but it is not the only one in the WebGL community. An analysis of similar projects reveals significant divergences in the numerical methods chosen to solve the differential equations of the Schwarzschild metric:

  • Direct Integration vs. RK4: While Teles uses a simple adaptive integration step (dt = max(0.05, 0.1 * (sqrt(r2) - 0.9))), other developers, such as the author of the Real-time Schwarzschild + binary black-hole lensing project (Guruprasad), use the 4th-order Runge-Kutta method (RK4) with fixed steps to ensure greater numerical stability, especially in binary system simulations.
  • Verlet Method: Developer Wilker Silva Lima, in a project that took about two years, opted for Verlet integration with an adaptive step, focusing on precision near the photon sphere (1.5 r_s) and calculating the critical impact parameter (b ≈ 2.6 r_s).

These variations demonstrate that there is no single standard for relativity simulations in the browser. The choice of method directly affects the balance between physical precision and frame rate (FPS).

Impact on the sector and for developers

The publication of this portfolio directly affects the web developer and graphics engineer community, especially in the Latin American market, where resource optimization is crucial due to the wide variation in user hardware.

  • Democratizing Physics via Code: The project proves that complex general relativity equations are becoming accessible for modern web development. Physics and computer graphics students now have open-source references to visualize phenomena that once required expensive proprietary software.
  • The Art of the Technical Portfolio: For the IT recruitment market, complex experimental projects serve as irrefutable proof of technical competence. The ability to manipulate GLSL and advanced mathematics sets senior developers apart in global hiring processes.
  • WebGL vs. GPU Limits: The project exposes the ongoing challenge of balancing visual fidelity with usability. The simulation requires high parallel processing power from the GPU. On mobile devices, the computational load of 140 iterations per pixel at high resolutions can cause severe performance drops.

What is still unknown

Despite the technical documentation provided by Teles, some points regarding the implementation and its practical impact remain open:

  • Battery consumption on mobile devices: The exact impact of continuously running such a heavy fragment shader on smartphone battery life has not been quantified.
  • Visual fidelity on small screens: The author mentions that the site uses "fewer calculation steps on small screens" to maintain performance. The extent to which this optimization compromises the accuracy of gravitational lensing and photon ring rendering is not detailed.
  • Post-processing pipeline: Supplementary sources mention the use of bloom filters and ACES tone mapping to improve the aesthetics of the accretion disk. It is unclear if Teles's project implements these post-processing techniques or if the color is generated purely in the main shader pass.

What to expect next

The evolution of physical simulations in the browser is expected to accelerate with the mass adoption of the WebGPU API, which offers more direct and efficient access to graphics hardware compared to WebGL.

  • Transition to WebGPU: Developers are expected to migrate these shaders from GLSL to WGSL (WebGPU Shading Language), allowing the use of Compute Shaders to calculate light trajectories asynchronously, freeing up the main rendering thread.
  • Rotating black hole simulations: The next technical step for the community is the real-time implementation of the Kerr metric (rotating black holes), which requires significantly more complex and asymmetric differential equations.
  • Adoption in educational tools: Physics and astronomy education platforms are likely to begin integrating these real-time simulations into their curricula, replacing pre-rendered videos with interactive in-browser labs.

Frequently Asked Questions

1. What is the photon sphere mentioned in the project? It is a spherical region around the black hole, located at 1.5 times the Schwarzschild radius, where gravity is so strong that light is forced to travel in circular orbits.

2. Why does the project run slowly on my phone? The simulation calculates the trajectory of light for each pixel on the screen individually, executing up to 140 mathematical steps per pixel. This is demanding on the GPU, and mobile graphics processors generally have fewer cores and higher thermal constraints than those in computers.

3. Is the Doppler effect shown on the accretion disk physically perfect? No. The author used a simple approximation where the side of the disk approaching the observer becomes brighter. A full relativistic simulation would require more complex calculations of relativistic beaming and gravitational redshift.

Consejo LatinoTech

¿Quieres crear tu propio portal de IA o SaaS sin programar? Usa la plataforma que nosotros usamos.

Conocer Base44 (No-Code)

INFORMACIÓN META (SEO)

Three.jsGLSLWebGLblack holegravitational lensingraymarchingTobias Teles

COMPARTIR ARTÍCULO

Ver noticia original en TabNews →

Master Artificial Intelligence before your competition.

Join thousands of professionals. Get the 5 best AI news and tools of the week, straight to your inbox.

Zero spam. Unsubscribe at any time.

Usamos cookies 🍪

Utilizamos cookies para mejorar su experiencia, analizar el tráfico y mostrar anuncios relevantes. Al continuar, acepta nuestro uso de cookies.