> Learn how to add a background material to your Babylon.js scene.

Source: https://doc.babylonjs.com/features/featuresDeepDive/environment/backgroundMaterial

# Background Material

## Introduction

Fully lit materials are not always desired in a scene. We are introducing a new unlit and fast material to help address the constraints you may have with standard or PBR materials.

The background material is fully unlit but can still receive shadows and be subject to image processing. This makes it a great fit for use as a skybox or ground material.

![background](https://doc.babylonjs.com/img/how_to/backgroundMaterial.webp)

## Diffuse

The diffuse part is used to simply give a color to the mesh.

```javascript
backgroundMaterial.diffuseTexture = new BABYLON.Texture("textures/grass.jpg", scene);
```

You can see an example of this here: [Playground: Simple Diffuse Background Material](https://playground.babylonjs.com/#157MGZ) - Simple example of how to add an unlit diffuse material to your scene.

### Shadows

The material is able to receive shadows despite being unlit \o/ This is actually one of its strengths, making it very attractive for grounds. If you want to reduce the amount of shadow, you can use the dedicated properties:

```javascript
backgroundMaterial.shadowLevel = 0.4;
```

You can see an example here: [Playground: Background Material with Shadows](https://playground.babylonjs.com/#G3HSAW#3) - Simple example of a background material receiving shadows.

Starting with Babylon.js v4.2, there is also a new `shadowOnly` property that renders only shadows, making the material behave like the `ShadowOnlyMaterial` material but without the single-light restriction.

When `shadowOnly = true`, you can use `primaryColor` to tint the shadow color and `alpha` to make the shadows more or less strong: [Playground: Background Material with Tinted Shadows](https://playground.babylonjs.com/#G3HSAW#33) - Simple example of a background material receiving tinted shadows.

### Opacity

If you want to make a transparent ground and the diffuse texture contains transparency information, it will be used by the material.

```javascript
backgroundMaterial.diffuseTexture.hasAlpha = true;
```

You can see an example here: [Playground: Background Material with Transparnecy](https://playground.babylonjs.com/#G3HSAW#4) - Simple example of a background material with transparency.

### Opacity Fresnel

Also, by default, the ground will disappear as your view gets close to being aligned with it. This prevents a harsh cut while navigating the scene. It is possible to disable it by:

```javascript
backgroundMaterial.opacityFresnel = false;
```

You can see an example here: [Playground: Removing opacityFresnel](https://playground.babylonjs.com/#G3HSAW#5) - Simple example of turning off the opacityFresnel of the background material.

## Reflection

Unlit materials are a great fit for creating a skybox. You can, just like with the standard material, set your reflection texture:

```javascript
backgroundMaterial.reflectionTexture = new BABYLON.CubeTexture("textures/TropicalSunnyDay", scene);
backgroundMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
```

You can see an example here: [Playground: Background Material with Reflection Texture](https://playground.babylonjs.com/#G3HSAW#6) - Simple example of a background material with a reflection texture.

### Mirror

As the reflection setup is comparable to the standard material, using a mirror works in the same way.

```javascript
mirror = new BABYLON.MirrorTexture("mirror", 512, scene);
mirror.mirrorPlane = new BABYLON.Plane(0, -1, 0, 0);
mirror.renderList.push(sphere);

backgroundMaterial.reflectionTexture = mirror;
```

You can see an example here: [Playground: Background Material with Mirror Reflection Texture](https://playground.babylonjs.com/#G3HSAW#9) - Simple example of a background material with a mirror reflection texture.

### Reflection Fresnel

As we can use both reflection and diffuse, reflection fresnel can help you feel more immersed in the experience:

```javascript
backgroundMaterial = new BABYLON.BackgroundMaterial("backgroundMaterial", scene);
backgroundMaterial.diffuseTexture = new BABYLON.Texture("https://assets.babylonjs.com/environments/backgroundGround.png", scene);
backgroundMaterial.diffuseTexture.hasAlpha = true;
backgroundMaterial.opacityFresnel = false;
backgroundMaterial.shadowLevel = 0.4;

mirror = new BABYLON.MirrorTexture("mirror", 512, scene);
mirror.mirrorPlane = new BABYLON.Plane(0, -1, 0, 0);
mirror.renderList.push(sphere);
backgroundMaterial.reflectionTexture = mirror;
backgroundMaterial.reflectionFresnel = true;
backgroundMaterial.reflectionStandardFresnelWeight = 0.8;

ground.material = backgroundMaterial;
```

You can see an example here: [Playground: Reflection Fresnel Example](https://playground.babylonjs.com/#G3HSAW#10) - Simple example of a using reflection fresnel.

## Misc and Colors

Sometimes all we need is color, and you can use the texture as grayscale information to mix with a color.

```javascript
backgroundMaterial.useRGBColor = false;
backgroundMaterial.primaryColor = BABYLON.Color3.Magenta();
```

You can see an example here: [Playground: Mix Gray Scale and Color](https://playground.babylonjs.com/#G3HSAW#11) - Simple example of a mixing grayscale and color.

## Environment

Going further, you can take a look at the [Environment documentation](https://doc.babylonjs.com/features/introductionToFeatures/chap5/sky) where you can find information on how to speed up the setup of your scene with a skybox and a ground.

For the ground projection capabilities of the material, you can have a look at the dedicated section within the [skybox documentation](https://doc.babylonjs.com/features/featuresDeepDive/environment/skybox#ground-projection).
