Set Lighting according to Time of the day

Started by
4 comments, last by Vilem Otte 6 years, 8 months ago

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

Advertisement

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.

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?

http://www.psa.es/sdg/sunpos.htm

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.

23 hours ago, MJP said:

http://www.psa.es/sdg/sunpos.htm

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/ 

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

This topic is closed to new replies.

Advertisement