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;
#221
07/08/2006 (10:42 pm)
those two files are located in the directory you installed the CG API. if you installed it in a different dir. just go to find, and type cgGL.h.

otherwise it would be located in:
C:\Program Files\NVIDIA Corporation\Cg\include\Cg\cgGL.h

Read through all the post commends to figure out all the litte bugs and fixes to get it working for TGE 1.4
#222
07/09/2006 (10:37 am)
i changed the little piece of code in the Nvidia Cg/include folder,
its the...

(you must modify the TGE project to include the Cg/lib and Cg/include folders to the library paths and the include paths, respectively. )

how do I modify the TGE project? does some code needs inserting to a file in the TGE itself to point to
the Nvidia/Cg/include folder? if so which file do I edit?

Apologies for my noobness
#223
07/09/2006 (12:03 pm)
@jojimbo
lol oh that. you must include the path directory for your API, otherwise VC, or whatever compiler your using wont know where the api can be found.

what are you using to compile this? vc8?
if so, go to tool->options->projects and solutions->VC++ Directories.
In that section you should see a drop down box that says "Execuateble files", click on it and change it to "include file". then past the include dir for the cg api, then change it to "libaries files" and do the same, but the lib directory.

if your using another compiler, google it. and you'll find what you need.
#224
07/10/2006 (3:00 am)
Okay, So lets see if I understand this, in the console it is saying it cant find a valid profile, the mission loads, the water block is completly visible (with a nice little foggy reflection) however the main Game graphics are now 1/4 of the screen in the top right corner.

Is this because all I have to play on tonight is my laptop?

Thanks guys

The Trusted One
#225
07/10/2006 (3:14 am)
sorry if I am not clear been up for going on 50 hours now ;) .... yeah for Jolt.

The Trusted One
#226
07/10/2006 (7:05 pm)
hello. Has anyone experienced terrain draw issues after implimenting this resource?
When I load up the game now, the terrain rendering distance is like a foot in front of the player - beyond that there is nothing but water off into the horizon, with my various props appearing to float out in the middle of where the terrain should be.

When I move around in the game, the terrain "pops" up out of no where when I get within a few "feet" of it.

I have re-compiled this resource over and over and it always happens. I may soon become a drama queen... ARRg.
#227
07/10/2006 (7:53 pm)
Hurray ok I have achieved something here.I was a nub and now a super coder...err hehe
My first success YAY I am so chuffed,first time ever made my first successful build AND got
the water to work and here is what I did...especially for teh nubs who know not.

1.Download Visual Express (its still free) and the platform sdk.
2.Install a fresh version of TGE 1.4 SDK follow this guide

http://tdn.garagegames.com/wiki/Torque/vs2k5

3.Do as Manoel says at the start.
4.Make a change under line 703 of Manoels Waterblock C/C++ file by inserting this
"dglSetCanonicalState();" without quotes
5.Build torque again (takes less time as it remembers your uber from last time)

Bob's your uncle,reflecting water

Thank you all so much you uber doods ;)

note1.
while your at it add this to the fxfoliagereplicator.c/c++ at the prepRenderImage section.
"if (state->mFlipCull) return false;" without quotes to force the grass to sway.
#228
07/22/2006 (4:41 pm)
I just ran into some trouble with this when I am looking out through a portal while standing in an interior, the projection goes a little screwy. Having trouble tracking down exactly what the problem is and I've got a very heavily modified TGE 1.3

I wonder if anyone else has seen this problem with their codebase?

thanks for your help
#229
07/22/2006 (5:16 pm)
found a workaround for my problem. I suspected my shader code or something was having trouble with the projection matrix setup for the portal. Instead of finding the problem and making it understand, I just setup the base projection instead of the object projection.
at the top of WaterBlock::renderObject( SceneState* state, SceneRenderImage* )

instead of:
state->setupObjectProjection( this );
use:
state->setupBaseProjection();

again not ideal but it looks correct, I'll see if I can findout exactly why it's not handling it correctly and post back.
#230
07/24/2006 (10:10 am)
What is the status of the GLSL port resource? I have done my own port of this resource to GLSL but if someone else is currently writing a resource for it I don't want to spend the time. Let me know if anyone is currently in the process or if there is anyone still interested in the port.

Thanks,

Jason
#231
07/24/2006 (10:17 am)
Status of GLSL port: It was finished back in early May, but GarageGames asked me not to release it.
#232
07/24/2006 (10:52 am)
Awe... That's interesting.

Did you submit the resource and get denied, or did they ask you to quit before you got that far?
#233
07/24/2006 (11:02 am)
I asked if they would be okay with my releasing a resource that had a GLSL port of this resource, a GLSL port of the interior bumpmap resource, and a GLSL version of DRL, and they prefered that I not release it.
#234
07/24/2006 (11:12 am)
TSE competition...???
#235
07/24/2006 (11:17 am)
Pretty much. Couple of other details that I can't talk about, but competiton with TSE was the main reason I think.
#236
07/24/2006 (11:27 am)
That's funny... TSE doesn't support GLSL (which is why this resource would be so useful to TGE'ers who don't want to wait years for TSE to support OpenGL... if ever). Way to go GG! Repress useful (and free) community contributions, so you can sell your own without any competition. That should really bolster the "community" you're trying to develop here...
#237
07/24/2006 (11:36 am)
I would really like to hear the explanation from someone at GG. I agree from the surface this does not reflect well upon GG and would like to hear the justification. I'm not saying they dont have their reasons, just that they are currently unclear, and because of that people will assume the worst.
#238
07/24/2006 (11:41 am)
I think you guys are jumping to conclusions here. Alex's "details he can't talk about" seem a little suspicious to me, and considering he's working on GLSL, which TSE doesn't support yet... hmmm, makes me wonder...
#239
07/24/2006 (12:30 pm)
I'm basically waiting on a GLSL port, i figure it'll solve the fog problem, since my terrains are mostly land surrounded by water.

Edit: by basically waiting, I mean that the project I'm using it for is not serious enough for me to look particularly hard for any other solution. On the other hand I could still do something for it if I had the time at some point.
#240
07/24/2006 (1:18 pm)
LOL... well, I guess I was willing to take Alex's word for it (without "jumping to conclusions" about any possible lack of truth to his post). His statements seem clear enough (to me at least). What sense would there be in lying about something he's willing to contribute to the community for free...?

Unless GG wants to use his GLSL code in TSE...

(...but THAT really WOULD be "jumping to conclusions, wouldn't it???)

;-)