Cosmicrift
forgeui/cosmicriftFreeComponent
A WebGL-powered animated cosmic background featuring a procedural starfield with twinkling effects and flowing nebula-like wave distortions, rendered in real time using shaders.
Live preview
live · rendered by the registry
Rendered by ForgeUI on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://forgeui.in/r/cosmicrift.jsonSource
1"use client";23import { useEffect, useMemo, useRef } from "react";4import { cn } from "@/lib/utils";56const vertexShaderGLSL = `7attribute vec2 position;8void main() {9 gl_Position = vec4(position, 0.0, 1.0);10}11`;1213const fragmentShaderGLSL = `14precision highp float;1516uniform vec2 u_resolution;17uniform float u_time;18uniform vec3 u_colorBackground;19uniform vec3 u_colorStars;20uniform float u_density;21uniform float u_speed;2223float hash(vec2 p) {24 return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453123);25}2627void main() {28 vec2 uv = gl_FragCoord.xy / u_resolution;29 float aspect = u_resolution.x / u_resolution.y;3031 vec2 p = uv;32 p.x *= aspect;3334 float t = u_time * u_speed * 0.5;3536 vec3 color = u_colorBackground;3738 float gridSize = 35.0 * u_density;39 vec2 gridPos = floor(p * gridSize);40 vec2 localUV = fract(p * gridSize) - 0.5;4142 float r = hash(gridPos);43 float threshold = 0.85; // Low threshold = dense stars4445 if (r > threshold) {46 vec2 offset = vec2(hash(gridPos + 12.0), hash(gridPos + 24.0)) - 0.5;47 float dist = length(localUV - offset * 0.7);4849 float size = 0.025 + (r - threshold) * 0.6;50 float brightness = smoothstep(size, 0.0, dist);5152 float twinkleSpeed = 1.0 + hash(gridPos + 100.0) * 3.0;53 float twinkle = sin(t * twinkleSpeed * 2.0 + hash(gridPos + 200.0) * 6.28) * 0.5 + 0.5;54 brightness *= (0.3 + twinkle * 0.7);5556 vec3 starCol = mix(u_colorStars, vec3(0.6, 0.8, 1.0), hash(gridPos + 300.0));5758 color += starCol * brightness * (r - threshold) * 7.0;59 }6061 vec2 cuv = uv * 2.0 - 1.0;62 cuv.x *= aspect;6364 vec3 waveColor = vec3(0.0);6566 for(float i = 1.0; i <= 4.0; i++) {67 float xDistort = sin(cuv.y * 2.0 * i + t * (0.5 + i * 0.15)) * 0.2;68 float yDistort = cos(cuv.x * 2.0 * i - t * 0.4) * 0.15;6970 vec2 distortedUV = cuv + vec2(xDistort, yDistort);71 float dist = abs(distortedUV.y);7273 float glow = 0.015 / (dist + 0.015);7475 vec3 c1 = vec3(0.1, 0.02, 0.3);76 vec3 c2 = vec3(0.0, 0.9, 1.0);77 vec3 c3 = vec3(0.9, 0.1, 0.7);7879 vec3 layerCol = mix(c1, c2, sin(cuv.x * 2.5 + t + i) * 0.5 + 0.5);80 layerCol = mix(layerCol, c3, cos(cuv.y * 3.0 - t) * 0.5 + 0.5);8182 waveColor += layerCol * glow * (1.5 / i);83 }8485 float mask = smoothstep(1.0, 0.05, abs(cuv.y));8687 color += waveColor * mask;8889 float vignette = uv.x * (1.0 - uv.x) * uv.y * (1.0 - uv.y) * 15.0;90 color *= pow(vignette, 0.15);9192// … truncated
Files it writes
More from ForgeUI
All 28 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Formanimated-form | ForgeUI | Components | Free | no deps | |
| Animated OTPanimated-otp | ForgeUI | Components | Free | no deps | |
| Animated Tabsanimated-tabs | ForgeUI | Components | Free | no deps | |
| Auralisauralis | ForgeUI | Components | Free | no deps | |
| Bot Detectionbot-detection | ForgeUI | Components | Free | no deps | |
| Chromatic Fluidchromatic-fluid | ForgeUI | Components | Free | no deps | |
| Cloudscapecloudscape | ForgeUI | Components | Free | no deps | |
| Expandable Cardexpandable-card | ForgeUI | Components | Free | no deps |
