WebGLRenderer Precision and Mobile Performance in Three.js

Configuring the precision attribute in Three.js’s WebGLRenderer is a critical step in optimizing web-based 3D applications for mobile devices. This article explores how choosing between high, medium, and low precision settings directly impacts GPU utilization, rendering speed, battery life, and visual fidelity on smartphones and tablets, helping you make the right trade-off for your mobile project.

Understanding Shader Precision

In WebGL, the precision attribute determines the mathematical detail (specifically, the bit depth of floating-point numbers) used by shaders during rendering calculations. Three.js allows you to set this parameter in the WebGLRenderer constructor using three values: 'highp' (high precision), 'mediump' (medium precision), and 'lowp' (low precision).

const renderer = new THREE.WebGLRenderer({ precision: 'mediump' });

While desktop graphics cards handle high-precision calculations effortlessly, mobile GPUs are highly sensitive to these settings due to hardware limitations designed to conserve power and reduce heat.

How Precision Levels Affect Mobile Performance

1. High Precision (highp)

2. Medium Precision (mediump)

3. Low Precision (lowp)

Visual Trade-offs on Mobile Screen Resolutions

Because mobile screens have high pixel densities (Retina/Super AMOLED displays), visual artifacts caused by lower precision settings can sometimes be less noticeable to the naked eye. However, certain rendering techniques suffer significantly under mediump and lowp:

Best Practices for Mobile Optimization

To achieve the best balance between performance and visual fidelity on mobile devices, consider the following approach:

  1. Default to Medium Precision: If your application targets mobile browsers, start by setting the renderer precision to 'mediump'.
  2. Use Conditional Precision: You can detect the user’s device capabilities and dynamically assign precision. Alternatively, let Three.js fall back automatically by leaving the default behavior, but override specific critical materials to use high precision only where absolutely necessary using the precision property on individual RawShaderMaterial or ShaderMaterial instances.
  3. Optimize the Viewport: Instead of lowering precision, you can also gain performance by reducing the pixel ratio on high-DPI mobile screens using renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)).