# How to place a light source on the central body from camera position

**URL:** <https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498>\
**Category:** CesiumJS\
**Created:** [December 24, 2015, 7:50am UTC](https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498 "2015-12-24T07:50:51Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Svetoslav\_Batsoev](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@Svetoslav\_Batsoev](https://community.cesium.com/u/Svetoslav_Batsoev)\
**Post date:** [December 24, 2015, 7:50am UTC](https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498/1 "2015-12-24T07:50:51Z")

</div>

Hello,  
Is there an easy way to put a light source (I think what I need is a point light) on the central body (the planet) which is located at the position of the camera. I tried terrainprovider but it uses only sun as a light source (I think?) and the planet is always lightened from one side and shaded from the other. I read about ellipsoidappearance, vertex and fragment shaders, and Centralbody.enablelighting (is that deprecated in latest versions?) but I’m not very familiar and I don’t know what’s the right way to do this. Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![Svetoslav\_Batsoev](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@Svetoslav\_Batsoev](https://community.cesium.com/u/Svetoslav_Batsoev)\
**Post date:** [December 24, 2015, 11:12pm UTC](https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498/2 "2015-12-24T23:12:02Z")

</div>

I just need slight shadows at the edges of the planet, independently of the viewing angle.

---

<div class="post-metadata">

**Author:** ![Svetoslav\_Batsoev](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@Svetoslav\_Batsoev](https://community.cesium.com/u/Svetoslav_Batsoev)\
**Post date:** [December 28, 2015, 5:56am UTC](https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498/3 "2015-12-28T05:56:50Z")

</div>

[![](https://lh3.googleusercontent.com/-bT8mmIa8Qp0/VoDKcNhU04I/AAAAAAAABpI/qhFpkqWKSeE/s320/CesiumLightSource.png)](https://lh3.googleusercontent.com/-bT8mmIa8Qp0/VoDKcNhU04I/AAAAAAAABpI/qhFpkqWKSeE/s1600/CesiumLightSource.png)

I’m willing to pay to whoever helps me achieve this. This is the lighting that I want (see the pic). The planet should always be lit this way, regardlessly of how it’s rotated. If you’re interested, write either here or on my email svetoslav80 at gmail соm

---

<div class="post-metadata">

**Author:** ![karthikkini](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@karthikkini](https://community.cesium.com/u/karthikkini)\
**Post date:** [August 15, 2016, 7:27pm UTC](https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498/4 "2016-08-15T19:27:01Z")

</div>

Hey Svetoslav, I have similar lighting requirement, though slightly different angle. Did you solve this? Anything you care share here?

---

<div class="post-metadata">

**Author:** ![Svetoslav\_Batsoev](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@Svetoslav\_Batsoev](https://community.cesium.com/u/Svetoslav_Batsoev)\
**Post date:** [September 21, 2016, 8:28pm UTC](https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498/5 "2016-09-21T20:28:24Z")

</div>

Nope, I was trying to manipulate the time of the day so that the position of the sun changes, using the code:

var date = new Date();  
date.setUTCFullYear(2011, 6, 4); // July 4, 2011 @ 12:00 UTC  
date.setUTCHours(3, 0, 0, 0);  
viewer.scene.globe.enableLighting = true;  
viewer.clock.currentTime = JulianDate.fromDate(date);  
viewer.clock.multiplier = 1;  
viewer.clock.shouldAnimate = true;

But whatever hour of the day I set, it seems the position of the sun is the same, or at least the shadow on the body doesn’t move … I have no idea why.

---

<div class="post-metadata">

**Author:** ![Svetoslav\_Batsoev](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@Svetoslav\_Batsoev](https://community.cesium.com/u/Svetoslav_Batsoev)\
**Post date:** [September 21, 2016, 8:53pm UTC](https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498/6 "2016-09-21T20:53:13Z")

</div>

Ah, it worked as I turned viewer animation on, but it’s not what I need because sun motion is limited.

---

<div class="post-metadata">

**Author:** ![Svetoslav\_Batsoev](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@Svetoslav\_Batsoev](https://community.cesium.com/u/Svetoslav_Batsoev)\
**Post date:** [September 22, 2016, 4:30pm UTC](https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498/7 "2016-09-22T16:30:33Z")

</div>

I’m excited to see this has been implemented in recent versions, here’s an example in sandcastle: [http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Shadows.html](http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Shadows.html) , I’m going to look into the code

---

<div class="post-metadata">

**Author:** ![sean\_lilley](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sean_lilley/32/2083_2.png) [@sean\_lilley](https://community.cesium.com/u/sean_lilley)\
**Post date:** [September 23, 2016, 12:30am UTC](https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498/8 "2016-09-23T00:30:50Z")

</div>

I’m not sure about an official way to do this, but if you are ok with a hacky solution and don’t mind editing the source code, this should work:

After this line: [https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Renderer/UniformState.js#L846](https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Renderer/UniformState.js#L846) put the code:

Cartesian3.clone(frameState.camera.directionWC, uniformState.\_sunDirectionWC);

Cartesian3.clone(Cartesian3.UNIT\_Z, uniformState.\_sunDirectionEC);

A sample Sandcastle demo for seeing the results:

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({

url : ‘[https://assets.agi.com/stk-terrain/world](https://assets.agi.com/stk-terrain/world)’,

requestWaterMask : true,

requestVertexNormals : true

});

viewer.terrainProvider = cesiumTerrainProviderMeshes;

viewer.scene.globe.enableLighting = true;

 ![lighting.JPG](https://global.discourse-cdn.com/cesium/original/2X/2/2f9a0d27052306a637e49477c5d935544327c746.jpeg)

---

<div class="post-metadata">

**Author:** ![Svetoslav\_Batsoev](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@Svetoslav\_Batsoev](https://community.cesium.com/u/Svetoslav_Batsoev)\
**Post date:** [September 24, 2016, 5:49pm UTC](https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498/9 "2016-09-24T17:49:30Z")

</div>

Sean Lilley Thank you so much. This works. requestWaterMask : true seems to spoils the colors but I removed it and now I have a real 3d planet. Thank you again.

---

<div class="post-metadata">

**Author:** ![Svetoslav\_Batsoev](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@Svetoslav\_Batsoev](https://community.cesium.com/u/Svetoslav_Batsoev)\
**Post date:** [October 5, 2016, 12:36pm UTC](https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498/10 "2016-10-05T12:36:12Z")

</div>

Sean, is there a quick way to apply a similar hack for EllipsoidTerrainProvider instead of STK world terrain, as the last seems to jag the terrain at one particular area on the globe?

---

<div class="post-metadata">

**Author:** ![sean\_lilley](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/sean_lilley/32/2083_2.png) [@sean\_lilley](https://community.cesium.com/u/sean_lilley)\
**Post date:** [October 10, 2016, 2:19pm UTC](https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498/11 "2016-10-10T14:19:19Z")

</div>

Yeah, it’s possible to add specular to the base but without the water mask. In GlobeFS.glsl place code like this after line 175 (tweak to your liking). You will need to run “npm run build” after editing the shader:

```
// Add specular highlights
vec3 positionToEyeEC = -v_positionEC;
float positionToEyeECLength = length(positionToEyeEC);
// The double normalize below works around a bug in Firefox on Android devices.
vec3 normalizedpositionToEyeEC = normalize(normalize(positionToEyeEC));
float specularIntensity = czm_getSpecular(czm_sunDirectionEC, normalizedpositionToEyeEC, normalEC, 4.0);
float surfaceReflectance = 0.5;
float specular = specularIntensity * surfaceReflectance;
finalColor += specular;

```

``

The new Sandcastle is just:

var viewer = new Cesium.Viewer(‘cesiumContainer’);

viewer.scene.globe.enableLighting = true;

``

---

<div class="post-metadata">

**Author:** ![Tim\_Hull](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@Tim\_Hull](https://community.cesium.com/u/Tim_Hull)\
**Post date:** [October 30, 2016, 5:11am UTC](https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498/12 "2016-10-30T05:11:36Z")

</div>

I wanted to position the sun/light at the camera too. Have you come across a way to do this without having to edit and compile the source ?

---

<div class="post-metadata">

**Author:** ![Svetoslav\_Batsoev](https://avatars.discourse-cdn.com/v4/letter/s/2acd7d/32.png) [@Svetoslav\_Batsoev](https://community.cesium.com/u/Svetoslav_Batsoev)\
**Post date:** [October 31, 2016, 8:44am UTC](https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498/13 "2016-10-31T08:44:35Z")

</div>

One of the main Cesium developers doesn’t know an official way to do this. No chance that I know something more than him. But it’s really easy to edit / compile the source. Is there a particular reason you don’t want to do this?

---

<div class="post-metadata">

**Author:** ![Tim\_Hull](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@Tim\_Hull](https://community.cesium.com/u/Tim_Hull)\
**Post date:** [November 1, 2016, 3:16am UTC](https://community.cesium.com/t/how-to-place-a-light-source-on-the-central-body-from-camera-position/3498/14 "2016-11-01T03:16:54Z")

</div>

I fear botching it up since I’m not a coder by profession. 🙂
