--- title: Lights and Shadows description: Learn how to add lights and shadows to your scene. author: alvarosabu thumbnail: /recipes/lights-and-shadows.png difficulty: 0 --- # Light-shadows This guide will help you get started with simple light and shadows in TresJS. We will build a simple scene with three meshes and a plane but only two will have shadows. ## Setting up the scene (optional) We import all the modules that we need, for comfort we can use the orbit-controls from cientos, [check here to know how](/cookbook/orbit-controls). Let's put four objects in our scene, one will be the plane that receive shadows, two of them will cast shadows and the last one will not cast any shadow at all. I'm going to use [MeshToonMaterial](https://threejs.org/docs/index.html?q=toon#api/en/materials/MeshToonMaterial). Simply because we can see the "soft shadow" easily. ```vue ``` ## Lights (explanation) As you know every instance in [ThreeJs](https://threejs.org/) is available in **TresJs** so are all the light types, we just need to add the `Tres` prefix to use them. But not all lights can cast shadows, this definition comes directly from ThreeJs and makes sense, for example the purpose of an [ambientLight](https://threejs.org/docs/index.html?q=ambient#api/en/lights/AmbientLight) is to iluminate everysingle side of your scene, so it makes no sense for it to cast shadows, on the contrary, a [DirectionalLight](https://threejs.org/docs/index.html?q=light#api/en/helpers/DirectionalLightHelper) immitating the sun can and should cast shadows. ## Shadows (explanation) There are also many types of shadows, for example the "soft shadow" is generated automatially when an object receives more light from one side, but in summary a "ThreeJS default shadow" that is directed towards another surface needs to be cast by a mesh and another mesh needs to receive it. As we see in our example, the `Plane` is receiving a shadow but not casting it. Please note that not all materials can cast or receive shadows. Internally, ThreeJS automatically generates a new mesh with a [ShadowMaterial](https://threejs.org/docs/index.html?q=shado#api/en/materials/ShadowMaterial) which gets updated in each frame, that is why if you apply animations, the shadow also is animated, but also why you have to use shadows carefully, because they could slow your performance down. ::: warning The overuse of shadows in this way could drop your performance. However, there are ways to increase your performance, for more information please check out [this video](https://youtu.be/WGNvVGrS0kY?si=q7XyL5eABKUh3gbS&t=1256) ::: ## Enabling shadows We could divide this into three steps: ### Activate shadows on the renderer ```vue //... ``` ### Set the light to cast shadows We can simply add the boolean `cast-shadow`, Vue understands this as a `prop` with a value of `true`. _The AmbientLight doesn't generate any type of shadow here_ ```vue //... ``` ### Set the objects to cast or receive shadows Similarly to the previous step, we set the mesh that we want to cast shadow (our sphere) with the `cast-shadow` prop, and set the object to receive shadow (our plane) with the `receive-shadow` prop. ```vue //... ``` Now we have all the necessary steps to add shadows to our scene, and if we apply what we learned in [basic animations](/cookbook/basic-animations), and we add movement to our cube, you will see the shadow is animated as well. 🤩 ```vue ``` _Note that I intentionally did not apply `cast-shadow` to the `Cone` so it doesn't cast any shadow_