Development#
Setting up#
nt3d’s dependencies, ntcanvas, ntgpuimage, and ntpicture among them, all come through Go modules:
git clone https://github.com/NimbleTerminal/nt3d
cd nt3d
task ciTo change ntpicture alongside nt3d, clone it beside nt3d and run task workspace, which copies go.work.example to go.work (git ignores it) so the build uses your checkout instead of the published module.
The library is one module. The demos in examples/demos are a second module, so that booba and the Bubble Tea fork the browser needs never become requirements of the library.
Tasks#
| Task | Does |
|---|---|
task ci | format check, race tests, vet (which also type-checks the GPU tests), native builds, and the complete WebAssembly gallery build |
task test-gpu | the GPU tests, which need a real WebGPU adapter and fail without one |
task fuzz-smoke | run every decoder, math, and geometry fuzz target briefly on one CPU |
task build-web, task serve | build the browser gallery, and serve it at http://localhost:8768 |
task terrain, task fur, … | run a demo |
task gogpu | run the native desktop WebGPU window viewer (examples/gogpu) |
task models-generate | regenerate the sample models the models demo embeds |
task tapes | record the demos’ GIFs and the gallery’s posters |
task docs:hugo:serve | serve this guide while editing it |
GPU tests check, among other things, that changing one node uploads only that node, that buffers survive other nodes coming and going, and that old frames replay to identical pixels. The GPU path is tested on Metal; ntgpuimage itself has been checked on Vulkan, but these demos haven’t. CI compiles the WebAssembly build.
Recording the demos#
The gallery’s posters are frames of the terminal demos, Kitty graphics and all, recorded by ntrecord from the tapes in tapes/. task tapes records every demo, or task tapes -- fur forest just some. Each tape records a GIF to share and a few poster candidates into dist/tapes/, and tapes/finish.sh copies the first that shows the scene to web/assets/, and trims and compresses the GIF. Only the posters are committed. Recording needs ntrecord, ffmpeg, gifsicle, and a GPU.
This guide#
The guide is a Hugo site in docs/hugo, using the hugo-book theme as a git submodule. Fetch it once with git submodule update --init, then task docs:hugo:serve serves the guide with live reload (it needs Hugo extended). task docs:hugo:build builds it into docs/hugo/public, and task build-site builds the gallery with the guide at its /docs/, as GitHub Pages serves them (.github/workflows/pages.yml deploys every push to main). The demo posters come straight from web/assets.
Where it came from#
nt3d was extracted from ntcharts3d, keeping the engine and leaving the charts behind. MIGRATION.md describes how ntcharts3d could later be rebuilt on it. Open work is in ROADMAP.md.
Indirect lighting internals#
indirect.go and the matching helpers in wgsl/scene_indirect.wgsl separate incoming light from material response. Diffuse samples contain irradiance divided by pi; specular samples contain radiance filtered for the requested roughness. PBR applies albedo, Fresnel, sheen, and clearcoat after sampling. Toon diffuse deliberately keeps its direction-independent SH approximation.
Each indirectSample / IndirectSample contains radiance premultiplied by coverage in [0,1]. Composition is front.radiance + (1-front.coverage)*fallback.radiance, with the same over operation on coverage. A black hit still covers its fallback. The hemisphere and environment together form a complete final fallback, including when they are dark.
Apply AO to a cached source’s radiance before composition, preserving its coverage. Future screen-space hits can then replace that source without receiving AO a second time. Compose only samples with matching units and filtering, in linear HDR light (Frame.Linear); the existing non-linear working-space mode is retained for compatibility. These helpers are internal, introduce no new render passes or buffers, and compose authored box-projected probes over the environment fallback. SSR and SSGI remain future sources.