π Prismatic Haze Background
Step into a world of dreamy, shifting colors with Prismatic Haze, a React animation effect that blends cosmic swirls, neon hues, and soft grain textures to create an immersive, hypnotic ambiance. β¨π This dynamic, iridescent mist flows like a living nebula, making it perfect for futuristic UIs, music visualizers, landing pages, and eye-catching web designs. Whether youβre aiming for a trippy, cyberpunk-inspired aesthetic or a soft, atmospheric glow, Prismatic Haze adds that effortlessly cool, next-gen vibe to your project. ππ«
Preview
Prismatic Haze Background
Follow below steps ππ»
Install dependencies
1npm i @react-three/fiber @react-three/drei three
Component
Create a file prismatic-haze.tsx in your components folder and paste this code
1import React, { JSX, useRef } from 'react';2import { Canvas, useFrame, extend } from '@react-three/fiber';3import { shaderMaterial } from '@react-three/drei';45const IridescentShaderMaterial = shaderMaterial(6{ uTime: 0 },7`8varying vec2 vUv;9void main() {10vUv = uv;11// Standard vertex transformation12gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);13}14`,15`16precision mediump float;1718varying vec2 vUv;19uniform float uTime;2021// Pseudo-random function based on a 2D input22float random (in vec2 st) {23return fract(sin(dot(st.xy, vec2(12.9898,78.233))) * 43758.5453123);24}2526// Simple 2D noise function using smooth interpolation27float noise (in vec2 st) {28vec2 i = floor(st);29vec2 f = fract(st);3031float a = random(i);32float b = random(i + vec2(1.0, 0.0));33float c = random(i + vec2(0.0, 1.0));34float d = random(i + vec2(1.0, 1.0));3536vec2 u = f * f * (3.0 - 2.0 * f);3738return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;39}4041// Function for generating an iridescent color effect with noise.42vec3 iridescentColor(vec2 uv, float time) {43// Offset the UV coordinates over time for movement.44uv.x += 0.1 * sin(time * 0.5);45uv.y += 0.1 * cos(time * 0.5);4647// Blend sinusoidal waves in different color channels.48float r = 0.5 + 0.5 * sin(uv.x * 6.0 + time);49float g = 0.5 + 0.5 * sin(uv.y * 6.0 + time + 2.0);50float b = 0.5 + 0.5 * sin((uv.x + uv.y) * 6.0 + time + 4.0);5152// Generate a noise value for organic variation.53float n = noise(uv * 10.0 + time);5455// Add a subtle noise offset to each channel.56r += 0.1 * n;57g += 0.1 * n;58b += 0.1 * n;5960return vec3(r, g, b);61}6263void main() {64// Center the UV coordinates for symmetrical effects.65vec2 centeredUV = vUv * 2.0 - 1.0;66float time = uTime * 0.5; // Slow down the time factor.6768// Get the fluid iridescent color.69vec3 color = iridescentColor(centeredUV, time);7071// Add a grain effect based on the fragment coordinates.72float grain = fract(sin(dot(gl_FragCoord.xy, vec2(12.9898, 78.233))) * 43758.5453123);73// Center and scale the grain: adjust 0.2 to increase/decrease intensity.74grain = (grain - 0.5) * 0.2;7576// Add the grain to the final color.77color += vec3(grain);7879gl_FragColor = vec4(color, 1.0);80}81`82);8384extend({ IridescentShaderMaterial });8586declare module '@react-three/fiber' {87interface ThreeElements {88iridescentShaderMaterial: JSX.IntrinsicElements['shaderMaterial'];89}90}9192function PrismaticHazePlane() {93const materialRef = useRef<any>(null);9495useFrame(({ clock }) => {96if (materialRef.current) {97materialRef.current.uTime = clock.getElapsedTime();98}99});100101return (102<mesh scale={[2, 2, 1]}>103<planeGeometry args={[1, 1, 32, 32]} />104<iridescentShaderMaterial ref={materialRef} />105</mesh>106);107}108109type PrismaticHazeBackgroundProps = {110children?: React.ReactNode;111className?: string;112};113114const PrismaticHazeBackground = ({ children, className }: PrismaticHazeBackgroundProps) => {115return (116<div className="relative w-full h-full">117<Canvas className="w-full h-full" camera={{ position: [0, 0, 1], fov: 40 }}>118<PrismaticHazePlane />119</Canvas>120121<div className={`absolute inset-0 ${className}`}>{children}</div>122</div>123);124};125126export default PrismaticHazeBackground;
Usage
1<PrismaticHazeBackground className="flex items-center justify-center">2<p className="text-black font-extrabold text-5xl">Prismatic Haze Background</p>3</PrismaticHazeBackground>
βοΈ Got a question or feedback?
Feel free to reach out!