GPU-skinned, instanced OpenGL ES 3.0 / WebGL2 creature renderer for NeverDark.
git clone https://github.com/tty-pt/nd-mob-glDocumentation
nd-mob-gl
GPU-skinned, instanced OpenGL ES 3.0 / WebGL2 creature renderer for NeverDark.
Built on the pure-C procedural creature DNA, watertight Catmull-Clark rigs, 2-bone slope IK, FK animation, and 2048ร2048 procedural PBR atlas headers from nd-mob, exposed across the libxylem XY two-header boundary (<nd/mob-gl-types.h> / <nd/mob-gl.h>).
Architecture
- 64-byte cache-line-aligned GPU-skinned vertex (
nd_mob_gl_vert_t): position, normal, color, 2-bone skinning indices/weights, surface/material flags, and UVs, lazily cached pergeom_hashinto staticGL_STATIC_DRAWVBO/IBO pairs (dynamically grown species cache with no hard species cap). - 64-byte instanced actor record (
nd_mob_gl_inst_t) + 100ร256GL_RGBA32Fbone & palette LUT onGL_TEXTURE14(32mat3x4bones = 96 texels + 4 RGBA32F palette slots per actor, up to 256 actors/frame). - 2048ร2048 procedural PBR atlases with optional async tile streaming:
GL_TEXTURE13: 2048ร2048 albedo + alpha atlas (4ร4 grid of 512ร512 padded tiles).GL_TEXTURE15: 2048ร2048 tangent-space normal + roughness + AO atlas.- Pass
ND_MOB_GL_FLAG_ASYNC_ATLAStond_mob_gl_init()/nd_mob_gl_reset_context()to bind instant 1ร1 placeholders at startup and stream individual 512ร512 tiles (plus 10-level mipchains) incrementally viand_mob_gl_upload_atlas_tile(). - Three-pass biological & forged-metal PBR pipeline:
- Depth-only shadow pass (
nd_mob_gl_shadow_vs_src/nd_mob_gl_shadow_fs_src) with normal-offset shadow bias. - Opaque PBR color pass (
nd_mob_gl_color_vs_src/nd_mob_gl_color_fs_src): NaN-safe TBN normal mapping, weathered/dark isotropic forged steel PBR, dermal subsurface scattering (SSS), warm material shadow tinting, eyelid cast shadows,MOB_SURF_ANISO_V-gated Kajiya-Kay hair specular, and per-pixelMOB_SURF_SPOTTEDcoat patterns (vPalSecvarying within GLSL ES 3.00 limits). - 8-shell volumetric fur/fleece pass (
nd_mob_gl_fur_vs_src/nd_mob_gl_fur_fs_src): grazing-attenuated combed directional fur shells with stencil and alpha writes disabled during the shell pass. - Terrain slope IK & secondary motion: consumes per-actor 4-foot ground deltas (
nd_mob_actor_in_t.foot_dz[4],ik_active) and terrain slope normals alongside per-actor cloth/hair/beard spring physics and blinking. - Non-blocking async shader compilation: compiles shadow, color, and fur programs asynchronously and polls
GL_COMPLETION_STATUS_KHRbeforeGL_LINK_STATUSforKHR_parallel_shader_compileand browsershaderWorkercompatibility. - Dual target: compiles natively (
lib/libnd-mob-gl.so/ static link with-DLAM_WEBGL_NATIVE) and to browser WebAssembly via<ttypt/webgl.h>.
Public XY API (<nd/mob-gl.h>)
nd_mob_gl_init(int flags)โ initialize GL resources (passND_MOB_GL_FLAG_ASYNC_ATLASfor non-blocking placeholder atlases)nd_mob_gl_reset_context(int flags)โ rebuild GL state after WebGL context loss/resetnd_mob_gl_sync(const nd_mob_actor_in_t *actors, unsigned count, float dt)โ animate 32-bone rigs, slope IK, and springs; update instance and LUT buffersnd_mob_gl_draw_shadow(const nd_mob_shadow_pass_t *pass)โ directional depth-only shadow passnd_mob_gl_draw_color(const nd_mob_frame_t *frame)โ PBR color + 8-shell volumetric fur passesnd_mob_gl_get_stats(nd_mob_gl_stats_t *out)โ query draw calls, cached species, and active actor countsnd_mob_gl_get_bone_matrix(uint64_t ref, uint8_t bone_idx, float *out_m34)โ read world/actormat3x4bone socket transformnd_mob_gl_upload_atlas_tile(uint32_t tile, const uint8_t *alb_mips, const uint8_t *nrm_mips)โ incrementally upload one baked 512ร512 PBR tile + mipchain
Build & Install
Prebuilt packages across all 9 platforms (deb, apk, rpm, pacman, brew, openbsd, winget + Scoop, android-lib, and ios-lib + SwiftPM XCFramework) are distributed via tty.pt packages.
Builds use the shared libstele makefile rules (include ttypt/include.mk, or resolved via TTYPT_MK / pkg-config --variable=include_mk stele):
make
make PREFIX="$HOME/.local" install
Dependencies: nd-mob, liblamina (<ttypt/webgl.h>), libxylem, libstele.
License
BSD 2-Clause. See LICENSE.