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;
#141
05/11/2006 (12:41 am)
@SphyxGames:

Maybe its the point.. ^^ :D
I have a full water levels, cause the game that i code actually is 70% inside the water ^^

Its a 2048x2048x~100-quader ^^ -.-

I have a Windows XP SP2 Athlon 64 3500+ 1GB Ram 2x6600GT - System

PS: You are right! have tested this level without shader -.-
Is it water block?! i have only a few objects (ca 12k polys) and a 2048x2048 map+water block... it drop my system down to <20 frames oO
in my main menue i get 600+++ frames
strange...

PPS: Its seems to be really the water block, its drop my framerate to 40% without any shader oO ..

PPPS: Has someone get it to work underwater? Havent try actually get this to work, but still a thing that need to be done ;)
#142
05/11/2006 (2:20 pm)
Thanks ! I'm going to implement this tonight ! It's very cool.

Could someone please tell me what's the best most current nVidia graphics card to buy for Windows ?
I've currently got an old ti4200 128mb.

Thanks
#143
05/11/2006 (6:36 pm)
Quote:
Could someone please tell me what's the best most current nVidia graphics card to buy for Windows ?
I've currently got an old ti4200 128mb
7900 GTX, 512mb. Appx $500 on Newegg.
#144
05/12/2006 (7:50 am)
woah.. go away for a couple of months and look what happens!!..
#145
05/12/2006 (2:57 pm)
For anyone having problems with grass and foliage not animating:

Go to the prepRenderImage method in both fxGrass and fxFoliage and add this right in the beginning:

if (state->mFlipCull) return;

That'll prevent the grass from rendering during the reflection pass. The grass and foliage will stop animating if they are rendered more than once per frame, because doing so messes up with their time-update code.

You can also do the same for any types of objects you don't want to render in the reflection, for performance purposes, as example.
#146
05/12/2006 (3:54 pm)
Thanks a lot Manoel, that did the trick! :)
#147
05/12/2006 (6:11 pm)
@Manoel,

Does this go in the prepRenderImage, or renderObject? I kept getting a "must return a value" error in prepRenderImage, but when I dropped it in renderObject it compiled fine, foliage sways and water is fine. Then again, maybe I misunderstood where it was suppose to go in the first place! =P

- Alan
#148
05/12/2006 (7:12 pm)
Use:

if (state->mFlipCull) return false;
#149
05/12/2006 (9:22 pm)
@Peter, Thank You
- Alan
#150
05/16/2006 (10:40 am)
Anybody know how to get mouse clicks to work over the new playgui.gui? In other words I am trying to select targets via mouse clicks, the problem is the new gui prevents mouse intervention with the objects in the world.
#151
05/16/2006 (10:50 am)
Did anyone fix the sometimes occuring issue with the waterblock not rendering, where it only shows gray fog? I've merged this twice now and fixed the canonical error I was receiving now I'm at a loss as to why its doing what it's doing now.

Thanks,

- Jon
#152
05/16/2006 (12:53 pm)
@Jon Ferris
There are so many comments on this above
#153
05/16/2006 (12:54 pm)
@Jon Jorajuria -

try changing the control to have "modal=false".
i believe you can do this either in the profile or the control itself.
#154
05/16/2006 (1:35 pm)
thanks for the response Orion...unforunately I tried that and it didn't work.
#155
05/16/2006 (1:41 pm)
Huh.
I'm surprised this is causing you headache actually,
i've also got mouse-move and -click events being captured by gui's
but the addition of the new GameTSCtrl didn't cause them any grief.

You could try putting the new GameTSCtrl after the old one ?
#156
05/16/2006 (6:28 pm)
OOPS,

my mistake!

we're having the same issue Jon describes.

i guess i was so awestruck by the water that i didn't actually try clicking on anything!

unfortunately i have other items piled high on plate above integrating the water resource,
so please let us know if you discover something!
#157
05/22/2006 (4:13 am)
Is this ressource working with the cvs HEAD and linux ?
I have a segmentation fault when calling initShader in fluidRender.cc on the following line.
cgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
I have tested all the examples from cg toolkit and all are working.
Some cg functions seems to work like "context = cgCreateContext();", but as soon as I try to access to the profile, the program crash.

Thanks for the help.
#158
05/22/2006 (7:34 am)
had someone make it to work underwater too?
#159
05/24/2006 (9:44 am)
hmmm...recompiled tge...the water upgrade worked great so far - weird thing is that it doesn't work anymore - not even after merging it with a clean 1.4. Not a single object is being reflected - only the sky like it was a view-angel-dependent texture atop the waterblock :(
What can I do?
#160
05/24/2006 (11:00 pm)
make sure you have configured the playgui correctly