Jump to content
  • Advertisement
Sign in to follow this  
Alessandro Pozzer

DX11 Set Lighting according to Time of the day

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 this post


Link to post
Share on other sites
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.

Edited by Styves

Share this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!