feat: implement full-image generative diffusion grain synthesis without sliding
This commit is contained in:
@@ -6,12 +6,12 @@ import {
|
||||
Play,
|
||||
Pause,
|
||||
RotateCcw,
|
||||
SlidersHorizontal,
|
||||
Zap,
|
||||
Eye,
|
||||
SlidersHorizontal,
|
||||
Layers,
|
||||
Maximize2
|
||||
Wand2
|
||||
} from 'lucide-react';
|
||||
import { BeforeAfterSlider } from './BeforeAfterSlider';
|
||||
|
||||
interface GrainTransformShowcaseProps {
|
||||
beforeUrl: string;
|
||||
@@ -27,117 +27,139 @@ export function GrainTransformShowcase({
|
||||
beforeUrl,
|
||||
afterUrl,
|
||||
beforeLabel = 'RAW INPUT PHOTO',
|
||||
afterLabel = 'AI SYNTHESIZED',
|
||||
afterLabel = 'AI SYNTHESIZED (4K)',
|
||||
aspectRatio = 'aspect-[4/3] lg:aspect-auto lg:h-full',
|
||||
className = '',
|
||||
initialMode = 'transform',
|
||||
}: GrainTransformShowcaseProps) {
|
||||
const [mode, setMode] = useState<'transform' | 'slider'>(initialMode);
|
||||
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 [isScrubbing, setIsScrubbing] = useState<boolean>(false);
|
||||
const [peekRaw, setPeekRaw] = useState<boolean>(false);
|
||||
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||
const noiseCanvasRef = useRef<HTMLCanvasElement>(null);
|
||||
const animFrameRef = useRef<number>(0);
|
||||
const lastTimeRef = useRef<number>(0);
|
||||
const phaseRef = useRef<'forward' | 'holdAfter' | 'reverse' | 'holdBefore'>('forward');
|
||||
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(() => {
|
||||
if (mode !== 'transform') return;
|
||||
const canvas = canvasRef.current;
|
||||
const canvas = noiseCanvasRef.current;
|
||||
if (!canvas) return;
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) return;
|
||||
|
||||
let particleAnimId: number;
|
||||
let particles: Array<{
|
||||
let noiseAnimId: number;
|
||||
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;
|
||||
y: number;
|
||||
vx: number;
|
||||
vy: number;
|
||||
size: number;
|
||||
alpha: number;
|
||||
color: string;
|
||||
life: number;
|
||||
hue: number;
|
||||
}> = [];
|
||||
|
||||
const resize = () => {
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
canvas.width = rect.width;
|
||||
canvas.height = rect.height;
|
||||
};
|
||||
resize();
|
||||
window.addEventListener('resize', resize);
|
||||
|
||||
const colors = ['#818cf8', '#a78bfa', '#38bdf8', '#f43f5e', '#ffffff'];
|
||||
// Pre-seed ambient latent particles
|
||||
for (let i = 0; i < 45; i++) {
|
||||
particles.push({
|
||||
x: Math.random() * (canvas.width || 600),
|
||||
y: Math.random() * (canvas.height || 450),
|
||||
vx: (Math.random() - 0.5) * 1.8,
|
||||
vy: (Math.random() - 0.5) * 1.8,
|
||||
size: Math.random() * 2.2 + 0.6,
|
||||
alpha: Math.random() * 0.7 + 0.2,
|
||||
hue: Math.floor(Math.random() * 60) + 220, // Blue-Indigo-Violet
|
||||
});
|
||||
}
|
||||
|
||||
const render = () => {
|
||||
if (canvas.width === 0 || canvas.height === 0) {
|
||||
noiseAnimId = requestAnimationFrame(render);
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
|
||||
// Only spawn particles if transition is active (not resting at 0 or 1)
|
||||
if (progress > 0.02 && progress < 0.98) {
|
||||
const sweepX = canvas.width * progress;
|
||||
// Noise intensity peaks at progress = 0.5 (deep latent space)
|
||||
// 0.0 -> 0.0 intensity, 0.5 -> 1.0 intensity, 1.0 -> 0.0 intensity
|
||||
const noiseIntensity = Math.sin(progress * Math.PI);
|
||||
|
||||
// Spawn particles along the transition sweep boundary
|
||||
for (let i = 0; i < 4; i++) {
|
||||
particles.push({
|
||||
x: sweepX + (Math.random() - 0.5) * 30,
|
||||
y: Math.random() * canvas.height,
|
||||
vx: (Math.random() - 0.3) * 3,
|
||||
vy: (Math.random() - 0.5) * 4,
|
||||
size: Math.random() * 2.5 + 0.8,
|
||||
alpha: Math.random() * 0.9 + 0.3,
|
||||
color: colors[Math.floor(Math.random() * colors.length)],
|
||||
life: 1.0,
|
||||
});
|
||||
if (noiseIntensity > 0.04) {
|
||||
// 1. Procedural High-Density Grain Static
|
||||
const imgData = ctx.createImageData(canvas.width, canvas.height);
|
||||
const buffer = new Uint32Array(imgData.data.buffer);
|
||||
const len = buffer.length;
|
||||
|
||||
// Density increases dramatically during midpoint
|
||||
const grainAlpha = Math.floor(noiseIntensity * 140);
|
||||
const colorShift = Math.sin(Date.now() * 0.003) * 15;
|
||||
|
||||
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
|
||||
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);
|
||||
noiseAnimId = requestAnimationFrame(render);
|
||||
};
|
||||
|
||||
render();
|
||||
|
||||
return () => {
|
||||
cancelAnimationFrame(particleAnimId);
|
||||
cancelAnimationFrame(noiseAnimId);
|
||||
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(() => {
|
||||
if (mode !== 'transform' || !isPlaying || isScrubbing) {
|
||||
if (!isPlaying || isScrubbing) {
|
||||
cancelAnimationFrame(animFrameRef.current);
|
||||
return;
|
||||
}
|
||||
|
||||
const duration = 2800; // 2.8s sweep duration
|
||||
const holdDuration = 1800; // 1.8s hold on result
|
||||
const duration = 3200; // 3.2s full diffusion synthesis
|
||||
const holdDuration = 2200; // 2.2s admiring hold on 4K result
|
||||
|
||||
const loop = (timestamp: number) => {
|
||||
if (!lastTimeRef.current) lastTimeRef.current = timestamp;
|
||||
@@ -163,7 +185,8 @@ export function GrainTransformShowcase({
|
||||
}
|
||||
} else if (phaseRef.current === 'reverse') {
|
||||
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) {
|
||||
phaseRef.current = 'holdBefore';
|
||||
holdTimerRef.current = 0;
|
||||
@@ -173,7 +196,7 @@ export function GrainTransformShowcase({
|
||||
});
|
||||
} else if (phaseRef.current === 'holdBefore') {
|
||||
holdTimerRef.current += delta;
|
||||
if (holdTimerRef.current >= 800) {
|
||||
if (holdTimerRef.current >= 900) {
|
||||
phaseRef.current = 'forward';
|
||||
}
|
||||
}
|
||||
@@ -187,7 +210,7 @@ export function GrainTransformShowcase({
|
||||
cancelAnimationFrame(animFrameRef.current);
|
||||
lastTimeRef.current = 0;
|
||||
};
|
||||
}, [mode, isPlaying, isScrubbing]);
|
||||
}, [isPlaying, isScrubbing]);
|
||||
|
||||
const handleManualScrub = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setIsScrubbing(true);
|
||||
@@ -206,263 +229,259 @@ export function GrainTransformShowcase({
|
||||
setIsPlaying(true);
|
||||
};
|
||||
|
||||
// Status pill text based on progress
|
||||
const getStatusText = () => {
|
||||
if (progress < 0.1) return 'Input Raw Photo';
|
||||
if (progress > 0.9) return 'AI Synthesized (Lossless 4K)';
|
||||
return `Synthesizing Neural Grains • ${Math.round(progress * 100)}%`;
|
||||
// Math for Generative Latent Diffusion Transition
|
||||
// Entire Before image transforms into grains across the whole screen, then crystallizes into After
|
||||
const effectiveProgress = peekRaw ? 0 : progress;
|
||||
|
||||
// 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 (
|
||||
<div className={`relative flex flex-col justify-between h-full bg-slate-950 rounded-3xl overflow-hidden ${className}`}>
|
||||
{/* Top Floating Glass Header */}
|
||||
<div className={`relative flex flex-col justify-between h-full bg-slate-950 rounded-3xl overflow-hidden select-none ${className}`}>
|
||||
{/* 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">
|
||||
{/* Dynamic 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">
|
||||
<span className={`w-2 h-2 rounded-full ${
|
||||
progress > 0.1 && progress < 0.9
|
||||
? '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>
|
||||
{/* Dynamic Generative Model Status Pill */}
|
||||
<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 ${status.color}`} />
|
||||
<span className="font-mono text-[11px] sm:text-xs">{status.text}</span>
|
||||
</div>
|
||||
|
||||
{/* Mode Switcher: Grain Transform vs Compare Slider */}
|
||||
<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">
|
||||
{/* Quick Actions (Peek Raw Photo / Diffusion Step Counter) */}
|
||||
<div className="pointer-events-auto flex items-center gap-2">
|
||||
{/* Hold to Peek Raw Photo */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMode('transform');
|
||||
setIsPlaying(true);
|
||||
}}
|
||||
className={`px-3 py-1 rounded-full text-[11px] font-bold tracking-wide transition-all ${
|
||||
mode === 'transform'
|
||||
? 'bg-gradient-to-r from-blue-600 to-indigo-600 text-white shadow-sm'
|
||||
: 'text-slate-400 hover:text-white'
|
||||
}`}
|
||||
onMouseDown={() => setPeekRaw(true)}
|
||||
onMouseUp={() => setPeekRaw(false)}
|
||||
onMouseLeave={() => setPeekRaw(false)}
|
||||
onTouchStart={() => setPeekRaw(true)}
|
||||
onTouchEnd={() => setPeekRaw(false)}
|
||||
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"
|
||||
title="Press and hold to compare with raw photo"
|
||||
>
|
||||
<Zap className="w-3 h-3 inline mr-1" />
|
||||
Grain Morph
|
||||
</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
|
||||
<Eye className="w-3.5 h-3.5 text-blue-400" />
|
||||
<span className="hidden sm:inline">Hold to</span> Peek Raw
|
||||
</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>
|
||||
|
||||
{/* 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}>
|
||||
{mode === 'slider' ? (
|
||||
<BeforeAfterSlider
|
||||
beforeUrl={beforeUrl}
|
||||
afterUrl={afterUrl}
|
||||
beforeLabel={beforeLabel}
|
||||
afterLabel={afterLabel}
|
||||
autoSlide={true}
|
||||
className="h-full w-full"
|
||||
<div className="relative w-full h-full overflow-hidden bg-slate-950">
|
||||
|
||||
{/* Layer 1: Ambient Backdrop Gradient */}
|
||||
<div className="absolute inset-0 bg-gradient-to-br from-slate-950 via-indigo-950/40 to-slate-950 pointer-events-none" />
|
||||
|
||||
{/* Layer 2: The Raw Input Photo (Whole Image converts into grains via displacement & blur) */}
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<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) */}
|
||||
<div
|
||||
className="absolute inset-0 overflow-hidden pointer-events-none transition-none"
|
||||
style={{
|
||||
clipPath: `polygon(0 0, ${100 - percent}% 0, ${100 - percent}% 100%, 0 100%)`,
|
||||
}}
|
||||
>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src={beforeUrl}
|
||||
alt={beforeLabel}
|
||||
className="absolute inset-0 w-full h-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
{/* Layer 3: The AI Synthesized Result (Resolves cleanly out of the noise) */}
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src={afterUrl}
|
||||
alt={afterLabel}
|
||||
className="absolute inset-0 w-full h-full object-cover transition-none will-change-transform"
|
||||
style={{
|
||||
opacity: afterOpacity,
|
||||
filter: displacementScale > 2
|
||||
? `url(#neural-grain-displace-${grainSeed}) blur(${noiseIntensity * 2.8}px)`
|
||||
: 'none',
|
||||
transform: `scale(${1.02 - (1 - noiseIntensity) * 0.02})`,
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Layer 3: Generative Neural Grain Front (Visible along the transform edge) */}
|
||||
{progress > 0.01 && progress < 0.99 && (
|
||||
<div
|
||||
className="absolute top-0 bottom-0 pointer-events-none z-20"
|
||||
style={{
|
||||
left: `calc(${100 - percent}% - 40px)`,
|
||||
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]" />
|
||||
{/* Layer 4: Whole-Image Generative Noise Canvas (Procedural Dancing Grain Particles) */}
|
||||
<canvas
|
||||
ref={noiseCanvasRef}
|
||||
className="absolute inset-0 w-full h-full pointer-events-none z-15 mix-blend-screen"
|
||||
style={{
|
||||
opacity: Math.min(1, noiseIntensity * 1.3),
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Intense High-Frequency Animated Noise Filter along boundary */}
|
||||
<svg className="absolute inset-0 w-full h-full opacity-70 mix-blend-overlay">
|
||||
<filter id={`transform-grain-${grainSeed}`}>
|
||||
<feTurbulence
|
||||
type="fractalNoise"
|
||||
baseFrequency="0.85"
|
||||
numOctaves="4"
|
||||
seed={grainSeed}
|
||||
/>
|
||||
<feColorMatrix type="saturate" values="0" />
|
||||
</filter>
|
||||
<rect
|
||||
width="100%"
|
||||
height="100%"
|
||||
filter={`url(#transform-grain-${grainSeed})`}
|
||||
fill="#fff"
|
||||
/>
|
||||
</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>
|
||||
{/* Layer 5: High-Frequency Film Grain Overlay (Subtle photographic latent emulsion) */}
|
||||
<div
|
||||
className="absolute inset-0 pointer-events-none z-20 mix-blend-overlay"
|
||||
style={{ opacity: 0.25 + noiseIntensity * 0.55 }}
|
||||
>
|
||||
<svg className="w-full h-full">
|
||||
<filter id={`film-grain-continuous-${grainSeed}`}>
|
||||
<feTurbulence
|
||||
type="fractalNoise"
|
||||
baseFrequency="0.8"
|
||||
numOctaves="3"
|
||||
seed={grainSeed}
|
||||
/>
|
||||
<feColorMatrix type="saturate" values="0" />
|
||||
</filter>
|
||||
<rect width="100%" height="100%" filter={`url(#film-grain-continuous-${grainSeed})`} fill="#fff" />
|
||||
</svg>
|
||||
</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>
|
||||
|
||||
{/* Bottom Interactive Playback & Scrub Bar (For Grain Morph Mode) */}
|
||||
{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="flex items-center gap-3">
|
||||
{/* 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>
|
||||
{/* Bottom Interactive Generative Timeline & Controls */}
|
||||
<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">
|
||||
{/* Play / Pause Toggle */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setMode('transform');
|
||||
setIsPlaying(true);
|
||||
}}
|
||||
className="text-blue-400 hover:underline flex items-center gap-1 text-[11px]"
|
||||
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 Synthesis' : 'Play Synthesis'}
|
||||
>
|
||||
<Zap className="w-3 h-3" />
|
||||
Switch back to Grain Morph
|
||||
{isPlaying ? <Pause className="w-4 h-4" /> : <Play className="w-4 h-4" />}
|
||||
</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>
|
||||
)}
|
||||
|
||||
{/* 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>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user