Game Development Community

dev|Pro Game Development Curriculum

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:
img66.imageshack.us/img66/43/drl1none5jc.th.jpgimg91.imageshack.us/img91/9994/drl13ij.th.jpg

Outdoor Before/After
img114.imageshack.us/img114/8752/drl3none8at.th.jpgimg89.imageshack.us/img89/9531/drl32nn.th.jpg

Night Before/After
img380.imageshack.us/img380/1152/drl5none7iw.th.jpgimg130.imageshack.us/img130/5092/drl53lc.th.jpg

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.
#141
12/13/2006 (5:54 pm)
Can anyone who's actually gotten this to work properly under linux please drop me a line.
I can get it to compile and run just fine, but when I enter the mission no water is being rendered at all in fact no water appears to exist at all.

I get a Cg Error: Invalid Handle (NULL) or something to that effect.

This is with a stock TGE 1.5 with Cg 1.5 stable (other Cg demos run like a top)
OS is Ubuntu Edgy, vid card is Nvidia 6100.
Anyways if anyone has gotten this fully functional under linux I would love to figure out what the difference is.

My email is smorrey@gmail.com
Thanks in Advance.
Regards,
Dreamer
#142
12/13/2006 (10:50 pm)
Dropped into TGE 1.5 + Server Side Melee + CG DOT3.
Works great on Windows.
Thx a million!
#143
12/14/2006 (12:02 pm)
whats CG DOT3?

ill post more info on everything you have to do to get it to work on linux later

i have Ubuntu Dapper still. nvidia 6800 with latest release drivers, Cg 1.5, TGE 1.5
everything works great!
#144
12/21/2006 (8:48 pm)
CG DOT3, is a Dot3 bumpmap mod for interior objects in Torque.

@BrokeAss Games
Does your Dot3 code work fine with the ATI cards? or are you running it on an nvidia card?
#145
01/10/2007 (12:44 am)
Here is a link to the CG DOT3 resource:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=6431

Also, for those in the community that think this will be plug-n-play, think again. It takes some reworking/rewriting to get it to work depending on your TGE distro. If you get the CG Water resource working, the CG DOT3 resource should be easier to impliment.
#146
01/11/2007 (12:19 pm)
but is buggy with the ATi cards. works great in the nvidia cards tho
#147
01/18/2007 (3:08 pm)
i can't get it to compile it takes me to this line

GBitmap *bitmap = new GBitmap(updateRect.extent.x, updateRect.extent.y, false, GBitmap::BitmapFormat::RGB);

and says:

`GBitmap::BitmapFormat' is not an aggregate type

how do i fix it?

i got it fixed, by changing

GBitmap *bitmap = new GBitmap(updateRect.extent.x, updateRect.extent.y, false, GBitmap::BitmapFormat::RGB);

to

GBitmap *bitmap = new GBitmap(updateRect.extent.x, updateRect.extent.y, false, GBitmap::RGB);

but now when i run torque everything thats not a part of a GUI is just white. if more information will help, I'm on a power mac G5 (before the intel macs came out) and i have no idea how to check what kind of graphics processor i have, or audio processor for that matter... does anyone here know why it has this problem? or how i can find out what kind of graphics processor i have & if i can get a new one if its not right.

also i can only compile the torque demo debug, the other has allot of errors about how a constructor is missing.
#148
01/22/2007 (6:16 pm)
@Patrick.

Ugh. I'm sorry to hear that. I haven't tested the code on macs.

Theres are some console functions that you can use to test it though:

DRL(false); will turn it off, which should bring it to a normal (with water reflection) state.

Has anyone read this weeks VGcats? Hey! I resemble that remark!

www.vgcats.com/comics/?strip_id=224

I haven't had much free time recently (new job and home) but I've been looking into the framerate bottleneck on this, and there just aren't enough cpu cycles to go around... :(
#149
01/25/2007 (11:12 am)
when i use DRL(false);
it's not white anymore, but there isn't any water either.

also i like the brown part of the background in 3rd panel of that comic, i can only assume that's supposed to be earth, but would it be possible to make torques terrain render like that, without completely rewriting it?
#150
01/28/2007 (11:58 pm)
Well the water is a different issue - DRL and water are actually separate code - I just included Manuel's water resource because it uses the CG shaders. The water doesn't work on my 9700 radeon mobility laptop either, so I'm assuming theres a shader compatibility thing there somewhere.

When I get loose, I'll polish up my current version and post it, then restart from near-scratch. What I had envisioned was an overall CG shader resource to make adding shaders easier, but now I know better - I see what Alex "Delerium" Scarborough meant by this place being a really stupid place to put shader code.

http://www.humus.ca/index.php?page=3D
Gives some really nice sample code for OpenGL and GLSL, and how a shader manager should look like - "renderer" in his framework code.

Note: some of humus' demos won't work right with nvidia cards because of the openGL extentions used.
#151
04/19/2007 (6:03 pm)
I'm getting some compile errors with Torque 1.5.1 and Mac OS X Tiger 10.4.9. I just bought the engine.

I'll try to find out what is happening and I'll post later on. IF anyone has comprehensive steps on how to get it working in OS X, please advice :D

Thanks guys! The patch looks GREAT!!
#152
08/01/2007 (1:59 pm)
So where's the difference between his and the TMK? I guess TMK has extra Interior goodness, but T Squared's space ork looks mighty nice...
#153
10/02/2007 (8:34 am)
Wow. Finally, I got it working! And this time I just copy-pasted the code, no need for a visual merge! It took me about 2 months to realize that the dynamicgamma-1_5 and dynamicgamma were different. Wow, the water looks good!
#154
12/28/2007 (11:34 am)
Edit -> Whoops, wrong resource.... Don't know how that happend
#155
01/02/2008 (5:31 pm)
Looks interesting, while it looks awesome whats the visual hit on this? and has anyone tried this with polysoup or the modernization kit?
#156
01/09/2008 (8:26 pm)
I was able to get this resource working with CG 2.0, TGE 1.5.2, and VS2005 after some merging (finally :))

The source code in dynamic_gamma-1_5.zip (C++, not script) doesn't compile out of the box with TGE 1.5.2 if you just overwrite the files without merging them. The biggest issue is that several methods in 1.5.2 were changed to be "const" and the dynamic_gamma-1_5.zip 1.5 based code doesn't take this into consideration. This was mostly a problem in sceneGraph.h/cc and sceneState.h/cc. If anyone is having issues with this I'd be happy to post my changes.

It looks great by the way, thanks to all that contributed - eye candy!
#157
02/27/2008 (6:34 am)
Hi BiffF,

I am very interested in you TGE 1.5.2 implementation.
Could you post the changes.
#158
04/08/2008 (4:17 pm)
Jesus Christ, macCarbGL.cc is hell to merge.

Please, Bill, POST YOUR CHANGES!
#159
04/11/2008 (8:04 pm)
Ok here are the changes I made to make it build with TGE 1.5.2. I'll assume you've overwritten the files from dynamic_gamma-1_5.zip into your 1.5.2 code base.

@Maddermadcat
I built for the win32 platform so this won't cover other platform issues, including macCarbGL.cc
I'll be willing to look at the build issues that you have and give suggestions if I can.


scenegraph.h

after
void buildFogTextureSpecial( SceneState *pState );

add
void getFogCoordData(F32 &invVisibleDistance, F32 &heightOffset, F32 &invHeightRange) const;

after

inline void SceneGraph::setBaseCameraPosition(const Point3F& p)
{
   mBaseCameraPosition = p;
}

add

inline void SceneGraph::getFogCoordData(F32 &invVisibleDistance, F32 &heightOffset, F32 &invHeightRange) const
{
   invVisibleDistance = mInvVisibleDistance;
   heightOffset = mHeightOffset;
   invHeightRange = mInvHeightRange;
}



scenestate.cc

replace
F32 SceneState::getHazeAndFog(float dist, float deltaZ)

with

F32 SceneState::getHazeAndFog(float dist, float deltaZ) const

replace
Vector<FogBand> *band;
with
const Vector<FogBand> *band;

replace
FogBand &bnd = (*band)[i];
with
const FogBand &bnd = (*band)[i];



sceneState.h

after
void setupBaseProjection();

add
/// Returns the scale of the distance based fog [used for haze]
   F32 getFogScale() const { return mFogScale; }

replace
F32 getVisibleDistance();

with
F32 getVisibleDistance() const;

replace
F32 getFogDistance();
with
F32 getFogDistance() const;

replace
F32 getHazeAndFog(float dist, float deltaZ);
with
F32 getHazeAndFog(float dist, float deltaZ) const;

after
Vector<FogBand> *getPosFogBands() { return &mPosFogBands; }
add
const Vector<FogBand> *getPosFogBands() const { return &mPosFogBands; }

after
Vector<FogBand> *getNegFogBands() { return &mNegFogBands; }

add
const Vector<FogBand> *getNegFogBands() const { return &mNegFogBands; }

replace
inline F32 SceneState::getVisibleDistance()
with
inline F32 SceneState::getVisibleDistance()const

replace
inline F32 SceneState::getFogDistance()
with
inline F32 SceneState::getFogDistance() const


mathutils.h
replace
void transformBoundingBox(const Box3F &sbox, const MatrixF &mat, Box3F &dbox);

with
void transformBoundingBox(const Box3F &sbox, const MatrixF &mat, const Point3F scale, Box3F &dbox);


fluidQuadTree.cc

replace
all references of .z to .Z
replace all m_Eye.x with m_Eye.X
replace all m_Eye.y with m_Eye.Y

replace
pV->XYZ.set( X, Y, Z );

with
pV->XYZ.X = X;
    pV->XYZ.Y = Y;
    pV->XYZ.Z = Z;
#160
04/16/2008 (12:58 pm)
You have :
replace all m_Eye.x with m_Eye.X
replace all m_Eye.y with m_Eye.Y
replace all m_Eye.x with m_Eye.Z

Should
replace all m_Eye.[b]x[/b] with m_Eye.Z
be
replace all m_Eye.[B]z[/b] with m_Eye.Z
?