Scaling React-Three-Fiber Applications beyond the Hello World

Rate this content
Bookmark
Slides

A lot of recent talks at other conferences have talked about how to start using React and THREE.js to create 3D experiences on the web. In my career I've built several complex applications using those technologies, including a big Figma-like 3D editor, and I've learnt a lot of patterns and tricks on how to make it actually fast and scalable. Unfortunately, though, nobody is also talking about those tricks an what it really takes to build an rendering engine similar to the one that Figma uses.
My goal with this talk is to give people an overview of the challenges that may arise when you try scaling your application, and what are some lesser known tricks to overcome them: instancing, memory usage reduction techniques, SDF-based text rendering, GPGPU and tree data structures. Everything of course done with Javascript, React and THREE.js.

This talk has been presented at React Summit 2023, check out the latest edition of this React Conference.

Watch video on a separate page

FAQ

WebGL is a browser technology that allows using the GPU to build 3D graphics-based applications with JavaScript.

WebGL has been around for almost 12 years.

Common applications that use WebGL include Google Maps and Figma, which use the GPU to accelerate rendering for both 3D and 2D applications.

3.js is a library that accelerates the development of WebGL applications by providing utilities and by wrapping its API, offering an API that is more similar to the DOM.

React ReFiber is a library that allows developers to use React declaratively to build applications and scenes using 3.js, which has boosted the adoption of WebGL applications.

Challenges include efficiently loading and downloading data, streaming data in tiles, handling levels of detail, fast collision checking, and optimizing GPU usage.

Instanced rendering is a technique that allows drawing multiple instances of the same object with a single draw call to the GPU, significantly reducing the CPU-GPU bottleneck and improving performance.

Optimizations include limiting React re-renders, profiling rendering and interaction times, reducing memory usage, using efficient algorithms and data structures, and optimizing GPU draw calls.

Flux is an online, browser-based, collaborative CAD editor for electronic engineering and printed circuit boards. It faces challenges such as rendering complex scenes with many components, supporting big documents, providing 3D views, and maintaining real-time interactions at 60 frames per second.

Giulio Zausa‮
Giulio Zausa‮
20 min
06 Jun, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

WebGL has evolved from showcasing technology to being used in everyday applications like Google Maps and Figma. React and 3.js can be used together to build WebGL applications, allowing for reusable components and declarative development. Building complex 3D graphics applications requires efficient data structures, algorithms, and rendering techniques. The Flux CAD editor uses React, 3.js, and React ReFiber to handle complex engineering documents and optimize GPU utilization. Optimizing the render loop and GPU performance is crucial for improving WebGL application performance. Instance rendering can be used to optimize text rendering in WebGL applications, achieving efficient rendering of thousands of 3D characters.

1. Introduction to WebGL and its History

Short description:

Hi! My name is Giulio. I'm a software engineer, and I've worked with React and JavaScript for quite a while now. Recently in my career I've been developing some stuff with WebGL, and today I wanted to talk about my experience doing it. WebGL is a browser technology that allows using the GPU to build 3D graphics-based applications with JavaScript. It has been around for quite a while now, almost 12 years, and its usage changed a lot during that time. It all started in the beginning with some power users building cool 3D graphics demos, which were showcasing the technology but not yet delivering value to users. After a while, though, we started building real applications that used WebGL to enhance user experience for some specific use cases, which answered a specific business need and enhanced the user experience. Those experiences, though, were still delivered as special applications, an isolated section of a website with a clear scene from the rest of it, not something that you would use every day. This changed, though, with time, and today WebGL is used in all sorts of applications that we use every day and professionally, even. Think about Google Maps or Figma. You don't even know that WebGL is there, but it's using the GPU to accelerate the rendering, both for 3D and 2D applications, and it's what makes the application possible in the first place. So since WebGL is today so widespread, can we say that 3D graphics on the web are nowadays a commodity, something that is easy to build? Well, to answer this question, I think we have to look at what is the current tooling ecosystem that is available for it.

Hi! My name is Giulio. I'm a software engineer, and I've worked with React and JavaScript for quite a while now. Recently in my career I've been developing some stuff with WebGL, and today I wanted to talk about my experience doing it. To talk about it, I think it makes sense first to discuss about what is it and its history.

WebGL is a browser technology that allows using the GPU to build 3D graphics-based applications with JavaScript. It has been around for quite a while now, almost 12 years, and its usage changed a lot during that time. It all started in the beginning with some power users building cool 3D graphics demos, which were showcasing the technology but not yet delivering value to users. After a while, though, we started building real applications that used WebGL to enhance user experience for some specific use cases, which answered a specific business need and enhanced the user experience. Those experiences, though, were still delivered as special applications, an isolated section of a website with a clear scene from the rest of it, not something that you would use every day.

This changed, though, with time, and today WebGL is used in all sorts of applications that we use every day and professionally, even. Think about Google Maps or Figma. You don't even know that WebGL is there, but it's using the GPU to accelerate the rendering, both for 3D and 2D applications, and it's what makes the application possible in the first place. So since WebGL is today so widespread, can we say that 3D graphics on the web are nowadays a commodity, something that is easy to build? Well, to answer this question, I think we have to look at what is the current tooling ecosystem that is available for it.

2. Using React and 3.js for WebGL Applications

Short description:

One example of this is 3.js, a library that accelerates the development of WebGL applications by providing utilities and by wrapping its API, providing an API that is more similar to the DOM. Nowadays, we can even use React together with 3.js to build WebGL applications. Thanks to a library called React ReFiber, we are now able to use React declaratively to build applications and scenes using 3.js. The power of React is that it allows to easily reuse components and bind your data without imperative mutations. React ReFiber has an ecosystem built around it, with many open source projects and component libraries that provide advanced rendering techniques. This allows developers to build cool applications with minimal code.

One example of this is 3.js, a library that accelerates the development of WebGL applications by providing utilities and by wrapping its API, providing an API that is more similar to the DOM. Nowadays, we can even use React together with 3.js to build WebGL applications. And this really boosted its adoption recently.

In fact, thanks to a library called React ReFiber, we are now able to use React declaratively to build applications and scenes using 3.js. The power of React is that it allows to easily reuse components and bind your data without imperative mutations. What's really powerful about React ReFiber is the ecosystem that is built around it. There are many open source projects that facilitate some common 3D rendering tasks such as post-processing, layouting, physics, and accessibility. There are even some component libraries, such as Tri, which provide advanced rendered techniques such as lighting, skyboxes, shadows, and keyboard and mouse controls as reusable React components.

This is really powerful since it allows everybody to build really cool applications with very few lines of code. For example, this demo really showcases what you can do with it. Physics, mouse controls, advanced materials, and reflections. The code that is needed to build something like this seems a lot, but actually it's surprisingly low. This demo is in fact around 60 lines of code. This is possible because it's able to reuse a lot of code from the component library.