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;
#301
10/10/2006 (1:48 am)
ok, cleared the undefined stuff by deleting all cg framework from my mac, installed the 1.5 and followed your step-by-step (actually, i did that from the beginning) to add it to the frameworks, and pressed compile, but now i get:

ld: warning -L: directory name (/System/Library/Frameworks/Cg/Versions/1.0) does not exist

ld: can't locate framework for: -framework Cg

and i've looked at the /system/library/frameworks/cg/version/1.0, and it's there... kinda driving me nuts, this crap... anyone on the mac side who wanna mail me a working setup? seriously... this is disturbing... almost like i need to boot my xbox up, put fight night in the slot and beat something up...
#302
10/10/2006 (2:12 am)
@Alex: Good, that's definitely a start. Now, you don't need a specific library search path for the Cg framework, so don't scratch your head over why the linker seemingly can't find a folder that's really there. Just remove it from your project's settings.

To do that, I think you'll find it if you right-click on your project's root ("torque_xcode_2_2_UB"), select "Get Info", then the "Build" tab, and set "Collection:" to "Search Paths". There you might see the directory name you mentioned; if so, remove it. In my project, all the search paths are empty (i.e. using only the defaults and the specific frameworks included in the project).

If the directory is not mentioned anywhere in that window, you might want to search for it (set the Collection to All Settings and write Cg into the search field to the right). Still no sign of it? Ok...

Next, you can look in each of the Targets' settings; double-click on the "Torque-MacCarb-Release" under "Targets", and select the "Search Paths" view under "Settings" in the left-hand pane. You should see sections for Headers, Frameworks and Libraries (and Java Classes). Remove anything that's under the Libraries heading. Repeat for the Torque-MacCarb-Debug target.

Did you find it?
#303
10/10/2006 (2:49 am)
i only found the last thing, the search path in the targets, but nothing of the earlier you posted (no directory in the build tab, and nothing when i search for it)... still getting the same error when building... and i did a clean all before...
#304
10/10/2006 (3:03 am)
@Alex: Ok, it didn't have to be in all the places I mentioned, just one. And you're sure you deleted it from the places you found it?

Ok, I'm getting close to asking you to follow Stephan's advice anyway, and starting with a clean TGE1.4. One last question, though: Can you recall having done anything else to try to get the Cg.framework to work; any settings, files that you included, or anything like that?

I'm sorry that I can't send you a useful Xcode project file, as the one I have at hand is both older than yours (for TGE 1.4.0, not 1.4.2 [may create problems], and thus without universal binary support [not a big deal] and really made for Xcode 2.1, though updated to Xcode 2.4) and contains too much stuff from our other projects, that I don't have time to remove.

So, I guess you have to continue hunting through every setting, info and panel in Xcode to make sure you get rid of all references to the *library* path for Cg, and *only* include it as a System Framework. Or, do as Stephan says, and try again from a clean source tree. Good luck!
#305
10/10/2006 (5:42 am)
@Erik: thanks for taking some time to by troubles. Nothing special was made. I strictly followed your steps from (Sep 20, 2006 at 20:45 GMT) on this resource.

@Alex+Eric: I'll give another try from the 1.4.0 and will send my updated xcode.project to Alex hoping it will both solve Alex's and my own problems.
Alex, I would recommend we communicte with emails or we will fill the resource with unsollicited stuff. We will post the results on success. Soon. 8-)

Thanks again Erik & people.
#306
10/10/2006 (9:36 am)
The "blue" bug. It might be here:
Warning: (/Users/stephan/tge_water/xcode/../engine/console/consoleObject.cc @ 62) Couldn't find class rep for dynamic class: sgGuiFullScreenFilter

Any idea?
#307
10/10/2006 (11:26 am)
@Stephan,

Do you have TLK or some other lighting-pack/-enhancement installed? Check out Alan's post above here (search for "sgGuiFullScreenFilter" on this page...) for a little hint. I don't have anything called sgGuiFullScreenFilter in my project at all, so I couldn't tell you if that has anything to do with your problems. But it isn't unlikely, I would say... :-)
#308
10/10/2006 (12:15 pm)
@Erik: no, this is plain stock (CVS) TGE.
One possibility might be the 16/9 ratio of the iMac sreen. I ran into some troubles in some rez with some games/applications.
Will check anyway.
#309
10/10/2006 (12:22 pm)
@Stephan,
Ok. It's been a while since I merged TGE from CVS into our own SDK repository, so there may be some changes that has introduced this "sgGuiFullScreenFilter" thingie. I take it there is nothing obviously wrong on line 62 of consoleObject.cc? Are there any other references to the "sgGuiFullScreenFilter" anywhere else in the code? (I know, I should just download from CVS myself... ;-))

I sorta' doubt it's the 16:9 (or is it 16:10?) ratio of the iMac screen. Does the blue tinting occur no matter what resolution you run at, and whether you're in fullscreen or not, or does it only show up in some resolutions/modes?
#310
10/10/2006 (12:33 pm)
@Erik: any resolution, either in window or full screen.
I missed this one in the console.log:
starter.fps/client/ui/PlayGui.gui (0): Unable to instantiate non-conobject class sgGuiFullScreenFilter.
#311
10/10/2006 (12:53 pm)
@Stephan: Ok, then I truly believe that it is very unlikely that this has anything to do with your screen having a 16:10 ratio.

I take it you have a sgGuiFullScreenFilter object defined in your playGui.gui. I believe that *only* applies when you have installed the TLK+DRL resource. So, you should could try to go through your code (both C++-side and .cs-side) and remove any references to sgGuiFullScreenFilter et al. And make sure that you have really merged in the right resource files/fixes in any other way as well... :-) Good luck!
#312
10/12/2006 (6:30 am)
At the moment, the "blue bug" as I call it, happens on intel Mac based only. Once ran with the Rosetta emulator (G4 emulation) the display is correct.
Just have to figure out what's wrong with the intel build...
#313
10/20/2006 (9:44 am)
c:\mmokit-1[1].5.rc2\mmokit1.5rc2\engine\terrain\fluidrender.cc(161) : warning C4700: uninitialized local variable 'BaseDriftY' used
c:\mmokit-1[1].5.rc2\mmokit1.5rc2\engine\terrain\fluidrender.cc(161) : warning C4700: uninitialized local variable 'BaseDriftX' used

can anybody explain those errors to me?

i have no idea how to fix em and they are crashing me when i get to loading the zone :(
#314
10/26/2006 (3:29 pm)
Works in TGE 1.5 :)

www.omnivirtual.com/images/screenshot_003-00002.jpg
#315
10/26/2006 (9:28 pm)
nice. tho its not really much different in code :P
#316
10/27/2006 (6:15 pm)
not sure what is happening in 1.5 as I am not a programmer, but tried to add this and got lots of errors regarding m_terrainsize and similar.

Trenton, could you just do a recap on anything you had to alter to get this to work?

Regards

Graham
#317
11/01/2006 (9:33 pm)
Its here a possibility to check what hardware-shader-version a pc has?
#318
11/03/2006 (12:48 pm)
EDIT: Nothing to see here... carry on
#319
11/11/2006 (1:38 am)
Has anyone had any problems getting the cg.lib to be linked properly using VS 2005? I used to use 2003 and had no problems with it. As soon as I started using VS 2005 and the solution files in the 2005 directory, I get this:

fatal error LNK1104: cannot open file 'cg.lib'

I have gone back over the whole process several times and cannot figure out what is the problem.
#320
11/11/2006 (3:47 am)
It looks like you need to set the directories for the project. I made all of the new cg, and directx directories global . Make sure you have no solution or projects loaded, (I don't know if that matters but it works) Then select Tools on the main menu and select Options at the bottom.
In the dialog box that appears you will see global settings in the left side tree.
Select Projects and Solutions. You said you had 2003 so you should be in familiar territory now.
Hope this helps