CG Dynamic Gamma & Water Upgrade
by Paul Jan · 07/11/2006 (12:43 pm) · 171 comments
Download Code File
I've merged the code files with the sample files because I found the gui was required, and with other changes goes over the 100k limit on uploads - the full file can be downloaded here:
dynamic_gamma.zip
Update (2006/10/29): Torque 1.5 version code here:
Update (2006/11/23): Some more bug fixes added.... dynamic_gamma-1_5.zip
I'll leave the old one up for folks who aren't moving to Torque 1.5. I haven't had the chance to test it as well as I'd like, so let me know if its not working right!
Before/After:


Outdoor Before/After


Night Before/After


To be honest, the code is a cobbled mess in some places. Still framerate is pretty good, and I've tested it on ATI (radeon 9800) and NV ( 6800 GS) platforms.
It should pretty much be unzip, copy into TLK & recompile. You will still need to install the Nvidia CG libraries as well.
Previous resources and credit where credit is due:
CG Water (Manoel Neto) has not changed from the original resource (adjusted to make DRL work)
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10357
+ Sky::render fix by David Laurie
CG Dynamic Gamma is similar in effect to the DRL 2.0 resource (Alex "Delerium" Scarborough)
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10232
using CG shaders increases performance.
It also takes parts from 5.10 Game Programming Gems 4 "Dynamic Gamma Using Sampled Scene Luminance", and VERC "Real time TRON 2.0" collective.valve-erc.com/index.php?go=tron1
edit (Aug 11, 2006) Fixed bloom-crippling bug.
I've merged the code files with the sample files because I found the gui was required, and with other changes goes over the 100k limit on uploads - the full file can be downloaded here:
dynamic_gamma.zip
Update (2006/10/29): Torque 1.5 version code here:
Update (2006/11/23): Some more bug fixes added.... dynamic_gamma-1_5.zip
I'll leave the old one up for folks who aren't moving to Torque 1.5. I haven't had the chance to test it as well as I'd like, so let me know if its not working right!
Before/After:


Outdoor Before/After


Night Before/After


To be honest, the code is a cobbled mess in some places. Still framerate is pretty good, and I've tested it on ATI (radeon 9800) and NV ( 6800 GS) platforms.
It should pretty much be unzip, copy into TLK & recompile. You will still need to install the Nvidia CG libraries as well.
Previous resources and credit where credit is due:
CG Water (Manoel Neto) has not changed from the original resource (adjusted to make DRL work)
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10357
+ Sky::render fix by David Laurie
CG Dynamic Gamma is similar in effect to the DRL 2.0 resource (Alex "Delerium" Scarborough)
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10232
using CG shaders increases performance.
It also takes parts from 5.10 Game Programming Gems 4 "Dynamic Gamma Using Sampled Scene Luminance", and VERC "Real time TRON 2.0" collective.valve-erc.com/index.php?go=tron1
edit (Aug 11, 2006) Fixed bloom-crippling bug.
About the author
#102
I mean... what is it that i do differently to you and others
I just CANT get it to work
could you give a brief explanation on how you did it... here i mean.. how were you able to compile with cg included.. without errors.. step-by-step a simple explanation
I would appreciate all the help i can get
I posted about my errors 3-5 posts above
Regards
11/10/2006 (5:10 am)
Edmond Brown... i did EXACTLY the same things like you... and when i compiled with the cg/lib and cg/instance and all that included i get over 9000 errors!I mean... what is it that i do differently to you and others
I just CANT get it to work
could you give a brief explanation on how you did it... here i mean.. how were you able to compile with cg included.. without errors.. step-by-step a simple explanation
I would appreciate all the help i can get
I posted about my errors 3-5 posts above
Regards
#103
11/10/2006 (5:42 am)
dont forget to change that cggh file in the include folder. Have to change one line in there(in the resadme file) or it wont compile properly. When i have more time tonight ill give a step by step process on what i did (remember, mine still doesnt work :\)
#104
insted of #include
And looking forward to see how you did yours differently to mine
Thanks for helping
(even though your doesnt work yet... its progress atleast to be able to compile it all without errors... :) )
Regards
Bardur
11/10/2006 (5:46 am)
I most defenetly did (must be 4 times now) change cgGh to #include And looking forward to see how you did yours differently to mine
Thanks for helping
(even though your doesnt work yet... its progress atleast to be able to compile it all without errors... :) )
Regards
Bardur
#105
1) I reinstalled 1.5 TGE onto my D drive (fresh install)
2)opened VC2005 and loaded the torque sdk.sln from the vc2005 directory within torque directory
3)Right clicked on the torque demo > properties.
4)Under debugging in the working directory area i put in ../example (stated to do so by the compiling reference http://tdn.garagegames.com/wiki/Torque/vs2k5 ), also put ../example in the release part of debugger as also stated by the resource.
5)Compile torque demo (right click torque demo and build)
Should get this:
Torque Demo - 0 error(s), 0 warning(s)
========== Build: 7 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
6) Uninstalled any previous CG toolkit i had installed
7) went to here: http://developer.nvidia.com/object/cg-toolkit-14.html to download the 1.41 toolkit
8) installed the toolkit to d:\NVIDIA Corporation\Cg, installed it will all the defualt options checked
9) went to d:\NVIDIA Corporation\Cg\include\Cg and opened cgGL.h with VC2005
10) Found #include and replaced it with #include
11)saved the file
12)Opened the torque sdk again, went to tools in the top menu, then to options
13)Expanded projects and solutions, and went to VC++ directories
14)lowered the "show directories for" menu and clicked on the include files option
15)double clicked on the space below the last entry and clicked on the "..." button to the right of it
16)selected my include folder, which after pressing open showed it as being D:\Nvidia Corporation\Cg\include. Pressed the blue checkmark above nothing appeared for an error
17) did the same thing for the lib folder, found the folder in my nvidia folder, pressed the blue check mark then pressed ok after i double checked that both entries were there.
18) for the hell of it i decided to compile torque demo again(right click > rebuild). See if anything changed after i did all that with CG files.... and i got this:
Torque Demo - 0 error(s), 0 warning(s)
========== Rebuild All: 7 succeeded, 0 failed, 0 skipped ==========
So, so far so good.
19) download the zip file from http://s87051801.onlinehome.us/dynamic_gamma-1_5.zip
20) unzip the file to a folder called Torque CG files
21) copied the Engine and Example folders over to torque/SDK folder chose to overright any files with the same name
22) check the init.cs file under Torque\SDK\Example\starter.fps\data to make sure it said "exec( "./interiors/propertyMap.cs" );" it does
23) the readme says "In your game directory (example) directory put CG\2TUfp20dot3.cg
I also have cgc.exe in that same directory" I could not find 2TUfp20dot3.cg anywhere on my computer, so im not sure what its talking about. For the cgc.exe i decided not to put it into the folder this time
24)opened VC2005 again and right clicked torque demo and pressed rebuild, and crossed my fingers
25)After the build completed i got this:
Torque Demo - 0 error(s), 1 warning(s)
========== Rebuild All: 7 succeeded, 0 failed, 0 skipped ==========
The warning was:
d:\torque\sdk\engine\game\gametsctrl.cc(244) : warning C4482: nonstandard extension used: enum 'GBitmap::BitmapFormat' used in qualified name
closed VC 2005
26)even with the warning i decided to try the fps starter kit, so i opened torque game engine SDK icon off the desktop and double clicked on fps starter kit and see if anything changed
Didnt change any of the options(aka still in windowed mode), chose the stronghold mission and loaded it
and i got this:
http://img213.imageshack.us/img213/2606/nowatertx7.jpg
27) Thinking it might be that error, i open VC2005 again, open gameTSCtrl.cc and go to this line:
GBitmap *bitmap = new GBitmap(updateRect.extent.x, updateRect.extent.y, false, GBitmap::BitmapFormat::RGB);
I then make it into this :
GBitmap *bitmap = new GBitmap(updateRect.extent.x, updateRect.extent.y, false, GBitmap::RGB);
28)Saved the file
29)Right clicked the torque demo and pressed rebuild
after it built i get this:
Torque Demo - 0 error(s), 0 warning(s)
========== Rebuild All: 7 succeeded, 0 failed, 0 skipped ==========
30) close down VC2005 and give the starter kit another try through the icon thats on my desktop
Get the same result as before. Dont get any new water effects or any new light effects :(
EDIT: It doesnt work on the fps starter, but if i go to the top and press debug, it works under the mission editor under torque demo. So for some reason it wont work on starter.fps but it will under the debugger when i activate through VS2005...
Edit again: K seems to be a problem with my waterblock. It gives me an error about GL when it loads it anywhere. The dynamic lighting is working tho
This is where it tells me its stopping, line 739 in waterblock.cc
AssertFatal( dglIsInCanonicalState(),
"Error, GL not in canonical state on exit" );
11/10/2006 (2:36 pm)
K ill do step by step of what im doing(im on win xp SP2):1) I reinstalled 1.5 TGE onto my D drive (fresh install)
2)opened VC2005 and loaded the torque sdk.sln from the vc2005 directory within torque directory
3)Right clicked on the torque demo > properties.
4)Under debugging in the working directory area i put in ../example (stated to do so by the compiling reference http://tdn.garagegames.com/wiki/Torque/vs2k5 ), also put ../example in the release part of debugger as also stated by the resource.
5)Compile torque demo (right click torque demo and build)
Should get this:
Torque Demo - 0 error(s), 0 warning(s)
========== Build: 7 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
6) Uninstalled any previous CG toolkit i had installed
7) went to here: http://developer.nvidia.com/object/cg-toolkit-14.html to download the 1.41 toolkit
8) installed the toolkit to d:\NVIDIA Corporation\Cg, installed it will all the defualt options checked
9) went to d:\NVIDIA Corporation\Cg\include\Cg and opened cgGL.h with VC2005
10) Found #include
11)saved the file
12)Opened the torque sdk again, went to tools in the top menu, then to options
13)Expanded projects and solutions, and went to VC++ directories
14)lowered the "show directories for" menu and clicked on the include files option
15)double clicked on the space below the last entry and clicked on the "..." button to the right of it
16)selected my include folder, which after pressing open showed it as being D:\Nvidia Corporation\Cg\include. Pressed the blue checkmark above nothing appeared for an error
17) did the same thing for the lib folder, found the folder in my nvidia folder, pressed the blue check mark then pressed ok after i double checked that both entries were there.
18) for the hell of it i decided to compile torque demo again(right click > rebuild). See if anything changed after i did all that with CG files.... and i got this:
Torque Demo - 0 error(s), 0 warning(s)
========== Rebuild All: 7 succeeded, 0 failed, 0 skipped ==========
So, so far so good.
19) download the zip file from http://s87051801.onlinehome.us/dynamic_gamma-1_5.zip
20) unzip the file to a folder called Torque CG files
21) copied the Engine and Example folders over to torque/SDK folder chose to overright any files with the same name
22) check the init.cs file under Torque\SDK\Example\starter.fps\data to make sure it said "exec( "./interiors/propertyMap.cs" );" it does
23) the readme says "In your game directory (example) directory put CG\2TUfp20dot3.cg
I also have cgc.exe in that same directory" I could not find 2TUfp20dot3.cg anywhere on my computer, so im not sure what its talking about. For the cgc.exe i decided not to put it into the folder this time
24)opened VC2005 again and right clicked torque demo and pressed rebuild, and crossed my fingers
25)After the build completed i got this:
Torque Demo - 0 error(s), 1 warning(s)
========== Rebuild All: 7 succeeded, 0 failed, 0 skipped ==========
The warning was:
d:\torque\sdk\engine\game\gametsctrl.cc(244) : warning C4482: nonstandard extension used: enum 'GBitmap::BitmapFormat' used in qualified name
closed VC 2005
26)even with the warning i decided to try the fps starter kit, so i opened torque game engine SDK icon off the desktop and double clicked on fps starter kit and see if anything changed
Didnt change any of the options(aka still in windowed mode), chose the stronghold mission and loaded it
and i got this:
http://img213.imageshack.us/img213/2606/nowatertx7.jpg
27) Thinking it might be that error, i open VC2005 again, open gameTSCtrl.cc and go to this line:
GBitmap *bitmap = new GBitmap(updateRect.extent.x, updateRect.extent.y, false, GBitmap::BitmapFormat::RGB);
I then make it into this :
GBitmap *bitmap = new GBitmap(updateRect.extent.x, updateRect.extent.y, false, GBitmap::RGB);
28)Saved the file
29)Right clicked the torque demo and pressed rebuild
after it built i get this:
Torque Demo - 0 error(s), 0 warning(s)
========== Rebuild All: 7 succeeded, 0 failed, 0 skipped ==========
30) close down VC2005 and give the starter kit another try through the icon thats on my desktop
Get the same result as before. Dont get any new water effects or any new light effects :(
EDIT: It doesnt work on the fps starter, but if i go to the top and press debug, it works under the mission editor under torque demo. So for some reason it wont work on starter.fps but it will under the debugger when i activate through VS2005...
Edit again: K seems to be a problem with my waterblock. It gives me an error about GL when it loads it anywhere. The dynamic lighting is working tho
This is where it tells me its stopping, line 739 in waterblock.cc
AssertFatal( dglIsInCanonicalState(),
"Error, GL not in canonical state on exit" );
#106
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10357
Hit "Ctrl"+"F" and search for "canonical"
and you will find your answer
11/10/2006 (6:42 pm)
The answer is located in the original Water Res:www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10357
Hit "Ctrl"+"F" and search for "canonical"
and you will find your answer
#107
It tells me i have to own the 1.42 TGE indie license to view that resource!(even though i own 1.5?) ARGH so close, and yet so far.
Time to send an email off to gg
11/11/2006 (4:38 am)
Thanks T squaredIt tells me i have to own the 1.42 TGE indie license to view that resource!(even though i own 1.5?) ARGH so close, and yet so far.
Time to send an email off to gg
#108
11/11/2006 (8:54 am)
You should only need to own TGE 1.4 to be able to view this res. Tho when i originally found this res. i had TLK 1.4
#109
i'm trying it out right now
ill post about my results
EDIT:
I STILL get those 9000+ errors.... and your step by step is infact the exacte way i did it all the other times
Strange!
and also.. it seems like VS2005 "Remembers" my settings for the Torque SDK.sln
Because even though i have reinstalled the SDK and every thing (Removed then reinstalled)
the settings are still there... the "include" settings and all that are still there... in the NEW "Torque SDK.sln"
How can i ... delete all previous settings in VS2005??.... this is really freaking my out...
Thanks for all you help though
Regards
11/11/2006 (10:37 am)
Thanks ALOT Edmond Brown!i'm trying it out right now
ill post about my results
EDIT:
I STILL get those 9000+ errors.... and your step by step is infact the exacte way i did it all the other times
Strange!
and also.. it seems like VS2005 "Remembers" my settings for the Torque SDK.sln
Because even though i have reinstalled the SDK and every thing (Removed then reinstalled)
the settings are still there... the "include" settings and all that are still there... in the NEW "Torque SDK.sln"
How can i ... delete all previous settings in VS2005??.... this is really freaking my out...
Thanks for all you help though
Regards
#110
I've tried some things suggested by Alex in his resource but no luck.

11/11/2006 (12:07 pm)
I was wondering if someone can tell me how to turn down the brightness. When the player is facing the sunlight its so overexposed that its hard to look at, any thoughts? I want to make it look darker =)I've tried some things suggested by Alex in his resource but no luck.

#111
In computeDRL()
glReadPixels(0, (extent.y/scale)-(arraySize/arrayWidth), arrayWidth, arraySize/arrayWidth, GL_RED, GL_UNSIGNED_BYTE, &pixels[0]);
You can't increase the size of the sample?
hmmm
11/11/2006 (3:04 pm)
Okay I've come to the conclusion that this problem is something that everyone else is having. Paul have you figured this out:In computeDRL()
glReadPixels(0, (extent.y/scale)-(arraySize/arrayWidth), arrayWidth, arraySize/arrayWidth, GL_RED, GL_UNSIGNED_BYTE, &pixels[0]);
You can't increase the size of the sample?
hmmm
#112
BUT!... this is the big BUT...
i have exactly the same problem as *Edmond Brown*.. the so called "canonical" problem
And i have tried commenting stuff out and compiled... etc etc..
But i cant seem to make it work
First of all it only works in Debug mode... and only DRL works there... and as soon as i add a water block i get the "canonical" error
What exactly should i comment out..
Every thing in the "water thread" is to loose on the "canonical" issue.. there is info and solutions (for some) in in it... but nothing that i can make work
What exactly is it that i should comment out and add?
And i have to add this... i once got the water working in the mission without crashing.. but the water was "Gray fog"... and i couldnt resolve it..
i would TOTALY appreaciate some help here (and i guess Edmond would too)
Regards
11/11/2006 (3:25 pm)
I FINALY got it to work... with ALOT of frustration and what not!BUT!... this is the big BUT...
i have exactly the same problem as *Edmond Brown*.. the so called "canonical" problem
And i have tried commenting stuff out and compiled... etc etc..
But i cant seem to make it work
First of all it only works in Debug mode... and only DRL works there... and as soon as i add a water block i get the "canonical" error
What exactly should i comment out..
Every thing in the "water thread" is to loose on the "canonical" issue.. there is info and solutions (for some) in in it... but nothing that i can make work
What exactly is it that i should comment out and add?
And i have to add this... i once got the water working in the mission without crashing.. but the water was "Gray fog"... and i couldnt resolve it..
i would TOTALY appreaciate some help here (and i guess Edmond would too)
Regards
#113
type "setMinOverexposure(float)"
the float default value is 0.5. 0.9 is a good lvl.
11/11/2006 (6:33 pm)
@Vince McMullin type "setMinOverexposure(float)"
the float default value is 0.5. 0.9 is a good lvl.
#114
11/12/2006 (6:40 am)
Well Bardur you're atleast one step ahead of me...I still cant access the resource since i didnt buy v1.4. I emailed GG and i havent gotten a response yet, ill have to try on irc later today hopefully
#115
I have tried everything i can imagine... but its not working yet
Maybe you could contact me on MSN and we could talk about a solution to the "canonical" issue?
After all you are a TGE owner.. so you should be able to get info on the "canonical state" problem
(Check my profile for MSN address )
Regards
Bardur Mikladal
11/12/2006 (7:08 am)
IF/When you find a/the solution tell me ;)I have tried everything i can imagine... but its not working yet
Maybe you could contact me on MSN and we could talk about a solution to the "canonical" issue?
After all you are a TGE owner.. so you should be able to get info on the "canonical state" problem
(Check my profile for MSN address )
Regards
Bardur Mikladal
#116
And since its sunday, i doubt any GG will be on to help me :(
11/12/2006 (10:11 am)
Does the resource tell you to just "comment" out a line or 2?And since its sunday, i doubt any GG will be on to help me :(
#117
but it basicly says to comment out a line and add a line... some of the guys that have posted there say that only adding one line gets rid of the problem and so on...
its kinda vague
Regards
11/12/2006 (10:15 am)
it says... well there are different solutions that people have used.. so there are like several things you can dobut it basicly says to comment out a line and add a line... some of the guys that have posted there say that only adding one line gets rid of the problem and so on...
its kinda vague
Regards
#118
K so more then 1 answer, well that sucks. BUT......its better then 6000 errors, am i right? :P
When they let me see the resource ill see if i can get mine to work. Because this seems to give alot to tge, and would be an awsome feature to have.
Edit: Also Bardur can u get the water to work in debug? i cant even get it to work through that
Edit: Well i got it to load. With both the water and DL however DL was on the fritz and was going on and off. And the lag was horrible. After turning to the right about 90 degrees it comes up with another canonical error for shapebase.cc give me a sec...
Also what i did was just delete the lines it said was giving errors....probably not the best thing to do but its gotten me the furthest so far
Edit again:

However the lighting seems to be going on and off, and under water isnt working properly. I wish i could see the resource to see which lines they were looking at, because as far as i can tell id have to remove that fatalassertion line for all the files that have it :(
11/12/2006 (11:57 am)
This is Ed BTW i just changed it from my fathers name (signed for this account years ago) to my own :)K so more then 1 answer, well that sucks. BUT......its better then 6000 errors, am i right? :P
When they let me see the resource ill see if i can get mine to work. Because this seems to give alot to tge, and would be an awsome feature to have.
Edit: Also Bardur can u get the water to work in debug? i cant even get it to work through that
Edit: Well i got it to load. With both the water and DL however DL was on the fritz and was going on and off. And the lag was horrible. After turning to the right about 90 degrees it comes up with another canonical error for shapebase.cc give me a sec...
Also what i did was just delete the lines it said was giving errors....probably not the best thing to do but its gotten me the furthest so far
Edit again:

However the lighting seems to be going on and off, and under water isnt working properly. I wish i could see the resource to see which lines they were looking at, because as far as i can tell id have to remove that fatalassertion line for all the files that have it :(
#119
Welll its INDEED better where i am now then having 9000+ errors
What is it your waiting for... GG to grant you access?.... well i could give you the important bit that have to do with the "canonical state" problem via MSN or something...
And also .. when im in debug mode only DRL works.... and as soon as i add a waterblock the error comes up!
i once got the water to work... but i have no idea how and it did also have the famous "gray fog" problem
its sad :(
Regards
11/12/2006 (12:35 pm)
Ok...hmm... Welll its INDEED better where i am now then having 9000+ errors
What is it your waiting for... GG to grant you access?.... well i could give you the important bit that have to do with the "canonical state" problem via MSN or something...
And also .. when im in debug mode only DRL works.... and as soon as i add a waterblock the error comes up!
i once got the water to work... but i have no idea how and it did also have the famous "gray fog" problem
its sad :(
Regards
#120
Edit: Also i think the main problem we have to face is the fact that GL isnt canonical, and why that is. If there is a way we could make sure it canonical id like to see the results throughout
11/12/2006 (12:49 pm)
I added you to MSN if you want to chat about this moreEdit: Also i think the main problem we have to face is the fact that GL isnt canonical, and why that is. If there is a way we could make sure it canonical id like to see the results throughout

Torque Owner Alexander Brown
I got the toolkit 1.41 from nvidia
got torque 1.5, installed it, compiled it(no errors), and then linked the cg/lib and cg/instance directories
changed the lines on the file to say #include
Then i copied the files over from the zip to their respective places within the torque directory
compiled it all (no errors)
Checked the starter.fps and i dont get either the warter effects or Dynamic gamma
help?