К основному содержанию
скилл CX Codex

3d-underwater-god-rays — скилл для Claude Code: лучи под водой

Скилл 3d-underwater-god-rays добавляет в сцену Three.js объёмные лучи света под водой: поле волн маршируется вдоль каждого луча зрения, и столбы сходятся на солнце.

MIT ★ 7 995 обновлён 2026-10-25

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add MengTo/Skills --skill 3d-underwater-god-rays -a claude-code
Открыть на GitHub

Что делает 3d-underwater-god-rays

Скилл кладёт в сцену объёмные лучи: одно поле дрейфующей зыби сэмплируется поперёк направления на солнце и интегрируется вдоль каждого луча зрения. Отсюда и параллакс — когда камера едет, столбы света проходят мимо рыб, а не висят на линзе. В комплекте переиспользуемый модуль assets/underwater-light.mjs: свой THREE вы передаёте снаружи, вторую копию библиотеки он не тянет.

Марш идёт в отдельный HalfFloat-таргет половинного разрешения, апскейл — четырёхточечный tent. Проверено на Three.js r170, WebGL2 и GLSL-материалах ShaderMaterial, тонмаппинг ACES написан руками, без библиотеки постобработки. Порядок в кадре важен: обновить uTime, вызвать camera.updateMatrixWorld(), затем light.render(renderer), и только потом воду с рыбой и один тонмаппинг в конце. Размер задаётся в пикселях drawing buffer и повторяется при ресайзе.

Камера над водой? Скилл не тот. Поверхность океана с горизонтом рисует 3d-ultra-realistic-water, а лучи в воздухе, пробитые кронами, берёт 3d-sky-rays. У второго экранное размытие маски не даёт ни параллакса, ни ряби, поэтому под водой он годится лишь как тихий компаньон для теней от рыб. Марш начинается в 4 единицах от камеры: со старта в 1.5 единицы один столб над камерой заливал четверть кадра ярким клином.

Какие задачи решает

  • добавить лучи света в подводную сцену Three.js
  • привязать столбы света к солнцу, чтобы они сходились в одну точку
  • превратить каустику в полосы вдоль каждого луча, а не в ровную дымку
  • покрасить рыб пятнами света, когда они проплывают через лучи
  • переиспользовать готовый модуль, не подключая вторую копию THREE

Примеры запросов агенту

  • Добавь подводные лучи в мою сцену Three.js через underwater-light.mjs, направление на солнце задай в uSunDirection.
  • Пусти марш в таргет половинного разрешения и не забудь вызвать light.setSize ещё раз при ресайзе.
  • Считай каустику внутри марша, а не наложением в экранном пространстве.

Как установить 3d-underwater-god-rays

1Через Skills CLI (Vercel)

npx skills add MengTo/Skills --skill 3d-underwater-god-rays -a claude-code

2Вручную: положить файлы

~/.claude/skills/3d-underwater-god-rays/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/3d-underwater-god-rays/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Вопросы о 3d-underwater-god-rays

Как установить 3d-underwater-god-rays в Claude Code?

Одна команда: npx skills add MengTo/Skills --skill 3d-underwater-god-rays -a claude-code. Файл скилла окажется по пути ~/.claude/skills/3d-underwater-god-rays/SKILL.md.

Что делает 3d-underwater-god-rays?

Рисует объёмные лучи света в подводной сцене Three.js: марш на половинном разрешении, каустика внутри марша, подсвеченная изнутри поверхность воды и блики на рыбе.

Чем он отличается от 3d-sky-rays?

3d-sky-rays работает в воздухе и размывает маску окклюзии в экранном пространстве. Под водой ему не хватает параллакса и ряби, поэтому в Blue Hour он идёт лишь как дешёвый слой для теней от рыб.

Исходный текст

SKILL.md · MIT
---
name: 3d-underwater-god-rays
description: Add volumetric underwater god rays to a Three.js scene, marching one drifting swell field along every view ray at half resolution so the light shafts converge on the sun, parallax with the camera and carry rippling caustic streaks, with a shimmering surface underside, a sun that wobbles through the ripples, and the same light dappling fish as they swim through the beams. Use for underwater scenes, oceans seen from below, aquariums, reefs, kelp forests, diving and shipwreck scenes, schools of fish, sunbeams or light shafts through water, caustics, "rays of light shining through the ocean", or watery ripples on a background. Includes a reusable module and the Blue Hour sardine-school demo.
---

# 3D Underwater God Rays

Use this when the camera is under the water and the light comes down through it. Reach for a sibling instead in these cases:

- **Sun shafts in air, cut by trees and rooflines:** use `3d-sky-rays`. Its screen-space radial blur of an occlusion mask is the right tool there. It cannot parallax or carry ripples, so under water keep it only as a low companion for fish shadows (Blue Hour runs it at 0.25).
- **The ocean surface seen from above, with a horizon:** use `3d-ultra-realistic-water`.
- **Authored shaft planes through one window in a lit interior:** use `3d-wood-lighting-scorecard`.

Source: extracted from **Blue Hour**, the living-ocean wallpaper of a Three.js iPhone Duo study. A school of 2,200 Blender sardines turns behind a glass device. The light had to read as sun through water across the whole 38 s camera dolly and on the device's own screen.

Verified stack: Three.js r170, WebGL2, GLSL `ShaderMaterial`s, one HalfFloat render target, and a hand-written ACES pass. No post-processing library.

## The mechanism

**Sample one drifting swell field across the sun direction, and integrate it along every view ray.** Each point in the water is lit by the swell value at its position measured perpendicular to the sun. The shafts are therefore parallel columns in the world. They converge on the sun the way rails converge on a vanishing point, and they slide past the fish when the camera moves. Paint the same shafts in screen space and they stay locked to the lens.

## Reuse the working effect

Copy [assets/underwater-light.mjs](assets/underwater-light.mjs). You pass in your own `THREE`, and the module does not import a second copy. [The demo](demo/index.html) runs this same module inside Blue Hour's renderer. `demo/build.mjs` rebuilds it from the Blue Hour sources.

```js
import { createUnderwaterLight, LIGHT_GLSL, WATER_GLSL } from './underwater-light.mjs';

// One uniforms object shared by the water, fish and particle materials.
const uniforms = {
  uSunDirection: { value: new THREE.Vector3(.25, .40, -1).normalize() },   // toward the sun
  uTime: { value: 0 },
  uCameraPosition: { value: camera.position },
  uCameraWorld: { value: camera.matrixWorld },
  uInverseProjection: { value: camera.projectionMatrixInverse },
};
const light = createUnderwaterLight(THREE, { uniforms });   // before creating the materials below
light.setSize(innerWidth * dpr, innerHeight * dpr);          // drawing-buffer pixels, again on resize

// Water: a full-screen quad. Declare uSunDirection, uCameraPosition, uTime,
// uShafts and uShaftTexel, then add ${LIGHT_GLSL}${WATER_GLSL} and in main():
//   vec3 sunRay = ray;
//   color += surfaceUnderside(ray, sunRay);     // also bends sunRay through the ripples
//   ...draw your sun with sunRay...
//   color += underwaterShafts(vUv, ray);
// Fish: declare uSunDirection, then add ${LIGHT_GLSL} and multiply the sun key
// by underwaterDapple(worldPosition, uTime).

// Every frame, in this order:
uniforms.uTime.value = time;
camera.updateMatrixWorld();
light.render(renderer);          // the march, into its own half-resolution target
// then the water, the fish, and one tone map at the end
```

## The numbers that shipped

| layer | constants |
| --- | --- |
| Swell | 4 sines along (.86, .51), (−.42, .91), (.13, −.99), (−.97, −.24) at ×1, 1.23, 0.87, 1.41; drift 0.29, 0.24, 0.19, 0.15 rad/s; domain warp 0.62 |
| Across the sun | scale 1.3, so the main period is about 4.8 world units against a frame about 22 units wide at the school |
| Shaft focus | `smoothstep(−0.05, 1, swell)²`, faded by `exp(−0.012 · distance to the surface along the sun)` |
| Caustic web | the swell again at ×2.6 and 1.35× speed, `(1 − |s|)^5`; light = focus × (0.45 + 0.9·web) |
| March | 26 steps, `t = 4 + 50·f²`, weight `exp(−0.06t)·(0.08 + f)`, divided by the weight sum; a stable per-pixel jitter (interleaved gradient noise) instead of temporal noise |
| Sun blend | `total = mix(total, 0.16, μ^28)`, where μ = ray·sun |
| Phase | `0.7 + 1.1μ^5 + 0.9μ^40`; rays below the horizon × `mix(0.45, 1, smoothstep(−0.45, 0.35, ray.y))` |
| Gain | (0.16, 0.40, 0.47) × 3.6, linear HDR, tone-mapped once at the end |
| Buffer | 0.5 × the drawing buffer, HalfFloat, single-sampled (the march is soft, so MSAA buys nothing), upsampled with a 4-tap tent at ½ texel |
| Surface underside | plane at y = 12; network `(1 − |swell(1.15s, 1.6t)|)^8·0.75 + (1 − |swell(2.19s, 2.1t)|)^10·0.55`; fog `exp(−0.028d)`; detail faded by `1 − smoothstep(0.35, 1.6, 0.9·|fwidth(s)|)`; colour (0.098, 0.221, 0.26); sun ray bent by 0.018 × the ripple slope |
| Fish | sun key × `0.62 + 1.5 · shaftLight` |
| The rest of the frame | sun corona halved to (0.043, 0.095, 0.123)·μ^48; screen-space ray pass cut from 0.82 to 0.25 |

## Rules, each with the failure it prevents

These came from A/B renders of the Blue Hour frame: the same camera, the same frozen fish, one change at a time.

- **Shape the swell into sparse peaks, not ridges.** `1 − |swell|` makes a web of thin sheets, and a ray that crosses many sheets averages them into flat haze. On a frozen frame the ridge web raised the mean brightness of the water by 20% and halved the contrast between pixel columns, from 0.247 to 0.118. The demo's **Ridge web** switch shows it.
- **Start the march 4 units out.** Starting at 1.5 units, a shaft passing over the camera filled a quarter of the frame with one bright wedge. Weight the samples by `exp(−0.06t)`: the near ones smear least, so they hold the beam edges.
- **Merge the shafts into the sun's glow as the ray points at it.** Looking straight up one column, the integral is a single swell value. Where the camera sat between shafts, that left a dark hole on the sun. `mix(total, 0.16, μ^28)` closes it.
- **Integrate the caustic web inside the march.** Sampled 4 times at full resolution instead, the web reads as a pool floor painted over the water. Inside the 26-step march at half resolution, it becomes fine streaks that run along each beam. The demo's **Painted on screen** switch shows it.
- **Turn down any uniform glow already in the frame.** Blue Hour's corona and screen-space ray pass lit the top of the frame evenly. The first shafts barely showed in the composite at about the gain that later shipped. They read only after the corona was halved and the radial pass cut from 0.82 to 0.25, so the shafts carry the light and the gaps stay dark.
- **Judge the gain on the composed page, not the raw canvas.** Gain 2.2 looked right on the canvas. On the page, where the canvas sits at 82% opacity under a darkening CSS shade, the same frame showed almost nothing. 3.6 survives the page.
- **Lift the sun above the top edge for full-frame beams.** At 21° the sun sits in frame: the convergence point is a glow and the beams are short. Between 30° and 44° it clears the top edge, and the beams fan down the whole frame. The demo's **Sun** slider sweeps it.
- **Declare each uniform once per shader.** `LIGHT_GLSL` declares its own uniforms (`uSurfaceY`, `uShaftScale`, `uShaftFloor`, `uCompare`) and expects the host to declare `uSunDirection` before it. Declaring one twice is a compile error, and the material quietly draws nothing.

## Cost

Under heavy machine load (load average about 60), headless Chrome on ANGLE Metal rendered the whole Blue Hour frame in 6–10 ms at 2048×1440. That frame includes 2,200 instanced sardines, the water, the 1024×720 march, the screen-space ray pass and the tone map. Skipping the march changed the median by less than the run-to-run noise (about ±2 ms) across 5 alternating rounds of 20 frames, so it is not the bottleneck here. If it shows up in your profile, lower the buffer scale or the step count. The shafts are low frequency, so both mostly cost softness, but measure that before you rely on it.

## Lifecycle and accessibility

- Step the simulation at 30 fps, with each step capped at 0.1 s. Blue Hour renders the aquarium into a fixed 2048×1440 canvas (1600×1125 below 800 px) and cover-fits it, so the march cost doesn't scale with the screen.
- Under `prefers-reduced-motion: reduce`, hold the frame at t = 0 and re-render only when a control changes. The jitter is stable per pixel, so a still frame doesn't crawl.
- Stop on `document.hidden`, and reset the frame clock on `visibilitychange` so the first frame back doesn't integrate the whole pause.

## Verify

- [ ] Orbit the camera: the shafts slide against the fish and still converge on the sun. If they move with the lens, they are painted in screen space.
- [ ] With **Ridge web** on, the water turns to haze. Back on sparse peaks, you see distinct beams with dark water between them.
- [ ] With **Painted on screen** on, a pool-floor web covers the water. Inside the march, fine streaks run along each beam.
- [ ] Looking straight at the sun, there is no dark hole.
- [ ] Sweep the sun from 21° to 44°: the convergence point moves off the top edge, and the beams lengthen across the frame.
- [ ] A fish crossing a beam brightens and dims again past it.
- [ ] Reduced motion holds a composed still, the controls still re-render it, and the console is clean at 1440×900 and 390×844.

© MengTo · MIT · MengTo/Skills

Похожие скиллы

Все скиллы по теме «Геймдев и 3D: Unity, Unreal, Godot, Blender» →
threejs-aaa-graphics-builder majidmanzarpour Скилл threejs-aaa-graphics-builder переводит браузерную 3D-графику Three.js из прототипа в качественный продакшен: настраивает материалы, свет, шейдеры и проверяет сцену по шкале качества. CX Codex +1 4 300установок threejs nexu-io Помогает ассистенту создавать 3D-сцены, настраивать материалы, камеру и пост-обработку на Three.js прямо в браузере. CX Codex +1 3 600установок three-best-practices three-agent-skills Скилл three-best-practices для Claude Code с правилами оптимизации Three.js. Срабатывает при написании, ревью и отладке кода с 3D-сценами, WebGL/WebGPU, шейдерами и TSL. CX Codex +1 1 700установок threejs-3d-graphics omer-metin Скилл threejs-3d-graphics задаёт агенту роль сеньор-разработчика WebGL и Three.js: помогает писать шейдеры на GLSL, снижать число draw calls и настраивать 3D-сцены в браузере. CX Codex +1 477установок cloudai-threejs podo Скилл cloudai-threejs для Claude Code объединяет инструкции по Three.js, WebGL, WebGPU и React Three Fiber для создания 3D-сцен, шейдеров и анимаций без устаревших паттернов. CX Codex +1 207установок tsl-complete-reference zebbern Правило tsl-complete-reference для Claude Code даёт справочник по TSL и помогает писать нодовые шейдеры без ошибок в типах и вызовах. CX Codex +1 ★ 4 719звёзд репо

Из того же набора178

Весь набор →
game-dev-combat-animation Скилл game-dev-combat-animation для Claude Code создаёт и проверяет боевые анимации персонажей: удары, выстрелы из лука, заклинания и атаки монстров. Выявляет проблемы в руках, кистях и оружии. CX Codex +1 ★ 7 995звёзд репо 3d-paper-material Скилл 3d-paper-material для Claude Code строит лист бумаги в Three.js с рельефом волокон, рваным краем и полупрозрачностью на просвет. Заменяет плоскую белую плоскость с прямыми краями. CX Codex +1 ★ 7 995звёзд репо game-dev-combat-skill-polish Скилл game-dev-combat-skill-polish оценивает боевые скиллы и заклинания по десятибалльной шкале и дорабатывает анимации, тайминги и визуальные эффекты до целевой планки. CX Codex +1 ★ 7 995звёзд репо 3d-cloth-material Скилл 3d-cloth-material для Claude Code создаёт материалы ткани для Three.js с переплетением нитей, складками, швами и просвечиванием. Описывает материалы для шёлка, шерсти и других драпировок. CX Codex +1 ★ 7 995звёзд репо 3d-metal-material Скилл 3d-metal-material настраивает реалистичные PBR-металлы в Three.js: физика проводника без альбедо, линейные значения F0, студия из ярких плашек с PMREM и слои шероховатости. CX Codex +1 ★ 7 995звёзд репо 3d-wood-material Скилл 3d-wood-material для Claude Code создаёт процедурный материал дерева для Three.js с годичными кольцами, порами, лучами, трещинами и следами инструмента из одного шума, без текстурных карт. CX Codex +1 ★ 7 995звёзд репо 3d-wood-lighting-scorecard Скилл 3d-wood-lighting-scorecard настраивает свет, процедурные текстуры дерева и объёмные лучи в Three.js, затем оценивает результат по рубрике и доводит каждый пункт до целевого балла. CX Codex +1 ★ 7 995звёзд репо html-demo Скилл html-demo помогает воссоздать работу интерфейса на чистом HTML и React вместо записи тяжёлых видео или GIF. Окно поэтапно воспроизводит сценарий, оставаясь чётким на любой плотности пикселей. CX Codex +1 ★ 7 995звёзд репо

Спонсоры проекта

Компании, которые помогают держать аналитику открытой