Is it possible to access the baked data from a light probe through Blender’s Python API?
In particular I’m hoping to get Spherical Harmonics coefficients for each cell in an Irradiance Volume, but coefficients for a Reflection Cubemap probe would be fine too. I’m assuming that’s stored in a cache somewhere, but digging around in the console (e.g. bpy.context.*
) and the source code isn’t getting me anywhere.
Thanks!
6 Likes
ncoder
July 20, 2020, 5:44am
2
Closest I could get is:
bpy.ops.scene.light_cache_bake()
bpy.ops.scene.light_cache_free()
bpy.context.scene.eevee.gi_cache_info
It doesn’t look like there are bindings for python, afaik. Would need a patch?
Suppose someone who’s never tried to expose new APIs in blender would try to do this, any pointers? What would be the right way to do it?
4 Likes
I think that’s correct, yes.
Suppose someone who’s never tried to expose new APIs in blender would try to do this, any pointers?
I tried to figure this out, too, but don’t understand C++ well enough to get anywhere with it sorry. There were definitely pointers involved.
I’m pretty sure all of that code is C, anyways
1 Like
Haha, well, i guess that tells you how far I got on this myself!
By the way, I posted the same suggestion on rightclickselect if anyone would like to upvote it.
3 Likes
ncoder
July 20, 2020, 8:53pm
7
Lol. Yes.
I think Don and I are interested in getting that blender lightprobe data into three.js’s three.js docs . I’ve got all the C/C++ experience required. I’m hesitant to try to put a patch together, as i expect I’ll just make the interface wrong way and my PR will get rejected.
I guess I’m looking for a “sponsor” that would be the right person to review the work who could tell me how they would do it, so that we’re all happy in the end.
4 Likes
Has anyone made any headway on this? Recently started to look into this myself and want to make sure I am not duplicating any work.
1 Like
@netpro2k no progress on the Blender portion of this, as far as I know. I did write up a draft PR to three.js for light probe volumes defined by interpolated SH values:
mrdoob:dev
← donmccurdy:feat-lightprobevolume
opened 09:26PM - 11 Jan 20 UTC
## 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

1 Like