# vtk lighting problem when source inside an object

**URL:** https://discourse.vtk.org/t/vtk-lighting-problem-when-source-inside-an-object/4329
**Category:** Support
**Created:** [October 1, 2020, 9:26am UTC](https://discourse.vtk.org/t/vtk-lighting-problem-when-source-inside-an-object/4329 "2020-10-01T09:26:29Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![archimedes](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@archimedes](https://discourse.vtk.org/u/archimedes)
#### Post date: [October 1, 2020, 9:26am UTC](https://discourse.vtk.org/t/vtk-lighting-problem-when-source-inside-an-object/4329/1 "2020-10-01T09:26:29Z")

</div>

On my Pythgon38 Windows10 platform, I am rejigging my solarsystem simulator from OpenGL to VTK. To illuminate the scene from the origin, I have placed a pair of 180deg coned spotlights back to back. With the help of comments in [lorensen.github.io/VTKExamples/site/Cxx/Lighting/Light/](http://lorensen.github.io/VTKExamples/site/Cxx/Lighting/Light/)  
the lighting seems correct, but the Sun sphere (also at the origin) has become a black hole, and re-rendering it has no effect. Can anyone enlighten me? Here is the code stripped of animation and other stuff to exhibit my problem  
:#!/usr/bin/env python  
from random import randint  
from math import sqrt, pi, sin, cos  
import vtk

colors = vtk.vtkNamedColors() # print(colors)  
k = pi / 180 # degrees to radians  
ScaleAU = 100 # so 1 AU 100pixels from center, 6 aus is ±600 pixels  
ScaleRad = 15 # so 1 earth rad is 15 pixels

class Object:  
def **init** (self, radius, orbit, color,theta = 0):  
self.radius = radius \* ScaleRad  
sphere = vtk.vtkSphereSource() # Create a sphere (from Sphere.py)  
sphere.SetRadius(self.radius)  
mapper = vtk.vtkPolyDataMapper()  
mapper.SetInputConnection(sphere.GetOutputPort())  
actor = vtk.vtkActor()  
actor.SetMapper(mapper) # actor is sphere  
actor.GetProperty().SetColor(colors.GetColor3d(color))  
self.orbit = orbit \* ScaleAU  
actor.SetPosition(self.orbit \* cos(theta), 0, self.orbit \* sin(theta))  
self.actor = actor

def main():  
ren = vtk.vtkRenderer()  
ren.SetBackground(colors.GetColor3d(“black”))  
renWin = vtk.vtkRenderWindow()  
renWin.SetWindowName(‘My Solar Sim’) # doesnt happen  
renWin.AddRenderer(ren)  
renWin.SetSize(1200, 750)  
intren = vtk.vtkRenderWindowInteractor()  
intren.SetRenderWindow(renWin)

```
Planet = []
Planet.append(Object(2.5,0.,"yellow")) # the Sun
Planet.append(Object(.7,.7,"silver", 0)) # Venus
Planet.append(Object(1.,1.,"blue", 180)) # Earth

camera = vtk.vtkCamera()
camera.SetPosition(0.0, 0.0, 500.) # stand well back!
camera.SetFocalPoint(0.0, 0.0, 30.)
camera.SetClippingRange(10., 600.)
camera.SetViewUp(0, 1, 0)
ren.SetActiveCamera(camera)      

for planet in Planet[0:]:
    ren.AddActor(planet.actor)
 
Lspot = vtk.vtkLight() # from lorensen.github.io/VTKExamples/site/Cxx/Lighting/Light/
Lspot.SetColor(1.,1.,1.)
Lspot.SetPosition(0., 0., 0.)
Lspot.SetPositional(True) 
Lspot.SetFocalPoint(-10., 0., 0.)
Lspot.SetConeAngle(180.)
Lspot.SetLightTypeToSceneLight() # what might this do?      
Rspot = vtk.vtkLight()
Rspot.SetColor(1.,1.,1.)
Rspot.SetPosition(0., 0., 0.)
Rspot.SetPositional(True)
Rspot.SetFocalPoint( 10., 0., 0.)
Rspot.SetConeAngle(180.)
Rspot.SetLightTypeToSceneLight()         
ren.AddLight(Lspot) # as in lorensen.github.io/VTKExamples/site/Cxx/Lighting/Light/
ren.AddLight(Rspot) # 2 spots but band dividing sun light an dark hemispheres

# lighting is correct but sun is dark so add it again here  
ren.AddActor(Planet[0].actor) # - still dark 

renWin.Render() # Reset the camera to view all actors added to scene 
intren.Initialize() # Render the image of positioned actors onto the scene
renWin.Render()
intren.Start() # start the event loop

```

if **name** == ‘ **main** ’:  
main()

---

<div class="post-metadata">

### Author: ![Aron\_Helser](https://discourse.vtk.org/user_avatar/discourse.vtk.org/aron_helser/32/14_2.png) [@Aron\_Helser](https://discourse.vtk.org/u/Aron_Helser)
#### Post date: [October 3, 2020, 12:15am UTC](https://discourse.vtk.org/t/vtk-lighting-problem-when-source-inside-an-object/4329/2 "2020-10-03T00:15:31Z")

</div>

I believe you are having a problem with normals - the normals for a sphere point out, and the renderer therefore treats the surface as facing away from the light. You might try negating all the normals on the sun sphere, or using ambient lighting for the sun.

HTH,  
Aron

---

<div class="post-metadata">

### Author: ![archimedes](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@archimedes](https://discourse.vtk.org/u/archimedes)
#### Post date: [October 3, 2020, 9:35am UTC](https://discourse.vtk.org/t/vtk-lighting-problem-when-source-inside-an-object/4329/3 "2020-10-03T09:35:34Z")

</div>

Thanks. Giving the object .SetAmbient(1.) fixes it.

---

<div class="post-metadata">

### Author: ![archimedes](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@archimedes](https://discourse.vtk.org/u/archimedes)
#### Post date: [October 6, 2020, 5:49pm UTC](https://discourse.vtk.org/t/vtk-lighting-problem-when-source-inside-an-object/4329/4 "2020-10-06T17:49:00Z")

</div>

thanks for your helpful suggestion, ambient lighting fixed my problem.  
Nick
