搭建react项目,以自然为主题,重点制作应用于网页背景的shader,能够模拟在不同色彩、不同角度的光影下,植物在白墙上的投影。shader应具有对植物投影的真实反映,鼓励拓展…
- User
搭建react项目,以自然为主题,重点制作应用于网页背景的shader,能够模拟在不同色彩、不同角度的光影下,植物在白墙上的投影。shader应具有对植物投影的真实反映,鼓励拓展并以自然为概念继续完善shader。 项目拥有背景配置子页和阅读子页,用于调整并展示效果。
Assistant
I'll build a React project themed around nature with a custom GLSL shader simulating plant shadows on a white wall. Let me plan the structure and start implementing.
Now I'll build the project. Plan:
- Custom WebGL shader for plant shadows on white wall (procedural leaves via domain-warped FBM, penumbra sampling, wind sway, parallax by light angle)
- Zustand store for shared settings (persist to localStorage)
- Two pages: Config (live tweak) and Reading (immersive reading with shader background)
- HashRouter for compatibility with singlefile build
Let me start by creating the shader and WebGL renderer:
Now the WebGL renderer component:
Now the settings store with presets:
Now the two pages and layout. Config page with control panel:
Now the Reading page:
Now the App entry with routing:
Update index.html title and add some base body styling:
Let's build and check:
Build succeeded. Let me verify the key pieces are correct—particularly the shader for realism. Let me review a potential issue: in the config page slider
parseFloat(...) as neveris a type escape hatch that works, but there may be issues with thesettings[row.key]being a string for color rows. Let me double check the slider is only used for number-valued keys—yes, the SliderRow arrays only include numeric keys, so it's fine.Let me also verify the reading page's paper color CSS variable fallback works. The
bg-[color:var(--paper,#f5efe1)]/85syntax uses arbitrary Tailwind values with opacity — Tailwind v4 supports this. Good.Everything builds cleanly. Here's a summary of what I built:
项目概览 — 墙 · 影 · 光
核心:真实感植物投影 Shader(
src/shader/plantShadow.glsl.ts)- 使用 domain-warped FBM 噪声 构建有机的枝叶密度场,配合每个网格单元的旋转椭圆微叶形,让叶片既有整体丛簇感又有细节剪影。
- 半影 (Penumbra) 模拟:
softShadow()用 10 次黄金角螺旋采样对密度场做加权模糊,采样半径随「植物-墙距离」放大,模拟真实光学中距离越远影子越虚。 - 光角度视差:光的方向 (
uLightDir) 与高度 (uLightHeight) 共同决定叶影在墙面上的偏移量,擦射光会产生长长的柔影,顶光则短促。 - 色彩物理感:光源色叠加环境光作为亮部;阴影处只保留环境光 + 阴影色调偏移;再对刚被遮挡的过渡区加一层暖色 rim,模拟叶片透光。
- 风的动画:多频正弦扰动 UV,与叶片密度场耦合。
- 氛围拓展:光柱条纹、墙面颗粒 (plaster grain)、暗角 vignette。
两个子页面(
react-router-dom+HashRouter):- 配置页
/— 右侧滑板可实时调整 20+ 参数(光强/角度/高度、叶片密度/边缘、阴影虚化/浓度、风、墙纹理…),并提供 6 个自然预设:晨光初照、正午白墙、黄昏橘调、夜色月影、林间碎光、米色安眠。四路取色器控制光色、阴影色调、墙色、环境光色。 - 阅读页
/read— 米黄色纸质阅读卡浮在实时光影背景上,含 3 篇自然主题短文、字号调节、宽窄栏切换、篇目切换。
状态管理:
zustand+persist中间件,所有参数自动存到 localStorage。Files built:
src/shader/plantShadow.glsl.ts,src/shader/ShaderCanvas.tsx,src/store/settings.ts,src/pages/ConfigPage.tsx,src/pages/ReadingPage.tsx,src/App.tsx,index.html
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.