Advertisement Jump to content
Sign in to follow this  

Day and Night Effects

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi All, I want to know how to create Day and Night Effects in DirectX.Right now I am using only device.RenderState.Ambient light to give the day and night effects by varying the RGB values.Is there any better way to create day and night effects.I really want the solution for this.plz can anyone help on this. thanks and regards.

Share this post

Link to post
Share on other sites
Having a dynamic sky would help a lot, I think (at least it has in my apps). This way, you can be on any day-night cycle that you want. However, if you don't need to change between the two in the same scene, I suppose just a correctly-colored sky-box or -dome would be appropriate.

If you are doing any type of global illumination, you can vary the parameters to that, as well. This can be as simple as a single directional light representing the sun/moon, to environment mapping, to PRT.

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
I had to do this for an assignment once.

I made a struct like this-

typedef struct
colour sky;
colour ambient;
colour sun;
float sun_angle;

Then I made an array of these environment structures, and blended between two of them at once.


int current_env = 1;
int next_env = 2;

float current_time = 12;
float env_change_end = 30;
float env_change_start = 0;

float fr1 = (current_time-env_change_start)/(env_change_end-env_change_start);
float fr2 = 1-fr1;

colour sky = my_environments[current_env]*fr1 + environments[next_env]*fr2;

Then before rendering the frame, i clear the background to the 'sky' colour and set the ambient light to the 'ambient' colour. I also create a directional light with the 'sun' colour, and set its rotation around the x-axis to the 'sun_angle'.

This way you can just create an array of environments, and it will fade between them for you.

Theres some things i skipped over, like creating the array, timing, changing the current and next enviornment, but hopefully you can figgure that stuff out ;)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!