Galaxy Universe 1
Galaxy Universe 1
Galaxy of Universes & Spiral Nebula
Note: Most of the code in this post was written by AI.
Human hands were involved, but most mathematical expressions and code were written by AI.
A pure WebGL/GLSL universe visualization combining recursive Spherical Inversion fractals with multi-octave stochastic fields
Mathematical structure of sample-line integration, Differential Spiral Phase, Value Noise, FBM, and linear light compositing
1. Overview
This project contains three real-time shaders. Each is built on a different generative principle.
Mode | Core Model | Visual Role |
|---|---|---|
Hybrid Universe | 8-iteration Kali Spherical Inversion + FBM spiral gas + Dust Attenuation | The default view, designed independently by Jungdongwoo, combining two density fields into a single linear light scene |
Galaxy of Universes | pseudo-3D sample-line integration + recursive Spherical Inversion + radius-dependent Differential Phase | Fine stellar orbital trails and a central fractal core |
Spiral Nebula | 2D Value Noise + 5-octave FBM + Polar Spiral Warp | Organic luminous gas and a pulsating core |
- Mode
Hybrid Universe
- Core Model
8-iteration Kali Spherical Inversion + FBM spiral gas + Dust Attenuation
- Visual Role
The default view, designed independently by Jungdongwoo, combining two density fields into a single linear light scene
- Mode
Galaxy of Universes
- Core Model
pseudo-3D sample-line integration + recursive Spherical Inversion + radius-dependent Differential Phase
- Visual Role
Fine stellar orbital trails and a central fractal core
- Mode
Spiral Nebula
- Core Model
2D Value Noise + 5-octave FBM + Polar Spiral Warp
- Visual Role
Organic luminous gas and a pulsating core
All three modes share the same Speed, Intensity, Field Zoom, Manual Rotation, and drag coordinate system. Each models a different phenomenon. Galaxy handles the orbital energy of an iterated function, Nebula the spatial correlation of a stochastic field, and Hybrid the combination of the two.
1.1 Authorship and Model Differences
Hybrid Universe is a custom shader designed and implemented directly by the author.
Dave Hoskins's Galaxy of Universes and the Kali-family spherical inversion belong to the algorithmic lineage of the fractal branch, while value noise and FBM are the mathematics the nebula branch is built from.
Adapting the two source visuals and merging them into one image inside a shared coordinate, time, and exposure system is itself Hybrid's original work.
Comparison | Galaxy of Universes | Spiral Nebula | Hybrid Universe |
|---|---|---|---|
Base Field | Orbital energy of recursive Spherical Inversion | Spiral-warped stochastic density field | Combined field of orbital energy and gas density |
Spatial Computation | pseudo-3D sample-line integration | 2D FBM field | sample-line branch and FBM branch share the same |
Compositing Method | Single fractal output | Single gas output | Nonlinear Linear Light Blending responding to fractal radiance |
Occlusion/Attenuation | Radial Window | Exponential radial attenuation | FBM-based dust mask selectively attenuates composited light |
Output Transform | power contrast + clamp | exponential exposure | exponential exposure applied once after compositing both branches |
Color Ownership | orbital accumulator | gas coordinates | Mutual modulation of two palettes and dust attenuation |
- Comparison
Base Field
- Galaxy of Universes
Orbital energy of recursive Spherical Inversion
- Spiral Nebula
Spiral-warped stochastic density field
- Hybrid Universe
Combined field of orbital energy and gas density
- Comparison
Spatial Computation
- Galaxy of Universes
pseudo-3D sample-line integration
- Spiral Nebula
2D FBM field
- Hybrid Universe
sample-line branch and FBM branch share the same
- Comparison
Compositing Method
- Galaxy of Universes
Single fractal output
- Spiral Nebula
Single gas output
- Hybrid Universe
Nonlinear Linear Light Blending responding to fractal radiance
- Comparison
Occlusion/Attenuation
- Galaxy of Universes
Radial Window
- Spiral Nebula
Exponential radial attenuation
- Hybrid Universe
FBM-based dust mask selectively attenuates composited light
- Comparison
Output Transform
- Galaxy of Universes
power contrast + clamp
- Spiral Nebula
exponential exposure
- Hybrid Universe
exponential exposure applied once after compositing both branches
- Comparison
Color Ownership
- Galaxy of Universes
orbital accumulator
- Spiral Nebula
gas coordinates
- Hybrid Universe
Mutual modulation of two palettes and dust attenuation
What sets Hybrid apart is the way the two results are combined:
Unlike simple addition , nebula emission is also boosted where the fractal filaments are already bright,
while the dust field derived from the FBM damps certain regions.
Hybrid's appearance therefore differs fundamentally from rendering Galaxy and Nebula separately and layering them with transparency. The two branches affect each other in linear light before exposure. Reproducing that compositing rule was the point.
2. Shared Screen Coordinates
2.1 Aspect Ratio Correction
For pixel coordinate and resolution ,
the normalization is applied as shown. Dividing each axis separately by and stretches radially symmetric structures into ellipses as the aspect ratio changes. Both axes are therefore divided together, and Nebula reaches the same goal with normalization.
2.2 Zoom, Rotation, and Drag
is Field Zoom, is Manual Rotation, and is the interpolated drag position. Hybrid uses a slightly larger drag offset of .
3. Galaxy of Universes
What follows is an analysis of Dave Hoskins's βGalaxy of Universesβ β ShaderToy.
The structure of galaxy.frag is not a rigorous gravitational N-body or general-relativistic simulation. It is a procedural fractal: each screen pixel advances a single pseudo-3D sample line, and at every position along it the orbital energy from a recursive spherical inversion is accumulated.
3.1 Radius-Dependent Differential Spiral Phase
The rotation phase depends on the distance from the center, .
Near the center the term grows, so the inner orbits wind more and the outer ones turn more gently. This expression is a visual differential swirl, unrelated to the Kerr metric or to real frame dragging.
3.2 Sample Line and Start-Point Jitter
With as the accumulated distance, the sample position is
built as shown. At most 120 steps are available, and the shader runs as many as the UI's Fractal Iterations specifies, defaulting to 90. The step length is for Galaxy and for Hybrid.
Integrating at fixed intervals from a fixed starting point leaves march bands that look like contour rings. To scatter them with fine noise, the first position is perturbed by a per-pixel hash.
3.3 8-Iteration Recursive Spherical Inversion
Each sample performs the following transformation exactly 8 times.
The transformation combines three operations:
: folds all octants into the positive region.
: performs Spherical Inversion with respect to the unit sphere.
: shifts the orbit away from the inversion center again.
During iteration, regions where is small are magnified strongly and large regions are compressed. Small differences in the initial conditions therefore branch into different orbital lengths and are amplified into fine filaments.
3.4 Three Energy Accumulators
The orbital energy of a single sample is accumulated into three channels, each in a different way.
When Wave Modulation is enabled, the first wave is
and the second wave uses a higher spatial frequency and a faster time rate.
It is a procedural density wave travelling outward from the center rather than a pulsar light curve.
3.5 Finite Support Radius
Different radial windows are multiplied in, which keeps fractal energy from filling the whole screen evenly.
The gap between the three radii separates the central core, the inner glow, and the outer filaments.
3.6 Color and Output Transform
Galaxy arranges into an asymmetric RGB combination. The final output is
where is the UI's Intensity. This is an artistic output transform that sets the contrast of the fractal energy rather than radiance-preserving tone mapping.
3.7 galaxy.frag FormulaβCode Correspondence
The expressions below are canonical forms that carry over the constants and the evaluation order of the current GLSL rather than general illustrations.
GLSL Symbol | Math Symbol | Definition |
|---|---|---|
| Screen coordinate with aspect ratio correction, zoom, rotation, and drag applied | |
| Radius-dependent differential rotation phase | |
| pseudo-3D sample-line distance | |
| State of the -th Spherical Inversion of the -th sample | |
| Orbital energy accumulators |
- GLSL Symbol
uv- Math Symbol
- Definition
Screen coordinate with aspect ratio correction, zoom, rotation, and drag applied
- GLSL Symbol
t- Math Symbol
- Definition
Radius-dependent differential rotation phase
- GLSL Symbol
s- Math Symbol
- Definition
pseudo-3D sample-line distance
- GLSL Symbol
p- Math Symbol
- Definition
State of the -th Spherical Inversion of the -th sample
- GLSL Symbol
v1,v2,v3- Math Symbol
- Definition
Orbital energy accumulators
Implementation β shaders/galaxy.frag, main()
float t = iTime * 0.1 * uSpeed
+ ((0.25 + 0.05 * sin(iTime * 0.1 * uSpeed))
/ (length(uv) + 0.07)) * 2.2;p = s * vec3(uv, 0.0);
p.xy *= ma;
p += vec3(0.22, 0.3, s - 1.5 - sin(iTime * 0.13 * uSpeed) * 0.1);for (int j = 0; j < 8; j++) {
p = abs(p) / dot(p, p) - 0.659;
}The final RGB combination matches the code as well.
vec3 col = vec3(
v3 * (1.5 + sin(iTime * 0.2 * uSpeed) * 0.4),
(v1 + v3) * 0.3,
v2
) + smoothstep(0.2, 0.0, len) * 0.85
+ smoothstep(0.0, 0.6, v3) * 0.3;col = min(pow(abs(col), vec3(uIntensity)), vec3(1.0));Here is uSpeed and is uIntensity.
The implementation and the GLSL are mapped one to one.
4. Spiral Nebula
nebula.frag composites a spatially continuous stochastic field at several scales rather than iterating a recursive fractal.
4.1 2D Value Noise
The coordinate is split into an integer cell and a position inside that cell, . The hash values at the four corners are
built as shown, and then bilinear interpolation is performed along a cubic Hermite curve
which reduces the slope discontinuities at cell edges that appear when only linear interpolation is used.
4.2 5-Octave FBM
Each octave doubles the frequency and halves the amplitude. Low-frequency octaves carry the large gas clumps, while high-frequency octaves handle the fine fluctuations at the edges.
4.3 Polar Spiral Warp
Sampling the noise defined in Cartesian coordinates at these spiral coordinates gives the circular cloud its wound-arm structure.
4.4 Gas Field at Three Spatial Frequencies
and drift in opposite directions and shear the arms, while , sampled directly in screen space, adds fine turbulence that stays independent of the spiral.
The final density is
smoothstep removes the sparse noise floor, and the exponential decay stops the gas from continuing at the same density all the way to the edge of the screen.
4.5 Color Space
Purple , magenta , and blue are interpolated in two stages.
The shift in color between interior and exterior is decided in the same coordinates used for the gas density rather than by a separate post-processing gradient.
4.6 Central Core and Exposure
The core is added, and then exponential exposure is applied to the whole color.
is Intensity / Glow. The transform stays non-negative and squeezes large emission values asymptotically toward 1, so it holds color in the core longer than a plain clamp would.
4.7 nebula.frag FormulaβCode Correspondence
GLSL Symbol | Math Symbol | Definition |
|---|---|---|
| ||
| ||
| Polar Spiral Warp position | |
| FBM fields at different coordinates and speeds | |
| Gas density with threshold and radial attenuation applied |
- GLSL Symbol
r- Math Symbol
- Definition
- GLSL Symbol
a- Math Symbol
- Definition
- GLSL Symbol
spiralCoord- Math Symbol
- Definition
Polar Spiral Warp position
- GLSL Symbol
n1,n2,n3- Math Symbol
- Definition
FBM fields at different coordinates and speeds
- GLSL Symbol
nebula- Math Symbol
- Definition
Gas density with threshold and radial attenuation applied
Implementation β shaders/nebula.frag, main()
float spiral = a + r * 4.0 - time * 0.5;
vec2 spiralCoord = vec2(cos(spiral), sin(spiral)) * r;float n1 = fbm(spiralCoord * 3.0 + time * 0.1);
float n2 = fbm(spiralCoord * 5.0 - time * 0.15);
float n3 = fbm(uv * 8.0 + vec2(time * 0.05, 0.0));float nebula = n1 * 0.5 + n2 * 0.3 + n3 * 0.2;
nebula = smoothstep(0.2, 0.8, nebula) * exp(-r * 0.8);The final color follows the code order and corresponds to
vec3 finalColor = mix(color1, color2, n1);
finalColor = mix(finalColor, color3, smoothstep(0.3, 0.7, r))
* nebula * 2.0;
float core = exp(-r * 3.0) * (1.0 + 0.3 * sin(time * 3.0));
finalColor += vec3(1.0, 0.95, 0.9) * core * 2.0;
finalColor *= 1.0 - r * 0.3;
finalColor = 1.0 - exp(-finalColor * uIntensity);
finalColor = pow(finalColor, vec3(0.85));as shown.
5. Hybrid Universe
hybrid.frag is an original compositing model I designed myself. Rather than alpha-blending finished Galaxy and Nebula frames, it evaluates both density fields at the same and . The two are then cross-modulated in linear light before exposure.
5.1 Galaxy Branch
Up to 120 samples, default 90 samples
8 Spherical Inversions per sample
Asymmetric RGB combination of
Central core and outer filament Radial Windows
5.2 Nebula Branch
Hybrid uses three denser FBM fields.
5.3 Linear Light Compositing
Nebula emission responds more strongly where the fractal is already bright. The two branches meet in linear light before either is tone-mapped, so the central luminance and the order of color mixing survive.
5.4 Dust Attenuation
High-frequency gas darkens interior regions above a threshold, which keeps every structure from looking like a plastic surface lit only by additive emission.
5.5 Final Exposure
In Hybrid, Intensity is applied once, after the linear-light composite.
5.6 hybrid.frag Canonical FormulaβCode Correspondence
Hybrid's originality lies less in having two branches than in the order and functions used to combine them. Below is the full compositing sequence of the current implementation.
Galaxy Branch
Implementation β shaders/hybrid.frag, main()
vec3 galaxyCol = vec3(
v3 * (1.6 + sin(time * 0.2) * 0.4) + v1 * 0.2,
(v1 + v3) * 0.38 + v2 * 0.15,
v2 * 1.1 + v1 * 0.25
);
galaxyCol += smoothstep(0.2, 0.0, len) * 0.95;
galaxyCol += smoothstep(0.0, 0.6, v3) * 0.35;Nebula Branch
float nebulaGas = n1 * 0.5 + n2 * 0.35 + n3 * 0.15;
nebulaGas = smoothstep(0.2, 0.78, nebulaGas) * exp(-len * 0.9);
vec3 nebulaCol = mix(nebColor1, nebColor2, n1);
nebulaCol = mix(nebulaCol, nebColor3, smoothstep(0.3, 0.8, len))
* nebulaGas * 1.6;Cross-Modulation
vec3 col = galaxyCol + nebulaCol * (0.6 + galaxyCol * 0.8);Multiplication and addition work per RGB component: bright blue fractal regions amplify the blue component of the nebula, bright red regions amplify its red, and each does so differently.
Core and Dust
float core = exp(-len * 3.5) * (1.0 + 0.25 * sin(time * 3.0));
col += vec3(1.0, 0.96, 0.92) * core * 1.8;float dust = smoothstep(0.4, 0.7, n2)
* (1.0 - smoothstep(0.05, 0.6, len));
col *= 1.0 - dust * 0.25;Single Output Transform
col = 1.0 - exp(-col * uIntensity * 1.15);
col = pow(col, vec3(0.85));This boxed expression runs exactly once, after every compositing, core, and dust calculation.
6. Mathematical Errors Corrected with AI Assistance During Implementation
6.1 Aspect Ratio Distortion
The old coordinates stretched radially symmetric structures horizontally on wide screens. Both axes are now divided together by or , which keeps the circular distance meaningful.
6.2 Color Interpolation No-Op
An earlier version of Hybrid contained the following pattern:
mix(nebColor3, nebColor3, weight)Both arguments were the same, so the interpolation did nothing, and it also overwrote the mix of two colors computed on the line above. The current version is
mix(mix(nebColor1, nebColor2, n1), nebColor3, radialWeight)written so that all three colors actually reach the output.
6.3 Fixed-Step Banding
Every pixel used to start at , which left regular circular bands across the image. A per-pixel hash jitter on the first step now scatters them.
6.4 Missing Hash Owner
A compile error was removed: galaxy.frag called hash() for the start-point jitter without defining it. Each fragment shader now owns the hash and noise functions it uses.
7. Parameters and Their Mathematical Effects
UI | Uniform | Effect |
|---|---|---|
Speed |
| Phase time , spiral movement, density wave speed |
Intensity / Glow |
| Galaxy power contrast or Nebula/Hybrid exponential exposure |
Field Zoom |
| Scale of the normalized coordinate |
Fractal Iterations |
| Number of sample-line steps for Galaxy/Hybrid, maximum 120 |
Manual Rotation |
| 2D rotation matrix applied to the input coordinate |
Auto Rotation | JavaScript state | Slowly increments |
Wave Modulation |
| Whether to apply the radial density wave in Galaxy/Hybrid |
- UI
Speed
- Uniform
uSpeed- Effect
Phase time , spiral movement, density wave speed
- UI
Intensity / Glow
- Uniform
uIntensity- Effect
Galaxy power contrast or Nebula/Hybrid exponential exposure
- UI
Field Zoom
- Uniform
uZoom- Effect
Scale of the normalized coordinate
- UI
Fractal Iterations
- Uniform
uIterations- Effect
Number of sample-line steps for Galaxy/Hybrid, maximum 120
- UI
Manual Rotation
- Uniform
uRotation- Effect
2D rotation matrix applied to the input coordinate
- UI
Auto Rotation
- Uniform
JavaScript state
- Effect
Slowly increments
uRotationeach frame
- UI
Wave Modulation
- Uniform
uPulseEffect- Effect
Whether to apply the radial density wave in Galaxy/Hybrid
Fractal Iterations leaves the 8 inner repetitions of the spherical inversion alone and changes only the number of outer samples taken along the ray. The boundary between the fractal definition itself and the integration quality therefore disappears.
8. Runtime and Implementation Structure
galaxy-of-universes/
βββ index.html # Three modes and parameter UI
βββ style.css # Fullscreen canvas and off-canvas studio
βββ README.md # Math and rendering documentation
βββ js/
β βββ shaders.js # Explicit GLSL URLs and preset registry
β βββ renderer.js # WebGL compile/link, uniforms, animation loop
β βββ controls.js # drag/zoom/mode switching and accessibility state
β βββ main.js # Initialization and error boundary
βββ shaders/
βββ vertex.vert # fullscreen triangle pair
βββ hybrid.frag # Galaxy + Nebula Nonlinear Linear Light Blending
βββ galaxy.frag # Recursive Spherical Inversion sample-line field
βββ nebula.frag # spiral-warped FBM fieldGLSL dependency files are declared explicitly so that both the static project bundler and the browser can resolve them.
const SHADER_URLS = {
vertex: new URL('../shaders/vertex.vert', import.meta.url),
hybrid: new URL('../shaders/hybrid.frag', import.meta.url),
galaxy: new URL('../shaders/galaxy.frag', import.meta.url),
nebula: new URL('../shaders/nebula.frag', import.meta.url)
};All GLSL is fetched in parallel and compiled strictly at startup. Missing files, shader compile failures, and program link failures are never silently swapped for another mode.
9. Validation Criteria
The criteria below were used as validation targets during the work.
The central core and Radial Window remain circular even when the aspect ratio changes.
Lowering
Fractal Iterationsreduces only the sample density; the 8-iteration Spherical Inversion structure is preserved.Turning off
Wave Modulationstops only the radial wave; the fractal orbits and FBM gas remain.The Galaxy start-point bands appear as fine dithering rather than fixed circular rings.
Nebula's three noise fields move at different speeds and in different coordinate spaces.
All three palettes of Hybrid, blue, purple, and magenta, reach the screen.
When switching modes, each GLSL source viewer displays the actual active fragment source.
Missing files or GLSL errors surface clearly as initialization errors.
10. Controls
Input | Action |
|---|---|
Mouse drag | Pan the coordinate field |
Mouse wheel | Zoom (β) |
| Pause/resume auto rotation |
| Show/hide title and FPS HUD |
| Open/close controls and GLSL panel |
| Close open panels |
- Input
Mouse drag
- Action
Pan the coordinate field
- Input
Mouse wheel
- Action
Zoom (β)
- Input
Space- Action
Pause/resume auto rotation
- Input
H- Action
Show/hide title and FPS HUD
- Input
Tab- Action
Open/close controls and GLSL panel
- Input
Esc- Action
Close open panels
11. Interpretive Limitations
The Spherical Inversion field is not the result of integrating an actual galaxy's mass distribution or stellar orbits.
The differential phase is a procedural warp that creates spiral structure, not a frame-dragging solution from general relativity.
Spiral Nebula is a model of a 2D stochastic field wound in polar coordinates, not a radiation hydrodynamics simulation.
The RGB palettes were not derived directly from spectroscopic observations.
Intensityis an exposure/contrast control, not a unit of energy.Hash and Value Noise are deterministic pseudorandom functions and do not reproduce the full statistics of physical turbulence.
12. References and Algorithmic Lineage
Implemented together with AI
Hybrid Universe: shared coordinate design for the fractal and nebula branches, luminance-responsive linear light compositing, FBM dust attenuation, the single-exposure pipeline, and final color design
Algorithmic Lineage and References
"Galaxy of Universes" β ShaderToy, Dave Hoskins β
Foundation of the Galaxy of Universes fractal branch
Kali β ShaderToy β lineage of the spherical-inversion iterated function system
Inigo Quilez β reference for Value Noise, FBM, SDF, and raymarching mathematics