Water edge seperate shader
by Alex Huck · in Torque Game Engine Advanced · 11/08/2006 (3:05 pm) · 8 replies
Hi, kind of a tall order here... How would one go about making an independent seperate shader for the waters edge, similar to TGE's lighter colored water near the edge of the terrain.
Or better yet, a shader modifier based on altitude from the atlas object, so I can make water appear darker in deeper areas, and more transparent in shallow areas, that would be awesome :) (To use the waterObject.clarity variable, and modify it based on its direct distance from the ground.)
I'm trying to learn shaders here, and in the beginning of waterCubeReflectRefractP.hlsl there is
struct ConnectData
{
float4 texCoord : TEXCOORD0;
float3 lightVec : TEXCOORD1;
float2 texCoord2 : TEXCOORD2;
float4 texCoord3 : TEXCOORD3;
float2 fogCoord : TEXCOORD4;
float3 pos : TEXCOORD6;
float3 eyePos : TEXCOORD7;
};
My first thought on this is this; "ConnectData", is connecting the hlsl file with data retrieved form the game.
the float# is a floating point integer with # of number sets (i.e a float 3 should have 3 groups of numbers example: float3 position "0 0 0";)
So my guesses are that it retrieves your eye position, (eyePos), the direction light sources are coming from (lightVec), and the games position of the object its-self (pos) and some other variables I can't guess what they do yet (texture Coordinates)
Are my guesses right? How does it gather this info, is there a way to import any variable from the game engine into the hlsl file for usage there?
Many thanks for your time, hopefully if this gets done and looks great it'll make an excellent resource
-edit- Another question: Why are they all called "TEXCOORD#", I wish they were named more clearly, isn't that kind of like naming all your variables x y and z, and x2,y2,z2 etc? :) What does light Vector have to do with TexCoordinates?
Or better yet, a shader modifier based on altitude from the atlas object, so I can make water appear darker in deeper areas, and more transparent in shallow areas, that would be awesome :) (To use the waterObject.clarity variable, and modify it based on its direct distance from the ground.)
I'm trying to learn shaders here, and in the beginning of waterCubeReflectRefractP.hlsl there is
struct ConnectData
{
float4 texCoord : TEXCOORD0;
float3 lightVec : TEXCOORD1;
float2 texCoord2 : TEXCOORD2;
float4 texCoord3 : TEXCOORD3;
float2 fogCoord : TEXCOORD4;
float3 pos : TEXCOORD6;
float3 eyePos : TEXCOORD7;
};
My first thought on this is this; "ConnectData", is connecting the hlsl file with data retrieved form the game.
the float# is a floating point integer with # of number sets (i.e a float 3 should have 3 groups of numbers example: float3 position "0 0 0";)
So my guesses are that it retrieves your eye position, (eyePos), the direction light sources are coming from (lightVec), and the games position of the object its-self (pos) and some other variables I can't guess what they do yet (texture Coordinates)
Are my guesses right? How does it gather this info, is there a way to import any variable from the game engine into the hlsl file for usage there?
Many thanks for your time, hopefully if this gets done and looks great it'll make an excellent resource
-edit- Another question: Why are they all called "TEXCOORD#", I wish they were named more clearly, isn't that kind of like naming all your variables x y and z, and x2,y2,z2 etc? :) What does light Vector have to do with TexCoordinates?
About the author
#2
Have it have volumetric fog (Which I think it already does, right?) under the water, and set clarity to semi clear, that way the volumetric fog (Which I think I heard mentioned somewhere) will add 2 nice effects
1) It will make it so that visability is impaired underwater, and
2) when out of water makes deeper areas look darker, and shallow areas clear.
Maybe I'm thinking og TGE, not TSE having volumetric fog... So if that's the case, and volumetric fog code isn't in, then this would be a more difficult approach, adding the fog code in from scratch
11/08/2006 (4:46 pm)
I was thinking about it, and I think I have come up with a more realistic / efficient / logical approach:Have it have volumetric fog (Which I think it already does, right?) under the water, and set clarity to semi clear, that way the volumetric fog (Which I think I heard mentioned somewhere) will add 2 nice effects
1) It will make it so that visability is impaired underwater, and
2) when out of water makes deeper areas look darker, and shallow areas clear.
Maybe I'm thinking og TGE, not TSE having volumetric fog... So if that's the case, and volumetric fog code isn't in, then this would be a more difficult approach, adding the fog code in from scratch
#3
and here

he has released the code here:
www.garagegames.com/mg/forums/result.thread.php?qt=58130
but a working version that is compatible with TGEA 1.0 has not yet been realesed
02/20/2007 (5:06 pm)
Jocobs water is going to do this you can see from this pic
and here
he has released the code here:
www.garagegames.com/mg/forums/result.thread.php?qt=58130
but a working version that is compatible with TGEA 1.0 has not yet been realesed
#4
addikt
03/01/2007 (2:59 am)
My question isnt directly related to that water shading, but more a question if anyone has any ideas how to implement waves at the water edge. A lot of games used animated textures of white water waves to simulate the crash onto the beach and hides the water edge quite well. Does anyone have any ideas on how this could be done?addikt
#5
03/01/2007 (3:08 pm)
Yeah I want to say that this listed as being supported already. I thik I saw it in the features list. I should would like to know how to enable it as well.
#6
03/03/2007 (5:18 am)
GDM November 2006 pg 21 'Go with the Flow'. Possibly archived on GamaSutra.
#7
It does not work with Atlas2 AFAIK and not legacy, so it is of limited use currently.
Here is how I would do it:
1. On mission startup, check altitute between terrain and waterplane and store it in a depth map, preferably on the water object. For ideas, check out Melv's depth map code in TGE.
2. Cache it so you do not have to calculate it each time.
3. Pass the depth map into the pixel shader and blend clarity with the depth map or in your case, the water edge texture.
03/07/2007 (5:05 am)
Quote:
Yeah I want to say that this listed as being supported already.
It does not work with Atlas2 AFAIK and not legacy, so it is of limited use currently.
Quote:My question isnt directly related to that water shading, but more a question if anyone has any ideas how to implement waves at the water edge.
Here is how I would do it:
1. On mission startup, check altitute between terrain and waterplane and store it in a depth map, preferably on the water object. For ideas, check out Melv's depth map code in TGE.
2. Cache it so you do not have to calculate it each time.
3. Pass the depth map into the pixel shader and blend clarity with the depth map or in your case, the water edge texture.
#8
03/07/2007 (9:51 am)
Getting this going with Atlas2 is tops on my "if I have time" list. I won't be able to work on it until after the end of the month, so if anyone gets it going sooner let me know.
Torque Owner Stefan Lundmark