Study Lab

Galaxy Universe 1

Galaxy Universe 1

Makonea
··19 min
Step 1 Lab experiment
Loading lab experiment...

Galaxy of Universes & Spiral Nebula

Warning

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 provides three real-time shaders, each 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

The three modes share the same Speed, Intensity, Field Zoom, Manual Rotation, and drag coordinate system, but they are not three approximations of the same physical phenomenon. Galaxy studies the orbital energy of iterated functions, Nebula studies the spatial correlation of stochastic fields, and Hybrid studies the combination of both results.

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 represent the algorithmic lineage of the fractal branch, while Value Noise and FBM are the mathematical materials of the nebula branch.

The method of combining the two source visuals by merging their two layers within a shared coordinate, time, and exposure system is itself the original implementation of Hybrid.

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 u,t\mathbf u, t

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

(v1,v2,v3)(v1, v2, v_3) orbital accumulator

(n1,n2,r)(n1, n2, r) 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 u,t\mathbf u, t

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

(v1,v2,v3)(v1, v2, v_3) orbital accumulator

Spiral Nebula

(n1,n2,r)(n1, n2, r) gas coordinates

Hybrid Universe

Mutual modulation of two palettes and dust attenuation

The key difference in Hybrid lies in the following compositing formula:

Chybrid=Cgalaxy+Cnebula(0.6+0.8Cgalaxy)\mathbf C_{hybrid}= \mathbf C_{galaxy}+ \mathbf C_{nebula} \left(0.6+0.8\mathbf C_{galaxy}\right)

Unlike simple addition Cg+Cn\mathbf Cg + \mathbf Cn, nebula emission is further amplified in regions where fractal filaments are already bright,

while the dust field derived from FBM attenuates certain regions.

ChybridChybrid(10.25D)\mathbf C_{hybrid}\leftarrow \mathbf C_{hybrid}(1-0.25D)

Therefore, the appearance of Hybrid cannot be reproduced by rendering Galaxy and Nebula separately and overlaying them with transparency. What matters is reproducing the compositing rule by which the two branches influence each other in linear light space, before exposure is applied.


2. Shared Screen Coordinates

2.1 Aspect Ratio Correction

For pixel coordinate x=(x,y)\mathbf x = (x, y) and resolution R=(Rx,Ry)\mathbf R = (Rx, Ry),

u=x12RRy\mathbf u= \frac{\mathbf x-\tfrac12\mathbf R}{R_y}

normalization is applied as shown. Dividing each axis separately by RxRx and RyRy is not used, because it stretches radially symmetric structures into ellipses depending on the screen's aspect ratio. Nebula uses min(Rx,Ry)\min(Rx, Ry) normalization for the same purpose.

2.2 Zoom, Rotation, and Drag

u=M(θr)(zu)+0.3(m0.5)\mathbf u'= \mathbf M(\theta_r)(z\mathbf u)+0.3(\mathbf m-0.5)
M(θ)=(cosθsinθsinθcosθ)\mathbf M(\theta)= \begin{pmatrix} \cos\theta&-\sin\theta\\ \sin\theta&\cos\theta \end{pmatrix}

zz is Field Zoom, θr\theta_r is Manual Rotation, and m\mathbf m is the interpolated drag position. Hybrid applies a slightly larger drag offset of 0.350.35.


3. Galaxy of Universes

Analysis of "Galaxy of Universes" — ShaderToy, a work by Dave Hoskins.

The structure of galaxy.frag is not a rigorous gravitational N-body or general relativistic simulation. It is a procedural fractal that advances a single pseudo-3D sample line from each screen pixel and accumulates the orbital energy obtained by applying recursive Spherical Inversion at each position.

3.1 Radius-Dependent Differential Spiral Phase

The rotational phase varies with the distance from center r=ur = |\mathbf u|.

θ(r,t)=0.1ts+2.20.25+0.05sin(0.1ts)r+0.07,ts=tspeed\theta(r,t)=0.1t_s+ 2.2\frac{0.25+0.05\sin(0.1t_s)}{r+0.07}, \qquad t_s=t\cdot\mathrm{speed}

Closer to the center, the 1/(r+0.07)1/(r + 0.07) term grows larger, causing inner orbits to wind more tightly while outer orbits rotate more gradually. This formula produces a visual differential swirl and is not a solution to the Kerr Metric or actual Frame Dragging.

3.2 Sample Line and Start-Point Jitter

Let sis_i be the accumulated distance; the sample position is then

pi=si(ux,uy,0)M(θ)+(0.22,0.30,si1.50.1sin(0.13ts))\mathbf p_i= s_i(u_x,u_y,0)\mathbf M(\theta) +(0.22,0.30,s_i-1.5-0.1\sin(0.13t_s))

constructed as shown. Up to 120 steps are available, but only as many as specified by the UI's Fractal Iterations are executed, with a default of 90. The step length is 0.0350.035 for Galaxy and 0.0330.033 for Hybrid.

Integrating at fixed intervals from a fixed starting point produces march bands in the form of contour rings. To disperse these with fine noise, the first position is perturbed using a per-pixel hash.

s0=0.033ξ(x,t),0ξ<1s_0=0.033\,\xi(\mathbf x,t), \qquad 0\le\xi<1

3.3 8-Iteration Recursive Spherical Inversion

Each sample performs the following transformation exactly 8 times.

pj+1=pjpjpj0.659,j=0,,7\mathbf p_{j+1}= \frac{|\mathbf p_j|}{\mathbf p_j\cdot\mathbf p_j}-0.659, \qquad j=0,\ldots,7

This transformation combines three operations:

  1. p|\mathbf p|: folds all octants into the positive region.

  2. p/(pp)\mathbf p / (\mathbf p \cdot \mathbf p): performs Spherical Inversion with respect to the unit sphere.

  3. 0.659-0.659: shifts the orbit away from the inversion center again.

During iteration, regions where p|\mathbf p| is small are greatly magnified while large regions are compressed. As a result, small differences in initial conditions are amplified into distinct orbital lengths and fine filaments.

3.4 Three Energy Accumulators

The orbital energy of a single sample is accumulated across three channels in different ways.

v1+=0.0015p2P1(r,t)v_1\mathrel{+}=0.0015\,\|\mathbf p\|^2 P_1(r,t)
v2+=0.0013p2P2(r,t)v_2\mathrel{+}=0.0013\,\|\mathbf p\|^2 P_2(r,t)
v3+=0.000310pxyv_3\mathrel{+}=0.0003\,\|10\mathbf p_{xy}\|

When Wave Modulation is enabled, the first wave is

P1(r,t)=1.8+sin(13r+0.50.2ts)P_1(r,t)=1.8+\sin(13r+0.5-0.2t_s)

and the second wave uses a higher spatial frequency and temporal speed.

P2(r,t)=1.5+sin(14.5r+1.20.3ts)P_2(r,t)=1.5+\sin(14.5r+1.2-0.3t_s)

This is a procedural density wave moving outward from the center, not a pulsar light curve.

3.5 Finite Support Radius

To prevent fractal energy from filling the entire screen uniformly, different Radial Windows are multiplied in.

v1v1smoothstep(0.7,0,r)v_1\leftarrow v_1\,\operatorname{smoothstep}(0.7,0,r)
v2v2smoothstep(0.5,0,r),v3v3smoothstep(0.9,0,r)v_2\leftarrow v_2\,\operatorname{smoothstep}(0.5,0,r), \qquad v_3\leftarrow v_3\,\operatorname{smoothstep}(0.9,0,r)

The differences among the three radii separate the central core, the inner glow, and the outer filaments.

3.6 Color and Output Transform

Galaxy arranges (v1,v2,v3)(v1, v2, v_3) in an asymmetric RGB combination. The final output is

Cout=min(Cγu,1)\mathbf C_{out}= \min\left(|\mathbf C|^{\gamma_u},1\right)

where γu\gamma_u is the UI's Intensity. This is not a physically radiance-preserving Tone Mapping but an artistic output transform that controls the contrast of fractal energy.

3.7 galaxy.frag Formula–Code Correspondence

The formulas below are not general illustrative expressions; they are canonical forms that directly reflect the constants and operation order of the current GLSL implementation.

GLSL Symbol

Math Symbol

Definition

uv

u\mathbf u

Screen coordinate with aspect ratio correction, zoom, rotation, and drag applied

t

θ\theta

Radius-dependent differential rotation phase

s

sis_i

pseudo-3D sample-line distance

p

pi,j\mathbf p_{i,j}

State of the jj-th Spherical Inversion of the ii-th sample

v1,v2,v3

v1,v2,v3v1, v2, v_3

Orbital energy accumulators

GLSL Symbol

uv

Math Symbol

u\mathbf u

Definition

Screen coordinate with aspect ratio correction, zoom, rotation, and drag applied

GLSL Symbol

t

Math Symbol

θ\theta

Definition

Radius-dependent differential rotation phase

GLSL Symbol

s

Math Symbol

sis_i

Definition

pseudo-3D sample-line distance

GLSL Symbol

p

Math Symbol

pi,j\mathbf p_{i,j}

Definition

State of the jj-th Spherical Inversion of the ii-th sample

GLSL Symbol

v1,v2,v3

Math Symbol

v1,v2,v3v1, v2, v_3

Definition

Orbital energy accumulators

θ=0.1tS+2.20.25+0.05sin(0.1tS)u+0.07\theta=0.1t\,S+ 2.2\frac{0.25+0.05\sin(0.1tS)}{\|\mathbf u\|+0.07}

Implementation — shaders/galaxy.frag, main()

GLSL
float t = iTime * 0.1 * uSpeed
        + ((0.25 + 0.05 * sin(iTime * 0.1 * uSpeed))
        / (length(uv) + 0.07)) * 2.2;
pi,0=(M(θ)siu+(.22,.30),si1.50.1sin(.13tS))\mathbf p_{i,0}= \left( \mathbf M(\theta)s_i\mathbf u+(.22,.30), s_i-1.5-0.1\sin(.13tS) \right)
GLSL
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);
pi,j+1=pi,jpi,j20.659,j=0,,7\mathbf p_{i,j+1}= \frac{|\mathbf p_{i,j}|}{\|\mathbf p_{i,j}\|^2}-0.659, \qquad j=0,\ldots,7
GLSL
for (int j = 0; j < 8; j++) {
    p = abs(p) / dot(p, p) - 0.659;
}

The final RGB combination also matches the code exactly.

Cg=(v3[1.5+0.4sin(0.2tS)]0.3(v1+v3)v2)+0.85smoothstep(0.2,0,r)+0.3smoothstep(0,0.6,v3)\mathbf C_g= \begin{pmatrix} v_3[1.5+0.4\sin(0.2tS)]\\ 0.3(v_1+v_3)\\ v_2 \end{pmatrix} +0.85\,\operatorname{smoothstep}(0.2,0,r) +0.3\,\operatorname{smoothstep}(0,0.6,v_3)
GLSL
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;
Cout=min(CgI,1)\mathbf C_{out}=\min(|\mathbf C_g|^I,1)
GLSL
col = min(pow(abs(col), vec3(uIntensity)), vec3(1.0));

Here SS is uSpeed and II is uIntensity.

The implementation and GLSL are mapped one-to-one.



4. Spiral Nebula

nebula.frag does not use a recursive fractal; instead, it composites a spatially continuous stochastic field at multiple scales.

4.1 2D Value Noise

Coordinate p\mathbf p is split into integer cell i=p\mathbf i = \lfloor \mathbf p \rfloor and intra-cell coordinate f=fract(p)\mathbf f = \operatorname{fract}(\mathbf p). The hash values at the four corners are

h(i)=fract[sin(127.1ix+311.7iy)43758.5453]h(\mathbf i)= \operatorname{fract}\left[ \sin(127.1i_x+311.7i_y)\,43758.5453 \right]

constructed as shown, then bilinear interpolation is performed using the cubic Hermite Curve

q=f2(32f)\mathbf q=\mathbf f^2(3-2\mathbf f)

to reduce the gradient discontinuities at cell boundaries that appear when only linear interpolation is used.

4.2 5-Octave FBM

fbm(p)=k=042(k+1)n(2kp)\operatorname{fbm}(\mathbf p)= \sum_{k=0}^{4}2^{-(k+1)}n(2^k\mathbf p)

Each octave doubles the frequency and halves the amplitude. Low-frequency octaves capture large gas clumps, while high-frequency octaves handle fine fluctuations at the edges.

4.3 Polar Spiral Warp

r=u,a=atan2(uy,ux)r=\|\mathbf u\|, \qquad a=\operatorname{atan2}(u_y,u_x)
ψ=a+4r0.5ts\psi=a+4r-0.5t_s
s(r,a,t)=r(cosψ,sinψ)\mathbf s(r,a,t)=r(\cos\psi,\sin\psi)

By sampling the noise in Cartesian coordinates at positions defined by this spiral coordinate, circular clouds acquire a wound-arm structure.

4.4 Gas Field at Three Spatial Frequencies

n1=fbm(3s+0.1ts)n_1=\operatorname{fbm}(3\mathbf s+0.1t_s)
n2=fbm(5s0.15ts)n_2=\operatorname{fbm}(5\mathbf s-0.15t_s)
n3=fbm(8u+(0.05ts,0))n_3=\operatorname{fbm}(8\mathbf u+(0.05t_s,0))

n1n1 and n2n2, moving in opposite directions, create shear in the arms, while n3n_3, sampled directly in screen coordinates, adds fine turbulence that is independent of the spiral.

N=0.5n1+0.3n2+0.2n3N=0.5n_1+0.3n_2+0.2n_3

The final density is

ρ(u)=smoothstep(0.2,0.8,N)e0.8r\rho(\mathbf u)= \operatorname{smoothstep}(0.2,0.8,N)e^{-0.8r}

The smoothstep removes the sparse noise floor, and the exponential decay prevents the gas from continuing at the same density to the edge of the screen.

4.5 Color Space

Purple c1\mathbf c1, magenta c2\mathbf c2, and blue c3\mathbf c_3 are interpolated in two stages.

c12=mix(c1,c2,n1)\mathbf c_{12}=\operatorname{mix}(\mathbf c_1,\mathbf c_2,n_1)
Cneb=mix(c12,c3,smoothstep(0.3,0.7,r))2ρ\mathbf C_{neb}= \operatorname{mix} (\mathbf c_{12},\mathbf c_3, \operatorname{smoothstep}(0.3,0.7,r)) \,2\rho

The color variation between interior and exterior is determined in the same coordinate space as the gas density calculation, not by a separate post-processing gradient.

4.6 Central Core and Exposure

K(r,t)=e3r[1+0.3sin(3ts)]K(r,t)=e^{-3r}\left[1+0.3\sin(3t_s)\right]

After adding the core, exponential exposure is applied to the entire color.

C=1eIC\mathbf C'=1-e^{-I\mathbf C}
Cout=(C)0.85\mathbf C_{out}=(\mathbf C')^{0.85}

II is Intensity / Glow. This transform has no negative values and asymptotically compresses large luminance values toward 1, so it preserves color in the central region longer than a simple clamp would.

4.7 nebula.frag Formula–Code Correspondence

GLSL Symbol

Math Symbol

Definition

r

rr

u\mathbf u

a

aa

atan2(uy,ux)\operatorname{atan2}(u_y, u_x)

spiralCoord

s\mathbf s

Polar Spiral Warp position

n1,n2,n3

n1,n2,n3n_1, n_2, n_3

FBM fields at different coordinates and speeds

nebula

ρ\rho

Gas density with threshold and radial attenuation applied

GLSL Symbol

r

Math Symbol

rr

Definition

u\mathbf u

GLSL Symbol

a

Math Symbol

aa

Definition

atan2(uy,ux)\operatorname{atan2}(u_y, u_x)

GLSL Symbol

spiralCoord

Math Symbol

s\mathbf s

Definition

Polar Spiral Warp position

GLSL Symbol

n1,n2,n3

Math Symbol

n1,n2,n3n_1, n_2, n_3

Definition

FBM fields at different coordinates and speeds

GLSL Symbol

nebula

Math Symbol

ρ\rho

Definition

Gas density with threshold and radial attenuation applied

ψ=a+4r0.5tS,s=r(cosψ,sinψ)\psi=a+4r-0.5tS, \qquad \mathbf s=r(\cos\psi,\sin\psi)

Implementation — shaders/nebula.frag, main()

GLSL
float spiral = a + r * 4.0 - time * 0.5;
vec2 spiralCoord = vec2(cos(spiral), sin(spiral)) * r;
n1=F(3s+0.1tS),n2=F(5s0.15tS),n3=F(8u+(0.05tS,0))\begin{aligned} n_1&=F(3\mathbf s+0.1tS),\\ n_2&=F(5\mathbf s-0.15tS),\\ n_3&=F(8\mathbf u+(0.05tS,0)) \end{aligned}
GLSL
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));
ρ=smoothstep(0.2,0.8,0.5n1+0.3n2+0.2n3)e0.8r\rho= \operatorname{smoothstep} \left(0.2,0.8,0.5n_1+0.3n_2+0.2n_3\right)e^{-0.8r}
GLSL
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 corresponds, in code order, to

C0=2ρmix[mix(c1,c2,n1),c3,smoothstep(0.3,0.7,r)]\mathbf C_0= 2\rho\,\operatorname{mix} \left[ \operatorname{mix}(\mathbf c_1,\mathbf c_2,n_1), \mathbf c_3, \operatorname{smoothstep}(0.3,0.7,r) \right]
C1=(10.3r)[C0+2(1,.95,.9)e3r(1+0.3sin3tS)]\mathbf C_1=(1-0.3r) \left[ \mathbf C_0+2(1,.95,.9)e^{-3r}(1+0.3\sin 3tS) \right]
Cout=(1eIC1)0.85\mathbf C_{out}=\left(1-e^{-I\mathbf C_1}\right)^{0.85}
GLSL
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 renders of Galaxy and Nebula, it computes both density fields at the same u\mathbf u and tst_s, then cross-modulates them in linear light space before exposure is applied.

5.1 Galaxy Branch

  • Up to 120 samples, default 90 samples

  • 8 Spherical Inversions per sample

  • Asymmetric RGB combination of (v1,v2,v3)(v1, v2, v_3)

  • Central core and outer filament Radial Windows

5.2 Nebula Branch

Hybrid uses three denser FBM fields.

n1=fbm(3.5s+0.08ts)n_1=\operatorname{fbm}(3.5\mathbf s+0.08t_s)
n2=fbm(6s0.12ts)n_2=\operatorname{fbm}(6\mathbf s-0.12t_s)
n3=fbm(9u+(0.05ts,0.05ts))n_3=\operatorname{fbm}(9\mathbf u+(0.05t_s,-0.05t_s))
ρh=smoothstep(0.2,0.78,0.5n1+0.35n2+0.15n3)e0.9r\rho_h= \operatorname{smoothstep} \left(0.2,0.78, 0.5n_1+0.35n_2+0.15n_3\right)e^{-0.9r}

5.3 Linear Light Compositing

C=Cgalaxy+Cnebula(0.6+0.8Cgalaxy)\mathbf C= \mathbf C_{galaxy}+ \mathbf C_{nebula} \left(0.6+0.8\mathbf C_{galaxy}\right)

Nebula emission responds more strongly in regions where fractal filaments are already bright. Because the two branches are not tone-mapped separately before addition, the central luminance and color blending order are preserved.

5.4 Dust Attenuation

D=smoothstep(0.4,0.7,n2)[1smoothstep(0.05,0.6,r)]D=\operatorname{smoothstep}(0.4,0.7,n_2) \left[1-\operatorname{smoothstep}(0.05,0.6,r)\right]
CC(10.25D)\mathbf C\leftarrow\mathbf C(1-0.25D)

High-frequency gas partially darkens interior regions that exceed a certain threshold, preventing every structure from appearing like a plastic surface with only additive emission.

5.5 Final Exposure

Cout=(1exp[1.15IC])0.85\mathbf C_{out}= \left(1-\exp[-1.15I\mathbf C]\right)^{0.85}

In Hybrid, Intensity is applied only once, after linear light compositing.

5.6 hybrid.frag Canonical Formula–Code Correspondence

The originality of Hybrid lies not merely in having two branches, but in the order and functions used to combine them. The following is the complete compositing sequence of the current implementation.

Galaxy Branch

Cg=(v3[1.6+0.4sin(0.2tS)]+0.2v10.38(v1+v3)+0.15v21.1v2+0.25v1)+0.95smoothstep(0.2,0,r)+0.35smoothstep(0,0.6,v3)\mathbf C_g= \begin{pmatrix} v_3[1.6+0.4\sin(0.2tS)]+0.2v_1\\ 0.38(v_1+v_3)+0.15v_2\\ 1.1v_2+0.25v_1 \end{pmatrix} +0.95\,\operatorname{smoothstep}(0.2,0,r) +0.35\,\operatorname{smoothstep}(0,0.6,v_3)

Implementation — shaders/hybrid.frag, main()

GLSL
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

ρh=smoothstep(0.2,0.78,0.5n1+0.35n2+0.15n3)e0.9r\rho_h= \operatorname{smoothstep} \left(0.2,0.78,0.5n_1+0.35n_2+0.15n_3\right)e^{-0.9r}
Cn=1.6ρhmix[mix(c1,c2,n1),c3,smoothstep(0.3,0.8,r)]\mathbf C_n= 1.6\rho_h\, \operatorname{mix}\left[ \operatorname{mix}(\mathbf c_1,\mathbf c_2,n_1), \mathbf c_3, \operatorname{smoothstep}(0.3,0.8,r) \right]
GLSL
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

C=Cg+Cn(0.6+0.8Cg)\mathbf C=\mathbf C_g+\mathbf C_n(0.6+0.8\mathbf C_g)
GLSL
vec3 col = galaxyCol + nebulaCol * (0.6 + galaxyCol * 0.8);

The multiplication and addition operate per RGB component. That is, bright blue fractal regions amplify the blue component of the nebula, and bright red regions amplify the red component, each differently.

Core and Dust

CC+1.8(1,.96,.92)e3.5r[1+0.25sin(3tS)]\mathbf C\leftarrow\mathbf C+ 1.8(1,.96,.92)e^{-3.5r}[1+0.25\sin(3tS)]
GLSL
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;
D=smoothstep(0.4,0.7,n2)[1smoothstep(0.05,0.6,r)]D=\operatorname{smoothstep}(0.4,0.7,n_2) [1-\operatorname{smoothstep}(0.05,0.6,r)]
CC(10.25D)\mathbf C\leftarrow\mathbf C(1-0.25D)
GLSL
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

Cout=[1exp(1.15IC)]0.85\boxed{ \mathbf C_{out}= \left[1-\exp(-1.15I\mathbf C)\right]^{0.85} }
GLSL
col = 1.0 - exp(-col * uIntensity * 1.15);
col = pow(col, vec3(0.85));

This boxed formula is executed exactly once, after all compositing, core, and dust calculations are complete.


6. Mathematical Errors Corrected with AI Assistance During Implementation

6.1 Aspect Ratio Distortion

The original [0.5,0.5]2[-0.5, 0.5]^2 coordinates stretched radially symmetric structures horizontally on widescreen displays. The current implementation divides both axes together by RyRy or min(Rx,Ry)\min(Rx, R_y) to preserve the meaning of circular distance rr.

6.2 Color Interpolation No-Op

A previous version of Hybrid contained the following pattern:

GLSL
mix(nebColor3, nebColor3, weight)

Both arguments were identical, so the interpolation had no effect, and it also overwrote the blend of two colors computed in the preceding line. The current version is

GLSL
mix(mix(nebColor1, nebColor2, n1), nebColor3, radialWeight)

structured so that all three colors actually reach the output.

6.3 Fixed-Step Banding

Sample-line integration that started every pixel at s=0s = 0 produced uniform circular bands. The current implementation applies a per-pixel Hash Jitter to the first step.

6.4 Missing Hash Owner

A compile error where galaxy.frag called hash() for start-point jitter without defining it has been removed. Each fragment shader now owns the hash/noise functions it uses directly.


7. Parameters and Their Mathematical Effects

UI

Uniform

Effect

Speed

uSpeed

Phase time tst_s, spiral movement, density wave speed

Intensity / Glow

uIntensity

Galaxy power contrast or Nebula/Hybrid exponential exposure

Field Zoom

uZoom

Scale of the normalized coordinate u\mathbf u

Fractal Iterations

uIterations

Number of sample-line steps for Galaxy/Hybrid, maximum 120

Manual Rotation

uRotation

2D rotation matrix applied to the input coordinate

Auto Rotation

JavaScript state

Slowly increments uRotation each frame

Wave Modulation

uPulseEffect

Whether to apply the radial density wave in Galaxy/Hybrid

UI

Speed

Uniform

uSpeed

Effect

Phase time tst_s, 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 u\mathbf u

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 uRotation each frame

UI

Wave Modulation

Uniform

uPulseEffect

Effect

Whether to apply the radial density wave in Galaxy/Hybrid

Fractal Iterations does not change the inner 8 repetitions of the Spherical Inversion. It only changes the number of outer samples evaluated along the ray. The boundary between the fractal definition itself and the integration quality is therefore preserved.


8. Runtime and Implementation Structure

Text
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 field

GLSL dependency files are declared explicitly so that both the static project bundler and the browser can resolve them.

JavaScript
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 not silently substituted with another mode.


9. Validation Criteria

The following criteria were used as validation targets throughout development.

  1. The central core and Radial Window remain circular even when the aspect ratio changes.

  2. Lowering Fractal Iterations reduces only the sample density; the 8-iteration Spherical Inversion structure is preserved.

  3. Turning off Wave Modulation stops only the radial wave; the fractal orbits and FBM gas remain.

  4. The Galaxy start-point bands appear as fine dithering rather than fixed circular rings.

  5. Nebula's three noise fields move at different speeds and in different coordinate spaces.

  6. All three palettes of Hybrid, blue, purple, and magenta, reach the screen.

  7. When switching modes, each GLSL source viewer displays the actual active fragment source.

  8. Missing files or GLSL errors surface clearly as initialization errors.


10. Controls

Input

Action

Mouse drag

Pan the coordinate field

Mouse wheel

Zoom (0.3×0.3\times3.0×3.0\times)

Space

Pause/resume auto rotation

H

Show/hide title and FPS HUD

Tab

Open/close controls and GLSL panel

Esc

Close open panels

Input

Mouse drag

Action

Pan the coordinate field

Input

Mouse wheel

Action

Zoom (0.3×0.3\times3.0×3.0\times)

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 1/(r+0.07)1/(r + 0.07) 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.

  • Intensity is 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

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