Loading

فارسی

Accent color

Background

Skip to article
Engineering

Designing 3D interfaces with WebGL: from idea to 60 frames per second

How we build interactive Three.js and React Three Fiber experiences that stay smooth on mobile — from shader optimisation to memory management.

This article is also available in other languagesفارسی

A few years ago, shipping a 3D experience on the web meant sacrificing half of your mobile users. Today, with tools like React Three Fiber and a better understanding of the GPU, we can build scenes that look great and still run smoothly on mid-range phones.

Start with the right mindset

Before the first line of code, know your frame budget. At 60fps you only have 16 milliseconds — and the browser itself eats a large part of it. JavaScript, GPU calls and DOM updates together should stay under 8 milliseconds.

Optimise the geometry

Most projects we audit started with models of several hundred thousand polygons. Reducing vertex counts, merging similar geometries with InstancedMesh and using LOD (Level of Detail) typically removes 30 to 60 percent of the GPU load.

Shaders: where the magic happens

A custom shader lets you build effects that standard materials cannot. But every extra varying, every texture lookup and every if branch in a fragment shader has a cost. Our rule: build the simplest version first, add one layer at a time, and measure after each layer.

Memory management

Memory leaks are a silent killer in Three.js. Every geometry, material and texture you create must be disposed. React Three Fiber usually does this for you, but when you create something outside the component lifecycle, it is your responsibility.

Wrapping up

3D on the web is the art of balance: between beauty and performance, between detail and simplicity. If you work with a performance-first mindset from day one, the final product will be both stunning and smooth in the hands of millions of users.

Likes and saves are currently kept in this browser only.

CommentsComing soon

We'd love to hear from you. Comments will be enabled soon.

Posting comments is not enabled yet.

The Mohtawa newsletterComing soon

Every two weeks, our best articles and lessons in your inbox.

Newsletter sign-up will be available soon.

Back to the blog