Join our Discord Community

React Silk Background

React silk background with 3D rendering. Features flowing silk patterns, customizable wave distortion, and shader effects using React Three Fiber.

Building flowing fabric animations?

Join our Discord community for help from other developers working with 3D shaders and React Three Fiber.


Remember those hypnotic fabric simulations that made you stop and stare? The ones where silky patterns flow like liquid, creating mesmerizing waves that seem to breathe with life? Most backgrounds settle for static textures or simple gradients that feel flat and lifeless. This React component brings that fluid, organic motion to your interface with procedurally generated silk patterns that ripple and flow in real-time, creating depth and movement that feels genuinely luxurious and alive.

Flowing silk with wave distortion

Watch silky patterns flow and ripple with customizable wave physics and rotation:

Loading component...

Built for React applications with TypeScript and Next.js. Uses React Three Fiber and WebGL shaders for hardware-accelerated 3D rendering that maintains 60fps with complex wave calculations and noise functions. The procedural pattern generation creates infinite, seamless silk textures that never repeat. Perfect for luxury brands, fashion applications, or any interface that needs to feel premium and sophisticated. Seamless integration with shadcn/ui design systems.

Installation

npx shadcn@latest add https://www.shadcn.io/registry/silk-background.json
npx shadcn@latest add https://www.shadcn.io/registry/silk-background.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/silk-background.json
bunx shadcn@latest add https://www.shadcn.io/registry/silk-background.json

Why static textures feel cheap

Developers add a background image or simple gradient and call it elegant. Maybe they add a subtle CSS animation that moves a few pixels. The problem? Static textures don't convey the fluid, premium quality that silk represents. They don't create emotional connection or communicate luxury.

Flowing silk patterns change everything. They tap into our fascination with natural motion—the way fabric moves in wind, how liquid flows, the organic patterns that emerge from wave interference. The mathematical precision of sine waves and noise functions creates movement that feels both natural and sophisticated.

This component handles the complex 3D setup automatically. Shader uniforms, Three.js mesh scaling, animation loops, and viewport adaptation all work together seamlessly. The result feels like premium digital fabric, not a flat texture overlay.

Features

  • Procedural silk patterns generated in real-time using mathematical wave functions
  • 3D wave distortion with customizable amplitude and frequency for realistic fabric motion
  • Dynamic rotation allowing pattern orientation changes during animation
  • Color customization with hex color support and normalized RGB conversion
  • Noise integration for organic texture variation and film grain effects
  • Performance optimization with React Three Fiber's efficient rendering pipeline
  • Responsive scaling that adapts to viewport dimensions automatically
  • Hardware acceleration using WebGL shaders for smooth 60fps animation
  • TypeScript support with complete prop forwarding and type safety

API Reference

SilkBackground

PropTypeDefaultDescription
speednumber5Animation speed multiplier (0.1 to 20)
scalenumber1Pattern scale factor (0.1 to 5.0)
colorstring"#7B7481"Hex color for the silk pattern
noiseIntensitynumber1.5Random noise strength for texture variation
rotationnumber0Pattern rotation angle in radians
classNamestring-Additional CSS classes for the container
...propsHTMLAttributes<HTMLDivElement>-All standard div props supported

Wave Mathematics

The silk patterns use layered sine wave calculations:

Wave LayerFunctionPurposeVisual Effect
Primary Wavesin(8.0 * tex.x - tOffset)Base ripple motionHorizontal flow direction
Pattern Wavesin(5.0 * (tex.x + tex.y + cos(...)))Main fabric textureSilk-like interference patterns
Detail Wavesin(20.0 * (tex.x + tex.y - 0.1 * tOffset))Fine texture detailHigh-frequency silk grain
Noise Layerfract(r.x * r.y * (1.0 + texCoord.x))Organic variationNatural imperfections

Style Examples

// Luxury gold silk
<SilkBackground 
  color="#D4AF37"
  speed={2}
  scale={1.2}
  noiseIntensity={0.8}
/>

// Ocean wave effect
<SilkBackground 
  color="#1E40AF" 
  speed={4}
  scale={2.0}
  rotation={0.3}
/>

// Subtle texture overlay
<SilkBackground 
  color="#F3F4F6"
  speed={1}
  scale={0.8}
  noiseIntensity={0.5}
/>

// Fast-flowing animation
<SilkBackground 
  speed={10}
  rotation={1.57}
  scale={3.0}
  noiseIntensity={2.0}
/>

Shader implementation details

Vertex Shader: Handles 3D positioning and UV coordinate mapping. The vertex shader scales the mesh to match viewport dimensions and passes texture coordinates to the fragment shader for pattern calculation.

Fragment Shader: Contains the core silk pattern logic using multiple wave functions, rotation matrices, and noise calculations. The shader processes each pixel independently, creating smooth gradients and wave interference patterns.

Uniforms System: Real-time parameter updates flow from React props through Three.js uniforms to GPU shaders. This allows dynamic color changes, speed adjustments, and pattern modifications without recreating the entire shader program.

Color Space: Uses normalized RGB values (0-1) for shader compatibility, with automatic conversion from hex color codes to the appropriate format.

Performance considerations

3D Rendering: React Three Fiber manages WebGL context creation and animation loops efficiently. The component uses requestAnimationFrame for smooth 60fps rendering while automatically pausing when not visible.

Shader Complexity: The fragment shader performs multiple trigonometric calculations per pixel. On lower-end devices, consider reducing the scale parameter to decrease texture detail and improve performance.

Memory Management: Three.js geometry and materials are automatically disposed when the component unmounts, preventing memory leaks in single-page applications.

Device Pixel Ratio: The canvas automatically adapts to high-DPI displays with dpr={[1, 2]}, providing crisp visuals on retina screens while maintaining performance.

Common gotchas

Container Dimensions: The Three.js canvas fills its parent container completely. Ensure the parent has explicit dimensions or the silk pattern may not render at the expected size.

Color Format: Only hex colors are supported (#RRGGBB format). RGB, HSL, or named colors need to be converted to hex before passing to the component.

Animation Continuity: The wave patterns are time-based and deterministic. Changing props during animation maintains smooth transitions, but large parameter jumps may cause visual discontinuities.

Z-Index Layering: The canvas renders as a standard HTML element. Use CSS z-index for proper layering with other interface elements, and consider mix-blend-mode for text overlays.

Three.js Context: Each component instance creates its own WebGL context. Multiple instances on the same page work fine, but be mindful of GPU resource usage on devices with limited graphics capabilities.

You might also like

Questions developers actually ask