[vtkusers] Adding two lightsources to a renderer

Oliver Natt onatt at gmx.de
Wed Sep 6 14:17:23 EDT 2017


Dear vtkusers,

I encountered a weird problem when using more than one positional light 
source in vtk. I am pretty sure that it worked with vtk 7.1 but it 
stopped working with vtk 8.0.0 and 8.0.1. An example in python is given 
below. The scene contains a plane which should be illuminated by two 
spot lights. However, only one spotlight is rendered. It seems that this 
is always the first spotlight that is added to the renderer. Is there 
any workaround for this problem?

Many thanks
Oliver


import vtk

# create a rendering window and renderer renderer = vtk.vtkRenderer()
render_window = vtk.vtkRenderWindow()
render_window.AddRenderer(renderer)

# create a renderwindowinteractor iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(render_window)

# create a plane and add it to the renderer rectangle_source = vtk.vtkPlaneSource()
rectangle_source.SetOrigin(-5.0,0.0,5.0)
rectangle_source.SetPoint1(5.0,0.0,5.0)
rectangle_source.SetPoint2(-5.0,0.0, -5.0)
rectangle_source.SetResolution(100,100)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(rectangle_source.GetOutputPort())
actor = vtk.vtkActor()
actor.SetMapper(mapper)
renderer.AddActor(actor)

# set camera view renderer.ResetCamera()
camera = renderer.GetActiveCamera()
camera.Azimuth(40.0)
camera.Elevation(30.0)

# create a green light light_green = vtk.vtkLight()
light_green.SetPositional(1)
light_green.SetPosition(-4.0,4.0, -1.0)
light_green.SetColor(0.0,1.0,0.0)
light_green.SetIntensity(0.5)

# create a pink ligh light_pink = vtk.vtkLight()
light_pink.SetPositional(1)
light_pink.SetPosition(4.0,5.0,1.0)
light_pink.SetColor(1.0,0.0,1.0)
light_pink.SetIntensity(0.6)

# add lights to the renderer # # This is interesting in vtk 8.0.0 and 
8.0.1: # Only the pink light spot is visible. If the two statements are 
swapped, # only the green light is visible. It seems that always only 
the first # light can be active. renderer.AddLight(light_pink)
renderer.AddLight(light_green)

# define a background for better visibility renderer.SetBackground(0.2,0.2,0.5)
renderer.SetBackground2(0.4,0.4,1.0)
renderer.SetGradientBackground(True)

# enable interactor iren.Initialize()
render_window.Render()
iren.Start()

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170906/636057e7/attachment.html>


More information about the vtkusers mailing list