feat: initial commit for Paralax creative engineering system
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
# Creative Direction & Art Direction Guide
|
||||
|
||||
> **Purpose:** Transform abstract project briefs into unmistakable, memorable visual languages. Avoid the sterile, generic "modern SaaS" aesthetic by grounding choices in sensory, cultural, and mechanical archetypes.
|
||||
|
||||
---
|
||||
|
||||
## 🎭 1. Creative Theme Taxonomy & Archetypes
|
||||
|
||||
When starting a project, classify it into one of these archetypes (or forge an intentional hybrid). Never let an AI prompt settle on "clean, modern, minimalist":
|
||||
|
||||
### Archetype A: Mechanical Velocity & Industrial Precision
|
||||
- **Industries:** Motorcycles, automotive, hyper-engineering, aerospace, heavy tech, performance gear.
|
||||
- **Sensory Palette:** Carbon fiber, raw titanium, forged steel, matte obsidian, asphalt darks (`#0B0C0E`), punctuated by high-visibility accents (surgical tachometer orange `#FF3D00` or electric acid lime `#D4FF00`).
|
||||
- **Typography:** Technical monospaced data markers (*Space Mono*, *JetBrains Mono*) juxtaposed against wide, high-impact industrial grotesques (*Monument Extended*, *Druk Wide*, *PP Neue Montreal*).
|
||||
- **Motion Character:** Instantaneous acceleration, mechanical snapping, zero-damping technical pivots, telemetry overlays, split-second camera pans.
|
||||
- **Visual Devices:** Technical wireframes, coordinate readouts, exploded component views, high-contrast monochrome studio photography with rim lighting.
|
||||
|
||||
### Archetype B: Quiet Luxury & High Editorial
|
||||
- **Industries:** Haute couture, architectural residences, fine horology, bespoke fragrances, Michelin dining.
|
||||
- **Sensory Palette:** Textured alabaster (`#F7F5F0`), deep warm bronze (`#2A2421`), slate stone, velvet midnight, muted champagne gold accents (`#C5A880`).
|
||||
- **Typography:** High-contrast display serifs (*Canela*, *Ogg*, *Italiana*, *PPEiko*) paired with quiet, spacious geometric sans-serifs (*Neue Haas Grotesk*, *Geist*, *Inter Tight*).
|
||||
- **Motion Character:** Cinematic weight, high-friction liquid damping, deliberate slow reveals, soft scale-down entrances, gentle cross-fades.
|
||||
- **Visual Devices:** Asymmetrical negative space (40%+ intentional emptiness), editorial crop ratios (4:5, 16:9 cinematic), smooth blur backdrops, subtle image masking.
|
||||
|
||||
### Archetype C: Cybernetic & Neo-Brutalist Digital
|
||||
- **Industries:** Web3, developer tooling, security research, cutting-edge AI engines, underground music festivals.
|
||||
- **Sensory Palette:** Terminal black (`#050505`), deep phosphor green, ultraviolet violet, electric cyan, harsh 1px borders (`rgba(255, 255, 255, 0.12)`).
|
||||
- **Typography:** Pixel/bitmap fonts, brutalist sans (*Clash Display*, *Syne*, *Cabinet Grotesk*), monospaced headers.
|
||||
- **Motion Character:** Glitch distortions, magnetic hover pulls, raw matrix cascades, scanline wipes, CRT phosphor glow effects.
|
||||
- **Visual Devices:** Visible 1px grid lines, raw JSON/code inspector callouts, custom ASCII accents, interactive magnetic cursor badges.
|
||||
|
||||
### Archetype D: Organic Bio-Atmosphere & Earth Architecture
|
||||
- **Industries:** Sustainable architecture, regenerative agriculture, mindfulness wellness, botanical spirits, outdoor exploration.
|
||||
- **Sensory Palette:** Terra cotta, moss forest green (`#1B2E23`), clay ochre, misty sage (`#8A9A86`), soft linen background (`#EFECE6`).
|
||||
- **Typography:** Organic humanist serifs (*Recurso*, *Fraunces*) combined with soft humanist sans (*Plus Jakarta Sans*, *General Sans*).
|
||||
- **Motion Character:** Gentle organic waves, inertia scrolling, breathing element pulses, soft displacement ripples.
|
||||
- **Visual Devices:** Curvature masks, grain texture overlays, generative particle fields, fluid SVG path morphing.
|
||||
|
||||
---
|
||||
|
||||
## 📐 2. Compositional Rules: Escaping the Card Grid Trap
|
||||
|
||||
Standard AI designs default to:
|
||||
1. Centered headline + subtitle + 2 buttons.
|
||||
2. 3 identical cards in a row.
|
||||
3. 2-column alternating text/image sections.
|
||||
|
||||
### Break the Pattern with These 5 Layout Techniques:
|
||||
|
||||
```
|
||||
1. The Off-Center Horizon:
|
||||
+------------------------------------------+
|
||||
| [TINY EYEBROW] |
|
||||
| MASSIVE HEADLINE ACROSS 8 COLS |
|
||||
| BLEEDING OFF THE RIGHT EDGE |
|
||||
| |
|
||||
| [HERO MEDIA: 5 COLS] |
|
||||
| [NARRATIVE TEXT] [FLOATING STAT] |
|
||||
+------------------------------------------+
|
||||
|
||||
2. Layered Depth & Overlap:
|
||||
+------------------------------------------+
|
||||
| +--------------------+ |
|
||||
| | LAYER 1: BACKDROP | |
|
||||
| +-------| (Slow Parallax) | |
|
||||
| | LAYER 2: FOREGROUND | |
|
||||
| | (High Contrast Text) +------+ |
|
||||
| +-------+ | |
|
||||
| | LAYER 3: FLOATING BADGE | |
|
||||
| +---------------------------+ |
|
||||
+------------------------------------------+
|
||||
|
||||
3. Full Bleed Cinematic Frame:
|
||||
+------------------------------------------+
|
||||
| [NAV: MINIMAL 4-CORNER ANCHORS] |
|
||||
| |
|
||||
| [CINEMATIC CANVAS |
|
||||
| OR 3D SCENE] |
|
||||
| |
|
||||
| [SCROLL CUE: 01 // 04] [AUDIO TOGGLE] |
|
||||
+------------------------------------------+
|
||||
```
|
||||
|
||||
1. **4-Corner Navigation Anchors**: Place brand top-left, status/time top-right, audio/theme bottom-left, scroll index bottom-right. Free up the entire center viewport for the narrative canvas.
|
||||
2. **Typographic Bleed**: Let oversized editorial display typography (e.g. `clamp(4rem, 12vw, 16rem)`) push across columns or slightly bleed beyond the viewport boundary with a reveal mask.
|
||||
3. **Multi-Plane Overlap**: Ensure elements occupy intersecting z-planes. An image card should partially overlap an oversized typography headline, with a floating technical spec box offset across both.
|
||||
4. **Intentional Asymmetry**: If column 1 spans 7 columns of a 12-column grid, column 2 should span 3 columns with 2 columns of pure negative space to give the eye a resting harbor.
|
||||
|
||||
---
|
||||
|
||||
## 🎨 3. Sensory Palette Formulation
|
||||
|
||||
A world-class creative palette requires strict role discipline:
|
||||
|
||||
```css
|
||||
:root {
|
||||
/* 1. Spatial Background (Never pure #000 or #FFF) */
|
||||
--bg-primary: #0a0b0d;
|
||||
--bg-elevated: #121418;
|
||||
--bg-glass: rgba(18, 20, 24, 0.7);
|
||||
|
||||
/* 2. Textual Hierarchy (Opacity-driven) */
|
||||
--text-primary: rgba(255, 255, 255, 0.95);
|
||||
--text-secondary: rgba(255, 255, 255, 0.65);
|
||||
--text-tertiary: rgba(255, 255, 255, 0.35);
|
||||
|
||||
/* 3. Surgical Accent (Use on < 5% of viewport area) */
|
||||
--accent-kinetic: #ff3e00; /* High energy ignition */
|
||||
--accent-glow: rgba(255, 62, 0, 0.25);
|
||||
|
||||
/* 4. Structural Dividers */
|
||||
--border-subtle: rgba(255, 255, 255, 0.08);
|
||||
--border-highlight: rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,279 @@
|
||||
# GSAP & ScrollTrigger Engineering Recipes
|
||||
|
||||
> **Engine:** GSAP 3.x with ScrollTrigger & `@gsap/react` (useGSAP hook).
|
||||
> **Target Framework:** React 18/19 & Next.js 14/15 (App Router).
|
||||
> **Language:** TypeScript.
|
||||
|
||||
---
|
||||
|
||||
## ⚡ 1. The Gold Standard React Lifecycle (`useGSAP`)
|
||||
|
||||
Never run raw `gsap.to()` in a basic `useEffect` without cleanup. In React 18+ (especially with StrictMode double-mounting), uncleaned ScrollTrigger instances leak memory and cause visual duplication.
|
||||
|
||||
### Recommended Setup:
|
||||
```bash
|
||||
npm install gsap @gsap/react
|
||||
```
|
||||
|
||||
### Safe Component Scaffolding:
|
||||
```tsx
|
||||
'use client';
|
||||
|
||||
import React, { useRef } from 'react';
|
||||
import gsap from 'gsap';
|
||||
import { ScrollTrigger } from 'gsap/ScrollTrigger';
|
||||
import { useGSAP } from '@gsap/react';
|
||||
|
||||
// Register plugins once outside render
|
||||
if (typeof window !== 'undefined') {
|
||||
gsap.registerPlugin(ScrollTrigger, useGSAP);
|
||||
}
|
||||
|
||||
export const CreativeScene: React.FC = () => {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useGSAP(
|
||||
() => {
|
||||
// All selectors inside this hook are automatically scoped to containerRef!
|
||||
const tl = gsap.timeline({
|
||||
scrollTrigger: {
|
||||
trigger: containerRef.current,
|
||||
start: 'top top',
|
||||
end: '+=200%',
|
||||
pin: true,
|
||||
scrub: 1, // 1-second organic smoothing
|
||||
anticipatePin: 1,
|
||||
invalidateOnRefresh: true, // Recalculate on screen resize
|
||||
},
|
||||
});
|
||||
|
||||
tl.from('.narrative-headline', {
|
||||
yPercent: 100,
|
||||
opacity: 0,
|
||||
ease: 'power3.out',
|
||||
})
|
||||
.to('.hero-image', {
|
||||
scale: 1.2,
|
||||
clipPath: 'polygon(0% 0%, 100% 0%, 100% 100%, 0% 100%)',
|
||||
ease: 'power2.inOut',
|
||||
}, '<') // Run concurrently with headline
|
||||
.to('.narrative-headline', {
|
||||
yPercent: -100,
|
||||
opacity: 0,
|
||||
ease: 'power2.in',
|
||||
}, '+=0.5');
|
||||
},
|
||||
{ scope: containerRef } // Crucial: automatic cleanup on unmount!
|
||||
);
|
||||
|
||||
return (
|
||||
<section ref={containerRef} className="relative h-screen w-full overflow-hidden bg-neutral-950 text-white">
|
||||
<div className="hero-image absolute inset-0 z-0 scale-100 bg-cover bg-center" style={{ backgroundImage: "url('/hero.jpg')", clipPath: 'polygon(15% 15%, 85% 15%, 85% 85%, 15% 85%)' }} />
|
||||
<div className="relative z-10 flex h-full items-center justify-center">
|
||||
<h1 className="narrative-headline text-7xl font-bold tracking-tighter">ENGINEERED ELEGANCE</h1>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🚂 2. Horizontal Storytelling Track (Pinned Viewport)
|
||||
|
||||
A horizontal gallery that converts vertical page scroll into smooth sideways translation:
|
||||
|
||||
```tsx
|
||||
'use client';
|
||||
|
||||
import React, { useRef } from 'react';
|
||||
import gsap from 'gsap';
|
||||
import { ScrollTrigger } from 'gsap/ScrollTrigger';
|
||||
import { useGSAP } from '@gsap/react';
|
||||
|
||||
export const HorizontalNarrative: React.FC = () => {
|
||||
const targetRef = useRef<HTMLDivElement>(null);
|
||||
const trackRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useGSAP(
|
||||
() => {
|
||||
const track = trackRef.current;
|
||||
if (!track) return;
|
||||
|
||||
// Calculate total horizontal scroll distance
|
||||
const getScrollAmount = () => -(track.scrollWidth - window.innerWidth);
|
||||
|
||||
gsap.to(track, {
|
||||
x: getScrollAmount,
|
||||
ease: 'none', // Strict linear scrubbing tied to scrollbar
|
||||
scrollTrigger: {
|
||||
trigger: targetRef.current,
|
||||
start: 'top top',
|
||||
end: () => `+=${track.scrollWidth - window.innerWidth}`,
|
||||
pin: true,
|
||||
scrub: 0.8,
|
||||
invalidateOnRefresh: true,
|
||||
},
|
||||
});
|
||||
},
|
||||
{ scope: targetRef }
|
||||
);
|
||||
|
||||
return (
|
||||
<div ref={targetRef} className="relative h-screen w-full overflow-hidden bg-neutral-900">
|
||||
<div ref={trackRef} className="flex h-full w-fit items-center gap-12 px-16">
|
||||
{[1, 2, 3, 4, 5].map((index) => (
|
||||
<div
|
||||
key={index}
|
||||
className="flex h-[70vh] w-[60vw] md:w-[40vw] flex-shrink-0 flex-col justify-end rounded-2xl bg-neutral-800 p-8 text-white border border-neutral-700/50"
|
||||
>
|
||||
<span className="text-sm font-mono text-neutral-400">PHASE 0{index}</span>
|
||||
<h2 className="text-4xl font-semibold mt-2">Cinematic Dimension {index}</h2>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ✂️ 3. Editorial `clip-path` Curtain Reveal
|
||||
|
||||
A cinematic transition where an image or video expands from a small geometric window into full bleed as the user scrolls into it:
|
||||
|
||||
```tsx
|
||||
'use client';
|
||||
|
||||
import React, { useRef } from 'react';
|
||||
import gsap from 'gsap';
|
||||
import { ScrollTrigger } from 'gsap/ScrollTrigger';
|
||||
import { useGSAP } from '@gsap/react';
|
||||
|
||||
export const CurtainExpand: React.FC = () => {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useGSAP(
|
||||
() => {
|
||||
gsap.fromTo(
|
||||
'.curtain-media',
|
||||
{
|
||||
clipPath: 'inset(25% 30% 25% 30% round 32px)',
|
||||
scale: 1.15,
|
||||
},
|
||||
{
|
||||
clipPath: 'inset(0% 0% 0% 0% round 0px)',
|
||||
scale: 1.0,
|
||||
ease: 'power2.inOut',
|
||||
scrollTrigger: {
|
||||
trigger: containerRef.current,
|
||||
start: 'top bottom',
|
||||
end: 'center center',
|
||||
scrub: 1.2,
|
||||
},
|
||||
}
|
||||
);
|
||||
},
|
||||
{ scope: containerRef }
|
||||
);
|
||||
|
||||
return (
|
||||
<section ref={containerRef} className="relative min-h-[140vh] w-full bg-black py-24">
|
||||
<div className="curtain-media sticky top-0 h-screen w-full overflow-hidden will-change-[clip-path]">
|
||||
<img
|
||||
src="/cinematic-backdrop.jpg"
|
||||
alt="Curtain reveal"
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔤 4. Staggered Kinetic Typography (Characters & Words)
|
||||
|
||||
Splitting text and revealing each glyph with a subtle rotation and opacity wave:
|
||||
|
||||
```tsx
|
||||
'use client';
|
||||
|
||||
import React, { useRef } from 'react';
|
||||
import gsap from 'gsap';
|
||||
import { useGSAP } from '@gsap/react';
|
||||
|
||||
export const KineticTitle: React.FC<{ text: string }> = ({ text }) => {
|
||||
const textRef = useRef<HTMLHeadingElement>(null);
|
||||
|
||||
useGSAP(
|
||||
() => {
|
||||
const letters = textRef.current?.querySelectorAll('.char');
|
||||
if (!letters || letters.length === 0) return;
|
||||
|
||||
gsap.from(letters, {
|
||||
yPercent: 120,
|
||||
rotateX: -45,
|
||||
opacity: 0,
|
||||
stagger: 0.02,
|
||||
duration: 0.9,
|
||||
ease: 'power3.out',
|
||||
scrollTrigger: {
|
||||
trigger: textRef.current,
|
||||
start: 'top 85%',
|
||||
},
|
||||
});
|
||||
},
|
||||
{ scope: textRef }
|
||||
);
|
||||
|
||||
return (
|
||||
<h2
|
||||
ref={textRef}
|
||||
className="overflow-hidden text-6xl md:text-8xl font-black uppercase tracking-tight [perspective:1000px]"
|
||||
>
|
||||
{text.split('').map((char, i) => (
|
||||
<span
|
||||
key={i}
|
||||
className="char inline-block will-change-transform will-change-opacity"
|
||||
>
|
||||
{char === ' ' ? '\u00A0' : char}
|
||||
</span>
|
||||
))}
|
||||
</h2>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🏎️ 5. Smooth Scroll Synergy (Lenis + ScrollTrigger)
|
||||
|
||||
When using modern smooth scroll libraries like [Lenis](https://github.com/darkroomengineering/lenis), you must synchronize Lenis's ticker with GSAP's ticker:
|
||||
|
||||
```tsx
|
||||
import Lenis from 'lenis';
|
||||
import gsap from 'gsap';
|
||||
import { ScrollTrigger } from 'gsap/ScrollTrigger';
|
||||
|
||||
export function setupSmoothScroll() {
|
||||
const lenis = new Lenis({
|
||||
duration: 1.2,
|
||||
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
|
||||
smoothWheel: true,
|
||||
});
|
||||
|
||||
// Synchronize Lenis scroll with ScrollTrigger
|
||||
lenis.on('scroll', ScrollTrigger.update);
|
||||
|
||||
gsap.ticker.add((time) => {
|
||||
lenis.raf(time * 1000);
|
||||
});
|
||||
|
||||
gsap.ticker.lagSmoothing(0);
|
||||
|
||||
return lenis;
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,170 @@
|
||||
# Interactive 3D & WebGL Engineering Guide
|
||||
|
||||
> **Core Libraries:** Three.js, `@react-three/fiber` (R3F), `@react-three/drei`.
|
||||
> **Philosophy:** Progressive enhancement. 3D must serve the narrative, not burden the hardware.
|
||||
|
||||
---
|
||||
|
||||
## 🎯 1. The Dimensional Decision Matrix
|
||||
|
||||
Before adding 3D dependencies (`three` ~150KB gzip), evaluate where the experience belongs on the dimensional spectrum:
|
||||
|
||||
```
|
||||
[Tier 1: CSS 3D] ------> [Tier 2: 2D Canvas] ------> [Tier 3: Three.js/R3F]
|
||||
perspective: 1200px Fluid particles, Real 3D models,
|
||||
transform: rotateX/Y interactive grid trails, custom GLSL shaders,
|
||||
Sub-pixel GPU compositing image displacement dynamic PBR lighting
|
||||
Cost: ~0KB Cost: ~3KB Cost: ~150KB+
|
||||
```
|
||||
|
||||
| Project Need | Optimal Technology | Why |
|
||||
| :--- | :--- | :--- |
|
||||
| Floating cards tilting to cursor | **CSS 3D Transforms** (`perspective`, `rotateX/Y`) | Native browser compositing, 0KB runtime overhead. |
|
||||
| Background interactive constellation / fluid particles | **HTML5 2D Canvas** | Direct draw calls, lightweight, full 60fps on mobile. |
|
||||
| Interactive vehicle, watch, product inspectable model | **React Three Fiber (R3F) + Drei** | Declarative scene graph, PBR lighting, GLTF compression. |
|
||||
| Cinematic full-screen liquid distortion or image wave | **Three.js Custom ShaderMaterial (GLSL)** | Fragment shader execution directly on GPU cores. |
|
||||
|
||||
---
|
||||
|
||||
## 🚀 2. Production React Three Fiber (R3F) Boilerplate
|
||||
|
||||
### Installation:
|
||||
```bash
|
||||
npm install three @types/three @react-three/fiber @react-three/drei
|
||||
```
|
||||
|
||||
### High-Performance Canvas Component:
|
||||
```tsx
|
||||
'use client';
|
||||
|
||||
import React, { Suspense, useRef } from 'react';
|
||||
import { Canvas, useFrame } from '@react-three/fiber';
|
||||
import { Float, Environment, ContactShadows, useGLTF } from '@react-three/drei';
|
||||
import * as THREE from 'three';
|
||||
|
||||
// 1. Model Component with GLTF pre-loading
|
||||
function ArtifactModel({ pointer }: { pointer: React.MutableRefObject<[number, number]> }) {
|
||||
const meshRef = useRef<THREE.Group>(null);
|
||||
// Replace with real GLTF model or geometry
|
||||
// const { scene } = useGLTF('/models/artifact.glb');
|
||||
|
||||
useFrame((state, delta) => {
|
||||
if (!meshRef.current) return;
|
||||
|
||||
// Organic continuous floating rotation
|
||||
meshRef.current.rotation.y += delta * 0.2;
|
||||
|
||||
// Smooth Lerp toward cursor position
|
||||
const targetX = (pointer.current[0] * Math.PI) / 8;
|
||||
const targetY = (pointer.current[1] * Math.PI) / 8;
|
||||
|
||||
meshRef.current.rotation.x = THREE.MathUtils.lerp(meshRef.current.rotation.x, targetY, 0.05);
|
||||
meshRef.current.rotation.z = THREE.MathUtils.lerp(meshRef.current.rotation.z, -targetX, 0.05);
|
||||
});
|
||||
|
||||
return (
|
||||
<group ref={meshRef}>
|
||||
<Float speed={2} rotationIntensity={0.5} floatIntensity={1}>
|
||||
<mesh castShadow receiveShadow>
|
||||
<torusKnotGeometry args={[1, 0.3, 128, 32]} />
|
||||
<meshStandardMaterial
|
||||
color="#FF3E00"
|
||||
roughness={0.15}
|
||||
metalness={0.85}
|
||||
clearcoat={1}
|
||||
clearcoatRoughness={0.1}
|
||||
/>
|
||||
</mesh>
|
||||
</Float>
|
||||
</group>
|
||||
);
|
||||
}
|
||||
|
||||
// 2. Main Stage with Hardware-Conscious Settings
|
||||
export const Interactive3DStage: React.FC = () => {
|
||||
const pointerPos = useRef<[number, number]>([0, 0]);
|
||||
|
||||
const handlePointerMove = (e: React.PointerEvent) => {
|
||||
// Normalize coordinates from -1 to 1
|
||||
pointerPos.current = [
|
||||
(e.clientX / window.innerWidth) * 2 - 1,
|
||||
-(e.clientY / window.innerHeight) * 2 + 1,
|
||||
];
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
onPointerMove={handlePointerMove}
|
||||
className="relative h-screen w-full bg-neutral-950"
|
||||
>
|
||||
<Canvas
|
||||
camera={{ position: [0, 0, 5], fov: 45 }}
|
||||
// STRICT PERFORMANCE GUARD: Cap device pixel ratio at 2.0 (never 3x or 4x on Retina)
|
||||
dpr={[1, Math.min(typeof window !== 'undefined' ? window.devicePixelRatio : 2, 2)]}
|
||||
gl={{
|
||||
antialias: true,
|
||||
powerPreference: 'high-performance',
|
||||
alpha: true,
|
||||
}}
|
||||
>
|
||||
<ambientLight intensity={0.4} />
|
||||
<directionalLight position={[10, 10, 5]} intensity={1.5} castShadow />
|
||||
<pointLight position={[-10, -10, -5]} color="#4F46E5" intensity={0.8} />
|
||||
|
||||
<Suspense fallback={null}>
|
||||
<ArtifactModel pointer={pointerPos} />
|
||||
<ContactShadows position={[0, -2, 0]} opacity={0.6} scale={10} blur={2.5} far={4} />
|
||||
<Environment preset="city" />
|
||||
</Suspense>
|
||||
</Canvas>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🌊 3. Liquid Image Wave Shader (Codrops-Tier Distortion)
|
||||
|
||||
To create organic liquid ripples across an image on hover or scroll, compile a custom `ShaderMaterial`:
|
||||
|
||||
### Vertex Shader:
|
||||
```glsl
|
||||
varying vec2 vUv;
|
||||
uniform float uTime;
|
||||
uniform vec2 uFrequency;
|
||||
|
||||
void main() {
|
||||
vUv = uv;
|
||||
vec3 newPosition = position;
|
||||
newPosition.z += sin(newPosition.x * uFrequency.x + uTime) * 0.1;
|
||||
newPosition.z += cos(newPosition.y * uFrequency.y + uTime) * 0.1;
|
||||
gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition, 1.0);
|
||||
}
|
||||
```
|
||||
|
||||
### Fragment Shader:
|
||||
```glsl
|
||||
uniform sampler2D uTexture;
|
||||
uniform float uProgress;
|
||||
varying vec2 vUv;
|
||||
|
||||
void main() {
|
||||
vec2 distortedUv = vUv;
|
||||
distortedUv.x += sin(vUv.y * 10.0 + uProgress * 3.14) * 0.03 * uProgress;
|
||||
vec4 color = texture2D(uTexture, distortedUv);
|
||||
gl_FragColor = color;
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🔋 4. GPU Conservation & Mobile Fallbacks
|
||||
|
||||
1. **Always Cap DPR**: High-DPI smartphones (iPhone Pro Max, Samsung Ultra) have physical pixel ratios of 3.0 or 4.0. Rendering a WebGL scene at 4x resolution requires rendering 16x as many pixels per frame, melting the GPU. Set:
|
||||
```ts
|
||||
dpr={[1, 2]} // Never higher than 2
|
||||
```
|
||||
2. **Dispose Geometries & Textures**: In vanilla Three.js, unmounted meshes must have their geometry, material, and textures explicitly disposed (`geometry.dispose()`, `material.dispose()`). R3F automatically disposes objects on unmount.
|
||||
3. **Turn Off Off-Screen Canvases**: Use `IntersectionObserver` to pause the render loop (`frameloop="never"`) when the 3D canvas scrolls out of the active viewport.
|
||||
4. **Mobile Fallback**: On low-end mobile devices, swap the 3D Canvas with a high-resolution WebP video loop (`<video autoPlay loop muted playsInline poster="...">`).
|
||||
@@ -0,0 +1,108 @@
|
||||
# Creative Performance & Accessibility Engineering
|
||||
|
||||
> **Goal:** Deliver breathtaking cinematic visuals while sustaining a rock-solid 60fps/120fps render loop and uncompromising WCAG AA accessibility.
|
||||
|
||||
---
|
||||
|
||||
## ⏱️ 1. The 16.6ms Frame Budget & The Critical Rendering Path
|
||||
|
||||
To sustain 60 frames per second, the browser has exactly **16.6 milliseconds** to execute all JavaScript, style calculations, layout geometry, painting, and GPU compositing. On modern 120Hz ProMotion displays, this budget shrinks to **8.3ms**.
|
||||
|
||||
```
|
||||
[ JavaScript / Ticker ] ──> [ Style Recalculation ] ──> [ Layout (Reflow) ] ──> [ Paint ] ──> [ Composite ]
|
||||
(GSAP / RAF) (CSS rules matched) (Geometry / Box) (Raster) (GPU Layers)
|
||||
```
|
||||
|
||||
### The Three Classes of CSS Properties:
|
||||
|
||||
| Pipeline Stage | Properties Animated | Performance Impact | Verdict for Creative Animation |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| **Layout (Reflow)** | `width`, `height`, `top`, `left`, `margin`, `padding`, `font-size` | **Catastrophic.** Forces browser to recalculate the geometry of the entire DOM tree on every scroll tick. | **STRICTLY FORBIDDEN** during scroll/motion. |
|
||||
| **Paint** | `color`, `background-color`, `border-color`, `box-shadow` | **Heavy.** Forces CPU rasterization of pixels before uploading textures to the GPU. | Acceptable for single state changes, avoid during continuous 60fps scrub. |
|
||||
| **Composite Only** | `transform` (`x`, `y`, `scale`, `rotate`), `opacity` | **Near Zero Overhead.** Handled directly on the GPU compositor thread without touching layout or paint. | **GOLD STANDARD.** 100% of continuous scroll animations must use these. |
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ 2. Layout Thrashing (Forced Synchronous Layout)
|
||||
|
||||
The most common cause of stutter in creative websites is **reading geometric layout values** immediately followed by **writing styles** in an unbatched loop.
|
||||
|
||||
```tsx
|
||||
// ❌ WRONG: Forces the browser to flush layout calculations repeatedly in a loop
|
||||
elements.forEach((el) => {
|
||||
const height = el.getBoundingClientRect().height; // READ (forces reflow)
|
||||
el.style.transform = `translateY(${height * 0.5}px)`; // WRITE (invalidates layout)
|
||||
});
|
||||
|
||||
// ✅ CORRECT: Batch all reads first, then execute all writes
|
||||
const heights = elements.map((el) => el.getBoundingClientRect().height); // All READS
|
||||
requestAnimationFrame(() => {
|
||||
elements.forEach((el, i) => {
|
||||
el.style.transform = `translateY(${heights[i] * 0.5}px)`; // All WRITES
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ♿ 3. Accessible Motion (`prefers-reduced-motion`)
|
||||
|
||||
Over 30% of users experience vestibular sensitivity, nausea, or visual vertigo from intense parallax, scaling, or sudden camera spins. **Every creative experience must provide an accessible, reduced-motion mode.**
|
||||
|
||||
### React / GSAP Implementation:
|
||||
```tsx
|
||||
import { useGSAP } from '@gsap/react';
|
||||
import gsap from 'gsap';
|
||||
import { ScrollTrigger } from 'gsap/ScrollTrigger';
|
||||
|
||||
export function useAccessibleTimeline(setupAnimation: (tl: gsap.core.Timeline) => void, scope: React.RefObject<any>) {
|
||||
useGSAP(
|
||||
() => {
|
||||
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
|
||||
if (prefersReducedMotion) {
|
||||
// Fallback: Reveal all elements with gentle opacity, no rapid movement or pinned scroll hijacking
|
||||
gsap.to(scope.current?.querySelectorAll('[data-motion-element]'), {
|
||||
opacity: 1,
|
||||
duration: 0.3,
|
||||
stagger: 0.05,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Full cinematic choreography for users without reduced motion preferences
|
||||
const tl = gsap.timeline();
|
||||
setupAnimation(tl);
|
||||
},
|
||||
{ scope }
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
### CSS Guardrail:
|
||||
```css
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
animation-duration: 0.01ms !important;
|
||||
animation-iteration-count: 1 !important;
|
||||
transition-duration: 0.01ms !important;
|
||||
scroll-behavior: auto !important;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 👁️ 4. Keyboard Navigation & Focus in Cinematic Layouts
|
||||
|
||||
Creative websites frequently hide or style native scrollbars, use custom canvas cursors, or pin views. You must ensure:
|
||||
1. **Focusable Elements Remain Visible**: Never remove `:focus-visible` outlines without providing a customized high-contrast focus ring (`outline: 2px solid var(--accent-kinetic)`).
|
||||
2. **Skip Links**: Include an accessible skip link at the top of the DOM:
|
||||
```html
|
||||
<a href="#main-content" class="sr-only focus:not-sr-only focus:fixed focus:top-4 focus:left-4 z-50 bg-black text-white px-4 py-2 rounded">
|
||||
Skip to main narrative
|
||||
</a>
|
||||
```
|
||||
3. **Canvas Accessibility**: A 3D WebGL `<canvas>` or Three.js scene must have hidden semantic HTML mirrors (`aria-label`, descriptions, or invisible interactive buttons with matching tab indices) so screen readers and keyboard users can inspect and navigate the content.
|
||||
Reference in New Issue
Block a user