The position of the camera has to be relative to the planet. The camera distance will be the length of the camera position vector:

```
objpos = obj.worldPosition
camerapos = camera.worldPosition - objpos
lightpos = lamp.worldPosition
m_fOuterRadius = 10.25
m_fInnerRadius = 10.00
cameraDistance = camerapos.length
#xOffset = objpos[0] - camerapos[0]
#yOffset = objpos[1] - camerapos[1]
#zOffset = objpos[2] - camerapos[2]
#dSquared = xOffset**2 + yOffset**2 + zOffset**2
#cameraDistance = math.sqrt(dSquared)
#cameraDistanceSq = dSquared
```

Now you need to consider how do you want the sunlight to work. Currently, the shader uses the lamp’s world position as light vector. If you want the light direction to change when you move the planet, you need to make the light position relative to the planet too:

```
lightpos = lightpos - objpos
lightDistance = lightpos.length
#xOffset1 = objpos[0] - lightpos[0]
#yOffset1 = objpos[1] - lightpos[1]
#zOffset1 = objpos[2] - lightpos[2]
#dSquared1 = xOffset1**2 + yOffset1**2 + zOffset1**2
#lightDistance = math.sqrt(dSquared1)
```

Or, if you want to use the lamp’s orientation as light vector:

```
lightpos = lamp.getAxisVect([0.0, 0.0, 1.0])
lightDistance = 1.0 # lightpos is already a normalized vector
#xOffset1 = objpos[0] - lightpos[0]
#yOffset1 = objpos[1] - lightpos[1]
#zOffset1 = objpos[2] - lightpos[2]
#dSquared1 = xOffset1**2 + yOffset1**2 + zOffset1**2
#lightDistance = math.sqrt(dSquared1)
```