An attempt to make day/night cycles in TMW
Posted: 24 Jan 2010, 23:29
Hi,
Today we had a talk with BlueSoul and some other people about how to implement a day and night cycle. Not the cycles scheduling system, the graphical effect.
One idea that came out is to use dark blue layer and blend it with the actual graphics in a special way.
The advantage of this system is that you dont have to modify the external graphics for the night cycle, and it allows transitional effects (night -> dawn -> day).
The main disadvantage is an additional graphics processing.
For testing purposes, here is a patch that implements this idea.
To install :
I noticed a little drop of fps with my configuration, but it is still nicely playable. I'd like to hear about you.
The patch applies the night effect all the time, and it also affects the GUI (more on this below).
What it does and how :
* For now, it is implemented for the software rendering, not OpenGL.
* The effect is performed on each screen update just before the SDL_Flip() call.
* It affects the SDL_Surface that represents the whole screen, so both the GUI and the world. I am sure their is an intermediate step where the GUI is not yet in this surface, or there is a separate SDL_Surface for it before a blit on the global SDL_Surface.
* A separate function performs an Overlay blending of a dark blue color on each pixel of the original SDL_Surface.
If you think this implementation is relevant for a day/night effect, what remains to do is :
* Retrieve the server time, for example every hour, and make a float in [0,1] to pass to the function that realizes the effect. That would update the rendering and make a smooth transition between day and full night.
* I think it's still acceptable to perform the effect on the GUI if there is no other choice, but it would be better to apply it only on the world.
* Optimize the rendering and implement it for the opengl rendering too.
Regards
Today we had a talk with BlueSoul and some other people about how to implement a day and night cycle. Not the cycles scheduling system, the graphical effect.
One idea that came out is to use dark blue layer and blend it with the actual graphics in a special way.
The advantage of this system is that you dont have to modify the external graphics for the night cycle, and it allows transitional effects (night -> dawn -> day).
The main disadvantage is an additional graphics processing.
For testing purposes, here is a patch that implements this idea.
To install :
Code: Select all
git clone git://gitorious.org/tmw/mainline.git tmw
cd tmw
git am path/to/the/patch
autoreconf -i
./configure
make
./src/tmw
The patch applies the night effect all the time, and it also affects the GUI (more on this below).
What it does and how :
* For now, it is implemented for the software rendering, not OpenGL.
* The effect is performed on each screen update just before the SDL_Flip() call.
* It affects the SDL_Surface that represents the whole screen, so both the GUI and the world. I am sure their is an intermediate step where the GUI is not yet in this surface, or there is a separate SDL_Surface for it before a blit on the global SDL_Surface.
* A separate function performs an Overlay blending of a dark blue color on each pixel of the original SDL_Surface.
If you think this implementation is relevant for a day/night effect, what remains to do is :
* Retrieve the server time, for example every hour, and make a float in [0,1] to pass to the function that realizes the effect. That would update the rendering and make a smooth transition between day and full night.
* I think it's still acceptable to perform the effect on the GUI if there is no other choice, but it would be better to apply it only on the world.
* Optimize the rendering and implement it for the opengl rendering too.
Regards