Game Development Community

dev|Pro Game Development Curriculum

Realistic DayNight cycle v0.1 beta

by Dimitris Matsouliadis · 09/09/2008 (6:16 am) · 13 comments

for better
-----------------------------------------------------------------------------------------
. Set your sky name to "Sky"
. Set your sun name to "MySun"
. Create a sunlightObject with "MyMoon" name

execute the SunCycle.cs
Any time you like after mission load or in consol use
SunCycle(MySun, 400); // 400 is the time of sun moving degree to degree
to start system

you can use in realtime
Mysun.Elevation = ; // degree to start or set the sun, default is 0 degree "sunrise"
Mysun.reset();
Mysun.Apply();
changeTheSky();
CreateTheMoon();
MyMoon.delete();


new Sun(Mysun) { //My drl sun
canSaveDynamicFields = "1";
Enabled = "1";
azimuth = "0";
elevation = "0";
color = "1 1 0.8 1";
ambient = "0.811765 0.847059 0.764706 0";
bloomAmount = "0.15";
bloomCutOff = "0.85";
bloomSeedAmount = "1";
castsShadows = "1";
direction = "0 0.954268 -0.298953";
DRLHighDynamicRange = "1";
DRLMax = "1.7";
DRLMin = "0.6";
DRLMultiplier = "1.3";
DRLTarget = "0.5";
LocalFlareBitmap = "common/lighting/corona.png";
TypeBool locked = "true";
position = "0 0 0";
rotation = "1 0 0 0";
scale = "1 1 1";
useBloom = "0";
useDynamicRangeLighting = "1";
useToneMapping = "0";
};
-------------------------------------------------------------------------------


This is the SunCycle.cs

//-----------------------------------------------------------------------------
// Torque Game Engine
// Copyright (C) GarageGames.com, Inc.
//
// day/night 09/2008 by Matsouliadis Dimitris
//------------------------------------------

$Skymaterial = "scriptsAndAssets/data/skies/sky_blue/sky_blue.dml";
$FogSet = 150;
$fogColor = "0.92 0.69 0.431373 0";
$checkSunPlace = 0;
$MySundrl = 1.3;
$MyMoonDate =1;


function SunCycle(%MySun,%duration)
{
if(isObject(%MySun))
{
%MySun.Elevation++;
%Sunelv = %MySun.Elevation; //support the sun degree
$MyMoonElevationTime = %duration / 3.5; //support the moon speed

if($checkSunPlace == %Sunelv)
{
//support the weather
}
else
{
$checkSunPlace = %Sunelv;
if(%MySun.Elevation > 359)
%MySun.Elevation = 0;


if(%Sunelv >=160 && %Sunelv <= 230) //sunset
{
$FogSet =690 -(%Sunelv * 3);
if($FogSet <=1)
$FogSet=1;

%fogClRed = "0.92" +((159 -%Sunelv) /70);
%fogClGreen = "0.92" +((159 -%Sunelv) /60);
%fogClBlue = "0.92" +((159 -%Sunelv) /50);
if(%fogClRed <= 0.01)
%fogClRed = 0.01;
if(%fogClGreen <= 0.01)
%fogClGreen = 0.01;
if(%fogClBlue <= 0.01)
%fogClBlue = 0.01;
$fogColor = (%fogClRed SPC %fogClGreen SPC %fogClBlue SPC "0");
//MySun.LocalFlareBitmap = "common/lighting/corona.png";
changeTheSky();
}

if(%Sunelv >=311) //sunrise
{
$FogSet = %Sunelv -300;
if(%Sunelv >=340)
{
%fogClRed = ((%Sunelv -339) /22.2);
%fogClGreen = ((%Sunelv -339) /29);
%fogClBlue = ((%Sunelv -339) /46.5);
$fogColor = (%fogClRed SPC %fogClGreen SPC %fogClBlue SPC "0");
//MySun.LocalFlareBitmap = "common/lighting/corona.png";
}
changeTheSky();
}

if(%Sunelv >=1 && %Sunelv <= 90) //step to midday
{
$FogSet = 60 + (%Sunelv * 10);
if($FogSet >= 500)
$FogSet=500;
if(%Sunelv >=1 && %Sunelv <= 60)
{
%fogClRed = "0.92";
%fogClGreen = "0.69" + (%Sunelv /261);
%fogClBlue = "0.43" + (%Sunelv /120);
$fogColor = (%fogClRed SPC %fogClGreen SPC %fogClBlue SPC "0");
if(%Sunelv >=30)
//MySun.LocalFlareBitmap = "common/lighting/corona.png";
}
changeTheSky();
}

if($MySundrl <= 0.1)
{
$MySundrl = 0.1;
}

%MySun.DrlMultiplier = $MySundrl;
%MySun.apply();

if(%Sunelv == 1)
{
$Skymaterial = "scriptsAndAssets/data/skies/sky_blue/sky_blue.dml";
$MySundrl = 1.3;
changeTheSky();
if(isObject(MyMoon))
MyMoon.delete();
}
if(%Sunelv == 160)
{
$MyMoonDate++;
CreateTheMoon();
}
if(%Sunelv == 170)
{
$Skymaterial = "scriptsAndAssets/data/skies/sky_middle/sky_middle.dml";
$MySundrl = 0.8;
changeTheSky();
}
if(%Sunelv == 210)
{
$Skymaterial = "scriptsAndAssets/data/skies/sky_night/sky_night.dml";
$MySundrl = 0.1;
changeTheSky();
}
if(%Sunelv == 350)
{
$Skymaterial = "scriptsAndAssets/data/skies/sky_middle/sky_middle.dml";
$MySundrl = 0.6;
changeTheSky();
}

schedule(%duration, 0, "SunCycle", %MySun, %duration);
}
}
}

function changeTheSky(){

%VisibleSet = $FogSet +100;
if(%VisibleSet >= 600)
%VisibleSet =600;
if(%VisibleSet <= 250)
%VisibleSet =250;

Sky.canSaveDynamicFields = "1";
Sky.Enabled = "1";
Sky.position = "336 136 0";
Sky.rotation = "1 0 0 0";
Sky.scale = "1 1 1";
Sky.materialList = $Skymaterial;
Sky.cloudHeightPer[0] = "0.01";
Sky.cloudHeightPer[1] = "0.2";
Sky.cloudHeightPer[2] = "0";
Sky.cloudSpeed1 = "0.0001";
Sky.cloudSpeed2 = "0.0003";
Sky.cloudSpeed3 = "0.0006";
Sky.visibleDistance = %VisibleSet;
Sky.fogDistance = $FogSet;
Sky.fogColor = $fogColor;
Sky.fogStorm1 = "0";
Sky.fogStorm2 = "0";
Sky.fogStorm3 = "0";
Sky.fogVolume1 = "0 0 0";
Sky.fogVolume2 = "0 0 0";
Sky.fogVolume3 = "0 0 0";
Sky.windVelocity = "5 1 0";
Sky.SkySolidColor = "0.6 0.6 0.6 0.1";
Sky.useSkyTextures = "1";
Sky.renderBottomTexture = "0";
Sky.noRenderBans = "0";
Sky.renderBanOffsetHeight = "50";
Sky.skyGlow = "0";
Sky.skyGlowColor = "0 0 0 0";
Sky.fogVolumeColor1 = "128 128 128 -2.22768e+038";
Sky.fogVolumeColor2 = "128 128 128 0";
Sky.fogVolumeColor3 = "128 128 128 -1.70699e+038";
Sky.windEffectPrecipitation = "1";
Sky.locked = "false";
Sky.applySkyChanges(); // This need some fix in engine:)
}

function CreateTheMoon(){

if($MyMoonDate >=7) //7 days cycle (27 normal)
$MyMoonDate = 1;

if($MyMoonDate >=1)
%MyMoonFace ="common/lighting/MyMoon.png";
if($MyMoonDate >=2)
%MyMoonFace ="common/lighting/MyMoon1.png";
if($MyMoonDate >=3)
%MyMoonFace ="common/lighting/MyMoon2.png";
if($MyMoonDate >=4)
%MyMoonFace ="common/lighting/MyMoon3.png";
if($MyMoonDate >=5)
%MyMoonFace ="common/lighting/MyMoon4.png";
if($MyMoonDate >=6)
%MyMoonFace ="common/lighting/MyMoon5.png";

if(isObject(MyMoon))
MyMoon.delete();

new fxSunLight(MyMoon) {
canSaveDynamicFields = "1";
Enabled = "1";
position = "3774.41 772.596 26.5183";
rotation = "1 0 0 0";
scale = "1 1 1";
Enable = "1";
LocalFlareBitmap = %MyMoonFace;
RemoteFlareBitmap = %MyMoonFace;
SunAzimuth = "30";
SunElevation = "0";
LockToRealSun = "0";
FlareTP = "1";
Colour = "1 1 1 1";
Brightness = "1";
FlareSize = "1";
LocalScale = "1";
FadeTime = "0.1";
BlendMode = "0";
AnimColour = "1";
AnimBrightness = "1";
AnimRotation = "0";
AnimSize = "0";
AnimAzimuth = "0";
AnimElevation = "1";
LerpColour = "1";
LerpBrightness = "1";
LerpRotation = "1";
LerpSize = "1";
LerpAzimuth = "1";
LerpElevation = "1";
LinkFlareSize = "0";
SingleColourKeys = "1";
MinColour = "0.5 0.45 0.35 0";
MaxColour = "0.65 0.5 0.4 0";
MinBrightness = "0.6";
MaxBrightness = "0.9";
MinRotation = "0";
MaxRotation = "359";
minSize = "0.5";
MaxSize = "1";
MinAzimuth = "20";
MaxAzimuth = "160";
MinElevation = "45";
MaxElevation = "270";
RedKeys = "AZA";
GreenKeys = "AZA";
BlueKeys = "AZA";
BrightnessKeys = "AZA";
RotationKeys = "AZA";
SizeKeys = "AZA";
AzimuthKeys = "AZ";
ElevationKeys = "AZ";
ColourTime = "200";
BrightnessTime = "500";
RotationTime = "600";
SizeTime = "5";
AzimuthTime = "5";
ElevationTime = $MyMoonElevationTime;
};
MissionGroup.add(MyMoon);
echo("The moon is rissing at: " @ MyMoon.SunElevation @ " with face: " @ %MyMoonFace );
}

Click Here for screenshots

About the author

entelsoft, commercial accounting software


#1
09/09/2008 (11:18 am)
Do you have a video or at least a handful of larger screenshots to show the effect?
#2
09/10/2008 (12:46 am)
yea i would love to be able to get a closer look at the sky ... you don't realy see alot in the mini screenie you have posted with the resource.


... now why GG haven't implemented the screens as clickable tubnails is beyond me... but that is something to take up on the forums instead.
#3
09/10/2008 (6:29 am)
Sorry but i dont have :(
I need 2-3 days to complete and the timeCycle/weatherCycle. This change the clouds under time control like the seasons and the rage of Rain, storm. I have to put lighting effects in the flash. I working with Torgue engine ~3 months and i hope to write some code for daily use.
It's easy to try this code... i will be happy to hear any suggestions or notes from you to make this better:)

Ok now some screenshots is here
Click Here for screenshots
#4
09/10/2008 (7:18 am)
I would be willing to help you out with hosting. Just send me a message if your interested.
#5
09/10/2008 (8:48 am)
Awesome! Just wondering if this works for multi-players?
#6
09/10/2008 (3:16 pm)
Yes this works for multyplayers in full real timing. I have check this with 4 lan clients simultaneus. The weather that i working now have also day/night, rain, snow and lighting effects sychronization with config constant under months and season cycles.

*Mikael*
Thanks ... ill be back in 2 days and i write you :)
#7
09/10/2008 (6:01 pm)
Can't wait for that!
#8
09/12/2008 (12:53 pm)
Has anyone tested this on TGE/AFX?
#9
09/12/2008 (1:50 pm)
I think working. Try you need 5 mins for testing
#10
09/15/2008 (2:43 pm)
Very cool.
#11
09/24/2008 (8:19 am)
Yes, I can confim that it does work with tge/afx. One question/ comment however. When updating the fog density and colour the engine tends to hick up. Is anyone else getting this issue?
#12
09/27/2008 (6:30 am)
Jeam
I live in 2 towns every week... Monday to Friday for work to one and Saturday-Sunday to another for weekend. For that i read this forum any weekend, sorry for the lateness to answer you :)
matter in hand
Some people have use this code... i dont no how many is. I am working on a MMOrpg game and some codes that i have write and test i stick down here. For me working properly except that you have in report.
I use 'Sky.applySkyChanges()' method who isnt better choice. Time to time ill be to make something for this.
For the other side is a method who dont need any changes to the engine, working only wiih employ of torque scripts.
Here www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=15391 you can find a extension of this code with day/month/season/year control. This extension handle rain, snow and clouds proportional with season. Soon ill add and water handle under weather pact. All this is under evolution and working properly. That i attend is the convertions with prev.versions.
#13
01/19/2015 (1:57 am)
Hello Dimitris, will this work for TGE 1_5_2? I am looking for day/night cycle.