Problem with ambient and specular color in vtkLight using vtk 8.2.0

Hi all,

I recently migrated from VTK 6.3 to 8.2. I use two lights on the scene, and I have a small UI option to change the value of the components of the light. For this purpose, I use SetXXXColor() method. It’s strange because since the migration, diffuse component still works, but ambient and specular seems to not be working properly (at all). Any ideas why can this be happening?

Regards,
Santiago.

Hello, Santiago,

When ambient and specular response are not working it means you have a problem in the light source and/or the material defined for the irresponsive object. Ambient (a.k.a. environment) color is normally defined in “world properties” as an omnidirectional/omnipresent/isotropic light (not as an individual light source). In VTK, “the world” is normally represented by the vtkRenderer class, so you set ambient color with renderer->SetAmbient(0.5, 0.5, 0.5). If this is right in your code, then you have to check the “material” of your actor, via the attached vtkProperty object. The same rationale applies to specular and other lighting effects.

You can see this example on how to setup the visual properties for the actors: https://www.paraview.org/Wiki/VTK/Examples/Cxx/Rendering/DiffuseSpheres

kind regards,

Paulo

Hi Paulo,

Thanks for your answer. Let me be clear here: you mention that I need to check the “material” of my actor, that’s ok. But what it’s failing here is the RGB values of the light itself. Suppose the next equation to calculate the specular component of light:

image

I need the RGB of the surface, the specular intensity or factor of the material, and the shininess factor. All these three can be set using the property. But what about the RGB of the light? I used to set that by using vtkLight::setSpecularColor. This works fine in 6.3, whereas in 8.2 stopped working. That was my initial question, can this be a bug?

Regards,
Santiago.

G’day, Santiago,

Setting the specular property of the light source alone does not guarantee (at least is not supposed to) all objects in the scene will give off a specular effect. You have to set specular properties in the “material” of the objects as well. Check the actors’ vtkProperty, via their getProperty() method. This setting is in the example I posted above.

If you were getting specular effect by configuring it in the light alone, then it was a “bug” in VTK 6.3 which later versions corrected to the expected behavior.

all the best,

Paulo

Hi Paulo,
CMakeLists-gl1.txt (969 Bytes) CMakeLists-gl2.txt (971 Bytes) DiffuseSpheres.cxx (2.6 KB)
Many thanks for your interest and your help. In order to explain myself better, I made an example to show the behavior of what I am facing and what I expect. I used the spheres tutorial and modify it a bit to fit my purposes.
On the example, I have only one sphere in the origin (0, 0, 0) and two lights, one blue on the right (1, 0, 0) and the other, red on the left (-1, 0, 0). The sphere’s actor property has only set the specular power § and the specular coefficient (M) on the above equation. Then, I set the light color and specular color. In the red light, I set the specular component to (0.5, 0, 0) whereas in the blue light to (0, 0, 1).

In one case, I use VTK 6.3 with OpenGL backend and I obtain this result:

image

You can see that the red dot produced by the specular effect is a bit smaller than the blue one.

Then, I use the same VTK version but with OpenGL2 as backend:

image

The red dot produced by both lights is the same size. vtkLight::SetSpecularColor is completely ignored.

You mentioned that this can be a bug of 6.3 version, but in my opinion, it’s more related to OpenGL backend. Do you have any idea of what can be happening? If so, how can I reproduce the same results I get using OpenGL as backend, but using OpenGL2 instead? Attached is the source file with the corresponding CMake files.

Regards,
Santiago.

OpenGL2 is quite old (from 2003, I think), maybe it has issues solved in OpenGL 3/4. OpenGL2 also introduced the shader API. Maybe there is something miscoded in the default shaders used by VTK’s back end. Or perhaps the lighting model was changed in OpenGL 2. I’d take your question to the VTK developer forum (citing this issue here in the support forum) or even to an OpenGL forum.

Thanks Paulo, I’ll create a post on the development forum.

Regards,
Santiago.