Join our Discord Community

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.

Powered by

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:

Loading component...

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.

PropTypeDefaultDescription
speednumber1.0Animation speed multiplier (0.1 to 3.0)
scalenumber1.0Grid scale factor (0.5 to 3.0)
useHexagonnumber1Grid type (0: Square, 1: Hexagon)
randomSubdivisionnumber1Random subdivision (0: Off, 1: On)
thickBordernumber0Border thickness (0: Thin, 1: Thick)
colorVariationnumber1.0Color variation intensity (0.0 to 3.0)
classNamestring-Additional Tailwind CSS classes
...propsHTMLAttributes<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:

Questions developers actually ask