# Reflection Probes

> Learn how to use reflection probes in your Babylon.js scene.

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

## How to use Reflection Probes

![Reflection Probes example](https://doc.babylonjs.com/img/reflectionProbe.webp)

Reflection probes are used to dynamically generate cube maps that can then be used as reflection textures, for instance.

Here is how to use them:

```javascript
const probe = new BABYLON.ReflectionProbe("main", 512, scene);
probe.renderList.push(yellowSphere);
probe.renderList.push(greenSphere);
probe.renderList.push(blueSphere);
probe.renderList.push(mirror);

mainMaterial.reflectionTexture = probe.cubeTexture;
```

As you can see, you have to define which meshes will be rendered by the reflection probe.

**You have to be cautious with reflection probes, as they need to generate 6 textures per frame (one per face).**

You can change the update rate (on every frame by default) with this code:

```javascript
probe.refreshRate = BABYLON.RenderTargetTexture.REFRESHRATE_RENDER_ONCE;
// or
probe.refreshRate = BABYLON.RenderTargetTexture.REFRESHRATE_RENDER_ONEVERYFRAME;
// or
probe.refreshRate = BABYLON.RenderTargetTexture.REFRESHRATE_RENDER_ONEVERYTWOFRAMES;
// or
probe.refreshRate = 3;
```

To get the best possible rendering, you also need to move your probe to the center of the mesh that should use the generated cube map.
(Internally, the probe will generate a ghost camera at that position and then render the faces from there.) You have two options to achieve this:

```javascript
probe.attachToMesh(root);
// or
probe.position = new BABYLON.Vector3(0, 1, 0);
```

If you want to try it, check this out: [Playground: Reflection Probe Example](https://playground.babylonjs.com/#KA93U#243) - Simple example of how to use reflection probes in your scene.

## Probes and PBR

If you want to achieve the highest quality for your PBR materials using probes for real-time reflections, the engine needs additional processing to achieve the right glossiness/roughness effect.
Getting it right is really simple: first, set up a probe on your mesh with a PBR material, as described in the previous paragraph. Then you need to enable this flag on your material:

```javascript
mainMaterial.reflectionTexture = probe.cubeTexture;
mainMaterial.realTimeFiltering = true;
```

This flag will ensure your PBR material is rendered correctly with the probe. However, it involves more GPU processing for your materials, so be sure to use it wisely. To keep performance under control, you can set the quality of the filtering process for your material:

```javascript
mainMaterial.realTimeFilteringQuality = BABYLON.Constants.TEXTURE_FILTERING_QUALITY_MEDIUM;
```

The default is `TEXTURE_FILTERING_QUALITY_LOW`. Try different qualities and see which gives the best performance/quality tradeoff for your scene.

Here is a playground example with a reflection probe and PBR material: [Playground: Reflection Probe and PBR Example](https://playground.babylonjs.com/#FEEK7G#116) - Simple example of how to use reflection probes with PBR in your scene.

You can also have a look at this [blog post](https://medium.com/@babylonjs/real-time-pbr-filtering-is-coming-to-babylon-cb0e81159d79) for more information about HDR filtering.

## Further reading

- [Reflections and Refractions](https://doc.babylonjs.com/features/featuresDeepDive/materials/using/reflectionTexture)
