Lighting update on camera position reset

Hi all.

In my Java-based, VTK-based application, I am working on the implementation of volume rendering functionalities. I am working with the latest VTK 8.2.

All is working pretty well at the moment: I can generate and view my volume correctly, and I can interact with the volume and with the view in a satisfactory way through the standard interactor of my vtkCanvas-derived GUI panel.

I have implemented a “reset view” function in my application, which resets the “default” camera view through a code looking like this:


    vtkRenderer existingCanvasRenderer = GetRenderer();
    vtkCamera activeCamera = existingCanvasRenderer.GetActiveCamera();
    double[] volCenter = volume.GetCenter();
    activeCamera.SetFocalPoint (volCenter[0], volCenter[1], volCenter[2]);
    activeCamera.SetPosition (volCenter[0], volCenter[1] - 850, volCenter[2]);
    activeCamera.SetViewUp (0, 0, 1);



However, “sometimes”, immediately after this view reset my scene appears a bit too dark, or at least with an incorrect lighting.
Then, the first time I interact again with the view through the mouse, for instance by dragging the scene and thus applying the slightest rotation to the camera, lighting is restored to normal state.

Here is how the view appeared in a specific case after view reset:

And here is how it is restored to normal lighting after the slightest mouse interaction with the view:

You can notice a significant difference between the 2 renderings, with the second being the “correct” one.

Should I make some additional calls in my “view reset” code in order to force an update of the lighting of my scene, following to reset of my camera position and orientation? Can you suggest why lighting doesn’t seem correct immediately after my “view reset” operation, at least in some cases?

Thanks in advance for your comments.

Best regards,

Marco Sambin

Hi all.
I reply to myself regarding the lighting issue outlined in my previous post.
Basically, I do not add any vtkLight explicitly to my scene, so upon first Render() VTK adds a default light for me. This is a “Scene” light. According to the documentation, a “Scene” light shall NOT move with the camera.

But actually, when I move the camera through the Interactor, dragging the scene with my mouse, it looks like the Scene light is indeed automatically moved by the Interactor itself. Is this expected? This behavior does not seem to match what the documentation says about “Scene” lights.

This “automatic move” of the Scene light, on the other side, does not happen if I programmatically move, elevate, azimuth, … my camera. Hence, in order to obtain the same update of the lighting as when I manually drag my scene, I have to programmatically and explicitly update the position and focal point of my Scene light to match the position and focal point of my camera.

Best regards,

Marco Sambin

Please add a vtkLightActor to follow your automatically added scenelight. Is this Actor also moving when moving the camera via Interactor? What about your vtkRenderer::LightFollowCamera flag?

Hello Peter,

thanks for your reply.

I have set “LightFollowCameraOff()” on both my renderer and my interator, but while I interact with the scene through mouse dragging (i.e., through the interactor) my Scenelight continues following the camera.

Please notice that this is indeed the behavior that I desire in my application, but I would not expect it to happen considering that I have a Scenelight.

Is there something I am missing?
Thanks and best regards,


vtkRenderWindowInteractor has a LightFollowCamera property, too. Probably you need to disable that.

Ahaaaa! I think I got it.

As I told in my original post, I am working in Java.
In particular, I am using a vtkCanvas-derived panel to paint my 3D scene.

It looks like vtkCanvas’s mouseDragged() Java method has an unconditional call to vtkPanel’s “UpdateLight()” method, which in turn unconditionally sets the position and focal point of the light to match the position and focal point of the active camera!

That’s the reason why this “automation” only works when dragging the mouse, but not when programmatically changing the position of my camera!!

To me, this implementation is too simplistic, and is not coherent with VTK native library’s implementation.
Any comment would be welcome.


Marco Sambin

1 Like

Thanks for sharing