ce08eabf62
- BackgroundFX: 1:1 移植原版 sz 多通道程序化背景(vignette→swirl→sine→shatter→bokeh→output,30% 分辨率 ping-pong,指针跟随、进度门控跳帧) - DotOverlay: 移植原版 s1 滚动点阵遮罩(renderOrder 10,uOpacity=sT(sP))——贴纸随滚动溶入页面底色的原版机制 - LoadingCurtain+LoadingOverlay: 移植原版入场流程(径向圆洞幕布 + MaskedDots 点阵化后处理 + 居中进度条,字体/重资产 5:5 计时轴) - sP 修正: f2 无 footer 时取 1(原版语义),相机 lerp(24,32,sP) 拉远恢复;视差 y 系数修正为 0.6 - 相机: ready 门控 intro dolly(lerp(A+8,A,customCubic),1.2s)+ 鼠标视差(lag .18/leave .05) - GlassModels: cursor 贴色修正为亮色主题 #009dff/#009dff;新增指针跟随高光控制器 ca() - 刷新回顶: scrollRestoration=manual + pageshow(bfcache) 双 rAF 重置 + lenis immediate - 新增 lib/pointer.ts、lib/loadingBus.ts、lib/customCubic.ts;loadingBus 打点: 模型/贴纸/about 图
125 lines
3.7 KiB
TypeScript
125 lines
3.7 KiB
TypeScript
"use client";
|
||
|
||
import { useLayoutEffect, useMemo, useRef } from "react";
|
||
import { useFrame, useThree } from "@react-three/fiber";
|
||
import { Color, Vector2 } from "three";
|
||
import { scrollBus } from "@/lib/scrollBus";
|
||
|
||
/**
|
||
* Scroll dot-overlay — 1:1 port of the original `s1` (chunk
|
||
* 4d3f3b68dbbde33a.js): a fullscreen transparent mesh at renderOrder 10
|
||
* whose opacity equals sT(sP) (the banner/footer camera progress). The
|
||
* page-background-colored dot grid (4px cells, radius .9 × opacity)
|
||
* melts the WebGL scene (stickers, glass, gradient bg) into the page
|
||
* background as you scroll past the hero — that IS the "stickers fade
|
||
* out on scroll" behavior of the original site. Near the footer sP → 0
|
||
* and the overlay opens again.
|
||
*
|
||
* Light-theme colors (c_): dark "#0F1111", light "#FBFAF4".
|
||
*/
|
||
|
||
const OVERLAY_COLORS = ["#0F1111", "#FBFAF4"] as const;
|
||
const OVERLAY_PIXEL_SIZE = 4;
|
||
const OVERLAY_RADIUS_SCALE = 0.9;
|
||
|
||
const clamp01 = (e: number) => Math.min(1, Math.max(0, e));
|
||
|
||
/** Original sT: normalize (values > 1 are treated as percentages). */
|
||
function sT(e?: number): number {
|
||
return e === undefined ? 0 : clamp01(e > 1 ? e / 100 : e);
|
||
}
|
||
|
||
export function DotOverlay() {
|
||
// Light-only theme (original: resolvedTheme from useThemeMode).
|
||
const isDark = false;
|
||
const size = useThree((s) => s.size);
|
||
const materialRef = useRef<any>(null);
|
||
|
||
const uniforms = useMemo(
|
||
() => ({
|
||
uColor: { value: new Color() },
|
||
uOpacity: { value: 1 },
|
||
uPixelSize: { value: OVERLAY_PIXEL_SIZE },
|
||
uRadiusScale: { value: OVERLAY_RADIUS_SCALE },
|
||
uResolution: { value: new Vector2(1, 1) },
|
||
}),
|
||
[]
|
||
);
|
||
|
||
// Theme color: light theme picks the second entry (original e[1]).
|
||
useLayoutEffect(() => {
|
||
const [dark, light] = OVERLAY_COLORS;
|
||
materialRef.current?.uniforms.uColor.value.set(isDark ? dark : light);
|
||
}, [isDark]);
|
||
|
||
useLayoutEffect(() => {
|
||
materialRef.current?.uniforms.uResolution.value.set(
|
||
Math.max(1, size.width),
|
||
Math.max(1, size.height)
|
||
);
|
||
}, [size.width, size.height]);
|
||
|
||
useFrame(() => {
|
||
const e = sT(scrollBus.sP);
|
||
if (materialRef.current) {
|
||
materialRef.current.uniforms.uOpacity.value = e;
|
||
}
|
||
});
|
||
|
||
return (
|
||
<mesh renderOrder={10} frustumCulled={false}>
|
||
<planeGeometry args={[2, 2]} />
|
||
<shaderMaterial
|
||
ref={materialRef}
|
||
transparent
|
||
depthTest={false}
|
||
depthWrite={false}
|
||
toneMapped={false}
|
||
uniforms={uniforms}
|
||
vertexShader={`
|
||
varying vec2 vUv;
|
||
|
||
void main() {
|
||
vUv = uv;
|
||
gl_Position = vec4(position.xy, 0.0, 1.0);
|
||
}
|
||
`}
|
||
fragmentShader={`
|
||
precision highp float;
|
||
|
||
varying vec2 vUv;
|
||
|
||
uniform vec3 uColor;
|
||
uniform float uOpacity;
|
||
uniform float uPixelSize;
|
||
uniform float uRadiusScale;
|
||
uniform vec2 uResolution;
|
||
|
||
void main() {
|
||
float a = clamp(uOpacity, 0.0, 1.0);
|
||
|
||
vec2 normalizedPixelSize = vec2(
|
||
uPixelSize / max(uResolution.x, 1.0),
|
||
uPixelSize / max(uResolution.y, 1.0)
|
||
);
|
||
|
||
vec2 safePixelSize = max(normalizedPixelSize, vec2(1e-6));
|
||
vec2 cellUV = fract(vUv / safePixelSize);
|
||
|
||
// 与 route_transition 点阵一致:透明度直接映射圆半径。
|
||
float radius = uRadiusScale * a;
|
||
float distanceFromCenter = distance(cellUV, vec2(0.5));
|
||
float aa = fwidth(distanceFromCenter) * 1.5;
|
||
float circleMask = smoothstep(radius, radius - aa, distanceFromCenter);
|
||
|
||
gl_FragColor = vec4(uColor, circleMask);
|
||
#include <colorspace_fragment>
|
||
}
|
||
`}
|
||
/>
|
||
</mesh>
|
||
);
|
||
}
|
||
|
||
export default DotOverlay;
|