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.
#21
08/09/2006 (1:11 pm)
okay, just played around with them. and i'm just comparing what i can do with GL DRL, and CG DRL. I'm trying to get this bloom effect from the original GL DRL.

www.geocities.com/tsune_l/gl.jpg
But the best i can do with the CG DRL is:

www.geocities.com/tsune_l/cg.jpg
any idea's? or does the CG one currently not support that function yet.
#22
08/10/2006 (4:51 pm)
I'm not sure what you mean - there is a bloom effect in the CG implementation.

setBloomStrength() will let you adjust how strongly it shows up (its not that accurate - it only adjusts the strength of bloom, and not how far it extends)

edit: Hm something seems to be wrong - basically if you setbasestrength(0) and setbloomstrength(100) you should see whats getting added, but you only end up with base picture...

edit2: wow do I feel like a dolt.
line 745, scenestate.cc
--> glBindTexture(GL_TEXTURE_2D, gClientSceneGraph->g_uiSceneTex);
should be commented out
--> // glBindTexture(GL_TEXTURE_2D, gClientSceneGraph->g_uiSceneTex);
I'll have an updated resource posted soon

edit3: updated. see how overrated bloom is, no one noticed for so long... :p
#23
08/10/2006 (6:17 pm)
lol. The main think i like about the DRL res, is the bloom effect. I'll comment out the code, and see how it works. Also, by any chance, will you be implementing an Anti Alias effect for TGE? that would be an awesome implementation.

Edit:
Now. this is much better. sample blur works good now too. I think i will be using this over the gl base one. :) Just going to add proper underwater reflection, and i'm good to go :). I'll post the code online with full water working soon.

Edit:
Okay, the underwater Code runs great with this. I have uploaded the code online, Paul, i recommend adding this code to your res, and upload it on your next update.

Also, is there a slow down on the DRL? like setChangeRate in Alex DRL?

www.geocities.com/tsune_l/uw1.jpg
www.geocities.com/tsune_l/underwater.zip

edit:
Also Is there a way you can get it to be brighter? it seems pretty dark.
#24
08/10/2006 (8:42 pm)
setBaseStrength(default = 100) adjusts the brightness of the base picture.
setBloomStrength(default = 50) adjusts the brightness of the bloom addition.
#25
08/10/2006 (8:48 pm)
well i mean less vivid, or rich in color. refer to the bloom pic above.
#26
08/10/2006 (9:00 pm)
increasing setMinOverexposure(default 0.50) should probably do it.

edit: nope, that didn't work.

edit2: okay, to a certain extent, this is working against the goal of DRL, but its all a matter of taste I guess.
Anyways, in gamma_ramp.cg,
==> const float BiasMax = 0.5f;
change it (no idea why its named that way - coming from GG4)
==> const float BiasMax = 0.0f;
or something similar.

I'll make this more accessable in the future.

Also I found a few bugs in the console to fix
#27
08/10/2006 (11:49 pm)
okay, well when i setMin, to 1, it stop the DRL. which sometimes i want. but when i set it back to 0.5, it gets really overexposed, when i look up to the sky.

Edit:
Also, could you list all the functions for this Resource, because in the readme, i didnt see the setMin, or Max in it.
#28
08/11/2006 (12:03 am)
Ya. The console function is currently broken - I used atoi() instead of atof(). oops.
Try something in between, like 0.90 or so.

Updated, with a readme update
#29
08/11/2006 (12:13 am)
what file did you forget to modify it in? sky.cc? if so, still didnt change anything. eitherway, if it is converting it to an int, giving a value of 0.9 wouldnt do anything.

Edit:
Okay, works great now. But you broke the underwater code. Trying to fix it right now.
#30
08/11/2006 (12:32 am)
The console functions were in scenegraph.cc.
#31
08/11/2006 (12:42 am)
Water Fix:

SceneGraph.cc
Line: 276 Change to:
pBaseState->mFlipCull = mReflectPass && !mCameraSubmerged;

SceneGraph.h
Line: 151 Add:
bool mCameraSubmerged;
#32
08/11/2006 (10:27 am)
Just implemented the interior dot3 bump mapping to this resource. Works good, only with Nvidia cards tho, still getting flickerings with the ATi's. anywayone want to take a look at the code, add me to aim.
#33
08/17/2006 (8:40 pm)
Updated with a merged example/code archive at top. Do NOT download the garagegames hosted file.
#34
09/14/2006 (7:51 pm)
@Paul, this is really awesome! works like a charm!

BTW, I'd like to allow my players to turn on/off these effects according to their system. Can you give me a hint from where to start? I'd like to make it possible to turn on/off one of them or all of them.

Thank you so much for your resource.

Hongjin
#35
09/17/2006 (6:00 pm)
DRL(true/false) - Toggles whether or not the DRL effect is active
#36
09/18/2006 (7:22 am)
@Paul;
It seems like I wasted your time with my poor knowledge. I had to spend more time with your code.
But you really helped me with your answer. Thank you so much for that!

Hongjin
#37
09/20/2006 (3:30 pm)
BUG FIX:

If you are experiencing color banding on an ATI card, go to engine\sceneGraph\sceneGraph.cc

In SceneGraph::captureScreen

change

glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, mTextureWidth/scale, mTextureHeight/scale, 0, GL_RGB, GL_UNSIGNED_INT, 0);

TO:

glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB[b]8[/b], mTextureWidth/scale, mTextureHeight/scale, 0, GL_RGB, GL_UNSIGNED_INT, 0);

---------------------
MORE PRONOUNCED BLOOM

Go into cg/glow_blur_fp.cg and REPLACE your current fout calls with

fout.col += tex2D(tex0, vin.tex0 + float2(-7 * step_width, -7 * step_height) * float2(texel_width, texel_width)) * 0.1f;
	fout.col += tex2D(tex0, vin.tex0 + float2(-6 * step_width, -6 * step_height) * float2(texel_width, texel_width)) * 0.1f;
	fout.col += tex2D(tex0, vin.tex0 + float2(-5 * step_width, -5 * step_height) * float2(texel_width, texel_width)) * 0.1f;
	fout.col += tex2D(tex0, vin.tex0 + float2(-4 * step_width, -4 * step_height) * float2(texel_width, texel_width)) * 0.1f;
	fout.col += tex2D(tex0, vin.tex0 + float2(-3 * step_width, -3 * step_height) * float2(texel_width, texel_width)) * 0.1f;
	fout.col += tex2D(tex0, vin.tex0 + float2(-2 * step_width, -2 * step_height) * float2(texel_width, texel_width)) * 0.15f;
	fout.col += tex2D(tex0, vin.tex0 + float2(-1 * step_width, -1 * step_height) * float2(texel_width, texel_width)) * 0.25f;
	fout.col += tex2D(tex0, vin.tex0 + float2(0, 0) * float2(texel_width, texel_width)) * 0.5f;
	fout.col += tex2D(tex0, vin.tex0 + float2(1 * step_width, 1 * step_height) * float2(texel_width, texel_width)) * 0.25f;
	fout.col += tex2D(tex0, vin.tex0 + float2(2* step_width, 2 *step_height) * float2(texel_width, texel_width)) * 0.15f;
	fout.col += tex2D(tex0, vin.tex0 + float2(3 * step_width, 3 * step_height) * float2(texel_width, texel_width)) * 0.1f;
	fout.col += tex2D(tex0, vin.tex0 + float2(4 * step_width, 4 * step_height) * float2(texel_width, texel_width)) * 0.1f;
	fout.col += tex2D(tex0, vin.tex0 + float2(5 * step_width, 5 * step_height) * float2(texel_width, texel_width)) * 0.1f;
	fout.col += tex2D(tex0, vin.tex0 + float2(6 * step_width, 6 * step_height) * float2(texel_width, texel_width)) * 0.1f;
	fout.col += tex2D(tex0, vin.tex0 + float2(7 * step_width, 7 * step_height) * float2(texel_width, texel_width)) * 0.1f;

This adjusts the blur radius to seven pixels. You can add more calls in the same pattern to make the bloom even more pronounced. Be sure to set your bloom strength down when you do this. I would reccommend setBloomStrength(30);


Glad to help

-Griff
#38
09/21/2006 (9:45 am)
Nice Griff, I didnt notice the color bug on my ATI card, but i did notice it on my buddies 9800 pro. For the bloom, thats awesome, going to have to check it out.
#39
09/22/2006 (10:46 am)
Thats what I love about CG - modifying the shaders is dead simple once you figure it out. :)

Eagerly waiting for 1.5 so I can update :)
#40
09/23/2006 (6:21 pm)
This is a nice little resource! One thing I noticed, is the DRL seems to adjust by whatever I have my cursor pointed at, rather than sample the screen and measure brightness/darkness of the whole scene. Is that how this is supposed to function or did I goof something up when adding this?