PBR + RenderToTexture + EnvironmentCamera

Hi,
PBR needs a LightProbe, which needs an EnvironmentCamera which is an AppState, right? I need some model rendered to texture using PBR, so I only want to have the preview viewport rendered in the EnvironmentCamera.

Any hint on how this scenario is supposed to work?

well… the preview is the render of a scene right?
Think of the probe as a light. A classic scene even in a preview would have some lights, right? Here you’ll have a light probe.
So set up your scene with a nice HDR skybox, then place the env camera in the center and generate a probe. then add your model into it.
also, you can save the probe in a j3o. And all texture data needed by the probe will be also saved. So basically you can then just load the probe without having to use the Env cam every time.

Thanks! I was aware of this - I just wasn’t aware that the scene(rootnode) for the 6 viewports is provided by the LightProbeFactory.makeProbe… So it will work.

Nevertheless, is there a way to manually use the EnvironmentCamera without attaching it as an appstate? The reason behind this, is that the offscreen rendering is only part of one dialog in the UI and I would like to avoid to have a dependecy to the application object to set it up…

Well, no it’s an appstate.
But don’t you have a probe in your main scene?
Because you could reuse it, can’t you?

I just had a similar idea: I don’t reuse the lightprobe (because I might have different sky in the main scene), but I reuse the EnvironmentCamera. And its working like a charm! Thanks a lot!!!

1 Like

My example in:

https://bitbucket.org/JavaSabr/jme3-spaceshift-editor/src/504a29815f16c728743b8cca060e913660c850fc/src/com/ss/editor/state/editor/impl/model/ModelEditorState.java?at=master&fileviewer=file-view-default

public void updateLightProbe() {
        EXECUTOR_MANAGER.addEditorThreadTask(() -> {

            final Node stateNode = getStateNode();
            stateNode.detachChild(getModelNode());
            stateNode.detachChild(getToolNode());
            stateNode.detachChild(getLightNode());

            frame = 0;
        });
    }

 @Override
    public void update(float tpf) {
        super.update(tpf);

        if (frame == 2) {

            final Node customSkyNode = getCustomSkyNode();

            final Array<Spatial> customSky = getCustomSky();
            customSky.forEach(spatial -> customSkyNode.attachChild(spatial.clone(false)));

            EDITOR.updateProbe(probeHandler);
        }
}
1 Like