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.
This commit is contained in:
@@ -41,3 +41,6 @@ yarn-error.log*
|
|||||||
next-env.d.ts
|
next-env.d.ts
|
||||||
|
|
||||||
haoqi_clone
|
haoqi_clone
|
||||||
|
|
||||||
|
.workbuddy/
|
||||||
|
outputs/
|
||||||
+80
-22
@@ -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() {
|
export default function Home() {
|
||||||
return (
|
return (
|
||||||
<main className="w-full h-full overflow-y-auto overscroll-contain no-scrollbar">
|
<main className="w-full h-full overflow-y-auto overscroll-contain no-scrollbar">
|
||||||
<div>
|
<div>
|
||||||
{/* Hero Section */}
|
{/* Banner Section */}
|
||||||
<div className="grid grid-cols-12 grid-rows-[auto_1fr] px-4 lg:px-14 py-18 lg:py-24 w-full h-dvh lg:h-screen">
|
<div className="grid grid-cols-12 grid-rows-[auto_1fr] px-4 lg:px-14 py-18 lg:py-24 w-full h-dvh lg:h-screen">
|
||||||
<div className="flex flex-col order-2 lg:order-1 lg:grid lg:grid-cols-12 col-span-12 font-mono text-base relative z-30">
|
<div className="flex flex-col order-2 lg:order-1 lg:grid lg:grid-cols-12 col-span-12 font-mono text-base relative z-30">
|
||||||
<span className="hidden lg:block lg:col-span-3 xl:col-span-2 lg:col-start-1 xl:col-start-1 p-2 font-sans font-medium text-[4svw] sm:text-2xl lg:text-3xl leading-tight">
|
<span className="hidden lg:block lg:col-span-3 xl:col-span-2 lg:col-start-1 xl:col-start-1 p-2 font-sans font-medium text-[4svw] sm:text-2xl lg:text-3xl leading-tight">
|
||||||
Design &<br />Engineering
|
<ScrambleReveal text="Design &" startDelayMs={300} letterDelayMs={10} />
|
||||||
</span>
|
<br />
|
||||||
<span className="hidden lg:block lg:col-span-3 xl:col-span-2 lg:col-start-4 xl:col-start-5 p-2 text-balance">
|
<ScrambleReveal text="Engineering" startDelayMs={300} letterDelayMs={10} />
|
||||||
Thinking in systems. Designing with care.
|
|
||||||
</span>
|
|
||||||
<span className="col-span-12 lg:col-span-6 xl:col-span-4 lg:col-start-7 xl:col-start-9 mt-auto lg:mt-0 p-2">
|
|
||||||
I'm Haoqi Wen, leading Design Engineering and AI exploration at
|
|
||||||
<span className="inline-flex items-baseline gap-[0.12em] mx-[0.06em] align-baseline cursor-pointer select-text mx-1">
|
|
||||||
■■■■■■
|
|
||||||
</span>
|
|
||||||
, engineering, and AI at scale. Outside work, I build design tools for team efficiency.
|
|
||||||
</span>
|
</span>
|
||||||
|
<ScrambleReveal
|
||||||
|
className="hidden lg:block lg:col-span-3 xl:col-span-2 lg:col-start-4 xl:col-start-5 p-2 text-balance"
|
||||||
|
text="Thinking in systems. Designing with care."
|
||||||
|
startDelayMs={300}
|
||||||
|
letterDelayMs={10}
|
||||||
|
/>
|
||||||
|
<ScrambleReveal
|
||||||
|
className="col-span-12 lg:col-span-6 xl:col-span-4 lg:col-start-7 xl:col-start-9 mt-auto lg:mt-0 p-2"
|
||||||
|
startDelayMs={300}
|
||||||
|
letterDelayMs={10}
|
||||||
|
parts={[
|
||||||
|
"I'm Haoqi Wen, leading Design Engineering and AI exploration at ",
|
||||||
|
"■".repeat(PASSCODE_LENGTH),
|
||||||
|
", engineering, and AI at scale. Outside work, I build design tools for team efficiency.",
|
||||||
|
]}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className="flex flex-col self-end order-1 lg:order-2 col-span-12 px-2 font-bold text-[7.2svw] lg:text-[6svw] 2xl:text-[5svw] xl:text-[5.6svw] uppercase leading-none relative z-30"
|
className="flex flex-col self-end order-1 lg:order-2 col-span-12 px-2 font-bold text-[7.2svw] lg:text-[6svw] 2xl:text-[5svw] xl:text-[5.6svw] uppercase leading-none relative z-30"
|
||||||
style={{ fontVariationSettings: '"wdth" 120' }}
|
style={{ fontVariationSettings: '"wdth" 120' }}
|
||||||
>
|
>
|
||||||
<span>I bring</span>
|
<ScrambleReveal text="I bring" startDelayMs={300} />
|
||||||
<span>craft & taste</span>
|
<ScrambleReveal text="craft & taste" startDelayMs={500} />
|
||||||
<span>to digital work</span>
|
<ScrambleReveal text="to digital work" startDelayMs={700} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* About Section Placeholder */}
|
{/* Signature / About Section */}
|
||||||
<div className="grid grid-cols-12 grid-rows-1 px-4 lg:px-14 py-24 w-full min-h-screen relative z-30">
|
<div className="grid grid-cols-12 px-4 lg:px-14 py-18 lg:py-24 lg:pb-28 w-full relative z-30">
|
||||||
<div className="col-span-12 lg:col-span-10 xl:col-span-8 lg:col-start-2 xl:col-start-3 flex flex-col justify-center font-medium text-[5svw] lg:text-[4svw] leading-snug">
|
<div className="relative col-span-12 sm:col-span-4 lg:col-span-3 p-2">
|
||||||
<p className="mb-12">
|
<div className="aspect-square" />
|
||||||
I explore how to shape AI-era workflows with craft and taste, building the next generation of digital products.
|
</div>
|
||||||
|
<div className="flex flex-col justify-start items-start gap-6 col-span-12 sm:col-span-7 lg:col-span-8 sm:col-start-6 lg:col-start-5 text-base lg:text-xl leading-none">
|
||||||
|
<p
|
||||||
|
className="p-2 w-full text-l1 md:text-[4.2svw] text-xl leading-[1.3] md:leading-none select-text"
|
||||||
|
style={{ fontFamily: "var(--font-tiktok), sans-serif" }}
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
I explore how to shape AI-era workflows with craft and taste,
|
||||||
|
building the next generation of digital products.
|
||||||
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p
|
||||||
I’m building <a href="https://reunimos.cc/" target="_blank" rel="noreferrer" className="underline decoration-1 underline-offset-4 hover:opacity-70 transition-opacity">reunimos™</a>, and previously worked on Alibaba <a href="https://www.alipan.com/" target="_blank" rel="noreferrer" className="underline decoration-1 underline-offset-4 hover:opacity-70 transition-opacity">aDrive</a>, <a href="https://www.teambition.com/" target="_blank" rel="noreferrer" className="underline decoration-1 underline-offset-4 hover:opacity-70 transition-opacity">Teambition</a>, and 100offer.
|
className="p-2 w-full text-l2 md:text-[4.2svw] text-xl leading-[1.3] md:leading-none select-text"
|
||||||
|
style={{ fontFamily: "var(--font-tiktok), sans-serif" }}
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
I’m building{" "}
|
||||||
|
<a
|
||||||
|
href="https://reunimos.cc"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="inline text-l1 underline underline-offset-[0.08em] decoration-solid decoration-l3 transition-[text-decoration-color] duration-150 ease-out lg:hover:decoration-l1"
|
||||||
|
>
|
||||||
|
reunimos™
|
||||||
|
</a>
|
||||||
|
, and previously worked on Alibaba{" "}
|
||||||
|
<a
|
||||||
|
href="https://www.alipan.com/"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="inline text-l1 underline underline-offset-[0.08em] decoration-solid decoration-l3 transition-[text-decoration-color] duration-150 ease-out lg:hover:decoration-l1"
|
||||||
|
>
|
||||||
|
aDrive
|
||||||
|
</a>
|
||||||
|
,{" "}
|
||||||
|
<a
|
||||||
|
href="https://www.teambition.com/"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="inline text-l1 underline underline-offset-[0.08em] decoration-solid decoration-l3 transition-[text-decoration-color] duration-150 ease-out lg:hover:decoration-l1"
|
||||||
|
>
|
||||||
|
Teambition
|
||||||
|
</a>
|
||||||
|
, and 100offer.
|
||||||
|
</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -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 <tonemapping_fragment>
|
||||||
|
#include <colorspace_fragment>
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
// 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<THREE.Group>(null!);
|
||||||
|
const spinRef = useRef<THREE.Group>(null!);
|
||||||
|
const materialRef = useRef<THREE.ShaderMaterial>(null!);
|
||||||
|
const meshLayerRef = useRef<THREE.Mesh>(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 (
|
||||||
|
<group ref={groupRef} position={position}>
|
||||||
|
<group rotation={rotationAxisTilt}>
|
||||||
|
<group ref={spinRef} rotation={rotation}>
|
||||||
|
<mesh
|
||||||
|
ref={meshLayerRef}
|
||||||
|
geometry={mergedGeometry}
|
||||||
|
scale={[scale, scale, scale]}
|
||||||
|
>
|
||||||
|
<shaderMaterial
|
||||||
|
ref={materialRef}
|
||||||
|
vertexShader={VERT}
|
||||||
|
fragmentShader={FRAG}
|
||||||
|
uniforms={uniforms}
|
||||||
|
toneMapped={false}
|
||||||
|
transparent
|
||||||
|
/>
|
||||||
|
</mesh>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function HelloModel({ isMobile = false }: { isMobile?: boolean }) {
|
||||||
|
return (
|
||||||
|
<GlassModel
|
||||||
|
url="/model/hello.gltf"
|
||||||
|
position={[-0.1, 0, 2]}
|
||||||
|
beforeRotation={[0, 240, 0]}
|
||||||
|
afterRotation={[0, 90, 0]}
|
||||||
|
rotation={[0, 4, 0]}
|
||||||
|
scale={isMobile ? 19 : 22}
|
||||||
|
tintEnabled
|
||||||
|
scrollSyncFactor={0.72}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CursorStar({ isMobile = false }: { isMobile?: boolean }) {
|
||||||
|
return (
|
||||||
|
<GlassModel
|
||||||
|
url="/model/cursor.glb"
|
||||||
|
position={isMobile ? [6.6, -5.6, -3] : [11.6, -4.2, -3]}
|
||||||
|
rotationAxisTilt={[0, 0, 45]}
|
||||||
|
beforeRotation={[0, 0, 0]}
|
||||||
|
afterRotation={[0, 720, 0]}
|
||||||
|
rotation={[0, 0, 0]}
|
||||||
|
scale={0.1}
|
||||||
|
tintColors={["#009dff", "#64c3ff"]}
|
||||||
|
tintEnabled
|
||||||
|
scrollSyncFactor={0.72}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,11 +1,27 @@
|
|||||||
"use client";
|
"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 { PerspectiveCamera } from "@react-three/drei";
|
||||||
|
import * as THREE from "three";
|
||||||
|
|
||||||
import { StickerDrop, StickerCamera } from "@/components/canvas/StickerDrop";
|
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() {
|
export function HeroScene() {
|
||||||
|
const isMobile = useIsMobile();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
// z-30 keeps it above the BackgroundGrid (z-20) to prevent mix-blend-difference from making it gray
|
// z-30 keeps it above the BackgroundGrid (z-20) to prevent mix-blend-difference from making it gray
|
||||||
<div className="z-30 fixed inset-0 w-full h-full pointer-events-none">
|
<div className="z-30 fixed inset-0 w-full h-full pointer-events-none">
|
||||||
@@ -19,8 +35,13 @@ export function HeroScene() {
|
|||||||
<PerspectiveCamera makeDefault position={[0, 0, 24]} near={0.1} far={200} />
|
<PerspectiveCamera makeDefault position={[0, 0, 24]} near={0.1} far={200} />
|
||||||
<StickerCamera />
|
<StickerCamera />
|
||||||
|
|
||||||
{/* 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. */}
|
||||||
<StickerDrop />
|
<StickerDrop />
|
||||||
|
|
||||||
|
{/* Glass hero models (hello + blue cursor star), refractive tint shader */}
|
||||||
|
<HelloModel isMobile={isMobile} />
|
||||||
|
<CursorStar isMobile={isMobile} />
|
||||||
</Canvas>
|
</Canvas>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
+69
-14
@@ -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() {
|
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 (
|
return (
|
||||||
<header className="z-50 fixed inset-0 flex flex-col justify-between font-mono-2 pointer-events-none transition-colors duration-300 ease-out text-l1">
|
<header className="z-50 fixed inset-0 flex flex-col justify-between font-mono-2 pointer-events-none transition-colors duration-300 ease-out text-l1">
|
||||||
<div className="flex justify-between items-center px-4 lg:px-14 py-4 lg:py-7 text-base">
|
<div className="flex justify-between items-center px-4 lg:px-14 py-4 lg:py-7 text-base">
|
||||||
<a
|
<a
|
||||||
className="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 p-2 font-sans font-bold uppercase pointer-events-auto transition-colors duration-300 ease-out"
|
className={`${dotted} p-2 font-sans font-bold uppercase pointer-events-auto transition-colors duration-300 ease-out`}
|
||||||
style={{ fontVariationSettings: '"wght" 700, "wdth" 120' }}
|
style={{ fontVariationSettings: '"wght" 700, "wdth" 120' }}
|
||||||
href="/"
|
href="/"
|
||||||
>
|
>
|
||||||
<span>haoqi.design</span>
|
<ScrambleReveal text="haoqi" startDelayMs={300} scrambleColors={false} />
|
||||||
|
<ScrambleReveal text=".design" startDelayMs={300} scrambleColors={false} />
|
||||||
</a>
|
</a>
|
||||||
<div className="hidden lg:flex flex-wrap justify-between items-center gap-x-3 gap-y-2 pointer-events-auto basis-1/2 xl:basis-1/3">
|
<div className="hidden lg:flex flex-wrap justify-between items-center gap-x-3 gap-y-2 pointer-events-auto basis-1/2 xl:basis-1/3">
|
||||||
<button type="button" className="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 p-2 uppercase cursor-pointer">
|
<button type="button" className={`${dotted} p-2 uppercase cursor-pointer`}>
|
||||||
Work
|
<ScrambleReveal text="Work" startDelayMs={300} scrambleColors={false} />
|
||||||
</button>
|
</button>
|
||||||
<button type="button" className="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 p-2 uppercase cursor-pointer">
|
<button type="button" className={`${dotted} p-2 uppercase cursor-pointer`}>
|
||||||
Contact
|
<ScrambleReveal text="Contact" startDelayMs={300} scrambleColors={false} />
|
||||||
</button>
|
</button>
|
||||||
<span role="button" tabIndex={0} className="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 p-2 uppercase cursor-pointer pointer-events-auto">
|
<span role="button" tabIndex={0} className={`${dotted} p-2 uppercase cursor-pointer pointer-events-auto`}>
|
||||||
THEME[A]
|
<ScrambleReveal text="THEME[A]" startDelayMs={300} scrambleColors={false} />
|
||||||
</span>
|
</span>
|
||||||
<span role="button" tabIndex={0} className="inline-flex shrink-0 items-baseline gap-0 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 p-2 uppercase cursor-pointer pointer-events-auto normal-case">
|
<span role="button" tabIndex={0} className={`${dotted} p-2 uppercase cursor-pointer pointer-events-auto normal-case`}>
|
||||||
SOUND[|]
|
<ScrambleReveal text="SOUND[|]" startDelayMs={300} scrambleColors={false} />
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between px-4 lg:px-14 py-4 lg:py-7">
|
<div className="flex justify-between px-4 lg:px-14 py-4 lg:py-7">
|
||||||
<span className="lg:hidden p-2 uppercase transition-colors duration-300 ease-out">--:--</span>
|
<span className="lg:hidden p-2 uppercase">
|
||||||
<span className="hidden lg:inline p-2 uppercase">GMT+8 CN --:--</span>
|
<ScrambleReveal text={time} startDelayMs={300} letterDelayMs={40} scrambleColors={false} />
|
||||||
<span className="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 hidden lg:inline lg:bottom-7 lg:left-1/2 lg:fixed p-2 lg:-translate-x-1/2 cursor-pointer pointer-events-auto">
|
</span>
|
||||||
0001 X 0001 Y
|
<span className="hidden lg:inline p-2 uppercase">
|
||||||
|
<ScrambleReveal text={`GMT+8 CN ${time}`} startDelayMs={300} letterDelayMs={40} scrambleColors={false} />
|
||||||
|
</span>
|
||||||
|
<span
|
||||||
|
className={`${dotted} hidden lg:inline lg:bottom-7 lg:left-1/2 lg:fixed p-2 lg:-translate-x-1/2 cursor-pointer pointer-events-auto`}
|
||||||
|
>
|
||||||
|
<ScrambleReveal
|
||||||
|
text={`${coords.x} X ${coords.y} Y`}
|
||||||
|
startDelayMs={300}
|
||||||
|
letterDelayMs={40}
|
||||||
|
scrambleColors={false}
|
||||||
|
/>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@@ -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<HTMLSpanElement>(null);
|
||||||
|
const [entered, setEntered] = useState(false);
|
||||||
|
const [startedAt, setStartedAt] = useState<number | null>(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 (
|
||||||
|
<span ref={ref} className={className}>
|
||||||
|
{strings.map((s, i) => (
|
||||||
|
<span key={i}>{entered ? s : ""}</span>
|
||||||
|
))}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// recompute random chars on each elapsed tick
|
||||||
|
let index = 0;
|
||||||
|
return (
|
||||||
|
<span ref={ref} className={className}>
|
||||||
|
{strings.map((s, si) => (
|
||||||
|
<span key={si}>
|
||||||
|
{s.split("").map((ch, ci) => {
|
||||||
|
const i = index++;
|
||||||
|
if (ch === "\n") return <br key={`br-${si}-${ci}`} />;
|
||||||
|
if (ch === " ") return <span key={`sp-${si}-${ci}`}> </span>;
|
||||||
|
const n = i * letterDelayMs;
|
||||||
|
if (V < n) {
|
||||||
|
return (
|
||||||
|
<span key={`c-${si}-${ci}`} style={{ opacity: 0 }}>
|
||||||
|
{ch}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (V < n + scrambleWindow) {
|
||||||
|
const phase = Math.min(
|
||||||
|
1,
|
||||||
|
Math.floor((V - n) / phaseLen)
|
||||||
|
);
|
||||||
|
const color = scrambleColors ? COLORS_LIGHT[phase] : undefined;
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
key={`c-${si}-${ci}`}
|
||||||
|
style={color ? { color } : undefined}
|
||||||
|
>
|
||||||
|
{randomChar()}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return <span key={`c-${si}-${ci}`}>{ch}</span>;
|
||||||
|
})}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -323,6 +323,9 @@ export class StickerLayer {
|
|||||||
);
|
);
|
||||||
mesh.frustumCulled = false;
|
mesh.frustumCulled = false;
|
||||||
mesh.count = 0;
|
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.geometry = geometry;
|
||||||
this.material = material;
|
this.material = material;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user