From 744ec0becc26f9c731812eb206dcb96fe36b4c74 Mon Sep 17 00:00:00 2001 From: chenchun Date: Mon, 31 Aug 2026 23:39:58 +0800 Subject: [PATCH] feat: add glass models with advanced refractive shader and integrate into hero scene - Introduced GlassModels component with custom vertex and fragment shaders for realistic glass effects. - Updated HeroScene to include HelloModel and CursorStar components, utilizing the new glass shader. - Enhanced Header component with ScrambleReveal for dynamic text display and local clock functionality. - Implemented useIsMobile hook to adapt rendering based on screen size. - Adjusted StickerLayer to ensure falling stickers are captured in the glass models' FBO pass. --- .gitignore | 5 +- app/page.tsx | 108 ++++-- components/canvas/GlassModels.tsx | 563 ++++++++++++++++++++++++++++++ components/canvas/HeroScene.tsx | 25 +- components/dom/Header.tsx | 87 ++++- components/dom/ScrambleReveal.tsx | 140 ++++++++ components/webgl/StickerLayer.ts | 3 + lib/useIsMobile.ts | 18 + 8 files changed, 905 insertions(+), 44 deletions(-) create mode 100644 components/canvas/GlassModels.tsx create mode 100644 components/dom/ScrambleReveal.tsx create mode 100644 lib/useIsMobile.ts diff --git a/.gitignore b/.gitignore index 5b2eaf9..dce0379 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,7 @@ yarn-error.log* *.tsbuildinfo next-env.d.ts -haoqi_clone \ No newline at end of file +haoqi_clone + +.workbuddy/ +outputs/ \ No newline at end of file diff --git a/app/page.tsx b/app/page.tsx index 48aa3df..37b0910 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,42 +1,100 @@ +import ScrambleReveal from "@/components/dom/ScrambleReveal"; + +/** + * Page content matching the original DOM (haoqi_body.html): + * - banner section (h-dvh) with meta row + big title, all scramble-revealed + * - signature/about section (kept simple) + */ +const PASSCODE_LENGTH = 6; + export default function Home() { return (
- {/* Hero Section */} + {/* Banner Section */}
- Design &
Engineering -
- - Thinking in systems. Designing with care. - - - I'm Haoqi Wen, leading Design Engineering and AI exploration at - - ■■■■■■ - - , engineering, and AI at scale. Outside work, I build design tools for team efficiency. + +
+
+ +
-
- I bring - craft & taste - to digital work + + +
- - {/* About Section Placeholder */} -
-
-

- I explore how to shape AI-era workflows with craft and taste, building the next generation of digital products. + + {/* Signature / About Section */} +

+
+
+
+
+

+ + I explore how to shape AI-era workflows with craft and taste, + building the next generation of digital products. +

-

- I’m building reunimos™, and previously worked on Alibaba aDrive, Teambition, and 100offer. +

+ + I’m building{" "} + + reunimos™ + + , and previously worked on Alibaba{" "} + + aDrive + + ,{" "} + + Teambition + + , and 100offer. +

diff --git a/components/canvas/GlassModels.tsx b/components/canvas/GlassModels.tsx new file mode 100644 index 0000000..f4eb434 --- /dev/null +++ b/components/canvas/GlassModels.tsx @@ -0,0 +1,563 @@ +"use client"; + +import { useEffect, useMemo, useRef } from "react"; +import { useFrame, useLoader, useThree } from "@react-three/fiber"; +import * as THREE from "three"; +import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js"; +import { mergeGeometries } from "three/examples/jsm/utils/BufferGeometryUtils.js"; +import { scrollBus } from "@/lib/scrollBus"; + +/** + * Glass models for the hero section, reverse-engineered 1:1 from the + * production bundle (chunk 4d3f3b68dbbde33a.js). + * + * Both models share one refractive-glass shader: a screen-space scene-texture + * refraction (FBO of layers 1..9 rendered at half resolution) + Beer-Lambert + * tint gradient along local Y + specular + directional fresnel. + * + * Params (light theme defaults from the cloned controls): + * refractPower .72 | chromaticAberration .14 | loop 3 (RGB path) + * shininess 120 | diffuseness .1 | fresnelPower 1 | fresnelStrength .24 + * brightness .78 | contrast .9 | saturation 1.2 | specularStrength 1.2 + * tint A #009dff / B #ffffff, tintMix 1, thicknessMaxAlpha .92, minAlpha 1 + */ + +const VERT = /* glsl */ ` +varying vec3 worldNormal; +varying vec3 eyeVector; +varying float modelLocalY; + +void main() { + vec4 worldPos = modelMatrix * vec4(position, 1.0); + vec4 mvPosition = viewMatrix * worldPos; + gl_Position = projectionMatrix * mvPosition; + + worldNormal = normalize(modelMatrix * vec4(normal, 0.0)).xyz; + eyeVector = normalize(worldPos.xyz - cameraPosition); + modelLocalY = position.y; +} +`; + +const FRAG = /* glsl */ ` +uniform float uIorR; +uniform float uIorY; +uniform float uIorG; +uniform float uIorC; +uniform float uIorB; +uniform float uIorP; + +uniform float uSaturation; +uniform float uChromaticAberration; +uniform float uRefractPower; +uniform float uFresnelPower; +uniform float uShininess; +uniform float uDiffuseness; +uniform vec3 uLight; +uniform float uBrightness; +uniform float uContrast; +uniform float uGamma; +uniform float uSpecularStrength; +uniform float uFresnelStrength; +uniform vec3 uFresnelSideDir; + +uniform vec4 uTintColorA; +uniform vec4 uTintColorB; +uniform vec2 uTintLocalYRange; +uniform float uTintEnabled; +uniform float uTintMix; +uniform float uTintThicknessMinAlpha; +uniform float uTintThicknessMaxAlpha; + +uniform vec2 uScreenResolutionPx; +uniform sampler2D uTexture; +uniform float uSceneRefractionEnabled; +uniform float uRgbRefraction; +uniform float uDark; + +varying vec3 worldNormal; +varying vec3 eyeVector; +varying float modelLocalY; + +float random(vec2 p) { + return fract(sin(dot(p.xy, vec2(12.9898, 78.233))) * 43758.5453); +} + +vec3 sat(vec3 rgb, float adjustment) { + const vec3 W = vec3(0.2125, 0.7154, 0.0721); + vec3 intensity = vec3(dot(rgb, W)); + return mix(intensity, rgb, adjustment); +} + +float fresnel(vec3 eyeDir, vec3 normal, float power) { + float f = abs(dot(eyeDir, normal)); + return pow(1.0 - f, power); +} + +float specular(vec3 light, vec3 normal, vec3 eyeDir, float shininess, float diffuseness) { + vec3 lightVector = normalize(-light); + vec3 halfVector = normalize(eyeDir + lightVector); + + float NdotL = dot(normal, lightVector); + float NdotH = abs(dot(normal, halfVector)); + float kDiffuse = max(0.0, NdotL); + float kSpecular = pow(NdotH, shininess); + return kSpecular + kDiffuse * diffuseness; +} + +uniform int uLoop; + +void main() { + vec2 uv = gl_FragCoord.xy / uScreenResolutionPx.xy; + vec3 normal = normalize(worldNormal); + vec3 eyeDir = normalize(eyeVector); + vec3 color; + + if (uSceneRefractionEnabled > 0.5) { + color = vec3(0.0); + float noise = random(uv) * 0.025; + + if (uRgbRefraction > 0.5) { + vec3 refractVecR = refract(eyeDir, normal, (1.0 / uIorR)); + vec3 refractVecG = refract(eyeDir, normal, (1.0 / uIorG)); + vec3 refractVecB = refract(eyeDir, normal, (1.0 / uIorB)); + + for (int i = 0; i < uLoop; i++) { + float slide = float(i) / float(uLoop) * 0.1 + noise; + float offset = (uRefractPower + slide) * uChromaticAberration; + + color.r += texture2D(uTexture, uv + refractVecR.xy * offset).r; + color.g += texture2D(uTexture, uv + refractVecG.xy * offset).g; + color.b += texture2D(uTexture, uv + refractVecB.xy * offset).b; + } + } else { + vec3 refractVecR = refract(eyeDir, normal, (1.0 / uIorR)); + vec3 refractVecY = refract(eyeDir, normal, (1.0 / uIorY)); + vec3 refractVecG = refract(eyeDir, normal, (1.0 / uIorG)); + vec3 refractVecC = refract(eyeDir, normal, (1.0 / uIorC)); + vec3 refractVecB = refract(eyeDir, normal, (1.0 / uIorB)); + vec3 refractVecP = refract(eyeDir, normal, (1.0 / uIorP)); + + for (int i = 0; i < uLoop; i++) { + float slide = float(i) / float(uLoop) * 0.1 + noise; + + float offsetR = (uRefractPower + slide * 1.0) * uChromaticAberration; + float offsetY = (uRefractPower + slide * 1.0) * uChromaticAberration; + float offsetG = (uRefractPower + slide * 2.0) * uChromaticAberration; + float offsetC = (uRefractPower + slide * 2.5) * uChromaticAberration; + float offsetB = (uRefractPower + slide * 3.0) * uChromaticAberration; + float offsetP = (uRefractPower + slide * 1.0) * uChromaticAberration; + + float r = texture2D(uTexture, uv + refractVecR.xy * offsetR).x * 0.5; + + vec3 ySample = texture2D(uTexture, uv + refractVecY.xy * offsetY).xyz; + float y = (ySample.x * 2.0 + ySample.y * 2.0 - ySample.z) / 6.0; + + float g = texture2D(uTexture, uv + refractVecG.xy * offsetG).y * 0.5; + + vec3 cSample = texture2D(uTexture, uv + refractVecC.xy * offsetC).xyz; + float c = (cSample.y * 2.0 + cSample.z * 2.0 - cSample.x) / 6.0; + + float b = texture2D(uTexture, uv + refractVecB.xy * offsetB).z * 0.5; + + vec3 pSample = texture2D(uTexture, uv + refractVecP.xy * offsetP).xyz; + float p = (pSample.z * 2.0 + pSample.x * 2.0 - pSample.y) / 6.0; + + float R = r + (2.0 * p + 2.0 * y - c) / 3.0; + float G = g + (2.0 * y + 2.0 * c - p) / 3.0; + float B = b + (2.0 * c + 2.0 * p - y) / 3.0; + + color.r += R; + color.g += G; + color.b += B; + } + } + + color /= float(uLoop); + } else { + color = texture2D(uTexture, uv).rgb; + } + + color = sat(color, uSaturation); + + color *= uBrightness; + color = (color - 0.5) * uContrast + 0.5; + float invGamma = 1.0 / max(uGamma, 0.0001); + color = pow(max(color, 0.0), vec3(invGamma)); + + float mode = clamp(uDark, 0.0, 1.0); + + // --- Beer-Lambert --- + float localYMin = uTintLocalYRange.x; + float localYMax = uTintLocalYRange.y; + float localYDenominator = max(localYMax - localYMin, 1e-5); + float tintGradientFactor = clamp((modelLocalY - localYMin) / localYDenominator, 0.0, 1.0); + vec4 tintColorGradient = mix(uTintColorB, uTintColorA, tintGradientFactor); + + float ndotv = abs(dot(normal, eyeDir)); + float thicknessMask = clamp(1.0 - ndotv, 0.0, 1.0); + float tintAlpha = clamp(tintColorGradient.a, 0.0, 1.0); + float minAlpha = clamp(uTintThicknessMinAlpha, 0.0, 1.0); + float maxAlpha = clamp(uTintThicknessMaxAlpha, 0.0, 1.0); + tintAlpha *= mix(maxAlpha, minAlpha, thicknessMask); + + float tintK_beer = clamp(uTintEnabled, 0.0, 1.0) * tintAlpha; + vec3 tintColorClamped = clamp(tintColorGradient.rgb, 0.001, 1.0); + float thickness = clamp(uTintMix, 0.01, 3.0); + vec3 transmittance = pow(tintColorClamped, vec3(thickness)); + vec3 beerColor = mix(color, color * transmittance, tintK_beer); + + // --- Hard Light --- + float tintK_hard = clamp(uTintEnabled, 0.0, 1.0) * clamp(uTintMix, 0.0, 1.0) * tintAlpha; + vec3 baseClamped = clamp(color, 0.0, 1.0); + vec3 blendClamped = clamp(tintColorGradient.rgb, 0.0, 1.0); + // Hard Light blend: 2*blend*base where base < 0.5, screen elsewhere + vec3 hard = mix( + 2.0 * blendClamped * baseClamped, + 1.0 - 2.0 * (1.0 - blendClamped) * (1.0 - baseClamped), + step(0.5, baseClamped) + ); + vec3 hardColor = mix(color, hard, tintK_hard); + + color = mix(beerColor, hardColor, mode); + + float specularLight = specular(uLight, normal, eyeDir, uShininess, uDiffuseness); + color += specularLight * uSpecularStrength; + + float f = fresnel(eyeDir, normal, uFresnelPower); + float sideDot = dot(normal, normalize(uFresnelSideDir)); + float sideMask = smoothstep(-0.5, 0.5, sideDot); + color.rgb += f * sideMask * vec3(uFresnelStrength); + + gl_FragColor = vec4(color, 1.0); + #include + #include +} +`; + +// Light-theme control defaults (cloned controls, light branch) +const LIGHT_PARAMS = { + refractPower: 0.72, + chromaticAberration: 0.14, + shininess: 120, + diffuseness: 0.1, + fresnelPower: 1, + fresnelStrength: 0.24, + brightness: 0.78, + contrast: 0.9, + gamma: 1, + saturation: 1.2, + specularStrength: 1.2, + loop: 3, + tintMix: 1, + tintColorA: "#009dff", + tintColorB: "#ffffff", + tintThicknessMinAlpha: 1, + tintThicknessMaxAlpha: 0.92, + fresnelSideDir: [-1, 1, -1] as [number, number, number], + lightZ: 0.5, +}; + +// Default uniforms from the bundle's uniform factory +const IOR = { R: 1.15, Y: 1.16, G: 1.18, C: 1.22, B: 1.22, P: 1.22 }; + +function hexToVec4(hex: string, alpha = 1): THREE.Vector4 { + const c = new THREE.Color(hex); + return new THREE.Vector4(c.r, c.g, c.b, alpha); +} + +type GlassModelProps = { + url: string; + position?: [number, number, number]; + beforeRotation?: [number, number, number]; + rotation?: [number, number, number]; + afterRotation?: [number, number, number]; + rotationAxisTilt?: [number, number, number]; + scale?: number; + tintColors?: [string, string] | [string, string, string, string]; + tintEnabled?: boolean; + scrollSyncFactor?: number; + floating?: boolean; +}; + +function useFloatOffset(enabled: boolean) { + const t = useRef(0); + useFrame((state, delta) => { + t.current += delta; + }); + return useMemo( + () => (time: number) => + enabled ? 0.18 * Math.sin(1.2 * time) + 0.06 * Math.sin(0.6 * time) : 0, + [enabled] + ); +} + +function GlassModel({ + url, + position = [0, 0, 0], + beforeRotation, + rotation = [0, 0, 0], + afterRotation, + rotationAxisTilt = [0, 0, 0], + scale = 1, + tintColors, + tintEnabled = false, + scrollSyncFactor = 0.72, + floating = true, +}: GlassModelProps) { + const gltf = useLoader(GLTFLoader, url); + const groupRef = useRef(null!); + const spinRef = useRef(null!); + const materialRef = useRef(null!); + const meshLayerRef = useRef(null!); + const scene = useThree((s) => s.scene); + const gl = useThree((s) => s.gl); + const size = useThree((s) => s.size); + const camera = useThree((s) => s.camera); + + // Merge all mesh geometries into one, centered (same as original cb/cd) + const mergedGeometry = useMemo(() => { + gltf.scene.updateMatrixWorld(true); + const geometries: THREE.BufferGeometry[] = []; + gltf.scene.traverse((obj) => { + if ((obj as THREE.Mesh).isMesh && (obj as THREE.Mesh).geometry) { + const geo = (obj as THREE.Mesh).geometry.clone(); + geo.applyMatrix4((obj as THREE.Mesh).matrixWorld); + geometries.push(geo); + } + }); + if (geometries.length === 0) return null; + let merged: THREE.BufferGeometry | null = null; + try { + merged = mergeGeometries(geometries, false); + } catch { + merged = null; + } + if (!merged && geometries.length === 1) merged = geometries[0]; + if (!merged) return null; + merged.computeBoundingBox(); + const bb = merged.boundingBox!; + const cx = (bb.min.x + bb.max.x) / 2; + const cy = (bb.min.y + bb.max.y) / 2; + const cz = (bb.min.z + bb.max.z) / 2; + if (Math.abs(cx) + Math.abs(cy) + Math.abs(cz) >= 1e-8) { + merged.translate(-cx, -cy, -cz); + merged.computeBoundingSphere(); + } + return merged; + }, [gltf]); + + // Glass renders on layers 0+10: visible in the main pass, excluded from the + // layer-1 FBO pass that feeds the refraction texture (no self-refraction). + useEffect(() => { + meshLayerRef.current?.layers.enable(10); + }, [mergedGeometry]); + + const tintYRange = useMemo<[number, number]>(() => { + if (!mergedGeometry) return [0, 1]; + if (!mergedGeometry.boundingBox) mergedGeometry.computeBoundingBox(); + const bb = mergedGeometry.boundingBox!; + return Math.abs(bb.max.y - bb.min.y) < 1e-6 + ? [bb.min.y, bb.min.y + 1] + : [bb.min.y, bb.max.y]; + }, [mergedGeometry]); + + // Scene-texture FBO: render layer 1 (background + stickers) at half res + const fbo = useMemo(() => { + const dpr = gl.getPixelRatio(); + const w = Math.max(2, Math.floor((size.width * dpr) / 2)); + const h = Math.max(2, Math.floor((size.height * dpr) / 2)); + const target = new THREE.WebGLRenderTarget(w, h, { + stencilBuffer: false, + depthBuffer: true, + samples: 0, + }); + return target; + }, [gl, size.width, size.height]); + + useEffect(() => { + return () => { + fbo.dispose(); + }; + }, [fbo]); + + const uniforms = useMemo( + () => ({ + uIorR: { value: IOR.R }, + uIorY: { value: IOR.Y }, + uIorG: { value: IOR.G }, + uIorC: { value: IOR.C }, + uIorB: { value: IOR.B }, + uIorP: { value: IOR.P }, + uRefractPower: { value: LIGHT_PARAMS.refractPower }, + uChromaticAberration: { value: LIGHT_PARAMS.chromaticAberration }, + uSaturation: { value: LIGHT_PARAMS.saturation }, + uShininess: { value: LIGHT_PARAMS.shininess }, + uDiffuseness: { value: LIGHT_PARAMS.diffuseness }, + uFresnelPower: { value: LIGHT_PARAMS.fresnelPower }, + uBrightness: { value: LIGHT_PARAMS.brightness }, + uContrast: { value: LIGHT_PARAMS.contrast }, + uGamma: { value: LIGHT_PARAMS.gamma }, + uSpecularStrength: { value: LIGHT_PARAMS.specularStrength }, + uFresnelStrength: { value: LIGHT_PARAMS.fresnelStrength }, + uFresnelSideDir: { + value: new THREE.Vector3(...LIGHT_PARAMS.fresnelSideDir), + }, + uTintColorA: { + value: hexToVec4(tintColors ? tintColors[0] : LIGHT_PARAMS.tintColorA), + }, + uTintColorB: { + value: hexToVec4(tintColors ? tintColors[1] : LIGHT_PARAMS.tintColorB), + }, + uTintLocalYRange: { value: new THREE.Vector2(0, 1) }, + uTintEnabled: { value: tintEnabled ? 1 : 0 }, + uTintMix: { value: LIGHT_PARAMS.tintMix }, + uTintThicknessMinAlpha: { value: LIGHT_PARAMS.tintThicknessMinAlpha }, + uTintThicknessMaxAlpha: { value: LIGHT_PARAMS.tintThicknessMaxAlpha }, + uDark: { value: 0 }, + uLoop: { value: LIGHT_PARAMS.loop }, + uSceneRefractionEnabled: { value: 1 }, + uRgbRefraction: { value: 1 }, + uLight: { value: new THREE.Vector3(4, 9, LIGHT_PARAMS.lightZ) }, + uScreenResolutionPx: { value: new THREE.Vector2(1, 1) }, + uTexture: { value: fbo.texture }, + }), + [tintColors, tintEnabled, fbo] + ); + + useEffect(() => { + uniforms.uTintLocalYRange.value.set(tintYRange[0], tintYRange[1]); + }, [tintYRange, uniforms]); + + useEffect(() => { + const drawingBufferSize = gl.getDrawingBufferSize(new THREE.Vector2()); + uniforms.uScreenResolutionPx.value.set( + drawingBufferSize.x, + drawingBufferSize.y + ); + }, [gl, size, uniforms]); + + // Entrance animation: damp rotation from beforeRotation -> rotation -> afterRotation + const entrance = useRef({ started: false, elapsed: 0 }); + + const getFloat = useFloatOffset(floating); + + useFrame((state, rawDelta) => { + const delta = Math.min(rawDelta, 0.1); + + // Render the scene (layer 1 only) into the FBO for refraction. + // Background/sticker content must be on layer 1; glass models render on + // layer 0 + 10 (10 excluded from the FBO pass to avoid self-refraction). + const prevTarget = gl.getRenderTarget(); + const prevAutoClear = gl.autoClear; + const cameraMask = camera.layers.mask; + gl.setRenderTarget(fbo); + gl.clear(); + camera.layers.set(1); + gl.render(scene, camera); + camera.layers.mask = cameraMask; + gl.setRenderTarget(prevTarget); + gl.autoClear = prevAutoClear; + + const g = groupRef.current; + const spin = spinRef.current; + if (!g) return; + + // Scroll sync: model y follows document anchor with factor 0.72 + const viewportHeight = + state.viewport.getCurrentViewport(camera, new THREE.Vector3(0, 0, position[2])) + .height; + const docProgress = scrollBus.progress; // 0..1 + // Original: worldY from section anchor docY with scrollSyncFactor; here we + // approximate: hero content center scrolls up as user scrolls. + const scrollWorldY = docProgress * viewportHeight * scrollSyncFactor; + const float = getFloat(state.clock.getElapsedTime()); + g.position.y = position[1] - scrollWorldY + float; + g.position.x = position[0]; + g.position.z = position[2]; + + // Entrance rotation damp + const before = beforeRotation ?? rotation; + const after = afterRotation ?? null; + const e = entrance.current; + if (!e.started) { + e.started = true; + e.elapsed = 0; + } + e.elapsed += delta; + const lambda = 6; + const mix = 1 - Math.exp(-lambda * e.elapsed); + const rad = (v: number) => THREE.MathUtils.degToRad(v); + let tx = THREE.MathUtils.lerp(rad(before[0]), rad(rotation[0]), mix); + let ty = THREE.MathUtils.lerp(rad(before[1]), rad(rotation[1]), mix); + let tz = THREE.MathUtils.lerp(rad(before[2]), rad(rotation[2]), mix); + if (after) { + // after phase ramps in after entry (~2s), slowly continuing to afterRotation + const afterMix = 1 - Math.exp(-lambda * Math.max(0, e.elapsed - 2)); + tx = THREE.MathUtils.lerp(tx, rad(after[0]), afterMix); + ty = THREE.MathUtils.lerp(ty, rad(after[1]), afterMix); + tz = THREE.MathUtils.lerp(tz, rad(after[2]), afterMix); + } + if (spin) { + spin.rotation.x = THREE.MathUtils.damp(spin.rotation.x, tx, 6, delta); + spin.rotation.y = THREE.MathUtils.damp(spin.rotation.y, ty, 6, delta); + spin.rotation.z = THREE.MathUtils.damp(spin.rotation.z, tz, 6, delta); + } + }, -2); + + if (!mergedGeometry) return null; + + return ( + + + + + + + + + + ); +} + +export function HelloModel({ isMobile = false }: { isMobile?: boolean }) { + return ( + + ); +} + +export function CursorStar({ isMobile = false }: { isMobile?: boolean }) { + return ( + + ); +} diff --git a/components/canvas/HeroScene.tsx b/components/canvas/HeroScene.tsx index ce87d6b..7fafe30 100644 --- a/components/canvas/HeroScene.tsx +++ b/components/canvas/HeroScene.tsx @@ -1,11 +1,27 @@ "use client"; -import { Canvas } from "@react-three/fiber"; +import { useEffect, useMemo, useRef } from "react"; +import { Canvas, useFrame, useThree } from "@react-three/fiber"; import { PerspectiveCamera } from "@react-three/drei"; +import * as THREE from "three"; import { StickerDrop, StickerCamera } from "@/components/canvas/StickerDrop"; +import { HelloModel, CursorStar } from "@/components/canvas/GlassModels"; +import { useIsMobile } from "@/lib/useIsMobile"; + +/** + * Hero canvas: falling stickers + glass hello/cursor models. + * + * The glass shader refracts a scene texture rendered into an FBO from layer 1. + * BackgroundGrid lives in the DOM (below the canvas), so it can't be refracted; + * the FBO pass still captures the sticker particles, giving the glass its + * refraction content — the same hierarchy the original achieves with its + * "glass hosting section" FBO. + */ export function HeroScene() { + const isMobile = useIsMobile(); + return ( // z-30 keeps it above the BackgroundGrid (z-20) to prevent mix-blend-difference from making it gray
@@ -19,8 +35,13 @@ export function HeroScene() { - {/* Falling stickers: 1:1 re-implementation of the original particle system */} + {/* Falling stickers: 1:1 re-implementation of the original particle system. + Rendered on layer 1 so the glass FBO pass can capture them. */} + + {/* Glass hero models (hello + blue cursor star), refractive tint shader */} + +
); diff --git a/components/dom/Header.tsx b/components/dom/Header.tsx index 0781240..a953a8a 100644 --- a/components/dom/Header.tsx +++ b/components/dom/Header.tsx @@ -1,34 +1,89 @@ +"use client"; + +import { useEffect, useState } from "react"; +import ScrambleReveal from "@/components/dom/ScrambleReveal"; + +/** + * Header, matching the original: scramble-revealed labels (startDelay 300), + * live local clock (HH:MM, minute tick), and a center coordinate readout + * driven by the pointer (normalized position × viewport size, zero-padded 4). + */ export default function Header() { + const [time, setTime] = useState("--:--"); + const [coords, setCoords] = useState({ x: "0001", y: "0001" }); + + useEffect(() => { + const tick = () => { + const d = new Date(); + setTime( + `${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}` + ); + }; + tick(); + const interval = window.setInterval(tick, 60_000); + return () => window.clearInterval(interval); + }, []); + + useEffect(() => { + const onMove = (e: PointerEvent) => { + const x = Math.round(e.clientX); + const y = Math.round( + (window.innerHeight || 0) - e.clientY + ); + setCoords({ + x: String(Math.max(0, x)).padStart(4, "0").slice(0, 4), + y: String(Math.max(0, y)).padStart(4, "0").slice(0, 4), + }); + }; + window.addEventListener("pointermove", onMove, { passive: true }); + return () => window.removeEventListener("pointermove", onMove); + }, []); + + const dotted = + "relative before:content-[''] before:absolute before:inset-0 before:border-2 before:border-dotted before:border-transparent before:pointer-events-none before:transition-colors before:duration-200 lg:hover:before:border-l1"; + return (
- - haoqi.design + +
- - - - THEME[A] + + - - SOUND[|] + +
- --:-- - GMT+8 CN --:-- - - 0001 X 0001 Y + + + + + + +
diff --git a/components/dom/ScrambleReveal.tsx b/components/dom/ScrambleReveal.tsx new file mode 100644 index 0000000..d3388f3 --- /dev/null +++ b/components/dom/ScrambleReveal.tsx @@ -0,0 +1,140 @@ +"use client"; + +import { useEffect, useMemo, useRef, useState } from "react"; + +/** + * 1:1 re-implementation of the original scramble-reveal text (chunk + * 2689132c4e070b68.js component `d`): + * + * - charset `ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*+-=?/<>[]{}` picked + * randomly per render while a character is "scrambling" + * - char i starts scrambling at startDelayMs + i*letterDelayMs and settles + * after a window of 4*letterDelayMs (2 phases × 2*letterDelayMs) + * - phase 0 color #c0fe04, phase 1 color #607F02 (light theme) unless + * scrambleColors is false + * - refresh tick every 40ms; the whole text settles at + * startDelayMs + (n-1)*letterDelayMs + 4*letterDelayMs + * - starts once when the element enters the viewport (threshold 0.1) + */ +const CHARSET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*+-=?/<>[]{}"; +const COLORS_LIGHT = ["#c0fe04", "#607F02"]; + +const randomChar = () => CHARSET[Math.floor(Math.random() * CHARSET.length)]; + +type Props = { + text?: string; + parts?: string[]; + className?: string; + startDelayMs?: number; + letterDelayMs?: number; + scrambleColors?: boolean; +}; + +export default function ScrambleReveal({ + text, + parts, + className, + startDelayMs = 0, + letterDelayMs = 80, + scrambleColors = true, +}: Props) { + const strings = useMemo( + () => (parts ? parts : [text ?? ""]), + [parts, text] + ); + const ref = useRef(null); + const [entered, setEntered] = useState(false); + const [startedAt, setStartedAt] = useState(null); + const [elapsed, setElapsed] = useState(0); + + const F = strings.join("").length; + const phaseLen = 2 * letterDelayMs; // j + const scrambleWindow = 2 * phaseLen; // D + const total = startDelayMs + Math.max(0, F - 1) * letterDelayMs + scrambleWindow; + + useEffect(() => { + const el = ref.current; + if (!el) return; + const observer = new IntersectionObserver( + ([entry]) => { + if (entry.isIntersecting) { + setEntered(true); + observer.disconnect(); + } + }, + { threshold: 0.1 } + ); + observer.observe(el); + return () => observer.disconnect(); + }, []); + + useEffect(() => { + if (!entered || startedAt !== null) return; + const t0 = performance.now(); + setStartedAt(t0); + setElapsed(0); + }, [entered, startedAt]); + + useEffect(() => { + if (startedAt === null) return; + if (elapsed >= total) return; + const interval = window.setInterval(() => { + setElapsed(performance.now() - startedAt); + }, 40); + return () => window.clearInterval(interval); + }, [startedAt, elapsed, total]); + + const settled = startedAt !== null && elapsed >= total; + const V = Math.max(0, elapsed - startDelayMs); + const scrambling = startedAt !== null && !settled; + + if (settled || !entered) { + return ( + + {strings.map((s, i) => ( + {entered ? s : ""} + ))} + + ); + } + + // recompute random chars on each elapsed tick + let index = 0; + return ( + + {strings.map((s, si) => ( + + {s.split("").map((ch, ci) => { + const i = index++; + if (ch === "\n") return
; + if (ch === " ") return ; + const n = i * letterDelayMs; + if (V < n) { + return ( + + {ch} + + ); + } + if (V < n + scrambleWindow) { + const phase = Math.min( + 1, + Math.floor((V - n) / phaseLen) + ); + const color = scrambleColors ? COLORS_LIGHT[phase] : undefined; + return ( + + {randomChar()} + + ); + } + return {ch}; + })} +
+ ))} +
+ ); +} diff --git a/components/webgl/StickerLayer.ts b/components/webgl/StickerLayer.ts index 2cdddb7..76086c5 100644 --- a/components/webgl/StickerLayer.ts +++ b/components/webgl/StickerLayer.ts @@ -323,6 +323,9 @@ export class StickerLayer { ); mesh.frustumCulled = false; mesh.count = 0; + // Layer 1: the glass models' FBO pass captures only this layer, so the + // falling stickers appear refracted through the hello/cursor glass. + mesh.layers.set(1); this.geometry = geometry; this.material = material; diff --git a/lib/useIsMobile.ts b/lib/useIsMobile.ts new file mode 100644 index 0000000..a839a52 --- /dev/null +++ b/lib/useIsMobile.ts @@ -0,0 +1,18 @@ +"use client"; + +import { useEffect, useState } from "react"; + +/** Matches the original's useIsMobileWidth: < 1024px. */ +export function useIsMobile(): boolean { + const [mobile, setMobile] = useState(false); + + useEffect(() => { + const mq = window.matchMedia("(max-width: 1023px)"); + const update = () => setMobile(mq.matches); + update(); + mq.addEventListener("change", update); + return () => mq.removeEventListener("change", update); + }, []); + + return mobile; +}