Mouse Wave Shader
An interactive and customizable component that creates a dynamic wave effect responding to mouse movements, perfect for immersive backgrounds.
Installation
Usage
import dynamic from "next/dynamic";
const MouseWaveScene = dynamic(
() => import("@/components/ui/mouse-wave-scene"),
{
ssr: false,
loading: () => (
<div className="h-full w-full bg-zinc-100 dark:bg-neutral-950">
{/* Skeleton loader */}
</div>
),
},
);
<div className="w-full max-w-[620px] h-auto">
<MouseWaveScene imageSrc="/images/shaders/forest-image.webp" />
</div>
You can use a placeholder while loading, to avoid potential issues, consider using dynamic imports.
The component is designed to automatically adjust based on the parent's width while maintaining the original image's aspect ratio. The height is always calculated dynamically.
By default, the shader is automatically disabled on mobile and replaced with a static image.
Props
mouse-wave-scene props.
Prop | Type | Default | Description |
---|---|---|---|
imageSrc | string | (required) | The source URL of the image used in the shader. |
alt | string | undefined | Alternative text for the image (used when the fallback <img> is displayed on mobile). |
marginFactor | number | 1.05 | Factor applied to the camera distance to ensure the shader is fully visible. Adjust this if parts of the shader are cut off. |
Credits
Resources
Here are some of the key resources that helped me learn about shaders. If you're interested in exploring shaders further, these are great places to start!
The Book Of Shaders
Version Requirements
If you are using Next.js 14 or earlier, install these packages instead: @react-three/[email protected] @react-three/[email protected] gsap
Changelog
2025-04-27
- Fixed a critical THREE.WebGLRenderer: Context Lost error occurring on Next.js 15 projects.
- Improved WebGL context handling for better stability across modern browsers.
- Adjusted recommended package versions to ensure compatibility with Next.js 14.
- Updated installation instructions to clearly differentiate requirements between Next.js 14 and 15 environments.