WebGL2 Techniques in Three.js

These demos look underneath three.js at the WebGL2 features it is built on. They cover render targets and multiple render targets (MRT) for G-buffers and GPU picking, stencil masking and depth pre-passes, uniform buffer objects, and vertex array objects.

More advanced examples use transform feedback for particles, occlusion queries and conditional rendering to skip hidden objects, framebuffer blitting for MSAA resolves, and texture arrays for batching many textures. Several demos drop down to raw WebGL2 calls, making them a practical reference for writing custom rendering code.

Most viewed in webgl techniques

All webgl techniques demos

16 Demos
Render Targets preview
Explore Demo →

Render Targets

Render to texture technique showing a spinning cube rendered to texture and applied to multiple objects.

webgl-techniques
MRT G-Buffer Visualizer (r183 roadmap) preview
Explore Demo →

MRT G-Buffer Visualizer (r183 roadmap)

WebGL2 multiple-render-target demo that captures normal and depth attachments and visualizes them alongside the beauty pass in a four-panel layout.

webgl-techniques
Three.js Multi-Pass Rendering (Stencil Masking & Depth Pre-Pass) preview
Explore Demo →

Three.js Multi-Pass Rendering (Stencil Masking & Depth Pre-Pass)

Multi-pass rendering in Three.js with a stencil-buffer X-ray lens that reveals hidden internals only inside a mask, plus an optional depth pre-pass that cuts overdraw by shading each pixel once.

webgl-techniques
Three.js Geometry Shader Effects (Emulated in WebGL) preview
Explore Demo →

Three.js Geometry Shader Effects (Emulated in WebGL)

Geometry-shader-style effects in Three.js (exploding triangles, shrinking to centroids, extruded spikes and noise displacement) emulated by baking per-face attributes into vertex data, since WebGL has no geometry stage.

webgl-techniques
Three.js GPGPU Compute (Cellular Automata on the GPU) preview
Explore Demo →

Three.js GPGPU Compute (Cellular Automata on the GPU)

Compute-shader-style GPGPU in Three.js, running Conway's Life, Brian's Brain and a 16-state cyclic automaton on grids up to 2949×2048 with ping-pong render targets, many generations per frame and painting with the pointer.

webgl-techniques
Three.js Custom & Instanced Attributes (300k Grass Blades) preview
Explore Demo →

Three.js Custom & Instanced Attributes (300k Grass Blades)

Custom vertex attributes in Three.js, with a field of up to 300,000 wind-blown grass blades from one InstancedBufferGeometry using a per-vertex tip weight and per-instance offset, height, phase, colour and lean in an interleaved buffer.

webgl-techniques
Three.js Uniform Buffer Objects (UniformsGroup / UBO) preview
Explore Demo →

Three.js Uniform Buffer Objects (UniformsGroup / UBO)

Share scene data across 400 materials in Three.js with a WebGL2 uniform buffer (UniformsGroup), holding four lights, fog and time in one std140 block uploaded once per frame, compared with per-material uniforms.

webgl-techniques
Three.js Transform Feedback Particles (Raw WebGL2) preview
Explore Demo →

Three.js Transform Feedback Particles (Raw WebGL2)

GPU particle physics with WebGL2 transform feedback alongside Three.js, where a vertex shader writes updated positions and velocities into a second buffer that is then drawn directly, for up to a million particles with no CPU readback.

webgl-techniques
Three.js Occlusion Queries (WebGL2 ANY_SAMPLES_PASSED) preview
Explore Demo →

Three.js Occlusion Queries (WebGL2 ANY_SAMPLES_PASSED)

Hardware occlusion queries in Three.js, wrapping each object's draw in a WebGL2 query via onBeforeRender/onAfterRender, reading results asynchronously and showing visible, occluded and frustum-culled objects in a top-down inset.

webgl-techniques
Three.js Conditional Rendering (Occlusion-Query Proxies) preview
Explore Demo →

Three.js Conditional Rendering (Occlusion-Query Proxies)

GPU-driven visibility in Three.js that emulates conditional rendering, querying cheap bounding-box proxies after the occluders and submitting expensive 100k-triangle meshes only when their proxy was visible last frame.

webgl-techniques
Three.js Vertex Array Objects (VAO vs Re-Binding, Raw WebGL2) preview
Explore Demo →

Three.js Vertex Array Objects (VAO vs Re-Binding, Raw WebGL2)

Measure what vertex array objects save in raw WebGL2 alongside Three.js, drawing up to 20,000 meshes either with one bindVertexArray per draw or by re-binding buffers and attribute pointers every time.

webgl-techniques
Three.js MRT GPU Picking & ID-Buffer Outlines preview
Explore Demo →

Three.js MRT GPU Picking & ID-Buffer Outlines

Multiple render targets in Three.js, where one pass writes colour, normals and a 24-bit object-ID buffer, used for pixel-exact GPU picking with readRenderTargetPixels and selection outlines from edge detection on the ID buffer.

webgl-techniques
Three.js Framebuffer Blitting (MSAA Resolve & Magnifier) preview
Explore Demo →

Three.js Framebuffer Blitting (MSAA Resolve & Magnifier)

WebGL2 blitFramebuffer with Three.js, compositing a split view of single-sample and 4× MSAA renders and a pixel magnifier entirely with framebuffer blits, using NEAREST or LINEAR filtering.

webgl-techniques
Three.js Texture Arrays (DataArrayTexture / sampler2DArray) preview
Explore Demo →

Three.js Texture Arrays (DataArrayTexture / sampler2DArray)

Bind many textures as one in Three.js with a DataArrayTexture, letting 1,600 instanced cubes each sample one of 16 layers via a per-instance attribute in a single draw call, compared with 16 separate textures and materials.

webgl-techniques
Three.js Environment Map Arrays (Cubemap Arrays Emulated) preview
Explore Demo →

Three.js Environment Map Arrays (Cubemap Arrays Emulated)

Many environment maps in one sampler in Three.js, with eight procedural skies stored as equirectangular layers of a mipmapped texture array so 40 reflective spheres pick their own environment and roughness in one draw call.

webgl-techniques
Three.js Vertex Animation Textures (Buffer Textures Emulated) preview
Explore Demo →

Three.js Vertex Animation Textures (Buffer Textures Emulated)

Large per-vertex datasets in textures in Three.js, where a verlet cloth simulation is baked into a float data texture and replayed on 400+ instanced flags with texelFetch by vertex index and frame, with no CPU work per frame.

webgl-techniques