Points and Sprites
local graph
Chapter 7 — Points and Sprites
Section titled “Chapter 7 — Points and Sprites”In the previous chapters, we discussed the most important concepts, objects, and APIs that Three.js has to offer. In this chapter, we’ll look into the only concepts we’ve skipped until now: points and sprites. With THREE.Points (sometimes also called sprites), it is very easy to create many small rectangles that always face the camera and you can use to simulate rain, snow, smoke, and other interesting effects. For instance, you can render individual geometries as a set of points and control these points separately. In this chapter, we’ll explore the various point- and sprite-related features provided by Three.js.
To be more specific, we’ll look at the following topics in this chapter:
- Creating and styling particles using
THREE.SpriteMaterialandTHREE.PointsMaterial - Using
THREE.Pointsto create a group of points - Using the canvas to style each point individually
- Using a texture to style the individual points
- Animating
THREE.Pointsobjects - Creating a
THREE.Pointsobject from existing geometries
A quick note on some of the names used in this chapter
In newer versions of Three.js, the names of the objects related to points have changed several times. The THREE.Points object was previously named THREE.PointCloud and, in even older versions, it was called THREE.ParticleSystem. THREE.Sprite used to be called THREE.Particle, and the materials have also undergone several name changes. So, if you see online examples using these old names, remember that they are talking about the same concepts.
Let’s start by exploring what a particle is and how you can create one.
Understanding points and sprites
Section titled “Understanding points and sprites”As we do with most new concepts, we’ll start with an example. In the sources for this chapter, you’ll find an example called sprite.html. Upon opening this example, you’ll see a minimalistic scene, containing a simple colored square:
![]()
Figure 7.1 – A single rendered sprite
You can use your mouse to rotate around this scene. One thing you’ll notice is that no matter how you look at the square, it will always look the same. For instance, the following screenshot shows a view of the same scene from a different position:
![]()
Figure 7.2 – A single rendered sprite will always be facing the camera
As you can see, the sprite is still angled toward the camera, and you can’t look behind it. You can think of a sprite as a 2D plane that always faces the camera. If you create a sprite without any properties, they are rendered as small, white, two-dimensional squares. To create a sprite, we only need to provide a material:
const material = new THREE.SpriteMaterial({ size: 0.1, color: 0xff0000 })const sprite = new THREE.Sprite(material)sprite.position.copy(new THREE.Vector3(1,1,1))You can configure how the sprite appears using THREE.SpriteMaterial:
color: This is the color of the sprite. The default color is white.sizeAttenuation: If this is set tofalse, the sprite will have the same size, regardless of how far from the camera it is positioned. If this is set totrue, the size is based on the distance from the camera. The default value istrue. Note that this only has an effect when usingTHREE.PerspectiveCamera. ForTHREE.OrthographicCamera, it always acts if set tofalse.map: With this property, you can apply a texture to the sprite. You can, for instance, make them look like snowflakes. This property isn’t shown in this example but is explained in the Styling particles using textures section in this chapter.opacity: This, together with thetransparentproperty, sets the opacity of the sprite. The default value is1(fully opaque).transparent: If this is set totrue, the sprite will be rendered with the opacity set by theopacityproperty. The default value isfalse.blending: This is the blend mode to use when rendering the sprite.
Note that THREE.SpriteMaterial extends from the base THREE.Material object, so all the properties from that object also can be used on THREE.SpriteMaterial.
Before we move on to more interesting THREE.Points objects, let’s look a bit closer at the THREE.Sprite object. A THREE.Sprite object extends from the THREE.Object3D object just as THREE.Mesh does. This means that most of the properties and functions you know from THREE.Mesh can be used on THREE.Sprite. You can set its position using the position attribute, scale it using the scale property, and move it along its axes using the translate property.
With THREE.Sprite, you can very easily create a set of objects and move them around the scene. This works well when you’re working with a small number of objects, but you’ll quickly run into performance issues when you want to work with a high number of THREE.Sprite objects. This is because each of the objects needs to be managed separately by Three.js. Three.js provides an alternative way of handling a large number of sprites using a THREE.Points object. With THREE.Points, Three.js doesn’t have to manage many individual THREE.Sprite objects, just the THREE.Points instance. This will allow Three.js to optimize how it draws the sprites and will result in better performance. The following screenshot shows several sprites rendered with the THREE.Points object:

Figure 7.3 – Multiple points rendered from THREE.BufferGeometry
To create a THREE.Points object, we need to provide it with THREE.BufferGeometry. For the previous screenshot, we can create a THREE.BufferGeometry like this:
const createPoints = () => { const points = [] for (let x = -15; x < 15; x++) { for (let y = -10; y < 10; y++) { let point = new THREE.Vector3(x / 4, y / 4, 0) points.push(point) } } const colors = new Float32Array(points.length * 3) points.forEach((e, i) => { const c = new THREE.Color(Math.random() * 0xffffff) colors[i * 3] = c.r colors[i * 3 + 1] = c.g colors[i * 3 + 2] = c.b }) const geom = new THREE.BufferGeometry().setFromPoints(points) geom.setAttribute('color', new THREE.BufferAttribute(colors, 3, true)) return geom}const material = new THREE.PointsMaterial({ size: 0.1, vertexColors: true, color: 0xffffff })const points = new THREE.Points(createPoint(), material)As you can see from this code fragment, first, we create an array of THREE.Vector3 objects – one for each position where we want to create a sprite. Additionally, we set the color attribute on THREE.BufferGeometry, which is used to color each sprite. With THREE.BufferGeometry and an instance of THREE.PointsMaterial, we can create the THREE.Points object. The properties of THREE.PointsMaterial are pretty much the same as they are for THREE.SpriteMaterial:
color: This is the color of the point. The default color is0xffffff.sizeAttenuationIf this is set tofalse, all the points will have the same size, regardless of how far from the camera they are positioned. If this is set totrue, the size is based on the distance from the camera. The default value istrue.map: With this property, you can apply a texture to the point. You can, for instance, make them look like snowflakes. This property isn’t shown in this example but is explained in the Styling particles using textures section later in this chapter.opacity: This, together with thetransparentproperty, sets the opacity of the sprites. The default value is1(no opacity).transparent: If this is set totrue, the sprites will be rendered with the opacity set by theopacityproperty. The default value isfalse.blending: This is the blend mode to use when rendering the sprites.vertexColors: Normally, all the points inTHREE.Pointshave the same color. If this property is set totrueand the color’s buffer attribute has been set on the geometry, each point will take the color from that array. The default value isfalse.
As always, you can play around with these properties using the menu on the right in each of the examples.
So far, we’ve only rendered the particles as small squares, which is the default behavior. There are, however, two additional ways you can style particles, which we’ll show in the next section.
Styling particles using textures
Section titled “Styling particles using textures”In this section, we’ll look at the following two ways of changing what the sprite looks like:
- Use an HTML canvas to draw an image and show that for each sprite
- Load an external image file to define what each sprite looks like
Let’s start by drawing the image ourselves.
Drawing an image on the canvas
Section titled “Drawing an image on the canvas”In the attributes for THREE.PointsMaterial, we mentioned the map property. With the map property, we can load a texture for the individual points. With Three.js, this texture can also be the output from an HTML5 canvas. Before we look at the code, let’s look at an example (canvastexture.js):
![]()
Figure 7.4 – Creating sprites using a canvas-based texture
Here, you can see that we’ve got a large set of Pac-Man-like ghosts on the screen. This uses the same approach that we saw in the Understanding points and sprites section earlier. This time, though, we aren’t showing a simple square but an image. To create this texture, we can use the following code:
const createGhostTexture = () => { const canvas = document.createElement('canvas') canvas.width = 32 canvas.height = 32 const ctx = canvas.getContext('2d') // the body ctx.translate(-81, -84) ctx.fillStyle = 'orange' ctx.beginPath() ctx.moveTo(83, 116) ctx.lineTo(83, 102) ctx.bezierCurveTo(83, 94, 89, 88, 97, 88) // some code removed for clarity ctx.fill() // the eyes ctx.fillStyle = 'white' ctx.beginPath() ctx.moveTo(91, 96) ctx.bezierCurveTo(88, 96, 87, 99, 87, 101) ctx.bezierCurveTo(87, 103, 88, 106, 91, 106) // some code removed for clarity ctx.fill() // the pupils ctx.fillStyle = 'blue' ctx.beginPath() ctx.arc(101, 102, 2, 0, Math.PI * 2, true) ctx.fill() ctx.beginPath() ctx.arc(89, 102, 2, 0, Math.PI * 2, true) ctx.fill() const texture = new THREE.Texture(canvas) texture.needsUpdate = true return texture}As you can see, first, we create an HTML canvas, on which we start drawing using the various ctx. functions. In the end, we convert this canvas into a THREE.Texture by calling new THREE.Texture(canvas), which results in a texture we can use for our sprites. Remember to set texture.needsUpdate to true, which triggers Three.js to load the actual canvas data into the texture.
Now that we’ve got a texture, we can use it to create a THREE.PointsMaterial, just like we did in the Understanding points and sprites section:
const createPoints = () => { const points = [] const range = 15 for (let i = 0; i < 15000; i++) { let particle = new THREE.Vector3( Math.random() * range - range / 2, Math.random() * range - range / 2, Math.random() * range - range / 2 ) points.push(particle) } const colors = new Float32Array(points.length * 3) points.forEach((e, i) => { const c = new THREE.Color(Math.random() * 0xffffff) colors[i * 3] = c.r colors[i * 3 + 1] = c.g colors[i * 3 + 2] = c.b }) const geom = new THREE.BufferGeometry().setFromPoints(points) geom.setAttribute('color', new THREE.BufferAttribute(colors, 3, true)) return geom}const material = new THREE.PointsMaterial({ size: 0.1, vertexColors: true, color: 0xffffff, map: createGhostTexture() })const points = new THREE.Points(createPoint(), material)As you can see, we create 15000 points for this example and position them randomly in the specified range. What you might notice is that even if you turn on transparency, some sprites seem to overlap other sprites. This is because Three.js doesn’t sort sprites based on their z-index, so during rendering, it can’t correctly determine which one is before another one. There are two ways you can work around this: you can turn off depthWrite, or you can play around with the alphaTest property (starting with 0.5 is a good starting point).
If you zoom out, you will see the 15,000 individual sprites:
![]()
Figure 7.5 – Showing 15,000 sprites all at once
The amazing thing is that even with 1 million points, everything is still rendered very smoothly (of course, this depends on the hardware you’re running these examples on):
![]()
Figure 7.6 – Showing 1 million sprites all at once
In the next section, we’ll load some textures from external images and use those instead of drawing the texture ourselves.
Using textures to style particles
Section titled “Using textures to style particles”In the example shown in the Drawing an image on the canvas section, we saw how to style THREE.Points using an HTML canvas. Since you can draw anything you want and even load external images, you can use this approach to add all kinds of styles to the particle system. There is, however, a more direct way to use an image to style your particles: you can use the THREE.TextureLoader().load() function to load an image as a THREE.Texture object. This THREE.Texture object can then be assigned to the map property of a material.
In this section, we’ll show you two examples and explain how to create them. Both these examples use an image as a texture for your particles. In the first example, we’ll create a simulation of rain (rain.html):

Figure 7.7 – Simulating rain falling down
The first thing we need to do is get a texture that will represent our raindrop. You can find a couple of examples in the assets/textures/particles folder. In the upcoming chapters, we will explain all the details and requirements for textures. For now, all you need to know is that the texture should be square and preferably a power of 2 (for example, 64 x 64, 128 x 128, or 256 x 256). For this example, we’ll use this texture:

Figure 7.8 – Raindrop texture
This texture is a simple transparent image and shows the shape and color of a raindrop. Before we can use this texture in THREE.PointsMaterial, we need to load it. This can be done with the following line of code:
const texture = new THREE.TextureLoader().load("../../assets/textures/particles/raindrop-3t.png");With this line of code, Three.js will load the texture, and we can use it in our material. For this example, we defined the material as follows:
const material = new THREE.PointsMaterial({ size: 0.1, vertexColors: false, color: 0xffffff, map: texture, transparent: true, opacity: 0.8, alphaTest: 0.01 }),In this chapter, we’ve discussed all of these properties. The main thing to understand here is that the map property points to the texture we loaded with the THREE.TextureLoader.load function. Note that we used the alphaTest property again to make sure there are no weird artifacts when two sprites are moving in front of one another.
That takes care of styling the THREE.Points object. What you’ll also see when you open this example is that the points themselves are moving. Doing this is very simple. Each point is represented as a vertex that makes up the geometry that was used to create the THREE.Points object. Let’s look at how we can add the points for this THREE.Points object:
const count = 25000const range = 20const createPoints = () => { const points = [] for (let i = 0; i < count; i++) { let particle = new THREE.Vector3( Math.random() * range - range / 2, Math.random() * range - range / 2, Math.random() * range - range / 1.5 ) points.push(particle) } const velocityArray = new Float32Array(count * 2) for (let i = 0; i < count * 2; i += 2) { velocityArray[i] = ((Math.random() - 0.5) / 5) * 0.1 velocityArray[i + 1] = (Math.random() / 5) * 0.1 + 0.01 } const geom = new THREE.BufferGeometry().setFromPoints(points) geom.setAttribute('velocity', new THREE.BufferAttribute(velocityArray, 2)) return geom}const points = new THREE.Points(geom, material);This isn’t that different than the previous examples we saw in this chapter. Here, we added another property to each particle called velocity. This property consists of two values: velocityX and velocityY. The first one defines how a particle (a raindrop) moves horizontally, while the second one defines how fast the raindrop falls. Now that each raindrop has its own speed, we can move the individual particles inside the render loop:
const positionArray = points.geometry.attributes.position.arrayconst velocityArray = points.geometry.attributes.velocity.arrayfor (let i = 0; i < points.geometry.attributes.position.count; i++) { const velocityX = velocityArray[i * 2] const velocityY = velocityArray[i * 2 + 1] positionArray[i * 3] += velocityX positionArray[i * 3 + 1] -= velocityY if (positionArray[i * 3] <= -(range / 2) || positionArray[i * 3] >= range / 2) positionArray[i * 3] = positionArray[i * 3] * -1 if (positionArray[i * 3 + 1] <= -(range / 2) || positionArray[i * 3 + 1] >= range / 2) positionArray[i * 3 + 1] = positionArray[i * 3 + 1] * -1}points.geometry.attributes.position.needsUpdate = trueIn this piece of code, we get all the vertices (particles) from the geometry that was used to create THREE.Points. For each of the particles, we take velocityX and velocityY and use them to change the current position of the particle. Then, we make sure the particles stay within the range we’ve defined. If the v.y position drops below 0, we add the raindrop back to the top, and if the v.x position reaches any of the edges, we make it bounce back by inverting the horizontal velocity. Finally, we need to tell Three.js we’ve changed some things in bufferGeometry so that it knows the correct values next time we’re rendering.
Let’s look at another example. This time, we won’t make rain; instead, we’ll make snow. Additionally, we won’t be using just a single texture – we’ll use three separate images (taken from the Three.js examples). Let’s start by looking at the result first (snow.html):

Figure 7.9 – Snowy scene based on multiple textures
In the preceding screenshot, if you look closely, you can see that instead of using just a single image as a texture, we’ve used multiple images that have transparent backgrounds. You might be wondering how we did this. As you probably remember, we can only have a single material for a THREE.Points object. If we want to have multiple materials, we just have to make multiple THREE.Points instances, as follows:
const texture1 = new THREE.TextureLoader().load ('/assets/textures/particles/snowflake4_t.png')const texture2 = new THREE.TextureLoader().load ('/assets/textures/particles/snowflake2_t.png')const texture3 = new THREE.TextureLoader().load ('/assets/textures/particles/snowflake3_t.png')const baseProps = { size: 0.1, color: 0xffffff, transparent: true, opacity: 0.5, blending: THREE.AdditiveBlending, depthTest: false, alphaTest: 0.01}const material1 = new THREE.PointsMaterial({ ...baseProps, map: texture1})const material2 = new THREE.PointsMaterial({ ...baseProps, map: texture2})const material3 = new THREE.PointsMaterial({ ...baseProps, map: texture3})const points1 = new THREE.Points(createPoints(), material1)const points2 = new THREE.Points(createPoints(), material2)const points3 = new THREE.Points(createPoints(), material3)In this code fragment, you can see that we create three different THREE.Points instances, each with its own materials. To move the snowflakes around, we use the same approach as for the rain, so we don’t show the details of createPoint and the render loop here. One thing to note here is that it is possible to have a single THREE.Points instance, where the individual sprites have different textures. However, this would require a custom fragment-shader and your own instance of THREE.ShaderMaterial.
Before we move on to the next section, note that using THREE.Points is a great way to add visual effects to an existing scene. For instance, the snow we saw in the previous example can quickly turn a standard scene into a snowy one:

Figure 7.10 – THREE.Points together with a cube map
Another way we can use sprites is to create a simple 2D heads-up display (HUD) on top of an existing scene. We’ll explore how to do this in the next section.
Working with sprite maps
Section titled “Working with sprite maps”At the beginning of this chapter, we used a THREE.Sprite object to render single points. These sprites were positioned somewhere in the 3D world, and their size was based on the distance from the camera (this is also sometimes called billboarding). In this section, we’ll show an alternative use of the THREE.Sprite object: we’ll show you how you can use THREE.Sprite to create a layer similar to a HUD for your 3D content using an extra THREE.OrthographicCamera instance and an additional THREE.Scene. We will also show you how to select the image for a THREE.Sprite object using a sprite map.
As an example, we’re going to create a simple THREE.Sprite object that moves from left to right over the screen. In the background, we’ll render a 3D scene with a camera, which you can move to illustrate that the THREE.Sprite object moves independently of the camera. The following screenshot shows what we’ll be creating for the first example (spritemap.html):

Figure 7.11 – Using two scenes and cameras to create a HUD
If you open this example in your browser, you’ll see a Pac-Man ghost-like sprite moving across the screen that changes color and form whenever it hits the right edge. The first thing we’ll do is look at how we can create THREE.OrthographicCamera and a separate scene to render this THREE.Sprite:
const sceneOrtho = new THREE.Scene()sceneOrtho.backgroundColor = new THREE.Color(0x000000)const cameraOrtho = new THREE.OrthographicCamera(0, window.innerWidth, window.innerHeight, 0, -10, 10)Next, let’s look at the construction of the THREE.Sprite object and how the various shapes the sprite can take are loaded:
const getTexture = () => { const texture = new THREE.TextureLoader().load ('/assets/textures/particles/sprite-sheet.png') return texture}const createSprite = (size, transparent, opacity, spriteNumber) => { const spriteMaterial = new THREE.SpriteMaterial({ opacity: opacity, color: 0xffffff, transparent: transparent, map: getTexture() }) // we have 1 row, with five sprites spriteMaterial.map.offset = new THREE.Vector2(0.2 * spriteNumber, 0) spriteMaterial.map.repeat = new THREE.Vector2(1 / 5, 1) // make sure the object is always rendered at the front spriteMaterial.depthTest = false const sprite = new THREE.Sprite(spriteMaterial) sprite.scale.set(size, size, size) sprite.position.set(100, 50, -10) sprite.velocityX = 5 sprite.name = 'Sprite' sceneOrtho.add(sprite)}In the getTexture() function, we load a texture. However, instead of loading five different images for each ghost, we load a single texture that contains all the sprites (also called a sprite map). The image we have as a texture looks like this:
![]()
Figure 7.12 – Input sprite sheet
With the map.offset and map.repeat properties, we can select the correct sprite to show on the screen. With the map.offset property, we determine the offset for the x a xis (u) and the y a xis (v) for the texture we loaded. The scale for these properties runs from 0 to 1. In our example, if we want to select the third ghost, we must set the u -offset (x a xis) to 0.4, and, because we’ve only got one row, we don’t need to change the v -offset (y a xis). If we only set this property, the texture shows the third, fourth, and fifth ghosts compressed together on screen. To only show one ghost, we need to zoom in. We can do this by setting the map.repeat property for the u -value to 1/5. This means that we zoom in (only for the x a xis) to only show 20% of the texture, which is exactly one ghost.
Finally, we need to update the render function:
renderer.render(scene, camera)renderer.autoClear = falserenderer.render(sceneOrtho, cameraOrtho)First, we render the scene with the normal camera and the two meshes; after that, we render the scene containing our sprite. In the render loop, we also switch some properties to show the next sprite when it hits the right wall and change the sprite’s direction (code not shown).
So far in this chapter, we’ve mainly looked at creating sprites and point clouds from scratch. An interesting option, though, is to create THREE.Points from an existing geometry.
Creating THREE.Points from existing geometry
Section titled “Creating THREE.Points from existing geometry”As you may recall, THREE.Points renders each point based on the vertices from the supplied THREE.BufferGeometry. This means that if we provide a complex geometry (for example, a torus knot or a tube), we can create THREE.Points based on the vertices from that specific geometry. In this final section of this chapter, we’ll create a torus knot, like the one we saw in Chapter 6, Exploring Advanced Geometries, and render it as a THREE.Points object.
We explained the torus knot in Chapter 6, so we won’t go into much detail here. The following screenshot shows the example (points-from-geom.html):

Figure 7.13 – Torus knot rendered as points with a small animation
As you can see from the preceding screenshot, every vertex used to generate the torus knot is used as a point. We can set this up like this:
const texture = new THREE.TextureLoader().load('/assets/textures/particles/glow.png')const geometry = new THREE.TorusKnotGeometry(2, 0.5, 100, 30, 2, 3)const material = new THREE.PointsMaterial({ size: 0.2, vertexColors: false, color: 0xffffff, map: texture, depthWrite: false, opacity: 0.1, transparent: true, blending: THREE.AdditiveBlending })const points = new THREE.Points(geometry, material)As you can see, we simply create a geometry and use that as input for the THREE.Points object. This way, we can render every geometry as a points object.
Note
If you load external models using a Three.js model loader (for example, a glTF model), you’ll often end up with a hierarchy of objects – often grouped in THREE.Group or THREE.Object3D objects. In those cases, you’ll have to convert each geometry in each group into a THREE.Points object.
Summary
Section titled “Summary”That’s a wrap for this chapter. We’ve explained what sprites and points are and how you can style these objects with the materials available. In this chapter, you saw how you can use THREE.Sprite directly, and that if you want to create a large number of particles, you should use a THREE.Points object. With THREE.Points, all the elements share the same material, and the only property you can change for an individual particle is its color by setting the vertexColors property of the material to true and providing a color value in the colors array of THREE.BufferGeometry, which is used to create THREE.Points. We also showed how you can easily animate particles by changing their position. This works the same for an individual THREE.Sprite instance and the vertices from the geometry used to create THREE.Points objects.
So far, we have created meshes based on geometries provided by Three.js. This works well for simple models, such as spheres and cubes, but isn’t the best approach when you want to create complex 3D models. For those models, you’d usually use a 3D modeling application, such as Blender or 3D Studio Max. In the next chapter, you’ll learn how you can load and display models created by such 3D modeling applications.