Game Development Community

dev|Pro Game Development Curriculum

TGE water upgrade

by Manoel Neto · 07/03/2006 (11:33 am) · 347 comments

Download Code File

This resource adds basic pixel shader and vertex shader support to the TGE waterblock, using CG, and support for drawing a reflected view of the world into a texture and using it in the waterblock. Right now it's windows-only, but there's nothing stopping you from making it work on OSX and Linux, since CG is also avaliable in those platforms.

Note: For those worrying about Cg being Nvidia-only, fear not, I've personally tested it in different ATI cards and it's compatible with no visible performance problems. Just make sure your drivers aren't ancient.

Note2:
Alex Scarborough (of the TLK DRL fame) is working on porting this resource to GLSL and making it work on OSX. Might get some news soon.

Installing the source changes:

First you'll need the CG toolkit. You can get it here:
developer.nvidia.com/object/cg_toolkit.html

After installing it you must modify the TGE project to include the Cg/lib and Cg/include folders to the library paths and the include paths, respectively.

Important: you also need to open cgGL.h in the "Cg/include" folder and replace this:
#include <GL/gl.h>
By this:
#include <dgl/dgl.h>
Otherwise you'll get loads of compile errors.

Included in the zip file are the modified source files. To install into a unmodified TGE 1.4, just replace the TGE files by the ones included. To install in modified TGE sources, use a merge tool, or copy the changes by hand (all changes are comment-tagged), then compile.

Script changes and usage:

The example folder in the ZIP contains the script files you need to actually see the water in the game. The "example/CG" folder must be copied to the same folder as your executable. It contains the vertex and fragment shaders. The filenames are very hardcoded into the source code, unfortunally.

In "example/starter.fps", you'll find a modified playGui.cs and a normal map for using with the water (it's actually one of TSE's water textures).

The modified playGui.cs is required to render the reflection texture. The GameTSCtrl control was modified and now features a flag called "isReflection". Turning it on will make the gameTsCtrl render the world using a reflected camera matrix, based on the first existing waterblock.

Waterblocks will search for a GameTSCtrl called "reflectionGui". If it's found, they'll grab the refleciton texture from it.

Waterblocks also have a new field, called NormalMaptexture. You need a suitable normal map there, otherwise the reflection texture coordinates will be badly displaced.

Known bugs/limitations:

- No refraction support;
- No specular;
- No fog (at most times it looks like the water is fogged, because the reflected scene is fogged);
- No proper support for using a static envornment map instead of a full reflection (it does use the texture, but it remains fixed, and won't rotate along the view, as the original did);
- Sometimes the reflection can go strange and "melt away". Something to do with clip planes;
#181
06/10/2006 (10:52 am)
@Eddie Liu
I believe the reflection only works on TLK.

there also this resource if you want to implement it with the DRL

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10591
#182
06/10/2006 (12:06 pm)
@Eddie
I got a 5700LE and dont use TLK, the reflection works fine , did you forget to add the new playgui.gui ?
#183
06/10/2006 (12:15 pm)
Nevermind I got it in you rock :>
#184
06/11/2006 (5:23 am)
Billy L and T Squared, thank your kindly help, I got it work. the 'starter.fps' example is still no reflection, I don't know why, but when I try to create a waterblok in my new game, hah, It work. thanks again.
#185
06/12/2006 (1:32 am)
Joseph: you need to link libGL just put -lGL in the make file along with the other libs

i actually got it to build completely, compile, link, RUN ON LINUX but as soon as i get into 3d it crashes..
#186
06/12/2006 (4:07 am)
idk if it is just me or what but I can't change the color of it or anything
#187
06/12/2006 (9:55 am)
Could some please help me ? All I see is fog where the water should be.
I've read the post over and over. I copied the files from the tge_water.rar
and I've compiled everything ok, I've checked to make sure that the cg folder
is in the correct location, for some reason it seems like the water texture is not
being applied. I'ts fog

Thanks,
#188
06/12/2006 (10:13 am)
uncheck the remove wet edge box because that's what happens when I check it
#189
06/12/2006 (10:41 am)
@Brian
Color of what? the water? you cant change the color. but you cant change the alpha and the texture of the water.
#190
06/12/2006 (11:31 am)
that sucks because I need to have lava in my game and not being able to control the overall color puts me in a situation :(
#191
06/12/2006 (2:45 pm)
I may be wrong, but can't ever remember seeing reflective lava if that's what you need the resource for. I'd imagine the light it's emitting would be it's most important quality. It'll deaden any reflections in real life anyhow. For example, Just look at your monitor, when it's switched on (ie. emitting light) you see very few reflections, turn it off, reflections......Same thing......I think.....

Have you seen the lava and particles in, I think it's RTS environment pack or something? Very, impressive just using TLK and some good quality textures and lights. It looks really effective.

Just a thought.

h
#192
06/13/2006 (1:04 pm)
Ok, I got it to work but it looks awful, I dont have a good water texture,

can someone give me a nice water texture, mine suck :( and I've tried to make
some but they look like @#!?

And I can't find that normal map thats susposed to be in the tge_water.rar ?

Please...

Thank you, :)
#193
06/13/2006 (1:52 pm)
@Areal Person
its in example/starter.fps/data/water/noise02.png, i dont understand how you can miss it. its the only image file in there.
#194
06/13/2006 (2:25 pm)
@T Squared (Or anyone who can help me)

Ok, I got that. But my water texture still sucks, and I can't make the
water look as good as the screenshots, I don't know what I'm doing wrong :(

Do I need to put in all that reflection stuff from Alex "Delerium" Scarborough up above ? or is it optional ? Is that why the water looks shiney in some areas ? My looks like %#@!..?

Thanks,
#195
06/13/2006 (2:28 pm)
@person - try posting a screenshot ? free image hosting at imageshack.us.
#196
06/13/2006 (3:26 pm)
@Areal Person

For some reason i think you are assigning noise02.png to the water texture not the normal, make sure you assign it to the normal map

http://e2g.50webs.com/normal.jpg
#197
06/13/2006 (7:39 pm)
@T Squared - (Or anyone who can help me)

Ok, I know I've compiled correctly. (VC7) I've linked with CG - no errors.
I've been working on it all night, I KNOW the code is executing, but I cant get the
water modifications to have any effect on the default starter.fps waterblock. (It looks like
it always does). I'm using the correct noise02.png in the NormalMapTexture field. I can set it in
the MissionGroup editor (F11) just like your picture.

my CG folder is located in - C:\Torque\SDK\example\CG
my exe. is located in - C:\Torque\SDK\example\mygame.exe

I'm using a nVidia Gforce4 Ti 4200 128mb.

I installed the PlayerGui.cs also in the correct location. The graphics options will only allow me to select OpenGL, It hides the D3D option now on the startup screen.

The modification simply has no effect ? (slight FPS lag)
What's wrong ?

Everyone is getting that nice wet look, mine just looks the same as always. :(

Thanks,
#198
06/13/2006 (8:08 pm)
Okay, what you are telling me is very strange. can you PLEASE post a screen shot. sometimes a visual picture can help ease the process. like Orion said. go to

imageshack.us and upload your pics there and send us a pic.

ALSO

Try my Resource of the Combined CG Water + DRL working together.

www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10591

Some people find it easier to implement, because it has all the bugs fixed here and there. This requires the TLK tho.
#199
06/13/2006 (9:13 pm)
i cant get this to work, im getting crashes in glGetTex.. something
gl functions.. i think its cause im linking the libGL libraries instead of using whatever built in stuff is going on..
#200
06/14/2006 (3:49 am)
Popped into TGE 1.3 w/ TLK in VC6.
No probs, working absolutely perfect on my geForce4 FX 5600.
Thanks, and CG is pretty damn cool!
Screenshot 1
Screenshot 2


Ari