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:
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;
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;
About the author
#162
05/25/2006 (7:49 am)
Well I managed to get it working, seems water was partially broken in 1.4. Doesn't like levels with a terrain square size other than 8 so going to have to fix that as well. When will the bugs end :(
#163
don't worry...it's quite normal for such a big project to include some bugs here and there. But we have the sourcecode and therefore can fix any bugs we find ;)
05/25/2006 (8:01 am)
@Timdon't worry...it's quite normal for such a big project to include some bugs here and there. But we have the sourcecode and therefore can fix any bugs we find ;)
#164
Manoel. You are a legend.
If anyone wants to see Mr Netos' water in action. We've created a little teaser trailer for our game at
http://www.stickmanstudios.co.uk/news.html
That's not a plug, just wanted to show how great this resource really is. I can't thank you all enough for the work that's been shared in this forum. A tiny two man game studio can be a lonely place sometimes, but not with you lot on board too 8)
man, there's alot of love in this room.
05/25/2006 (10:18 am)
Well, what can I say. Manoel. You are a legend.
If anyone wants to see Mr Netos' water in action. We've created a little teaser trailer for our game at
http://www.stickmanstudios.co.uk/news.html
That's not a plug, just wanted to show how great this resource really is. I can't thank you all enough for the work that's been shared in this forum. A tiny two man game studio can be a lonely place sometimes, but not with you lot on board too 8)
man, there's alot of love in this room.
#165
@ Kaya Dogan
You are right. However I use several other engines and am used to new builds reducing the bug count, not increasing them. 1.4 of TGE seems to have introduced 100's of new bugs, not 100's of bug fixes as was advertised by GG. If you're making a game (not a puzzle / sports game) that utilizes many of the engines features you will notice just how many things are broken in 1.4 that worked fine in 1.3. Yes I have the source code but the whole reason for me buying an engine was to make a game, not fix someone else's engine. I spend 2 -4 hours a day on my game... 75% of that is bug fixing :(
05/25/2006 (11:11 pm)
Manoel, if you're still following this resource allow me to pass on my extreme gratitude. After playing around with some settings and fixing some bugs this water renders beautifully and without error. Even under water. I don't won't to offend anyone but this water looks better than the shader engine's water and is far more stable. Thanks for all your great work.@ Kaya Dogan
You are right. However I use several other engines and am used to new builds reducing the bug count, not increasing them. 1.4 of TGE seems to have introduced 100's of new bugs, not 100's of bug fixes as was advertised by GG. If you're making a game (not a puzzle / sports game) that utilizes many of the engines features you will notice just how many things are broken in 1.4 that worked fine in 1.3. Yes I have the source code but the whole reason for me buying an engine was to make a game, not fix someone else's engine. I spend 2 -4 hours a day on my game... 75% of that is bug fixing :(
#166
I totaly feel you on the 1.4 thing. Im hoping 1.42 gets released soon to fix all those bugs.
Is there anyway you could post your modified version? Im sure everyone would appreciate that.
Thanks
05/25/2006 (11:20 pm)
@TimI totaly feel you on the 1.4 thing. Im hoping 1.42 gets released soon to fix all those bugs.
Is there anyway you could post your modified version? Im sure everyone would appreciate that.
Thanks
#167
I see. Well...I'm pretty sure GG is aware of most bugs in TGE and will hopefully fix them. TSE is the successor and TGE development will be dropped soon I guess, but I think there's a chance that at least the most critical bugs will be fixed. Of course it's annoying if you have to spend too much time on fixing the engine before getting to work on the actual game. Let's hope GG will release some patches soon :)
05/26/2006 (2:35 am)
@TimI see. Well...I'm pretty sure GG is aware of most bugs in TGE and will hopefully fix them. TSE is the successor and TGE development will be dropped soon I guess, but I think there's a chance that at least the most critical bugs will be fixed. Of course it's annoying if you have to spend too much time on fixing the engine before getting to work on the actual game. Let's hope GG will release some patches soon :)
#168
Yeah 1.4 was a big let down for us. I have a list of most of the crucial bugs and let's just say my pencil has been worn down to a stub. As far as the fixes for this water resource, I only implemented the ones on this page and also a few from the DRL2 resource and a couple of trivial ones I found in the forums. The main thing we had to do to get it rendering correctly was:
- Use a terrain square size of 8. This isn't a flaw of this resource, Torque's water has never worked well with small terrain sqaure sizes; which is a shame as the terrain rendering / texturing in Torque is quite weak.
- Keep your water block size square.
If you're having problems with under water rendering as others have reported, it would most likely be a compiling error or perhaps it's hardware related?
Kaya,
In it's current state I would never waste my money on TSE. So much time has been spent on it by so many people and yet the results don't show.
No lighting and shadowing after 2.5 years, well why have bump mapping if you don't have pixel lighting? Lighting and shadowing must be done first. They will affect how EVERYTHING looks and is the hardest bit of an engine to optimize. Everything must be tied into the core lighting system of an engine which is why I question the future of TSE.
Also, the sound layer has not been touched. Sound is very important to me, and I don't like the idea of buying an engine with a messy code base, no decent audio and only a few trivial eye candy effects. Slapping shadders on top of TGE was a very very bad decision IMO. GG should be fixing the core engine before making other products that are derived from it. They should also stick to one thing at a time, they never seem to get anything finished. All their products are in an 'early adopter' state and have been for years.
Seriously, I've seen the milestone 3 demo's and couldn't believe how poor it was.
In it's current state, poorly otimized, lacking lighting and shadowing, residual unused TGE code all over the place, no OpenGl, crippled audio layer, buggy editors, graphical artifacts, poor frame rate, real time editors which require a nasa computer to run smoothly, datablocks for materials - I wouldn't waste my time.
Having said that, I respect GG and this community and if they were to pull their finger out and bring TSE to the level it should have been at a year age, I would buy it.
05/26/2006 (6:41 am)
Hi Peter & Kaya,Yeah 1.4 was a big let down for us. I have a list of most of the crucial bugs and let's just say my pencil has been worn down to a stub. As far as the fixes for this water resource, I only implemented the ones on this page and also a few from the DRL2 resource and a couple of trivial ones I found in the forums. The main thing we had to do to get it rendering correctly was:
- Use a terrain square size of 8. This isn't a flaw of this resource, Torque's water has never worked well with small terrain sqaure sizes; which is a shame as the terrain rendering / texturing in Torque is quite weak.
- Keep your water block size square.
If you're having problems with under water rendering as others have reported, it would most likely be a compiling error or perhaps it's hardware related?
Kaya,
In it's current state I would never waste my money on TSE. So much time has been spent on it by so many people and yet the results don't show.
No lighting and shadowing after 2.5 years, well why have bump mapping if you don't have pixel lighting? Lighting and shadowing must be done first. They will affect how EVERYTHING looks and is the hardest bit of an engine to optimize. Everything must be tied into the core lighting system of an engine which is why I question the future of TSE.
Also, the sound layer has not been touched. Sound is very important to me, and I don't like the idea of buying an engine with a messy code base, no decent audio and only a few trivial eye candy effects. Slapping shadders on top of TGE was a very very bad decision IMO. GG should be fixing the core engine before making other products that are derived from it. They should also stick to one thing at a time, they never seem to get anything finished. All their products are in an 'early adopter' state and have been for years.
Seriously, I've seen the milestone 3 demo's and couldn't believe how poor it was.
In it's current state, poorly otimized, lacking lighting and shadowing, residual unused TGE code all over the place, no OpenGl, crippled audio layer, buggy editors, graphical artifacts, poor frame rate, real time editors which require a nasa computer to run smoothly, datablocks for materials - I wouldn't waste my time.
Having said that, I respect GG and this community and if they were to pull their finger out and bring TSE to the level it should have been at a year age, I would buy it.
#169
I'm wondering, what do people with older video cards get to see? Can they run the game? Does it crash? is it possible to let them run the game but show the original water?
I think this is a really cool resource, but I'm worried by adding it I will exclude a lot of people from playing the game.
05/29/2006 (11:47 am)
Hey,I'm wondering, what do people with older video cards get to see? Can they run the game? Does it crash? is it possible to let them run the game but show the original water?
I think this is a really cool resource, but I'm worried by adding it I will exclude a lot of people from playing the game.
#170
05/29/2006 (11:57 am)
@Ward: They should just see the original water.
#171
But now the water is all screwed up.
here a screen shot of the water.
http://e2g.50webs.com/error.jpg
*edit
doh, like everyone else, i didnt realize that you had to set the normal map texture in the editor. thanks guys for all your help
05/30/2006 (3:04 pm)
Okay, i got past the GL error, by putting this dglSetCanonicalState(); below line 703 in waterblock.cc.But now the water is all screwed up.
here a screen shot of the water.
http://e2g.50webs.com/error.jpg
*edit
doh, like everyone else, i didnt realize that you had to set the normal map texture in the editor. thanks guys for all your help
#172
the problem you are seeing has been covered multiple times,
including the very first screenshot posted in the comments!
edit make that *two* screenshots showing the exact issue.
05/30/2006 (3:08 pm)
man, read the resource.the problem you are seeing has been covered multiple times,
including the very first screenshot posted in the comments!
edit make that *two* screenshots showing the exact issue.
#173
my initial error wasnt that same issue. it was just getting the bug in. As you can see. soon after i posted the message. i just realized that they had the same issue with the screen shot.
My issue with the GL error, took a lot of digging around to find.
05/30/2006 (3:26 pm)
@Orion Elenzil my initial error wasnt that same issue. it was just getting the bug in. As you can see. soon after i posted the message. i just realized that they had the same issue with the screen shot.
My issue with the GL error, took a lot of digging around to find.
#174
*Edit
Okay, i got the reflections to work. All i had to do was to get this compiled in the TLK. and it worked, thanks for the help all.
05/30/2006 (3:53 pm)
Okay, now that i got it working. i have another bug. i cant seem to get the Reflection working right. I went into the PlayGui.cs and in the GameTSCtrl i turned isReflection on, and it didnt do anything, just set all the values to ap. and when i try to modify it. the game just exits. *Edit
Okay, i got the reflections to work. All i had to do was to get this compiled in the TLK. and it worked, thanks for the help all.
#175
05/31/2006 (2:44 am)
I'm not sure whats going on? But i hand merged with DRL, and the Lighting Kit. Now, i'm crashing at 75% of the Loading Objects bar. ANy ideas?
#176
hmm, thats interesting, make sure its a clean TLK, and see how it goes. otherwise it could be the map file itself.
For Those ppl having trouble merging CG water with DRL, i posted the package online
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10591
05/31/2006 (11:16 am)
@Chris. hmm, thats interesting, make sure its a clean TLK, and see how it goes. otherwise it could be the map file itself.
For Those ppl having trouble merging CG water with DRL, i posted the package online
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10591
#177
To Fix Gray Fog Problem, Open Console and Type
Edit: @T: Your resource stopped my DRL, from being DRL. I have bloom, but it doesn't change contrast.
05/31/2006 (1:26 pm)
Thanks T Squared, works like a charm now that i fixed the gray fog problem!To Fix Gray Fog Problem, Open Console and Type
$shaderloaded = false;
Edit: @T: Your resource stopped my DRL, from being DRL. I have bloom, but it doesn't change contrast.
#178
hmm, wierd. it seems to be a scripting issue. with the one i package in my latest resource the DRL seems to not be active. but when i ran the app with the Combo pack2 the DRL was working fine, but having issue with the proper reflections of the water. Not sure exactly why. i will have to look more into. or ask Alex if he knows what going on.
06/01/2006 (2:12 pm)
@Chrishmm, wierd. it seems to be a scripting issue. with the one i package in my latest resource the DRL seems to not be active. but when i ran the app with the Combo pack2 the DRL was working fine, but having issue with the proper reflections of the water. Not sure exactly why. i will have to look more into. or ask Alex if he knows what going on.
#179
Any help or hint as to what I'm doing wrong would be really appreciated!
06/07/2006 (12:41 pm)
I got it to work just fine under windows, but under Linux I'm hitting the following link error (on the dedicated server even!), and I'm starting to pull my hairs in frustration...--> Linking out.GCC3.RELEASE/indigod.bin ../lib/cg/lib/libCgGL.so: undefined reference to glXGetCurrentDisplay ../lib/cg/lib/libCgGL.so: undefined reference to glXQueryExtensionsString ../lib/cg/lib/libCgGL.so: undefined reference to glXGetProcAddressARB collect2: ld returned 1 exit status make[1]: *** [out.GCC3.RELEASE/indigod.bin] Error 1 make: *** [dedicated] Error 2
Any help or hint as to what I'm doing wrong would be really appreciated!
#180
WaterBlock(powp) {
position = "-1024 -1024 0";
rotation = "1 0 0 0";
scale = "2048 2048 125";
UseDepthMask = "1";
surfaceTexture = "editor/data/water/water";
envMapOverTexture = "~/data/water/specmask.png";
NormalMapTexture = "~/data/water/noise02.png";
liquidType = "OceanWater";
density = "0.1";
viscosity = "11";
waveMagnitude = "1";
surfaceOpacity = "1";
envMapIntensity = "11";
TessSurface = "50";
TessShore = "50";
SurfaceParallax = "1.5";
FlowAngle = "0";
FlowRate = "0";
DistortGridScale = "0.1";
DistortMag = "0.05";
DistortTime = "0.5";
ShoreDepth = "13";
DepthGradient = "2";
MinAlpha = "0.1";
MaxAlpha = "1";
tile = "1";
removeWetEdges = "1";
specularColor = "0.937255 0.937255 0.937255 0.650177";
specularPower = "1";
};
Can anybody help me?
the screenshot:
http://www.pixvers.com/pixvers/flash/noreflection.jpg
06/10/2006 (7:07 am)
Hey, I have got it work in TGE1.4 ( Cg1.4.1 ), water is better. but have no reflection. I ran it in my NVIDIA GeForce FX 5700LE, and my waterblock is:WaterBlock(powp) {
position = "-1024 -1024 0";
rotation = "1 0 0 0";
scale = "2048 2048 125";
UseDepthMask = "1";
surfaceTexture = "editor/data/water/water";
envMapOverTexture = "~/data/water/specmask.png";
NormalMapTexture = "~/data/water/noise02.png";
liquidType = "OceanWater";
density = "0.1";
viscosity = "11";
waveMagnitude = "1";
surfaceOpacity = "1";
envMapIntensity = "11";
TessSurface = "50";
TessShore = "50";
SurfaceParallax = "1.5";
FlowAngle = "0";
FlowRate = "0";
DistortGridScale = "0.1";
DistortMag = "0.05";
DistortTime = "0.5";
ShoreDepth = "13";
DepthGradient = "2";
MinAlpha = "0.1";
MaxAlpha = "1";
tile = "1";
removeWetEdges = "1";
specularColor = "0.937255 0.937255 0.937255 0.650177";
specularPower = "1";
};
Can anybody help me?
the screenshot:
http://www.pixvers.com/pixvers/flash/noreflection.jpg

Torque Owner Tim Heldna
Little help please. Got this in and working fine, except for 1 small problem. When I exit the game and go back into it the water disappears. If I go into the editor and select the water block it comes back.
Anyone else experience this???
P.S. Using tlk1.4