Game Development Community

Day and Night Cycles in TGEA

by Matt Vitelli · 04/03/2008 (10:28 am) · 54 comments

Download Code File

First thing's first, this resource was written for TGEA 1.7 beta 2. Beta 1 has a problem initializing new shaders to the skybox class. Extract the engine files into the engine/source/terrain folder. Do a fresh recompile and then get ready to add some new code.

Copy SkyP.hlsl and SkyV.hlsl into your game/shaders folder.

Once you've recompiled, add the following code to your scriptsAndAssets/client/scripts/shaders.cs file:

new ShaderData( SkyShader )
{
   DXVertexShaderFile 	= "shaders/skyV.hlsl";
   DXPixelShaderFile 	= "shaders/skyP.hlsl";
   pixVersion = 2.0;
};

Next, copy scriptsAndAssets/server/scripts/DayNight.cs into the corresponding folder. Open game.cs and ender the following code below the other execs:

exec("./dayNight.cs");

Now, very important:

Two extra material lists must be added to your sky object. If they are not, your mission WILL NOT load up.

In your mission file, edit the sky object so that the material lists look like:
materialList = "scriptsAndAssets/data/skies/Skies/sky_day.dml";
sunsetList = "scriptsAndAssets/data/skies/Skies/sky_sunset.dml";
nightList = "scriptsAndAssets/data/skies/Skies/sky_night.dml";

Basically, materialList controls the mid-day sky, sunsetList controls the sunset sky, and nightList controls the night-time sky. Depending on your sun object's elevation, the sky's coloring will change based on the skyboxes.

Now that all is in place, you can use the DayNight function. The DayNight function uses a schedule to manipulate a sun object for a user-inputed duration of time. The function modifies the sun's azimuth and elevation. The change in elevation is statically set to add one or subtract one. The lower the change, the subtler the effect. Ideally, the change in azimuth should be twice as much as the change in elevation. (Because the total amount of elevation you can move is 180 and the total amount of azimuth you can move is 360 before going back to the point of origin.) Your sun's base elevation and azimuth should also keep this into account. To keep things simple, I set both of mine to zero so that when the function is called, it increases/decreases them at the same rate.

So, in the mission editor name your sun something along the lines of "GreatSun" or "MySun" and then call the dayNight function like this:

DayNight(GreatSun,50);

Where 50 is the time in milliseconds before the next sun update. I hope this resource is helpful to people. Really, a lot of interesting effects can be done with this. It is well-suited to handle an Oblivion-type of simulation using a persistent world. Since the time of day is locked to the sun's elevation, it's easy to save and adjust.
Page«First 1 2 3 Next»
#41
06/16/2009 (4:40 pm)
Hi Bryce, could you post a screenshot of what it looks like? Can you see any sky at all? Also, were you sure to include the shader?
#42
06/17/2009 (2:16 pm)
The game is running exactly as before except the Sun moves. I cant upload pictures at the current time sorry, but i hope my description will help you out.
#43
06/19/2009 (1:22 am)
Bump, Here is a video of what is happening

#44
06/19/2009 (6:56 am)
Hmm..and you made the change where you commented out both GFX->setupGenericShaders( GFXDevice::GSModColorTexture ); calls in renderSkyBox()?

#45
06/20/2009 (6:03 am)
Yes i did (starts crying). If you have made this in 1.7.1 could you send me your code files that work?
#46
06/23/2009 (4:22 am)
Bump i still don't know why it isn't working, my email is bryce@nimansoft.com, just send me an email and hopefully we can figure this out
#47
06/23/2009 (4:31 am)
I would like to know if anyone has gotten this working for TGEA 1.8.1? However, since I am seeing identical problems to Bryce, it seems it was a bit earlier version that broke this.
#48
06/23/2009 (7:10 am)
I'll send you the code, but I tested this in a stock build of TGEA 1.71 and it works fine.
#49
06/23/2009 (11:05 pm)
Matt would you please send it to me as well at RJNelson68@cox.net? Thank you in advance.
#50
06/26/2009 (1:42 am)
Well thanks for sending me the code Matt but it seems the differences in rendering code methods changed so drastically in TGEA 1.8.1 that this might not work without a major rework.
#51
06/30/2009 (5:14 am)
i implemented this resource in TGEA1.8.1 , but the sky box is not changing, can anyone of you tell me how to implement this in TGEA1.8.1?? thanks in Advance...
#52
02/10/2010 (12:52 am)
Well it has been half a year and I was just wondering if anyone ever got this to work in later versions?
#53
04/13/2010 (8:19 pm)
This version works for me in TGEA 1.7.1. Recently i switched to use TGEA 1.8.2 and i try to port this daynight code from TGEA 1.7.1 to TGEA 1.8.2.

All I see now is just a gray sky and it will flicker if the camera rotated to certain angle.

Anyone knows what is the problem ? Thanks in advance.
#54
04/14/2010 (1:01 am)
Solved the grey sky problem. Now facing the same problem with Adithyaa whereby the sky box is not changing.

The lighting works like previous version in 1.7.1. Is there anyone of you still using this daynight or you guys use other method to do this effect ?
Page«First 1 2 3 Next»