abyssal-garden README

项目的 README,来自 github.com/Noniv/abyssal-garden。合并为一个 markdown 文件:README.md。

Abyssal Garden

A dreamy underwater world you can swim through, right in your browser.

Towering kelp forests, sunbeams pouring through a rippling surface, a sunken ship, manta rays gliding overhead. And all of it is made by code: no images, no 3D models, no sound files. The whole world fits in one 96 KB HTML file.

Kelp forest with a stone whale tail and a manta ray

Try it

  1. Download index.html.
  2. Open it in Chrome or Edge on a desktop computer.
  3. Wait a few seconds while the world is built, then press Dive in and start swimming.

Nothing to install, and it works offline. It needs a browser with WebGPU. If you see "This scene needs WebGPU", update your browser or switch to Chrome / Edge.

What's down there

Shipwreck Looking up through the kelp
Barrel sponges Light rays over the kelp basin

The purple grotto

Controls

Keyboard & mouse
Look around Move the mouse
Swim W A S D
Up / down E / Q
Swim faster Hold Shift
Jump to a viewpoint 1 to 6 (the spots in the screenshots)
Menu Esc releases the mouse and opens the menu with the list of controls; Resume takes you back
Sound on / off M (sound starts when you dive in)
Performance stats H
Detail level Low, Medium or High in the menu (reloads the page)

The seabed, cliffs and arches are solid: you glide along the rock instead of swimming into it, and you still fit through every tunnel and arch. Kelp, plants, corals, sponges, loose rocks, the floating boulders, the ship and the whale tail you can swim through.

On a touchscreen: hold one finger down to swim forward and slide it to steer. Put a second finger down to go faster. The ≡ button in the corner opens the menu. Phones always show the scene in landscape and start on Low or Medium detail. (Touch support is experimental.)

Detail levels

The Low, Medium and High buttons in the menu pick the detail level; the current one is lit. Each level is the same world, built with less in it:

Level What it is Picked on a first visit for
High The full scene Computers
Medium Half of the leaves, sparkles and pebbles; small rocks, sponges and corals cast no shadows Phones with 8 GB of memory
Low A quarter of the leaves, no anti-aliasing, coarser rocks and corals, simpler lighting, 480p to start with Other phones, and computers with 4 GB of memory or less

If loading crashes the tab, or the graphics driver gives up, the page starts again one level lower. Your browser remembers the level, and the resolution and draw distance the scene settled on, for the next visit.

How it works

Make it your own

The readable source code is in the source folder. To change something and rebuild index.html you need Node.js 18 or newer:

cd source
npm install
npm run build

This writes a new index.html next to this README. npm run build:readable writes an unminified version instead, which is easier to debug in the browser's developer tools.

npm run build:dev writes a separate dev.html with two extra tools that are not part of index.html: F flies the camera along a one-minute path through the whole world, and B runs that flight as a benchmark and reports frame and GPU times.

File What's inside
source/src/world.js The world layout: rock walls, arches, tunnels, kelp forests, sponge gardens, fish schools, mantas, the ship and the whale tail. A good place to start.
source/src/shaders.js The look: water and fog colors, lighting, kelp, rocks, the water surface and light rays (WGSL shader code)
source/src/main.js The renderer, the camera, the controls, the six viewpoints and the camera path the world is laid out around
source/src/audio.js The soundscape
source/src/quality.js The detail levels: which one a device starts on, and what is remembered between visits
source/src/math.js Noise, random numbers and mesh-building helpers
source/src/dev.js Development tools (fly-through and benchmark), only in dev.html
source/template.html The page around the scene: loading bar, start menu, links and their styles

Some easy first tweaks:

License

MIT: free to use, change and share, including in your own projects.

abyssal-garden (Noniv/abyssal-garden)

正在搜索数据库…

这是什么?一个梦幻的水下世界,可以在浏览器里游览,里面有海带森林、光束、沉船和魔鬼鱼。所有内容都由代码生成,因此没有图片、3D 模型或声音文件。
有没有目标,还是只是用来探索的?README 描述的是一个可以探索的场景:你可以游动、环顾四周、观赏这个世界。文中没有提到任何目标或游戏机制。
怎么让它运行起来?下载 index.html,然后在桌面电脑上用 Chrome 或 Edge 打开。等几秒钟让世界加载完成,然后点击 Dive in 即可。无需安装,离线也能使用。
需要什么浏览器?需要支持 WebGPU 的浏览器。推荐在桌面电脑上使用 Chrome 或 Edge。如果场景无法启动,请更新浏览器,或改用这两款浏览器之一。
手机上也能用吗?可以,但属于实验性支持。用一根手指按住即可向前游,滑动手指可以转向;加上第二根手指可以加速。菜单按钮位于角落。手机上场景始终以横屏显示。
我可以把它用在自己的项目里吗?可以。它采用 MIT 许可证,因此你可以自由地使用、修改和分享,包括用在自己的项目中。
没有任何图片或模型,整个世界是怎么构建出来的?每次打开页面时,海底都会在你的显卡上实时雕琢出来;海带、岩石、沉船和鲸鱼尾巴则由简单的数学图形搭建。声音通过 Web Audio API 实时合成。
这个场景有哪些操作方式?移动鼠标可以环顾四周,使用 W A S D 游动,E 和 Q 分别用于上浮和下潜。按住 Shift 可以加速游动,按 1 到 6 跳转到不同的观景点,按 M 控制声音,按 H 查看性能数据。按 Esc 打开菜单。
我能自己修改这个场景吗?可以。可读的源代码位于 source 文件夹中,使用 Node.js 18 或更新版本即可重新构建 index.html。水的颜色、阳光、亮度和游动速度是最容易上手调整的参数。
Low、Medium 和 High 三档画质有什么区别?它们展示的是同一个世界,但较低档位中的树叶、闪光和卵石数量更少;Low 档还会关闭抗锯齿并简化光照。浏览器会记住你选择的画质,下次访问时自动沿用。
作者
Noniv
大小
1.7 MB
星标
2.1K
更新
提交Nov 14
时长
6天
提交 · 90 天