Game Development Community

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;
Page«First 12 13 14 15 16 17 18 Next»
#341
10/18/2007 (5:35 am)
Or better, if you want to reload the shader automatically, add

Con::setBoolVariable("$shaderloaded", false);

at the end of GL_EXT_Init, bevore "return true" ;)

PS: Windows only ;)
#342
11/18/2007 (8:29 am)
I've almost got this working in tge 1.5
I have the following error that I cant figure out how to fix. Any help would be appreciated.

fluidRender.cc
..\engine\terrain\fluidRender.cc(408) : error C2039: 'X' : is not a member of 'Point3F'
        ../engine\math/mPoint.h(265) : see declaration of 'Point3F'
..\engine\terrain\fluidRender.cc(409) : error C2039: 'Y' : is not a member of 'Point3F'
        ../engine\math/mPoint.h(265) : see declaration of 'Point3F'
..\engine\terrain\fluidRender.cc(410) : error C2039: 'Z' : is not a member of 'Point3F'
        ../engine\math/mPoint.h(265) : see declaration of 'Point3F'

Any ideas?
#343
11/26/2007 (7:04 am)
My project need implement a new water rendering system and I try borrow the code and shader from the Cg water resource without success. Anyone who know how the resource work can help explain the shader code is welcome.
#344
04/20/2009 (8:41 am)
Hey!
Is this project still supported? It's a great resource but I've run into a snag with it. Problem is that the water resource crashes the game when running in fullscreen and switching resolution or alt-tabbing out of the game. The cause of the crash is that the texture can't be recreated. It occurs in TextureManager::resurrect() when texFileName is NULL.
GBitmap *bmp = loadBitmapInstance(probe->texFileName);
AssertISV(bmp != NULL, "Error resurrecting the texture cache.\n"
                   "Possible cause: a bitmap was deleted during the course of gameplay.");
I am using version 1.5.0 of TGE.
Did anyone else have this problem with the resource? I'd really appreciate any help with solving this problem.
#345
10/28/2009 (11:18 am)
Does this work with Version 1.5.2? I tried it myself and got 55 errors (I HAVE changed the include line).
#346
12/24/2009 (6:26 am)
Okay not trying to necro,but it took my novice programming butt several hours to figure out what was up. Hopefully this will save someone else the time. This is using TGE 1.52+afx.

To fix the 01.fluidRender.cc issue just change the X Y Z that it mentions to lower case.
02...\engine\terrain\fluidRender.cc(408) : error C2039: 'X' : is not a member of 'Point3F'
03. ../engine\math/mPoint.h(265) : see declaration of 'Point3F'
04...\engine\terrain\fluidRender.cc(409) : error C2039: 'Y' : is not a member of 'Point3F'
05. ../engine\math/mPoint.h(265) : see declaration of 'Point3F'
06...\engine\terrain\fluidRender.cc(410) : error C2039: 'Z' : is not a member of 'Point3F'
07. ../engine\math/mPoint.h(265) : see declaration of 'Point3F'


Not sure what the 55 errors are but if they are the same ones I had then it could be the need to comment out a second spot of code in the cgGL.h file around line 100. Comment out these two lines fixed the cgGL.h errors.
#else
#include <GL/gl.h>
#347
01/11/2010 (11:18 pm)
I can't seem to get my water NormalMap to show up in the media area on the editor. Anyone else have this problem?
Page«First 12 13 14 15 16 17 18 Next»