Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Shaders

Pro

Cosmic Waves Shader for React

One large, soft cosmic glow drawn on the GPU: its colors loop from blue through violet and cyan to pink, swirled by slow waves, with small stars twinkling in front. For React with Base UI, when a hero, a pricing section or a launch needs a colorful, moving glow behind its copy.

Framework

Cosmic Waves Shader fills its box with one large, soft glow that slowly changes color. Three sine waves interfere with a layer of fractal noise to make a swirling pattern, and the pattern picks each pixel's place on a loop of four colors, blue to violet to cyan to pink and back, so bands of color sweep through the glow as the loop turns. Two layers of small stars drift and twinkle in front, and a round vignette takes the corners to black. A WGSL fragment shader on WebGPU computes every pixel each frame, for about a quarter of a millisecond of GPU time.

Use it behind a dark hero, a pricing or launch section, or anywhere a glow should carry your brand's colors: all four loop colors and the center glow are props. For drifting clouds in one tint instead, use Nebula Shader; for bands of light, Aurora Shader; for a CSS backdrop with no GPU, the Nebula background. It runs only while it's on screen, holds a still frame with reduced motion, and shows a gradient of the same colors in browsers without WebGPU.

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Usage

import { CosmicWavesShader } from "@/components/ui/cosmic-waves-shader";
<CosmicWavesShader className="flex min-h-[32rem] items-center justify-center">
  <h1 className="text-5xl font-semibold text-white">Ship faster</h1>
</CosmicWavesShader>

Cosmic Waves Shader is a container: your content sits on top of the glow, in normal flow. It fills its own box, so give it a height or content. For a backdrop behind the whole page, render it empty with className="fixed inset-0 -z-10". The glow is dark around the edges and moderately bright in the middle, in both color schemes, so put white or light text over it, large in the middle or on a panel such as bg-black/40.

Demos

Brand colors

colorSpeed={0} stops the loop, so the glow holds the part of it around firstColor, blended toward secondColor and fourthColor where the waves rise and fall; thirdColor hardly shows. Here a violet glow swirls into pink and cyan.

Preview width

In a card

The glow scales with its box. amplitude={0.6} calms the swirls into a smoother glow, and stars={1.4} packs in more, smaller stars.

Preview width

Performance

About 0.26 ms of GPU time a frame at 1280×720 on an M2 Max laptop; slower GPUs take several times longer. The props don't change the cost. The glow is soft, so quality={0.5} renders a quarter of the pixels and looks nearly the same; only the stars get coarser. The animation stops when the shader scrolls out of view, and the browser pauses it in a hidden tab. Every shader on a page shares one GPU device and one frame loop, and vgpu loads only when the first one mounts.

Browser support

The shader needs WebGPU: Chrome and Edge, Safari 26 and later, and Firefox on Windows and macOS. Elsewhere, and until the first frame, the box shows a CSS gradient of soft teal, blue and pink glows on dark navy, so the layout never jumps. data-state on the root reads unsupported there, if you want to style around it. See Shader Canvas.

Accessibility

The glow is decoration: it's hidden from assistive tech and lets every click through to your content. With reduced motion it draws one still frame, a cyan and pink glow, and stops. Nothing flashes: the colors loop once every 10 seconds at the default colorSpeed, and each star fades in and out over about three seconds. Across 18 frames over 23 seconds, white text reaches 4.5:1 on 95% of the shader, but on only 81% of the middle, where the glow is brightest; it stays above 3:1 on 94% of the middle. So a large white headline reads there, and small text needs a panel.

FAQ

How do the colors cycle, and how do I slow or stop them?

Each pixel's color is a place on a loop of four colors, set by time plus the wave pattern, so bands of color sweep through the glow. colorSpeed sets how fast the loop turns: 0.5, the default, takes 10 seconds, 1 takes 5 (shadcn.io's pace), and 0 holds the colors while the waves keep moving. speed scales everything, the waves, the drift and the twinkle included.

Can I use my brand colors?

Yes: firstColor, secondColor, thirdColor and fourthColor are the loop, in order, and glowColor is the soft light added at the center. They take any CSS color and follow a theme switch, so var(--primary) works. With colorSpeed={0}, the first color leads and the second and fourth show at the edges of the swirls.

How are the stars made?

The frame is split into a grid, and one cell in twenty, picked by a hash, holds a soft dot. Two such grids at different sizes drift slowly in different directions, and each star twinkles on its own beat. stars sets the grid's density: 2 gives more, smaller stars, and 0 hides them.

What's the difference between amplitude and scale?

amplitude is how strongly the waves bend the colors and the light: 0 leaves a smooth glow, 2 bold swirls. scale is their size: below 1 one broad swell, above 1 many tight ripples. Neither changes the cost.

What happens in browsers without WebGPU?

The box keeps its CSS gradient, soft teal, blue and pink glows on dark navy, so the page still looks finished. Nothing errors: the root's data-state reads unsupported.

Will it slow my page down?

It costs about 0.26 ms of GPU time a frame at 1280×720 on a laptop, and the CPU only sets a few numbers each frame. It stops when it's off screen. On a slow GPU or a large screen, quality={0.5} renders at half resolution, a quarter of the pixels, and the glow looks the same.

API Reference

CosmicWavesShader

data-slot="cosmic-waves-shader"

PropType
amplitude?number

How strongly the waves bend the colours and the light, from 0 (a smooth glow) to 2 (bold swirls). @default 1.

Default
1
colorSpeed?number

How fast the colours loop, on top of speed: 0.5 is a full loop every 10 seconds, 1 every 5, and 0 holds them. @default 0.5.

Default
0.5
fallback?string

What shows until the first frame and in browsers without WebGPU: a CSS background value (gradients, sizes, a colour) that looks like the shader. It can use the colour props' --shader-<field> variables.

firstColor?string

The first colour of the loop. Any CSS colour. @default "#1a33cc".

Default
"#1a33cc"
fourthColor?string

The fourth colour of the loop, which leads back to the first. Any CSS colour. @default "#e64d99".

Default
"#e64d99"
glowColor?string

The soft light added at the centre. Any CSS colour. @default "#3366cc".

Default
"#3366cc"
interactive?boolean

Whether u.pointer follows the pointer. @default false.

paused?boolean

Holds the current frame. @default false.

quality?number

Render scale, from 0.25 to 1, of the screen's pixels (capped at 2×). @default 1.

scale?number

The size of the waves, from 0.5 (one broad swell) to 2 (many tight ripples). @default 1.

Default
1
secondColor?string

The second colour of the loop. Any CSS colour. @default "#991ae6".

Default
"#991ae6"
speed?number

Animation speed: 1 is normal, 0 holds the frame. @default 1.

stars?number

How many stars, from 0 (none) to 2: more stars are also smaller. @default 1.

Default
1
thirdColor?string

The third colour of the loop. Any CSS colour. @default "#1acce6".

Default
"#1acce6"
time?number

A fixed moment, in seconds: draws it and doesn't animate.

render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Forwarded to the part.

All 101 shaders