Page 1 of 2

An attempt to make day/night cycles in TMW

Posted: 24 Jan 2010, 23:29
by v0id
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
0001-Nightfall-system.patch.zip
patch for git.
(1.99 KiB) Downloaded 104 times
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
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).
Night (amount = 1.0)
Night (amount = 1.0)
night.jpg (169.02 KiB) Viewed 4800 times
Dawn (amount = 0.5)
Dawn (amount = 0.5)
nightfall_or_dawn.jpg (171.82 KiB) Viewed 4801 times
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

Re: An attempt to make day/night cycles in TMW

Posted: 25 Jan 2010, 00:13
by baseballboy
Interesting

Re: An attempt to make day/night cycles in TMW

Posted: 25 Jan 2010, 06:46
by Rotonen
It shouldn't dim the light effects like the soul menhir effect.

Re: An attempt to make day/night cycles in TMW

Posted: 25 Jan 2010, 12:01
by Crush
Is there a reason why you don't use the existing overlay system (the engine which draws the clouds, for example) for this? That way you wouldn't also affect the gui. As Rotonen pointed out it would be better when it would be possible to exclude some graphics like certain particle effects from the effect. The only feasible method I could think of would be to reclor tiles and sprites themself before drawing with them.

Re: An attempt to make day/night cycles in TMW

Posted: 25 Jan 2010, 13:22
by v0id
Is there a reason why you don't use the existing overlay system
Thanks to point that out. That's my will to use something like that. In fact, I ve just explored the code yesterday, and my priority was to test the effect, in terms of performance and quality (and i d like to know more about that, if some of you could test it :) ). So i ve gone straight to the global sdl surface :)

So that's the next step.
The only feasible method I could think of would be to reclor tiles and sprites themself before drawing with them.
Good idea. That would prevent to apply the effect each frame and save some cpu.

Re: An attempt to make day/night cycles in TMW

Posted: 25 Jan 2010, 13:27
by Claire
night-time and day time is a great idea!!! yay!! :)

Re: An attempt to make day/night cycles in TMW

Posted: 25 Jan 2010, 20:36
by Caput
Yeah, that is a good idea!

Re: An attempt to make day/night cycles in TMW

Posted: 26 Jan 2010, 21:15
by Doulos
Please keep in mind that certain areas will remain unaffected.

Caves, for example, cannot undergo "night". That's just silly since they're not lit up by the Sun. Other areas I can think of would be inside buildings. The lighting would be local (lamps, candles, etc.) unless you care to explain away the coding laziness by saying all TMW buildings come complete with glass tops.

Please don't create a global, careless "night".

Note: :idea: Dawn/nightfall would be more convincing if the land had a more orange "cast" than just a steadily increasing blue that covers the land.

If you're going to implement day/night, do it well.

:wink:

Re: An attempt to make day/night cycles in TMW

Posted: 26 Jan 2010, 21:25
by Crush
Regarding night in buildings: It depends.

Some buildings might be abandoned and dark during the night.

Other buildings might be lit by torches, candles or other light sources during the night. I would expect the light conditions to be different from during the day where the main light source is the sunlight which comes through the windows.

In any case the view out of the windows should be different during the night.


An idea how we could do that? anyone?

Re: An attempt to make day/night cycles in TMW

Posted: 26 Jan 2010, 22:49
by Jaxad0127
Crush wrote:Regarding night in buildings: It depends.

Some buildings might be abandoned and dark during the night.

Other buildings might be lit by torches, candles or other light sources during the night. I would expect the light conditions to be different from during the day where the main light source is the sunlight which comes through the windows.

In any case the view out of the windows should be different during the night.


An idea how we could do that? anyone?
Duplicate each tileset for day/night and carefully map so we can swap between them on the fly and have it look good. Your map changing proposal for manaserv is the best place to add this new functionality (tileset swapping).

Re: An attempt to make day/night cycles in TMW

Posted: 26 Jan 2010, 23:52
by Doulos
Crush wrote:Regarding night in buildings: It depends.

Some buildings might be abandoned and dark during the night.

Other buildings might be lit by torches, candles or other light sources during the night. I would expect the light conditions to be different from during the day where the main light source is the sunlight which comes through the windows.

In any case the view out of the windows should be different during the night.


An idea how we could do that? anyone?
True: buildings would be darker if they only had candles lighting them. They'd be subject to partial change. Caves should be static.

Would this mean actually lighting the rooms with light sources? No shadows necessary... but parts of the room where the candle light is brightest?

Re: An attempt to make day/night cycles in TMW

Posted: 27 Jan 2010, 02:29
by August Knight
I've noticed that players with their Ambient FX on high wandering in caves acts as a light source. Maybe create an NPC with such effects to simulate a candle/light source.

On magic "houses" or areas, we could use the glow of those wisps/spectre/poltergeist, if not bobbing around, as a source of light/static NPC.

Re: An attempt to make day/night cycles in TMW

Posted: 27 Jan 2010, 03:10
by Jaxad0127
August Knight wrote:I've noticed that players with their Ambient FX on high wandering in caves acts as a light source. Maybe create an NPC with such effects to simulate a candle/light source.

On magic "houses" or areas, we could use the glow of those wisps/spectre/poltergeist, if not bobbing around, as a source of light/static NPC.
That's just a simple overlay.

Re: An attempt to make day/night cycles in TMW

Posted: 27 Jan 2010, 14:41
by Doulos
Rotonen wrote:It shouldn't dim the light effects like the soul menhir effect.
Or on any of the game windows such as chat box (it's a dark blue too, just noticed it).

Re: An attempt to make day/night cycles in TMW

Posted: 27 Jan 2010, 22:02
by Axalix
jaxad0127 wrote:Duplicate each tileset for day/night and carefully map so we can swap between them on the fly and have it look good. Your map changing proposal for manaserv is the best place to add this new functionality (tileset swapping).
Why can't you apply the same mechanisms that are being used while coloring the items (clothes)? Duplicating each tileset (manually) may take much time, plus it will double current number of objects. Nevertheless, recoloring tiles on the fly can also help with the effect of gradual changing from twilight to deep night. So, i also agree with this:
Crush wrote:The only feasible method I could think of would be to reclor tiles and sprites themself before drawing with them.