# ThreeJS light probes

**URL:** <https://discourse.threejs.org/t/threejs-light-probes/55981>\
**Category:** Questions\
**Tags:** light-probes, blender\
**Created:** [September 13, 2023, 2:19pm UTC](https://discourse.threejs.org/t/threejs-light-probes/55981 "2023-09-13T14:19:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gillesboisson](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gillesboisson/32/39924_2.png) [@gillesboisson](https://discourse.threejs.org/u/gillesboisson)\
**Post date:** [September 13, 2023, 2:19pm UTC](https://discourse.threejs.org/t/threejs-light-probes/55981/1 "2023-09-13T14:19:57Z")

</div>

Hi,

I’m working on blender plugin which export probes (irradiance grid and reflection cubemap). It is still in progress but it has enough features to be integrated with existing engine.

I didn’t see much stuff about threejs supporting light probes it so I would like to work also on some plugin which extends existing light system with probes. Is anyone is also interested to work on something like this or know existing work ?

Cheers

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [September 13, 2023, 2:51pm UTC](https://discourse.threejs.org/t/threejs-light-probes/55981/2 "2023-09-13T14:51:48Z")

</div>

> [@gillesboisson](#):
>
> I didn’t see much stuff about threejs supporting light probes it so I would like to work also on some plugin which extends existing light system with probes. Is anyone is also interested to work on something like this or know existing work ?

`three.js` has a basic light probe implementation. There is the [LightProbe](https://threejs.org/docs/index.html#api/en/lights/LightProbe) class itself as well as a [LightProbeGenerator](https://threejs.org/docs/index.html#examples/en/lights/LightProbeGenerator) that can be used to generate a light probe from cube textures/render targets.

There is also a WIP PR by @donmccurdy which adds a `LightProbeVolume` class.

> <https://github.com/mrdoob/three.js/pull/18371>
>
> \## Summary
> 
> A LightProbeVolume samples diffuse indirect lighting in a scene at… each of several LightProbe locations, then provides approximate diffuse lighting for dynamic objects at any location within that space. The method complements baked lighting and lightmaps — which only support static objects — by providing high-quality lighting for dynamic objects as they move throughout a larger scene. Like lightmaps, LightProbeVolumes can be 'baked' offline and stored, then loaded and applied at runtime very efficiently.
> 
> Fixes https://github.com/mrdoob/three.js/issues/16228.
> 
> Thanks to @WestLangley, @bhouston, and @richardmonette for helpful discussions and code that contributed to this PR.
> 
> \## API
> 
> Bake:
> 
> \`\`\`javascript
> var cubeCamera = new THREE.CubeCamera( 0.1, 100, 256, {
> format: THREE.RGBAFormat,
> magFilter: THREE.LinearFilter,
> minFilter: THREE.LinearFilter
> } );
> 
> // Renderer output is sRGB. Configure renderTarget accordingly.
> cubeCamera.renderTarget.texture.encoding = THREE.sRGBEncoding;
> 
> // Generate a light probe volume and populate probes in a 10x3x10 grid. Then
> // sample lighting at each probe using the CubeCamera.
> var volume = new THREE.LightProbeVolume()
> .setFromBounds( new THREE.Box3().setFromObject( scene ), 10, 3, 10 )
> .build()
> .bake( renderer, scene, cubeCamera );
> 
> // Store volume and baked lighting as a small JSON object.
> var data = volume.toJSON();
> \`\`\`
> 
> Apply:
> 
> \`\`\`javascript
> // Reconstruct the volume with pre-baked lighting.
> var volume = new THREE.LightProbeVolume().fromJSON( data );
> scene.add( volume );
> 
> probe = new THREE.LightProbe();
> scene.add( probe );
> 
> function render () {
> 
> volume.update( mesh, probe.sh );
> 
> renderer.render( scene, camera );
> 
> }
> \`\`\`
> 
> Lighting is sampled only at the center of each mesh, and larger objects like terrain and buildings will not receive realistic lighting from a single sample. Shadows are not cast by light probes.
> 
> \## Unresolved
> 
> \- \[\] \*\*Per-object SH.\*\* While per-object SH coordinates can be computed, only one "probe" is actually in the scene graph functioning as a light. So only one mesh can receive dynamic lighting. This can be resolved with an API to assign SH coordinates or a light probe to a specific object or material.
> \- \[\] \*\*Optimize.\*\* Various inefficiencies left as TODO. For example, LightProbeVolumeHelper should use InstancedMesh, and \`volume.update()\` should search incrementally from the last known cell to improve update times.
> \- \[\] \*\*Correct baking.\*\* I'm not convinced my "baking" method is quite right, but it looks pretty good. Maybe this could be done offline in other tools.
> \- \[X\] \*\*Class structure.\*\* ~~In this demo, LightProbeVolume is in the scene graph but its probes are not (I don't want them all affecting the mesh). I'm open to other ways of structuring this.~~ It's useful for the volume to have position in the scene.
> \- \[x\] \*\*Grid volumes.\*\* ~~Should we allow arbitrarily-shaped volumes, or require grid-shaped volumes? Blender and Godot appear to be OK with grids. That would let us omit the Delaunay library (which generates ~5x~ 1.5x more tetrahedra than needed, for a grid?), improving volume creation time. And if (in the future) we want to upload the whole volume's SH coordinates to a GPU texture for sampling in the fragment shader, I think a grid would be necessary. But it is less flexible / optimizable.~~ Grids only, for now.
> 
> \## Demo
> 
> https://raw.githack.com/donmccurdy/three.js/feat-lightprobevolume-build/examples/?q=volume#webgl\_lightprobe\_volume
> 
> !\[Screen Shot 2020-01-11 at 1 19 31 PM\](https://user-images.githubusercontent.com/1848368/72210746-0f41a600-3475-11ea-96c4-48da18c3e44a.png)

I think it’s best if you use this implementation as a basis for your exporter since `LightProbeVolume` can read irradiance data from JSON files. It would be great if your Blender exporter could support the respective JSON format.

---

<div class="post-metadata">

**Author:** ![gillesboisson](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gillesboisson/32/39924_2.png) [@gillesboisson](https://discourse.threejs.org/u/gillesboisson)\
**Post date:** [September 13, 2023, 3:19pm UTC](https://discourse.threejs.org/t/threejs-light-probes/55981/3 "2023-09-13T15:19:08Z")

</div>

Thanks, really interesting stuff.

I forgot to share the link of the blender plugin repo. It works out the box by just installing the plugin source in blender.

> **[GitHub - gillesboisson/blender-probes-export: Blender plugin allowing to...](https://github.com/gillesboisson/blender-probes-export)**
>
> Blender plugin allowing to precompute reflectance, indirect luminance from blender and export data for use in external engine - GitHub - gillesboisson/blender-probes-export: Blender plugin allowing...

for info It exports :

- irradiance probes grid as cubemaps sheet (one sheet per grid, SH not supported yet)
- and reflection cubemap as multi level roughness level cubemap sheet.
