Complete standalone WebGPU lighting, global illumination, hybrid BVH ray tracing, GPU lightmapping, photometric IES/Projector lights, volumetrics, look presets, diagnostics, post-processing, and TSL shader pack (three@0.187.x, three/webgpu + three/tsl).
For AI agents: integrating the kit into a game? Read INTEGRATION.md (shipped in the package at node_modules/directed-lighting/INTEGRATION.md). It has the install, the review workflow, every option and what each rig.check() item means. llms.txt indexes the docs.
The package is not published on npm yet. Install it from GitHub (public, no login needed) and pin a commit:
git ls-remote https://github.com/directed-games/directed-lighting HEAD # prints "<sha> HEAD"
npm install github:directed-games/directed-lighting#<sha>Pin a tag (#<tag>) once release tags exist.
Drop the kit into an existing game. The game keeps its own lights, materials, camera and loop; the kit adds sky, sun shadows, sky reflections, atmosphere and post around them (coexist mode).
import * as THREE from 'three/webgpu';
import { createRenderer, createDirectedLighting } from 'directed-lighting';
const { renderer } = await createRenderer();
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);
// The game's scene, camera and lights, as they were before the kit.
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(50, innerWidth / innerHeight, 0.1, 2000);
// ...the game's meshes and lights...
const rig = createDirectedLighting(renderer, scene, camera);
addEventListener('keydown', (e) => {
if (e.code === 'KeyB') rig.setEnabled(!rig.enabled); // before/after toggle
});
const timer = new THREE.Timer();
renderer.setAnimationLoop(() => {
timer.update();
rig.update(timer.getDelta());
rig.render();
});Then run rig.check() and apply each fix until ok is true. Options (sun, post, overhaul, worldScale, pools, ...) and the take-over steps (addLevel, addActor, adoptLights, adoptMaterials) are in INTEGRATION.md.
- Turnkey Facade & glTF Auto-Wirer (
directed-lighting/rig):createDirectedLighting(renderer, scene, camera, opts)— single-call orchestrator for sky, daylight, weather, post, volumetrics, auto-exposure, auto-scaler, hybrid BVH ray tracing, GPU lightmapping, path-tracing wipe, and.dispose(). Coexists with the game by default;rig.check()reports the integration with a fix per item,rig.setEnabled(false)restores the game's own look, andrig.dispose()removes the kit and gives the game back its scene (scene switches, hot reload).prepareGLTF(gltfOrRoot, rig, rules)— sets shadow flags, wiresuserData.traceand (without a rig) IBL (neverlightsNode, so your own lights stay visible), lists opaque meshes instaticMeshes(pass static roots torig.addLevelto merge, and moving objects torig.addActor), extracts emissive sources, and detects glass/water/foliage slots (with a rig, hand them over withrig.adoptMaterials; without one they are upgraded in place).
- Artist Look Workflow (
directed-lighting/presets,schemas/look.schema.json):LOOK_THEMES— 7 curated themes (desert-cinema,cyberpunk-wet,nordic-fog,cathedral-chiaroscuro,studio-neutral,bleach-bypass,golden-hour).serializeLook,applyLookPreset,validateLookPreset,encodeLookToParam,decodeLookFromParam— one-click JSON export/import and?look=...share links with zero shader reloads.
- Ray Tracing Baked Into the Kit (
directed-lighting/raytracing,directed-lighting/lightmapper,directed-lighting/pathtraced):createRayTracedLighting— Real-Time Hybrid GPU BVH Ray Tracing (three-mesh-bvh/webgpu): builds TLAS/BLAS storage buffers and evaluates fragment-callable WGSL ray-traced soft sun shadows and ray-traced ambient occlusion (RTAO) viabuiltinShadowContext/builtinAOContext.createGPULightMapper,ensureLightmapUVs— In-Engine WebGPU GPU Lightmap Baker wrapping Three.js r187LightMapper+VXGIVolume(vxgiIrradiance) with automaticuv1atlas packing.createPathTraced,renderSkyEquirect— WebGPU Path-Traced Reference (three-gpu-pathtracer/webgpu, tree-shaken & lazily loaded) with Split-Screen Raster ↔ Path-Trace Wipe, live Spatial Denoiser (DenoiseNode), Sobol/blue-dither sampling, and physical transmissive glass stand-ins.
- Next-Tier Three.js r187 Lights & Auto-Scaling (
directed-lighting/photometric,directed-lighting/autoscaler):createIESSpotLight,loadIESProfile,parseIESProfile,makeProceduralIESTexture— photometricTHREE.IESSpotLightfixtures.createProjectorLight,makeProjectionTexture—THREE.ProjectorLightfor stained-glass windows, caustics, and architectural gobos.enableClusteredLighting— Forward+ClusteredLightingfor 50–1000+ simultaneous point/spot lights.createAutoScaler— rolling frame-time dynamic resolution scaler for FSR 1 /scenePass.
- Guardrails, Visual Debug Views & CLI (
directed-lighting/diagnostics,bin/directed-lighting.mjs):inspectMaterials— WebGPU 16-Sampler Budget Doctor flagging materials near or over the per-stage limit.createDebugViewController— live zero-reload debug modes:lit,albedo,normals,metalrough,ao, andsampler-heatmap.npx directed-lighting validate <look.json>|themes|check --url <url>— preset validation and headless Playwright visual/budget check CLI.
- Core Sky, Volumetrics, Post-Processing & TSL Shaders:
createSky,createDust,createDaylight,createWeather,createVolumetricFogVolume,createVolumetricPass,createGodraysEffect,createScreenSpaceGodrays.createPost,displayOf,createColorGradeUniforms,applyLiveColorGrade,parseCubeLUT,createAutoExposure,createReflection,createControls(F2).directed-lighting/shaders:SkyReflection,applyBakedLight,createLayeredSurfaceMaterial,createEmissiveMaterial,createFoliageMaterial,createSpills,createWaterMaterial,createGlassMaterial,createSubsurfaceMaterial.
We are looking for collaborators! If you're interested in contributing to WebGPU lighting, GI, shaders, or demo scenes for Three.js, reach out on X at x.com/jgrebski.
Released under the MIT License: free to use, change, and ship in commercial or non-commercial projects, as long as the copyright and license notice stay with the code. Contributions are welcome; see CONTRIBUTING.md.
npm install
npm test # unit tests (vitest, no GPU)
npm run assets # fetch the demo's Poly Haven assets (dev, build:demo, test:render run it)
npm run dev # 5-scene interactive WebGPU demo (The Room first) on http://127.0.0.1:8785/
npm run build:demo # production demo bundle
npx directed-lighting themes # list built-in Look Themes
npx directed-lighting validate my-look.json # validate a Look Preset JSON fileDemo assets. The demo's first scene, The Room, uses CC0 models and textures from Poly Haven (credited although CC0 does not require it). They are not in the repository or the npm package: npm run assets downloads the files pinned in demo/assets.manifest.json (checked by size and MD5) into the gitignored demo/public/assets/, and does nothing when they are already there. The list, with sources, is in demo/ASSETS.md.
