Creating waves on a water surface (HLSL)

Started by
28 comments, last by kobingo 17 years, 11 months ago
Hey, I got a water reflection that stretches over a big quad made by two triangles. What I want to do now is distort the pixels on the water to make it look like the water is moving (waves). How can I do this using a vertexshader/pixelshader (HLSL)? My vertexshader looks like this:

vertexOutput VS_TransformAndTexture(vertexInput IN) 
{
   vertexOutput OUT;

   // This does projective texturing

   OUT.pos = mul(float4(IN.position.xyz , 1.0), worldViewProj);

   OUT.project.x = 0.5 * (OUT.pos.w + OUT.pos.x);
   OUT.project.y = 0.5 * (OUT.pos.w - OUT.pos.y);
   OUT.project.z = OUT.pos.w;
	
   OUT.color = IN.diffuseColor;

   return OUT;
}
... and my pixelshader looks like this:

float4 PS_Textured( vertexOutput IN): COLOR
{
   float2 projcoord = (IN.project.xy / IN.project.z);
   float4 reflect = tex2D(TextureSampler, projcoord);

   return reflect;
}
The result I would like to make it look something like this: Water sample Thanks in advance! [Edited by - kobingo on May 9, 2006 12:29:14 PM]
Advertisement
I'm sure someone can help me with this...
Try passing a du_dv map of the wave into the shader.

use the red and green to offset the uv of the water reflection by a certailn amount. you can also incorporate the fresnel term if you want realistic reflection/refraction.
Thanks for the reply, could you describe a little bit more how to do that (maybe in code)?
Yeah, use a per-pixel distortion on the reflection coords from a normal or dudv map. The key is to distort the texture coordinates after projecting, so that you avoid some ugly glitches.
I know the theory, just don't know how to implement it in code... someone?
It's not HLSL, but maybe this would help.

Also check out the site's forum, for it has a couple of additions to the tutorial.
Hope that helps.

Greets
Thanks, but it didn't help much :-(
perhaps this does help: GameTutorials->RealisticWater
It's written for GLSL, but deals with the theory...
That one didn't really explain it either :-(

This topic is closed to new replies.

Advertisement