Polished up daylight cycles
by Chris \"Hobbiticus\" Weiland · 03/31/2003 (11:10 am) · 71 comments
Download Code File
Basically, I've rewritten and torque-ized Josh Ritter's day/night cycles to be a lot more robust. Instead of keeping everything in ugly and "unstable" externs, I've put everything into it's own class with good stuff like information hiding. It's still a little ugly because of all of the statics, however.
All you should have to do is apply the patch to a head version of torque, add the game/fx/daylightCycle.h/cc to your project file, compile and run.
Also, IF YOU GET MY TERRAIN BUMP MAPPING CODE (now available), you can go change this:
Then you will get dynamically generated bumps that change with the sun vector!
Added benefits:
Ability to get sunlight vector/color easily, only runs when sky is being rendered, modular, scalable, toggleable.
Have fun!
Basically, I've rewritten and torque-ized Josh Ritter's day/night cycles to be a lot more robust. Instead of keeping everything in ugly and "unstable" externs, I've put everything into it's own class with good stuff like information hiding. It's still a little ugly because of all of the statics, however.
All you should have to do is apply the patch to a head version of torque, add the game/fx/daylightCycle.h/cc to your project file, compile and run.
Also, IF YOU GET MY TERRAIN BUMP MAPPING CODE (now available), you can go change this:
VectorF sunVector; //if you use my updated day/night cycles you can use this for dynamic bumps //sunVector = DaylightCycle::getTrueSunVector(); static Vector<LightInfo*> lights; lights.clear(); gClientSceneGraph->getLightManager()->getLights(lights); sunVector = -lights[0]->mDirection; //first light is always sun //find s and t tangentsto this:
VectorF sunVector = DaylightCycle::getTrueSunVector(); //find s and t tangentsin terrRender.cc
Then you will get dynamically generated bumps that change with the sun vector!
Added benefits:
Ability to get sunlight vector/color easily, only runs when sky is being rendered, modular, scalable, toggleable.
Have fun!
#22
applying a patch ... see testing
www.garagegames.com/docs/torque.sdk/gstarted/patches.html
List o patches...
www.garagegames.com/index.php?sec=mg&mod=resource&page=category&qid=140
Here is the terrain
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4210
Must have this on the client side!! Looks pretty cool... here is a screenie from rise of power.
05/13/2003 (1:56 pm)
Hey newbies!! Here is some info on patches...applying a patch ... see testing
www.garagegames.com/docs/torque.sdk/gstarted/patches.html
List o patches...
www.garagegames.com/index.php?sec=mg&mod=resource&page=category&qid=140
Here is the terrain
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=4210
Must have this on the client side!! Looks pretty cool... here is a screenie from rise of power.
#23
I've see you patched this against the HEAD, but I have the last
TAIL...what should I do ?
05/16/2003 (2:40 am)
Ehi!! I've tryed to patched it and it gives me many of hunks.I've see you patched this against the HEAD, but I have the last
TAIL...what should I do ?
#24
//we need to scale up band calc for sky... they are set for a visible
//distance of 500... hopefully linear works
float bscale = 1.0;
if (sky)
bscale = sky->getVisibleDistance() / 500.0f;
But in the missione we now use 1500 for visible distance..so try to change the
value.
05/23/2003 (1:21 am)
Look this ://we need to scale up band calc for sky... they are set for a visible
//distance of 500... hopefully linear works
float bscale = 1.0;
if (sky)
bscale = sky->getVisibleDistance() / 500.0f;
But in the missione we now use 1500 for visible distance..so try to change the
value.
#25
05/25/2003 (9:35 pm)
#26
I havent checked this post for a while, but I just read this:
Well, it seems wrong to me, doesn't it? :)
As far as I saw it, it should take the fog color into account
(and if it really needs to be forced to white, then in the mission file the Fog Color should be set to 1 1 1 1)
Please tell me where I am wrong.
Isidore
05/27/2003 (8:28 am)
@hadokenI havent checked this post for a while, but I just read this:
Quote:
I believe that this resource sets the fog color for the scene without caring about your mission color
Well, it seems wrong to me, doesn't it? :)
As far as I saw it, it should take the fog color into account
(and if it really needs to be forced to white, then in the mission file the Fog Color should be set to 1 1 1 1)
Please tell me where I am wrong.
Isidore
#27
05/30/2003 (11:56 am)
i found that you cant have lens flare with this, is there anyway to implement it? thanks chris
#28
Isidore: It doesn't take the fog color into account right now. That's something that I just havn't gotten around to, and I doubt I will for a while. If you can add in support for it, be my guest to show me how to do it and I'll try to get it into the resource.
05/30/2003 (9:41 pm)
Chris: I havn't tried with a lense flare, but I assume it would work fine if you can have an fxSunLight and lense flare at the same time. I don't really see why this would affect that.Isidore: It doesn't take the fog color into account right now. That's something that I just havn't gotten around to, and I doubt I will for a while. If you can add in support for it, be my guest to show me how to do it and I'll try to get it into the resource.
#29
VectorF sunVector = DaylightCycle::getTrueSunVector();
//find s and t tangents
05/30/2003 (9:51 pm)
what file do you change the line to this?VectorF sunVector = DaylightCycle::getTrueSunVector();
//find s and t tangents
#30
05/31/2003 (9:07 am)
i tried to implement the lens flare code i found on the resources page but it didn't work, i wrote to the person but he hasn't responded. thanks thou for the response. if you find anything could you let me know. thanks chris
#31
Chris: It might help to give me something other than "it didn't work" ;)
What kinds of things aren't working? It might just be a simple matter. I might be able to get to it this/next week while I'm still free, but after that, I'm going to be busy with a job, my game premiering, and a lot of random stuff.
05/31/2003 (9:28 am)
Tyler: terrRender.cc, about 3/4 down - I updated the description. Sorry for the confusion.Chris: It might help to give me something other than "it didn't work" ;)
What kinds of things aren't working? It might just be a simple matter. I might be able to get to it this/next week while I'm still free, but after that, I'm going to be busy with a job, my game premiering, and a lot of random stuff.
#32
06/01/2003 (1:23 pm)
well it simply didn't show up in the demo. theres not much else to say about it. the code looks fine, ive been programming for 4 years and it looks good. theres just something on my side that is conflicting. i followed the instructions and i installed this patch previously for this daycycle. I also have added numerous things of my own and others that i found on the forums and they seem to work fine. i thought it might be that i needed the HEAD version for the flare to work i was just wondering if you knew. i'll just try to use flare on HEAD and see if it works. if it does work then some thing might be conflicting with this patch.
#33
but I've found the the sky doesn't change color with che dn cicle,
only the inferior bans.
It's possibile to make sky color changing ?
06/02/2003 (1:05 am)
A little question...I would like to not use sky texture....but I've found the the sky doesn't change color with che dn cicle,
only the inferior bans.
It's possibile to make sky color changing ?
#34
About the fog, I think the change I talk about above solve the problem.
ie:
Changing (in daylightcycle.cc)
to
In scorched earth, without this change and while using a green fogcolor (0.113000 0.948000 0.215000 1.000000) I obtain this:
membres.lycos.fr/aoworld/temp/default_daynight.jpg
After the code change, I obtain this:
membres.lycos.fr/aoworld/temp/modified_daynight.jpg
which, even if not better, seems more consistent.
What do you think?
Isidore
PS: while using the fractal sky, it seems that the fog color is used for the sky color, so I changed the sky.cc file so that it uses the SkySolidColor when using fractal sky only (no idea if this is correct but it looks better (^_^;) (here))
06/02/2003 (12:18 pm)
@ChrisAbout the fog, I think the change I talk about above solve the problem.
ie:
Changing (in daylightcycle.cc)
mFogColor = mCurrentBandColor;
to
mFogColor = mOrigionalFogColor * mCurrentBandColor;
In scorched earth, without this change and while using a green fogcolor (0.113000 0.948000 0.215000 1.000000) I obtain this:
membres.lycos.fr/aoworld/temp/default_daynight.jpg
After the code change, I obtain this:
membres.lycos.fr/aoworld/temp/modified_daynight.jpg
which, even if not better, seems more consistent.
What do you think?
Isidore
PS: while using the fractal sky, it seems that the fog color is used for the sky color, so I changed the sky.cc file so that it uses the SkySolidColor when using fractal sky only (no idea if this is correct but it looks better (^_^;) (here))
#35
Sam
06/18/2003 (12:09 pm)
This is nice, I have been loading two sky boxes and fading between them. Its a nice effect within its self but nothing like this. I may incorporate my stuff with yours just to see how it looks.Sam
#36
Change this (Line 65, 336, 363)
Sky* sky = (Sky*)Sim::findObject("Sky");
to this instead:
Sky* sky = gClientSceneGraph->getCurrentSky();
The line
'Sky* sky = (Sky*)Sim::findObject("Sky");'
always returns Null in the sky object then a client is connect to a Server.
Because of this, allot of code are not been executed after the 'if (sky)' statement.
if (sky)
{
...
Some useful code here
...
}
Why the 'Sim::findObject("Sky");' return a Null pointer, is mayby because the Sky object resides in the ServerConnection SimGroup instead then it is connected to the server. See the 'Tree()' command.
I found that 'gClientSceneGraph->getCurrentSky()' seems to work perfectly as a replacement.
Thomas
10/12/2003 (2:50 pm)
To solve the problem that the terrain is not lit correctly on the client (if the client is not on the same machine as the server) I did this in daylightCycle.ccChange this (Line 65, 336, 363)
Sky* sky = (Sky*)Sim::findObject("Sky");
to this instead:
Sky* sky = gClientSceneGraph->getCurrentSky();
The line
'Sky* sky = (Sky*)Sim::findObject("Sky");'
always returns Null in the sky object then a client is connect to a Server.
Because of this, allot of code are not been executed after the 'if (sky)' statement.
if (sky)
{
...
Some useful code here
...
}
Why the 'Sim::findObject("Sky");' return a Null pointer, is mayby because the Sky object resides in the ServerConnection SimGroup instead then it is connected to the server. See the 'Tree()' command.
I found that 'gClientSceneGraph->getCurrentSky()' seems to work perfectly as a replacement.
Thomas
#38
interiorrender.cc(1005) : error C2065: 'pFirstOpFirstOutputPoint' : undeclared identifier
LINE = glTexCoordPointer(2, GL_FLOAT, sizeof(OutputPoint), &pFirstOpFirstOutputPoint->lmCoord);
interiorrender.cc(1005) : error C2227: left of '->lmCoord' must point to class/struct/union
LINE = glTexCoordPointer(2, GL_FLOAT, sizeof(OutputPoint), &pFirstOpFirstOutputPoint->lmCoord);
interiorrender.cc(1559) : error C2601: 'renderLights' : local function definitions are illegal
LINE = {
interiorrender.cc(1627) : error C2601: 'renderAsShape' : local function definitions are illegal
LINE = {
interiorrender.cc(1700) : fatal error C1004: unexpected end of file found
LINE = timeScale = sky->getTimeScale();
daylightcycle.cc(67) : error C2064: term does not evaluate to a function
I have not modified daylightcycle.cc
any ideas? :S
10/28/2003 (12:28 pm)
I am getting errors and cannot track them down.. :(interiorrender.cc(1005) : error C2065: 'pFirstOpFirstOutputPoint' : undeclared identifier
LINE = glTexCoordPointer(2, GL_FLOAT, sizeof(OutputPoint), &pFirstOpFirstOutputPoint->lmCoord);
interiorrender.cc(1005) : error C2227: left of '->lmCoord' must point to class/struct/union
LINE = glTexCoordPointer(2, GL_FLOAT, sizeof(OutputPoint), &pFirstOpFirstOutputPoint->lmCoord);
interiorrender.cc(1559) : error C2601: 'renderLights' : local function definitions are illegal
LINE = {
interiorrender.cc(1627) : error C2601: 'renderAsShape' : local function definitions are illegal
LINE = {
interiorrender.cc(1700) : fatal error C1004: unexpected end of file found
LINE = timeScale = sky->getTimeScale();
daylightcycle.cc(67) : error C2064: term does not evaluate to a function
I have not modified daylightcycle.cc
any ideas? :S
#39
interiorrender.cc errors were cause by a stray }
daylightcycle.cc was calling a function that didnt exist. getTimeScale so i wrote that to return mTimeScale.
Now to chnage it so the players shadow chnages direction.. i cannot find where its getting the sun vector in player.cc
10/29/2003 (4:47 am)
No Matter i fixed it.interiorrender.cc errors were cause by a stray }
daylightcycle.cc was calling a function that didnt exist. getTimeScale so i wrote that to return mTimeScale.
Now to chnage it so the players shadow chnages direction.. i cannot find where its getting the sun vector in player.cc
#40
There should be a line similar to:
VectorF sunVector = VectorF(0.537, 0.537, -0.537);
change that to:
VectorF sunVector = DaylightCycle::getSunVector();
The shadow not changing is actually not an issue with the cycling code, but with the engine itself. The sun vector for shapebase shadows is a hardcoded value, which is kinda dumb.
10/31/2003 (9:17 am)
You want to look in shapeBase.ccThere should be a line similar to:
VectorF sunVector = VectorF(0.537, 0.537, -0.537);
change that to:
VectorF sunVector = DaylightCycle::getSunVector();
The shadow not changing is actually not an issue with the cycling code, but with the engine itself. The sun vector for shapebase shadows is a hardcoded value, which is kinda dumb.

Torque Owner Hadoken
It looks like the terrain is not lit correctly on the client (if the client is not on the same machine as the server), because of these lines in daylightCycle.cc
Sky* sky = (Sky*)Sim::findObject("Sky"); if (sky) if (sky->usesDNCycle()) {line 337 and again at line 364The problem might be that sky->usesDNCycle() (or maybe (sky), i haven't checked) will always be false on the client. Removing the IFs would make the terrain look right on the client, but then this resource wouldn't be toggleable.
Unfortunately i don't know enough about torque to make a proper fix.
EDIT: some more network issues: i had problems with the syncStartTime console function, this is what i changed:
in daylightCycle.cc line 109, it uses this to calculate what time it is:
In order for this to be the same on both the server and the client, we want that:
serverCurrentTime - serverStartTime = clientCurrentTime - clientStartTime
so:
clientStartTime = serverStartTime - serverCurrentTime + clientCurrentTime
from the server we send a value, which is (serverStartTime - serverCurrentTime), then we need to add clientCurrentTime to get the correct start time. So line 391 should be
where serverStartTime is actually (serverStartTime - serverCurrentTime).
In the scripts you may want to use something like this:
to sync time correctly.