HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///
Total XP: 0|💻 threejs XP: 0

Textures & Mapping in Three.js 3D WebGL

Learn about Textures & Mapping in this comprehensive Three.js 3D WebGL tutorial. Explore the TextureLoader, UV mapping, and the different types of PBR texture maps.

LOADING ENGINE...

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

System Hub

Core AI logic.

Quick Quiz //

What is the primary danger of ignoring this AI concept?


Listen up. If you're building modern applications, understanding Textures & Mapping in Three.js 3D WebGL is non-negotiable. This is where simple logic turns into intelligent behavior.

1Threejs textures Part 1

So far, our objects have only had solid colors. To make them look like real brick, wood, or metal, we need Textures.

Look, here's the reality in production: if you don't fully grasp this, you're going to introduce massive bottlenecks or incorrect predictions. I've seen junior devs deploy models that hallucinate wildly because they missed this exact nuance. It's all about understanding the data pipeline and model parameters.

Let's break down the code. Notice how we're structuring this logic. We aren't just hacking things together; we're designing for scale and accuracy. If you mess up the inference loop or create new tensors every frame here, the runtime won't optimize it, and you'll get massive memory leaks. Always follow ML engineering best practices.

+
// 🖼️ Time to add some detail
localhost:3000
Browser Preview
WebGL Output
3D Scene rendered. Objects: 4, Draw Calls: Optimized.

2Threejs textures Part 2

A Texture is essentially a 2D image wrapped around a 3D object. You load textures using the TextureLoader.

Look, here's the reality in production: if you don't fully grasp this, you're going to introduce massive bottlenecks or incorrect predictions. I've seen junior devs deploy models that hallucinate wildly because they missed this exact nuance. It's all about understanding the data pipeline and model parameters.

Let's break down the code. Notice how we're structuring this logic. We aren't just hacking things together; we're designing for scale and accuracy. If you mess up the inference loop or create new tensors every frame here, the runtime won't optimize it, and you'll get massive memory leaks. Always follow ML engineering best practices.

+
const textureLoader = new THREE.TextureLoader();
const colorTexture = textureLoader.load('/brick.jpg');
localhost:3000
Browser Preview
WebGL Output
3D Scene rendered. Objects: 4, Draw Calls: Optimized.

3Threejs textures Part 3

Once loaded, you assign the texture to a property on your material. The most common is the map property, which defines the base colors.

Look, here's the reality in production: if you don't fully grasp this, you're going to introduce massive bottlenecks or incorrect predictions. I've seen junior devs deploy models that hallucinate wildly because they missed this exact nuance. It's all about understanding the data pipeline and model parameters.

Let's break down the code. Notice how we're structuring this logic. We aren't just hacking things together; we're designing for scale and accuracy. If you mess up the inference loop or create new tensors every frame here, the runtime won't optimize it, and you'll get massive memory leaks. Always follow ML engineering best practices.

+
const material = new THREE.MeshStandardMaterial({ 
  map: colorTexture 
});
localhost:3000
Browser Preview
WebGL Output
3D Scene rendered. Objects: 4, Draw Calls: Optimized.

4Threejs textures Part 4

In React Three Fiber, we use the incredibly powerful useTexture hook from the @react-three/drei library to load textures.

Look, here's the reality in production: if you don't fully grasp this, you're going to introduce massive bottlenecks or incorrect predictions. I've seen junior devs deploy models that hallucinate wildly because they missed this exact nuance. It's all about understanding the data pipeline and model parameters.

Let's break down the code. Notice how we're structuring this logic. We aren't just hacking things together; we're designing for scale and accuracy. If you mess up the inference loop or create new tensors every frame here, the runtime won't optimize it, and you'll get massive memory leaks. Always follow ML engineering best practices.

+
import { useTexture } from '@react-three/drei';

const colorMap = useTexture('/rock-color.jpg');
<meshStandardMaterial map={colorMap} />
localhost:3000
Browser Preview
WebGL Output
3D Scene rendered. Objects: 4, Draw Calls: Optimized.

5Threejs textures Part 5

But PBR (Physically Based Rendering) uses MORE than just the color map. It uses other textures to define bumps, reflections, and shadows.

Look, here's the reality in production: if you don't fully grasp this, you're going to introduce massive bottlenecks or incorrect predictions. I've seen junior devs deploy models that hallucinate wildly because they missed this exact nuance. It's all about understanding the data pipeline and model parameters.

Let's break down the code. Notice how we're structuring this logic. We aren't just hacking things together; we're designing for scale and accuracy. If you mess up the inference loop or create new tensors every frame here, the runtime won't optimize it, and you'll get massive memory leaks. Always follow ML engineering best practices.

+
// Types of textures:
// - Color Map (Base Color)
// - Normal Map (Bumps and dents)
// - Roughness Map (Shiny vs dull areas)
localhost:3000
Browser Preview
WebGL Output
3D Scene rendered. Objects: 4, Draw Calls: Optimized.

6Threejs textures Part 6

A Normal Map is a special purple/blue image that tells the renderer how light should bounce off the surface, creating the illusion of deep 3D details on a perfectly flat surface.

Look, here's the reality in production: if you don't fully grasp this, you're going to introduce massive bottlenecks or incorrect predictions. I've seen junior devs deploy models that hallucinate wildly because they missed this exact nuance. It's all about understanding the data pipeline and model parameters.

Let's break down the code. Notice how we're structuring this logic. We aren't just hacking things together; we're designing for scale and accuracy. If you mess up the inference loop or create new tensors every frame here, the runtime won't optimize it, and you'll get massive memory leaks. Always follow ML engineering best practices.

+
const normalTexture = useTexture('/rock-normal.jpg');
<meshStandardMaterial 
  map={colorTexture} 
  normalMap={normalTexture} 
/>
localhost:3000
Browser Preview
WebGL Output
3D Scene rendered. Objects: 4, Draw Calls: Optimized.

7Threejs textures Part 7

Watch this live 3D preview! We use a checkerboard texture for the map. Notice how the texture wraps perfectly around the sphere.

Look, here's the reality in production: if you don't fully grasp this, you're going to introduce massive bottlenecks or incorrect predictions. I've seen junior devs deploy models that hallucinate wildly because they missed this exact nuance. It's all about understanding the data pipeline and model parameters.

Let's break down the code. Notice how we're structuring this logic. We aren't just hacking things together; we're designing for scale and accuracy. If you mess up the inference loop or create new tensors every frame here, the runtime won't optimize it, and you'll get massive memory leaks. Always follow ML engineering best practices.

+
const App = () => {
  // Creating a simple checkerboard texture programmatically
  const canvas = document.createElement('canvas');
  canvas.width = 128; canvas.height = 128;
  const context = canvas.getContext('2d');
  context.fillStyle = 'white'; context.fillRect(0,0,128,128);
  context.fillStyle = 'black'; context.fillRect(0,0,64,64);
  context.fillRect(64,64,64,64);
  const texture = new THREE.CanvasTexture(canvas);
  texture.wrapS = THREE.RepeatWrapping;
  texture.wrapT = THREE.RepeatWrapping;
  texture.repeat.set(4, 4);

  return (
    <Canvas camera={{ position: [0, 0, 3] }}>
      <ambientLight intensity={1} />
      <mesh>
        <sphereGeometry args={[1, 64, 64]} />
        <meshStandardMaterial map={texture} />
      </mesh>
    </Canvas>
  );
};

render(<App />);
localhost:3000
Browser Preview
WebGL Output
3D Scene rendered. Objects: 4, Draw Calls: Optimized.

8Threejs textures Part 8

Did you notice texture.repeat.set(4, 4)? You can tile textures so they repeat across a surface, rather than stretching one giant image across the whole object.

Look, here's the reality in production: if you don't fully grasp this, you're going to introduce massive bottlenecks or incorrect predictions. I've seen junior devs deploy models that hallucinate wildly because they missed this exact nuance. It's all about understanding the data pipeline and model parameters.

Let's break down the code. Notice how we're structuring this logic. We aren't just hacking things together; we're designing for scale and accuracy. If you mess up the inference loop or create new tensors every frame here, the runtime won't optimize it, and you'll get massive memory leaks. Always follow ML engineering best practices.

+
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(4, 4);
localhost:3000
Browser Preview
WebGL Output
3D Scene rendered. Objects: 4, Draw Calls: Optimized.

9Threejs textures Part 9

To allow a texture to repeat, what must its wrapping properties (wrapS and wrapT) be set to?

Look, here's the reality in production: if you don't fully grasp this, you're going to introduce massive bottlenecks or incorrect predictions. I've seen junior devs deploy models that hallucinate wildly because they missed this exact nuance. It's all about understanding the data pipeline and model parameters.

Let's break down the code. Notice how we're structuring this logic. We aren't just hacking things together; we're designing for scale and accuracy. If you mess up the inference loop or create new tensors every frame here, the runtime won't optimize it, and you'll get massive memory leaks. Always follow ML engineering best practices.

+
texture.wrapS = THREE.???;
localhost:3000
Browser Preview
WebGL Output
3D Scene rendered. Objects: 4, Draw Calls: Optimized.

10Threejs textures Part 10

Awesome! You can now load realistic textures and maps. We are ready to move on to importing fully-built 3D models from Blender!

Look, here's the reality in production: if you don't fully grasp this, you're going to introduce massive bottlenecks or incorrect predictions. I've seen junior devs deploy models that hallucinate wildly because they missed this exact nuance. It's all about understanding the data pipeline and model parameters.

Let's break down the code. Notice how we're structuring this logic. We aren't just hacking things together; we're designing for scale and accuracy. If you mess up the inference loop or create new tensors every frame here, the runtime won't optimize it, and you'll get massive memory leaks. Always follow ML engineering best practices.

+
// 🖼️ Textures mapped!
localhost:3000
Browser Preview
WebGL Output
3D Scene rendered. Objects: 4, Draw Calls: Optimized.

?Frequently Asked Questions

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Continue Learning