# DX11 Set Lighting according to Time of the day

This topic is 493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am creating a simple Graphics Engine and I want to let the user set the time of the day for the scene, but I have problems translating it into the lighting direction.

The light direction is now given by a vector of three float.

i.e. The user set time = 12 (noon). I want the light direction to be right on the top of the scene.

Is there a way to achieve that?

Thank you

##### Share on other sites

You can use longitude/latitude to describe the trajectory of the sun, and use the time to determine which point along the latitude that the sun is currently at. Longitude will control which direction the sun is actually coming from (east, north, west, south, etc). Latitude controls the height of the sun.

That would look something like this:

x = cos(long) * sin(lat);
y = sin(long) * sin(lat);
z = cos(lat);

If you want to simplify it, you can always assume a longitude of 0 and only focus on the latitude, which will only control the height of the sun.

Edited by Styves

##### Share on other sites
10 minutes ago, Styves said:

You can use longitude/latitude to describe the trajectory of the sun, and use the time to determine which point along the latitude that the sun is currently at. Longitude will control which direction the sun is actually coming from (east, north, west, south, etc). Latitude controls the height of the sun.

That would look something like this:


x = cos(long) * sin(lat);
y = sin(long) * sin(lat);
z = cos(lat);

If you want to simplify it, you can always assume a longitude of 0 and only focus on the latitude, which will only control the height of the sun.

Thank you for your reply! and how could I calculate longitude and latitude?

##### Share on other sites
23 hours ago, MJP said:

The function will take your time of day as well as location on earth (specified as a latitude/longitude coordinate pair), and give you the direction of the sun in spherical coordinates.

Or if you want to go more precise - https://midcdmz.nrel.gov/spa/

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 11
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633722
• Total Posts
3013540
×