Jump to content
  • Advertisement
Sign in to follow this  
kobingo

Creating waves on a water surface (HLSL)

This topic is 4446 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Thanks for the reply, could you describe a little bit more how to do that (maybe in code)?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!