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
#122
I'm enjoying quite satisfying looking of my game using this resource with TGE 1.4. Thanks again for this resource.
Today, I tried to bring this effect to my gun DTS and player. All I did was to add a line something like below.
Do I need more to do to get what I want?
Thanks in advance.
Hongjin
11/14/2006 (11:48 pm)
Greetings!I'm enjoying quite satisfying looking of my game using this resource with TGE 1.4. Thanks again for this resource.
Today, I tried to bring this effect to my gun DTS and player. All I did was to add a line something like below.
addMaterialMapping("w_m99" , "normal: troup/data/shapes/weapons/m99a/w_m99_nm");But there was no difference after that adding. I also tried 'detail' instead of 'normal' in above code. No luck either.Do I need more to do to get what I want?
Thanks in advance.
Hongjin
#123
11/15/2006 (5:20 am)
That only works if you bought Torque Shader Engine. This resource only effects the water and lighting.
#125
11/22/2006 (4:04 pm)
I found out whats causing the problem with the sample size - you have to disable cg before you perform the readpixel operation. Otherwise the number of valid pixels you can use is messed up. I'll have an update loaded in a day or so.
#126
11/22/2006 (5:50 pm)
Trying to clean up some other bugs that have popped up during testing - For some reason my code is working in 1024 x 768 resolution, but crashes in 800 x 600. Just gotta step on this bug :)
#127
the water doesnt have any distance fog effect on it
so if your looking waaay down a river the banks on both sides fog out, but the water doesnt.. it looks very unnatural
11/25/2006 (5:19 pm)
i noticed an issuethe water doesnt have any distance fog effect on it
so if your looking waaay down a river the banks on both sides fog out, but the water doesnt.. it looks very unnatural
#128
11/26/2006 (11:44 am)
Yes, the water isn't really mine - I just try to keep it working in combination with the gamma effect.
#129
The waterblock will render as a pink tone due to the surface texture being re-assigned to the normalmap texture.
To fix this bug, go to line 403 in waterblock.cc and change mSurfaceTexture to mNormalMapTexture.
12/05/2006 (12:03 pm)
There is a bug with the waterblock when running on a system that does not support PS/VS.The waterblock will render as a pink tone due to the surface texture being re-assigned to the normalmap texture.
To fix this bug, go to line 403 in waterblock.cc and change mSurfaceTexture to mNormalMapTexture.
#130
12/05/2006 (12:04 pm)
If you want to use the standard fogging with the shader water, go to line 900 in fluidRender.cc and move the text block to line 868. That will force fogging to be used with both standard and shader water.
#131
12/06/2006 (6:32 am)
Paul could you tell me what was supposed to be in the text block? My version is apparently not the same as yours.
#132
12/06/2006 (8:54 am)
Hmm, it should have a close bracket. I'm going by the source in the file linked at the top, so any merged code could move the position.
#133
Change it to read:
That will take the fogging out of the non-shader fallback code and put it in for both.
There is a slight issue with the edge of the visible waterblock, but it's a lot less noticeable than before.
12/06/2006 (11:32 am)
Close to the end of fluid::Render in fluidRender.cc you will see code as follows:// ***************************************************************** // // Fog Map. // // ***************************************************************** // ***************************************************************** // TMU #0 - Fog Map. // ***************************************************************** glEnableClientState ( GL_VERTEX_ARRAY ); glEnableClientState ( GL_COLOR_ARRAY ); glVertexPointer ( 3, GL_FLOAT, sizeof(vertex), &(m_pVertex[0].XYZ) ); glColorPointer ( 4, GL_FLOAT, sizeof(vertex), &(m_pVertex[0].RGBA4) ); glEnable ( GL_BLEND ); glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); // ***************************************************************** // Draw the Surface. // ***************************************************************** glDrawElements ( GL_TRIANGLES, m_IUsed, GL_UNSIGNED_SHORT, m_pIndex ); // ***************************************************************** // Restore State #0 - Fog Map. // ***************************************************************** //------------------------------------------- // PRLD_WATER_SHADER //------------------------------------------- } //------------------------------------------- // PRLD_WATER_SHADER //-------------------------------------------
Change it to read:
//------------------------------------------- // PRLD_WATER_SHADER //------------------------------------------- } //------------------------------------------- // PRLD_WATER_SHADER //------------------------------------------- // ***************************************************************** // // Fog Map. // // ***************************************************************** // ***************************************************************** // TMU #0 - Fog Map. // ***************************************************************** glEnableClientState ( GL_VERTEX_ARRAY ); glEnableClientState ( GL_COLOR_ARRAY ); glVertexPointer ( 3, GL_FLOAT, sizeof(vertex), &(m_pVertex[0].XYZ) ); glColorPointer ( 4, GL_FLOAT, sizeof(vertex), &(m_pVertex[0].RGBA4) ); glEnable ( GL_BLEND ); glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); // ***************************************************************** // Draw the Surface. // ***************************************************************** glDrawElements ( GL_TRIANGLES, m_IUsed, GL_UNSIGNED_SHORT, m_pIndex ); // ***************************************************************** // Restore State #0 - Fog Map. // *****************************************************************
That will take the fogging out of the non-shader fallback code and put it in for both.
There is a slight issue with the edge of the visible waterblock, but it's a lot less noticeable than before.
#134
Thanks
12/06/2006 (6:16 pm)
Well I got it to compile ok using cg 1.5 and tge 1.5 and it seems to work fine was just wondering in the FPS Starter kit / Strong hold demo when you look into the water I see a blue and cloudy sky even though in reality the sky is stormy snowing. Also when you look up from under the water you see the sky as blue and cloudy as well. Any Ideas.Thanks
#135
philippe@josie:~/cvs/torque15$ make
--> Linking out.GCC4.DEBUG/torqueDemo_DEBUG.bin
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/libCgGL.so: undefined reference to 'glXGetCurrentDisplay'
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/libCgGL.so: undefined reference to 'glXQueryExtensionsString'
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/libCgGL.so: undefined reference to 'glXGetProcAddressARB'
collect2: ld returned 1 exit status
make[1]: *** [out.GCC4.DEBUG/torqueDemo_DEBUG.bin] Error 1
make: *** [default] Error 2
how to solve it ?
Philippe C
12/10/2006 (1:43 pm)
When I compile CG Gamma & water on Linux with tge 1.5 i got the following errors message during linking with ubuntu dapper:philippe@josie:~/cvs/torque15$ make
--> Linking out.GCC4.DEBUG/torqueDemo_DEBUG.bin
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/libCgGL.so: undefined reference to 'glXGetCurrentDisplay'
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/libCgGL.so: undefined reference to 'glXQueryExtensionsString'
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/libCgGL.so: undefined reference to 'glXGetProcAddressARB'
collect2: ld returned 1 exit status
make[1]: *** [out.GCC4.DEBUG/torqueDemo_DEBUG.bin] Error 1
make: *** [default] Error 2
how to solve it ?
Philippe C
#136
i did post a thread about it in the TGE/linux section though
also above i posted some info about it
i have TGE 1.5, and Cg 1.5
mostly there were alot of case sensativity issues (explained above) and i had to change the way it links (explained on the TGE/linux forum)
12/11/2006 (9:47 am)
i managed to get everything working on linux, but im not at home atm and cant tell you exactly what all i didi did post a thread about it in the TGE/linux section though
also above i posted some info about it
i have TGE 1.5, and Cg 1.5
mostly there were alot of case sensativity issues (explained above) and i had to change the way it links (explained on the TGE/linux forum)
#137
GL_FUNCTION(void*, glXGetProcAddressARB, (const GLubyte *procName), return NULL; )
GL_FUNCTION(void*, glXGetCurrentDisplay, (void), return NULL; )
GL_FUNCTION(void*, glXQueryExtensionsString, (void *dpy, int screen), return NULL; )
it is OK the binary is generated.
But when I launch the demo now I get a core dump :
....
fxFoliageReplicator - Approx. 0.36Mb allocated.
fxFoliageReplicator - Lev: 2 PotNodes: 21 Used: 20 Objs: 16807 Time: 0.3990s.
fxFoliageReplicator - Approx. 1.83Mb allocated.
fxFoliageReplicator - Client Foliage Replication Startup is complete.
*** Phase 3: Mission Lighting
Lighting mission....
%
//-----------------------------------------------
Synapse Gaming Lighting Pack
%
Starting scene lighting...
Starting TGE based scene lighting...
Lighting with light #1 (TGE vector light)...
Lighting object 1 of 1...
Object lighting complete (1.387 seconds)
TGE based scene lighting complete (1.614 seconds)
Starting Synapse Gaming Lighting Pack scene lighting...
Lighting object 1 of 1...
Object lighting complete (0.015 seconds)
Synapse Gaming Lighting Pack scene lighting complete (1.996 seconds)
%
Lighting Pack lighting system stats:
Interior Lexel Count: 0
Interior Lexel Time: 0.000000
Interior Object Count: 1
Interior Object Included Count: 0
Interior Object Illumination Count: 0
Interior Surface Included Count: 0
Interior Surface Illumination Count: 0
Interior Surface Illuminated Count: 0
Interior Occluder Count: 0
Terrain Lexel Count: 0
Terrain Lexel Time: 0.000000
Successfully saved mission lighting file: 'starter.fps/data/missions/cpdemo1_460ad9dd.ml'
Scene lighting complete (2.528 seconds)
//-----------------------------------------------
%
Mission lighting done
Mapping string: MissionStartPhase3Ack to index: 2
Mapping string: MissionStart to index: 11
Mapping string: SyncClock to index: 12
Could not locate texture: starter.fps/data/shapes/player/crossbow
Could not locate texture: starter.fps/data/shapes/player/clip
*** Initial Control Object
CG:callback2 set
% Segmentation fault (core dumped)
12/12/2006 (12:25 pm)
Now the linking works , i have added these 3 lines to platform/GLCoreFunc.h : GL_FUNCTION(void*, glXGetProcAddressARB, (const GLubyte *procName), return NULL; )
GL_FUNCTION(void*, glXGetCurrentDisplay, (void), return NULL; )
GL_FUNCTION(void*, glXQueryExtensionsString, (void *dpy, int screen), return NULL; )
it is OK the binary is generated.
But when I launch the demo now I get a core dump :
....
fxFoliageReplicator - Approx. 0.36Mb allocated.
fxFoliageReplicator - Lev: 2 PotNodes: 21 Used: 20 Objs: 16807 Time: 0.3990s.
fxFoliageReplicator - Approx. 1.83Mb allocated.
fxFoliageReplicator - Client Foliage Replication Startup is complete.
*** Phase 3: Mission Lighting
Lighting mission....
%
//-----------------------------------------------
Synapse Gaming Lighting Pack
%
Starting scene lighting...
Starting TGE based scene lighting...
Lighting with light #1 (TGE vector light)...
Lighting object 1 of 1...
Object lighting complete (1.387 seconds)
TGE based scene lighting complete (1.614 seconds)
Starting Synapse Gaming Lighting Pack scene lighting...
Lighting object 1 of 1...
Object lighting complete (0.015 seconds)
Synapse Gaming Lighting Pack scene lighting complete (1.996 seconds)
%
Lighting Pack lighting system stats:
Interior Lexel Count: 0
Interior Lexel Time: 0.000000
Interior Object Count: 1
Interior Object Included Count: 0
Interior Object Illumination Count: 0
Interior Surface Included Count: 0
Interior Surface Illumination Count: 0
Interior Surface Illuminated Count: 0
Interior Occluder Count: 0
Terrain Lexel Count: 0
Terrain Lexel Time: 0.000000
Successfully saved mission lighting file: 'starter.fps/data/missions/cpdemo1_460ad9dd.ml'
Scene lighting complete (2.528 seconds)
//-----------------------------------------------
%
Mission lighting done
Mapping string: MissionStartPhase3Ack to index: 2
Mapping string: MissionStart to index: 11
Mapping string: SyncClock to index: 12
Could not locate texture: starter.fps/data/shapes/player/crossbow
Could not locate texture: starter.fps/data/shapes/player/clip
*** Initial Control Object
CG:callback2 set
% Segmentation fault (core dumped)
#138
http://www.garagegames.com/mg/forums/result.thread.php?qt=53032
this ways simpler, easier (probably a tad faster) less complex, and best of all, it works ;)
12/13/2006 (9:34 am)
here do this insteadhttp://www.garagegames.com/mg/forums/result.thread.php?qt=53032
this ways simpler, easier (probably a tad faster) less complex, and best of all, it works ;)
#139
warning message :
#######CG ERROR:Failed to initialize Frag shader! Hardware doesn't support any of the Frag shading extensions!
12/13/2006 (10:59 am)
Ok it works now but ... see picture belowwarning message :
#######CG ERROR:Failed to initialize Frag shader! Hardware doesn't support any of the Frag shading extensions!
#140
12/13/2006 (12:20 pm)
That means it's time to upgrade your video card to one that support Pixel Shaders. 
Torque Owner Bardur Mikladal
Well i now added you to MSN..
lets talk about it tomorrow
I