Ethscriptions commited on
Commit
c0d0800
·
verified ·
1 Parent(s): 4b7c857

暮归江南 · 步骤10:全片检查与调优、使用说明

Browse files
README.md CHANGED
@@ -114,7 +114,18 @@ tools/jiangnan/ # 旁白生成、字体子集化、实况图
114
 
115
  ---
116
 
117
- ## F. 进度日志(项目二)
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  - **步骤 1** ✅ 写好计划、大纲、步骤与做法(本节),推送到 Space。
120
  - **步骤 2** ✅ 渲染引擎骨架:新页面入口 `/jiangnan/`(`jiangnan/index.html` + `src/jiangnan/main.tsx`,`vite.config.ts` 增加多页面入口,原页面不变);时间轴(10 个镜头、日落曲线、旁白时间);程序化天空(夕阳、晚霞、云、蓝调、星空、新月);山谷地形 + 远山 + 高精度梯田(水田镜面反光);实时平面反射的河面(涟漪、阳光碎金、灯影拉丝);高度雾与空气透视;后期(体积光、辉光、ACES、分色调色、暗角、颗粒)。
@@ -125,6 +136,7 @@ tools/jiangnan/ # 旁白生成、字体子集化、实况图
125
  - **步骤 7** ✅ 封面与文案:16:9 / 4:3 / 3:4 三种比例 × 4 个画面(石桥夕照、灯火长街、星夜水乡、古樟斜阳),每张按比例重新取景渲染并排书法标题,可多选、单张或打包下载;小红书 / 抖音 / 视频号 / B站 各 3–4 个标题(字数实时校验,全部在限制内)、描述、话题,一键复制,也可下载 txt。
126
  - **步骤 8** ✅ 实况图:把 LiveCanvas skill 的 Python 配对器移植成浏览器端 TypeScript(`src/jiangnan/export/livephoto.ts`),网页里一键生成 6 组 3:4 / 30fps / 3 秒实况图,压缩包内含同名 jpg + mov、.pvt 资源包、manifest、使用说明与图文文案。用 skill 原版 `verify_pair` + `package_live_photo.py` 校验浏览器生成的文件:标识一致、still-image-time 读回正确、ffprobe 时间样本正确、完整解码通过。
127
  - **步骤 9** ✅ Blender 场景脚本 `blender/jiangnan_village.py`:已在沙盒里用 Blender 4.2 LTS(bpy)实际运行,生成 218 栋民居、178 盏灯笼(含关键帧点亮)、石拱桥、水车(旋转动画)、古樟、竹林、Nishita 天空 + 日落关键帧 + 蓝调天光、暮霭体积、10 个镜头(时间轴标记自动切换),并用 Cycles 试渲通过。
 
128
 
129
 
130
  ---
 
114
 
115
  ---
116
 
117
+ ## F. 使用说明
118
+
119
+ 1. 打开 **https://ethscriptions-video.hf.space/jiangnan/** ,等待「搭建场景 → 合成配乐与旁白」完成(约 10–20 秒),点播放。手机竖着打开会自动切换为竖屏构图,也可手动切换「横屏 16:9 / 竖屏 9:16」。
120
+ 2. **导出 MP4**:选择画幅(横 / 竖)、清晰度(1080p / 720p)、帧率(24 / 30 / 60)、是否烧录字幕 → 开始导出 → 保存。全部在本机浏览器完成;推荐电脑版 Chrome / Edge(音轨为 AAC;个别浏览器不支持 AAC 时自动改用 Opus)。
121
+ 3. **封面**:多选比例(16:9 / 4:3 / 3:4)和画面(石桥夕照 / 灯火长街 / 星夜水乡 / 古樟斜阳)→ 生成 → 勾选 → 下载(多张自动打包 ZIP)。
122
+ 4. **发布文案**:切换小红书 / 抖音 / 微信视频号 / 哔哩哔哩,选标题,一键复制标题、描述、话题或全部;也可下载全部文案 txt。
123
+ 5. **实况图**:点「生成 6 组实况图」→ 下载 ZIP。Mac 上把 `1_jpg+mov` 文件夹里同名的 jpg 和 mov 一起拖进「照片」即成实况照片,同步到 iPhone 后发小红书 / 抖音图文;图文标题、正文、话题在同一区域复制。
124
+ 6. **Blender**:页面底部下载 `jiangnan_village.py`(仓库里也有 `blender/jiangnan_village.py`),Blender 4.x → Scripting → Run Script,约 1–2 分钟生成完整场景,Cycles 渲染。
125
+
126
+ 本地开发:`npm install && npm run dev`,打开 `/jiangnan/`。自动画面检查脚本在 `tools/jiangnan/`(`analyze.py` 用无头浏览器渲染各镜头并输出构图 / 亮度图;`verify_live_photo.py` 调用 LiveCanvas 原版校验器检查实况图)。
127
+
128
+ ## G. 进度日志(项目二)
129
 
130
  - **步骤 1** ✅ 写好计划、大纲、步骤与做法(本节),推送到 Space。
131
  - **步骤 2** ✅ 渲染引擎骨架:新页面入口 `/jiangnan/`(`jiangnan/index.html` + `src/jiangnan/main.tsx`,`vite.config.ts` 增加多页面入口,原页面不变);时间轴(10 个镜头、日落曲线、旁白时间);程序化天空(夕阳、晚霞、云、蓝调、星空、新月);山谷地形 + 远山 + 高精度梯田(水田镜面反光);实时平面反射的河面(涟漪、阳光碎金、灯影拉丝);高度雾与空气透视;后期(体积光、辉光、ACES、分色调色、暗角、颗粒)。
 
136
  - **步骤 7** ✅ 封面与文案:16:9 / 4:3 / 3:4 三种比例 × 4 个画面(石桥夕照、灯火长街、星夜水乡、古樟斜阳),每张按比例重新取景渲染并排书法标题,可多选、单张或打包下载;小红书 / 抖音 / 视频号 / B站 各 3–4 个标题(字数实时校验,全部在限制内)、描述、话题,一键复制,也可下载 txt。
137
  - **步骤 8** ✅ 实况图:把 LiveCanvas skill 的 Python 配对器移植成浏览器端 TypeScript(`src/jiangnan/export/livephoto.ts`),网页里一键生成 6 组 3:4 / 30fps / 3 秒实况图,压缩包内含同名 jpg + mov、.pvt 资源包、manifest、使用说明与图文文案。用 skill 原版 `verify_pair` + `package_live_photo.py` 校验浏览器生成的文件:标识一致、still-image-time 读回正确、ffprobe 时间样本正确、完整解码通过。
138
  - **步骤 9** ✅ Blender 场景脚本 `blender/jiangnan_village.py`:已在沙盒里用 Blender 4.2 LTS(bpy)实际运行,生成 218 栋民居、178 盏灯笼(含关键帧点亮)、石拱桥、水车(旋转动画)、古樟、竹林、Nishita 天空 + 日落关键帧 + 蓝调天光、暮霭体积、10 个镜头(时间轴标记自动切换),并用 Cycles 试渲通过。
139
+ - **步骤 10** ✅ 全片检查与调优:用无头浏览器逐镜头渲染(横屏 + 竖屏)并做构图 / 曝光量化检查,修正了:远山遮挡夕阳、开场机位、河面朝向、太阳水面倒影过曝导致的辉光泛白(加入高光压缩)、古樟镜头机位穿进民居、夜河镜头里看不到船、终章大全景构图、Blender 夜景镜头穿模与 Nishita 天空在日落后发黑;新增每个镜头独立曝光、水车水花、夜里河岸萤火虫;播放器加入音频时钟失效时的兜底;整页冒烟测试(加载、合成音频、播放、横竖屏切换、封面渲染)无报错。
140
 
141
 
142
  ---
blender/jiangnan_village.py CHANGED
@@ -760,7 +760,7 @@ def build_cameras(scene, coll):
760
  8: (qp(river_s_at_x(-150), -0.8, GROUND_Y + 2.6), qp(river_s_at_x(-150) + 26, -1.6, GROUND_Y + 2.4),
761
  qp(river_s_at_x(-150) + 21, -0.8, GROUND_Y + 2.6), qp(river_s_at_x(-150) + 47, -1.6, GROUND_Y + 2.4), 48),
762
  9: (rp(bs + 52, -4.6, 1.25), (bx + bnx * 1.5, 3.4, bz + bnz * 1.5), rp(bs + 45, -4.6, 1.25), (bx + bnx * 1.5, 3.4, bz + bnz * 1.5), 42),
763
- 10: ((95, 9, 34), (-10, 3, -4), (250, 125, 205), (-520, 60, -230), 44),
764
  }
765
  cams = {}
766
  for i, (sid, t0) in enumerate(SHOT_TIMES):
 
760
  8: (qp(river_s_at_x(-150), -0.8, GROUND_Y + 2.6), qp(river_s_at_x(-150) + 26, -1.6, GROUND_Y + 2.4),
761
  qp(river_s_at_x(-150) + 21, -0.8, GROUND_Y + 2.6), qp(river_s_at_x(-150) + 47, -1.6, GROUND_Y + 2.4), 48),
762
  9: (rp(bs + 52, -4.6, 1.25), (bx + bnx * 1.5, 3.4, bz + bnz * 1.5), rp(bs + 45, -4.6, 1.25), (bx + bnx * 1.5, 3.4, bz + bnz * 1.5), 42),
763
+ 10: ((95, 9, 34), (-10, 3, -4), (205, 88, 160), (-330, 26, -150), 44),
764
  }
765
  cams = {}
766
  for i, (sid, t0) in enumerate(SHOT_TIMES):
src/jiangnan/JiangnanApp.tsx CHANGED
@@ -60,7 +60,7 @@ export default function JiangnanApp() {
60
  const ovRef = useRef<HTMLCanvasElement>(null)
61
  const filmRef = useRef<Film | null>(null)
62
  const audioRef = useRef<{ ctx: AudioContext | null; buf: AudioBuffer | null; src: AudioBufferSourceNode | null; gain: GainNode | null }>({ ctx: null, buf: null, src: null, gain: null })
63
- const clockRef = useRef({ playing: false, startPerf: 0, startT: 0, t: 0 })
64
  const scaleRef = useRef(1)
65
  const busyRef = useRef(false)
66
  const dirtyRef = useRef(true)
@@ -99,6 +99,11 @@ export default function JiangnanApp() {
99
  const r = await exportMp4(film, { width: w, height: h, fps, start, duration, audio: audioRef.current.buf, overlay: { subtitles: true, titles: true }, signal: { cancelled: false }, onProgress: () => {} })
100
  return blobB64(r.blob)
101
  },
 
 
 
 
 
102
  live: async (w: number, h: number, frames: number) => {
103
  const r = await generateLivePhotos(film, () => {}, { cancelled: false }, { w, h, frames, clips: 1 })
104
  return blobB64(r.zip)
@@ -135,6 +140,7 @@ export default function JiangnanApp() {
135
  const film = filmRef.current
136
  const el = playerRef.current
137
  if (!film || !el || busyRef.current) return
 
138
  const rect = el.getBoundingClientRect()
139
  const dpr = Math.min(window.devicePixelRatio || 1, 2)
140
  const maxLong = isMobile() ? 1100 : 1600
@@ -163,8 +169,13 @@ export default function JiangnanApp() {
163
  const c = clockRef.current
164
  if (!c.playing) return c.t
165
  const a = audioRef.current
166
- if (a.ctx && a.src) return c.startT + (a.ctx.currentTime - c.startPerf)
167
- return c.startT + (performance.now() - c.startPerf) / 1000
 
 
 
 
 
168
  }
169
 
170
  const stopAudio = () => {
@@ -192,7 +203,9 @@ export default function JiangnanApp() {
192
  src.start(0, t)
193
  a.src = src
194
  c.startPerf = a.ctx.currentTime
195
- } else c.startPerf = performance.now()
 
 
196
  c.startT = t
197
  c.playing = true
198
  setPlaying(true)
 
60
  const ovRef = useRef<HTMLCanvasElement>(null)
61
  const filmRef = useRef<Film | null>(null)
62
  const audioRef = useRef<{ ctx: AudioContext | null; buf: AudioBuffer | null; src: AudioBufferSourceNode | null; gain: GainNode | null }>({ ctx: null, buf: null, src: null, gain: null })
63
+ const clockRef = useRef({ playing: false, startPerf: 0, startT: 0, t: 0, wall: 0, audioClock: true })
64
  const scaleRef = useRef(1)
65
  const busyRef = useRef(false)
66
  const dirtyRef = useRef(true)
 
99
  const r = await exportMp4(film, { width: w, height: h, fps, start, duration, audio: audioRef.current.buf, overlay: { subtitles: true, titles: true }, signal: { cancelled: false }, onProgress: () => {} })
100
  return blobB64(r.blob)
101
  },
102
+ cover: async (key: string, ratio: Ratio) => {
103
+ const d = COVER_DESIGNS.find((x) => x.key === key)!
104
+ const c = renderCover(film, d, ratio)
105
+ return blobB64(await canvasToBlob(c))
106
+ },
107
  live: async (w: number, h: number, frames: number) => {
108
  const r = await generateLivePhotos(film, () => {}, { cancelled: false }, { w, h, frames, clips: 1 })
109
  return blobB64(r.zip)
 
140
  const film = filmRef.current
141
  const el = playerRef.current
142
  if (!film || !el || busyRef.current) return
143
+ if (new URLSearchParams(location.search).get('w')) return // fixed-size QA mode
144
  const rect = el.getBoundingClientRect()
145
  const dpr = Math.min(window.devicePixelRatio || 1, 2)
146
  const maxLong = isMobile() ? 1100 : 1600
 
169
  const c = clockRef.current
170
  if (!c.playing) return c.t
171
  const a = audioRef.current
172
+ if (a.ctx && a.src && c.audioClock) {
173
+ const at = a.ctx.currentTime - c.startPerf
174
+ // audio clock stalled (no output device / blocked): fall back to the wall clock
175
+ if (performance.now() - c.wall > 800 && at < 0.05) c.audioClock = false
176
+ else return c.startT + at
177
+ }
178
+ return c.startT + (performance.now() - c.wall) / 1000
179
  }
180
 
181
  const stopAudio = () => {
 
203
  src.start(0, t)
204
  a.src = src
205
  c.startPerf = a.ctx.currentTime
206
+ }
207
+ c.audioClock = true
208
+ c.wall = performance.now()
209
  c.startT = t
210
  c.playing = true
211
  setPlaying(true)
src/jiangnan/assets/fonts/title.woff2 CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:63d01c7d2c75f65eccdc89e79f1cafb080f04af1869be4c2e1c875739b81a0a2
3
- size 152776
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8a0e19db8353edace27893e2bdd4572a167ed6492c5247363582b65a43843e62
3
+ size 233272
src/jiangnan/assets/fonts/wenkai.woff2 CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:7316dfca75b5cbbee358a61eacb711e6cd44f476959c4fd63a0ea7362be2e322
3
- size 100608
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bc282ef76d0be3bc574df1397041696fbcf13c37cb1a1af64ce15a23adc9f6e8
3
+ size 143264
src/jiangnan/blender/jiangnan_village.py CHANGED
@@ -760,7 +760,7 @@ def build_cameras(scene, coll):
760
  8: (qp(river_s_at_x(-150), -0.8, GROUND_Y + 2.6), qp(river_s_at_x(-150) + 26, -1.6, GROUND_Y + 2.4),
761
  qp(river_s_at_x(-150) + 21, -0.8, GROUND_Y + 2.6), qp(river_s_at_x(-150) + 47, -1.6, GROUND_Y + 2.4), 48),
762
  9: (rp(bs + 52, -4.6, 1.25), (bx + bnx * 1.5, 3.4, bz + bnz * 1.5), rp(bs + 45, -4.6, 1.25), (bx + bnx * 1.5, 3.4, bz + bnz * 1.5), 42),
763
- 10: ((95, 9, 34), (-10, 3, -4), (250, 125, 205), (-520, 60, -230), 44),
764
  }
765
  cams = {}
766
  for i, (sid, t0) in enumerate(SHOT_TIMES):
 
760
  8: (qp(river_s_at_x(-150), -0.8, GROUND_Y + 2.6), qp(river_s_at_x(-150) + 26, -1.6, GROUND_Y + 2.4),
761
  qp(river_s_at_x(-150) + 21, -0.8, GROUND_Y + 2.6), qp(river_s_at_x(-150) + 47, -1.6, GROUND_Y + 2.4), 48),
762
  9: (rp(bs + 52, -4.6, 1.25), (bx + bnx * 1.5, 3.4, bz + bnz * 1.5), rp(bs + 45, -4.6, 1.25), (bx + bnx * 1.5, 3.4, bz + bnz * 1.5), 42),
763
+ 10: ((95, 9, 34), (-10, 3, -4), (205, 88, 160), (-330, 26, -150), 44),
764
  }
765
  cams = {}
766
  for i, (sid, t0) in enumerate(SHOT_TIMES):
src/jiangnan/engine/Film.ts CHANGED
@@ -185,7 +185,9 @@ export class Film {
185
  ;(wu.uSunCol.value as THREE.Color).setRGB(st.sun[0], st.sun[1], st.sun[2])
186
  wu.uSunI.value = st.sunI * sunVis
187
  ;(wu.uSkyAmb.value as THREE.Color).setRGB(st.zen[0] * 2 + st.hor[0] * 0.5, st.zen[1] * 2 + st.hor[1] * 0.5, st.zen[2] * 2 + st.hor[2] * 0.5)
188
- this.renderer.toneMappingExposure = st.exposure
 
 
189
  this.life.update(t)
190
  return st
191
  }
 
185
  ;(wu.uSunCol.value as THREE.Color).setRGB(st.sun[0], st.sun[1], st.sun[2])
186
  wu.uSunI.value = st.sunI * sunVis
187
  ;(wu.uSkyAmb.value as THREE.Color).setRGB(st.zen[0] * 2 + st.hor[0] * 0.5, st.zen[1] * 2 + st.hor[1] * 0.5, st.zen[2] * 2 + st.hor[2] * 0.5)
188
+ // per-shot exposure, like a cinematographer riding the iris between set-ups
189
+ const SHOT_EXPOSURE = [1, 1, 1, 1, 1.35, 1.12, 1.15, 1.3, 1.18, 0.86, 1.2]
190
+ this.renderer.toneMappingExposure = st.exposure * SHOT_EXPOSURE[shotAt(t).id]
191
  this.life.update(t)
192
  return st
193
  }
src/jiangnan/engine/camera.ts CHANGED
@@ -121,8 +121,8 @@ const shots: Record<number, ShotFn> = {
121
  // 10 · crane up and pull back over the glowing village under the first stars
122
  10: (u, _t, p) => {
123
  const e = easeInOut(clamp(u * 1.05))
124
- const pos = mix(V(95, 9, 34), V(250, 125, 205), e)
125
- const target = mix(V(-10, 3, -4), V(-520, 60, -230), e)
126
  if (p) { pos.add(V(20, 25, 20)); target.y -= 8 }
127
  return { pos, target, fov: lerp(44, 40, e) }
128
  },
 
121
  // 10 · crane up and pull back over the glowing village under the first stars
122
  10: (u, _t, p) => {
123
  const e = easeInOut(clamp(u * 1.05))
124
+ const pos = mix(V(95, 9, 34), V(205, 88, 160), e)
125
+ const target = mix(V(-10, 3, -4), V(-330, 26, -150), e)
126
  if (p) { pos.add(V(20, 25, 20)); target.y -= 8 }
127
  return { pos, target, fov: lerp(44, 40, e) }
128
  },
src/jiangnan/engine/life.ts CHANGED
@@ -560,6 +560,104 @@ export function createLife(village: VillageOut, props: PropsOut): LifeOut {
560
  smoke.renderOrder = 5
561
  group.add(smoke)
562
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
563
  // ---------------------------------------------------------------- night boat + boatman + bow lantern
564
  const boat = props.movingBoat
565
  const boatman = makeFigure(rng, mats, { hat: true })
@@ -573,8 +671,8 @@ export function createLife(village: VillageOut, props: PropsOut): LifeOut {
573
  boatLantern.position.set(0, 1.55, 2.6)
574
  boat.add(boatLantern)
575
  const boatPos = (t: number) => {
576
- const s = riverSAtX(150) - (t - 60) * 1.15
577
- const r = riverPoint(s, 2.2)
578
  return V3(r.x, 0.02, r.z)
579
  }
580
 
 
560
  smoke.renderOrder = 5
561
  group.add(smoke)
562
 
563
+ // ---------------------------------------------------------------- water-wheel splashes
564
+ {
565
+ const N = 700
566
+ const wi = props.wheelInfo
567
+ const pos = new Float32Array(N * 3)
568
+ const seed = new Float32Array(N)
569
+ for (let i = 0; i < N; i++) seed[i] = hash1(i, 71)
570
+ const g = new THREE.BufferGeometry()
571
+ g.setAttribute('position', new THREE.BufferAttribute(pos, 3))
572
+ g.setAttribute('aSeed', new THREE.BufferAttribute(seed, 1))
573
+ const m = new THREE.ShaderMaterial({
574
+ uniforms: {
575
+ uTime: U.uTime, uC: { value: wi.center }, uT: { value: wi.tangent }, uA: { value: wi.axis }, uR: { value: wi.radius },
576
+ uSunDir: U.uSunDir, uCol: { value: new THREE.Color(1, 0.85, 0.65) },
577
+ },
578
+ vertexShader: /* glsl */ `
579
+ uniform float uTime; uniform vec3 uC; uniform vec3 uT; uniform vec3 uA; uniform float uR;
580
+ attribute float aSeed; varying float vA;
581
+ float h(float x) { return fract(sin(x * 91.7) * 43758.5); }
582
+ void main() {
583
+ float life = 1.1;
584
+ float rate = 0.9 + h(aSeed) * 0.4;
585
+ float cyc = uTime * rate + aSeed * 13.0;
586
+ float age = fract(cyc) * life;
587
+ float idx = floor(cyc);
588
+ float r1 = h(aSeed * 7.0 + idx), r2 = h(aSeed * 3.0 + idx * 1.7), r3 = h(aSeed * 5.0 + idx * 2.3);
589
+ // drops shed from paddles on the rising side, plus the stream poured from the bamboo tubes at the top
590
+ bool pour = r1 < 0.28;
591
+ float th = pour ? mix(1.25, 1.75, r2) : mix(1.75, 3.55, r2);
592
+ float om = 0.42;
593
+ vec2 p0 = vec2(cos(th), sin(th)) * (uR + 0.15);
594
+ vec2 v0 = om * uR * vec2(sin(th), -cos(th)) * (pour ? 0.2 : 0.9) + (vec2(r3, r1) - 0.5) * 0.6;
595
+ vec2 p = p0 + v0 * age + vec2(0.0, -4.9) * age * age;
596
+ float side = (r3 - 0.5) * 1.3;
597
+ vec3 wp = uC + uT * p.x + vec3(0.0, p.y, 0.0) + uA * side;
598
+ vA = (1.0 - age / life) * step(0.02, wp.y) * (pour ? 0.9 : 0.7);
599
+ vec4 mv = viewMatrix * vec4(wp, 1.0);
600
+ gl_PointSize = clamp(55.0 / -mv.z, 1.0, 7.0);
601
+ gl_Position = projectionMatrix * mv;
602
+ }`,
603
+ fragmentShader: /* glsl */ `
604
+ uniform vec3 uCol; varying float vA;
605
+ void main() {
606
+ vec2 d = gl_PointCoord - 0.5;
607
+ float a = smoothstep(0.5, 0.1, length(d)) * vA;
608
+ if (a < 0.01) discard;
609
+ gl_FragColor = vec4(uCol * 1.6, a);
610
+ }`,
611
+ transparent: true, depthWrite: false,
612
+ })
613
+ const splash = new THREE.Points(g, m)
614
+ splash.frustumCulled = false
615
+ group.add(splash)
616
+ }
617
+
618
+ // ---------------------------------------------------------------- fireflies over the banks at night
619
+ {
620
+ const N = 260
621
+ const base = new Float32Array(N * 3)
622
+ const ph = new Float32Array(N)
623
+ for (let i = 0; i < N; i++) {
624
+ const s = VILLAGE_S0 - 60 + hash1(i, 3) * (VILLAGE_S1 - VILLAGE_S0 + 160)
625
+ const side = hash1(i, 4) < 0.5 ? -1 : 1
626
+ const w = riverHalfWidth(s)
627
+ const p = riverPoint(s, side * (w + (hash1(i, 5) - 0.3) * 6))
628
+ base[i * 3] = p.x; base[i * 3 + 1] = 0.6 + hash1(i, 6) * 2.4; base[i * 3 + 2] = p.z
629
+ ph[i] = hash1(i, 7) * 100
630
+ }
631
+ const g = new THREE.BufferGeometry()
632
+ g.setAttribute('position', new THREE.BufferAttribute(base, 3))
633
+ g.setAttribute('aPh', new THREE.BufferAttribute(ph, 1))
634
+ const m = new THREE.ShaderMaterial({
635
+ uniforms: { uTime: U.uTime, uNight: U.uNight },
636
+ vertexShader: /* glsl */ `
637
+ uniform float uTime; uniform float uNight; attribute float aPh; varying float vA;
638
+ void main() {
639
+ vec3 p = position + vec3(sin(uTime * 0.3 + aPh) * 1.5, sin(uTime * 0.5 + aPh * 1.3) * 0.5, cos(uTime * 0.27 + aPh * 0.7) * 1.5);
640
+ float blink = pow(max(0.0, sin(uTime * (0.8 + fract(aPh) * 0.9) + aPh)), 6.0);
641
+ vec4 mv = viewMatrix * vec4(p, 1.0);
642
+ vA = blink * smoothstep(0.55, 0.95, uNight) * exp(-(-mv.z) * 0.012);
643
+ gl_PointSize = clamp(90.0 / -mv.z, 1.5, 9.0);
644
+ gl_Position = projectionMatrix * mv;
645
+ }`,
646
+ fragmentShader: /* glsl */ `
647
+ varying float vA;
648
+ void main() {
649
+ float d = length(gl_PointCoord - 0.5);
650
+ float a = smoothstep(0.5, 0.0, d) * vA;
651
+ if (a < 0.004) discard;
652
+ gl_FragColor = vec4(vec3(0.75, 1.0, 0.35) * a * 4.0, 1.0);
653
+ }`,
654
+ transparent: true, depthWrite: false, blending: THREE.AdditiveBlending,
655
+ })
656
+ const ff = new THREE.Points(g, m)
657
+ ff.frustumCulled = false
658
+ group.add(ff)
659
+ }
660
+
661
  // ---------------------------------------------------------------- night boat + boatman + bow lantern
662
  const boat = props.movingBoat
663
  const boatman = makeFigure(rng, mats, { hat: true })
 
671
  boatLantern.position.set(0, 1.55, 2.6)
672
  boat.add(boatLantern)
673
  const boatPos = (t: number) => {
674
+ const s = riverSAtX(84) - (t - 65) * 1.25
675
+ const r = riverPoint(s, 2.0)
676
  return V3(r.x, 0.02, r.z)
677
  }
678
 
src/jiangnan/engine/post.ts CHANGED
@@ -34,7 +34,7 @@ const GodRaysShader = {
34
  uv += stepv;
35
  vec3 c = texture2D(tDiffuse, clamp(uv, 0.0, 1.0)).rgb;
36
  float l = dot(c, vec3(0.2126, 0.7152, 0.0722));
37
- acc += c * smoothstep(1.6, 4.0, l) * decay;
38
  decay *= 0.965;
39
  }
40
  acc /= float(N);
@@ -43,6 +43,20 @@ const GodRaysShader = {
43
  }`,
44
  }
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  const GradeShader = {
47
  uniforms: {
48
  tDiffuse: { value: null as THREE.Texture | null },
@@ -99,6 +113,7 @@ export function createPost(renderer: THREE.WebGLRenderer, scene: THREE.Scene, ca
99
  composer.addPass(new RenderPass(scene, camera))
100
  const rays = new ShaderPass(GodRaysShader)
101
  composer.addPass(rays)
 
102
  const bloom = new UnrealBloomPass(new THREE.Vector2(w, h), 0.5, 0.55, 0.92)
103
  composer.addPass(bloom)
104
  composer.addPass(new OutputPass())
 
34
  uv += stepv;
35
  vec3 c = texture2D(tDiffuse, clamp(uv, 0.0, 1.0)).rgb;
36
  float l = dot(c, vec3(0.2126, 0.7152, 0.0722));
37
+ acc += c * smoothstep(2.0, 5.0, l) * decay;
38
  decay *= 0.965;
39
  }
40
  acc /= float(N);
 
43
  }`,
44
  }
45
 
46
+ // soft-compress extreme HDR highlights (sun disk, glints) so bloom stays a halo, not a flood
47
+ const HighlightShader = {
48
+ uniforms: { tDiffuse: { value: null as THREE.Texture | null } },
49
+ vertexShader: /* glsl */ `varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }`,
50
+ fragmentShader: /* glsl */ `
51
+ uniform sampler2D tDiffuse; varying vec2 vUv;
52
+ void main() {
53
+ vec3 c = texture2D(tDiffuse, vUv).rgb;
54
+ float m = max(max(c.r, c.g), c.b);
55
+ float k = m > 4.0 ? (4.0 + (m - 4.0) / (1.0 + (m - 4.0) * 0.35)) / m : 1.0;
56
+ gl_FragColor = vec4(c * k, 1.0);
57
+ }`,
58
+ }
59
+
60
  const GradeShader = {
61
  uniforms: {
62
  tDiffuse: { value: null as THREE.Texture | null },
 
113
  composer.addPass(new RenderPass(scene, camera))
114
  const rays = new ShaderPass(GodRaysShader)
115
  composer.addPass(rays)
116
+ composer.addPass(new ShaderPass(HighlightShader))
117
  const bloom = new UnrealBloomPass(new THREE.Vector2(w, h), 0.5, 0.55, 0.92)
118
  composer.addPass(bloom)
119
  composer.addPass(new OutputPass())
src/jiangnan/engine/sky.ts CHANGED
@@ -45,7 +45,7 @@ export function skyState(t: number): SkyState {
45
  sun: mixRGB(a.sun, b.sun, f), sunI: lerp(a.sunI, b.sunI, f),
46
  cloudLit: mixRGB(a.cloudLit, b.cloudLit, f), cloudDark: mixRGB(a.cloudDark, b.cloudDark, f),
47
  // camera "eye adaptation": open up as the light fades
48
- exposure: lerp(0.85, 1.55, smoothstep(1, -9, elev)),
49
  }
50
  }
51
 
@@ -130,7 +130,7 @@ void main() {
130
  col += uSunCol * (g1 * 0.12 + g2 * 0.5 + g3 * 2.2) * (0.3 + uSunI * 0.3) * sunVis;
131
  // sun disk (slightly oversized for cinematic effect), dimmed and reddened near the horizon
132
  float disk = smoothstep(0.99982, 0.99990, sunDot);
133
- col += uSunCol * disk * (20.0 + uSunI * 18.0) * smoothstep(-0.02, 0.01, uSunDir.y);
134
 
135
  // clouds: thin stratus / cirrus layer
136
  if (h > 0.0) {
 
45
  sun: mixRGB(a.sun, b.sun, f), sunI: lerp(a.sunI, b.sunI, f),
46
  cloudLit: mixRGB(a.cloudLit, b.cloudLit, f), cloudDark: mixRGB(a.cloudDark, b.cloudDark, f),
47
  // camera "eye adaptation": open up as the light fades
48
+ exposure: lerp(0.72, 1.5, smoothstep(1, -9, elev)),
49
  }
50
  }
51
 
 
130
  col += uSunCol * (g1 * 0.12 + g2 * 0.5 + g3 * 2.2) * (0.3 + uSunI * 0.3) * sunVis;
131
  // sun disk (slightly oversized for cinematic effect), dimmed and reddened near the horizon
132
  float disk = smoothstep(0.99982, 0.99990, sunDot);
133
+ col += uSunCol * disk * (7.0 + uSunI * 4.0) * smoothstep(-0.02, 0.01, uSunDir.y);
134
 
135
  // clouds: thin stratus / cirrus layer
136
  if (h > 0.0) {
src/jiangnan/engine/water.ts CHANGED
@@ -75,7 +75,7 @@ void main() {
75
  // sun glitter
76
  vec3 R = reflect(-V, N);
77
  float sd = max(dot(R, uSunDir), 0.0);
78
- col += uSunCol * (pow(sd, 900.0) * 18.0 + pow(sd, 120.0) * 0.9) * uSunI * smoothstep(-0.01, 0.03, uSunDir.y);
79
  col = applyWorldFog(col, vWorld);
80
  if (uDebug > 1.5) col = vec3(uv, 0.0);
81
  else if (uDebug > 0.5) col = refl;
 
75
  // sun glitter
76
  vec3 R = reflect(-V, N);
77
  float sd = max(dot(R, uSunDir), 0.0);
78
+ col += uSunCol * (pow(sd, 900.0) * 5.0 + pow(sd, 120.0) * 0.45) * uSunI * smoothstep(-0.01, 0.03, uSunDir.y);
79
  col = applyWorldFog(col, vWorld);
80
  if (uDebug > 1.5) col = vec3(uv, 0.0);
81
  else if (uDebug > 0.5) col = refl;