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
#2
07/12/2006 (8:34 am)
cool :)
#3
07/12/2006 (9:12 am)
@Paul, this is absolutely awesome! Do you mind if this resource makes it's way into the MMORPG Enhancement Kit's next version?
#4
I would love to use this I am guess there is a probelm with one of the things I have been using and I hope someone can guide me in the right direction.
07/12/2006 (9:18 am)
I tried this with out such wonderful results and hopefully someone might be able to tell me why. I had DRL 2.1, CG Water, TLK 1.4, and TGE 1.4. When I use this I at first get a screen that looks like something from a 1970's lava lamp. If I change from full screen to windowed it goes good and remains so even after switching back to full screen. However, I am seeing some odd flashing of lights and objects like trees are iluminating irregularly.I would love to use this I am guess there is a probelm with one of the things I have been using and I hope someone can guide me in the right direction.
#5
Not a problem, that would be cool.
@Ron Nelson
At a guess, its conflicting with the DRL 2.1 somewhere. I had the lavalamp effect happening at one stage of development - I'd started out with DRL 2.0 but ended up carving out almost all of the actual DRL code.
07/12/2006 (9:26 am)
@DreamerNot a problem, that would be cool.
@Ron Nelson
At a guess, its conflicting with the DRL 2.1 somewhere. I had the lavalamp effect happening at one stage of development - I'd started out with DRL 2.0 but ended up carving out almost all of the actual DRL code.
#6
07/12/2006 (9:35 am)
Great work Paul :) I've just noticed you submitted this resource so decided to tweak my submission differently. Great to see all of it!
#7
I've noticed a couple of places in stock code that the view culling frustrum is using different methods of determining your view.
Usually this is surrounded by comments like "Hey I know this is a hack, but it's much faster than the other method, you really should be using method xyz though for best results"
Anyways they are right for a stock TGE implementation where not a whole heck of a lot depends on the viewing frustrum accuracy it's fine, but in cases where we are literally calculating lights on the fly this makes a HUGE difference.
As far as the Lava Lamp effect try starting out in full screen mode instead. If it's not there then most likely it has something to do with your video driver. However if it is still there, it might be that the rendering order is out of sync and the changing of modes re-syncs it. I imagine this could happen if you are writing to multiple offscreen buffers simulataneously while waiting for the PlayGui to pop. Doing a window size change would of course wipe the buffers in theory and restore the writing order.
Anyways all that is based on my best guesses, anyone is more than welcome to solve the actual issues :)
Regards,
Dreamer
07/12/2006 (9:35 am)
Make sure the viewing frustrum is using exactly the same culling algorithim in all cases.I've noticed a couple of places in stock code that the view culling frustrum is using different methods of determining your view.
Usually this is surrounded by comments like "Hey I know this is a hack, but it's much faster than the other method, you really should be using method xyz though for best results"
Anyways they are right for a stock TGE implementation where not a whole heck of a lot depends on the viewing frustrum accuracy it's fine, but in cases where we are literally calculating lights on the fly this makes a HUGE difference.
As far as the Lava Lamp effect try starting out in full screen mode instead. If it's not there then most likely it has something to do with your video driver. However if it is still there, it might be that the rendering order is out of sync and the changing of modes re-syncs it. I imagine this could happen if you are writing to multiple offscreen buffers simulataneously while waiting for the PlayGui to pop. Doing a window size change would of course wipe the buffers in theory and restore the writing order.
Anyways all that is based on my best guesses, anyone is more than welcome to solve the actual issues :)
Regards,
Dreamer
#8
07/12/2006 (10:19 am)
This is a great resource and thanks so much for sharing it, however one of my issues is the water.... it looks pretty but the sky's clouds move with the view. When I move my mouse the clouds follow. What did I do wrong :) ?
#9
Has anyone tried using this with the TLK?
07/12/2006 (11:11 pm)
Well I went through and used Winmerge to make sure my code matched yours to no avail. Also, besides the problems I mentioned earlier, I noticed I have no water any more as well. I have gone through each of the different changes and DRL 2.0 did not have much of a difference from 2.1 which I had gotten with the combo DRL and water upgrade previously released. Since your code replaces everything there, I can't see where that would make a difference.Has anyone tried using this with the TLK?
#10
However I ONLY have one problem. The clouds that reflect off of the waters surface move with my view, so when I move the mouse the sky follows and it looks nasty, even though there is a noise png applied to the normal map on the water block. Everything else works like a charm.
PLEASE HELP ;)
Thanks
07/12/2006 (11:20 pm)
Yea I have TGE 1.4 and TLK. I intergrated TLK into a fresh n clean TGE (using winmerge, just make sure you get all of the folders moved over even if it gives you an error some of the folders contain some files needed, go through each folder), then compiled it. I then extracted this resources zip, into my SDK folder, cleaned and recompiled :) Worked like a charm. The Nvidia CG Toolkit I used was the last stable version 1.4 . . . 1.5 has issues. However I ONLY have one problem. The clouds that reflect off of the waters surface move with my view, so when I move the mouse the sky follows and it looks nasty, even though there is a noise png applied to the normal map on the water block. Everything else works like a charm.
PLEASE HELP ;)
Thanks
#11
all i did to install this is set up a clean tlk wich compiles properly(1.4) and drag the files into the folders(no winmerge), if you use windows it will place the new files in the proper places without deleting the old files unless they are being replaced. Do a full clean of the entire resource and then a full compile because libraries need rebuilt. I did the complete install without anyerror first try. Hope that helps.
now that thats said heres my analisys.
Im doing a sidebyside comparison. I like this resource so far, although sidebyside they look almost identical (to the standard cg with water). I think there is some tweeking to make this thing golden. Im seeing brightness flashes, this is similar to drl2 with out corrections being made to the bloom to prevent picking up light from brighter or darker textures. With the standard installation I see the water isnt adjustable in surfacetexture, this is very noticable in the tlk demo level with the green ooze. In the night level the water emits light as if it actually had lights submerged into it. I like the lighting and shadows but at first glance it would seem the difference is simply the brightness of the entire scene, the one striking thing is the detail in the clouds that this rescource brings out.
I have seen these effects before, when i installed watercg and drl2 manualy without the unified resource it looked just like this. I think your definitly on the right track, my hopes and wishes to come out of this resource is: a controlable lightlevel for the entire scene ( the maxbrightness to maxshadow), shore texture chanel control (perhaps a chanel for fine detail in shore for water foam with an independent noisemap), proper submerge texture with a lighter reflection for relistic submerge effects.
Good work anyhow your on the right track and we may see a more efficiant and more user friendly cgwater kit!
07/12/2006 (11:51 pm)
@all who are confusedall i did to install this is set up a clean tlk wich compiles properly(1.4) and drag the files into the folders(no winmerge), if you use windows it will place the new files in the proper places without deleting the old files unless they are being replaced. Do a full clean of the entire resource and then a full compile because libraries need rebuilt. I did the complete install without anyerror first try. Hope that helps.
now that thats said heres my analisys.
Im doing a sidebyside comparison. I like this resource so far, although sidebyside they look almost identical (to the standard cg with water). I think there is some tweeking to make this thing golden. Im seeing brightness flashes, this is similar to drl2 with out corrections being made to the bloom to prevent picking up light from brighter or darker textures. With the standard installation I see the water isnt adjustable in surfacetexture, this is very noticable in the tlk demo level with the green ooze. In the night level the water emits light as if it actually had lights submerged into it. I like the lighting and shadows but at first glance it would seem the difference is simply the brightness of the entire scene, the one striking thing is the detail in the clouds that this rescource brings out.
I have seen these effects before, when i installed watercg and drl2 manualy without the unified resource it looked just like this. I think your definitly on the right track, my hopes and wishes to come out of this resource is: a controlable lightlevel for the entire scene ( the maxbrightness to maxshadow), shore texture chanel control (perhaps a chanel for fine detail in shore for water foam with an independent noisemap), proper submerge texture with a lighter reflection for relistic submerge effects.
Good work anyhow your on the right track and we may see a more efficiant and more user friendly cgwater kit!
#12
You'll probably have to test the compile by going into command prompt
>cgc script.cg
error C1115 - blah blah blah "tex2D", and error C1060 incompadible types doesn't really mean a whole lot.
07/14/2006 (12:12 am)
One note - "lava lamp" (well more like acid trip) effects tend to mean something crashed the compile of the cg script.You'll probably have to test the compile by going into command prompt
>cgc script.cg
error C1115 - blah blah blah "tex2D", and error C1060 incompadible types doesn't really mean a whole lot.
#13
07/14/2006 (1:02 am)
Nevermind. Totally my fault. I had moved my CG folder in the Water ugrade to facilitate my directory structure. Kind of forgot to do it for all of the new stuff again.
#14
At any rate, my only issue is that the general "brightness" of the level is a tad too dark. Is there a way to adjust the brighteness levels?
Sorry if this is a lame question...
07/18/2006 (9:47 am)
hello. I love this resource; it works "straight out of the box" just as advertised - I had been trying to get a successfull compile of the drl2.0 and water for a while and kept getting unsatisfactory results...At any rate, my only issue is that the general "brightness" of the level is a tad too dark. Is there a way to adjust the brighteness levels?
Sorry if this is a lame question...
#15
In the console, you can use setbasestrength() to increase the brightness. The default value is 100.
To permanently adjust it without having to go through a recompile - you can open up glow_combine_fg.cg . There, adjust the exposure value.
07/18/2006 (4:48 pm)
Not at all. In the console, you can use setbasestrength() to increase the brightness. The default value is 100.
To permanently adjust it without having to go through a recompile - you can open up glow_combine_fg.cg . There, adjust the exposure value.
#16
I've been trying for a couple of hours now but can't find a way. I'm not too good with CG.
07/21/2006 (8:49 pm)
Hey, is there any way to turn off the Bloom effect?I've been trying for a couple of hours now but can't find a way. I'm not too good with CG.
#17
I seem to remember having the issue and then resolving it when I installed the water upgrade alone, but for the life of me I can't remember what I did. Banging my head on the desk hasn't helped.
07/21/2006 (9:37 pm)
I'm having the same problem as Steve Adamson,I seem to remember having the issue and then resolving it when I installed the water upgrade alone, but for the life of me I can't remember what I did. Banging my head on the desk hasn't helped.
#18
07/23/2006 (5:27 pm)
Turning off the bloom (blur) is simple - just setBloomStrength(0) in the console.
#19
07/26/2006 (1:05 am)
Okay yes I see the oddball sky reflection - the fix is to add the example/client/ui/PlayGui.gui change in the sample mission files.
#20
The resource is missing some code. In Scenegraph.cc, in the function SceneGraph::RenderScene, add the following:
(after the creation of the SceneState object).
now everything works. This will effect everyone that has implemented this resource, since the result is that it culls out the terrain on the reflection.
Also if you want the fix for the underwater bug by Trond Abusdal, go to the orginal water res.
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10357
edit: nm. just tested it, it works fine, just need to modify the play gui.
08/09/2006 (12:14 pm)
Cool Res. I havnt tried implementing it yet, but just by looking at your screens, your water Resource isnt completed. I notice your terrain isnt rendering from far. I had a similar problem in the past.The resource is missing some code. In Scenegraph.cc, in the function SceneGraph::RenderScene, add the following:
//--------------------------------- // PRLD_WATER_SHADER //--------------------------------- pBaseState->mFlipCull = mReflectPass; //--------------------------------- // PRLD_WATER_SHADER //--------------------------------- right BEFORE these lines: // build the fog texture PROFILE_START(BuildFogTexture);
(after the creation of the SceneState object).
now everything works. This will effect everyone that has implemented this resource, since the result is that it culls out the terrain on the reflection.
Also if you want the fix for the underwater bug by Trond Abusdal, go to the orginal water res.
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10357
edit: nm. just tested it, it works fine, just need to modify the play gui.

Torque 3D Owner iHugMedia
Testing it out now, Loving you all the way man!
Update: I just added it, and it works VERY well. I get a very stable framerate and the image is clear and easy to install. Great work Paul!