Advertisement Jump to content
Morrison Din

OpenGL Water DuDV Maps, not mapping correctly

Recommended Posts

Posted (edited)

Hello all,

I need some help with distorting a water quad using a DuDv map. I have been following ThinMatrix's Water tutorials, for the most part successfully. For my particular problem, I followed this tutorial: https://www.youtube.com/watch?v=6B7IF6GOu7s.

Upon using a DuDv map to distort my water quad, all seems fine, except that there is a small problem. There are line seams across the water quad.

The attached image illustrates the issue.Seam.png.97baebdd246a97ab95a532e22663b2b9.png

This is my code:

water.vertexshader
 

// The coordinates to sample the dudv map with

layout(location = 0) in vec3 vertex;

void main(){

texCoords = vec2(vertex.x/2.0 + 0.5, vertex.z/2.0 + 0.5) * 0.24; // vertex is a read-in coordinate from a blender exported mesh file

}

water.fragmentshader
 

uniform sampler2D waterDuDv;

uniform float in_time;

void main(){

vec2 distortion = texture(waterDuDv, vec2(texCoords.x + in_time, texCoords.y)).rg * 0.1;
distortion = texCoords + vec2(distortion.x, distortion.y + in_time);
vec2 totalDistortion = (texture(waterDuDv, distortion).rg * 2.0 - 1.0) * 0.02;

// Projectively map the reflection texture
vec2 clipProj = ((clipSpace.xy / clipSpace.w) / 2.0 + 0.5);

clipProj.y *= -1.0f;

// Distort sampled texture with dudv map
clipProj += totalDistortion;

clipProj.x = clamp(clipProj.x, 0.001, 0.999);
clipProj.y = clamp(clipProj.y, -0.999, -0.001);

finalVec = vec4(texture(waterTexture, clipProj).rgb, 1.0); // waterTexture is a Render to Texture reflection image of the scene


}

If anyone could point out what's wrong or point me in the right direction, I would appreciate it.

Thank you in advance!

Edited by Morrison Din
Update

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!