# ShadowOnly Material

> The Babylon.js materials library ShadowOnlyMaterial displays only shadows cast by a light on a receiving object.

Source: https://doc.babylonjs.com/toolsAndResources/assetLibraries/materialsLibrary/shadowOnlyMat

## General

![Screenshot](https://doc.babylonjs.com/img/extensions/materials/shadowOnly.webp)

The goal of the ShadowOnlyMaterial is to display only shadows cast by a light on a receiving object. It is mostly useful when you want to display shadows on a transparent canvas (on top of your existing DOM).

The ShadowOnly material can be found here: [https://cdn.babylonjs.com/materialsLibrary/babylon.shadowOnlyMaterial.js](https://cdn.babylonjs.com/materialsLibrary/babylon.shadowOnlyMaterial.js)

> [!WARNING]
> **Warning**
>
> The CDN should not be used in production environments. The purpose of our CDN is to serve Babylon packages to users learning how to use the platform or running small experiments. Once you've built an application and are ready to share it with the world at large, you should serve all packages from your own CDN.

A demo can be found here: PG: [Playground: Shadow Only Material](https://playground.babylonjs.com/#1KF7V1) - Example of shadow only material

## Using the ShadowOnly material

ShadowOnly material is very simple to use. Just apply it as a material to any mesh where you want to display only shadows:

```
var ground = BABYLON.MeshBuilder.CreatePlane('ground', { size: 1000 }, scene)
ground.rotation.x = Math.PI / 2
ground.material = new BABYLON.ShadowOnlyMaterial('shadowOnly', scene)
ground.receiveShadows = true
```

By default, the shadow color is black, but you can force an artificial color with `material.shadowColor = BABYLON.Color3.Red()`.

Demo here:  PG: [Playground: Shadow Only Material](https://playground.babylonjs.com/#1KF7V1#19) - Example of shadow only material color

**Limitation:** Please note that only the first light that can reach the mesh will be used. 
So if you have multiple lights in your scene, you may need to use `light.includedOnlyMeshes` or `light.excludedMeshes` or `light.includeOnlyWithLayerMask` or `light.excludeWithLayerMask`.
You can also force the material to pick a specific light with `material.activeLight = light`.
