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.
Key topics: webgl2 blitframebuffer, msaa resolve, framebuffer copy, magnifier, multisample render target, raw webgl
Game Over
What this code does
- Blit: `blitFramebuffer` copies (and optionally scales or flips) a rectangle between framebuffers on the GPU, with no shaders or textures.
- MSAA Resolve: three.js resolves a `samples: 4` render target into its texture with a blit when rendering ends.
- Composition: the left half of the screen is blitted from the plain target and the right half from the MSAA target.
- Magnifier: a small source rectangle under the pointer is blitted 2–12× larger into a corner, showing raw pixels.
- Access: three's internal framebuffer comes from `renderer.properties.get(target).__webglFramebuffer`, then `resetState()` restores state.
- Controls: MSAA samples, split, magnifier, zoom, blit filter and spin.
Related Demos
Continue Learning
JavaScript Implementation
// Copy pixels between framebuffers on the GPU — scaling, flipping and MSAA resolve in one call
const gl = renderer.getContext()
renderer.setRenderTarget(target); renderer.render(scene, camera); renderer.setRenderTarget(null)
const readFbo = renderer.properties.get(target).__webglFramebuffer
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, readFbo)
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null) // the canvas
gl.blitFramebuffer(x0, y0, x0 + 64, y0 + 64, // source rect
10, 10, 10 + 384, 10 + 384, // destination rect (6× zoom)
gl.COLOR_BUFFER_BIT, gl.NEAREST)
renderer.resetState()