Subscribe to our free newsletter

To make sure you won't miss any valuable content we share with our community.

Using Video as a Texture in Three JS

We have discussed the textures many times on our blog and covered many articles about them in Three.js, but we have always focused on an image texture instead of a video texture. You might want to use the video texture on a geometrical shape and simulate a kind of a 3D cinema or want to map a video inside of a skybox. This will give you infinite possibilities. In this tutorial, we will focus on how to map a video on a geometrical shape and then use this script to create more cool stuff along the way. We will definitely need to load the video in the index.html file created by the Vite plugin in the project directory.

Getting started from scratch:

We will get started with the main elements of a Three js scene, including the camera, the renderer, the scene, and the object. Before doing that, we use the Vite plugin to easily create all the folders and files you need to run the Three.js code. First off, create a folder in the directory of your projects by using the following commands: mkdir VideoTextures
cd VideoTextures
Then, inside of the your project folder, create the necessary files and folders by simply running the Vite plugin command: npm create [email protected] Then enter the name of the project. You can write the name of your project as the name. And also the package (the name is arbitrary, and you can choose anything you want). Then select vanilla as the framework and variant. After that, enter the following commands in the terminal. Notice that here VideoTextures is the project folder’s name, and thus, we have changed the directory to VideoTextures. The name depends on the name you enter in the Vite plugin : cd VideoTextures
npm install
Afterward, you can enter the JavaScript code you want to write in the main.js file. So, we will enter the base or template code for running every project with an animating object, such as a sphere. Also, do not forget to install the Three.js package library every time you create a project: npm install three

The code :

Now, enter the following script in the main.js file:

import * as THREE from 'three';
import { Mesh } from 'three';
import { VideoTexture } from 'three';
import {OrbitControls} "/node_modules/three/examples/jsm /controls/OrbitControls.js";
import Stats from "/node_modules/three/examples/jsm/libs/stats.module.js";

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, innerWidth /innerHeight , 0.1, 1000);
const renderer = new THREE.WebGLRenderer({
     antialias : true

renderer.setSize(innerWidth, innerHeight);
const video = document.getElementById( 'video' );
const videoTexture = new THREE.VideoTexture( video );

//creating a sphere
const geometry = new THREE.BoxGeometry(8,8,8);
const material = new THREE.MeshBasicMaterial({
     map : new THREE.VideoTexture( video ),
     side : THREE.FrontSide,
     toneMapped : false,

const sphere = new THREE.Mesh(geometry, material);
camera.position.z = 15;

function animate(){
     sphere.rotation.y += 0.003;
     //videoTexture.needsUpdate = true;


We should also change the HTML as below:

<!DOCTYPE html>
<html lang="en">
          <meta charset="UTF-8" />
          <link rel="icon" type="image/svg+xml" href="/vite.svg" />
          <meta name="viewport" content="width=device-width, initial-scale=1.0" />
          <title>Vite App</title>
               id = "video"
               style="display: none"
          <div id="app"></div>
          <script type="module" src="/main.js"></script>

Notice that in the above .html script we only add the video tag in the body:

     id = "video"
     style="display: none"

Do not forget to copy the video inside a folder called video and set the name of the video as vid1. Now if we save the code, and enter the following command in the terminal: npm run dev The above script will give the following result:

And as you can see we have a video on each sides of the cube.


In this tutorial, we worked on a cool project: placing a video texture onto a cube. This project can open the door to so many possibilities. To make this happen, we first created a folder and pasted a video in it. Afterward, we added the video HTML tag in the index.html file and the Three.js code in the main.js file. This approach helped us develop some 3D cinema. In future tutorials, we will teach you how you can create an actual 3D cinema with 360 views.

Download this Article in PDF format

3d websites

Arashtad Custom Services

In Arashtad, we have gathered a professional team of developers who are working in fields such as 3D websites, 3D games, metaverses, and other types of WebGL and 3D applications as well as blockchain developemnet.

Arashtad Serivces
Drop us a message and tell us about your ideas.
Fill in the Form
Blockchain Development