What You'll Learn in This Three.js Guide
This free interactive guide teaches you Three.js — the most popular JavaScript library for 3D web graphics. Every concept comes with a live interactive demo you can manipulate in real-time, plus code examples you can copy directly into your projects.
01 — Geometry
Geometry defines the shape of 3D objects using vertices, edges, and faces. Everything in Three.js is a BufferGeometry — typed arrays of vertex data sent directly to the GPU. Three.js ships 21 built-in geometry constructors including BoxGeometry, SphereGeometry, CylinderGeometry, TorusGeometry, LatheGeometry, ExtrudeGeometry, and more. Adjust segment counts to control smoothness vs. performance.
02 — Materials
Materials control how objects look — color, shininess, transparency, and how they respond to light. The material hierarchy goes from MeshBasicMaterial (unlit, cheapest) to MeshLambertMaterial (diffuse) to MeshPhongMaterial (specular) to MeshStandardMaterial (PBR with roughness/metalness) to MeshPhysicalMaterial (clearcoat, transmission, iridescence, sheen). Other types include MeshToonMaterial for cel-shading and MeshMatcapMaterial for texture-based lighting.
03 — Cameras
The camera defines how 3D space is projected onto your 2D screen. PerspectiveCamera mimics human vision with depth — farther objects appear smaller. OrthographicCamera has no perspective distortion — used for isometric games, CAD, and technical views. This section includes 10 real-world camera presets: Free Orbit, First Person, Third Person, Top Down, Racing, Side Scroller, Isometric, Cinematic, Bird's Eye, and Security Cam.
04 — Lighting
Lighting makes a 3D scene feel real. Three.js offers DirectionalLight (sun), PointLight (light bulb), SpotLight (cone beam), HemisphereLight (sky + ground ambient), RectAreaLight (soft panel), and AmbientLight (uniform fill). Learn three-point lighting setups, shadow configuration, and how each light type affects PBR materials differently.
05 — Scene Objects
Everything in a Three.js scene is an Object3D. A Mesh combines geometry + material. InstancedMesh draws thousands of copies in one GPU draw call. Points renders particle systems. Group creates parent-child hierarchies. Sprite creates billboards that always face the camera. LOD automatically switches detail levels based on distance.
06 — Controls
Controls translate user input into camera movement. OrbitControls is the default for model viewers. MapControls for top-down maps. FlyControls for free-flight navigation. FirstPersonControls for FPS-style games. TrackballControls for unconstrained rotation. Each has configurable damping, speed limits, and distance constraints.
07 — Post-Processing
EffectComposer chains screen-space effects after the scene renders. Stack passes like UnrealBloomPass (glow), FilmPass (grain), GlitchPass (distortion), AfterimagePass (motion trails), DotScreenPass (halftone), plus custom ShaderPass for vignette and pixelation. Order matters — always start with RenderPass and end with OutputPass.
08 — Style Gallery
One scene, 16 looks. The same tree and house rendered in completely different visual styles: Realistic PBR, Clay, Low-Poly, Toon, Wireframe, Normals, Neon, Glass, Pixel Art, Isometric Voxel, Matcap, X-Ray, Blueprint, Hologram, Gold/Chrome, and Sunset. Each style demonstrates different Three.js techniques — materials, camera types, lighting, and post-processing.
09 — Shaders (GLSL)
Shaders are GPU programs that give you complete control over how vertices are positioned and pixels are colored. ShaderMaterial accepts raw GLSL code with custom uniforms, varyings, and both vertex and fragment shaders. This section includes four interactive presets: Wave Deformation (vertex displacement with sin/cos), Noise Pattern (procedural noise coloring), Gradient (two-color blending with angle control), and Dissolve Effect (noise-based disintegration with glowing edges).
10 — Textures & Maps
Textures are images mapped onto 3D surfaces using UV coordinates. Beyond base color, Three.js supports multiple map types: normalMap for faking surface detail, bumpMap for simple height-based shading, displacementMap for actual vertex displacement, aoMap for ambient occlusion, emissiveMap for self-illumination, and envMap for environment reflections. This section lets you toggle each map type independently on a sphere, adjust tiling with repeat/wrapping controls, and tune material parameters like roughness and metalness.
11 — Animation
Animation in Three.js uses THREE.Clock for frame-independent delta time, easing functions for natural motion curves (linear, ease-in-out, bounce, elastic, back), AnimationMixer with KeyframeTrack for declarative keyframe playback, morph targets for smooth shape blending, and clip crossfading for character animation. This section demonstrates four modes: compare five easing curves side by side, play keyframe animations with interpolation modes, blend shapes with morph targets, and crossfade between Idle/Walk/Run clips on a loaded GLTF character with full AnimationAction controls.
12 — Raycasting
Raycasting is how you pick and interact with 3D objects using the mouse. THREE.Raycaster shoots an invisible ray from the camera through normalized mouse coordinates into the scene. Convert pixel coordinates to NDC, call raycaster.intersectObjects() to get sorted hits with object reference, world-space intersection point, distance, face normal, face index, and UV coordinates. This section lets you hover to highlight, click to inspect, and drag objects to reposition them on the ground plane.