Game Development Community

Big waves in TSE?

by Vashner · in Torque Game Engine Advanced · 10/11/2005 (3:34 pm) · 34 replies

It looks to me like the waterblock in TSE has a limited wave size. How would one
go about doing something like big ocean swells? Like 6-8 foot or higher seas.

I have seen it done in EQ2 with what looks like a shader function...
Page «Previous 1 2
#1
10/15/2005 (10:41 pm)
TSE water is flat, there are no waves at all.
#2
10/16/2005 (12:10 am)
Correct... the waves, as far as I can tell, are just an effect of the normal map.
#3
10/16/2005 (12:24 am)
You'll need to implement some vert shaders to do physical waves. There are loads of good example shaders online that could be implemented in TSE. :)
#4
10/16/2005 (7:58 am)
Thx Josh w... i'll start looking there. I have seen stuff like speakers in render monkey.
#5
10/16/2005 (8:28 am)
We had it in for a bit but it ended up being very costly in the vertex shader, so we ripped it out again. :P Easy to get going, as Josh says.
#6
10/16/2005 (6:51 pm)
Randy, from what I remember off hand EQ2 has flat water, but there is a really big pulsing whiteness that looks like sea waves at a distance, and to some degree, close up.
#7
10/17/2005 (3:30 am)
EQ 2 has flat water for the most part, but on the ships they appear to be using vertex shaders to replicate actual waves. Nektulos Forest also I believe has real waves in the river. Most likely it was used in those two scenarios because your dealing with special situatiosn where they worked well. On the various ship zones the entire zone is one ship surrounded by an animated sea. In Nektulos the river is a very thin object in the zone. So in those cases the performance hit was probably not bad enough to make a difference. In the cases of large bodies of water inside of zones though I believe the water is flat.
#8
10/17/2005 (5:35 pm)
Ah you're right JC, on the boats. And I guess the water in Nek a bit too. Those do look like vertex shaders, the waves sort of look like a sine function :P

My first thought was the water in FP/Ant/SS, which is all flat.

I'm not sure, but the water "ripples" you make when you move in the water seem to look more like the ripples in Nek - sharp changes on the water surface vertices.

Frankly, EQ2 has bizzare water. If you can ever get a situation where there are 2 adjacent (but not connected) bodies of water (or anything where you can get one on top of the other on your screen, that is what matters), walk around in the one in front, but look at the one in back. The surface ripples will spread over into the one in the back, even though it's not physically connected at all (in the sense of real simulation). Sort of bizzare effect, I could get a screenshot I guess. The fountains in Shimmering Citadel are a good place to do this.
#9
10/18/2005 (12:37 am)
The example in Rendermonkey 1.6 for oceanwater_asm is interesting.

Quote:

//--------------------------------------------------------------//
// Vertex Shader
{
vs.1.1

dcl_position v0
dcl_normal v1
dcl_texcoord v2
dcl_tangent v3
dcl_binormal v4

// use tex coords as input to sinusoidal warp //
mul r0, c14, v2.x
mad r0, c15, v2.y, r0

mov r1, c16.x // time...
mad r0, r1, c13, r0 // add scaled time to move bumps according to freq
add r0, r0, c12 // starting time offset
frc r0.xy, r0 // take frac of all 4 components
frc r1.xy, r0.zwzw //
mov r0.zw, r1.xyxy //

mul r0, r0, c10.x // mul by fixup (due to inaccuracy)
sub r0, r0, c0.y // subtract 0.5
mul r0, r0, c1.w // mul tex coords by 2pi (coords range from -pi to pi)

mul r5, r0, r0 // (wave vec)^2
mul r1, r5, r0 // (wave vec)^3
mul r6, r1, r0 // (wave vec)^4
mul r2, r6, r0 // (wave vec)^5
mul r7, r2, r0 // (wave vec)^6
mul r3, r7, r0 // (wave vec)^7
mul r8, r3, r0 // (wave vec)^8

mad r4, r1, c2.y, r0 // (wave vec) ((wave vec)^3)/3!
mad r4, r2, c2.z, r4 // + ((wave vec)^5)/5!
mad r4, r3, c2.w, r4 // ((wave vec)^7/7!

mov r0, c0.z // 1
mad r5, r5, c3.x, r0 // -(wave vec)^2/2!
mad r5, r6, c3.y, r5 // +(wave vec)^4/4!
mad r5, r7, c3.z, r5 // -(wave vec)^6/6!
mad r5, r8, c3.w, r5 // +(wave vec)^8/8!

sub r0, c0.z, c0.x //... 1-wave scale
mul r4, r4, r0 // scale sin
mul r5, r5, r0 // scale cos

dp4 r0, r4, c11 // mul by wave heights

mul r0.xyz, v1, r0 // mul wave mag at this vertex by normal
add r0.xyz, r0, v0 // add to position
mov r0.w, c0.z // homogenous component

m4x4 oPos, r0, c4 // Outpos = ObjSpace * World-view-proj matrix

mul r1, r5, c11 // cos * wave height
dp4 r9.x, -r1, c14 // normal x offset
dp4 r9.yzw, -r1, c15 // normal y offset and tangent offset
mov r5, v1 // starting normal
mad r5.xy, r9, c10.y, r5 //warped normal move nx, ny according to
// cos*wavedir*waveheight
mov r4, v3 // tangent
mad r4.z, -r9.x, c10.y, r4.z // warped tangent vector

dp3 r10.x, r5, r5 // normalize the normal
rsq r10.y, r10.x
mul r5, r5, r10.y

dp3 r10.x, r4, r4 // normalize the tangent
rsq r10.y, r10.x
mul r4, r4, r10.y

mul r3, r4.yzxw, r5.zxyw // xprod to find binormal
mad r3, r4.zxyw, -r5.yzxw, r3


mov r6, c8 // get eye pos into object space
m4x4 r2, r6, c20

sub r2, r2, r0 // find view vector

dp3 r10.x, r2, r2 // normalize view vector
rsq r10.y, r10.x
mul r2, r2, r10.y

mov r0, c16.x
mul r0, r0, c18.xyxy
frc r0.xy, r0 // frac of incoming time
add r0, v2, r0 // add time to tex coords
mov oT0, r0 // output tex coords

mov r0, c16.x
mul r0, r0, c18.zwzw
frc r0.xy, r0 // frac of incoming time
add r0, v2, r0 // add time to tex coords
mov oT1, r0.yxzw // output distorted tex coord1

mov oT2, r2 // pass in view vector (world space)
mov oT3, r3 // tangent
mov oT4, r4 // binormal
mov oT5, r5 // normal
};
#10
10/18/2005 (12:37 am)
Pixel shader
Quote:// Pixel Shader
{
ps.1.4

def c0, 0.5, 0.5, 0.5, 1.0

texld r0, t0 // bump map 0
texld r1, t1 // bump map 1
texcrd r2.rgb, t2 // view vec
texcrd r3.rgb, t3 // tangent
texcrd r4.rgb, t4 // binormal
texcrd r5.rgb, t5 // normal
add_d4 r0.xy, r0_bx2, r1_bx2 // scaled avg of 2 bumpmap xy offsets
mul r1.rgb, r0.x, r3 // put bump maps into world space
mad r1.rgb, r0.y, r4, r1
mad r1.rgb, r0.z, r5, r1
dp3 r0.rgb, r1, r2 // V.N
mad r2.rgb, r1, r0_x2, -r2 // R = 2N(V.N)-V
mov_sat r0.rgb, r0_x2 // 2 * V.N (sample over range of 1D map)

phase

texld r2, r2 // env map
texld r3, r0 // index frenel map using 2*N.V

mul r2.rgb, r2, r2 // square env map
+mul r2.a, r2.g, r2.g // use green of env as specular
mul r2.rgb, r2, 1-r0.r // fresnel term
+mul r2.a, r2.a, r2.a // specular ^4

add_d4_sat r2.rgb, r2, r3_x2 // += water color
+mul r2.a, r2.a, r2.a // specular ^8

mad_sat r0, r2.a, c1, r2 // += specular * specular color
#11
10/19/2005 (1:11 pm)
Question: The solution to adding big waves, should I change the waterblock in source or add some custom shader using scripting?
I am just now looking at the waterblock source.
#12
10/19/2005 (10:10 pm)
I'd think you could get away with changing the vertex shader alone. There may be issues caused by this implementation that need to be worked out (maybe on the edges of the water?), but as far as implementation...

I can't think of anything. Even the pixel shader could be left alone, provided the vertex shader doesnt mess up the way it reflects.

If we had SM 3.0 instead of 2.0...
You might want to load up another texture to use as a wave map or something, but AFAIK using textures in a vertex shader isn't allowed in 2.0, you have to use 3.0. So even that's out of the picture.
#13
10/20/2005 (9:51 am)
It's likely you'll have to set up your geometry in the waterblock to match what rendermonkey expects as well. I doubt the drop in of the vertex shader will do it all for you.
#14
10/20/2005 (2:23 pm)
Yea because I think the waterblock shader is embedded into the waterblock c code. But I am happy camper. I know
what to work on for now.
#15
10/21/2005 (5:11 pm)
The shader isn't in the code, you can specify what material you want the waterblock to use. but yeah, you may have to change how it sets up the geometry...
#16
11/28/2005 (2:51 pm)
Hey randy.. If your not after anything TOO fancy..heres a rough outline to get waves happening in the vert shader
(code ripped from NeHe vertex shader tutorial)


send a float value to the vert shader, in the water's render loop (ie updated every frame)
#define		TWO_PI 6.2831853071	//put these somewhere else
float wave_movement =0.0;

// then doen in the render loop
wave_movement += 0.00001;					// Increment Our Wave Movement
if (wave_movement > TWO_PI)					// Prevent Crashing
     wave_movement = 0.0;

GFX->setVertexShaderConstF( VC_USERDEF1,(float*)wave_movement,1);

then in the vertex shader add (before the position transform)
IN.position.y = ( sin(wave + (IN.position.x / 5.0) ) + sin(wave + (IN.position.z / 4.0) ) ) * 2.5f;
where wave is:
uniform float   wave   : register(VC_USERDEF1)

and volia.. ungulating water!!


;)
#17
11/28/2005 (3:35 pm)
Randy ,

1. Perlin noise. Weak method, but good in some settings.

2. Look into FFT methods , they are resonably easy to implement , but they are not physical model of water simulation, but statistical.

3.A more powerfull method is to use a Navier Stokes solver. This is also more accurate than FFT water.
But this is a hell of a motherfuckerwater.

Read this:

http://www.andyc.org/lecture/viewlog.php?log=Realistic%20Water%20Rendering,%20by%20Yann%20L


Also google for Gerstner waves. I think i have readiy shaders for this on some CD somehwere. I cant recall exactly. I think this was used by Cyan in theyr Myst titles. Look cool, and can make very decent shorelines waves. IIRC , go to Nvidia FTP and download the source code from Gpu Gems 1. it should have some sample made fom a guy from Cyan.

Always remember, Randy, nextgen technologies in games can be found today by using Google, if you know where to look foor, and what for. Its just a little matter of implmenting them sometimes into a specific engine.

Dan, humble begginer programmer
#18
11/28/2005 (8:19 pm)
Yea I started the post more to get it down and come back to it later. Thx guys. @Dan - yea I know about google... lol.. You think I am that dumb? lol you post was perfect till the google comment. :) I'll check out that URL thanks man.

I just ordered a 6800 GT so i'll be able to play with water again in the coming months. There is a great example of voxel use where you can make realistic wakes etc.

@Kevin - thanks for the input on subject.
#19
11/28/2005 (8:44 pm)
You can find that a NS solver is a too complete beast to implmement it in a vertex shader. Its not a problem , it works just great
as a CPU deformer, whithout impacting the speed of the engine on modern CPUs. Also, in some situations you may want to clone
a new object for water rendering , and use a vertex grid which is highly tesselated on the shorelines, where the effects must look
cool to the user , and sparsley tesselated towards the inward of the water.

Sorry about google thing. Wasnt really for you. For others which might have read this post.
#20
11/29/2005 (2:19 am)
There was a nice paper on water rendering on the nvidia site I believe it was.. they had a new vertex shader implementation that looked pretty nice in the shots (which were from pacific fighters by Maddox/Ubisoft)
Page «Previous 1 2