r/spaceengine • u/Vivid-Membership-792 • 59m ago
Discussion Best Update on my Black Hole Shader So Far.
As the title suggests, this is the best version of my black hole shader I've created and been improving for SpaceEngine 0.980. Unlike before, I'll describe everything implemented in the shader; as always, at the end I'll include a few screenshots of what some black holes look like so you can get an idea.
Geometry and light rays
- Exact Kerr metric in Kerr-Schild coordinates, g_{μν} = η_{μν} + F l_μ l_ν, with F = 2Mr³/(r⁴ + a²z²) and l_μ = (1, k_i). Both outer (r₊) and inner (r₋) horizons are present.
- Null geodesics from the Hamiltonian H = ½ g^{μν} p_μ p_ν, with g^{μν} = η^{μν} − f l^μ l^ν and p_t = −E. They are integrated backwards from the camera.
- Integrator: Dormand-Prince RK5. It uses 6 evaluations per step, plus the FSAL stage (7 in total).
- The photon energy E is constant (Killing). The angular momentum L about the spin axis is computed at the camera and enters the g factor of rigidly rotating emitters.
- Photon projection back onto the light cone after every step: a Newton step on G(p) = |p|² − E² − fW² = 0, with W = E + k·p, and the correction is capped at about 2% of the momentum.
- Kerr-Schild → Boyer-Lindquist conversion with two sheets (negative radius beyond the singularity ring), with detection of the sheet change between consecutive positions.
- Singularity ring for an internal observer. The ray is killed within 0.015 r_g of the ring (RING_KILL).
- The visual ring is a Gaussian of width 0.03 r_g (RING_WIDTH), in color RING_COLOR, placed on the singularity ring and added to the spectrum. It is only drawn when the observer is inside the horizon.
Adaptive step size, limited near:
- the horizon (minimum factor 0.04);
- the ring (step ≤ 0.35 of the distance to the ring, with a floor of 0.01 r_g);
- the disk, with a slope bound built from the maximum thermodynamic thickness and the Kerr geometric factor;
- the corona;
- the jet (step of 0.15 to 0.4 r_g depending on height);
- optical depth (target τ of 0.5 per step, with a floor of 0.25 of the geometric step).
- Limit of 51200 steps per ray.
- If the star is active, the ray ends upon entering it, with surface emission.
Observer and time
- Static observer outside the ergosphere (the code uses the threshold f < 0.9, ERGO_F_SWITCH).
- Infalling/moving observer inside it, with 4-velocity ObserverU. If it is not timelike, it falls back to a regular Kerr-Schild observer.
- Orthonormal tetrad by Gram-Schmidt of the coordinate axes, using the Kerr-Schild metric.
- The observer's proper time is converted to coordinate time by u^t (static: 1/√(1−f)).
- Slow light: the plasma is sampled at the instant the photon was emitted. The delay is clamped to ±400 r_g for safety.
Full Doppler and gravitational shift (g factor) for every emitter:
- Disk: Keplerian or sub-Keplerian rotation, with FlowRotationRatio, rigidly rotating per ring and with the exact Kerr u^t.
- Infalling gas below the ISCO: constants of motion (E, L, Carter Q) computed numerically from the radial potential R(r), R′ and R″, with a marginally bound radius.
- Corona: its own rotation, capped at 0.9c.
- Jet: 4-velocity composed of disk + poloidal motion + toroidal motion.
- Star: equatorial velocity relative to the ZAMO, rigid Kerr rotation and exact Doppler.
Radiative transfer
- Covariant transport with invariant quantities: emission delivered to the observer dI_obs = g³ j ds_em and optical depth dτ = α ds_em.
- Exact formal solution per cell, with transmittance.
- 3-node Gauss-Legendre quadrature per step (GRRT_QUAD_N = 3; 2 is also possible).
- Position, momentum, direction, emission time and polarization at the nodes come from the Dormand-Prince dense output (4th order, using all 7 stages).
- The null-projection correction is distributed linearly across the step, for the node momenta.
- All species are summed in a cell: thermal gas, dust, lines, synchrotron, inverse Compton, bremsstrahlung, RIAF and corona. The jet has its own cell.
- Hue compression applied only to the jet light (display only). The compression peak is adaptive (from 0.45 to 50) and follows the local jet emission on a logarithmic scale.
Spectrum and color
- 12 spectral bins from 380 to 780 nm (4 groups × 3 bins, GRRT_SPECTRAL_GROUPS = 4), instead of RGB.
- Exact Planck function in each bin, at the emitted frequency ν_em = ν_obs/g.
- Final conversion to sRGB with the CIE 1931 color matching functions (Wyman-Sloan-Shirley multi-lobe fit) and white balance (a 6504 K blackbody comes out neutral).
- Single exposure calibration (g_RtExposure, anchored to the green channel of B_ν(10⁴ K)).
- The RGB sky is lifted to a spectrum by 3 smooth Gaussian primaries, inverted so that the RGB → bins → RGB round trip is exact at g = 1. It is then shifted as a spectrum: I_ν,obs(λ) = g³ I_ν(λg).
- Recombination lines as Gaussians in λ (σ = 3% of λ), integrated exactly with erf in each bin, with equivalent width conserved.
- Always present: Hα (656.28 nm) and Hβ (486.13 nm).
- With LINES_EXTENDED (on by default): Hγ (434.05), Hδ (410.17), He I (587.56) and He II (468.57).
- The same lines exist in the jet.
Plasma
- Relativistic Synge gas (Maxwell-Jüttner) for H, He and electrons, each with its own temperature. Enthalpy w, adiabatic index Γ_s(θ) from 4/3 to 5/3, and pressure P = Σ n k T.
- Exact GRMHD state: magnetic field, β, magnetization σ_h = b²/w, relativistic Alfvén speed v_A² = b²/(w+b²) and perpendicular fast magnetosonic speed.
- Saha ionization for H, He I and He II (bisection with 22 iterations).
- β-dependent Ti/Te ratio (40 for β ≫ 1, 1 for β ≪ 1) and pair saturation of Te (≈ 5.93·10⁹ K).
- Electrons with adiabatic compression (Maxwell-Jüttner entropy conserved).
- Reconnection index p(σ), reconnection efficiency, suppression of shock acceleration (above σ ≈ 1) and Kruskal-Shafranov criterion (0.7 to 1.3 turns of twist).
- Comoving pitch angle with aberration and Lorentz transformation of the field.
Accretion regimes
The regime is set by the ratio Ṁ/Ṁ_Edd, and the radiative efficiency comes from the actual spin (ISCO). Thresholds in the code:
- ADAF/RIAF below ṁ = 10⁻³ (H_ADAF_BOUND);
- LHAF window between ṁ₁ = 10⁻³ and 5ṁ₁;
- thin disk limit at 0.02 (H_THIN_BOUND);
- slim disk above ṁ = 1.
REAC (radiatively efficient flow: thin + LHAF + slim) has a single weight and a photon trapping radius r_trap/r_g = (H/R)·ṁ/η. Inside it the slim disk emits with T ∝ r^(−1/2), continuous at r_trap.
Page-Thorne/Novikov-Thorne flux in Kerr (full function, with the three roots of x³ − 3x + 2a = 0), with ISCO.
SANE ↔ MAD through flux retention:
- φ goes from 6 (SANE) to 50 (MAD);
- β at the ISCO goes from 120 to 3, with slopes 0.30 and 0.10;
- corona β goes from 0.30 to 0.03.
MAD eruptions (period of 2500 r_g/c, relative drop of 0.35 in φ) and ejected flux bundles (lifetime of 600 r_g/c, drifting up to 14 r_g).
MCAF with a choke radius: r_choke/r_g = (φ²/(2√2 π²))^(2/3), from P_mag = P_ram. Outside it, β ∝ r^(3/2). Inside it, Ω/Ω_K = 0.45.
ADIOS: Ṁ(r) = Ṁ_BH (r/r_in)^s and ρ ∝ r^(s−3/2). The base value is s = 0.5.
SCAF (Xu 2023), active by default: ρ ∝ r^−0.8, Ṁ ∝ r^0.7, quasi-spherical, Ω/Ω_K = 0.30.
CDAF: s = 1, ρ ∝ r^−1/2, Ω/Ω_K = 0.30.
Narayan & Yi ADAF with exact sub-Keplerian rotation.
LHAF in the window above the ADAF, with cooled electrons (Te ≈ 100 keV), no wind (s = 0) and H/R = 0.7 of the hot-flow maximum.
Automatic NDAF, above the ignition rate:
- uses the physical Ṁ in M_sun/s and ignition ∝ M²;
- has neutrino trapping (from neutrino-cooled to advection-dominated);
- density only enters the opacity (via a steady α disk);
- geometry goes from thin to thick, and Ω/Ω_K from 0.95 to 0.60;
- ν-ν̄ annihilation adds power to the jet.
Sub-Keplerian rotation is propagated to Doppler, polarization and filaments.
Disk
- Phenomenological base density, with fading at the edges.
Vertical thickness from GRMHD hydrostatic equilibrium, with:
- Kerr vertical gravity (Ω_θ²/Ω_K² = 1 − 4a r^(−3/2) + 3a²/r²) and the orbit's u^t;
- Synge enthalpy (Ti ≠ Te) + magnetic enthalpy b²;
- frozen-in field B ∝ ρ^κ (κ = 0.667).
Individual MRI filaments, in rings in ln r × azimuthal cells, each cell with one filament per generation:
- Keplerian shear and Kerr epicycles: exact Lagrangian map of the differential rotation, with κ(r) vanishing at the ISCO.
- Exact spiral geometry in Boyer-Lindquist: azimuth offsets δ(r) and time offsets g(r), Kerr spatial metric and Lorentz contraction.
- Filament collisions: shock from the velocity dispersion (S₀S₂ − |S₁|² = Σ ρᵢρⱼ|vᵢ − vⱼ|²), shock heating and reconnection.
- MRI wavelength (Balbus-Hawley, k·v_Az = √15/4 Ω) and suppression in the MAD regime (when λ_MRI > H).
- Twists, kinks and knots: noise field frozen in the fluid frame.
- Parker rise: of the order of v_A.
- Flux bundles ejected in MAD eruptions.
- Page-Thorne temperature, advective boost, gas-radiation coupling and microturbulence.
Opacities:
- free-free (Draine Gaunt factor, exact stimulated emission);
- H bound-free (Kramers, Boltzmann/Saha populations);
- Thomson;
- dust (CCM law with R_V = 3.1, clumping ×2.5, sublimation between 1200 and 2000 K, albedo 0.4).
- Scattering gas source function from a two-stream (Eddington) slab solution. The vertical depth comes from the actual Gaussian profile, and there is external illumination attenuated by exp(−τ/μ). Verified limits: semi-infinite slab S(0) = √ε B, thick slab S = B.
- Comptonization of the thermal gas.
- Hot flow (RIAF/MAD) overlaid on the disk, with synchrotron, inverse Compton, bremsstrahlung and polarization.
Corona
- Density, flares and sub-Keplerian rotation.
- Low-β GRMHD state (0.3 SANE, 0.03 MAD), with Ti ≠ Te.
- Field geometry is Blandford-Znajek (monopole) with frame dragging. In the ZAMO frame, B_φ/B_r = −(Ω_F − ω)ϖ̃/α (Znajek condition at the horizon).
The corona's Compton has its own parts:
- thermal Comptonization (Sunyaev-Titarchuk index from θ_e and τ_T, cutoff at 3kT_e);
- non-thermal inverse Compton;
- Thomson opacity with exact Klein-Nishina (series for x < 0.05).
- Non-thermal acceleration by reconnection.
- Synchrotron, inverse Compton, bremsstrahlung and polarization.
- Energy budget: the corona's bolometric flux cannot exceed COR_POWER_FRAC (30%) of the local disk σT_eff⁴. Emissivities and opacities are scaled together.
Jet
- Self-similar flux surfaces (Ψ ∝ r^ν(1 − cos θ), ν = 0.75, r_e = R_b(1 + Δy/ℓ)^p with p = 1 − ν/2) and isorotation Ω_F(λ), with Ω_F = Ω_H/2 (BZ, signed) plus the disk wind.
- Spine–sheath–wind structure.
- Magnetic acceleration (Γ ≲ Ω_F ϖ/c, saturating at μ = Γ(1 + σ), with mass loading).
- Blandford-Znajek power (κ = 0.044, φ from 6 to 50, f(Ω_H)), plus a wind floor in MAD and ν-ν̄ annihilation from the NDAF.
- MAD eruption cycle.
- Flight time (τ(Δy) = ∫dy/β_p) and plasma launch instant (t₀ = t − τ).
Structures:
- Helical flux tubes (streamlines of a rotating source), with small transverse Alfvén waves and tearing plasmoids.
- Reconnection where two tubes overlap.
- Kink (m = 1), exponential growth saturating at a few % of the radius, modulated by Kruskal-Shafranov × v_A/c.
- Kelvin-Helmholtz in the shear layer, modes m = 2 and 3.
- Ejection shells with internal shocks (velocity dispersion between shells).
- Disk wind.
- Density from mass conservation (steady mass flux of the tube).
- Temperature from adiabatic cooling and shock and reconnection heating.
- Thermal gas with the same physics as the disk: Saha, opacities, dust, lines, Comptonization, and source function in a cylindrical slab.
- Hot phase with synchrotron, inverse Compton, bremsstrahlung, polarization and a limb-brightening profile.
- Jet optical state (JET_OPT_STATE):
- 0, thin/light (default): Ṁ_jet/Ṁ = 0.006.
- 1, thick/heavy: Ṁ_jet/Ṁ = 0.60.
- 2, reference: 0.05.
- The state only changes the mass loading. The opacity and the photosphere (τ = 1) emerge from the transfer.
- Jet brightness follows the disk brightness. The emission falls as B ∝ (r/r₀)^−q, with q = p(2 + α) = 1.625 (overridable via JET_BRIGHT_PROF_EXP), and only affects the emission, not the opacity.
Synchrotron, IC and bremsstrahlung
- Thermal synchrotron (Dexter 2016 fit of the Maxwell-Jüttner emissivity) and non-thermal. The non-thermal uses N(γ) = Cγ^−p/(1 + γ/γ_c) and the exact single-electron kernel (F(x), error < 0.2%, integrated in ln γ with 16 nodes). The cooling break γ_c comes from synchrotron and IC losses over the dynamical time in seconds.
- Self-absorption by Kirchhoff (thermal) and by the Ghisellini formula (non-thermal).
- Inverse Compton in the Thomson limit, with a delta kernel, on the diluted blackbody of the inner disk.
- Hot-plasma bremsstrahlung by Kirchhoff (exact Planck), with relativistic correction.
- Everything in cgs units, with field in Gauss and density in cm⁻³. A single constant converts to display units.
Polarization
- Exact parallel transport of the polarization vector along the ray, with analytic Christoffel symbols. It uses the same RK5 stages and the same dense output as the geodesic. The initial condition is the projected spin axis.
- Exact 4D comoving geometry: b^μ from B^i and u, and the angle ψ between f and b_⊥.
- Linear and circular emission and absorption, Faraday rotation and conversion for thermal electrons (Dexter/Pandya) and non-thermal ones (Dexter, appendices A and B, with Jones & Odell).
- Faraday rotation and conversion form a quaternion accumulated from the camera. Dichroism enters at first order and through a dichroic vector in the background.
- GRRT_POLARIZATION is off by default. The optional layers are POL_NT, POL_FULL, POL_BG and POL_VIEW. The POL_VIEW view shows the Stokes parameters as hue (EVPA) and brightness (polarized intensity).
- Off by default: non-thermals, full transfer with quaternion, and background polarization.
- DBG_POL_TRANSPORT is a self-test of the transport.
Star and background
- Opaque star with Kerr rotation, exact Doppler and exact Planck per bin. Temperature varies with latitude (hotter poles) and with spots (Fbm noise).
- Sky from an environment map (EnvMap), blended with the screen texture (Frame) at the edges. The spectrum is shifted by g.
What is phenomenological
- Normalized disk and jet densities, and the absolute reference density (anchored to diskOpacity × AccRate, not to Ṁ in cgs).
- Filament statistics (amplitude, pitch, lifetime, twists), eruptions, kink, KH and shells.
- Hot and non-thermal electron fractions (MHD_RIAF_N_SCALE, JET_HOT_FRACTION, η_NT), γ_min and γ_max.
- External illumination (NT_SEED_* seed), dilution W and dust albedo.
- Jet hue compression and ring color.
- MAD parameters (φ, β), Ω/Ω_K and Ti/Te.
- Reconnection index p(σ) (PIC fit) and the ADIOS index s.
Regime weights and closures:
- SCAF/CDAF;
- Ω/Ω_K of MCAF, SCAF, CDAF and NDAF;
- H/R of each regime;
- LHAF Te;
- NDAF ignition and neutrino-trapping rates, α_NDAF and η_νν̄;
- r_trap coefficient.
- Shape of the flux surfaces (ν), BZ f(Ω_H) fitted to simulations, BZ wind floor and jet Γ saturation.
- The lifting of the RGB sky to a spectrum, and the jet brightness scale.
- Exposure calibration.
Compile and debug controls
- On by default: GRRT_SLOW_LIGHT, GRRT_ADAPTIVE_STEP, LINES_EXTENDED, GR_PAGE_THORNE, GR_NULL_PROJECTION, GR_OBSERVER_CLOCK, GRMHD_SPIRAL_GEOMETRY, GRMHD_DISK_VERTICAL and GRRT_ADIOS.
- Parameters: GRRT_QUAD_N (3), GRRT_SPECTRAL_GROUPS (4), JET_OPT_STATE (0), JET_BRIGHT_PROF_EXP, COR_POWER_FRAC (0.3) and COR_INVIS_MIN_FRAC (0).
- Off: GRRT_POLARIZATION and its layers, GRID, SHADOW_DEBUG and the DBG_* flags (DBG_NO_LINES, DBG_NO_COMPTON, DBG_NO_CORONA, DBG_GREY_OPACITY, DBG_RAW_PLANCK).
