Hello,
I’m currently working on a project, and I’m facing some issues with lighting. I have started with this minimalist program and work on it:
import vtk
sphere_1 = vtk.vtkSphereSource()
sphere_1.SetCenter(25, 0, 0)
sphere_1.SetRadius(10)
sphere_1.SetThetaResolution(120)
sphere_1.SetPhiResolution(120)
mapper_1 = vtk.vtkPolyDataMapper()
mapper_1.SetInputConnection(sphere_1.GetOutputPort())
actor_1 = vtk.vtkActor()
actor_1.SetMapper(mapper_1)
sphere_2 = vtk.vtkSphereSource()
sphere_2.SetCenter(0, 0, 0)
sphere_2.SetRadius(10)
sphere_2.SetThetaResolution(120)
sphere_2.SetPhiResolution(120)
mapper_2 = vtk.vtkPolyDataMapper()
mapper_2.SetInputConnection(sphere_2.GetOutputPort())
actor_2 = vtk.vtkActor()
actor_2.SetMapper(mapper_2)
sphere_3 = vtk.vtkSphereSource()
sphere_3.SetCenter(-25, 0, 0)
sphere_3.SetRadius(10)
sphere_3.SetThetaResolution(120)
sphere_3.SetPhiResolution(120)
mapper_3 = vtk.vtkPolyDataMapper()
mapper_3.SetInputConnection(sphere_3.GetOutputPort())
actor_3 = vtk.vtkActor()
actor_3.SetMapper(mapper_3)
actor_3.GetProperty().SetOpacity(0)
light = vtk.vtkLight()
light.SetPosition(-25, 0, 0)
light.SetConeAngle(180)
renderer = vtk.vtkRenderer()
renderer.AddActor(actor_1)
renderer.AddActor(actor_2)
renderer.AddActor(actor_3)
renderer.AddLight(light)
render_window = vtk.vtkRenderWindow()
render_window.AddRenderer(renderer)
shadows = vtk.vtkShadowMapPass()
seq = vtk.vtkSequencePass()
passes = vtk.vtkRenderPassCollection()
passes.AddItem(shadows.GetShadowMapBakerPass())
passes.AddItem(shadows)
seq.SetPasses(passes)
cameraP = vtk.vtkCameraPass()
cameraP.SetDelegatePass(seq)
glrenderer = renderer
glrenderer.SetPass(cameraP)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(render_window)
iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
iren.Initialize()
iren.Start()
My intention is to have three spheres, with a light at the center of sphere_1
, so that sphere_1
acts analogous to the sun, the half of sphere_2
facing sphere_1
lit, while the other half is dark, and sphere_3
completely dark, being eclipsed by sphere_2
.
sphere_2
and sphere_1
render the way I want, but I expected sphere_1
to be lit as well.
From what I understand, the problem is because of making it transparent, using actor_3.GetProperty().SetOpacity(0)
. Is there a workaround?