feat: implement full-image generative diffusion grain synthesis without sliding
This commit is contained in:
@@ -6,12 +6,12 @@ import {
|
|||||||
Play,
|
Play,
|
||||||
Pause,
|
Pause,
|
||||||
RotateCcw,
|
RotateCcw,
|
||||||
SlidersHorizontal,
|
|
||||||
Zap,
|
Zap,
|
||||||
|
Eye,
|
||||||
|
SlidersHorizontal,
|
||||||
Layers,
|
Layers,
|
||||||
Maximize2
|
Wand2
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { BeforeAfterSlider } from './BeforeAfterSlider';
|
|
||||||
|
|
||||||
interface GrainTransformShowcaseProps {
|
interface GrainTransformShowcaseProps {
|
||||||
beforeUrl: string;
|
beforeUrl: string;
|
||||||
@@ -27,117 +27,139 @@ export function GrainTransformShowcase({
|
|||||||
beforeUrl,
|
beforeUrl,
|
||||||
afterUrl,
|
afterUrl,
|
||||||
beforeLabel = 'RAW INPUT PHOTO',
|
beforeLabel = 'RAW INPUT PHOTO',
|
||||||
afterLabel = 'AI SYNTHESIZED',
|
afterLabel = 'AI SYNTHESIZED (4K)',
|
||||||
aspectRatio = 'aspect-[4/3] lg:aspect-auto lg:h-full',
|
aspectRatio = 'aspect-[4/3] lg:aspect-auto lg:h-full',
|
||||||
className = '',
|
className = '',
|
||||||
initialMode = 'transform',
|
|
||||||
}: GrainTransformShowcaseProps) {
|
}: GrainTransformShowcaseProps) {
|
||||||
const [mode, setMode] = useState<'transform' | 'slider'>(initialMode);
|
|
||||||
const [isPlaying, setIsPlaying] = useState<boolean>(true);
|
const [isPlaying, setIsPlaying] = useState<boolean>(true);
|
||||||
const [progress, setProgress] = useState<number>(0); // 0.0 to 1.0
|
const [progress, setProgress] = useState<number>(0); // 0.0 to 1.0 (Diffusion Step)
|
||||||
const [grainSeed, setGrainSeed] = useState<number>(1);
|
const [grainSeed, setGrainSeed] = useState<number>(1);
|
||||||
const [isScrubbing, setIsScrubbing] = useState<boolean>(false);
|
const [isScrubbing, setIsScrubbing] = useState<boolean>(false);
|
||||||
|
const [peekRaw, setPeekRaw] = useState<boolean>(false);
|
||||||
|
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
const noiseCanvasRef = useRef<HTMLCanvasElement>(null);
|
||||||
const animFrameRef = useRef<number>(0);
|
const animFrameRef = useRef<number>(0);
|
||||||
const lastTimeRef = useRef<number>(0);
|
const lastTimeRef = useRef<number>(0);
|
||||||
const phaseRef = useRef<'forward' | 'holdAfter' | 'reverse' | 'holdBefore'>('forward');
|
const phaseRef = useRef<'forward' | 'holdAfter' | 'reverse' | 'holdBefore'>('forward');
|
||||||
const holdTimerRef = useRef<number>(0);
|
const holdTimerRef = useRef<number>(0);
|
||||||
|
|
||||||
// Grain particle canvas effect
|
// Full-Frame Generative Neural Latent Grain Canvas Simulation
|
||||||
|
// Creates dancing multicolored grain particles across the ENTIRE image like diffusion models
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (mode !== 'transform') return;
|
const canvas = noiseCanvasRef.current;
|
||||||
const canvas = canvasRef.current;
|
|
||||||
if (!canvas) return;
|
if (!canvas) return;
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
if (!ctx) return;
|
if (!ctx) return;
|
||||||
|
|
||||||
let particleAnimId: number;
|
let noiseAnimId: number;
|
||||||
let particles: Array<{
|
const resize = () => {
|
||||||
|
const rect = canvas.getBoundingClientRect();
|
||||||
|
if (rect.width > 0 && rect.height > 0) {
|
||||||
|
// Scaled internal buffer for high density granular performance
|
||||||
|
canvas.width = Math.min(rect.width, 640);
|
||||||
|
canvas.height = Math.min(rect.height, 480);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
resize();
|
||||||
|
window.addEventListener('resize', resize);
|
||||||
|
|
||||||
|
// Dynamic Grain Particles that swirl in latent space
|
||||||
|
const particles: Array<{
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
vx: number;
|
vx: number;
|
||||||
vy: number;
|
vy: number;
|
||||||
size: number;
|
size: number;
|
||||||
alpha: number;
|
alpha: number;
|
||||||
color: string;
|
hue: number;
|
||||||
life: number;
|
|
||||||
}> = [];
|
}> = [];
|
||||||
|
|
||||||
const resize = () => {
|
// Pre-seed ambient latent particles
|
||||||
const rect = canvas.getBoundingClientRect();
|
for (let i = 0; i < 45; i++) {
|
||||||
canvas.width = rect.width;
|
particles.push({
|
||||||
canvas.height = rect.height;
|
x: Math.random() * (canvas.width || 600),
|
||||||
};
|
y: Math.random() * (canvas.height || 450),
|
||||||
resize();
|
vx: (Math.random() - 0.5) * 1.8,
|
||||||
window.addEventListener('resize', resize);
|
vy: (Math.random() - 0.5) * 1.8,
|
||||||
|
size: Math.random() * 2.2 + 0.6,
|
||||||
const colors = ['#818cf8', '#a78bfa', '#38bdf8', '#f43f5e', '#ffffff'];
|
alpha: Math.random() * 0.7 + 0.2,
|
||||||
|
hue: Math.floor(Math.random() * 60) + 220, // Blue-Indigo-Violet
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const render = () => {
|
const render = () => {
|
||||||
|
if (canvas.width === 0 || canvas.height === 0) {
|
||||||
|
noiseAnimId = requestAnimationFrame(render);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
|
|
||||||
// Only spawn particles if transition is active (not resting at 0 or 1)
|
// Noise intensity peaks at progress = 0.5 (deep latent space)
|
||||||
if (progress > 0.02 && progress < 0.98) {
|
// 0.0 -> 0.0 intensity, 0.5 -> 1.0 intensity, 1.0 -> 0.0 intensity
|
||||||
const sweepX = canvas.width * progress;
|
const noiseIntensity = Math.sin(progress * Math.PI);
|
||||||
|
|
||||||
// Spawn particles along the transition sweep boundary
|
if (noiseIntensity > 0.04) {
|
||||||
for (let i = 0; i < 4; i++) {
|
// 1. Procedural High-Density Grain Static
|
||||||
particles.push({
|
const imgData = ctx.createImageData(canvas.width, canvas.height);
|
||||||
x: sweepX + (Math.random() - 0.5) * 30,
|
const buffer = new Uint32Array(imgData.data.buffer);
|
||||||
y: Math.random() * canvas.height,
|
const len = buffer.length;
|
||||||
vx: (Math.random() - 0.3) * 3,
|
|
||||||
vy: (Math.random() - 0.5) * 4,
|
// Density increases dramatically during midpoint
|
||||||
size: Math.random() * 2.5 + 0.8,
|
const grainAlpha = Math.floor(noiseIntensity * 140);
|
||||||
alpha: Math.random() * 0.9 + 0.3,
|
const colorShift = Math.sin(Date.now() * 0.003) * 15;
|
||||||
color: colors[Math.floor(Math.random() * colors.length)],
|
|
||||||
life: 1.0,
|
for (let i = 0; i < len; i += 2) {
|
||||||
});
|
if (Math.random() < noiseIntensity * 0.85) {
|
||||||
|
const val = (Math.random() * 255) | 0;
|
||||||
|
const r = Math.min(255, val + colorShift);
|
||||||
|
const g = Math.min(255, val + 10);
|
||||||
|
const b = Math.min(255, val + 35);
|
||||||
|
// Little-endian RGBA packing: ABGR
|
||||||
|
buffer[i] = (grainAlpha << 24) | (b << 16) | (g << 8) | r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx.putImageData(imgData, 0, 0);
|
||||||
|
|
||||||
|
// 2. Swirling Latent Sparkle Particles
|
||||||
|
for (let i = 0; i < particles.length; i++) {
|
||||||
|
const p = particles[i];
|
||||||
|
p.x += p.vx * (1 + noiseIntensity * 2);
|
||||||
|
p.y += p.vy * (1 + noiseIntensity * 2);
|
||||||
|
|
||||||
|
if (p.x < 0) p.x = canvas.width;
|
||||||
|
if (p.x > canvas.width) p.x = 0;
|
||||||
|
if (p.y < 0) p.y = canvas.height;
|
||||||
|
if (p.y > canvas.height) p.y = 0;
|
||||||
|
|
||||||
|
ctx.fillStyle = `hsla(${p.hue}, 85%, 70%, ${p.alpha * noiseIntensity})`;
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.arc(p.x, p.y, p.size * (1 + noiseIntensity * 0.5), 0, Math.PI * 2);
|
||||||
|
ctx.fill();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update and draw particles
|
noiseAnimId = requestAnimationFrame(render);
|
||||||
for (let i = particles.length - 1; i >= 0; i--) {
|
|
||||||
const p = particles[i];
|
|
||||||
p.x += p.vx;
|
|
||||||
p.y += p.vy;
|
|
||||||
p.life -= 0.025;
|
|
||||||
p.alpha = Math.max(0, p.life);
|
|
||||||
|
|
||||||
if (p.life <= 0) {
|
|
||||||
particles.splice(i, 1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.fillStyle = p.color;
|
|
||||||
ctx.globalAlpha = p.alpha;
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
|
|
||||||
ctx.fill();
|
|
||||||
}
|
|
||||||
ctx.globalAlpha = 1.0;
|
|
||||||
|
|
||||||
particleAnimId = requestAnimationFrame(render);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
render();
|
render();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
cancelAnimationFrame(particleAnimId);
|
cancelAnimationFrame(noiseAnimId);
|
||||||
window.removeEventListener('resize', resize);
|
window.removeEventListener('resize', resize);
|
||||||
};
|
};
|
||||||
}, [mode, progress]);
|
}, [progress]);
|
||||||
|
|
||||||
// Main animation clock loop: Smooth cycle through Raw -> Grain Morph Sweep -> Synthesized Result -> Rest
|
// Main Diffusion Synthesis Animation Clock (Procedural sampling loop)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (mode !== 'transform' || !isPlaying || isScrubbing) {
|
if (!isPlaying || isScrubbing) {
|
||||||
cancelAnimationFrame(animFrameRef.current);
|
cancelAnimationFrame(animFrameRef.current);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const duration = 2800; // 2.8s sweep duration
|
const duration = 3200; // 3.2s full diffusion synthesis
|
||||||
const holdDuration = 1800; // 1.8s hold on result
|
const holdDuration = 2200; // 2.2s admiring hold on 4K result
|
||||||
|
|
||||||
const loop = (timestamp: number) => {
|
const loop = (timestamp: number) => {
|
||||||
if (!lastTimeRef.current) lastTimeRef.current = timestamp;
|
if (!lastTimeRef.current) lastTimeRef.current = timestamp;
|
||||||
@@ -163,7 +185,8 @@ export function GrainTransformShowcase({
|
|||||||
}
|
}
|
||||||
} else if (phaseRef.current === 'reverse') {
|
} else if (phaseRef.current === 'reverse') {
|
||||||
setProgress((prev) => {
|
setProgress((prev) => {
|
||||||
const next = prev - (delta / (duration * 0.7)); // faster rewind
|
// Smooth rewind back to raw photo
|
||||||
|
const next = prev - (delta / 1400);
|
||||||
if (next <= 0.0) {
|
if (next <= 0.0) {
|
||||||
phaseRef.current = 'holdBefore';
|
phaseRef.current = 'holdBefore';
|
||||||
holdTimerRef.current = 0;
|
holdTimerRef.current = 0;
|
||||||
@@ -173,7 +196,7 @@ export function GrainTransformShowcase({
|
|||||||
});
|
});
|
||||||
} else if (phaseRef.current === 'holdBefore') {
|
} else if (phaseRef.current === 'holdBefore') {
|
||||||
holdTimerRef.current += delta;
|
holdTimerRef.current += delta;
|
||||||
if (holdTimerRef.current >= 800) {
|
if (holdTimerRef.current >= 900) {
|
||||||
phaseRef.current = 'forward';
|
phaseRef.current = 'forward';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,7 +210,7 @@ export function GrainTransformShowcase({
|
|||||||
cancelAnimationFrame(animFrameRef.current);
|
cancelAnimationFrame(animFrameRef.current);
|
||||||
lastTimeRef.current = 0;
|
lastTimeRef.current = 0;
|
||||||
};
|
};
|
||||||
}, [mode, isPlaying, isScrubbing]);
|
}, [isPlaying, isScrubbing]);
|
||||||
|
|
||||||
const handleManualScrub = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleManualScrub = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setIsScrubbing(true);
|
setIsScrubbing(true);
|
||||||
@@ -206,263 +229,259 @@ export function GrainTransformShowcase({
|
|||||||
setIsPlaying(true);
|
setIsPlaying(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Status pill text based on progress
|
// Math for Generative Latent Diffusion Transition
|
||||||
const getStatusText = () => {
|
// Entire Before image transforms into grains across the whole screen, then crystallizes into After
|
||||||
if (progress < 0.1) return 'Input Raw Photo';
|
const effectiveProgress = peekRaw ? 0 : progress;
|
||||||
if (progress > 0.9) return 'AI Synthesized (Lossless 4K)';
|
|
||||||
return `Synthesizing Neural Grains • ${Math.round(progress * 100)}%`;
|
// Diffusion Curve (smooth S-curve)
|
||||||
|
const diffusionStep = Math.min(30, Math.floor(effectiveProgress * 30));
|
||||||
|
const noiseIntensity = Math.sin(effectiveProgress * Math.PI); // 0 -> 1 -> 0
|
||||||
|
|
||||||
|
// Pixel displacement scale: breaks image into scattered granular particles
|
||||||
|
const displacementScale = Math.round(noiseIntensity * 36);
|
||||||
|
|
||||||
|
// Before image dissolves out from 0.0 to 0.55
|
||||||
|
const beforeOpacity = effectiveProgress <= 0.5
|
||||||
|
? Math.max(0, 1 - Math.pow(effectiveProgress / 0.48, 1.4))
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
// After image crystallizes in from 0.45 to 1.0
|
||||||
|
const afterOpacity = effectiveProgress >= 0.45
|
||||||
|
? Math.min(1, Math.pow((effectiveProgress - 0.45) / 0.52, 1.3))
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
// Dynamic status text resembling generative diffusion models
|
||||||
|
const getStatusInfo = () => {
|
||||||
|
if (peekRaw) return { text: 'Original Raw Input Photo', color: 'bg-slate-400' };
|
||||||
|
if (effectiveProgress < 0.12) return { text: 'Raw Input Photo • Ready for Synthesis', color: 'bg-blue-400' };
|
||||||
|
if (effectiveProgress < 0.45) return { text: `Forward Diffusion • Dissolving into Grains (${diffusionStep}/30)`, color: 'bg-amber-400 animate-pulse' };
|
||||||
|
if (effectiveProgress < 0.65) return { text: `Neural Latent Synthesis • Denoising Tensor (${diffusionStep}/30)`, color: 'bg-indigo-400 animate-ping' };
|
||||||
|
if (effectiveProgress < 0.94) return { text: `Reverse Diffusion • Crystallizing 4K Details (${diffusionStep}/30)`, color: 'bg-sky-400 animate-pulse' };
|
||||||
|
return { text: 'AI Synthesis Complete • Lossless 4K Masterpiece', color: 'bg-emerald-400' };
|
||||||
};
|
};
|
||||||
|
|
||||||
const percent = Math.round(progress * 100);
|
const status = getStatusInfo();
|
||||||
|
const percent = Math.round(effectiveProgress * 100);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`relative flex flex-col justify-between h-full bg-slate-950 rounded-3xl overflow-hidden ${className}`}>
|
<div className={`relative flex flex-col justify-between h-full bg-slate-950 rounded-3xl overflow-hidden select-none ${className}`}>
|
||||||
{/* Top Floating Glass Header */}
|
{/* Hidden SVG Filter Definition for Physical Procedural Grain Displacement */}
|
||||||
|
<svg className="absolute w-0 h-0 pointer-events-none" aria-hidden="true">
|
||||||
|
<defs>
|
||||||
|
<filter id={`neural-grain-displace-${grainSeed}`} x="-20%" y="-20%" width="140%" height="140%">
|
||||||
|
<feTurbulence
|
||||||
|
type="fractalNoise"
|
||||||
|
baseFrequency="0.65"
|
||||||
|
numOctaves="4"
|
||||||
|
seed={grainSeed}
|
||||||
|
result="noise"
|
||||||
|
/>
|
||||||
|
<feDisplacementMap
|
||||||
|
in="SourceGraphic"
|
||||||
|
in2="noise"
|
||||||
|
scale={displacementScale}
|
||||||
|
xChannelSelector="R"
|
||||||
|
yChannelSelector="G"
|
||||||
|
result="displaced"
|
||||||
|
/>
|
||||||
|
</filter>
|
||||||
|
</defs>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
{/* Top Floating Glass Header Bar */}
|
||||||
<div className="absolute top-3 left-3 right-3 sm:top-4 sm:left-4 sm:right-4 z-30 flex items-center justify-between gap-2 pointer-events-none">
|
<div className="absolute top-3 left-3 right-3 sm:top-4 sm:left-4 sm:right-4 z-30 flex items-center justify-between gap-2 pointer-events-none">
|
||||||
{/* Dynamic Status Pill */}
|
{/* Dynamic Generative Model Status Pill */}
|
||||||
<div className="pointer-events-auto inline-flex items-center gap-2 px-3 py-1.5 rounded-full bg-slate-900/85 backdrop-blur-md border border-white/15 text-white text-xs font-semibold shadow-lg">
|
<div className="pointer-events-auto inline-flex items-center gap-2 px-3.5 py-1.5 rounded-full bg-slate-900/90 backdrop-blur-md border border-white/15 text-white text-xs font-semibold shadow-lg">
|
||||||
<span className={`w-2 h-2 rounded-full ${
|
<span className={`w-2 h-2 rounded-full ${status.color}`} />
|
||||||
progress > 0.1 && progress < 0.9
|
<span className="font-mono text-[11px] sm:text-xs">{status.text}</span>
|
||||||
? 'bg-amber-400 animate-ping'
|
|
||||||
: progress >= 0.9
|
|
||||||
? 'bg-emerald-400'
|
|
||||||
: 'bg-blue-400'
|
|
||||||
}`} />
|
|
||||||
<span className="font-mono text-[11px] sm:text-xs">{getStatusText()}</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Mode Switcher: Grain Transform vs Compare Slider */}
|
{/* Quick Actions (Peek Raw Photo / Diffusion Step Counter) */}
|
||||||
<div className="pointer-events-auto inline-flex items-center p-0.5 rounded-full bg-slate-900/85 backdrop-blur-md border border-white/15 shadow-lg">
|
<div className="pointer-events-auto flex items-center gap-2">
|
||||||
|
{/* Hold to Peek Raw Photo */}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => {
|
onMouseDown={() => setPeekRaw(true)}
|
||||||
setMode('transform');
|
onMouseUp={() => setPeekRaw(false)}
|
||||||
setIsPlaying(true);
|
onMouseLeave={() => setPeekRaw(false)}
|
||||||
}}
|
onTouchStart={() => setPeekRaw(true)}
|
||||||
className={`px-3 py-1 rounded-full text-[11px] font-bold tracking-wide transition-all ${
|
onTouchEnd={() => setPeekRaw(false)}
|
||||||
mode === 'transform'
|
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-slate-900/85 hover:bg-slate-800 text-slate-300 hover:text-white border border-white/15 backdrop-blur-md text-[11px] font-bold shadow-md transition-all active:scale-95"
|
||||||
? 'bg-gradient-to-r from-blue-600 to-indigo-600 text-white shadow-sm'
|
title="Press and hold to compare with raw photo"
|
||||||
: 'text-slate-400 hover:text-white'
|
|
||||||
}`}
|
|
||||||
>
|
>
|
||||||
<Zap className="w-3 h-3 inline mr-1" />
|
<Eye className="w-3.5 h-3.5 text-blue-400" />
|
||||||
Grain Morph
|
<span className="hidden sm:inline">Hold to</span> Peek Raw
|
||||||
</button>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => {
|
|
||||||
setMode('slider');
|
|
||||||
setIsPlaying(false);
|
|
||||||
}}
|
|
||||||
className={`px-3 py-1 rounded-full text-[11px] font-bold tracking-wide transition-all ${
|
|
||||||
mode === 'slider'
|
|
||||||
? 'bg-gradient-to-r from-blue-600 to-indigo-600 text-white shadow-sm'
|
|
||||||
: 'text-slate-400 hover:text-white'
|
|
||||||
}`}
|
|
||||||
>
|
|
||||||
<SlidersHorizontal className="w-3 h-3 inline mr-1" />
|
|
||||||
Split Slider
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
{/* Model Iteration Pill */}
|
||||||
|
<div className="inline-flex items-center gap-1 px-2.5 py-1.5 rounded-full bg-blue-600/30 border border-blue-400/30 text-blue-300 font-mono text-[11px] font-bold backdrop-blur-md">
|
||||||
|
<Wand2 className="w-3 h-3 text-blue-400" />
|
||||||
|
<span>Step {diffusionStep}/30</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Main Visual Display Stage */}
|
{/* Main Full-Frame Generative Diffusion Stage (NO SLIDING - WHOLE IMAGE TRANSFORMS) */}
|
||||||
<div className={`relative flex-1 min-h-[380px] sm:min-h-[460px] overflow-hidden ${aspectRatio}`} ref={containerRef}>
|
<div className={`relative flex-1 min-h-[380px] sm:min-h-[460px] overflow-hidden ${aspectRatio}`} ref={containerRef}>
|
||||||
{mode === 'slider' ? (
|
<div className="relative w-full h-full overflow-hidden bg-slate-950">
|
||||||
<BeforeAfterSlider
|
|
||||||
beforeUrl={beforeUrl}
|
{/* Layer 1: Ambient Backdrop Gradient */}
|
||||||
afterUrl={afterUrl}
|
<div className="absolute inset-0 bg-gradient-to-br from-slate-950 via-indigo-950/40 to-slate-950 pointer-events-none" />
|
||||||
beforeLabel={beforeLabel}
|
|
||||||
afterLabel={afterLabel}
|
{/* Layer 2: The Raw Input Photo (Whole Image converts into grains via displacement & blur) */}
|
||||||
autoSlide={true}
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
className="h-full w-full"
|
<img
|
||||||
|
src={beforeUrl}
|
||||||
|
alt={beforeLabel}
|
||||||
|
className="absolute inset-0 w-full h-full object-cover transition-none will-change-transform"
|
||||||
|
style={{
|
||||||
|
opacity: beforeOpacity,
|
||||||
|
filter: displacementScale > 2
|
||||||
|
? `url(#neural-grain-displace-${grainSeed}) blur(${noiseIntensity * 3.5}px)`
|
||||||
|
: 'none',
|
||||||
|
transform: `scale(${1 + noiseIntensity * 0.04})`,
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
|
||||||
<div className="relative w-full h-full select-none overflow-hidden bg-slate-900">
|
|
||||||
{/* Layer 1: The AI Synthesized Result (Bottom Layer) */}
|
|
||||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
||||||
<img
|
|
||||||
src={afterUrl}
|
|
||||||
alt={afterLabel}
|
|
||||||
className="absolute inset-0 w-full h-full object-cover"
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Layer 2: Raw Input Photo (Clipped by Transition Progress) */}
|
{/* Layer 3: The AI Synthesized Result (Resolves cleanly out of the noise) */}
|
||||||
<div
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
className="absolute inset-0 overflow-hidden pointer-events-none transition-none"
|
<img
|
||||||
style={{
|
src={afterUrl}
|
||||||
clipPath: `polygon(0 0, ${100 - percent}% 0, ${100 - percent}% 100%, 0 100%)`,
|
alt={afterLabel}
|
||||||
}}
|
className="absolute inset-0 w-full h-full object-cover transition-none will-change-transform"
|
||||||
>
|
style={{
|
||||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
opacity: afterOpacity,
|
||||||
<img
|
filter: displacementScale > 2
|
||||||
src={beforeUrl}
|
? `url(#neural-grain-displace-${grainSeed}) blur(${noiseIntensity * 2.8}px)`
|
||||||
alt={beforeLabel}
|
: 'none',
|
||||||
className="absolute inset-0 w-full h-full object-cover"
|
transform: `scale(${1.02 - (1 - noiseIntensity) * 0.02})`,
|
||||||
/>
|
}}
|
||||||
</div>
|
/>
|
||||||
|
|
||||||
{/* Layer 3: Generative Neural Grain Front (Visible along the transform edge) */}
|
{/* Layer 4: Whole-Image Generative Noise Canvas (Procedural Dancing Grain Particles) */}
|
||||||
{progress > 0.01 && progress < 0.99 && (
|
<canvas
|
||||||
<div
|
ref={noiseCanvasRef}
|
||||||
className="absolute top-0 bottom-0 pointer-events-none z-20"
|
className="absolute inset-0 w-full h-full pointer-events-none z-15 mix-blend-screen"
|
||||||
style={{
|
style={{
|
||||||
left: `calc(${100 - percent}% - 40px)`,
|
opacity: Math.min(1, noiseIntensity * 1.3),
|
||||||
width: '80px',
|
}}
|
||||||
}}
|
/>
|
||||||
>
|
|
||||||
{/* Latent Neural Laser Beam */}
|
|
||||||
<div className="absolute top-0 bottom-0 left-1/2 -translate-x-1/2 w-[3px] bg-gradient-to-b from-blue-400 via-indigo-300 to-amber-300 shadow-[0_0_15px_#818cf8,0_0_30px_#6366f1]" />
|
|
||||||
|
|
||||||
{/* Intense High-Frequency Animated Noise Filter along boundary */}
|
{/* Layer 5: High-Frequency Film Grain Overlay (Subtle photographic latent emulsion) */}
|
||||||
<svg className="absolute inset-0 w-full h-full opacity-70 mix-blend-overlay">
|
<div
|
||||||
<filter id={`transform-grain-${grainSeed}`}>
|
className="absolute inset-0 pointer-events-none z-20 mix-blend-overlay"
|
||||||
<feTurbulence
|
style={{ opacity: 0.25 + noiseIntensity * 0.55 }}
|
||||||
type="fractalNoise"
|
>
|
||||||
baseFrequency="0.85"
|
<svg className="w-full h-full">
|
||||||
numOctaves="4"
|
<filter id={`film-grain-continuous-${grainSeed}`}>
|
||||||
seed={grainSeed}
|
<feTurbulence
|
||||||
/>
|
type="fractalNoise"
|
||||||
<feColorMatrix type="saturate" values="0" />
|
baseFrequency="0.8"
|
||||||
</filter>
|
numOctaves="3"
|
||||||
<rect
|
seed={grainSeed}
|
||||||
width="100%"
|
/>
|
||||||
height="100%"
|
<feColorMatrix type="saturate" values="0" />
|
||||||
filter={`url(#transform-grain-${grainSeed})`}
|
</filter>
|
||||||
fill="#fff"
|
<rect width="100%" height="100%" filter={`url(#film-grain-continuous-${grainSeed})`} fill="#fff" />
|
||||||
/>
|
</svg>
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Layer 4: Global Film Grain Shimmer (Simulates Real Photographic Latent Emulsion) */}
|
|
||||||
<div className="absolute inset-0 pointer-events-none mix-blend-overlay opacity-30 z-10">
|
|
||||||
<svg className="w-full h-full">
|
|
||||||
<filter id="film-grain-ambient">
|
|
||||||
<feTurbulence
|
|
||||||
type="fractalNoise"
|
|
||||||
baseFrequency="0.75"
|
|
||||||
numOctaves="3"
|
|
||||||
seed={grainSeed}
|
|
||||||
/>
|
|
||||||
<feColorMatrix type="saturate" values="0" />
|
|
||||||
</filter>
|
|
||||||
<rect width="100%" height="100%" filter="url(#film-grain-ambient)" fill="#ffffff" />
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Layer 5: Canvas Particle Spark Emitter along transition wave */}
|
|
||||||
<canvas
|
|
||||||
ref={canvasRef}
|
|
||||||
className="absolute inset-0 w-full h-full pointer-events-none z-25"
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Corner Badges */}
|
|
||||||
<div className="absolute bottom-16 left-4 z-25 pointer-events-none">
|
|
||||||
<span className={`px-2.5 py-1 rounded-md text-[10px] font-mono font-bold tracking-wider uppercase backdrop-blur-md border transition-opacity duration-300 ${
|
|
||||||
progress < 0.5
|
|
||||||
? 'bg-black/75 text-white border-white/20 opacity-100'
|
|
||||||
: 'bg-black/40 text-slate-400 border-transparent opacity-40'
|
|
||||||
}`}>
|
|
||||||
{beforeLabel}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="absolute bottom-16 right-4 z-25 pointer-events-none">
|
|
||||||
<span className={`px-2.5 py-1 rounded-md text-[10px] font-mono font-bold tracking-wider uppercase backdrop-blur-md border transition-opacity duration-300 ${
|
|
||||||
progress >= 0.5
|
|
||||||
? 'bg-blue-600/90 text-white border-blue-400/40 opacity-100 shadow-md'
|
|
||||||
: 'bg-black/40 text-slate-400 border-transparent opacity-40'
|
|
||||||
}`}>
|
|
||||||
{afterLabel}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
|
{/* Layer 6: Mid-Diffusion Latent Glow Wave (Aurora Pulse across center at peak grain state) */}
|
||||||
|
{noiseIntensity > 0.3 && (
|
||||||
|
<div
|
||||||
|
className="absolute inset-0 pointer-events-none z-22 bg-[radial-gradient(circle_at_50%_50%,rgba(99,102,241,0.22),rgba(56,189,248,0.12),transparent_70%)] transition-opacity duration-300"
|
||||||
|
style={{ opacity: Math.pow(noiseIntensity, 2) }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Layer 7: Final Completion Flash Sheen (Runs momentarily when reaching 100% synthesis) */}
|
||||||
|
{effectiveProgress > 0.94 && (
|
||||||
|
<div className="absolute inset-0 pointer-events-none z-25 bg-gradient-to-r from-transparent via-white/18 to-transparent animate-shimmer" />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Corner Dynamic Tags */}
|
||||||
|
<div className="absolute bottom-16 left-4 z-25 pointer-events-none">
|
||||||
|
<span className={`px-2.5 py-1 rounded-md text-[10px] font-mono font-bold tracking-wider uppercase backdrop-blur-md border transition-all duration-300 ${
|
||||||
|
effectiveProgress < 0.45
|
||||||
|
? 'bg-black/80 text-white border-white/20 shadow-md'
|
||||||
|
: 'bg-black/30 text-slate-500 border-transparent opacity-30'
|
||||||
|
}`}>
|
||||||
|
{beforeLabel}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="absolute bottom-16 right-4 z-25 pointer-events-none">
|
||||||
|
<span className={`px-2.5 py-1 rounded-md text-[10px] font-mono font-bold tracking-wider uppercase backdrop-blur-md border transition-all duration-300 ${
|
||||||
|
effectiveProgress >= 0.55
|
||||||
|
? 'bg-blue-600/90 text-white border-blue-400/40 shadow-lg shadow-blue-500/20'
|
||||||
|
: 'bg-black/30 text-slate-500 border-transparent opacity-30'
|
||||||
|
}`}>
|
||||||
|
{afterLabel}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Bottom Interactive Playback & Scrub Bar (For Grain Morph Mode) */}
|
{/* Bottom Interactive Generative Timeline & Controls */}
|
||||||
{mode === 'transform' && (
|
<div className="p-3 sm:p-4 bg-slate-900/95 border-t border-white/10 flex flex-col gap-2.5 z-30">
|
||||||
<div className="p-3 sm:p-4 bg-slate-900/95 border-t border-white/10 flex flex-col gap-2.5 z-30">
|
<div className="flex items-center gap-3">
|
||||||
<div className="flex items-center gap-3">
|
{/* Play / Pause Toggle */}
|
||||||
{/* Play / Pause Toggle */}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => setIsPlaying(!isPlaying)}
|
|
||||||
className="p-2 rounded-xl bg-white/10 hover:bg-white/20 text-white transition-all active:scale-95 flex items-center justify-center shrink-0"
|
|
||||||
title={isPlaying ? 'Pause Transformation' : 'Play Transformation'}
|
|
||||||
>
|
|
||||||
{isPlaying ? <Pause className="w-4 h-4" /> : <Play className="w-4 h-4" />}
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{/* Replay Button */}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={handleReplay}
|
|
||||||
className="p-2 rounded-xl bg-white/10 hover:bg-white/20 text-white transition-all active:scale-95 flex items-center justify-center shrink-0"
|
|
||||||
title="Replay from Beginning"
|
|
||||||
>
|
|
||||||
<RotateCcw className="w-4 h-4" />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{/* Manual Timeline Scrubber */}
|
|
||||||
<div className="relative flex-1 flex items-center">
|
|
||||||
<input
|
|
||||||
type="range"
|
|
||||||
min="0"
|
|
||||||
max="1"
|
|
||||||
step="0.005"
|
|
||||||
value={progress}
|
|
||||||
onChange={handleManualScrub}
|
|
||||||
onMouseUp={handleScrubEnd}
|
|
||||||
onTouchEnd={handleScrubEnd}
|
|
||||||
className="w-full h-1.5 bg-slate-700 rounded-lg appearance-none cursor-pointer accent-blue-500 hover:accent-blue-400 focus:outline-none"
|
|
||||||
aria-label="Transformation timeline scrubber"
|
|
||||||
/>
|
|
||||||
{/* Progress Glow Fill */}
|
|
||||||
<div
|
|
||||||
className="absolute left-0 top-1/2 -translate-y-1/2 h-1.5 bg-gradient-to-r from-blue-500 via-indigo-400 to-amber-300 rounded-l-lg pointer-events-none"
|
|
||||||
style={{ width: `${percent}%` }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Numerical Progress Indicator */}
|
|
||||||
<span className="font-mono text-xs font-bold text-slate-300 shrink-0 w-10 text-right">
|
|
||||||
{percent}%
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center justify-between text-[11px] text-slate-400 font-mono">
|
|
||||||
<span className="flex items-center gap-1.5">
|
|
||||||
<Sparkles className="w-3 h-3 text-blue-400" />
|
|
||||||
Generative Latent Grain Diffusion
|
|
||||||
</span>
|
|
||||||
<span className="hidden sm:inline text-slate-400">
|
|
||||||
Drag slider to scrub frame-by-frame
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Hint for Split Slider Mode */}
|
|
||||||
{mode === 'slider' && (
|
|
||||||
<div className="p-3 sm:p-4 bg-slate-900/95 border-t border-white/10 flex items-center justify-between text-xs text-slate-300 font-mono z-30">
|
|
||||||
<span className="flex items-center gap-1.5">
|
|
||||||
<SlidersHorizontal className="w-3.5 h-3.5 text-blue-400" />
|
|
||||||
Drag divider line to inspect textures
|
|
||||||
</span>
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => {
|
onClick={() => setIsPlaying(!isPlaying)}
|
||||||
setMode('transform');
|
className="p-2 rounded-xl bg-white/10 hover:bg-white/20 text-white transition-all active:scale-95 flex items-center justify-center shrink-0"
|
||||||
setIsPlaying(true);
|
title={isPlaying ? 'Pause Synthesis' : 'Play Synthesis'}
|
||||||
}}
|
|
||||||
className="text-blue-400 hover:underline flex items-center gap-1 text-[11px]"
|
|
||||||
>
|
>
|
||||||
<Zap className="w-3 h-3" />
|
{isPlaying ? <Pause className="w-4 h-4" /> : <Play className="w-4 h-4" />}
|
||||||
Switch back to Grain Morph
|
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
{/* Replay Full Synthesis from Beginning */}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleReplay}
|
||||||
|
className="p-2 rounded-xl bg-white/10 hover:bg-white/20 text-white transition-all active:scale-95 flex items-center justify-center shrink-0"
|
||||||
|
title="Re-run Generative Synthesis"
|
||||||
|
>
|
||||||
|
<RotateCcw className="w-4 h-4" />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{/* Generative Diffusion Progress Scrubber */}
|
||||||
|
<div className="relative flex-1 flex items-center">
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min="0"
|
||||||
|
max="1"
|
||||||
|
step="0.005"
|
||||||
|
value={effectiveProgress}
|
||||||
|
onChange={handleManualScrub}
|
||||||
|
onMouseUp={handleScrubEnd}
|
||||||
|
onTouchEnd={handleScrubEnd}
|
||||||
|
className="w-full h-1.5 bg-slate-700 rounded-lg appearance-none cursor-pointer accent-blue-500 hover:accent-blue-400 focus:outline-none"
|
||||||
|
aria-label="Diffusion sampling timeline scrubber"
|
||||||
|
/>
|
||||||
|
{/* Glowing Gradient Progress Fill */}
|
||||||
|
<div
|
||||||
|
className="absolute left-0 top-1/2 -translate-y-1/2 h-1.5 bg-gradient-to-r from-blue-500 via-indigo-400 to-amber-300 rounded-l-lg pointer-events-none"
|
||||||
|
style={{ width: `${percent}%` }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Numerical % Progress Indicator */}
|
||||||
|
<span className="font-mono text-xs font-bold text-slate-300 shrink-0 w-12 text-right">
|
||||||
|
{percent}%
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
|
{/* Informative Sub-Bar */}
|
||||||
|
<div className="flex items-center justify-between text-[11px] text-slate-400 font-mono">
|
||||||
|
<span className="flex items-center gap-1.5">
|
||||||
|
<Sparkles className="w-3 h-3 text-blue-400" />
|
||||||
|
Neural Diffusion Generative Model (Whole-Image Transformation)
|
||||||
|
</span>
|
||||||
|
<span className="hidden sm:inline text-slate-400">
|
||||||
|
Drag slider to inspect grain sampling frame-by-frame
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user