v0.1.1NeverDark ModuleBSD-2-Clause

GPU-skinned, instanced OpenGL ES 3.0 / WebGL2 creature renderer for NeverDark.

GitHub
git clone https://github.com/tty-pt/nd-mob-gl

Documentation

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 per geom_hash into static GL_STATIC_DRAW VBO/IBO pairs (dynamically grown species cache with no hard species cap).
  • 64-byte instanced actor record (nd_mob_gl_inst_t) + 100ร—256 GL_RGBA32F bone & palette LUT on GL_TEXTURE14 (32 mat3x4 bones = 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_ATLAS to nd_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 via nd_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-pixel MOB_SURF_SPOTTED coat patterns (vPalSec varying 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_KHR before GL_LINK_STATUS for KHR_parallel_shader_compile and browser shaderWorker compatibility.
  • 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 (pass ND_MOB_GL_FLAG_ASYNC_ATLAS for non-blocking placeholder atlases)
  • nd_mob_gl_reset_context(int flags) โ€” rebuild GL state after WebGL context loss/reset
  • nd_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 buffers
  • nd_mob_gl_draw_shadow(const nd_mob_shadow_pass_t *pass) โ€” directional depth-only shadow pass
  • nd_mob_gl_draw_color(const nd_mob_frame_t *frame) โ€” PBR color + 8-shell volumetric fur passes
  • nd_mob_gl_get_stats(nd_mob_gl_stats_t *out) โ€” query draw calls, cached species, and active actor counts
  • nd_mob_gl_get_bone_matrix(uint64_t ref, uint8_t bone_idx, float *out_m34) โ€” read world/actor mat3x4 bone socket transform
  • nd_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.

Maintained by:tty-pt