React Random Grid Subdivision
Fractal-like polygonal patterns with CSG operations on randomly subdivided grids. Pure WebGL grid subdivision for React with TypeScript and shadcn/ui—fractal complexity meets performance.
Building fractal grid effects?
Join our Discord community for help from other developers working with WebGL shaders.
Creating convincing fractal-like subdivision patterns requires sophisticated mathematical operations and careful balance between randomness and structure. This React component uses CSG operations on variable frequency grids with random rotation and offset to produce complex polygonal patterns reminiscent of subdivided Voronoi cells, all running smoothly at 60fps.
Fractal subdivision patterns
Beautiful random grid subdivision with CSG operations and procedural coloring:
Created by Shane in 2022-05-25
Built for React applications with TypeScript and Next.js in mind. The animation runs entirely on the GPU using WebGL with CSG operations, hexagonal/square grid mathematics, and sophisticated random subdivision algorithms. Works seamlessly with shadcn/ui design systems.
Installation
npx shadcn@latest add https://www.shadcn.io/registry/random-grid-subdivision-shaders.json
npx shadcn@latest add https://www.shadcn.io/registry/random-grid-subdivision-shaders.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/random-grid-subdivision-shaders.json
bunx shadcn@latest add https://www.shadcn.io/registry/random-grid-subdivision-shaders.json
Usage
import { RandomGridSubdivisionShaders } from "@/components/ui/random-grid-subdivision-shaders";
export default function Hero() {
return (
<RandomGridSubdivisionShaders>
<div className="relative z-10">
<h1>Your content here</h1>
</div>
</RandomGridSubdivisionShaders>
);
}
Why most subdivision implementations fail
Most developers try to create subdivision patterns using simple recursive algorithms or pre-computed textures. Poor approach. You miss the mathematical complexity of CSG operations and the organic randomness that makes patterns truly fractal-like. Basic implementations often produce regular, predictable results that lack the natural variation found in real subdivision processes.
This React component uses authentic CSG operations with variable frequency grids, random rotation matrices, and probabilistic subdivision termination. The GPU handles everything using optimized hexagonal/square grid mathematics with procedural coloring and directional lighting. No pre-computed patterns, no regular artifacts, just pure mathematical subdivision at 60fps.
Features
- Zero pre-computation - Pure mathematical CSG operations with real-time grid subdivision
- Dual grid systems supporting both hexagonal and square grid subdivision patterns
- Random subdivision control with probabilistic termination for organic fractal-like complexity
- CSG operation chains using variable frequency grids with rotation and offset transformations
- TypeScript definitions for proper IDE support in React projects
- Customizable parameters with 6 props for complete subdivision control
- Performance optimization through efficient GPU-based grid mathematics
- shadcn/ui compatible for consistent design systems
- Responsive design with automatic canvas resizing and resolution independence
API Reference
RandomGridSubdivisionShaders
Main container component for the random grid subdivision effect.
Prop | Type | Default | Description |
---|---|---|---|
speed | number | 1.0 | Animation speed multiplier (0.1 to 3.0) |
scale | number | 1.0 | Grid scale factor (0.5 to 3.0) |
useHexagon | number | 1 | Grid type (0: Square, 1: Hexagon) |
randomSubdivision | number | 1 | Random subdivision (0: Off, 1: On) |
thickBorder | number | 0 | Border thickness (0: Thin, 1: Thick) |
colorVariation | number | 1.0 | Color variation intensity (0.0 to 3.0) |
className | string | - | Additional Tailwind CSS classes |
...props | HTMLAttributes<HTMLDivElement> | - | All standard div props |
Common gotchas
Pattern appears too regular: Enable randomSubdivision
to introduce probabilistic termination that creates more organic, fractal-like subdivision patterns instead of uniform recursive division.
Performance issues on mobile: CSG operations and multiple grid iterations are GPU-intensive. Reduce scale
and consider limiting subdivision depth for better mobile performance.
Grid type differences: Hexagonal grids (useHexagon=1
) create more organic patterns but require more complex mathematics. Square grids (useHexagon=0
) are faster but more geometric.
Animation too fast/slow: The speed
parameter affects both grid movement and rotation. Lower values create more contemplative, slowly evolving patterns.
Colors too similar: Increase colorVariation
to enhance the procedural coloring differences between subdivision cells. Higher values create more dramatic color contrasts.
You might also like
Explore other shader-based background components for React applications:
Pyramid Pattern
Animated pyramid patterns with bump mapping and noise-driven offsets
2D Noise Contours
Smooth fractal contour lines with numerical gradients
Mandelbrot Patterns
Decorated Mandelbrot fractal with complex pattern overlays
3-Tap Voronoi Shaders
Ultra-fast 3-tap Voronoi with simplex grid and highlights
Cellular Tiled Tunnel
Raymarched 2nd-order Voronoi tunnel with 3D cellular tiling
Smooth Voronoi Contours
Voronoi cellular patterns with smooth contour lines
Questions developers actually ask
React Pyramid Pattern
Animated pyramid patterns with bump mapping and noise-driven offset tips. Pure WebGL geometric patterns for React with TypeScript and shadcn/ui—dimensional texture meets performance.
React Raymarching Shaders
Hypnotic 3D raymarching effects with ACES tonemapping and dot noise. Pure WebGL shaders for React with TypeScript and shadcn/ui—smooth GPU animations.