← Back to blog
July 10, 2026Shaders

GLSL Sun Shader

Live shaderReal-time GLSL running in your browser

Shader not running? It needs a browser with WebGL2. If it's slow, open Controls and set Quality to Low.

Source sun.fragView and edit the GLSL, live

This sun started as a GLSL TOP in TouchDesigner. I pushed it toward the look of NASA's Solar Dynamics Observatory footage, in particular the deep red AIA 304 Å channel, where the surface turns into a tangle of bright active regions and dark magnetic channels. Then I ported it to WebGL2 so it runs live right here in the page.

Everything you see is one fragment shader of about 1,500 lines. There are no textures or models on the sun itself; the only image is the Milky Way behind it. Here's how it's put together.

A deep red sun with bright active regions, dark filament channels and faint arches at the edge
The default look: deep red, modelled on SDO's 304 Å channel.

The surface

The sun is a ray-traced sphere, and every point on it is shaded from 3D noise sampled on its surface. Plain FBM noise just looks like clouds, so most of the work went into bending and layering it until it read as plasma held in place by magnetic fields:

  • Domain warping: a slow noise field pushes every later lookup sideways, so the texture flows into curved, looping streamlines instead of round blobs.
  • Curl noise: the gradient of another noise field, turned 90° along the surface. Because that flow never converges or spreads, it drags the texture along long field lines, like iron filings around a magnet.
  • Four stacked layers: hemisphere-sized dark zones, then filament channels, then granulation (bright convection cells with dark lanes), then fine fibrils. Each layer lets through a fraction of the light from the one below. Multiplying them together, rather than adding, gives the look of light breaking through stacked sheets of gas.
  • Filament channels: the long dark rivers come from a single, very low-frequency noise field, darkened wherever it crosses its midpoint. One octave gives one clean, continuous line per arc. Adding more octaves breaks the channels into fragments.
  • Differential rotation: like the real sun, the equator turns faster than the poles, so the pattern slowly shears as it spins.
Close-up of the sun's surface: dark channels, granulation and bright yellow active regions
Zoomed in: dark zones, filament channels, granulation and the brightest active regions.

Active regions and sunspots

A separate, larger noise field marks the active regions: the top quarter or so of its values become hot spots that ramp up to yellow and white. They're multiplied by the granulation layer, so a hot spot is a cluster of glowing cells rather than a flat blob.

Sunspots sit at the peak of each hot spot. The shader takes the slope of the hot-spot field to find which way points out from each spot's centre, then samples stretched noise along that direction. That gives the radial fibres of the penumbra around a dark umbra, with no extra geometry.

God rays and the corona

Outside the sphere, every pixel marches its view ray through the space around the sun, 32 steps per pixel. At each step it fires a shadow ray toward a light at the sun's centre and checks where that ray leaves the surface. If it leaves through an active region, light scatters toward the camera. So the beams always erupt from the same hot spots you can see on the disk, and they turn with the sun.

  • Breakup: two more noise layers, one on the surface and one in the volume, stop the beams from looking like solid slabs.
  • Length and flicker: every beam gets its own length, a soft fade at the tip and an independent flicker, plus a slow pulse from the light inside.
  • Colour: the light shifts from hot yellow near the surface to deep red at the ends, with slow-drifting dust motes catching it.
  • No stair-steps: each pixel starts its march at a random offset that changes every frame. This turns the banding you'd normally get from 32 steps into fine grain.
The sun with bright red god rays streaming out from its active regions
God ray brightness and length turned up in Controls.

Spicules, clouds and prominences

The same march picks up three more layers just above the surface. Each one is independent, so I can tune them separately in TouchDesigner:

  • Spicules: a thin, glowing shell of hair-like jets, made from coarse clumps multiplied by fine strands.
  • Chromospheric clouds: wispy sheets of plasma floating at a set height, fading in and out softly at the top and bottom.
  • Prominences: real geometry. Each arch is a torus centred on the surface, so its top half loops out of the sun and the bottom half hides inside it. Arches are scattered across the sphere in Voronoi cells, each with its own height and random orientation, and noise flows along the tube like plasma running along a magnetic loop. Big arches can reach two cells away, so each step checks 125 neighbouring cells. Two cheap tests throw out almost all of them before any torus maths runs.
The sun at a closer zoom with prominence arches looping out from its edges
Prominences raised in Controls: torus arches looping off the limb.

Palettes

One surface colour drives the whole palette, so a single value moves the sun from the deep red EUV look to an orange ember or something close to visible light. The god rays take their own colour, so they can match or contrast.

Side by side: the sun in the orange ember palette and in the visible light palette
Orange ember and visible light, from the Palette menu.

Controls

Drag on the sun to rotate it, scroll or pinch to zoom, and double-click to reset. Open Controls in the top-right corner for:

  • Quality: Low, Medium, High (the default on desktop) and Extreme. Extreme renders at twice the resolution in each direction and scales it down, which smooths the edges of the disk and the god rays. It's heavy, so save it for a fast graphics card.
  • Palette, the Milky Way background, Pause and Reset.
  • Sliders for rotation speed, zoom, surface churn, god ray brightness and length, prominences, sunspots, filament channels, dark zones, differential rotation, exposure and bloom.

Under the hood

The TouchDesigner network does more than the shader, so the port rebuilds that too, as a few small WebGL2 passes:

  • Sun: the main shader, with uniform values copied from my TouchDesigner project so the browser matches what I see there.
  • Level and composite: the same black level and brightness as the Level TOP, then the sun laid over a dimmed Milky Way. The shader writes transparency, so in TouchDesigner it can sit over any footage.
  • Bloom: the brightest parts are pulled out at quarter resolution, blurred in two separable passes and added back.
  • Rotation: in TouchDesigner a Speed CHOP feeds the rotation; here a small loop does the same, and dragging adds a camera rotation on top.

The GLSL source sits below the shader on this page. You can edit it and the sun recompiles live, so try changing a number and see what breaks.

— CGDavidB