defnotmid

Projects / 06

o3d

3D for Odin in three.js's vocabulary. Every frame is described from scratch and drawn on the GPU through SDL_GPU, or on the CPU by a software renderer that draws the same picture.

  • Odin
  • MIT
  • three.js terms
  • SDL_GPU · CPU
  • glTF · 3MF · OBJ
48 seconds of o3d at 60 fps, every frame an onimite script drawn by o3d, to a song made with odawg. Oxa lifts from 32 × 32 pixel art into voxels; standard, physical (clearcoat, transmission, sheen) and toon materials; a shadow-casting spotlight, emissive light and bloom; glTF skins, morph targets and animation; 2D panels and extruded shapes drawn on 3D surfaces; and the same view split between the GPU (SDL_GPU on Vulkan) and the software renderer on the CPU, which match in all 49 of gpu_check's cases. Rendered by onimite v0.1.0. Models from the Khronos glTF Sample Assets: Fox, model CC0 by PixelMannen, rigging and animations CC-BY 4.0 by @tomkranis; AnimatedMorphCube and ToyCar, CC0. Source: o3d's demo/intro at e9ded22e.
The same scene twice: a red sphere, a yellow torus, a dark cube and a see-through blue panel on a lit floor, rendered on the GPU (left) and on the CPU (right).
o3d's demo scene (odin run demo) at 960×540, drawn on the GPU through SDL_GPU on Vulkan (left) and by the software renderer on the CPU (right): PSNR 60.7 dB between them, and 44 of 518,400 pixels off by more than one level.

By the numbers

parity cases match, GPU vs CPU
49 / 49
on Vulkan (RADV) and Metal (Apple M4); PSNR 43.8 dB (motion blur) to 71.1 dB (shapes) on RADV
heap allocations a warm frame
0
the software renderer, run by the benchmark under an allocator that panics
model formats
3
glTF 2.0 / GLB, 3MF and OBJ with MTL, into the same tables
shadow-casting lights a frame
4
directional or spot, with PCF

Parity from tools/gpu_check on o3d v0.1.0 with oksl v0.1.0, 2026-11-17, on an AMD Radeon RX 9070 series (Vulkan through RADV) and an Apple M4 (Metal); allocations from bench on v0.0.11, 2026-10-16 on an RX 9070 XT (Vulkan through RADV); formats and the shadow limit from the README.

What's in it

  1. 01What three.js knows carries over

    Right-handed and Y up, Euler rotations in radians, a vertical field of view in degrees, and MeshStandardMaterial, MeshBasicMaterial, MeshToonMaterial and ShaderMaterial with three.js's parameters and light units.

  2. 02Two renderers, one picture

    SDL_GPU on Vulkan or Metal, and a software renderer that is the reference the GPU is tested against. On Metal, checked on an Apple Silicon Mac (macOS 27): every tools/gpu_check case matches the software renderer. A CPU frame is the same bytes with or without a thread pool.

  3. 03Your own shaders

    ShaderMaterial takes GLSL ES (three.js's GLSL 1 style, or GLSL 3) with three.js's built-in uniforms plus instanceColor and instanceId, compiled at run time by oksl for both renderers: no shader toolchain to install.

  4. 04Lights and shadows

    Ambient, hemisphere, directional, point and spot lights; PCF shadows from directional and spot lights; image-based lighting from equirectangular environments, fog, and Linear, Reinhard, Cineon, ACES Filmic, AgX or Neutral tone mapping.

  5. 05Models people make

    glTF 2.0 with node hierarchies, skins, morph targets, keyframe animation, punctual lights, texture transforms and quantized meshes; 3MF and OBJ load into the same tables and draw the same way.

  6. 06Geometry by parameters

    Box, sphere, plane, cylinder and cone, torus and capsule, a lit tube through points each frame, lines, polylines, wireframes and point clouds; any draw can be instanced, with a colour per instance.

  7. 07Frames from scratch

    A frame is a pure function of whatever drives it: the scene is refilled every frame, while geometry and textures are kept, and the same parameters give the same geometry id.

  8. 08Data-oriented

    Flat tables, draws as a structure of arrays, interleaved 40-byte vertices, and skins and morphs in arrays of their own so plain meshes pay nothing. The CPU draws in bands of 32 rows, 4x MSAA on both renderers.

Not yet

  • Compressed glTF (Draco, meshopt, KTX2 / Basis and WebP textures) fails cleanly when required; transmission, clearcoat, sheen and the other optional PBR extensions are ignored.
  • No shadows from point lights.
  • No textures that change every frame, and no textures in ShaderMaterials.

Use it

geos: o3d.Geometries                       // kept: geometry is made once
textures: o3d.Textures                     // kept: textures and mipmaps are made once
albedo, _ := o3d.texture_load(&textures, "brick.png")
scene: o3d.Scene                           // filled every frame
o3d.scene_clear(&scene)
scene.camera = {position = {0, 2, 6}, target = {0, 0.5, 0}, fov = 40, near = 0.1, far = 100}
scene.tone_mapping, scene.tone_mapping_exposure = .ACES_Filmic, 1.0
scene.fog = {kind = .Exp2, color = {0.05, 0.06, 0.08}, density = 0.04}
append(&scene.lights, o3d.Light{kind = .Hemisphere, color = {0.8, 0.9, 1}, ground = {0.2, 0.15, 0.2}, intensity = 1.5})
append(&scene.lights, o3d.Light{kind = .Directional, color = {1, 1, 1}, intensity = 2.5, position = {3, 5, 2},
	cast_shadow = true, shadow = {map_size = 1024, bias = -0.0005}})
m := o3d.MATERIAL_DEFAULT
m.color, m.roughness, m.color_map = {1, 0.35, 0.3}, 0.4, albedo
m.flags = {.Cast_Shadow, .Receive_Shadow}
append(&scene.draws, o3d.Draw{o3d.box(&geos, 1, 1, 1), o3d.compose({0, 0.5, 0}, {0, t, 0}), m})

The family