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.
#41
09/23/2006 (7:24 pm)
No it isn't just you I see it too. Every time I look at the sky and then down it changes the DRL.
#42
09/23/2006 (7:27 pm)
not just the sky, but if i look at a white rock on the ground, and then a black rock, or a cloud, and then a bit of the sky in between, as in the color of the pixel at the center of my cursor... How can we increase the size of the rectangle it samples??
#43
09/24/2006 (10:54 pm)
Well its supposed to sample the whole screen, but I wouldn't say I'd be too surprised to find out that that the sample is messed up.

Because in one part of the code, it is, and I just can't figure it out.

In computeDRL()

glReadPixels(0, (extent.y/scale)-(arraySize/arrayWidth), arrayWidth, arraySize/arrayWidth, GL_RED, GL_UNSIGNED_BYTE, &pixels[0]);

Its a lot smaller sample than it should be, but if you enlarge it, all you seem to get are pure black pixels.
#44
10/26/2006 (9:01 pm)
I got a 1.5 version working, I'll slap it around a little, then post it in a new resource...
#45
10/26/2006 (9:26 pm)
cool. i got it working too. but by any chance. did you happen to have anytime to optimize it a bit more :)

i126.photobucket.com/albums/p117/seijisota/p1.jpgi126.photobucket.com/albums/p117/seijisota/p3.jpgi126.photobucket.com/albums/p117/seijisota/p5.jpgi126.photobucket.com/albums/p117/seijisota/p6.jpgi126.photobucket.com/albums/p117/seijisota/p2.jpgi126.photobucket.com/albums/p117/seijisota/p4.jpg
#46
10/28/2006 (1:06 am)
well i tried to merge tonight

mostly it seemed to be not TOO complicated

one of the asm files left me scratching my head some..
but mostly i dont have a clue at all what the hell to do with fluidRender.cc, the files seem to be pretty drastically different from eachother so i dont want to even try guessing what should stay and what should go...

when do you think youll be posting the updated resource?
hopefully today ;)
#47
10/28/2006 (8:29 am)
Hope you can post the resource, having trouble with the fluidRender as well.
#48
10/28/2006 (11:27 am)
why not try posting your errors?
#49
10/28/2006 (3:06 pm)
well im not even trying to guess on that one, so much code seems to have been moved all around, and i dont know what this code is doing, ill just let the expert handle it ;)
#50
10/28/2006 (11:45 pm)
I found that its not really stuff being moved, if you're using WinMerge, there are changes in the indentation that are giving it fits. Anyhoo, my 1.5 version seems to run okay, posted at top. Just copy into a new 1.5 install, compile, and run..
#51
10/29/2006 (8:18 am)
badass thanks man!
#52
10/29/2006 (9:24 am)
i just compared the code from 1.4 cg with 1.4 stock. found the new methods and toss them into 1.5. bam worked. but i can see Paul already posted it online. good stuff.
#53
10/29/2006 (2:50 pm)
ok i got it to compile and link and all on linux
but as soon as it gets into 3d it crashes

has anyone gotten this to work on linux?
#54
10/29/2006 (11:05 pm)
well i finally got it to build link and run on linux, without crashing

but first run it didnt show cg water or drl

then i noticed playgui.gui wasnt building

the playgui.gui file in the 1.5 resource doesnt compile
so none of the effects are visible i guess.. or maybe my cg stuff just isnt working either

i tried to change the playgui to be like how i thought maybe it should be and i saw a little gui with anupside down render of the world, still no drl, and no water anywhere
#55
10/29/2006 (11:35 pm)
well i tried a few different things with playgui, i am pretty sure i have it setup how its supposed to be

but still no water or drl

i got this error in the console:
#########CG ERROR: CG ERROR : Invalid parameter handle.
(null)


any tips for troubleshooting?

when i use cgc *.cg on the different cg files in the CG directory i get:
error C3004: function "tex2D" not supported in this profile

on almost all of them ;(
that does this mean?
i have a GeForce 6800 GT, and the 1.4 version worked for me on windows

but im trying this on linux now
#56
10/30/2006 (12:20 am)
well after more digging, it wasnt working at the command line cause i wasnt even picking a profile
it seems to work with near every profile so that cant be was messing it up

i tried to debug into that code to see what parameter its talking about as being bad but thats not possible because the code doesnt even run in debug!!

there are tons of fatal assertions, anywhere it checks canonical state after making gl calls

is this just me?
#57
10/30/2006 (5:34 am)
Copied the resource as Paul posted last night into a fresh 1.5 build and it will not load into 3d. playgui.gui is not building. The source appears to build without error though (Cg included).

Windows XP
VS2005
Cg 1.5

Anyone else having these problems?
#58
10/30/2006 (7:24 am)
ya i had the problem with playgui.gui

i basically added an extra
};
to the end, then it built
im not sure if this is the correct thing to do..

try it though and tell me if after that change it works for you
cause its still not working for me on linux
#59
10/30/2006 (10:23 am)
Nope, does not work for me.

starter.fps/client/ui/PlayGui.gui Line: 229 - parse error
>>> Advanced script error report. Line 229.
>>> Some error context, with ## on sides of error halt:
horizSizing = "right";
vertSizing = "top";
position = "50 299";
extent = "32 172";
minExtent = "8 8";
visible = "1";
helpTag = "0";
bitmap = "./healthBar";
wrap = "0";
};

};

//--- OBJECT WRITE END ---
#60
10/30/2006 (12:30 pm)
put an extra }; at the end of the file
therea re two now, add a 3rd
then it should build playgui without error
then see if the effect works for you