I need to add a light probe to Maud. I was ready to figure out how to use light probes by reading source code and then experimenting. Then it occurred to me: we ought to have a tutorial in the wiki!
Then rootNode.addLight(probe) or someNode.addLight(probe) when you want it.
Edit: and note this is not for generated probes… it’s for pregenerated probes or using probes from a standard set. (For example, the studio light probe is a pretty general probe that will work for a lot of indoor scenes.)
I’ll see what I can do about a wiki page. (Something tells me I should give up coding for the month of December and just work on documentation.)
The intended workflow is a mystery to me.
Suppose I have a working environment with no probes: just a floor geometry, skybox, DirectionalLight, AmbientLight, and a shadow processor. Should I do a makeProbe(), serialize it, and then restart the application with just the floor geometry, skybox, and (deserialized) probe?
Or do I need the shadow processor in addition to the probe? Will they even work together?
What follows are my observations about probes when last I tried them, about a year ago.
When using the probe if the model is outside the radius it will be black. Using the SDK will show the radius of the probe and whats being lit inside the radius.
The size of the world and radius of probe determines what is lit. The larger the radius, the longer for the probe to build. It can take a huge amount of time for a large radius.
I wasn’t paying attention to the shadows when I tried probes as they were there and working as expected. This being said, its the reflection of things that I found determines what to do with a probe. The probe will reflect whatever was at that position in the scene when it was built. So if a model like the hover car is in the scene when built, it will show in the reflection of certain materials the probe lights, like metal or shiny objects , even though it may not be in the scene.
Its been awhile so I am rusty on the subject so others should chime in to give more details if they can.
I build some trivial (uniform) light probes at runtime in the MyWorld client - will chime in as soon as I’ve some time to condense what I’m doing with them into a useful forum post.
My knowledge on the topic might be a bit outdated, but here’s how I did it when I last used jME for something that wasn’t a short experiment.
How to create a light probe in code (kitbashed together from my old projects and current documentation, might need some testing):
EnvironmentCamera envCam = new EnvironmentCamera(); //Make an env camera
stateManager.attach(envCam);
envCam.initialize(stateManager, app); //Manually initilaize so we can add a probe before the next update happens
LightProbe probe = LightProbeFactory.makeProbe(envCam, rootNode);
probe.getArea().setRadius(10); //Set the probe's radius in world units
probe.setPosition(new Vector3f(1, 0, -2)); //Position it in 3d space
rootNode.addLight(probe);
This will add the light probe to the root node and kick off the rendering in a separate thread. After the rendering finishes, there is usually a visible change in scene lighting, so using the SDK or a custom baker to bake the light probes beforehand is kind of a must. That way the probe can be simply loaded from a j3o (as paul already posted) and is available for use immediately.
A bit late responding, but here’s the setup I use in the MyWorld client to generate simple uniform lighting probes (these are handy for OSR model viewing windows, for one):
public static LightProbe generateUniform(Application app, float intensity, Runnable completionListener) {
intensity = Math.min(1.0f, Math.max(intensity, 0)); // cap intensity between 0 & 1
Geometry skyBox = new Geometry("sky", new Box(1, 1, 1));
Material unshaded = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
unshaded.setColor("Color", ColorRGBA.White.clone().multLocal(intensity));
// Need to disable face culling since we're interested in the inside of the mesh, not the outside
unshaded.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
skyBox.setMaterial(unshaded);
skyBox.setQueueBucket(Bucket.Sky);
Node scene = new Node("Snapshot");
scene.attachChild(skyBox);
scene.updateGeometricState();
EnvironmentCamera envCam = new EnvironmentCamera(4);
envCam.initialize(app.getStateManager(), app);
app.getStateManager().attach(envCam);
return LightProbeFactory.makeProbe(envCam, scene, new JobProgressListener<LightProbe>() {
@Override
public void start() {
}
@Override
public void step(String message) {
}
@Override
public void progress(double value) {
}
@Override
public void done(LightProbe result) {
if(completionListener != null) {
completionListener.run();
}
app.enqueue(() -> {
app.getStateManager().detach(envCam);
});
}
});
}
Note that even though generating the light probe is an asynchronous process, they’re safe to attach immediately - they’re aware of whether or not they’re ready for use and won’t cause problems if they’re attached before they’re ready.
I have tried this , but in Android context & I cannot see a 360 reflections on my Spatials , even though they are reflecting light properly , is there something that should be added ?
I was under the opposite impression - other light types do work with the shaders, but I think that baking directionality and global ambience into a light probe would give a better result (assuming that the data was closer to real-world conditions than, say, a single directional vector for directional light). I could be totally off there, however - curious to get some feedback as I’ve not experimented with that yet
I experimented by removing the DirectionalLight from TestPBRLighting after adding the LightProbe. Once the probe was ready, the hovertank illuminated only by the probe looked great, so apparently light probes aren’t supplementary in the way I imagined.
Perhaps the PBR material uses directional lights only if there’s no ready probe in range. I browsed “PBRLighting.frag” and wasn’t convinced. Still figuring this out…
My understanding is that the HDR by itself can’t illuminate the tank model. Information from the HDR gets baked into the probe, and the probe illuminates the model.
In fact , I am using only DirectionalLight plus some PointLights with different colors & it’s good illuminated on Android , but still havenot tried lightProbes yet , because it’s not supported in android java code but what I see from my experiments that PBRLighting Materials could be lit up by any light except ambient & they gave different results , I donot know if I am true or not , but that were live experiments
For Android, indirect lighting cannot be obtained through code, you can only add indirect lighting through the SceneComposer of the SDK. Then load j3o in android.