Jump to content
  • Advertisement
Sign in to follow this  
DirectXGuru

Day and Night Effects

This topic is 4339 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
Advertisement
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;
}environment;


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

eg.

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 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!